当前位置:网站首页>Mobile note application

Mobile note application

2022-07-01 12:33:00 Comeจุ๊

Note application

The functions realized by the memo Application

1、 Add, delete, modify and check the memo Application
2、 Modify the skin of note application , Synchronize the color of the note on the home page

 Insert picture description here

3、 Make a specific display for the time display of the memo Application : The day shows –> today hh:mm , Displayed yesterday --> yesterday hh:mm, This week shows –> What day of the week hh:mm, Otherwise, it will show yyyy/MM/dd

 Insert picture description here

4、 On the edit page of the memo , You can set the reminder time of the memo , Select the date for the first time , Choose the second time

 Insert picture description here
 Insert picture description here

5、 Long press the home page to operate the memo as a whole

 Insert picture description here

6、 You can set the top setting for the memo , Can be set individually , It can also be set in batch

 Insert picture description here

7、 When the notes are all on top , Long press the edited Overhead The button becomes Cancel the top Button

 Insert picture description here

7、 When selecting an un overhead tag , You will be prompted whether to place the label on top , The opposite is true

 Insert picture description here

The overall idea and code of memo application

1、 First, conceive the homepage layout of the memo Application ,

Specific data display uses RecyclerView Show the data , The layout of the home page shows a new button , And it hides the layout after long pressing ( Cancel 、 Future generations 、 Overhead 、 Delete ); And in the layout visibility Set to gone

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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" android:background="@color/background" android:orientation="vertical">

    <Toolbar android:id="@+id/id_note_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/toolbar" android:visibility="gone">

        <Button android:id="@+id/header_cancel" android:layout_width="wrap_content" android:layout_height="40dp" android:layout_gravity="left" android:gravity="center" android:background="@drawable/button_style" android:backgroundTint="@color/toolbar_button" android:text="@string/press_cancel" android:textSize="15sp"/>

        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:textColor="@color/white" android:text="@string/press_edit" android:textSize="20sp"/>

        <Button android:id="@+id/header_selectAll" android:layout_width="wrap_content" android:layout_height="40dp" android:layout_gravity="right" android:background="@drawable/button_style" android:backgroundTint="@color/toolbar_button" android:textColor="@color/white" android:layout_marginRight="20dp" android:text="@string/press_selectAll" android:textSize="15sp"/>

    </Toolbar>

    <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler" android:layout_marginTop="10dp" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1">

    </androidx.recyclerview.widget.RecyclerView>

    <LinearLayout android:id="@+id/id_note_add" android:layout_width="match_parent" android:layout_height="120dp" android:layout_weight="1" android:background="#302424" android:orientation="vertical" android:visibility="visible">

        <ImageView android:id="@+id/add_pic" android:layout_width="20dp" android:layout_height="20dp" android:src="@mipmap/ic_note_add" android:layout_gravity="center" android:layout_weight="1"/>

        <TextView android:id="@+id/add_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:textSize="15sp" android:text="@string/main_add" android:gravity="center" android:textColor="@color/white" android:layout_weight="1"/>

    </LinearLayout>

    <!--  Hide the bottom navigation bar  ==>  Top and delete buttons  -->
    <LinearLayout android:id="@+id/id_note_bottom" android:layout_width="match_parent" android:layout_height="180dp" android:layout_weight="1" android:orientation="horizontal" android:visibility="gone" android:background="@color/purple_200">

        <LinearLayout android:id="@+id/header_top" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:background="@color/toolbar" android:orientation="vertical">

            <ImageView android:layout_width="20dp" android:layout_height="20dp" android:layout_gravity="center" android:src="@mipmap/ic_note_edit_top"/>

            <TextView android:id="@+id/tv_header_top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:textColor="@color/white" android:textSize="15sp" android:paddingTop="5dp" android:text="@string/home_top"/>

        </LinearLayout>

        <TextView android:layout_width="1dp" android:layout_height="match_parent" android:background="#4f4545"/>

        <LinearLayout android:id="@+id/header_delete" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/toolbar" android:gravity="center" android:orientation="vertical">

            <ImageView android:layout_width="20dp" android:layout_height="20dp" android:layout_gravity="center" android:src="@mipmap/ic_note_edit_delete"/>

            <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:textColor="@color/white" android:textSize="15sp" android:paddingTop="5dp" android:text="@string/delete"/>

        </LinearLayout>

    </LinearLayout>


</LinearLayout>

Initial homepage layout :

 Insert picture description here

Hidden homepage layout ( Long press to display ):
 Insert picture description here

2、 For each item The specific layout of , Use RecyclerView Layout display

note_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="5dp">

    <LinearLayout android:id="@+id/lr_list_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:background="@color/menu_theme4">

        <ImageView android:id="@+id/iv_topTab" android:visibility="invisible" android:layout_width="20dp" android:layout_height="20dp" android:src="@mipmap/ic_header_top"/>

        <LinearLayout android:id="@+id/recycler_background" android:layout_width="wrap_content" android:layout_height="100dp" android:layout_weight="1" android:orientation="horizontal" android:padding="10dp">

            <TextView android:id="@+id/tv_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv_time" android:layout_gravity="center" android:layout_marginTop="5dp" android:maxLines="2" android:text=" I don't want to " android:textColor="@color/black" android:textSize="20sp" />

        </LinearLayout>

        <LinearLayout android:layout_width="wrap_content" android:layout_height="100dp" android:orientation="vertical">

            <TextView android:id="@+id/tv_time" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_marginRight="10dp" android:paddingLeft="5dp" android:text="2021/5/30 02:30" android:textColor="@color/black" android:textSize="16sp" android:layout_weight="1" android:gravity="right"/>

            <LinearLayout android:layout_width="150dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="right" android:orientation="horizontal">

                <ImageView android:id="@+id/iv_remind" android:layout_width="30dp" android:layout_height="30dp" android:layout_gravity="center_vertical" android:layout_marginRight="10dp" android:src="@mipmap/ic_note_clock" android:visibility="visible" />

                <CheckBox android:id="@+id/checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:buttonTint="#ffffff" android:checked="false" android:gravity="center_vertical" android:scaleX="1.5" android:scaleY="1.5" android:visibility="gone" />


            </LinearLayout>

        </LinearLayout>

    </LinearLayout>


