|
|
@ -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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 被勾选了,或取消勾选了,就改变hashmap里的该项的value的boolean值
|
|
|
|
* 当列表项的选择状态改变时调用,更新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 true表示项现在被选中,false表示项现在取消选中
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|