0


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实现。
publicclassMainActivityextendsAppCompatActivity{privateBottomNavigationView bottomNavigationView;@OverrideprotectedvoidonCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initToolbar();initFragment();initNavigationBottom();}@SuppressLint("ResourceAsColor")privatevoidinitNavigationBottom(){
        bottomNavigationView =findViewById(R.id.navigation_bottom);
        bottomNavigationView.setItemIconTintList(null);
        bottomNavigationView.setOnNavigationItemSelectedListener(itemSelectedListener);}@OverridepublicbooleanonCreateOptionsMenu(Menu menu){returnsuper.onCreateOptionsMenu(menu);}privatevoidinitFragment(){DiariesFragment diariesFragment =getDiariesFragment();if(diariesFragment ==null){
            diariesFragment =newDiariesFragment();ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), diariesFragment,R.id.content);}}privateDiariesFragmentgetDiariesFragment(){return(DiariesFragment)getSupportFragmentManager().findFragmentById(R.id.content);}privatevoidinitToolbar(){//设置顶部状态栏为透明getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);Toolbar toolbar =findViewById(R.id.toolbar);setSupportActionBar(toolbar);}privatefinalBottomNavigationView.OnNavigationItemSelectedListener itemSelectedListener = item ->{switch(item.getItemId()){caseR.id.menu_diary:MeController.setToolbarVisibility(this);ActivityUtils.removeFragmentTOActivity(getSupportFragmentManager(),getSupportFragmentManager().findFragmentById(R.id.content));ActivityUtils.addFragmentToActivity(getSupportFragmentManager(),newDiariesFragment(),R.id.content);break;caseR.id.menu_me:findViewById(R.id.toolbar).setVisibility(View.GONE);ActivityUtils.removeFragmentTOActivity(getSupportFragmentManager(),getSupportFragmentManager().findFragmentById(R.id.content));ActivityUtils.addFragmentToActivity(getSupportFragmentManager(),newMeFragment(),R.id.content);break;caseR.id.menu_new:
                bottomNavigationView.setVisibility(View.GONE);MeController.setToolbarVisibility(this);ActivityUtils.removeFragmentTOActivity(getSupportFragmentManager(),getSupportFragmentManager().findFragmentById(R.id.content));ActivityUtils.addFragmentToActivity(getSupportFragmentManager(),newAddDiaryFragment(),R.id.content);break;}returntrue;};}

MainActivity的layout

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns: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.AppBarLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><androidx.appcompat.widget.Toolbarandroid: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><FrameLayoutandroid:id="@+id/content"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"/><com.google.android.material.bottomnavigation.BottomNavigationViewandroid: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,对应导航栏新增日记、个人中心及日记列表。
publicclassDiariesFragmentextendsFragment{privateDiariesController mController;@OverridepublicvoidonCreate(@NullableBundle savedInstanceState){super.onCreate(savedInstanceState);
        mController =newDiariesController(this);}@Nullable@OverridepublicViewonCreateView(@NonNullLayoutInflater inflater,@NullableViewGroup container,@NullableBundle savedInstanceState){View root = inflater.inflate(R.layout.fragment_diaries, container,false);
        mController.setDiariesList(root.findViewById(R.id.diaries_list));return root;}@OverridepublicvoidonResume(){super.onResume();
        mController.loadDiaries();}}

DiariesFragment的layout

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/diaries_list"android:layout_width="match_parent"android:layout_height="wrap_content"/></RelativeLayout>
publicclassAddDiaryFragmentextendsFragmentimplementsView.OnClickListener{privateAddDiaryController mController;privateView edit_layout;privateButton btn_confirm;privateEditText edit_title;privateEditText edit_desc;@OverridepublicvoidonCreate(@NullableBundle savedInstanceState){super.onCreate(savedInstanceState);
        mController =newAddDiaryController(this);}privatevoidinitView(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);}@OverridepublicvoidonCreateOptionsMenu(@NonNullMenu menu,@NonNullMenuInflater inflater){
        inflater.inflate(R.menu.menu_cancel, menu);}@OverridepublicbooleanonOptionsItemSelected(@NonNullMenuItem item){switch(item.getItemId()){caseR.id.menu_cancel:
                mController.closeWriteDiary(getActivity().getSupportFragmentManager(),this);
                mController.setNavigationVisibility();returntrue;}returnfalse;}@Nullable@OverridepublicViewonCreateView(@NonNullLayoutInflater inflater,@NullableViewGroup container,@NullableBundle savedInstanceState){View root = inflater.inflate(R.layout.fragment_add_diary, container,false);initView(root);return root;}@OverridepublicvoidonDestroy(){super.onDestroy();}@OverridepublicvoidonClick(View view){switch(view.getId()){caseR.id.add_diary_confirm:
                mController.addDiaryToRepository(edit_title.getText().toString().trim(), edit_desc.getText().toString().trim());
                mController.setNavigationVisibility();
                mController.closeWriteDiary(getActivity().getSupportFragmentManager(),this);break;caseR.id.edit_layout:
                mController.changeFocus(edit_desc);break;}}}

