|
|
|
@ -79,6 +79,8 @@ import java.io.InputStreamReader;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
|
|
public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener {
|
|
|
|
|
//首页背景变换
|
|
|
|
|
private int mode = -1;
|
|
|
|
|
private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;
|
|
|
|
|
|
|
|
|
|
private static final int FOLDER_LIST_QUERY_TOKEN = 1;
|
|
|
|
@ -95,28 +97,38 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 声明一些私有成员变量。
|
|
|
|
|
private ListEditState mState; // 当前列表的编辑状态
|
|
|
|
|
private BackgroundQueryHandler mBackgroundQueryHandler; // 用于在后台执行查询的处理程序
|
|
|
|
|
private NotesListAdapter mNotesListAdapter; // 笔记列表的适配器
|
|
|
|
|
private ListView mNotesListView; // 显示笔记列表的视图
|
|
|
|
|
private Button mAddNewNote; // 添加新笔记的按钮
|
|
|
|
|
private boolean mDispatch; // 一个标志,可能用于控制事件分发
|
|
|
|
|
private int mOriginY; // 原始Y坐标,可能用于触摸事件处理
|
|
|
|
|
private int mDispatchY; // 分发的Y坐标,也可能用于触摸事件处理
|
|
|
|
|
private TextView mTitleBar; // 标题栏文本视图
|
|
|
|
|
private long mCurrentFolderId; // 当前文件夹的ID
|
|
|
|
|
private ContentResolver mContentResolver; // 内容解析器,用于访问应用的数据
|
|
|
|
|
private ModeCallback mModeCallBack; // 模式回调接口的实现,可能用于在不同的操作模式之间切换
|
|
|
|
|
private ListEditState mState;
|
|
|
|
|
|
|
|
|
|
private BackgroundQueryHandler mBackgroundQueryHandler;
|
|
|
|
|
|
|
|
|
|
private NotesListAdapter mNotesListAdapter;
|
|
|
|
|
|
|
|
|
|
private ListView mNotesListView;
|
|
|
|
|
|
|
|
|
|
private Button mAddNewNote;
|
|
|
|
|
|
|
|
|
|
private boolean mDispatch;
|
|
|
|
|
|
|
|
|
|
private int mOriginY;
|
|
|
|
|
|
|
|
|
|
private int mDispatchY;
|
|
|
|
|
|
|
|
|
|
private TextView mTitleBar;
|
|
|
|
|
|
|
|
|
|
private long mCurrentFolderId;
|
|
|
|
|
|
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
|
|
|
|
|
|
|
private ModeCallback mModeCallBack;
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "NotesListActivity";
|
|
|
|
|
|
|
|
|
|
public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;
|
|
|
|
|
//正在关注的笔记数据对象
|
|
|
|
|
|
|
|
|
|
private NoteItemData mFocusNoteDataItem;
|
|
|
|
|
|
|
|
|
|
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
|
|
|
|
|
//拼接访问串
|
|
|
|
|
|
|
|
|
|
private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>"
|
|
|
|
|
+ Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)" + " OR ("
|
|
|
|
|
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER + " AND "
|
|
|
|
@ -124,22 +136,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
private final static int REQUEST_CODE_OPEN_NODE = 102;
|
|
|
|
|
private final static int REQUEST_CODE_NEW_NODE = 103;
|
|
|
|
|
//表示是否在私密模式
|
|
|
|
|
public static int secret_mode = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @classname: NotesListActivity
|
|
|
|
|
* @methodname onCreate
|
|
|
|
|
* @description:完成活动的初始化
|
|
|
|
|
* @date: 2024/1/4 11:47
|
|
|
|
|
* @author: Xia Yanbo
|
|
|
|
|
* @param:savedInstanceState保存的状态
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
//根据布局文件呈现菜单视图
|
|
|
|
|
setContentView(R.layout.note_list);
|
|
|
|
|
getWindow().setBackgroundDrawableResource(R.drawable.decade);//将decade作为初始背景
|
|
|
|
|
initResources();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -147,59 +149,32 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
*/
|
|
|
|
|
setAppInfoFromRawRes();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @classname: NotesListActivity
|
|
|
|
|
* @methodname onActivityResult
|
|
|
|
|
* @description:当从活动中得到返回调用,处理返回的结果
|
|
|
|
|
* @date: 2024/1/4 11:49
|
|
|
|
|
* @author: Xia Yanbo
|
|
|
|
|
* @param:requestCode请求码
|
|
|
|
|
* @param:resultCode结果码
|
|
|
|
|
* @param:data 意图的数据
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
// 根据请求的代码类型进行相应的处理
|
|
|
|
|
if (resultCode == RESULT_OK // 如果返回的结果码是RESULT_OK,表示操作成功
|
|
|
|
|
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) { // 并且请求码是打开节点或新建节点
|
|
|
|
|
// 清空笔记列表的适配器游标(可能是在执行打开或新建节点操作后,刷新或重置列表)
|
|
|
|
|
if (resultCode == RESULT_OK
|
|
|
|
|
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
|
|
|
|
|
mNotesListAdapter.changeCursor(null);
|
|
|
|
|
} else { // 其他情况
|
|
|
|
|
// 调用父类的onActivityResult方法,将结果传递给上层处理。
|
|
|
|
|
} else {
|
|
|
|
|
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对象,用于读取资源文件
|
|
|
|
|
InputStream in = null;
|
|
|
|
|
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;
|
|
|
|
@ -208,7 +183,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return;
|
|
|
|
|
} finally {
|
|
|
|
|
// 最后,关闭InputStream对象,释放资源
|
|
|
|
|
if(in != null) {
|
|
|
|
|
try {
|
|
|
|
|
in.close();
|
|
|
|
@ -218,17 +192,14 @@ 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;
|
|
|
|
|
}
|
|
|
|
@ -444,35 +415,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
private void startAsyncNotesListQuery() {
|
|
|
|
|
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
|
|
|
|
|
: NORMAL_SELECTION;
|
|
|
|
|
if(secret_mode == 0) {
|
|
|
|
|
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
|
|
|
|
|
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[]{
|
|
|
|
|
String.valueOf(mCurrentFolderId)
|
|
|
|
|
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
String str1 = "444";
|
|
|
|
|
String [] PROJECTION = new String [] { //定义一个新的PROJECTION数组,只换掉SNIPPET
|
|
|
|
|
NoteColumns.ID,
|
|
|
|
|
NoteColumns.ALERTED_DATE,
|
|
|
|
|
NoteColumns.BG_COLOR_ID,
|
|
|
|
|
NoteColumns.CREATED_DATE,
|
|
|
|
|
NoteColumns.HAS_ATTACHMENT,
|
|
|
|
|
NoteColumns.MODIFIED_DATE,
|
|
|
|
|
NoteColumns.NOTES_COUNT,
|
|
|
|
|
NoteColumns.PARENT_ID,
|
|
|
|
|
// NoteColumns.SNIPPET,
|
|
|
|
|
str1,
|
|
|
|
|
NoteColumns.TYPE,
|
|
|
|
|
NoteColumns.WIDGET_ID,
|
|
|
|
|
NoteColumns.WIDGET_TYPE,
|
|
|
|
|
};
|
|
|
|
|
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
|
|
|
|
|
Notes.CONTENT_NOTE_URI, PROJECTION, selection, new String[]{
|
|
|
|
|
String.valueOf(mCurrentFolderId)
|
|
|
|
|
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
|
|
|
|
|
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {
|
|
|
|
|
String.valueOf(mCurrentFolderId)
|
|
|
|
|
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final class BackgroundQueryHandler extends AsyncQueryHandler {
|
|
|
|
@ -829,16 +775,28 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
} else {
|
|
|
|
|
Log.e(TAG, "Wrong state:" + mState);
|
|
|
|
|
}
|
|
|
|
|
if(secret_mode == 1)
|
|
|
|
|
menu.findItem(R.id.menu_secret).setVisible(false);
|
|
|
|
|
else
|
|
|
|
|
menu.findItem(R.id.menu_quit_secret).setVisible(false);
|
|
|
|
|
|
|
|
|
|
if(mode==-1){//decade
|
|
|
|
|
menu.findItem(R.id.menu_decade).setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
else if(mode==1){//zio
|
|
|
|
|
menu.findItem(R.id.menu_zio).setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
if(item.getItemId()==R.id.menu_new_folder){
|
|
|
|
|
if(item.getItemId()==R.id.menu_decade){
|
|
|
|
|
mode = -1;
|
|
|
|
|
getWindow().setBackgroundDrawableResource(R.drawable.decade);
|
|
|
|
|
}
|
|
|
|
|
else if(item.getItemId()==R.id.menu_zio){
|
|
|
|
|
mode = 1;
|
|
|
|
|
getWindow().setBackgroundDrawableResource(R.drawable.zio);
|
|
|
|
|
}
|
|
|
|
|
else if(item.getItemId()==R.id.menu_new_folder){
|
|
|
|
|
showCreateOrModifyFolderDialog(true);
|
|
|
|
|
}
|
|
|
|
|
else if(item.getItemId()==R.id.menu_export_text ){
|
|
|
|
@ -865,53 +823,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
else if(item.getItemId()==R.id.menu_search) {
|
|
|
|
|
onSearchRequested();
|
|
|
|
|
}
|
|
|
|
|
else if(item.getItemId()==R.id.menu_secret)
|
|
|
|
|
{//进入私密模式
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
Toast.makeText(NotesListActivity.this,"您已进入私密模式",Toast.LENGTH_SHORT).show();
|
|
|
|
|
secret_mode = 1;
|
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which){}
|
|
|
|
|
});
|
|
|
|
|
dialog.show();
|
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if(item.getItemId()==R.id.menu_quit_secret)
|
|
|
|
|
{ //退出私密模式
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
secret_mode = 0;
|
|
|
|
|
Toast.makeText(NotesListActivity.this,"您已退出私密模式",Toast.LENGTH_SHORT).show();
|
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which){}
|
|
|
|
|
});
|
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -1049,16 +960,4 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void setSecretMode() {
|
|
|
|
|
if(secret_mode==0)
|
|
|
|
|
{
|
|
|
|
|
secret_mode=1;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
secret_mode=0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|