Android studio课程计划开辟实现---日记APP

打印 上一主题 下一主题

主题 547|帖子 547|积分 1641

Android studio课程计划开辟实现—日记APP



  

前言

你们好,我是oy,介绍一个浅易日记APP。
一、结果

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

2.日记相关功能

3.个人中心界面

二、功能介绍

1.重要功能


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


2.涉及知识点


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


三、实现思路


  • MainActivity中使用BottomNavigationView、ViewPager2、Toolbar实现。
  1. public class MainActivity extends AppCompatActivity {
  2.     private BottomNavigationView bottomNavigationView;
  3.     @Override
  4.     protected void onCreate(Bundle savedInstanceState) {
  5.         super.onCreate(savedInstanceState);
  6.         setContentView(R.layout.activity_main);
  7.         initToolbar();
  8.         initFragment();
  9.         initNavigationBottom();
  10.     }
  11.     @SuppressLint("ResourceAsColor")
  12.     private void initNavigationBottom() {
  13.         bottomNavigationView = findViewById(R.id.navigation_bottom);
  14.         bottomNavigationView.setItemIconTintList(null);
  15.         bottomNavigationView.setOnNavigationItemSelectedListener(itemSelectedListener);
  16.     }
  17.     @Override
  18.     public boolean onCreateOptionsMenu(Menu menu) {
  19.         return super.onCreateOptionsMenu(menu);
  20.     }
  21.     private void initFragment() {
  22.         DiariesFragment diariesFragment = getDiariesFragment();
  23.         if (diariesFragment == null) {
  24.             diariesFragment = new DiariesFragment();
  25.             ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), diariesFragment, R.id.content);
  26.         }
  27.     }
  28.     private DiariesFragment getDiariesFragment() {
  29.         return (DiariesFragment) getSupportFragmentManager().findFragmentById(R.id.content);
  30.     }
  31.     private void initToolbar() {
  32.         //设置顶部状态栏为透明
  33.         getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  34.         Toolbar toolbar = findViewById(R.id.toolbar);
  35.         setSupportActionBar(toolbar);
  36.     }
  37.     private final BottomNavigationView.OnNavigationItemSelectedListener itemSelectedListener = item -> {
  38.         switch (item.getItemId()) {
  39.             case R.id.menu_diary:
  40.                 MeController.setToolbarVisibility(this);
  41.                 ActivityUtils.removeFragmentTOActivity(getSupportFragmentManager(), getSupportFragmentManager().findFragmentById(R.id.content));
  42.                 ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), new DiariesFragment(), R.id.content);
  43.                 break;
  44.             case R.id.menu_me:
  45.                 findViewById(R.id.toolbar).setVisibility(View.GONE);
  46.                 ActivityUtils.removeFragmentTOActivity(getSupportFragmentManager(), getSupportFragmentManager().findFragmentById(R.id.content));
  47.                 ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), new MeFragment(), R.id.content);
  48.                 break;
  49.             case R.id.menu_new:
  50.                 bottomNavigationView.setVisibility(View.GONE);
  51.                 MeController.setToolbarVisibility(this);
  52.                 ActivityUtils.removeFragmentTOActivity(getSupportFragmentManager(), getSupportFragmentManager().findFragmentById(R.id.content));
  53.                 ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), new AddDiaryFragment(), R.id.content);
  54.                 break;
  55.         }
  56.         return true;
  57.     };
  58. }
复制代码
MainActivity的layout
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:app="http://schemas.android.com/apk/res-auto"
  5.     xmlns:tools="http://schemas.android.com/tools"
  6.     android:layout_width="match_parent"
  7.     android:layout_height="match_parent"
  8.     android:orientation="vertical"
  9.     tools:context=".MainActivity">
  10.     <com.google.android.material.appbar.AppBarLayout
  11.         android:layout_width="match_parent"
  12.         android:layout_height="wrap_content">
  13.         <androidx.appcompat.widget.Toolbar
  14.             android:id="@+id/toolbar"
  15.             android:layout_width="match_parent"
  16.             android:layout_height="wrap_content"
  17.             android:background="?attr/colorPrimary"
  18.             android:minHeight="?attr/actionBarSize"
  19.             android:fitsSystemWindows="true"
  20.             android:theme="@style/Widget.AppCompat.Toolbar"
  21.             app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
  22.     </com.google.android.material.appbar.AppBarLayout>
  23.     <FrameLayout
  24.         android:id="@+id/content"
  25.         android:layout_width="match_parent"
  26.         android:layout_height="0dp"
  27.         android:layout_weight="1"/>
  28.     <com.google.android.material.bottomnavigation.BottomNavigationView
  29.         android:id="@+id/navigation_bottom"
  30.         android:layout_width="match_parent"
  31.         android:layout_height="wrap_content"
  32.         app:menu="@menu/menu_navigation"
  33.         android:background="?android:attr/windowBackground"/>
  34. </LinearLayout>