</LinearLayout>

According to the effect :checkbox To hide (gone), When long press , appear checkbox

 Insert picture description here

3、recyclerView Adapter code

RecyclerAdapter.java

package com.tinno.adapter;

import static android.view.View.VISIBLE;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toolbar;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;

import com.tinno.bean.Note;
import com.tinno.db.NoteDbHelper;
import com.tinno.sticky_note.EditNoteActivity;
import com.tinno.sticky_note.MainActivity;
import com.tinno.sticky_note.R;
import com.tinno.utils.FormatTime;

import java.io.Serializable;
import java.util.List;

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.RecyclerViewHolder> {
    

    private static final String TAG = "RecyclerAdapter";

    private List<Note> mBeanList;
    private Context mContext;
    private boolean showIcon = false;
    private int flag = 0; // Number of hits 
    public boolean isCheck;


    private LinearLayout mNoteAdd,mNoteBottom;
    private Toolbar noteToolbar;

    public RecyclerAdapter(Context context, List<Note> mBeanList) {
    
        this.mContext = context;
        this.mBeanList = mBeanList;
    }

    @NonNull
    @Override
    public RecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    
        View view = LayoutInflater.from(mContext).inflate(R.layout.note_item, parent, false);

        return new RecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
    
        Note note = mBeanList.get(position);
        holder.mTvCreateTime.setText(FormatTime.FormatTimeForDb(note.getCreatedTime()));
        holder.mTvContent.setText(note.getContent());
        holder.lrContainer.setBackgroundColor(note.getColor());

        //  Set the long press click event for the control 
        holder.lrContainer.setOnLongClickListener(new View.OnLongClickListener() {
    

            @Override
            public boolean onLongClick(View view) {
    
                // Yes flag Make a self increasing , When flag From the beginning of clicking , When flag yes 2 The divisor of ,showIcon Set up false, On the contrary, set it to true;
                flag++;
                Log.d(TAG, "showIcon " + showIcon);
                //  Set all variables , When long press and click , The status changes to true, And call  notifyItemRangeChanged(int positionStart,int itemCount) Method to refresh from the specified location , How many to refresh 
                //Toast.makeText(mContext, "showIcon The state of " + showIcon, Toast.LENGTH_SHORT).show();
                if (flag % 2 == 0 ){
    
                    showIcon = false;
                }else {
    
                    showIcon = true;
                }

                showOrHide(showIcon);
                //Toast.makeText(mContext, " Get the item Of id" + mBeanList.get(position), Toast.LENGTH_SHORT).show();
                notifyItemRangeChanged(0,mBeanList.size());

                return true;
            }
        });


        //  Judge showIcon Is the state of true, by true When ,checkbox Show , Anyway, it's hidden 
        holder.mCheckBox.setVisibility(showIcon ? VISIBLE : View.GONE);


        /** * When the user clicks the button, the content of the memo is passed to AddNoteActivity */
        holder.lrContainer.setOnClickListener(view -> {
    
            Intent intent = new Intent(mContext, EditNoteActivity.class);
            intent.putExtra("note",note);
            Log.d(TAG, "adapter towards activity The value of intermediate transmission is : " + note.getId());
            mContext.startActivity(intent);

        });

        //  Judge whether the alarm clock reminder time is set , If the reminder time is not set , Hide the alarm icon 
        NoteDbHelper noteDbHelper = new NoteDbHelper(mContext);
        List<Note> noteList = noteDbHelper.queryAllFromDb();
        if (TextUtils.isEmpty(noteList.get(position).getRemind())){
    
            //Log.d(TAG, "onBindViewHolder: " + 123);
            holder.mTvRemind.setVisibility(View.GONE);
        }else {
    
            holder.mTvRemind.setVisibility(VISIBLE);
            holder.mTvRemind.setOnClickListener(view -> {
    
                showDialog(noteList.get(position).getRemind());
            });
        }

        //  Set the top tag for the content of the top memo 
        if (noteList.get(position).getIsTop() == 1){
    
            holder.mIvTopTab.setVisibility(VISIBLE);
        }else if (noteList.get(position).getIsTop() == 0){
    
            holder.mIvTopTab.setVisibility(View.INVISIBLE);
        }
    }

    //  Click the alarm clock icon , Pop up a dialog, Used to display the content and time of the prompt 
    public void showDialog(String str){
    
        AlertDialog dialog = new AlertDialog.Builder(mContext)
                .setTitle(" Event reminder ")
                .setMessage(str + "\n" + str)
                .create();

        dialog.show();
    }


    //  obtain MainActivity Control in , And show and hide the control 
    public void showOrHide(boolean isShow){
    
        mNoteAdd = ((MainActivity) mContext).findViewById(R.id.id_note_add);
        mNoteBottom = ((MainActivity) mContext).findViewById(R.id.id_note_bottom);
        noteToolbar = ((MainActivity) mContext).findViewById(R.id.id_note_toolbar);

        if (isShow){
    
            mNoteAdd.setVisibility(View.GONE);
            mNoteBottom.setVisibility(VISIBLE);
            noteToolbar.setVisibility(VISIBLE);
        }else {
    
            mNoteAdd.setVisibility(VISIBLE);
            mNoteBottom.setVisibility(View.GONE);
            noteToolbar.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
    
        return mBeanList == null ? 0 : mBeanList.size();
    }

    @Override
    public long getItemId(int position) {
    
        return position;
    }

    public class RecyclerViewHolder extends RecyclerView.ViewHolder {
    

        private TextView mTvCreateTime;
        private TextView mTvContent;
        private ImageView mTvRemind,mIvTopTab;
        private ViewGroup lrContainer;
        private LinearLayout recycler_background;
        private CheckBox mCheckBox;

        public RecyclerViewHolder(@NonNull View itemView) {
    
            super(itemView);

            mTvCreateTime = itemView.findViewById(R.id.tv_time);
            mTvContent = itemView.findViewById(R.id.tv_content);
            mTvRemind = itemView.findViewById(R.id.iv_remind);
            lrContainer = itemView.findViewById(R.id.lr_list_container);
            mCheckBox = itemView.findViewById(R.id.checkbox);
            recycler_background = itemView.findViewById(R.id.recycler_background);
            mIvTopTab = itemView.findViewById(R.id.iv_topTab);

            //  Click event of multiple selection boxes 
            mCheckBox.setOnClickListener(view -> {
    
                if (mCheckBox.isChecked()){
    
                    mOnItemClickListener.onRecyclerItemClick(getAdapterPosition());
                }
            });
        }
    }

    private OnRecyclerItemClickListener mOnItemClickListener;

    // Set the method of listening 
    public void setRecyclerItemClickListener(OnRecyclerItemClickListener listener){
    
        mOnItemClickListener = listener;
    }

    // Customize a listener 
    public interface OnRecyclerItemClickListener{
    
        void onRecyclerItemClick(int position);
    }

}

