代码有加新的标注,上一次提交仅提交了文档,忘记更新src了

wlx_real_branch
王岚馨 1 year ago
parent f418039001
commit 21d41e3052

@ -24,7 +24,7 @@ import android.telephony.PhoneNumberUtils;
import android.util.Log; import android.util.Log;
import java.util.HashMap; import java.util.HashMap;
//联系人数据库
public class Contact { public class Contact {
private static HashMap<String, String> sContactCache; private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact"; private static final String TAG = "Contact";

@ -17,6 +17,7 @@
package com.example.notes_master.src.net.micode.notes.data; package com.example.notes_master.src.net.micode.notes.data;
import android.net.Uri; import android.net.Uri;
//便签数据库,用于记录便签相关属性和数据
public class Notes { public class Notes {
public static final String AUTHORITY = "micode_notes"; public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes"; public static final String TAG = "Notes";

@ -26,7 +26,7 @@ import com.example.notes_master.src.net.micode.notes.data.Notes.DataColumns;
import com.example.notes_master.src.net.micode.notes.data.Notes.DataConstants; import com.example.notes_master.src.net.micode.notes.data.Notes.DataConstants;
import com.example.notes_master.src.net.micode.notes.data.Notes.NoteColumns; import com.example.notes_master.src.net.micode.notes.data.Notes.NoteColumns;
//数据库帮助类,用于辅助创建、处理数据库的条目
public class NotesDatabaseHelper extends SQLiteOpenHelper { public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "note.db"; private static final String DB_NAME = "note.db";

@ -35,7 +35,7 @@ import com.example.notes_master.src.net.micode.notes.data.NotesDatabaseHelper.TA
import net.micode.notes.R; import net.micode.notes.R;
//便签信息提供类
public class NotesProvider extends ContentProvider { public class NotesProvider extends ContentProvider {
private static final UriMatcher mMatcher; private static final UriMatcher mMatcher;

@ -24,7 +24,7 @@ import com.example.notes_master.src.net.micode.notes.tool.GTaskStringUtils;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
//关于同步任务的元数据
public class MetaData extends Task { public class MetaData extends Task {
private final static String TAG = MetaData.class.getSimpleName(); private final static String TAG = MetaData.class.getSimpleName();

@ -19,7 +19,7 @@ package com.example.notes_master.src.net.micode.notes.gtask.data;
import android.database.Cursor; import android.database.Cursor;
import org.json.JSONObject; import org.json.JSONObject;
//同步任务的管理节点,用于设置、保存同步动作的信息
public abstract class Node { public abstract class Node {
public static final int SYNC_ACTION_NONE = 0; public static final int SYNC_ACTION_NONE = 0;

@ -34,7 +34,7 @@ import com.example.notes_master.src.net.micode.notes.gtask.exception.ActionFailu
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
//数据库中基本数据,方法包括读取数据、获取数据库中数据、提交数据到数据库
public class SqlData { public class SqlData {
private static final String TAG = SqlData.class.getSimpleName(); private static final String TAG = SqlData.class.getSimpleName();

@ -37,7 +37,7 @@ import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
//数据库中便签数据,方法包括读取便签内容、从数据库中获取便签数据、设置便签内容、提交便签到数据库
public class SqlNote { public class SqlNote {
private static final String TAG = SqlNote.class.getSimpleName(); private static final String TAG = SqlNote.class.getSimpleName();

@ -31,7 +31,7 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
//同步任务将创建、更新和同步动作包装成JSON对象用本地和远程的JSON对节点内容进行设置获取同步信息进行本地和远程的同步
public class Task extends Node { public class Task extends Node {
private static final String TAG = Task.class.getSimpleName(); private static final String TAG = Task.class.getSimpleName();

@ -29,7 +29,7 @@ import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
//同步任务列表将Task组织成同步任务列表进行管理
public class TaskList extends Node { public class TaskList extends Node {
private static final String TAG = TaskList.class.getSimpleName(); private static final String TAG = TaskList.class.getSimpleName();

@ -15,7 +15,7 @@
*/ */
package com.example.notes_master.src.net.micode.notes.gtask.exception; package com.example.notes_master.src.net.micode.notes.gtask.exception;
//动作失败异常
public class ActionFailureException extends RuntimeException { public class ActionFailureException extends RuntimeException {
private static final long serialVersionUID = 4425249765923293627L; private static final long serialVersionUID = 4425249765923293627L;

@ -15,7 +15,7 @@
*/ */
package com.example.notes_master.src.net.micode.notes.gtask.exception; package com.example.notes_master.src.net.micode.notes.gtask.exception;
//网络失败异常
public class NetworkFailureException extends Exception { public class NetworkFailureException extends Exception {
private static final long serialVersionUID = 2107610287180234136L; private static final long serialVersionUID = 2107610287180234136L;

@ -32,7 +32,7 @@ import com.example.notes_master.src.net.micode.notes.ui.NotesPreferenceActivity;
import net.micode.notes.R; import net.micode.notes.R;
//GTask异步任务方法包括任务同步和取消显示同步任务的进程、通知和结果
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> { public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
private static int GTASK_SYNC_NOTIFICATION_ID = 5234235; private static int GTASK_SYNC_NOTIFICATION_ID = 5234235;

@ -60,7 +60,7 @@ import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater; import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream; import java.util.zip.InflaterInputStream;
//GTask客户端提供登录Google账户创建任务和任务列表添加和删除节点提交、重置更新获取任务列表等功能
public class GTaskClient { public class GTaskClient {
private static final String TAG = GTaskClient.class.getSimpleName(); private static final String TAG = GTaskClient.class.getSimpleName();

@ -47,7 +47,7 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
//GTask管理者提供同步本地和远端的任务初始化任务列表同步内容、文件夹添加、更新本地和远端节点刷新本地同步任务ID等功能
public class GTaskManager { public class GTaskManager {
private static final String TAG = GTaskManager.class.getSimpleName(); private static final String TAG = GTaskManager.class.getSimpleName();

@ -22,7 +22,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
//GTask同步服务用于提供同步服务开始、取消同步发送广播
public class GTaskSyncService extends Service { public class GTaskSyncService extends Service {
public final static String ACTION_STRING_NAME = "sync_action_type"; public final static String ACTION_STRING_NAME = "sync_action_type";

@ -32,8 +32,7 @@ import com.example.notes_master.src.net.micode.notes.data.Notes.NoteColumns;
import com.example.notes_master.src.net.micode.notes.data.Notes.TextNote; import com.example.notes_master.src.net.micode.notes.data.Notes.TextNote;
import java.util.ArrayList; import java.util.ArrayList;
//单个便签项
public class Note { public class Note {
private ContentValues mNoteDiffValues; private ContentValues mNoteDiffValues;
private NoteData mNoteData; private NoteData mNoteData;

@ -31,7 +31,7 @@ import com.example.notes_master.src.net.micode.notes.data.Notes.NoteColumns;
import com.example.notes_master.src.net.micode.notes.data.Notes.TextNote; import com.example.notes_master.src.net.micode.notes.data.Notes.TextNote;
import com.example.notes_master.src.net.micode.notes.tool.ResourceParser.NoteBgResources; import com.example.notes_master.src.net.micode.notes.tool.ResourceParser.NoteBgResources;
//当前活动便签项
public class WorkingNote { public class WorkingNote {
// Note for the working note // Note for the working note
private Note mNote; private Note mNote;

@ -36,7 +36,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
//备份工具类,用于数据备份读取、显示
public class BackupUtils { public class BackupUtils {
private static final String TAG = "BackupUtils"; private static final String TAG = "BackupUtils";
// Singleton stuff // Singleton stuff

@ -34,7 +34,7 @@ import com.example.notes_master.src.net.micode.notes.ui.NotesListAdapter.AppWidg
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
//便签数据处理工具类,封装如查找、移动、删除数据等工作
public class DataUtils { public class DataUtils {
public static final String TAG = "DataUtils"; public static final String TAG = "DataUtils";
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) { public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {

@ -15,7 +15,7 @@
*/ */
package com.example.notes_master.src.net.micode.notes.tool; package com.example.notes_master.src.net.micode.notes.tool;
//同步中使用的字符串工具类为JSONObject提供string对象
public class GTaskStringUtils { public class GTaskStringUtils {
public final static String GTASK_JSON_ACTION_ID = "action_id"; public final static String GTASK_JSON_ACTION_ID = "action_id";

@ -22,7 +22,7 @@ import android.preference.PreferenceManager;
import com.example.notes_master.src.net.micode.notes.ui.NotesPreferenceActivity; import com.example.notes_master.src.net.micode.notes.ui.NotesPreferenceActivity;
import net.micode.notes.R; import net.micode.notes.R;
//界面元素的解析工具类利用R.java这个类获取资源供程序调用
public class ResourceParser { public class ResourceParser {
public static final int YELLOW = 0; public static final int YELLOW = 0;

@ -41,7 +41,7 @@ import net.micode.notes.R;
import java.io.IOException; import java.io.IOException;
//闹铃提醒界面
public class AlarmAlertActivity extends AppCompatActivity implements OnClickListener, OnDismissListener { public class AlarmAlertActivity extends AppCompatActivity implements OnClickListener, OnDismissListener {
private long mNoteId; private long mNoteId;
private String mSnippet; private String mSnippet;

@ -27,7 +27,7 @@ import android.database.Cursor;
import com.example.notes_master.src.net.micode.notes.data.Notes; import com.example.notes_master.src.net.micode.notes.data.Notes;
import com.example.notes_master.src.net.micode.notes.data.Notes.NoteColumns; import com.example.notes_master.src.net.micode.notes.data.Notes.NoteColumns;
//闹铃提醒启动消息接收器
public class AlarmInitReceiver extends BroadcastReceiver { public class AlarmInitReceiver extends BroadcastReceiver {
private static final String [] PROJECTION = new String [] { private static final String [] PROJECTION = new String [] {

@ -19,7 +19,7 @@ package com.example.notes_master.src.net.micode.notes.ui;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
//闹铃提醒接收器
public class AlarmReceiver extends BroadcastReceiver { public class AlarmReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {

@ -26,7 +26,7 @@ import net.micode.notes.R;
import java.text.DateFormatSymbols; import java.text.DateFormatSymbols;
import java.util.Calendar; import java.util.Calendar;
//设置提醒时间的部件
public class DateTimePicker extends FrameLayout { public class DateTimePicker extends FrameLayout {
private static final boolean DEFAULT_ENABLE_STATE = true; private static final boolean DEFAULT_ENABLE_STATE = true;

@ -28,7 +28,7 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import android.text.format.DateUtils; import android.text.format.DateUtils;
//设置提醒时间的对话框界面
public class DateTimePickerDialog extends AlertDialog implements OnClickListener { public class DateTimePickerDialog extends AlertDialog implements OnClickListener {
private Calendar mDate = Calendar.getInstance(); private Calendar mDate = Calendar.getInstance();

@ -26,7 +26,7 @@ import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.PopupMenu.OnMenuItemClickListener;
import net.micode.notes.R; import net.micode.notes.R;
//下拉菜单界面
public class DropdownMenu { public class DropdownMenu {
private Button mButton; private Button mButton;
private PopupMenu mPopupMenu; private PopupMenu mPopupMenu;

@ -29,7 +29,7 @@ import com.example.notes_master.src.net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.R; import net.micode.notes.R;
//文件夹列表适配器(链接数据库)
public class FoldersListAdapter extends CursorAdapter { public class FoldersListAdapter extends CursorAdapter {
public static final String [] PROJECTION = { public static final String [] PROJECTION = {
NoteColumns.ID, NoteColumns.ID,

@ -73,7 +73,7 @@ import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
//便签编辑活动
public class NoteEditActivity extends AppCompatActivity implements OnClickListener, public class NoteEditActivity extends AppCompatActivity implements OnClickListener,
NoteSettingChangedListener, OnTextViewChangeListener { NoteSettingChangedListener, OnTextViewChangeListener {
private class HeadViewHolder { private class HeadViewHolder {

@ -35,7 +35,7 @@ import net.micode.notes.R;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
//便签的文本编辑界面
public class NoteEditText extends androidx.appcompat.widget.AppCompatEditText { public class NoteEditText extends androidx.appcompat.widget.AppCompatEditText {
private static final String TAG = "NoteEditText"; private static final String TAG = "NoteEditText";
private int mIndex; private int mIndex;

@ -25,7 +25,7 @@ import com.example.notes_master.src.net.micode.notes.data.Notes;
import com.example.notes_master.src.net.micode.notes.data.Notes.NoteColumns; import com.example.notes_master.src.net.micode.notes.data.Notes.NoteColumns;
import com.example.notes_master.src.net.micode.notes.tool.DataUtils; import com.example.notes_master.src.net.micode.notes.tool.DataUtils;
//便签项数据
public class NoteItemData { public class NoteItemData {
static final String [] PROJECTION = new String [] { static final String [] PROJECTION = new String [] {
NoteColumns.ID, NoteColumns.ID,
@ -77,20 +77,20 @@ public class NoteItemData {
private boolean mIsMultiNotesFollowingFolder; private boolean mIsMultiNotesFollowingFolder;
public NoteItemData(Context context, Cursor cursor) { public NoteItemData(Context context, Cursor cursor) {
mId = cursor.getLong(ID_COLUMN); mId = cursor.getLong(ID_COLUMN);//0
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN); mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);//1
mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN); mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN);//2
mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN); mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN);//3
mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false; mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false;//4
mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN); mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN);//5
mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN); mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN);//6
mParentId = cursor.getLong(PARENT_ID_COLUMN); mParentId = cursor.getLong(PARENT_ID_COLUMN);//7
mSnippet = cursor.getString(SNIPPET_COLUMN); mSnippet = cursor.getString(SNIPPET_COLUMN);//8
mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace( mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace(
NoteEditActivity.TAG_UNCHECKED, ""); NoteEditActivity.TAG_UNCHECKED, "");
mType = cursor.getInt(TYPE_COLUMN); mType = cursor.getInt(TYPE_COLUMN);//9
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN); mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);//10
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN); mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);//11
mPhoneNumber = ""; mPhoneNumber = "";
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) { if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {

@ -13,9 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.example.notes_master.src.net.micode.notes.ui; package com.example.notes_master.src.net.micode.notes.ui;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
@ -80,78 +78,49 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.HashSet; import java.util.HashSet;
//主界面
public class NotesListActivity extends AppCompatActivity implements OnClickListener, OnItemLongClickListener { public class NotesListActivity extends AppCompatActivity implements OnClickListener, OnItemLongClickListener {
private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;//查询文件夹中的便签列表 private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;//查询文件夹中的便签列表
private static final int FOLDER_LIST_QUERY_TOKEN = 1;//查询文件夹列表 private static final int FOLDER_LIST_QUERY_TOKEN = 1;//查询文件夹列表
private static final int MENU_FOLDER_DELETE = 0;//删除文件夹
private static final int MENU_FOLDER_DELETE = 0; private static final int MENU_FOLDER_VIEW = 1;//查看文件夹
private static final int MENU_FOLDER_CHANGE_NAME = 2;//修改文件夹名字
private static final int MENU_FOLDER_VIEW = 1;
private static final int MENU_FOLDER_CHANGE_NAME = 2;
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction"; private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
private enum ListEditState { private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
}; };
private ListEditState mState; private ListEditState mState;
private BackgroundQueryHandler mBackgroundQueryHandler; private BackgroundQueryHandler mBackgroundQueryHandler;
private NotesListAdapter mNotesListAdapter; private NotesListAdapter mNotesListAdapter;
private ListView mNotesListView; private ListView mNotesListView;
private Button mAddNewNote; private Button mAddNewNote;
private boolean mDispatch; private boolean mDispatch;
private int mOriginY; private int mOriginY;
private int mDispatchY; private int mDispatchY;
private TextView mTitleBar; private TextView mTitleBar;
private long mCurrentFolderId; private long mCurrentFolderId;
private ContentResolver mContentResolver; private ContentResolver mContentResolver;
private ModeCallback mModeCallBack; private ModeCallback mModeCallBack;
private static final String TAG = "NotesListActivity";//打印日志时作标签
private static final String TAG = "NotesListActivity";
public static final int NOTES_LISTVIEW_SCROLL_RATE = 30; public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;
private NoteItemData mFocusNoteDataItem; private NoteItemData mFocusNoteDataItem;
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?"; private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>" private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>"
+ Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)" + " OR (" + Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)" + " OR ("
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER + " AND " + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER + " AND "
+ NoteColumns.NOTES_COUNT + ">0)"; + NoteColumns.NOTES_COUNT + ">0)";
private final static int REQUEST_CODE_OPEN_NODE = 102; private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103; private final static int REQUEST_CODE_NEW_NODE = 103;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.note_list); setContentView(R.layout.note_list);
initResources(); initResources();
/** /**
* Insert an introduction when user firstly use this application * Insert an introduction when user firstly use this application
*/ */
setAppInfoFromRawRes(); setAppInfoFromRawRes();
} }
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK if (resultCode == RESULT_OK
@ -161,14 +130,16 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
} }
} }
//当用户第一次使用小米便签时,把默认的欢迎便签保存到界面上
private void setAppInfoFromRawRes() { private void setAppInfoFromRawRes() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) { if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {//"net.micode.notes.introduction"
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
InputStream in = null; InputStream in = null;
// 把资源文件放到应用程序的/raw/raw下那么就可以在应用中使用getResources获取资源后,
// 以openRawResource方法不带后缀的资源文件名打开这个文件。
try { try {
in = getResources().openRawResource(R.raw.introduction); in = getResources().openRawResource(R.raw.introduction);//该文件内容Welcome to use MIUI notes!
if (in != null) { if (in != null) {
InputStreamReader isr = new InputStreamReader(in); InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr); BufferedReader br = new BufferedReader(isr);
@ -194,12 +165,13 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
} }
} }
} }
// 创建空的WorkingNote
WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER, WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE, AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
ResourceParser.RED); ResourceParser.RED);
note.setWorkingText(sb.toString()); note.setWorkingText(sb.toString());
if (note.saveNote()) { if (note.saveNote()) {
// 更新保存note的信息
sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit(); sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
} else { } else {
Log.e(TAG, "Save introduction note error"); Log.e(TAG, "Save introduction note error");
@ -207,18 +179,17 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
} }
} }
} }
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
startAsyncNotesListQuery(); startAsyncNotesListQuery();
} }
// 初始化资源
private void initResources() { private void initResources() {
mContentResolver = this.getContentResolver(); mContentResolver = this.getContentResolver();// 获取应用程序的数据,得到类似数据表的东西
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver()); mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
mCurrentFolderId = Notes.ID_ROOT_FOLDER;//0 mCurrentFolderId = Notes.ID_ROOT_FOLDER;//0
mNotesListView = (ListView) findViewById(R.id.notes_list); mNotesListView = (ListView) findViewById(R.id.notes_list);// 绑定XML中的ListView作为Item的容器
mNotesListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.note_list_footer, null), mNotesListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.note_list_footer, null),
null, false); null, false);
mNotesListView.setOnItemClickListener(new OnListItemClickListener());//单击监听器 mNotesListView.setOnItemClickListener(new OnListItemClickListener());//单击监听器
@ -236,16 +207,27 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
mModeCallBack = new ModeCallback(); mModeCallBack = new ModeCallback();
} }
//内部类 //内部类
/**
* `ModeCallback``ListView.MultiChoiceModeListener``OnMenuItemClickListener`
*
*/
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener { private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
private DropdownMenu mDropDownMenu; private DropdownMenu mDropDownMenu; // 下拉菜单对象
private ActionMode mActionMode; private ActionMode mActionMode; // 操作模式对象
private MenuItem mMoveMenu; private MenuItem mMoveMenu; // 移动菜单项对象
/**
*
* @param mode ActionMode
* @param menu
* @return true
*/
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
getMenuInflater().inflate(R.menu.note_list_options, menu);//通过调用 getMenuInflater().inflate() 方法加载菜单布局文件 R.menu.note_list_options //通过调用 getMenuInflater().inflate() 方法加载菜单布局文件 R.menu.note_list_options
// 并将菜单项添加到 menu 中。 // 并将菜单项添加到 menu 中。
menu.findItem(R.id.delete).setOnMenuItemClickListener(this); getMenuInflater().inflate(R.menu.note_list_options, menu); // 加载菜单布局文件
mMoveMenu = menu.findItem(R.id.move); menu.findItem(R.id.delete).setOnMenuItemClickListener(this); // 设置删除菜单项的点击监听器
mMoveMenu = menu.findItem(R.id.move); // 获取移动菜单项
// 根据条件设置移动菜单项的可见性和点击监听器
if (mFocusNoteDataItem.getParentId() == Notes.ID_CALL_RECORD_FOLDER if (mFocusNoteDataItem.getParentId() == Notes.ID_CALL_RECORD_FOLDER
|| DataUtils.getUserFolderCount(mContentResolver) == 0) { || DataUtils.getUserFolderCount(mContentResolver) == 0) {
mMoveMenu.setVisible(false); mMoveMenu.setVisible(false);
@ -254,33 +236,32 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
mMoveMenu.setOnMenuItemClickListener(this); mMoveMenu.setOnMenuItemClickListener(this);
} }
mActionMode = mode; mActionMode = mode;
mNotesListAdapter.setChoiceMode(true);//设置列表适配器的选择模式为 true以启用多选模式 mNotesListAdapter.setChoiceMode(true); // 设置列表适配器的选择模式为多选模式
mNotesListView.setLongClickable(false);//将列表视图的长按点击功能禁用。 mNotesListView.setLongClickable(false); // 禁用列表视图的长按点击功能
mAddNewNote.setVisibility(View.GONE); mAddNewNote.setVisibility(View.GONE); // 设置添加新笔记按钮不可见
// 创建自定义视图并设置给操作模式
View customView = LayoutInflater.from(NotesListActivity.this).inflate( View customView = LayoutInflater.from(NotesListActivity.this)
R.layout.note_list_dropdown_menu, null); .inflate(R.layout.note_list_dropdown_menu, null);
mode.setCustomView(customView); mode.setCustomView(customView);
// 创建下拉菜单对象并设置下拉菜单项的点击监听器
mDropDownMenu = new DropdownMenu(NotesListActivity.this, mDropDownMenu = new DropdownMenu(NotesListActivity.this,
(Button) customView.findViewById(R.id.selection_menu), (Button) customView.findViewById(R.id.selection_menu),
R.menu.note_list_dropdown); R.menu.note_list_dropdown);
mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){ mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected()); mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
updateMenu(); updateMenu();
return true; return true;
} }
}); });
return true; return true;
} }
/** /**
* *
*/ */
private void updateMenu() { private void updateMenu() {
int selectedCount = mNotesListAdapter.getSelectedCount();//多选时选的项数 int selectedCount = mNotesListAdapter.getSelectedCount(); // 获取选中的项数
// Update dropdown menu // 更新下拉菜单标题
String format = getResources().getString(R.string.menu_select_title, selectedCount);//第二个参数是换第一个参数的占位符的 String format = getResources().getString(R.string.menu_select_title, selectedCount);//第二个参数是换第一个参数的占位符的
mDropDownMenu.setTitle(format); mDropDownMenu.setTitle(format);
MenuItem item = mDropDownMenu.findItem(R.id.action_select_all); MenuItem item = mDropDownMenu.findItem(R.id.action_select_all);
@ -294,49 +275,64 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
} }
} }
} }
/**
*
* @param mode ActionMode
* @param menu
* @return true
*/
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub // TODO: 添加准备操作模式的逻辑(如果有的话)
return false; return false;
} }
/**
*
* @param mode ActionMode
* @param item
* @return true
*/
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// TODO Auto-generated method stub // TODO: 处理菜单项的点击事件
return false; return false;
} }
/**
*
* @param mode ActionMode
*/
public void onDestroyActionMode(ActionMode mode) { public void onDestroyActionMode(ActionMode mode) {
mNotesListAdapter.setChoiceMode(false); mNotesListAdapter.setChoiceMode(false); // 取消多选模式
mNotesListView.setLongClickable(true); mNotesListView.setLongClickable(true); // 启用列表视图的长按点击功能
mAddNewNote.setVisibility(View.VISIBLE); mAddNewNote.setVisibility(View.VISIBLE); // 设置添加新笔记按钮可见
} }
/**
* 退
*/
public void finishActionMode() { public void finishActionMode() {
mActionMode.finish(); mActionMode.finish();
} }
/** /**
* hashmapvalueboolean * HashMap
* @param mode The {@link ActionMode} providing the selection mode * @param mode ActionMode
* @param position Adapter position of the item that was checked or unchecked * @param position
* @param id Adapter ID of the item that was checked or unchecked * @param id ID
* @param checked <code>true</code> if the item is now checked, <code>false</code> * @param checked truefalse
* if the item is now unchecked.
*/ */
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
boolean checked) {
mNotesListAdapter.setCheckedItem(position, checked); mNotesListAdapter.setCheckedItem(position, checked);
updateMenu(); updateMenu();
} }
/**
*
* @param item
* @return true
*/
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
if (mNotesListAdapter.getSelectedCount() == 0) { if (mNotesListAdapter.getSelectedCount() == 0) {
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none), Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
Toast.LENGTH_SHORT).show();//没有选中项,操作无效 Toast.LENGTH_SHORT).show(); // 如果没有选中项,显示提示消息
return true; return true;
} }
switch (item.getItemId()) {
switch (item.getItemId()) {//选中的下拉菜单中的菜单项
case R.id.delete: case R.id.delete:
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(getString(R.string.alert_title_delete)); builder.setTitle(getString(R.string.alert_title_delete));
@ -362,12 +358,12 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
return true; return true;
} }
} }
private class NewNoteOnTouchListener implements OnTouchListener { private class NewNoteOnTouchListener implements OnTouchListener {
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) { switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: { case MotionEvent.ACTION_DOWN: {
// 获取屏幕显示
Display display = getWindowManager().getDefaultDisplay(); Display display = getWindowManager().getDefaultDisplay();
int screenHeight = display.getHeight(); int screenHeight = display.getHeight();
int newNoteViewHeight = mAddNewNote.getHeight(); int newNoteViewHeight = mAddNewNote.getHeight();
@ -376,6 +372,7 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
/** /**
* Minus TitleBar's height * Minus TitleBar's height
*/ */
// 如果当前状态是ListEditState.SUB_FOLDER则减去标题栏的高度
if (mState == ListEditState.SUB_FOLDER) { if (mState == ListEditState.SUB_FOLDER) {
eventY -= mTitleBar.getHeight(); eventY -= mTitleBar.getHeight();
start -= mTitleBar.getHeight(); start -= mTitleBar.getHeight();
@ -389,6 +386,7 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
* Notice that, if the background of the button changes, the formula should * Notice that, if the background of the button changes, the formula should
* also change. This is very bad, just for the UI designer's strong requirement. * also change. This is very bad, just for the UI designer's strong requirement.
*/ */
// 如果点击的是"New Note"按钮的透明部分(根据特定的公式判断),则将事件分发给按钮后面的列表视图
if (event.getY() < (event.getX() * (-0.12) + 94)) { if (event.getY() < (event.getX() * (-0.12) + 94)) {
View view = mNotesListView.getChildAt(mNotesListView.getChildCount() - 1 View view = mNotesListView.getChildAt(mNotesListView.getChildCount() - 1
- mNotesListView.getFooterViewsCount()); - mNotesListView.getFooterViewsCount());
@ -404,6 +402,7 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
break; break;
} }
case MotionEvent.ACTION_MOVE: { case MotionEvent.ACTION_MOVE: {
// 如果之前已经进行了事件分发,则根据手指移动的距离更新事件的位置,并将事件继续分发给列表视图
if (mDispatch) { if (mDispatch) {
mDispatchY += (int) event.getY() - mOriginY; mDispatchY += (int) event.getY() - mOriginY;
event.setLocation(event.getX(), mDispatchY); event.setLocation(event.getX(), mDispatchY);
@ -412,6 +411,7 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
break; break;
} }
default: { default: {
// 如果之前已经进行了事件分发,则将事件的位置更新,并停止事件的分发
if (mDispatch) { if (mDispatch) {
event.setLocation(event.getX(), mDispatchY); event.setLocation(event.getX(), mDispatchY);
mDispatch = false; mDispatch = false;
@ -422,18 +422,22 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
} }
return false; return false;
} }
}
};
private void startAsyncNotesListQuery() { private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION // 检查当前文件夹ID是否为根文件夹ID确定查询的条件
: NORMAL_SELECTION; String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION : NORMAL_SELECTION;
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null, // 使用BackgroundQueryHandler开始异步查询
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] { // 参数1查询令牌用于标识查询的唯一性
String.valueOf(mCurrentFolderId) // 参数2对象用于传递额外的数据给查询结果的回调方法
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC"); // 参数3查询的URI指定要查询的数据表的内容URI
// 参数4查询的投影指定要查询的列
// 参数5查询的选择条件
// 参数6选择条件中的占位符的值
// 参数7查询的排序方式
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");
} }
/* /*
线 线
@ -442,7 +446,6 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
public BackgroundQueryHandler(ContentResolver contentResolver) { public BackgroundQueryHandler(ContentResolver contentResolver) {
super(contentResolver); super(contentResolver);
} }
/** /**
* token * token
* cookie * cookie
@ -470,7 +473,6 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
} }
} }
} }
private void showFolderListMenu(Cursor cursor) { private void showFolderListMenu(Cursor cursor) {
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(R.string.menu_title_select_folder);//选择文件夹 builder.setTitle(R.string.menu_title_select_folder);//选择文件夹
@ -491,38 +493,39 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
}); });
builder.show(); builder.show();
} }
private void createNewNote() { private void createNewNote() {
// 创建一个Intent对象指定目标为NoteEditActivity并设置操作为ACTION_INSERT_OR_EDIT
Intent intent = new Intent(this, NoteEditActivity.class); Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_INSERT_OR_EDIT); intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
// 将当前文件夹ID作为额外的INTENT_EXTRA_FOLDER_ID数据传递给Intent
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mCurrentFolderId); intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mCurrentFolderId);
// 启动NoteEditActivity并获取结果
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE); this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
} }
private void batchDelete() { private void batchDelete() {
// 创建一个异步任务
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() { new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) { protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
// 获取选中笔记项关联的小部件信息
HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget(); HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget();
if (!isSyncMode()) { if (!isSyncMode()) {
// if not synced, delete notes directly // 如果不处于同步模式,直接删除选中的笔记
if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter.getSelectedItemIds())) {
.getSelectedItemIds())) { // 删除成功
} else { } else {
Log.e(TAG, "Delete notes error, should not happens"); Log.e(TAG, "Delete notes error, should not happens");
} }
} else { } else {
// in sync mode, we'll move the deleted note into the trash // 如果处于同步模式,将选中的笔记移动到回收站文件夹
// folder if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter.getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
.getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
Log.e(TAG, "Move notes to trash folder error, should not happens"); Log.e(TAG, "Move notes to trash folder error, should not happens");
} }
} }
return widgets; return widgets;
} }
@Override @Override
protected void onPostExecute(HashSet<AppWidgetAttribute> widgets) { protected void onPostExecute(HashSet<AppWidgetAttribute> widgets) {
// 更新与选中笔记关联的小部件
if (widgets != null) { if (widgets != null) {
for (AppWidgetAttribute widget : widgets) { for (AppWidgetAttribute widget : widgets) {
if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
@ -531,28 +534,30 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
} }
} }
} }
// 完成操作模式,退出多选模式
mModeCallBack.finishActionMode(); mModeCallBack.finishActionMode();
} }
}.execute(); }.execute();
} }
private void deleteFolder(long folderId) { private void deleteFolder(long folderId) {
// 检查文件夹ID是否为根文件夹的ID如果是则记录错误日志并返回
if (folderId == Notes.ID_ROOT_FOLDER) { if (folderId == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Wrong folder id, should not happen " + folderId); Log.e(TAG, "Wrong folder id, should not happen " + folderId);
return; return;
} }
// 创建HashSet来存储要删除的文件夹ID
HashSet<Long> ids = new HashSet<Long>(); HashSet<Long> ids = new HashSet<Long>();
ids.add(folderId); ids.add(folderId);
HashSet<AppWidgetAttribute> widgets = DataUtils.getFolderNoteWidget(mContentResolver, // 获取与文件夹关联的小部件信息
folderId); HashSet<AppWidgetAttribute> widgets = DataUtils.getFolderNoteWidget(mContentResolver, folderId);
// 如果不处于同步模式,直接删除文件夹
if (!isSyncMode()) { if (!isSyncMode()) {
// if not synced, delete folder directly
DataUtils.batchDeleteNotes(mContentResolver, ids); DataUtils.batchDeleteNotes(mContentResolver, ids);
} else { } else {
// in sync mode, we'll move the deleted folder into the trash folder // 在同步模式下,将被删除的文件夹移动到回收站文件夹
DataUtils.batchMoveToFolder(mContentResolver, ids, Notes.ID_TRASH_FOLER); DataUtils.batchMoveToFolder(mContentResolver, ids, Notes.ID_TRASH_FOLER);
} }
// 更新与该文件夹关联的小部件
if (widgets != null) { if (widgets != null) {
for (AppWidgetAttribute widget : widgets) { for (AppWidgetAttribute widget : widgets) {
if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
@ -562,63 +567,75 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
} }
} }
} }
private void openNode(NoteItemData data) { private void openNode(NoteItemData data) {
// 创建一个Intent对象指定目标为NoteEditActivity并设置操作为ACTION_VIEW
Intent intent = new Intent(this, NoteEditActivity.class); Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW);
// 将笔记项的ID作为额外的UID数据传递给Intent
intent.putExtra(Intent.EXTRA_UID, data.getId()); intent.putExtra(Intent.EXTRA_UID, data.getId());
// 启动NoteEditActivity并获取结果
this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE); this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
} }
private void openFolder(NoteItemData data) { private void openFolder(NoteItemData data) {
// 将当前文件夹ID设置为给定数据项的ID
mCurrentFolderId = data.getId(); mCurrentFolderId = data.getId();
// 启动异步查询以获取当前文件夹下的笔记列表
startAsyncNotesListQuery(); startAsyncNotesListQuery();
// 根据文件夹ID设置状态和标题栏的文本
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) { if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
mState = ListEditState.CALL_RECORD_FOLDER; mState = ListEditState.CALL_RECORD_FOLDER;
mAddNewNote.setVisibility(View.GONE); mAddNewNote.setVisibility(View.GONE);
} else {
mState = ListEditState.SUB_FOLDER;
}
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
mTitleBar.setText(R.string.call_record_folder_name); mTitleBar.setText(R.string.call_record_folder_name);
} else { } else {
mState = ListEditState.SUB_FOLDER;
mTitleBar.setText(data.getSnippet()); mTitleBar.setText(data.getSnippet());
} }
// 显示标题栏
mTitleBar.setVisibility(View.VISIBLE); mTitleBar.setVisibility(View.VISIBLE);
} }
public void onClick(View v) { public void onClick(View v) {
switch (v.getId()) { switch (v.getId()) {
case R.id.btn_new_note: case R.id.btn_new_note:
// 点击“新建笔记”按钮时调用createNewNote()方法
createNewNote(); createNewNote();
break; break;
default: default:
break; break;
} }
} }
private void showSoftInput() { private void showSoftInput() {
// 获取输入法管理器实例
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// 检查输入法管理器是否为空
if (inputMethodManager != null) { if (inputMethodManager != null) {
// 切换显示软键盘
// 参数1显示软键盘的标志使用SHOW_FORCED表示强制显示
// 参数2指定额外的标志此处为0
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
} }
} }
private void hideSoftInput(View view) { private void hideSoftInput(View view) {
// 获取输入法管理器实例
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// 隐藏软键盘
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
} }
private void showCreateOrModifyFolderDialog(final boolean create) { private void showCreateOrModifyFolderDialog(final boolean create) {
// 创建AlertDialog.Builder实例
final AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog.Builder builder = new AlertDialog.Builder(this);
// 加载布局文件dialog_edit_text.xml作为对话框的内容视图
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null); View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
// 获取布局文件中的EditText控件
final EditText etName = (EditText) view.findViewById(R.id.et_foler_name); final EditText etName = (EditText) view.findViewById(R.id.et_foler_name);
// 显示软键盘
showSoftInput(); showSoftInput();
// 根据create参数确定对话框的标题和EditText的初始文本
if (!create) { if (!create) {
if (mFocusNoteDataItem != null) { if (mFocusNoteDataItem != null) {
etName.setText(mFocusNoteDataItem.getSnippet()); etName.setText(mFocusNoteDataItem.getSnippet());
builder.setTitle(getString(R.string.menu_folder_change_name)); builder.setTitle(getString(R.string.menu_folder_change_name));
} else { } else {
// 如果长按的数据项mFocusNoteDataItem为null记录错误日志并返回
Log.e(TAG, "The long click data item is null"); Log.e(TAG, "The long click data item is null");
return; return;
} }
@ -626,27 +643,35 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
etName.setText(""); etName.setText("");
builder.setTitle(this.getString(R.string.menu_create_folder)); builder.setTitle(this.getString(R.string.menu_create_folder));
} }
// 设置对话框的确定按钮
builder.setPositiveButton(android.R.string.ok, null); builder.setPositiveButton(android.R.string.ok, null);
// 设置对话框的取消按钮,并在点击时隐藏软键盘
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
hideSoftInput(etName); hideSoftInput(etName);
} }
}); });
// 创建对话框并显示
final Dialog dialog = builder.setView(view).show(); final Dialog dialog = builder.setView(view).show();
// 获取对话框中的确定按钮
final Button positive = (Button)dialog.findViewById(android.R.id.button1); final Button positive = (Button)dialog.findViewById(android.R.id.button1);
// 设置确定按钮的点击事件监听器
positive.setOnClickListener(new OnClickListener() { positive.setOnClickListener(new OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
// 隐藏软键盘
hideSoftInput(etName); hideSoftInput(etName);
// 获取输入的文件夹名称
String name = etName.getText().toString(); String name = etName.getText().toString();
// 检查文件夹名称是否已存在
if (DataUtils.checkVisibleFolderName(mContentResolver, name)) { if (DataUtils.checkVisibleFolderName(mContentResolver, name)) {
Toast.makeText(NotesListActivity.this, getString(R.string.folder_exist, name), Toast.makeText(NotesListActivity.this, getString(R.string.folder_exist, name),
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
etName.setSelection(0, etName.length()); etName.setSelection(0, etName.length());
return; return;
} }
// 根据create参数确定是修改文件夹还是创建新文件夹
if (!create) { if (!create) {
// 修改文件夹
if (!TextUtils.isEmpty(name)) { if (!TextUtils.isEmpty(name)) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(NoteColumns.SNIPPET, name); values.put(NoteColumns.SNIPPET, name);
@ -658,27 +683,25 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
}); });
} }
} else if (!TextUtils.isEmpty(name)) { } else if (!TextUtils.isEmpty(name)) {
// 创建新文件夹
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(NoteColumns.SNIPPET, name); values.put(NoteColumns.SNIPPET, name);
values.put(NoteColumns.TYPE, Notes.TYPE_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
mContentResolver.insert(Notes.CONTENT_NOTE_URI, values); mContentResolver.insert(Notes.CONTENT_NOTE_URI, values);
} }
// 关闭对话框
dialog.dismiss(); dialog.dismiss();
} }
}); });
// 如果EditText的文本为空禁用确定按钮
if (TextUtils.isEmpty(etName.getText())) { if (TextUtils.isEmpty(etName.getText())) {
positive.setEnabled(false); positive.setEnabled(false);
} }
/** // EditText文本改变时根据文本是否为空来启用或禁用确定按钮
* When the name edit text is null, disable the positive button
*/
etName.addTextChangedListener(new TextWatcher() { etName.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
if (TextUtils.isEmpty(etName.getText())) { if (TextUtils.isEmpty(etName.getText())) {
positive.setEnabled(false); positive.setEnabled(false);
@ -686,24 +709,27 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
positive.setEnabled(true); positive.setEnabled(true);
} }
} }
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
}); });
} }
/**
*
*/
@Override @Override
public void onBackPressed() { public void onBackPressed() {
// 根据当前的状态进行处理
switch (mState) { switch (mState) {
case SUB_FOLDER: case SUB_FOLDER:
// 如果当前状态是SUB_FOLDER则回退到根文件夹
mCurrentFolderId = Notes.ID_ROOT_FOLDER; mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST; mState = ListEditState.NOTE_LIST;
startAsyncNotesListQuery(); startAsyncNotesListQuery();
mTitleBar.setVisibility(View.GONE); mTitleBar.setVisibility(View.GONE);
break; break;
case CALL_RECORD_FOLDER: case CALL_RECORD_FOLDER:
// 如果当前状态是CALL_RECORD_FOLDER则回退到根文件夹
mCurrentFolderId = Notes.ID_ROOT_FOLDER; mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST; mState = ListEditState.NOTE_LIST;
mAddNewNote.setVisibility(View.VISIBLE); mAddNewNote.setVisibility(View.VISIBLE);
@ -711,62 +737,73 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
startAsyncNotesListQuery(); startAsyncNotesListQuery();
break; break;
case NOTE_LIST: case NOTE_LIST:
// 如果当前状态是NOTE_LIST则调用父类的onBackPressed方法
super.onBackPressed(); super.onBackPressed();
break; break;
default: default:
break; break;
} }
} }
private void updateWidget(int appWidgetId, int appWidgetType) { private void updateWidget(int appWidgetId, int appWidgetType) {
// 创建一个广播意图,用于更新小部件
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
// 根据小部件类型设置接收广播的类
if (appWidgetType == Notes.TYPE_WIDGET_2X) { if (appWidgetType == Notes.TYPE_WIDGET_2X) {
intent.setClass(this, NoteWidgetProvider_2x.class); intent.setClass(this, NoteWidgetProvider_2x.class);
} else if (appWidgetType == Notes.TYPE_WIDGET_4X) { } else if (appWidgetType == Notes.TYPE_WIDGET_4X) {
intent.setClass(this, NoteWidgetProvider_4x.class); intent.setClass(this, NoteWidgetProvider_4x.class);
} else { } else {
// 未支持的小部件类型,记录错误日志并返回
Log.e(TAG, "Unspported widget type"); Log.e(TAG, "Unspported widget type");
return; return;
} }
// 将小部件ID作为额外数据添加到意图中
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
appWidgetId appWidgetId
}); });
// 发送广播意图,通知小部件进行更新
sendBroadcast(intent); sendBroadcast(intent);
// 设置结果为RESULT_OK表示更新小部件成功
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
} }
private final OnCreateContextMenuListener mFolderOnCreateContextMenuListener = new OnCreateContextMenuListener() { private final OnCreateContextMenuListener mFolderOnCreateContextMenuListener = new OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
// 检查当前焦点的笔记数据项是否为null
if (mFocusNoteDataItem != null) { if (mFocusNoteDataItem != null) {
// 设置上下文菜单的标题为焦点笔记数据项的摘要
menu.setHeaderTitle(mFocusNoteDataItem.getSnippet()); menu.setHeaderTitle(mFocusNoteDataItem.getSnippet());
// 添加菜单项到上下文菜单
// 参数解释:(groupId, itemId, order, title)
menu.add(0, MENU_FOLDER_VIEW, 0, R.string.menu_folder_view); menu.add(0, MENU_FOLDER_VIEW, 0, R.string.menu_folder_view);
menu.add(0, MENU_FOLDER_DELETE, 0, R.string.menu_folder_delete); menu.add(0, MENU_FOLDER_DELETE, 0, R.string.menu_folder_delete);
menu.add(0, MENU_FOLDER_CHANGE_NAME, 0, R.string.menu_folder_change_name); menu.add(0, MENU_FOLDER_CHANGE_NAME, 0, R.string.menu_folder_change_name);
} }
} }
}; };
@Override @Override
public void onContextMenuClosed(Menu menu) { public void onContextMenuClosed(Menu menu) {
// 当上下文菜单关闭时调用该方法
if (mNotesListView != null) { if (mNotesListView != null) {
// 将mNotesListView的OnCreateContextMenuListener设置为null以取消菜单监听器
mNotesListView.setOnCreateContextMenuListener(null); mNotesListView.setOnCreateContextMenuListener(null);
} }
super.onContextMenuClosed(menu); super.onContextMenuClosed(menu);
} }
@Override @Override
public boolean onContextItemSelected(MenuItem item) { public boolean onContextItemSelected(MenuItem item) {
// 当上下文菜单项被选中时调用该方法
if (mFocusNoteDataItem == null) { if (mFocusNoteDataItem == null) {
// 检查焦点笔记数据项是否为null
Log.e(TAG, "The long click data item is null"); Log.e(TAG, "The long click data item is null");
return false; return false;
} }
switch (item.getItemId()) { switch (item.getItemId()) {
case MENU_FOLDER_VIEW: case MENU_FOLDER_VIEW:
// 如果选中的菜单项是MENU_FOLDER_VIEW则打开文件夹
openFolder(mFocusNoteDataItem); openFolder(mFocusNoteDataItem);
break; break;
case MENU_FOLDER_DELETE: case MENU_FOLDER_DELETE:
// 如果选中的菜单项是MENU_FOLDER_DELETE则显示删除文件夹的对话框
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.alert_title_delete)); builder.setTitle(getString(R.string.alert_title_delete));
builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setIcon(android.R.drawable.ic_dialog_alert);
@ -781,65 +818,80 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
builder.show(); builder.show();
break; break;
case MENU_FOLDER_CHANGE_NAME: case MENU_FOLDER_CHANGE_NAME:
// 如果选中的菜单项是MENU_FOLDER_CHANGE_NAME则显示创建或修改文件夹的对话框
showCreateOrModifyFolderDialog(false); showCreateOrModifyFolderDialog(false);
break; break;
default: default:
break; break;
} }
return true; return true;
} }
@Override @Override
public boolean onPrepareOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear(); // 当准备显示选项菜单时调用该方法
menu.clear(); // 清空菜单项
// 根据当前状态mState选择要显示的菜单项
if (mState == ListEditState.NOTE_LIST) { if (mState == ListEditState.NOTE_LIST) {
// 如果状态为NOTE_LIST则从资源文件中填充note_list菜单项
getMenuInflater().inflate(R.menu.note_list, menu); getMenuInflater().inflate(R.menu.note_list, menu);
// set sync or sync_cancel // 根据同步状态设置菜单项的标题为“sync”或“sync_cancel”
menu.findItem(R.id.menu_sync).setTitle( menu.findItem(R.id.menu_sync).setTitle(
GTaskSyncService.isSyncing() ? R.string.menu_sync_cancel : R.string.menu_sync); GTaskSyncService.isSyncing() ? R.string.menu_sync_cancel : R.string.menu_sync);
} else if (mState == ListEditState.SUB_FOLDER) { } else if (mState == ListEditState.SUB_FOLDER) {
// 如果状态为SUB_FOLDER则从资源文件中填充sub_folder菜单项
getMenuInflater().inflate(R.menu.sub_folder, menu); getMenuInflater().inflate(R.menu.sub_folder, menu);
} else if (mState == ListEditState.CALL_RECORD_FOLDER) { } else if (mState == ListEditState.CALL_RECORD_FOLDER) {
// 如果状态为CALL_RECORD_FOLDER则从资源文件中填充call_record_folder菜单项
getMenuInflater().inflate(R.menu.call_record_folder, menu); getMenuInflater().inflate(R.menu.call_record_folder, menu);
} else { } else {
// 如果状态不是上述已定义的状态,则记录错误日志
Log.e(TAG, "Wrong state:" + mState); Log.e(TAG, "Wrong state:" + mState);
} }
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
// 当选项菜单项被选中时调用该方法
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.menu_new_folder: { case R.id.menu_new_folder: {
// 如果选中的菜单项是menu_new_folder则显示创建或修改文件夹的对话框
showCreateOrModifyFolderDialog(true); showCreateOrModifyFolderDialog(true);
break; break;
} }
case R.id.menu_export_text: { case R.id.menu_export_text: {
// 如果选中的菜单项是menu_export_text则导出笔记为文本文件
exportNoteToText(); exportNoteToText();
break; break;
} }
case R.id.menu_sync: { case R.id.menu_sync: {
// 如果选中的菜单项是menu_sync则根据同步模式进行相应操作
if (isSyncMode()) { if (isSyncMode()) {
if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) { if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) {
// 如果菜单项标题为"menu_sync",则启动同步服务
GTaskSyncService.startSync(this); GTaskSyncService.startSync(this);
} else { } else {
// 如果菜单项标题为"menu_sync_cancel",则取消同步服务
GTaskSyncService.cancelSync(this); GTaskSyncService.cancelSync(this);
} }
} else { } else {
// 如果不是同步模式,则启动首选项活动
startPreferenceActivity(); startPreferenceActivity();
} }
break; break;
} }
case R.id.menu_setting: { case R.id.menu_setting: {
// 如果选中的菜单项是menu_setting则启动首选项活动
startPreferenceActivity(); startPreferenceActivity();
break; break;
} }
case R.id.menu_new_note: { case R.id.menu_new_note: {
// 如果选中的菜单项是menu_new_note则创建新的笔记
createNewNote(); createNewNote();
break; break;
} }
case R.id.menu_search: case R.id.menu_search:
// 如果选中的菜单项是menu_search则启动搜索
onSearchRequested(); onSearchRequested();
break; break;
default: default:
@ -847,67 +899,61 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
} }
return true; return true;
} }
@Override @Override
public boolean onSearchRequested() { public boolean onSearchRequested() {
startSearch(null, false, null /* appData */, false); // 当搜索请求时调用该方法
startSearch(null, false, null /* appData */, false); // 启动搜索
return true; return true;
} }
private void exportNoteToText() { private void exportNoteToText() {
// 获取BackupUtils的实例
final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this); final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
// 创建一个异步任务
new AsyncTask<Void, Void, Integer>() { new AsyncTask<Void, Void, Integer>() {
@Override @Override
protected Integer doInBackground(Void... unused) { protected Integer doInBackground(Void... unused) {
// 在后台线程中执行导出笔记为文本的操作
return backup.exportToText(); return backup.exportToText();
} }
@Override @Override
protected void onPostExecute(Integer result) { protected void onPostExecute(Integer result) {
// 在后台线程执行完毕后,在主线程中根据导出结果显示相应的对话框
if (result == BackupUtils.STATE_SD_CARD_UNMOUONTED) { if (result == BackupUtils.STATE_SD_CARD_UNMOUONTED) {
// 如果导出失败SD卡未挂载则显示失败对话框
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(NotesListActivity.this builder.setTitle(NotesListActivity.this.getString(R.string.failed_sdcard_export));
.getString(R.string.failed_sdcard_export)); builder.setMessage(NotesListActivity.this.getString(R.string.error_sdcard_unmounted));
builder.setMessage(NotesListActivity.this
.getString(R.string.error_sdcard_unmounted));
builder.setPositiveButton(android.R.string.ok, null); builder.setPositiveButton(android.R.string.ok, null);
builder.show(); builder.show();
} else if (result == BackupUtils.STATE_SUCCESS) { } else if (result == BackupUtils.STATE_SUCCESS) {
// 如果导出成功,则显示成功对话框,并显示导出的文件位置
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(NotesListActivity.this builder.setTitle(NotesListActivity.this.getString(R.string.success_sdcard_export));
.getString(R.string.success_sdcard_export));
builder.setMessage(NotesListActivity.this.getString( builder.setMessage(NotesListActivity.this.getString(
R.string.format_exported_file_location, backup R.string.format_exported_file_location, backup.getExportedTextFileName(),
.getExportedTextFileName(), backup.getExportedTextFileDir())); backup.getExportedTextFileDir()));
builder.setPositiveButton(android.R.string.ok, null); builder.setPositiveButton(android.R.string.ok, null);
builder.show(); builder.show();
} else if (result == BackupUtils.STATE_SYSTEM_ERROR) { } else if (result == BackupUtils.STATE_SYSTEM_ERROR) {
// 如果导出失败,发生系统错误,则显示失败对话框
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(NotesListActivity.this builder.setTitle(NotesListActivity.this.getString(R.string.failed_sdcard_export));
.getString(R.string.failed_sdcard_export)); builder.setMessage(NotesListActivity.this.getString(R.string.error_sdcard_export));
builder.setMessage(NotesListActivity.this
.getString(R.string.error_sdcard_export));
builder.setPositiveButton(android.R.string.ok, null); builder.setPositiveButton(android.R.string.ok, null);
builder.show(); builder.show();
} }
} }
}.execute(); // 执行异步任务
}.execute();
} }
private boolean isSyncMode() { private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0; return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
} }
private void startPreferenceActivity() { private void startPreferenceActivity() {
Activity from = getParent() != null ? getParent() : this; Activity from = getParent() != null ? getParent() : this;
Intent intent = new Intent(from, NotesPreferenceActivity.class); Intent intent = new Intent(from, NotesPreferenceActivity.class);
from.startActivityIfNeeded(intent, -1); from.startActivityIfNeeded(intent, -1);
} }
private class OnListItemClickListener implements OnItemClickListener { private class OnListItemClickListener implements OnItemClickListener {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (view instanceof NotesListItem) { if (view instanceof NotesListItem) {
NoteItemData item = ((NotesListItem) view).getItemData(); NoteItemData item = ((NotesListItem) view).getItemData();
@ -944,14 +990,15 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
} }
} }
} }
} }
private void startQueryDestinationFolders() { private void startQueryDestinationFolders() {
// 构建查询条件
String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?"; String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?";
selection = (mState == ListEditState.NOTE_LIST) ? selection: // 根据当前的列表编辑状态mState确定最终的查询条件
selection = (mState == ListEditState.NOTE_LIST) ? selection :
"(" + selection + ") OR (" + NoteColumns.ID + "=" + Notes.ID_ROOT_FOLDER + ")"; "(" + selection + ") OR (" + NoteColumns.ID + "=" + Notes.ID_ROOT_FOLDER + ")";
// 启动后台查询操作
mBackgroundQueryHandler.startQuery(FOLDER_LIST_QUERY_TOKEN, mBackgroundQueryHandler.startQuery(FOLDER_LIST_QUERY_TOKEN,
null, null,
Notes.CONTENT_NOTE_URI, Notes.CONTENT_NOTE_URI,
@ -964,18 +1011,24 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
}, },
NoteColumns.MODIFIED_DATE + " DESC"); NoteColumns.MODIFIED_DATE + " DESC");
} }
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
// 检查长按的视图是否为NotesListItem
if (view instanceof NotesListItem) { if (view instanceof NotesListItem) {
// 获取长按的笔记项数据
mFocusNoteDataItem = ((NotesListItem) view).getItemData(); mFocusNoteDataItem = ((NotesListItem) view).getItemData();
// 检查笔记项类型是否为Note类型且不在选择模式下
if (mFocusNoteDataItem.getType() == Notes.TYPE_NOTE && !mNotesListAdapter.isInChoiceMode()) { if (mFocusNoteDataItem.getType() == Notes.TYPE_NOTE && !mNotesListAdapter.isInChoiceMode()) {
// 启动操作模式ActionMode以支持多选操作
if (mNotesListView.startActionMode(mModeCallBack) != null) { if (mNotesListView.startActionMode(mModeCallBack) != null) {
// 更新选中项的状态,并执行长按反馈(震动)
mModeCallBack.onItemCheckedStateChanged(null, position, id, true); mModeCallBack.onItemCheckedStateChanged(null, position, id, true);
mNotesListView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); mNotesListView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
} else { } else {
// 启动操作模式失败
Log.e(TAG, "startActionMode fails"); Log.e(TAG, "startActionMode fails");
} }
} else if (mFocusNoteDataItem.getType() == Notes.TYPE_FOLDER) { } else if (mFocusNoteDataItem.getType() == Notes.TYPE_FOLDER) {
// 如果笔记项类型为Folder类型则设置上下文菜单监听器
mNotesListView.setOnCreateContextMenuListener(mFolderOnCreateContextMenuListener); mNotesListView.setOnCreateContextMenuListener(mFolderOnCreateContextMenuListener);
} }
} }