复制代码

  • ViewPager2中切换不同fragment,对应导航栏新增日记、个人中心及日记列表。
  1. public class DiariesFragment extends Fragment {
  2.     private DiariesController mController;
  3.     @Override
  4.     public void onCreate(@Nullable Bundle savedInstanceState) {
  5.         super.onCreate(savedInstanceState);
  6.         mController = new DiariesController(this);
  7.     }
  8.    
  9.     @Nullable
  10.     @Override
  11.     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  12.         View root = inflater.inflate(R.layout.fragment_diaries, container, false);
  13.         mController.setDiariesList(root.findViewById(R.id.diaries_list));
  14.         return root;
  15.     }
  16.     @Override
  17.     public void onResume() {
  18.         super.onResume();
  19.         mController.loadDiaries();
  20.     }
  21. }
复制代码
DiariesFragment的layout
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="match_parent" android:layout_height="match_parent"
  4.     android:orientation="vertical">
  5.     <androidx.recyclerview.widget.RecyclerView
  6.         android:id="@+id/diaries_list"
  7.         android:layout_width="match_parent"
  8.         android:layout_height="wrap_content"/>
  9. </RelativeLayout>
复制代码
  1. public class AddDiaryFragment extends Fragment implements View.OnClickListener {
  2.     private AddDiaryController mController;
  3.     private View edit_layout;
  4.     private Button btn_confirm;
  5.     private EditText edit_title;
  6.     private EditText edit_desc;
  7.     @Override
  8.     public void onCreate(@Nullable Bundle savedInstanceState) {
  9.         super.onCreate(savedInstanceState);
  10.         mController = new AddDiaryController(this);
  11.     }
  12.     private void initView(View view) {
  13.         btn_confirm = view.findViewById(R.id.add_diary_confirm);
  14.         btn_confirm.setOnClickListener(this);
  15.         edit_title = view.findViewById(R.id.edit_add_title);
  16.         edit_desc = view.findViewById(R.id.edit_add_desc);
  17.         edit_layout = view.findViewById(R.id.edit_layout);
  18.         edit_layout.setOnClickListener(this);
  19.     }
  20.     @Override
  21.     public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
  22.         inflater.inflate(R.menu.menu_cancel, menu);
  23.     }
  24.     @Override
  25.     public boolean onOptionsItemSelected(@NonNull MenuItem item) {
  26.         switch (item.getItemId()) {
  27.             case R.id.menu_cancel:
  28.                 mController.closeWriteDiary(getActivity().getSupportFragmentManager(), this);
  29.                 mController.setNavigationVisibility();
  30.                 return true;
  31.         }
  32.         return false;
  33.     }
  34.     @Nullable
  35.     @Override
  36.     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  37.         View root = inflater.inflate(R.layout.fragment_add_diary, container, false);
  38.         initView(root);
  39.         return root;
  40.     }
  41.     @Override
  42.     public void onDestroy() {
  43.         super.onDestroy();
  44.     }
  45.     @Override
  46.     public void onClick(View view) {
  47.         switch (view.getId()) {
  48.             case R.id.add_diary_confirm:
  49.                 mController.addDiaryToRepository(edit_title.getText().toString().trim(), edit_desc.getText().toString().trim());
  50.                 mController.setNavigationVisibility();
  51.                 mController.closeWriteDiary(getActivity().getSupportFragmentManager(), this);
  52.                 break;
  53.             case R.id.edit_layout:
  54.                 mController.changeFocus(edit_desc);
  55.                 break;
  56.         }
  57.     }
  58. }
