系统概述
结合本学期课程所学的关于Android通知的知识以及期中期末作业的记事本软件应用开发,我在之前就有想法做一个将两者结合的应用即备忘录,既能记事又能提醒。
具体定义为:具有备忘录的基本功能,支持备忘事项的创建,同时提供定时提醒功能(在指定的时间到达前在通知栏上弹出相应的通知来提醒用户)。
系统总体设计
其中,删除用长按ListView实现,添加由点击按钮实现,编辑由点击ListView实现。闹钟提醒由广播通知实现。
系统设计与实现部分
关键代码及说明
①构造xml文件,使用ReclcyerView控件实现备忘录的列表显示,通过CardView控件实现备忘录的卡片式显示,以及添加FloatingActionButton控件进行添加活动的跳转。TextView和ImageView实现细节展示。
(1)activity_main.xml(部分代码)
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="670dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="14dp"
android:src="@drawable/ic_add"
app:backgroundTint="#FF2229" />
(2)activity_edit.xml(部分代码)
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="275dp"
android:layout_height="122dp"
android:layout_weight="5"
android:orientation="vertical">
<LinearLayout
android:layout_width="289dp"
android:layout_height="59dp"
android:orientation="horizontal">
<TextView
android:id="@+id/dateText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="现在是2020/1/1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25sp" />
<TextView
android:id="@+id/timeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="00:00"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="25sp" />
</LinearLayout>
<TextView
android:id="@+id/alarmView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="提醒时间:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="25sp" />
</LinearLayout>
<ImageButton
android:id="@+id/alarmButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/alarm"
android:onClick="setAlarm" />
</LinearLayout>
(3)note_card.xml(部分代码)
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="22dp"
android:layout_gravity="center_horizontal"
android:padding="0dp"
android:layout_margin="0dp"
android:baselineAligned="false"
android:layout_marginBottom="1dp">
<TextView
android:id="@+id/textDate"
android:layout_width="118dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="left|center_vertical"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#908d8d"
android:textSize="16sp"
android:typeface="sans" />
<Space
android:layout_width="5dp"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textTime"
android:layout_width="105dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="left|center_vertical"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#908d8d"
android:textSize="16sp"
android:typeface="sans" />
<Space
android:layout_width="224dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageView
android:id="@+id/alarm"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="0"
android:src="@drawable/alarm" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="58dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/mainText"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:textSize="16sp"
android:typeface="sans"
android:maxLines="2"
android:ellipsize="end"
android:lineSpacingMultiplier="1.2"/>
</LinearLayout>
</LinearLayout>
②编写Note.java,创建备忘录的实体类,通过get和set方法获取和传入对应属性值。
public class Note {
private int id;
private int num;//列表中的位置
private String textDate;
private String textTime;
private String alarm;
private String mainText;
public Note(){
}
public Note(int num, int tag, String textDate, String textTime, String alarm