4、 The code of the main initiator ,

And set click events for some controls on the main page

MainActivity.java

package com.tinno.sticky_note;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.tinno.adapter.RecyclerAdapter;
import com.tinno.bean.Note;
import com.tinno.db.NoteDbHelper;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    

    private static final String TAG = "MainActivity";

    private Context mContext;
    private List<Note> data;
    private RecyclerView mRecyclerView;
    private RecyclerAdapter mRecyclerAdapter;
    private List<String> list;

    private NoteDbHelper mNoteDbHelper = new NoteDbHelper(this);

    private LinearLayout mNoteAdd;

    private Button headerCancel,headerSelectAll;
    private LinearLayout headerTop,headerDelete;

    private TextView tvHeaderTop;

    private ImageView addpic;   // Add Icon 

    private Intent intent;

    private Handler mHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mContext = this;

        mNoteAdd = findViewById(R.id.id_note_add);
        mNoteAdd.setOnClickListener(this);


        initView();
    }

    @Override
    protected void onResume() {
    
        super.onResume();

        mRecyclerView = (RecyclerView) findViewById(R.id.recycler);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mNoteDbHelper = new NoteDbHelper(mContext);
        data = new ArrayList<>();
        Log.d(TAG, "init: ....." );
        data = mNoteDbHelper.queryAllFromDb();
       // Log.d(TAG, "init: " + data);
        mRecyclerAdapter = new RecyclerAdapter(mContext,data);
        mRecyclerView.setAdapter(mRecyclerAdapter);

        //  Change the top setting to cancel the top setting 
        ChangeTopButtonContent();
        //  Get the recyclerview Medium checkbox
        show();
    }

    //  obtain RecyclerView in checkBox Contents of the selection box 
    public void show(){
    
        list = new ArrayList<>();
        mRecyclerAdapter.setRecyclerItemClickListener(position -> {
    
            list.add(data.get(position).getId());
            Log.d(TAG, "show: " + list);
            //Toast.makeText(mContext, " Whether it is overhead " + data.get(position).getIsTop(), Toast.LENGTH_SHORT).show();
            if (data.get(position).getIsTop() == 1){
    
                Toast.makeText(mContext, " Whether to cancel the overhead ", Toast.LENGTH_SHORT).show();
                tvHeaderTop.setText(" Cancel the top ");
            }else {
    
                Toast.makeText(mContext, " Whether it is overhead ", Toast.LENGTH_SHORT).show();
                tvHeaderTop.setText(" Overhead ");
            }
        });
    }



    //  If all labels are placed on top , The top button changes to cancel the top , If not , The top button remains unchanged 
    public void ChangeTopButtonContent(){
    
        List<Integer> list = new ArrayList<>();
        for (Note datum : data) {
    
            list.add(datum.getIsTop());
        }
        if (list != null){
    
            int first = list.get(0);
            for (Integer integer : list) {
    
                if(integer.equals(first)){
    
                    tvHeaderTop.setText(" Cancel the top ");
                }else {
    
                    tvHeaderTop.setText(" Overhead ");
                }
            }
        }
    }

    public void initView(){
    
        headerCancel = (Button) findViewById(R.id.header_cancel);
        headerSelectAll = (Button) findViewById(R.id.header_selectAll);
        headerTop = (LinearLayout) findViewById(R.id.header_top);
        headerDelete = (LinearLayout) findViewById(R.id.header_delete);
        tvHeaderTop = (TextView) findViewById(R.id.tv_header_top);
        addpic = (ImageView) findViewById(R.id.add_pic);



        headerCancel.setOnClickListener(this);
        headerSelectAll.setOnClickListener(this);
        headerTop.setOnClickListener(this);
        headerDelete.setOnClickListener(this);
        addpic.setOnClickListener(this);
    }

    //  Return to the perfect state of the home page 
    public void showHome(){
    
        RecyclerAdapter adapter = new RecyclerAdapter(mContext,data);
        adapter.showOrHide(false);
        onResume();
    }

    //  Set note top event 
    public void setThingTop(){
    
        //  Traverse all the array contents queried from the database 
        for (Note datum : data) {
    
            Log.d(TAG, "onClick: " + datum);
            //  Yes checkbox Click the event to traverse , obtain id
            for (String noteId : list){
    
                //  Judge the database's id and checkbox Get content id Whether it is equal or not , If equal, proceed to the next step 
                if (datum.getId().equals(noteId)){
    
                    Log.d(TAG, "onClick: -------------------------------------------");
                    Log.d(TAG, " Get events : " + datum.getContent() + "=>" + datum.getId());
                    Note n = new Note();
                    n.setId(datum.getId());
                    n.setContent(datum.getContent());
                    n.setRemind(datum.getRemind());
                    n.setColor(datum.getColor());
                    n.setCreatedTime(datum.getCreatedTime());
                    if (tvHeaderTop.getText().toString().equals(" Overhead ")){
    
                        n.setIsTop(1);
                    }else if (tvHeaderTop.getText().toString().equals(" Cancel the top ")){
    
                        n.setIsTop(0);
                    }

                    mNoteDbHelper.updateData(n);
                    Log.d(TAG, " To obtain a new Note object :" + n);
                    Log.d(TAG, "onClick: ---------------------------------------------" );
                }
            }
        }
    }
    

    @Override
    public void onClick(View view) {
    
        switch (view.getId()){
    
            case R.id.add_pic:
                intent = new Intent(this, AddNoteActivity.class);
                startActivity(intent);
                break;
            case R.id.header_cancel:
                showHome();
                break;
            case R.id.header_selectAll:
                break;
            case R.id.header_top:
                setThingTop();
                showHome();
                break;
            case R.id.header_delete:
                for (String s : list) {
    
                    mNoteDbHelper.deleteFromDbById(s);
                }
                showHome();
                break;
        }
    }
}