@ -30,7 +30,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
//便签列表适配器(链接数据库)
public class NotesListAdapter extends CursorAdapter { public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter"; private static final String TAG = "NotesListAdapter";
private Context mContext; private Context mContext;

@ -30,7 +30,7 @@ import com.example.notes_master.src.net.micode.notes.tool.ResourceParser.NoteIte
import net.micode.notes.R; import net.micode.notes.R;
//便签列表项
public class NotesListItem extends LinearLayout { public class NotesListItem extends LinearLayout {
private ImageView mAlert; private ImageView mAlert;
private TextView mTitle; private TextView mTitle;

@ -46,7 +46,7 @@ import com.example.notes_master.src.net.micode.notes.gtask.remote.GTaskSyncServi
import net.micode.notes.R; import net.micode.notes.R;
//便签同步的设置界面
public class NotesPreferenceActivity extends PreferenceActivity { public class NotesPreferenceActivity extends PreferenceActivity {
public static final String PREFERENCE_NAME = "notes_preferences"; public static final String PREFERENCE_NAME = "notes_preferences";

@ -32,7 +32,7 @@ import com.example.notes_master.src.net.micode.notes.ui.NoteEditActivity;
import com.example.notes_master.src.net.micode.notes.ui.NotesListActivity; import com.example.notes_master.src.net.micode.notes.ui.NotesListActivity;
import net.micode.notes.R; import net.micode.notes.R;
//桌面挂件
public abstract class NoteWidgetProvider extends AppWidgetProvider { public abstract class NoteWidgetProvider extends AppWidgetProvider {
public static final String [] PROJECTION = new String [] { public static final String [] PROJECTION = new String [] {
NoteColumns.ID, NoteColumns.ID,

@ -23,7 +23,7 @@ import com.example.notes_master.src.net.micode.notes.data.Notes;
import com.example.notes_master.src.net.micode.notes.tool.ResourceParser; import com.example.notes_master.src.net.micode.notes.tool.ResourceParser;
import net.micode.notes.R; import net.micode.notes.R;
//2倍大小的桌面挂件
public class NoteWidgetProvider_2x extends NoteWidgetProvider { public class NoteWidgetProvider_2x extends NoteWidgetProvider {
@Override @Override

@ -24,7 +24,7 @@ import com.example.notes_master.src.net.micode.notes.tool.ResourceParser;
import net.micode.notes.R; import net.micode.notes.R;
//4倍大小的桌面挂件
public class NoteWidgetProvider_4x extends NoteWidgetProvider { public class NoteWidgetProvider_4x extends NoteWidgetProvider {
@Override @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

Loading…
Cancel
Save