Android NotePad application function expansion

Android NotePad application function expansion (5)

1, Implementation function

1. Night mode switching



2. Reverse time collation





2, Project code analysis

1. Night mode switching

Just do all the things about the interface and add this code (judge the background of the mode setting)

if (super.isNightMode())
            myToolbar.setNavigationIcon(getDrawable(R.drawable.ic_menu_white_24dp));
        else myToolbar.setNavigationIcon(getDrawable(R.drawable.ic_menu_black_24dp)); // Three bars

        myToolbar.setNavigationOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                showPopUpWindow();
            }
        });

2. Reverse time collation

 //Sort notes by mode time
    public void sortNotes(List<Note> noteList, final int mode) {
        Collections.sort(noteList, new Comparator<Note>() {
            @Override
            public int compare(Note o1, Note o2) {
                try {
                    if (mode == 1) {
                        Log.d(TAG, "sortnotes 1");
                        return npLong(dateStrToSec(o2.getTime()) - dateStrToSec(o1.getTime()));
                    }
                    else if (mode == 2) {//reverseSort
                        Log.d(TAG, "sortnotes 2");
                        return npLong(dateStrToSec(o1.getTime()) - dateStrToSec(o2.getTime()));
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                return 1;
            }
        });
    }

    //Scheduling by pattern time
    public void sortPlans(List<Plan> planList, final int mode){
        Collections.sort(planList, new Comparator<Plan>() {
            @Override
            public int compare(Plan o1, Plan o2) {
                try {
                    if (mode == 1)
                        return npLong(calStrToSec(o1.getTime()) - calStrToSec(o2.getTime()));
                    else if (mode == 2) //reverseSort
                        return npLong(calStrToSec(o2.getTime()) - calStrToSec(o1.getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                return 1;
            }
        });
    }

3, References

Related reference: Android NotePad application function expansion (I)
Author GitHub download link: https://github.com/KangKangBigWorld/Android/tree/master/Mid_Test

Tags: Android github

Posted on Tue, 19 May 2020 10:51:37 -0400 by Ironmann00