5、 Create database

In order to store data , Create noteSql database , And create note Data sheet , And initialize the database operation in this class CURD Methods .

NoteDbHelper.java

package com.tinno.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.tinno.bean.Note;

import java.util.ArrayList;
import java.util.List;

/** * Notes Database class */
public class NoteDbHelper extends SQLiteOpenHelper {
    

    private static final String TAG = "NoteDbHelper";

    private Context context;

    private static final String DB_NAME = "noteSql.db";
    private static final String NOTE_TABLE_NAME = "note";

    // Database Version
    private static final int DATABASE_VERSION =1;

    private static final String CREATE_TABLE_SQL = "CREATE TABLE IF NOT EXISTS " + NOTE_TABLE_NAME + " (id INTEGER PRIMARY KEY AUTOINCREMENT, content TEXT, create_time TEXT, remind TEXT, color TEXT,isTop TEXT)";



    public NoteDbHelper(Context context){
    
        super(context,DB_NAME,null,DATABASE_VERSION);
        this.context = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
    
        db.execSQL(CREATE_TABLE_SQL);
        Toast.makeText(context, " Database created successfully ", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
    

    }

    /** * Query all contents of the database * @return */
    public List<Note> queryAllFromDb(){
    
        SQLiteDatabase db = getWritableDatabase();
        List<Note> noteList = new ArrayList<>();

        Cursor cursor = db.query(NOTE_TABLE_NAME, null, null, null, null, null, "isTop DESC");
        if (cursor != null){
    
            while (cursor.moveToNext()){
    
                String id = cursor.getString(cursor.getColumnIndexOrThrow("id"));
                String content = cursor.getString(cursor.getColumnIndexOrThrow("content"));
                String createTime  = cursor.getString(cursor.getColumnIndexOrThrow("create_time"));
                String remind = cursor.getString(cursor.getColumnIndexOrThrow("remind"));
                int color = cursor.getInt(cursor.getColumnIndexOrThrow("color"));
                int isTop = cursor.getInt(cursor.getColumnIndexOrThrow("isTop"));

                Note note = new Note();
                note.setId(id);
                note.setContent(content);
                note.setCreatedTime(createTime);
                note.setRemind(remind);
                note.setColor(color);
                note.setIsTop(isTop);

                noteList.add(note);
            }
            cursor.close();
        }
        return noteList;
    }

    public long insertData(Note note){
    
        SQLiteDatabase db = getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put("content",note.getContent());
        values.put("create_time",note.getCreatedTime());
        values.put("remind",note.getRemind());
        values.put("color",note.getColor());
        values.put("isTop",note.getIsTop());

        return db.insert(NOTE_TABLE_NAME,null,values);
    }

    public int deleteFromDbById(String id) {
    
        SQLiteDatabase db = getWritableDatabase();
        return db.delete(NOTE_TABLE_NAME, "id like ?", new String[]{
    id});
    }

    public int updateData(Note note) {
    

        SQLiteDatabase db = getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put("content", note.getContent());
        values.put("create_time", note.getCreatedTime());
        values.put("remind",note.getRemind());
        values.put("color",note.getColor());
        values.put("isTop",note.getIsTop());
        Log.d(TAG, "updateData: " + values);
        return db.update(NOTE_TABLE_NAME, values, "id like ?", new String[]{
    note.getId()});
    }


    public List<Note> queryFromDbByContent(String content) {
    
        if (TextUtils.isEmpty(content)) {
    
            return queryAllFromDb();
        }

        SQLiteDatabase db = getWritableDatabase();
        List<Note> noteList = new ArrayList<>();

        Cursor cursor = db.query(NOTE_TABLE_NAME, null, "content like ?", new String[]{
    "%"+content+"%"}, null, null, null);

        if (cursor != null) {
    

            while (cursor.moveToNext()) {
    
                String id = cursor.getString(cursor.getColumnIndexOrThrow("id"));
                String content2 = cursor.getString(cursor.getColumnIndexOrThrow("content"));
                String createTime = cursor.getString(cursor.getColumnIndexOrThrow("create_time"));
                String remind = cursor.getString(cursor.getColumnIndexOrThrow("remind"));
                int color = cursor.getInt(cursor.getColumnIndexOrThrow("color"));
                int isTop = cursor.getInt(cursor.getColumnIndexOrThrow("isTop"));

                Note note = new Note();
                note.setId(id);
                note.setContent(content2);
                note.setCreatedTime(createTime);
                note.setRemind(remind);
                note.setColor(color);
                note.setIsTop(isTop);
                noteList.add(note);
            }
            cursor.close();
        }
        return noteList;
    }
}

6、 Time initialization

When initializing the note creation ( Data stored in the database ) And the specific time displayed on the page

FormatTime.java

package com.tinno.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/** *  Time tools  */
    public class FormatTime {
    

