Compare commits

..

16 Commits

Binary file not shown.

Binary file not shown.

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

@ -17,6 +17,7 @@
package com.example.notes_master.src.net.micode.notes.data;
import android.net.Uri;
//便签数据库,用于记录便签相关属性和数据
public class Notes {
public static final String AUTHORITY = "micode_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.NoteColumns;
//数据库帮助类,用于辅助创建、处理数据库的条目
public class NotesDatabaseHelper extends SQLiteOpenHelper {
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;
//便签信息提供类
public class NotesProvider extends ContentProvider {
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.JSONObject;
//关于同步任务的元数据
public class MetaData extends Task {
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 org.json.JSONObject;
//同步任务的管理节点,用于设置、保存同步动作的信息
public abstract class Node {
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.JSONObject;
//数据库中基本数据,方法包括读取数据、获取数据库中数据、提交数据到数据库
public class SqlData {
private static final String TAG = SqlData.class.getSimpleName();

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

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

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

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

@ -15,7 +15,7 @@
*/
package com.example.notes_master.src.net.micode.notes.gtask.exception;
//网络失败异常
public class NetworkFailureException extends Exception {
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;
//GTask异步任务方法包括任务同步和取消显示同步任务的进程、通知和结果
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
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.InflaterInputStream;
//GTask客户端提供登录Google账户创建任务和任务列表添加和删除节点提交、重置更新获取任务列表等功能
public class GTaskClient {
private static final String TAG = GTaskClient.class.getSimpleName();

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

@ -22,7 +22,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
//GTask同步服务用于提供同步服务开始、取消同步发送广播
public class GTaskSyncService extends Service {
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 java.util.ArrayList;
//单个便签项
public class Note {
private ContentValues mNoteDiffValues;
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.tool.ResourceParser.NoteBgResources;
//当前活动便签项
public class WorkingNote {
// Note for the working note
private Note mNote;

@ -36,7 +36,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
//备份工具类,用于数据备份读取、显示
public class BackupUtils {
private static final String TAG = "BackupUtils";
// 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.HashSet;
//便签数据处理工具类,封装如查找、移动、删除数据等工作
public class DataUtils {
public static final String TAG = "DataUtils";
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {

@ -15,7 +15,7 @@
*/
package com.example.notes_master.src.net.micode.notes.tool;
//同步中使用的字符串工具类为JSONObject提供string对象
public class GTaskStringUtils {
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 net.micode.notes.R;
//界面元素的解析工具类利用R.java这个类获取资源供程序调用
public class ResourceParser {
public static final int YELLOW = 0;

@ -41,7 +41,7 @@ import net.micode.notes.R;
import java.io.IOException;
//闹铃提醒界面
public class AlarmAlertActivity extends AppCompatActivity implements OnClickListener, OnDismissListener {
private long mNoteId;
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.NoteColumns;
//闹铃提醒启动消息接收器
public class AlarmInitReceiver extends BroadcastReceiver {
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.Context;
import android.content.Intent;
//闹铃提醒接收器
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {

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

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

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

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

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

@ -35,7 +35,7 @@ import net.micode.notes.R;
import java.util.HashMap;
import java.util.Map;
//便签的文本编辑界面
public class NoteEditText extends androidx.appcompat.widget.AppCompatEditText {
private static final String TAG = "NoteEditText";
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.tool.DataUtils;
//便签项数据
public class NoteItemData {
static final String [] PROJECTION = new String [] {
NoteColumns.ID,
@ -77,20 +77,20 @@ public class NoteItemData {
private boolean mIsMultiNotesFollowingFolder;
public NoteItemData(Context context, Cursor cursor) {
mId = cursor.getLong(ID_COLUMN);
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);
mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN);
mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN);
mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false;
mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN);
mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN);
mParentId = cursor.getLong(PARENT_ID_COLUMN);
mSnippet = cursor.getString(SNIPPET_COLUMN);
mId = cursor.getLong(ID_COLUMN);//0
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);//1
mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN);//2
mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN);//3
mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false;//4
mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN);//5
mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN);//6
mParentId = cursor.getLong(PARENT_ID_COLUMN);//7
mSnippet = cursor.getString(SNIPPET_COLUMN);//8
mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace(
NoteEditActivity.TAG_UNCHECKED, "");
mType = cursor.getInt(TYPE_COLUMN);
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
mType = cursor.getInt(TYPE_COLUMN);//9
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);//10
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);//11
mPhoneNumber = "";
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {

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

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

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

@ -46,7 +46,7 @@ import com.example.notes_master.src.net.micode.notes.gtask.remote.GTaskSyncServi
import net.micode.notes.R;
//便签同步的设置界面
public class NotesPreferenceActivity extends PreferenceActivity {
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 net.micode.notes.R;
//桌面挂件
public abstract class NoteWidgetProvider extends AppWidgetProvider {
public static final String [] PROJECTION = new String [] {
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 net.micode.notes.R;
//2倍大小的桌面挂件
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
@Override

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

Loading…
Cancel
Save