复制代码
AddDiaryFragment的layout
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:layout_width="match_parent"
  5.     android:layout_height="match_parent"
  6.     android:orientation="vertical">
  7.     <LinearLayout
  8.         android:layout_width="match_parent"
  9.         android:layout_height="wrap_content"
  10.         android:layout_marginTop="10dp"
  11.         android:layout_marginStart="10dp"
  12.         android:layout_marginEnd="10dp"
  13.         android:orientation="vertical">
  14.         <EditText
  15.             android:id="@+id/edit_add_title"
  16.             android:hint="@string/add_title_hint"
  17.             android:minLines="1"
  18.             android:layout_width="match_parent"
  19.             android:layout_height="wrap_content" />
  20.     </LinearLayout>
  21.     <LinearLayout
  22.         android:id="@+id/edit_layout"
  23.         android:layout_width="match_parent"
  24.         android:layout_height="0dp"
  25.         android:layout_weight="1"
  26.         android:layout_marginTop="5dp"
  27.         android:layout_marginStart="10dp"
  28.         android:layout_marginEnd="10dp"
  29.         android:layout_marginBottom="10dp">
  30.         <LinearLayout
  31.             android:layout_width="match_parent"
  32.             android:layout_height="match_parent"
  33.             android:paddingStart="5dp"
  34.             android:paddingTop="5dp"
  35.             android:paddingEnd="5dp"
  36.             android:paddingBottom="5dp"
  37.             android:background="@drawable/edit_background">
  38.             <EditText
  39.                 android:id="@+id/edit_add_desc"
  40.                 android:hint="@string/add_title_description"
  41.                 android:gravity="top"
  42.                 android:layout_width="match_parent"
  43.                 android:layout_height="wrap_content"
  44.                 android:scrollbars="vertical"
  45.                 android:background="@null"/>
  46.         </LinearLayout>
  47.     </LinearLayout>
  48.     <LinearLayout
  49.         android:layout_width="match_parent"
  50.         android:layout_height="wrap_content"
  51.         android:gravity="center"
  52.         android:orientation="horizontal">
  53.         <Button
  54.             android:id="@+id/add_diary_confirm"
  55.             android:text="@string/btn_ok"
  56.             android:layout_width="wrap_content"
  57.             android:layout_height="wrap_content"/>
  58.     </LinearLayout>
  59. </LinearLayout>
复制代码

  • 将应用暗码加密生存与文件中。每次登岸获取暗码并对比。
  1. public class LoginDirectActivity extends AppCompatActivity implements View.OnClickListener {
  2.     private EditText edit_input_text;
  3.     private Button btn_comeIn;
  4.     private TextView tv_setPsw;
  5.     private static final String TAG = "Login2Activity";
  6.     @Override
  7.     protected void onCreate(Bundle savedInstanceState) {
  8.         super.onCreate(savedInstanceState);
  9.         setContentView(R.layout.activity_direct_login);
  10.         bindView();
  11.     }
  12.     private void bindView() {
  13.         getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  14.         edit_input_text = findViewById(R.id.edit_login2_input_text);
  15.         btn_comeIn = findViewById(R.id.btn_login2_comeIn);
  16.         btn_comeIn.setOnClickListener(this);
  17.         tv_setPsw = findViewById(R.id.tv_setPsw);
  18.         tv_setPsw.setOnClickListener(this);
  19.     }
  20.     @Override
  21.     public void onClick(View v) {
  22.         switch (v.getId()) {
  23.             case R.id.tv_setPsw:
  24.                 Intent setPsw_intent = new Intent(LoginDirectActivity.this, LoginActivity.class);
  25.                 startActivity(setPsw_intent);
  26.                 LoginDirectActivity.this.finish();
  27. //                overridePendingTransition(R.anim.out_to_left,R.anim.in_from_right);
  28.                 break;
  29.             case R.id.btn_login2_comeIn:
  30.                 String psw = edit_input_text.getText().toString().trim();
  31.                 if (psw.isEmpty()) {
  32.                     Toast.makeText(this, "密码不能为空!", Toast.LENGTH_SHORT).show();
  33.                     return;
  34.                 }
  35.                 String readInfoByContext = FileUtils.readInfoByContext(this);
  36.                 if (psw.equals(readInfoByContext)) {
  37.                     Toast.makeText(this, "登录成功!", Toast.LENGTH_SHORT).show();
  38.                     Intent intent = new Intent(this, MainActivity.class);
  39.                     startActivity(intent);
  40. //                    overridePendingTransition(R.anim.out_to_left,R.anim.in_from_right);
  41.                 } else {
  42.                     Toast.makeText(this, "密码不正确!", Toast.LENGTH_SHORT).show();
  43.                 }
  44.                 break;
  45.         }
  46.     }
  47. }