    //  How to get the current time 
    public static String getCurrentTimeFormat(){
    
        long currentTime = System.currentTimeMillis();
        String timeNow = new SimpleDateFormat("yyyy/MM/dd HH:mm").format(currentTime);
        return timeNow;
    }

    
    /** *  Through the collation of database time , Combined with the current time , Integrate the displayed time  *  Time display  * 1、 today : hh-mm; * 2、 yesterday :  yesterday  hh-mm; * 3、 Within this week :  What day of the week  hh-mm; * 4、 Outside this week : nnnn-yy-dd; * @param time  The time point of the incoming database storage  * @return */
    public static String FormatTimeForDb(String time){
    
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        Date date2;

        date2 = new Date(System.currentTimeMillis());
        int year1 = Integer.parseInt(time.substring(0,4));
        int month1 = Integer.parseInt(time.substring(5,7));
        int day1 = Integer.parseInt(time.substring(8,10));
        int h1 = Integer.parseInt(time.substring(11,13));
        int m1 = Integer.parseInt(time.substring(14,16));



        //  Time now 
        String str2 = simpleDateFormat.format(date2);
        int year2 = Integer.parseInt(str2.substring(0, 4));
        int month2 = Integer.parseInt(str2.substring(5, 7));
        int day2 = Integer.parseInt(str2.substring(8, 10));
        int h2 = Integer.parseInt(str2.substring(11, 13));
        int m2 = Integer.parseInt(str2.substring(14, 16));

        if (year2 > year1) {
    
            return year1 + "/" + time.substring(5, 7) + "/" + time.substring(8, 10);
        } else if (month2 > month1) {
    
            return year1 + "/" + time.substring(5, 7) + "/" + time.substring(8, 10);
        } else if (day2 > day1) {
    
            if (day2 - day1 == 1){
    
                return " yesterday  " + time.substring(11,13) + ":" + time.substring(14,16);
            }else if (day2 - day1 < 7){
    
                return getWeek(time) + " " + time.substring(11,13) + ":" + time.substring(14,16);
            }else {
    
                return year1 + "/" + time.substring(5, 7) + "/" + time.substring(8, 10);
            }
        } else {
    
            return " today  " + time.substring(11, 13) + ":" + time.substring(14, 16);
        }
    }

    /** *  Get the day of week tool class at the specified time  * @param dateTime  Enter the specific time that needs to be changed   The format is  yyyy/MM/dd * @return */
    private static int getDayofWeek(String dateTime) {
    
        Calendar cal = Calendar.getInstance();
        if (dateTime.equals("")) {
    
            cal.setTime(new Date(System.currentTimeMillis()));
        } else {
    
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.getDefault());
            Date date;
            try {
    
                date = sdf.parse(dateTime);
            } catch (ParseException e) {
    
                date = null;
                e.printStackTrace();
            }
            if (date != null) {
    
                cal.setTime(new Date(date.getTime()));
            }
        }
        return cal.get(Calendar.DAY_OF_WEEK);
    }

    /** *  Convert the specified time into the specific day of the week displayed  * @param time * @return */
    public static String getWeek(String time){
    
        int dayofWeek = getDayofWeek(time);

        if (1 == dayofWeek){
    
            return  " Sunday ";
        }else if (2 == dayofWeek){
    
            return  " Monday ";
        }else if (3 ==dayofWeek){
    
            return  " Tuesday ";
        }else if (4 == dayofWeek){
    
            return  " Wednesday ";
        }else if (5==dayofWeek){
    
            return  " Thursday ";
        }else if (6 == dayofWeek){
    
            return  " Friday ";
        }else{
    
            return  " Saturday ";
        }
    }

}

7、 Post it skin display and modification

Use popupWindow Control to display the effect of sticky note skin , And set click events for each skin , Monitor clicks and change theme colors

popupWindow Layout popup_theme.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">

    <LinearLayout android:layout_width="320dp" android:layout_height="80dp" android:orientation="horizontal" android:background="@color/menu_background" android:layout_gravity="end" android:layout_marginTop="10dp" android:layout_marginRight="10dp">

        <FrameLayout android:id="@+id/theme1" android:layout_width="60dp" android:layout_height="60dp" android:background="@color/menu_theme1" android:layout_gravity="center" android:layout_margin="10dp"/>

        <FrameLayout android:id="@+id/theme2" android:layout_width="60dp" android:layout_height="60dp" android:background="@color/menu_theme2" android:layout_gravity="center" android:layout_margin="10dp"/>

        <FrameLayout android:id="@+id/theme3" android:layout_width="60dp" android:layout_height="60dp" android:background="@color/menu_theme3" android:layout_gravity="center" android:layout_margin="10dp"/>

        <FrameLayout android:id="@+id/theme4" android:layout_width="60dp" android:layout_height="60dp" android:background="@color/menu_theme4" android:layout_gravity="center" android:layout_margin="10dp"/>

    </LinearLayout>

</LinearLayout>

effect :

 Insert picture description here

Code implementation :

// popupWindow Control and display of 
    public void showPopupWindow(View view){
    
        View popupView = getLayoutInflater().inflate(R.layout.popup_theme,null);

        FrameLayout btn1,btn2,btn3,btn4;
        btn1 = popupView.findViewById(R.id.theme1);
        btn2 = popupView.findViewById(R.id.theme2);
        btn3 = popupView.findViewById(R.id.theme3);
        btn4 = popupView.findViewById(R.id.theme4);

        PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT,true);

        popupWindow.showAsDropDown(edit_themes);

        btn1.setOnClickListener(view1 -> {
    
            content_container.setBackgroundColor(Color.parseColor("#BFC8FD"));
            edit_themes.setBackgroundColor(Color.parseColor("#BFC8FD"));
            Log.d(TAG, "showPopupWindow:  Color ");
            popupWindow.dismiss();
        });

        btn2.setOnClickListener(view1 -> {
    
            content_container.setBackgroundColor(Color.parseColor("#A5EEE5"));
            edit_themes.setBackgroundColor(Color.parseColor("#A5EEE5"));
            popupWindow.dismiss();
        });

        btn3.setOnClickListener(view1 -> {
    
            content_container.setBackgroundColor(Color.parseColor("#FCBEBE"));
            edit_themes.setBackgroundColor(Color.parseColor("#FCBEBE"));
            popupWindow.dismiss();
        });

        btn4.setOnClickListener(view1 -> {
    
            content_container.setBackgroundColor(Color.parseColor("#FFF195"));
            edit_themes.setBackgroundColor(Color.parseColor("#FFF195"));
            popupWindow.dismiss();
        });

    }

