修复了私密模式未经允许提前进入以及按键不随是否属于私密模式变换的bug

pull/11/head
夏彦博 10 months ago
parent 11acb45652
commit be81ecfa6a

@ -169,22 +169,37 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
super.onActivityResult(requestCode, resultCode, data);
}
}
/**
* @classname: NotesListActivity
* @methodname setAppInfoFromRawRes
* @description:WorkingNote
* @date: 2024/1/12 9:58
* @author: Xia Yanbo
*/
private void setAppInfoFromRawRes() {
// 获取默认的SharedPreferences对象用于存储和获取应用的一些常用配置信息
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
// 创建一个StringBuilder对象用于构建从资源文件中读取的内容
StringBuilder sb = new StringBuilder();
InputStream in = null;
InputStream in = null;// 声明一个InputStream对象用于读取资源文件
try {
//打开资源,作为读取的对象
in = getResources().openRawResource(R.raw.introduction);
if (in != null) {
// 创建一个InputStreamReader对象将InputStream转换为字符流
InputStreamReader isr = new InputStreamReader(in);
// 创建一个BufferedReader对象用于按行读取字符流的内容
BufferedReader br = new BufferedReader(isr);
// 创建一个字符数组用于临时存储从资源文件中读取的字符数据每个块大小为1024字节
char [] buf = new char[1024];
int len = 0;
int len = 0; // 声明一个整型变量,用于存储每次从资源文件中读取的字符数量
// 循环读取字符数据,直到没有数据可读
while ((len = br.read(buf)) > 0) {
// 将读取到的字符数据追加到StringBuilder对象中
sb.append(buf, 0, len);
}
//读取失败在日志中输出错误信息
} else {
Log.e(TAG, "Read introduction file error");
return;
@ -193,6 +208,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
e.printStackTrace();
return;
} finally {
// 最后关闭InputStream对象释放资源
if(in != null) {
try {
in.close();
@ -202,14 +218,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
}
// 创建一个工作笔记对象,并设置一些属性值
WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
ResourceParser.RED);
// 将从资源文件中读取的内容设置到工作笔记的文本属性中
note.setWorkingText(sb.toString());
// 如果成功保存工作笔记则将一个布尔值添加到SharedPreferences中键为PREFERENCE_ADD_INTRODUCTION值为true并提交更改
if (note.saveNote()) {
sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
} else {
// 如果保存失败,则在日志中输出错误信息,并结束方法执行
Log.e(TAG, "Save introduction note error");
return;
}
@ -432,7 +451,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
}
else{
String str1 = "520";
String str1 = "444";
String [] PROJECTION = new String [] { //定义一个新的PROJECTION数组只换掉SNIPPET
NoteColumns.ID,
NoteColumns.ALERTED_DATE,
@ -848,16 +867,18 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
else if(item.getItemId()==R.id.menu_secret)
{//进入私密模式
secret_mode = 1;
AlertDialog.Builder dialog = new AlertDialog.Builder(NotesListActivity.this);
dialog.setTitle("重要提醒");
dialog.setMessage("您确认进入私密模式吗?");
dialog.setCancelable(false);
dialog.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startAsyncNotesListQuery();
Toast.makeText(NotesListActivity.this,"您已进入私密模式",Toast.LENGTH_SHORT).show();
secret_mode = 1;
startAsyncNotesListQuery();
}
});
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@ -866,11 +887,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
});
dialog.show();
startAsyncNotesListQuery();
Toast.makeText(this,"您已进入私密模式",Toast.LENGTH_SHORT).show();
}
else if(item.getItemId()==R.id.menu_quit_secret)
{ //退出私密模式
secret_mode = 0;
AlertDialog.Builder dialog = new AlertDialog.Builder(NotesListActivity.this);
dialog.setTitle("重要提醒");
dialog.setMessage("您确认退出私密模式吗?");
@ -878,8 +899,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
dialog.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startAsyncNotesListQuery();
secret_mode = 0;
Toast.makeText(NotesListActivity.this,"您已退出私密模式",Toast.LENGTH_SHORT).show();
startAsyncNotesListQuery();
}
});
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {

Loading…
Cancel
Save