Android:实现安卓小程序-记事本(备忘录)的开发

这篇博客详细记录了Android环境下记事本应用的开发过程,包括记事本的基本设计、数据存储、主界面设计、编辑功能、背景色设置、闹钟功能和高级搜索等。开发者采用文件存储而非SQLite,实现了浮动菜单、滑动删除、自定义Adapter等功能,并引入了动态搜索框第三方库。通过这个项目,作者提升了对Intent、Adapter等技术的掌握,也学习了程序UI美化和数据存储的新知识。
摘要由CSDN通过智能技术生成

目录

1. 前言

2. 记事本功能需求

3. 部分关键代码解析及程序截图

3.1 记事本类的基本设计

3.2 记事本的数据存储设计

3.3 主界面的设计

3.4 记事本的编辑

3.5 记事本的背景色设置

3.6 记事本的闹铃功能

3.7 高级搜索

4. 总结


1. 前言

在学习安卓开发这门课程中期,学会了安卓开发的基本知识,比如,UI组件的应用,Intent的应用等等,同时期中作业为编写一个记事本程序,基于google的记事本demo, 但对于我本人来说,我更喜欢对代码从头到位都有自己的参与,于是我决定自己从头编写一个基本记事本的开发和记事本的相关扩展功能。

开发环境: Android Studio (API25以上)

2. 记事本功能需求

功能名称 功能概述 优先级
记事本基本功能 对记事本的增删改 最高
时间戳显示 记事本的最近编辑时间的显示
高级搜索 对记事本的查找
UI美化 对用户界面的美化
记事本背景色的设置 记事本背景色的设置
记事本闹钟设置 记事本的闹钟功能设置

 

 

 

 

 

 

 

3. 部分关键代码解析及程序截图

3.1 记事本类的基本设计

Note.java

//序列化便于本地存储
public class Note  implements Serializable,Comparable{

    private String title;
    private String create_date;
    private String update_date;
    private String text;
    private String background;
    private String date_alarm;
    public Note(String title,String text) {
        //标题
        this.title = title;
        //创建日期
        this.create_date = new SimpleDateFormat("yyyy-MM-dd HH-mm").format(new Date());
        //更新日期
        this.update_date = this.create_date;
        //内容
        this.text = text;
        //背景色
        this.background = null;
        //闹钟日期
        this.date_alarm = "";
    }
}

3.2 记事本的数据存储设计

这里由于我当时暂未学习到SQLite的数据存储方式,采用了文件读写的方式来存储记事本的条目。

首先,在AndroidManifest.xml中设置允许程序读写文件的权限。

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.VIBRATE" />

将Note存储在哈希表内,再将哈希表的内容写入文件中,同时文件存储在内置的SD卡的路径下。

NoteManager.java

public class NoteManager {

    private Context mContext;
    private List<Note> list;
    private String root_file;
    public NoteManager(Context context){
        root_file = Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"NoteList";
        this.mContext = context;
        list = getNoteList();
    }
    
    //更新当前notes列表
    public void updateNoteList(List<Note> now_data){
        try {
            File file = new File(root_file);
            if (!file.exists()){
                file.createNewFile();
            }
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(root_file));
            oos.writeObject(now_data);
            oos.close();
        }
        catch (Exception e1){
            e1.printStackTrace();
        }
    }
}

3.3 主界面的设计

为了更好的用户体验,决定将用户设计设计成两种情况,一种为用户程序中暂无存储记事文件的情况下,一种为程序中已存有记事文件下。附上部分关键代码以及程序截图。

主界面-1 主界面-2
//检查数据列表是否为空,如果为空,那么渲染blank_View
    public void emptyListCheck(){
        int number = 0;
        if(data!=null){
            number=data.size();
        }
        if(number == 0) {
            smlvMain.setVisibility(View.GONE);
            RelativeLayout empty = (RelativeLayout) findViewById(R.id.blank_view);
            empty.setVisibility(View.VISIBLE);
            fabMenu.setVisibility(View.VISIBLE);
        }else{
            smlvMain.setVisibility(View.VISIBLE);
            RelativeLayout empty = (RelativeLayout) findViewById(R.id.blank_view);
            empty.setVisibility(View.GONE);
        }
    }

这里设置了Note条目的菜单模块和空白模块,若数据列表为空,则隐藏条目菜单模块,显示空白模块,若不为空,则隐藏空白模块,显示菜单模块。

3.4 记事本的编辑

可以看到在主界面的右下角存在一个浮动窗口菜单,这里涉及到第三方依赖的添加:

com.getbase.floatingactionbutton.FloatingActionButton

res/layout/activity_main.xml

<com.getbase.floatingactionbutton.FloatingActionsMenu
            adroid:id="@+id/fab_menu"
            adroid:layout_width="wrap_content"
            adroid:layout_height="wrap_content"
            adroid:layout_alignParentRight="true"
            adroid:layout_alignParentBottom="true"
            fab:fab_labelStyle="@style/fab_label_style"
            app:fab_addButtonSize="mini"
            fab:fab_addButtonColorNormal="#5e96b9"
            fab:fab_addButtonColorPressed="@null"
            fab:fab_addButtonPlusIconColor="@color/black"
            adroid:layout_marginBottom="16dp"
            adroid:layout_marginRight="16dp">

            <com.getbase.floatingactionbutton.FloatingActionButton
                adroid:id="@+id/fab_add"
                adroid:layout_width="wrap_content"
                adroid:layout_height="wrap_content"
                fab:fab_colorNormal="@color/white"
                fab:fab_colorPressed="@color/green"
                fab:fab_title="新备忘录"
                fab:fab_size="mini"
                fab:fab_icon="@drawable/fab_add" />
            <com.getbase.floatingactionbutton.FloatingActionButton
                adroid:id="@+id/fab_exit"
                adroid:layout_width="wrap_content"
                adroid:layout_height="wrap_content"
                fab:fab_colorNormal="@color/white"
                fab:fab_colorPressed="@color/green"
                fab:fab_title="退出应用"
                fab:fab_size="mini"
                app:fab_icon="@drawable/fab_exit" />
</com.getbase.floatingactionbutton.FloatingActionsMenu>

这里可以看到对浮动菜单栏的xml设计,包含两种功能,新建Note和应用的退出,涉及到功能的逻辑代码这里就不赘述了。

  • 23
    点赞
  • 296
    收藏
    觉得还不错? 一键收藏
  • 26
    评论
评论 26
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值