8、 Time and date selector

In the edit and add pages , Click the alarm button , Add a reminder time , eject 3 individual dialog, The first is the memo reminder text , Click OK to pop up the date selector , After select date , The selected date appears in the date box above , Click the confirm button , Pop up the time selector , Click to confirm the city , above textView The selected date and time appear .

First complete a layout for the date and time selector , Based on this layout, a dialog The pop-up window of

dialog_date_select.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal" android:gravity="center_horizontal">

    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/set_alarm_title" android:textStyle="bold" android:textSize="20sp" android:typeface="serif" android:layout_marginTop="5dp" android:textColor="@color/black"/>

    <LinearLayout android:layout_width="match_parent" android:layout_height="30dp" android:gravity="center">

        <TextView android:id="@+id/dds_time" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text=" Time (10:55)" android:textSize="16sp" android:layout_weight="1" />

        <TextView android:id="@+id/dds_date" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text=" date (06/27)" android:layout_weight="1" android:textSize="16sp" />

    </LinearLayout>

    <DatePicker android:id="@+id/date_picker" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:spinnersShown="false" />

    <TimePicker android:id="@+id/time_picker" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" />
</LinearLayout>

effect :
 Insert picture description here

Implementation code

    //  Pop up a dialog
    public void showDialog(){
    
        final EditText message = new EditText(this);
        message.setPadding(10,10,10,10);
        message.setTextColor(Color.BLACK);
        message.setBackgroundColor(Color.WHITE);

        TextView title = new TextView(this);
        title.setText(" Notes to remind ");
        title.setPadding(10,10,10,10);
        title.setGravity(Gravity.CENTER);
        title.setTextColor(Color.BLACK);
        title.setTextSize(26);
        title.setBackgroundColor(Color.parseColor("#F2F2F2"));
        AlertDialog dialog = new AlertDialog.Builder(this)
                .setView(message)
                .setCustomTitle(title)
                .setNeutralButton(" Enter the memo ", null)
                .setPositiveButton(" confirm ",null)
                .create();
        dialog.show();

        //  Enter the memo button 
        dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View view) {
    
                dialog.dismiss();
            }
        });

        //  OK button 
        dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View view) {
    
                Toast.makeText(context, " Get the contents of the input box :" + message.getText().toString(), Toast.LENGTH_SHORT).show();
                showDate();
                //Toast.makeText(context, " confirm button ", Toast.LENGTH_SHORT).show();
            }
        });

    }

    //  Initialize the date and time selector layout 
    public void initShowDateView(){
    
        v = View.inflate(context,R.layout.dialog_date_select,null);
        datePicker = (DatePicker) v.findViewById(R.id.date_picker);
        timePicker = (TimePicker) v.findViewById(R.id.time_picker);
        ddsDate = (TextView) v.findViewById(R.id.dds_date);
        ddsTime = (TextView) v.findViewById(R.id.dds_time);
    }

    //  Date Pickers 
    public void  showDate(){
    
        //  Initialize control 
        initShowDateView();

        //  Remove the unnecessary time selection control here 
        ((ViewGroup)v).removeView(timePicker);

        AlertDialog alertDialog = new AlertDialog.Builder(context)
                .setView(v)
                .setNeutralButton(getString(R.string.cancel),null)
                .setPositiveButton(getString(R.string.sure),null)
                .create();
        alertDialog.show();

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH);
        day = calendar.get(Calendar.DAY_OF_MONTH);
        /** * // Initialize the date selector and set the date change listener  * datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() { * @Override * public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { * // Get the selected date  * DataPickerActivity.this.year = year; * // From the month 0 At the beginning  * DataPickerActivity.this.month = (monthOfYear+1); * DataPickerActivity.this.day = dayOfMonth; * // Popup window display  * Toast.makeText(DataPickerActivity.this,DataPickerActivity.this.year+" year "+DataPickerActivity.this.month+" month "+DataPickerActivity.this.day+" Japan ",Toast.LENGTH_SHORT).show(); * } * }); */
        //  Set listener , Monitor data changes 
        datePicker.init(year, month, day, (datePicker1, i, i1, i2) -> {
    
            this.year = i;
            this.month = i1 + 1;
            this.day = i2;
            //Toast.makeText(context, "i=>" + i + "<=> i1 <=>" + i1 + "<=> i2 <=>" + i2, Toast.LENGTH_SHORT).show();
            //Toast.makeText(context, year + "/" + month + "/" + day, Toast.LENGTH_SHORT).show();
            ddsDate.setText(year+"/"+month+"/"+day);
            //EditNoteActivity.this.ddsDate.setText(dateStr);
        });
        //Toast.makeText(EditNoteActivity.this, year + "/" + month + "/" + day, Toast.LENGTH_SHORT).show();


        alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(view -> {
    
            alertDialog.dismiss();
        });

        alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(view -> {
    
            showTime();
            //Toast.makeText(context, " Time selector ", Toast.LENGTH_SHORT).show();
        });
    }

    //  Time selector 
    public void showTime(){
    

        initShowDateView();

        //  Remove the time selector and date selector before adding the time selector 
        ((ViewGroup)v).removeView(datePicker);
        ((ViewGroup)v).removeView(timePicker);
        ((ViewGroup)v).addView(timePicker);

        AlertDialog dialog = new AlertDialog.Builder(context)
                .setView(v)
                .setNeutralButton(getString(R.string.cancel),null)
                .setPositiveButton(getString(R.string.sure),null)
                .create();
        dialog.show();


        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        timePicker.setIs24HourView(true);
        timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
        timePicker.setCurrentMinute(Calendar.MINUTE);


        //  Cancel button 
        dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(view -> {
    
            dialog.dismiss();
        });

        // confirm button 
        dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(view -> {
    
            String CurrentHour = timePicker.getCurrentHour().toString();
            String CurrentMinute = timePicker.getCurrentMinute().toString();

            if (timePicker.getCurrentHour() >= 0 && timePicker.getCurrentHour() <= 9) {
    
                CurrentHour = "0" + timePicker.getCurrentHour() ;
            }
            if (timePicker.getCurrentMinute() >= 0 && timePicker.getCurrentMinute() <= 9) {
    
                CurrentMinute = "0" + timePicker.getCurrentMinute();
            }
            StringBuffer sb = new StringBuffer();
            sb.append(String.format("%d/%02d/%02d",
                    datePicker.getYear(),
                    datePicker.getMonth() + 1,
                    datePicker.getDayOfMonth()));
            sb.append(" ");
            sb.append(CurrentHour)
                    .append(":")
                    .append(CurrentMinute);

            String ttime = sb.toString();

            String[] s = ttime.split(" ");
            //Toast.makeText(context, Arrays.toString(s), Toast.LENGTH_SHORT).show();
            //Toast.makeText(context, "date ==> "+ s[0] + "<==> time ==> " + s[1], Toast.LENGTH_SHORT).show();
            //  Cut the date and time , And copy the corresponding value to the corresponding control 
            ddsDate.setText(s[0]);
            ddsTime.setText(s[1]);

            Note n = new Note();
            n.setId(note.getId());
            n.setCreatedTime(note.getCreatedTime());
            n.setColor(note.getColor());
            n.setContent(note.getContent());
            n.setIsTop(note.getIsTop());
            n.setRemind(ttime);
            Log.d(TAG, " Get the value of  : " + n);
            mNoteDbHelper = new NoteDbHelper(this);
            mNoteDbHelper.updateData(n);
            finish();
        });

    }

