Android studio课程设计开发实现---日记APP

Posted 勤奋的oyoung

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android studio课程设计开发实现---日记APP相关的知识,希望对你有一定的参考价值。

android studio课程设计开发实现—日记APP


文章目录


前言

你们好,我是oy,介绍一个简易日记APP。

一、效果

1.启动页、引导页及登陆注册

2.日记相关功能

3.个人中心界面

二、功能介绍

1.主要功能

  1. 实现应用启动页及引导页
  2. 实现设置密码进入APP,对密码进行加密处理
  3. 实现底部导航栏,分为日记列表,新建日记,个人中心模块
  4. 实现对日记删除、修改、新增的基础功能
  5. 实现圆形头像,通过相册及拍照并裁剪图片设置头像。可实时保存。
  6. 实现网络更新个人中心美图。
  7. 对密码展示及关闭,跳转应用设置界面
  8. 动态获取拍照及相册访问权限

2.涉及知识点

  1. activity与fragment数据传递、页面更新、相互跳转。
  2. SharedPrefrenced存储、文件存储、文件加密。
  3. Android应用权限获取及设置
  4. 控件的使用:Button、EditText、AlertDialog、Imageview、ImageButton、viewPager2、Toolbar、RecycleView、NavigationButton等
  5. 布局的使用:LinearLayout、ConstraintLayout、RelativeLayout等
  6. 调用Android系统应用
  7. 自定义View:底部弹窗(比较复杂)、圆形头像
  8. Glide框架使用:网络加载图片
  9. Android框架:MVC

三、实现思路

  1. MainActivity中使用BottomNavigationView、ViewPager2、Toolbar实现。
public class MainActivity extends AppCompatActivity 
    private BottomNavigationView bottomNavigationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initToolbar();
        initFragment();
        initNavigationBottom();
    

    @SuppressLint("ResourceAsColor")
    private void initNavigationBottom() 
        bottomNavigationView = findViewById(R.id.navigation_bottom);
        bottomNavigationView.setItemIconTintList(null);
        bottomNavigationView.setOnNavigationItemSelectedListener(itemSelectedListener);
    

    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
        return super.onCreateOptionsMenu(menu);
    

    private void initFragment() 
        DiariesFragment diariesFragment = getDiariesFragment();
        if (diariesFragment == null) 
            diariesFragment = new DiariesFragment();
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), diariesFragment, R.id.content);
        
    

    private DiariesFragment getDiariesFragment() 
        return (DiariesFragment) getSupportFragmentManager().findFragmentById(R.id.content);
    

    private void initToolbar() 
        //设置顶部状态栏为透明
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    

    private final BottomNavigationView.OnNavigationItemSelectedListener itemSelectedListener = item -> 
        switch (item.getItemId()) 
            case R.id.menu_diary:
                MeController.setToolbarVisibility(this);
                ActivityUtils.removeFragmentTOActivity(getSupportFragmentManager(), getSupportFragmentManager().findFragmentById(R.id.content));
                ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), new DiariesFragment(), R.id.content);
                break;
            case R.id.menu_me:
                findViewById(R.id.toolbar).setVisibility(View.GONE);
                ActivityUtils.removeFragmentTOActivity(getSupportFragmentManager(), getSupportFragmentManager().findFragmentById(R.id.content));
                ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), new MeFragment(), R.id.content);
                break;
            case R.id.menu_new:
                bottomNavigationView.setVisibility(View.GONE);
                MeController.setToolbarVisibility(this);
                ActivityUtils.removeFragmentTOActivity(getSupportFragmentManager(), getSupportFragmentManager().findFragmentById(R.id.content));
                ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), new AddDiaryFragment(), R.id.content);
                break;
        
        return true;
    ;

MainActivity的layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            android:fitsSystemWindows="true"
            android:theme="@style/Widget.AppCompat.Toolbar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
    </com.google.android.material.appbar.AppBarLayout>

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigation_bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:menu="@menu/menu_navigation"
        android:background="?android:attr/windowBackground"/>

</LinearLayout>
  1. ViewPager2中切换不同fragment,对应导航栏新增日记、个人中心及日记列表。
public class DiariesFragment extends Fragment 
    private DiariesController mController;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        mController = new DiariesController(this);
    
    
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) 
        View root = inflater.inflate(R.layout.fragment_diaries, container, false);
        mController.setDiariesList(root.findViewById(R.id.diaries_list));
        return root;
    

    @Override
    public void onResume() 
        super.onResume();
        mController.loadDiaries();
    

DiariesFragment的layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/diaries_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</RelativeLayout>
public class AddDiaryFragment extends Fragment implements View.OnClickListener 
    private AddDiaryController mController;
    private View edit_layout;
    private Button btn_confirm;
    private EditText edit_title;
    private EditText edit_desc;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        mController = new AddDiaryController(this);
    

    private void initView(View view) 
        btn_confirm = view.findViewById(R.id.add_diary_confirm);
        btn_confirm.setOnClickListener(this);
        edit_title = view.findViewById(R.id.edit_add_title);
        edit_desc = view.findViewById(R.id.edit_add_desc);
        edit_layout = view.findViewById(R.id.edit_layout);
        edit_layout.setOnClickListener(this);
    



    @Override
    public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) 
        inflater.inflate(R.menu.menu_cancel, menu);
    

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) 
        switch (item.getItemId()) 
            case R.id.menu_cancel:
                mController.closeWriteDiary(getActivity().getSupportFragmentManager(), this);
                mController.setNavigationVisibility();
                return true;
        
        return false;
    

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) 
        View root = inflater.inflate(R.layout.fragment_add_diary, container, false);
        initView(root);
        return root;
    

    @Override
    public void onDestroy() 
        super.onDestroy();
    

    @Override
    public void onClick(View view) 
        switch (view.getId()) 
            case R.id.add_diary_confirm:
                mController.addDiaryToRepository(edit_title.getText().toString().trim(), edit_desc.getText().toString().trim());
                mController.setNavigationVisibility();
                mController.closeWriteDiary(getActivity().getSupportFragmentManager(), this);
                break;
            case R.id.edit_layout:
                mController.changeFocus(edit_desc);
                break;
        
    

AddDiaryFragment的layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        android:orientation="vertical">
        <EditText
            android:id="@+id/edit_add_title"
            android:hint="@string/add_title_hint"
            android:minLines="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/edit_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginTop="5dp"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        android:layout_marginBottom="10dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingStart="5dp"
            android:paddingTop="5dp"
            android:paddingEnd="5dp"
            android:paddingBottom="5dp"
            android:background="@drawable/edit_background">
            <EditText
                android:id="@+id/edit_add_desc"
                android:hint="@string/add_title_description"
                android:gravity="top"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="vertical"
                android:background="@null"/>
        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">
        <Button
            Android课程---Android Studio安装及使用

微课程--Android--Android概述

Android课程---Android Studio使用小技巧:提取方法代码片段

Android Studio实现考试管理系统

第一章 : Android Studio 介绍 [Learn Android Studio 汉化教程]

Android课程---Android Studio的一些小技巧