Android记事本NotePad应用功能拓展(五)
一、实现功能
1.夜间模式切换
2.反转时间排序规则
二、项目代码分析
1.夜间模式切换
只要做所有关于界面的地方加上这段代码即可(判断模式设置背景)
if (super.isNightMode())
myToolbar.setNavigationIcon(getDrawable(R.drawable.ic_menu_white_24dp));
else myToolbar.setNavigationIcon(getDrawable(R.drawable.ic_menu_black_24dp)); // 三道杠
myToolbar.setNavigationOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showPopUpWindow();
}
});
2.反转时间排序规则
//按模式时间排序笔记
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;
}
});
}
//按模式时间排序计划
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;
}
});
}
三、参考资料
相关参考:Android记事本NotePad应用功能拓展(一)
作者GitHub下载链接:https://github.com/KangKangBigWorld/Android/tree/master/Mid\_Test