9、 Long press the editing function

On the home page , Long press one item, Four edit buttons and multiple selection buttons appear , You can top up the homepage notes 、 Delete and other functions

Delete function

Implementation code :

  1. First, long press a control to show and hide functions

    @Override
        public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
          
            Note note = mBeanList.get(position);
            holder.mTvCreateTime.setText(FormatTime.FormatTimeForDb(note.getCreatedTime()));
            holder.mTvContent.setText(note.getContent());
            holder.lrContainer.setBackgroundColor(note.getColor());
    
            //  Set the long press click event for the control 
            holder.lrContainer.setOnLongClickListener(new View.OnLongClickListener() {
          
    
                @Override
                public boolean onLongClick(View view) {
          
                    // Yes flag Make a self increasing , When flag From the beginning of clicking , When flag yes 2 The divisor of ,showIcon Set up false, On the contrary, set it to true;
                    flag++;
                    Log.d(TAG, "showIcon " + showIcon);
                    //  Set all variables , When long press and click , The status changes to true, And call  notifyItemRangeChanged(int positionStart,int itemCount) Method to refresh from the specified location , How many to refresh 
                    //Toast.makeText(mContext, "showIcon The state of " + showIcon, Toast.LENGTH_SHORT).show();
                    if (flag % 2 == 0 ){
          
                        showIcon = false;
                    }else {
          
                        showIcon = true;
                    }
    
                    showOrHide(showIcon);
                    //Toast.makeText(mContext, " Get the item Of id" + mBeanList.get(position), Toast.LENGTH_SHORT).show();
                    notifyItemRangeChanged(0,mBeanList.size());
    
                    return true;
                }
            });
    
    
            //  Judge showIcon Is the state of true, by true When ,checkbox Show , Anyway, it's hidden 
            holder.mCheckBox.setVisibility(showIcon ? VISIBLE : View.GONE);
    
    		......
            ......
            ......
        }
    
     //  obtain MainActivity Control in , And show and hide the control 
        public void showOrHide(boolean isShow){
          
            mNoteAdd = ((MainActivity) mContext).findViewById(R.id.id_note_add);
            mNoteBottom = ((MainActivity) mContext).findViewById(R.id.id_note_bottom);
            noteToolbar = ((MainActivity) mContext).findViewById(R.id.id_note_toolbar);
    
            if (isShow){
          
                mNoteAdd.setVisibility(View.GONE);
                mNoteBottom.setVisibility(VISIBLE);
                noteToolbar.setVisibility(VISIBLE);
            }else {
          
                mNoteAdd.setVisibility(VISIBLE);
                mNoteBottom.setVisibility(View.GONE);
                noteToolbar.setVisibility(View.GONE);
            }
        }
    
  2. stay RecyclerAdapter Customize an interface in , Used to receive click events of multiple selection boxes .

    public class RecyclerViewHolder extends RecyclerView.ViewHolder {
          
    
            private TextView mTvCreateTime;
            private TextView mTvContent;
            private ImageView mTvRemind,mIvTopTab;
            private ViewGroup lrContainer;
            private LinearLayout recycler_background;
            private CheckBox mCheckBox;
    
            public RecyclerViewHolder(@NonNull View itemView) {
          
                super(itemView);
    
                mTvCreateTime = itemView.findViewById(R.id.tv_time);
                mTvContent = itemView.findViewById(R.id.tv_content);
                mTvRemind = itemView.findViewById(R.id.iv_remind);
                lrContainer = itemView.findViewById(R.id.lr_list_container);
                mCheckBox = itemView.findViewById(R.id.checkbox);
                recycler_background = itemView.findViewById(R.id.recycler_background);
                mIvTopTab = itemView.findViewById(R.id.iv_topTab);
    
                //  Click event of multiple selection boxes 
                mCheckBox.setOnClickListener(view -> {
          
                    if (mCheckBox.isChecked()){
          
                        mOnItemClickListener.onRecyclerItemClick(getAdapterPosition());
                    }
                });
            }
        }
    
        private OnRecyclerItemClickListener mOnItemClickListener;
    
        // Set the method of listening 
        public void setRecyclerItemClickListener(OnRecyclerItemClickListener listener){
          
            mOnItemClickListener = listener;
        }
    
        // Customize a listener 
        public interface OnRecyclerItemClickListener{
          
            void onRecyclerItemClick(int position);
        }
    
  3. stay MainActivity.java In order to get RecyclerView in CheckBox Contents of the selection box

    //  obtain RecyclerView in checkBox Contents of the selection box 
        public void show(){
          
            list = new ArrayList<>();
            mRecyclerAdapter.setRecyclerItemClickListener(position -> {
          
                list.add(data.get(position).getId());
                Log.d(TAG, "show: " + list);
                //Toast.makeText(mContext, " Whether it is overhead " + data.get(position).getIsTop(), Toast.LENGTH_SHORT).show();
                if (data.get(position).getIsTop() == 1){
          
                    Toast.makeText(mContext, " Whether to cancel the overhead ", Toast.LENGTH_SHORT).show();
                    tvHeaderTop.setText(" Cancel the top ");
                }else {
          
                    Toast.makeText(mContext, " Whether it is overhead ", Toast.LENGTH_SHORT).show();
                    tvHeaderTop.setText(" Overhead ");
                }
            });
    
  4. Return to an original state of the home page

    //  Return to the perfect state of the home page 
        public void showHome(){
          
            RecyclerAdapter adapter = new RecyclerAdapter(mContext,data);
            adapter.showOrHide(false);
            onResume();
        }
    
  5. In the click button , Calling method , Get the checkbox The data of id, Perform a data deletion

@Override
    public void onClick(View view) {
    
        switch (view.getId()){
    
            ....
            ....
            case R.id.header_delete:
                for (String s : list) {
    
                    mNoteDbHelper.deleteFromDbById(s);
                }
                showHome()
                break;
        }
    }

Overhead function

Implementation code

@Override
    public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
    
        Note note = mBeanList.get(position);
        holder.mTvCreateTime.setText(FormatTime.FormatTimeForDb(note.getCreatedTime()));
        holder.mTvContent.setText(note.getContent());
        holder.lrContainer.setBackgroundColor(note.getColor());

		......
        ......
        ......

        //  Set the top tag for the content of the top memo 
        if (noteList.get(position).getIsTop() == 1){
    
            holder.mIvTopTab.setVisibility(VISIBLE);
        }else if (noteList.get(position).getIsTop() == 0){
    
            holder.mIvTopTab.setVisibility(View.INVISIBLE);
        }
    }