AddDiaryFragment的layout

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:layout_marginStart="10dp"android:layout_marginEnd="10dp"android:orientation="vertical"><EditTextandroid: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><LinearLayoutandroid: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"><LinearLayoutandroid: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"><EditTextandroid: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><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:orientation="horizontal"><Buttonandroid:id="@+id/add_diary_confirm"android:text="@string/btn_ok"android:layout_width="wrap_content"android:layout_height="wrap_content"/></LinearLayout></LinearLayout>
  1. 将应用密码加密保存与文件中。每次登陆获取密码并对比。
publicclassLoginDirectActivityextendsAppCompatActivityimplementsView.OnClickListener{privateEditText edit_input_text;privateButton btn_comeIn;privateTextView tv_setPsw;privatestaticfinalStringTAG="Login2Activity";@OverrideprotectedvoidonCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_direct_login);bindView();}privatevoidbindView(){getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        edit_input_text =findViewById(R.id.edit_login2_input_text);
        btn_comeIn =findViewById(R.id.btn_login2_comeIn);
        btn_comeIn.setOnClickListener(this);
        tv_setPsw =findViewById(R.id.tv_setPsw);
        tv_setPsw.setOnClickListener(this);}@OverridepublicvoidonClick(View v){switch(v.getId()){caseR.id.tv_setPsw:Intent setPsw_intent =newIntent(LoginDirectActivity.this,LoginActivity.class);startActivity(setPsw_intent);LoginDirectActivity.this.finish();//                overridePendingTransition(R.anim.out_to_left,R.anim.in_from_right);break;caseR.id.btn_login2_comeIn:String psw = edit_input_text.getText().toString().trim();if(psw.isEmpty()){Toast.makeText(this,"密码不能为空!",Toast.LENGTH_SHORT).show();return;}String readInfoByContext =FileUtils.readInfoByContext(this);if(psw.equals(readInfoByContext)){Toast.makeText(this,"登录成功!",Toast.LENGTH_SHORT).show();Intent intent =newIntent(this,MainActivity.class);startActivity(intent);//                    overridePendingTransition(R.anim.out_to_left,R.anim.in_from_right);}else{Toast.makeText(this,"密码不正确!",Toast.LENGTH_SHORT).show();}break;}}}

LoginDirectActivity 的layout

<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayoutxmlns: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"tools:context=".view.LoginDirectActivity"><Buttonandroid:id="@+id/btn_login2_comeIn"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginStart="40dp"android:layout_marginEnd="40dp"android:text="进入"app:layout_constraintBottom_toTopOf="@+id/guideline5"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"/><LinearLayoutandroid:id="@+id/linearLayout"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginStart="40dp"android:layout_marginEnd="40dp"android:gravity="center_vertical"android:orientation="horizontal"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="@+id/guideline7"><ImageViewandroid:layout_width="32dp"android:layout_height="32dp"android:src="@mipmap/come_in_key"/><EditTextandroid:id="@+id/edit_login2_input_text"android:hint="输入您的密码"android:inputType="textPassword"android:layout_width="match_parent"android:layout_height="wrap_content"/></LinearLayout><androidx.constraintlayout.widget.Guidelineandroid:id="@+id/guideline4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"app:layout_constraintGuide_percent="0.22"/><androidx.constraintlayout.widget.Guidelineandroid:id="@+id/guideline5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"app:layout_constraintGuide_percent="0.58"/><TextViewandroid:id="@+id/tv_login2_password_title"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:text="输入密码"android:textSize="30sp"android:textStyle="bold"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="@+id/guideline4"/><androidx.constraintlayout.widget.Guidelineandroid:id="@+id/guideline7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"app:layout_constraintGuide_percent="0.4"/><TextViewandroid:id="@+id/tv_setPsw"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="设置密码"android:textStyle="bold"app:layout_constraintEnd_toEndOf="@+id/linearLayout"app:layout_constraintTop_toBottomOf="@+id/linearLayout"/></androidx.constraintlayout.widget.ConstraintLayout>
  1. 使用SharedPrefrenced存储日记内容及标题。
publicfinalclassSharedPreferencesUtils{privatestaticfinalSimpleArrayMap<String,SharedPreferencesUtils> mCaches =newSimpleArrayMap<>();privateSharedPreferences mSharedPreferences;privateSharedPreferencesUtils(finalString spName,finalint mode){
        mSharedPreferences =YyApplication.get().getSharedPreferences(spName, mode);}publicstaticSharedPreferencesUtilsgetInstance(String spName){SharedPreferencesUtils utils = mCaches.get(spName);if(utils ==null){
            utils =newSharedPreferencesUtils(spName,Context.MODE_PRIVATE);}return utils;}publicvoidput(finalString key,finalString value){
        mSharedPreferences.edit().putString(key, value).apply();}publicStringget(finalString key){return mSharedPreferences.getString(key,"");}publicvoidremove(finalString key){
        mSharedPreferences.edit().remove(key).apply();}}

总结

以上就是今天讲的内容,本文仅仅简单介绍了Android日记APP,需要掌握上述知识点,能够较好的理解此应用逻辑。


本文转载自: https://blog.csdn.net/m0_49534667/article/details/128087389
版权归原作者 勤奋的oyoung 所有, 如有侵权,请联系我们删除。

“Android studio课程设计开发实现---日记APP”的评论:

还没有评论