基于NotePad应用做功能扩展

基于NotePad应用做功能扩展

#写在前面,解决图片不能查看问题

因为有 墙 的存在,DNS污染了,存在不能查看GitHub上图片问题
​​在这里插入图片描述

配置hosts文件,直接指向github的服务器。用ipaddress查一下GitHub: Where the world builds software · GitHub 的ip
在这里插入图片描述
hosts文件win10目录:C:\Windows\System32\drivers\etc
在这里插入图片描述
在文件尾部添加:

185.199.108.133 raw.githubusercontent.com
185.199.109.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.111.133 raw.githubusercontent.com
185.199.108.133 githubusercontent.com
185.199.109.133 githubusercontent.com
185.199.110.133 githubusercontent.com
185.199.111.133 githubusercontent.com

在这里插入图片描述
保存,关闭,重新加载网页即可

NotePad

This is an AndroidStudio rebuild of google SDK sample NotePad

新增类,修改类(部分代码展示)

在这里插入图片描述

• MyCursorAdapter.java

    public void bindView(View view, Context context, Cursor cursor){
    super.bindView(view, context, cursor);
    //从数据库中读取的cursor中获取笔记列表对应的颜色数据,并设置笔记颜色
    int x =               
   cursor.getInt(cursor.getColumnIndex(NotePad.Notes.COLUMN_NAME_BACK_COLOR));
    switch (x){
        case NotePad.Notes.DEFAULT_COLOR:
            view.setBackgroundColor(Color.rgb(255, 255, 255));
            break;
        case NotePad.Notes.YELLOW_COLOR:
            view.setBackgroundColor(Color.rgb(247, 216, 133));
            break;
        case NotePad.Notes.BLUE_COLOR:
            view.setBackgroundColor(Color.rgb(165, 202, 237));
            break;
        case NotePad.Notes.GREEN_COLOR:
            view.setBackgroundColor(Color.rgb(161, 214, 174));
            break;
        case NotePad.Notes.RED_COLOR:
            view.setBackgroundColor(Color.rgb(244, 149, 133));
            break;
        default:
            view.setBackgroundColor(Color.rgb(255, 255, 255));
            break;
    }
}

• NoteSearch.java

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.note_search_list);
    Intent intent = getIntent();
    if (intent.getData() == null) {
        intent.setData(NotePad.Notes.CONTENT_URI);
    }
    SearchView searchview = (SearchView)findViewById(R.id.search_view);
    searchview.setOnQueryTextListener(NoteSearch.this);  //为查询文本框注册监听器
}

• OutputText.java

    private void write()
{
    try
    {
        // 如果手机插入了SD卡,而且应用程序具有访问SD的权限
        if (Environment.getExternalStorageState().equals(
                Environment.MEDIA_MOUNTED)) {
            // 获取SD卡的目录
            File sdCardDir = Environment.getExternalStorageDirectory();
            //创建文件目录
            File targetFile = new File(sdCardDir.getCanonicalPath() + "/" + mName.getText() + ".txt");
            //写文件
            PrintWriter ps = new PrintWriter(new OutputStreamWriter(new FileOutputStream(targetFile), "UTF-8"));
            ps.println(TITLE);
            ps.println(NOTE);
            ps.println("创建时间:" + CREATE_DATE);
            ps.println("最后一次修改时间:" + MODIFICATION_DATE);
            ps.close();
            Toast.makeText(this, "保存成功,保存位置:" + sdCardDir.getCanonicalPath() + "/" + mName.getText() + ".txt", Toast.LENGTH_LONG).show();
        }
    }

• NoteEditor.java
设置颜色

switch (x){
            case NotePad.Notes.DEFAULT_COLOR:
                mText.setBackgroundColor(Color.rgb(255, 255, 255));
                break;
            case NotePad.Notes.YELLOW_COLOR:
                mText.setBackgroundColor(Color.rgb(247, 216, 133));
                break;
            case NotePad.Notes.BLUE_COLOR:
                mText.setBackgroundColor(Color.rgb(165, 202, 237));
                break;
            case NotePad.Notes.GREEN_COLOR:
                mText.setBackgroundColor(Color.rgb(161, 214, 174));
                break;
            case NotePad.Notes.RED_COLOR:
                mText.setBackgroundColor(Color.rgb(244, 149, 133));
                break;
            default:
                mText.setBackgroundColor(Color.rgb(255, 255, 255));
                break;
        }

• NotePad.java
设置颜色

    public static final int DEFAULT_COLOR = 0; //白
    public static final int YELLOW_COLOR = 1;//黄
    public static final int BLUE_COLOR = 2;//蓝
    public static final int GREEN_COLOR = 3;//绿
    public static final int RED_COLOR = 4;//红

• NotesList.java
设置搜索,排序

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_add:
      /*
       * Launches a new Activity using an Intent. The intent filter for the Activity
       * has to have action ACTION_INSERT. No category is set, so DEFAULT is assumed.
       * In effect, this starts the NoteEditor Activity in NotePad.
       */
            startActivity(new Intent(Intent.ACTION_INSERT, getIntent().getData()));
            return true;
        case R.id.menu_paste:
      /*
       * Launches a new Activity using an Intent. The intent filter for the Activity
       * has to have action ACTION_PASTE. No category is set, so DEFAULT is assumed.
       * In effect, this starts the NoteEditor Activity in NotePad.
       */
            startActivity(new Intent(Intent.ACTION_PASTE, getIntent().getData()));
            return true;
        //添加搜素
        case R.id.menu_search:
            Intent intent = new Intent();
            intent.setClass(NotesList.this,NoteSearch.class);
            NotesList.this.startActivity(intent);
            return true;

        //创建时间排序
        case R.id.menu_sort1:
            cursor = managedQuery(
                    getIntent().getData(),            // Use the default content URI for the provider.
                    PROJECTION,                       // Return the note ID and title for each note. and modifcation date
                    null,                             // No where clause, return all records.
                    null,                             // No where clause, therefore no where column values.
                    NotePad.Notes._ID  // Use the default sort order.
            );
            adapter = new MyCursorAdapter(
                    this,
                    R.layout.noteslist_item,
                    cursor,
                    dataColumns,
                    viewIDs
            );
            setListAdapter(adapter);
            return true;

        //修改时间排序
        case R.id.menu_sort2:
            cursor = managedQuery(
                    getIntent().getData(),            // Use the default content URI for the provider.
                    PROJECTION,                       // Return the note ID and title for each note. and modifcation date
                    null,                             // No where clause, return all records.
                    null,                             // No where clause, therefore no where column values.
                    NotePad.Notes.DEFAULT_SORT_ORDER // Use the default sort order.
            );

            adapter = new MyCursorAdapter(
                    this,
                    R.layout.noteslist_item,
                    cursor,
                    dataColumns,
                    viewIDs
            );
            setListAdapter(adapter);
            return true;

        //颜色排序
        case R.id.menu_sort3:
            cursor = managedQuery(
                    getIntent().getData(),            // Use the default content URI for the provider.
                    PROJECTION,                       // Return the note ID and title for each note. and modifcation date
                    null,                             // No where clause, return all records.
                    null,                             // No where clause, therefore no where column values.
                    NotePad.Notes.COLUMN_NAME_BACK_COLOR // Use the default sort order.
            );
            adapter = new MyCursorAdapter(
                    this,
                    R.layout.noteslist_item,
                    cursor,
                    dataColumns,
                    viewIDs
            );
            setListAdapter(adapter);
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}

