1、项目需求分析
1.1、记事功能需求分析:
1.1.1、显示记事
用户打开记事本可以看到之前所写的所有记事内容,进入主页后,软件应该从数据库中搜索出该用户所写的全部记事,并将所有的数据进行显示。
1.1.2、添加记事
设置添加按钮,点击添加按钮之后可以编辑记事的标题和内容。
1.1.3、编辑记事
在主界面的记事列表中,点击一条记事,能够进行编辑,包括更改记事和删除记事。
1.1.4、查询记事
在主界面中设置查询功能,使用户可以通过对标题进行模糊查询。
1.2、账户管理
为了保护用户的隐私,在使用记事本时首先需要进行用户的登录,在登录账号之后才可以使用记事本的功能。
1.2.1、注册账号
使用记事本功能首先需要进行用户的注册,在注册过程中应注意用户名以及密码的正确输入才可注册成功。
1.2.2、登录
登录时需要对账号以及密码进行检测,如果账号密码正确即可进入记事本页面,使用记事本功能。
1.3、数据库需求分析
在该项目中使用了两个数据库表,分别为存储用户信息的users表以及存储记事本内容的note表。
1.4、界面需求分析
在该项目中,一个有六个页面,分别是用户界面activity_user、注册页面activity_register、记事本主页面activity_main、添加页面activity_add、编辑页面activity_edit、删除页面List_item_dialog。
总体布局以及背景色调使用简约风格。
2、项目的设计
2.1、注册功能
图 1 注册功能
2.2、登录功能
图 2 登录功能
2.3、记事功能
图 3 记事功能
3、关键的代码
3.1、页面代码(部分)
3.1.1、用户界面activity_user.xml
<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"
tools:context=".MainActivity"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="@string/app_name">
</androidx.appcompat.widget.Toolbar>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="40dp"
android:gravity="center_vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号:"
android:textSize="25sp"
/>
<EditText
android:id="@+id/et_account"
android:layout_width="match_parent"
android:hint="请输入用户名或手机号"
android:layout_marginLeft="10dp"
style="@style/MyEditStyle"
android:inputType="text"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:gravity="center_vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码:"
android:textSize="25sp"
/>
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="请输入密码"
android:textSize="18sp"
android:layout_marginLeft="10dp"
android:paddingLeft="5dp"
android:inputType="numberPassword"
android:background="@drawable/edit_text_bg"
/>
</L