//  Set note top event 
    public void setThingTop(){
    
        //  Traverse all the array contents queried from the database 
        for (Note datum : data) {
    
            Log.d(TAG, "onClick: " + datum);
            //  Yes checkbox Click the event to traverse , obtain id
            for (String noteId : list){
    
                //  Judge the database's id and checkbox Get content id Whether it is equal or not , If equal, proceed to the next step 
                if (datum.getId().equals(noteId)){
    
                    Log.d(TAG, "onClick: -------------------------------------------");
                    Log.d(TAG, " Get events : " + datum.getContent() + "=>" + datum.getId());
                    Note n = new Note();
                    n.setId(datum.getId());
                    n.setContent(datum.getContent());
                    n.setRemind(datum.getRemind());
                    n.setColor(datum.getColor());
                    n.setCreatedTime(datum.getCreatedTime());
                    if (tvHeaderTop.getText().toString().equals(" Overhead ")){
    
                        n.setIsTop(1);
                    }else if (tvHeaderTop.getText().toString().equals(" Cancel the top ")){
    
                        n.setIsTop(0);
                    }

                    mNoteDbHelper.updateData(n);
                    Log.d(TAG, " To obtain a new Note object :" + n);
                    Log.d(TAG, "onClick: ---------------------------------------------" );
                }
            }
        }
    }
@Override
    public void onClick(View view) {
    
        switch (view.getId()){
    
            ....
            ....
            case R.id.header_top:
                setThingTop();
                showHome();
                break;
            ....
            ....
      
        }
    }

10、 The note with alarm function set for the note in the home page displays a small alarm icon

  1. stay RecyclerAdapter

    @Override
        public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
          
            Note note = mBeanList.get(position);
            holder.mTvCreateTime.setText(FormatTime.FormatTimeForDb(note.getCreatedTime()));
            holder.mTvContent.setText(note.getContent());
            holder.lrContainer.setBackgroundColor(note.getColor());
    
            ......
            ......
            ......
    
            //  Judge whether the alarm clock reminder time is set , If the reminder time is not set , Hide the alarm icon 
            NoteDbHelper noteDbHelper = new NoteDbHelper(mContext);
            List<Note> noteList = noteDbHelper.queryAllFromDb();
            if (TextUtils.isEmpty(noteList.get(position).getRemind())){
          
                //Log.d(TAG, "onBindViewHolder: " + 123);
                holder.mTvRemind.setVisibility(View.GONE);
            }else {
          
                holder.mTvRemind.setVisibility(VISIBLE);
                holder.mTvRemind.setOnClickListener(view -> {
          
                    showDialog(noteList.get(position).getRemind());
                });
            }
    
            ......
            ......
            ......
        }
    
    //  Click the alarm clock icon , Pop up a dialog, Used to display the content and time of the prompt 
        public void showDialog(String str){
          
            AlertDialog dialog = new AlertDialog.Builder(mContext)
                    .setTitle(" Event reminder ")
                    .setMessage(str + "\n" + str)
                    .create();
    
            dialog.show();
        }
    

    effect
     Insert picture description here

The whole code (Demo)

gitee Address :https://gitee.com/SmellWang/sticky_-note.git

原网站

版权声明
本文为[Comeจุ๊]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/182/202207011225490996.html