新建布局,修改布局

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7MJisHpw-1639216778159)(https://raw.githubusercontent.com/cqm123456/NotePad/master/images/Newlayout.jpg)]

• note_color.xml
举例

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-O7fKtFfW-1639216778160)()]

• note_srarch_list.xml

<ImageButton
    android:id="@+id/color_white"
    android:layout_width="0dp"
    android:layout_height="50dp"
    android:layout_weight="1"
    android:background="@color/colorWhite"
    android:onClick="white"/>

<ImageButton
    android:id="@+id/color_yellow"
    android:layout_width="0dp"
    android:layout_height="50dp"
    android:layout_weight="1"
    android:background="@color/colorYellow"
    android:onClick="yellow"/>

<ImageButton
    android:id="@+id/color_blue"
    android:layout_width="0dp"
    android:layout_height="50dp"
    android:layout_weight="1"
    android:background="@color/colorBlue"
    android:onClick="blue"/>

<ImageButton
    android:id="@+id/color_green"
    android:layout_width="0dp"
    android:layout_height="50dp"
    android:layout_weight="1"
    android:background="@color/colorGreen"
    android:onClick="green"/>

<ImageButton
    android:id="@+id/color_red"
    android:layout_width="0dp"
    android:layout_height="50dp"
    android:layout_weight="1"
    android:background="@color/colorRed"
    android:onClick="red"/>

Image text

• output_text.xml

<EditText android:id="@+id/output_name"
    android:maxLines="1"
    android:layout_marginTop="2dp"
    android:layout_marginBottom="15dp"
    android:layout_width="wrap_content"
    android:ems="25"
    android:layout_height="wrap_content"
    android:autoText="true"
    android:capitalize="sentences"
    android:scrollHorizontally="true" />

<Button android:id="@+id/output_ok"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:text="@string/output_ok"
    android:onClick="OutputOk" />

在这里插入图片描述

• colors.xml

Image text

页面布局

Image text

基本要求:

• NoteList中显示条目增加时间戳显示

在这里插入图片描述

• 添加笔记查询功能(根据标题查询)
默认title为输入内容,可自行更改,但查询是按照title查询,若title与笔记内容则笔记内容便无法查询到

在这里插入图片描述

Image text

在这里插入图片描述

附加功能:

• UI美化
我的排版参考PPT中的UI美化,将功能按键安排在上方

Image text

• 更改记事本的背景
需要在笔记中设置,在笔记初始展示页以带背景颜色的横条表示

在这里插入图片描述

在这里插入图片描述

• 导出笔记

Image text

Image text

• 笔记排序
可以根据创建时间、修改时间和颜色进行排序

Image text

Image text

源码地址:源码

作者:陈巧蔓
原文链接:原文

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值