复制代码
LoginDirectActivity 的layout
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".view.LoginDirectActivity">
  8.     <Button
  9.         android:id="@+id/btn_login2_comeIn"
  10.         android:layout_width="match_parent"
  11.         android:layout_height="wrap_content"
  12.         android:layout_marginStart="40dp"
  13.         android:layout_marginEnd="40dp"
  14.         android:text="进入"
  15.         app:layout_constraintBottom_toTopOf="@+id/guideline5"
  16.         app:layout_constraintEnd_toEndOf="parent"
  17.         app:layout_constraintStart_toStartOf="parent" />
  18.     <LinearLayout
  19.         android:id="@+id/linearLayout"
  20.         android:layout_width="match_parent"
  21.         android:layout_height="wrap_content"
  22.         android:layout_marginStart="40dp"
  23.         android:layout_marginEnd="40dp"
  24.         android:gravity="center_vertical"
  25.         android:orientation="horizontal"
  26.         app:layout_constraintEnd_toEndOf="parent"
  27.         app:layout_constraintStart_toStartOf="parent"
  28.         app:layout_constraintTop_toTopOf="@+id/guideline7">
  29.         <ImageView
  30.             android:layout_width="32dp"
  31.             android:layout_height="32dp"
  32.             android:src="@mipmap/come_in_key" />
  33.         <EditText
  34.             android:id="@+id/edit_login2_input_text"
  35.             android:hint="输入您的密码"
  36.             android:inputType="textPassword"
  37.             android:layout_width="match_parent"
  38.             android:layout_height="wrap_content" />
  39.     </LinearLayout>
  40.     <androidx.constraintlayout.widget.Guideline
  41.         android:id="@+id/guideline4"
  42.         android:layout_width="wrap_content"
  43.         android:layout_height="wrap_content"
  44.         android:orientation="horizontal"
  45.         app:layout_constraintGuide_percent="0.22" />
  46.     <androidx.constraintlayout.widget.Guideline
  47.         android:id="@+id/guideline5"
  48.         android:layout_width="wrap_content"
  49.         android:layout_height="wrap_content"
  50.         android:orientation="horizontal"
  51.         app:layout_constraintGuide_percent="0.58" />
  52.     <TextView
  53.         android:id="@+id/tv_login2_password_title"
  54.         android:layout_width="match_parent"
  55.         android:layout_height="wrap_content"
  56.         android:gravity="center"
  57.         android:text="输入密码"
  58.         android:textSize="30sp"
  59.         android:textStyle="bold"
  60.         app:layout_constraintEnd_toEndOf="parent"
  61.         app:layout_constraintStart_toStartOf="parent"
  62.         app:layout_constraintTop_toTopOf="@+id/guideline4" />
  63.     <androidx.constraintlayout.widget.Guideline
  64.         android:id="@+id/guideline7"
  65.         android:layout_width="wrap_content"
  66.         android:layout_height="wrap_content"
  67.         android:orientation="horizontal"
  68.         app:layout_constraintGuide_percent="0.4" />
  69.     <TextView
  70.         android:id="@+id/tv_setPsw"
  71.         android:layout_width="wrap_content"
  72.         android:layout_height="wrap_content"
  73.         android:text="设置密码"
  74.         android:textStyle="bold"
  75.         app:layout_constraintEnd_toEndOf="@+id/linearLayout"
  76.         app:layout_constraintTop_toBottomOf="@+id/linearLayout" />
  77. </androidx.constraintlayout.widget.ConstraintLayout>
复制代码

  • 使用SharedPrefrenced存储日记内容及标题。
  1. public final class SharedPreferencesUtils {
  2.     private static final SimpleArrayMap<String, SharedPreferencesUtils> mCaches = new SimpleArrayMap<>();
  3.     private SharedPreferences mSharedPreferences;
  4.     private SharedPreferencesUtils(final String spName, final int mode) {
  5.         mSharedPreferences = YyApplication.get().getSharedPreferences(spName, mode);
  6.     }
  7.     public static SharedPreferencesUtils getInstance(String spName) {
  8.         SharedPreferencesUtils utils = mCaches.get(spName);
  9.         if (utils == null) {
  10.             utils = new SharedPreferencesUtils(spName, Context.MODE_PRIVATE);
  11.         }
  12.         return utils;
  13.     }
  14.     public void put(final String key, final String value) {
  15.         mSharedPreferences.edit().putString(key, value).apply();
  16.     }
  17.     public String get(final String key) {
  18.         return mSharedPreferences.getString(key, "");
  19.     }
  20.     public void remove(final String key) {
  21.         mSharedPreferences.edit().remove(key).apply();
  22.     }
  23. }
复制代码
下载链接

源码下载:https://pan.baidu.com/s/1bzSSuPrtlq1m5UG29TWvoQ
提取码:1111 (好像不需要)
总结

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

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

杀鸡焉用牛刀

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表