ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

基于NotePad应用做功能扩展

2021-12-11 18:32:00  阅读:146  来源: 互联网

标签:case 基于 COLOR NotePad Notes 扩展 break new


基于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

源码地址:源码

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

标签:case,基于,COLOR,NotePad,Notes,扩展,break,new
来源: https://blog.csdn.net/chen_qm/article/details/121877176

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有