|
|
|
@ -78,63 +78,76 @@ import java.io.InputStream;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 笔记列表活动类
|
|
|
|
|
* 负责显示笔记列表、文件夹列表,并处理笔记的创建、删除、移动等操作
|
|
|
|
|
* 实现了点击监听器和长按监听器接口
|
|
|
|
|
*/
|
|
|
|
|
public class NotesListActivity extends Activity 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_VIEW = 1; // 文件夹查看菜单项
|
|
|
|
|
|
|
|
|
|
private static final int MENU_FOLDER_CHANGE_NAME = 2;
|
|
|
|
|
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 {
|
|
|
|
|
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; // 原始Y坐标
|
|
|
|
|
|
|
|
|
|
private int mDispatchY;
|
|
|
|
|
private int mDispatchY; // 分发Y坐标
|
|
|
|
|
|
|
|
|
|
private TextView mTitleBar;
|
|
|
|
|
private TextView mTitleBar; // 标题栏
|
|
|
|
|
|
|
|
|
|
private long mCurrentFolderId;
|
|
|
|
|
private long mCurrentFolderId; // 当前文件夹ID
|
|
|
|
|
|
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
|
|
private ContentResolver mContentResolver; // 内容解析器
|
|
|
|
|
|
|
|
|
|
private ModeCallback mModeCallBack;
|
|
|
|
|
private ModeCallback mModeCallBack; // 模式回调
|
|
|
|
|
|
|
|
|
|
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 + "<>"
|
|
|
|
|
+ Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)" + " OR ("
|
|
|
|
|
+ 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_NEW_NODE = 103;
|
|
|
|
|
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);
|
|
|
|
@ -142,11 +155,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
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
|
|
|
|
@ -157,6 +174,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从原始资源设置应用信息
|
|
|
|
|
* 读取介绍文件并创建介绍笔记
|
|
|
|
|
*/
|
|
|
|
|
private void setAppInfoFromRawRes() {
|
|
|
|
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
|
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
|
|
|
|
@ -184,7 +205,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
try {
|
|
|
|
|
in.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
// TODO 自动生成的 catch 块
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -203,12 +224,20 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 活动开始时调用
|
|
|
|
|
* 开始异步查询笔记列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onStart() {
|
|
|
|
|
super.onStart();
|
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化资源
|
|
|
|
|
* 设置列表视图、适配器和按钮等界面元素
|
|
|
|
|
*/
|
|
|
|
|
private void initResources() {
|
|
|
|
|
mContentResolver = this.getContentResolver();
|
|
|
|
|
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
|
|
|
|
@ -231,11 +260,19 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
mModeCallBack = new ModeCallback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 模式回调类
|
|
|
|
|
* 处理多选模式下的菜单和操作
|
|
|
|
|
*/
|
|
|
|
|
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
|
|
|
|
|
private DropdownMenu mDropDownMenu;
|
|
|
|
|
private ActionMode mActionMode;
|
|
|
|
|
private MenuItem mMoveMenu;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建操作模式
|
|
|
|
|
* 初始化菜单项
|
|
|
|
|
*/
|
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
|
getMenuInflater().inflate(R.menu.note_list_options, menu);
|
|
|
|
|
menu.findItem(R.id.delete).setOnMenuItemClickListener(this);
|
|
|
|
@ -259,6 +296,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
(Button) customView.findViewById(R.id.selection_menu),
|
|
|
|
|
R.menu.note_list_dropdown);
|
|
|
|
|
mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
|
|
|
|
|
/**
|
|
|
|
|
* 下拉菜单项点击事件处理
|
|
|
|
|
* 处理全选/取消全选操作
|
|
|
|
|
*/
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
|
|
|
|
|
updateMenu();
|
|
|
|
@ -269,9 +310,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新菜单
|
|
|
|
|
* 更新下拉菜单的标题和选择状态
|
|
|
|
|
*/
|
|
|
|
|
private void updateMenu() {
|
|
|
|
|
int selectedCount = mNotesListAdapter.getSelectedCount();
|
|
|
|
|
// Update dropdown menu
|
|
|
|
|
// 更新下拉菜单
|
|
|
|
|
String format = getResources().getString(R.string.menu_select_title, selectedCount);
|
|
|
|
|
mDropDownMenu.setTitle(format);
|
|
|
|
|
MenuItem item = mDropDownMenu.findItem(R.id.action_select_all);
|
|
|
|
@ -286,32 +331,56 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 准备操作模式
|
|
|
|
|
* 在操作模式准备好时调用
|
|
|
|
|
*/
|
|
|
|
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
// TODO 自动生成的方法存根
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 操作项点击事件处理
|
|
|
|
|
* 处理操作模式下的菜单项点击
|
|
|
|
|
*/
|
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
// TODO 自动生成的方法存根
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 销毁操作模式
|
|
|
|
|
* 退出多选模式时恢复界面状态
|
|
|
|
|
*/
|
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
|
|
|
|
mNotesListAdapter.setChoiceMode(false);
|
|
|
|
|
mNotesListView.setLongClickable(true);
|
|
|
|
|
mAddNewNote.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 结束操作模式
|
|
|
|
|
* 完成当前的操作模式
|
|
|
|
|
*/
|
|
|
|
|
public void finishActionMode() {
|
|
|
|
|
mActionMode.finish();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 项目选中状态改变处理
|
|
|
|
|
* 当列表项的选中状态发生变化时更新菜单
|
|
|
|
|
*/
|
|
|
|
|
public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
|
|
|
|
|
boolean checked) {
|
|
|
|
|
mNotesListAdapter.setCheckedItem(position, checked);
|
|
|
|
|
updateMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 菜单项点击事件处理
|
|
|
|
|
* 处理删除和移动操作
|
|
|
|
|
*/
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
if (mNotesListAdapter.getSelectedCount() == 0) {
|
|
|
|
|
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
|
|
|
|
@ -328,6 +397,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
mNotesListAdapter.getSelectedCount()));
|
|
|
|
|
builder.setPositiveButton(android.R.string.ok,
|
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
/**
|
|
|
|
|
* 确认删除对话框点击事件处理
|
|
|
|
|
* 执行批量删除操作
|
|
|
|
|
*/
|
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
|
int which) {
|
|
|
|
|
batchDelete();
|
|
|
|
@ -344,8 +417,16 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新建笔记触摸监听器类
|
|
|
|
|
* 处理新建笔记按钮的触摸事件
|
|
|
|
|
*/
|
|
|
|
|
private class NewNoteOnTouchListener implements OnTouchListener {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 触摸事件处理
|
|
|
|
|
* 处理新建笔记按钮的触摸事件分发
|
|
|
|
|
*/
|
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
|
switch (event.getAction()) {
|
|
|
|
|
case MotionEvent.ACTION_DOWN: {
|
|
|
|
@ -357,20 +438,19 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
int start = screenHeight - newNoteViewHeight;
|
|
|
|
|
int eventY = start + (int) event.getY();
|
|
|
|
|
/**
|
|
|
|
|
* Minus TitleBar's height
|
|
|
|
|
* 减去标题栏的高度
|
|
|
|
|
*/
|
|
|
|
|
if (mState == ListEditState.SUB_FOLDER) {
|
|
|
|
|
eventY -= mTitleBar.getHeight();
|
|
|
|
|
start -= mTitleBar.getHeight();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* HACKME:When click the transparent part of "New Note" button, dispatch
|
|
|
|
|
* the event to the list view behind this button. The transparent part of
|
|
|
|
|
* "New Note" button could be expressed by formula y=-0.12x+94(Unit:pixel)
|
|
|
|
|
* and the line top of the button. The coordinate based on left of the "New
|
|
|
|
|
* Note" button. The 94 represents maximum height of the transparent part.
|
|
|
|
|
* 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.
|
|
|
|
|
* 技巧:当点击"新建笔记"按钮的透明部分时,将事件分发到
|
|
|
|
|
* 按钮后面的列表视图。"新建笔记"按钮的透明部分可以用公式
|
|
|
|
|
* y=-0.12x+94(单位:像素)和按钮顶部的线表示。坐标基于
|
|
|
|
|
* "新建笔记"按钮的左侧。94表示透明部分的最大高度。
|
|
|
|
|
* 注意,如果按钮的背景发生变化,公式也应该改变。这很不好,
|
|
|
|
|
* 只是为了满足UI设计师的强烈要求。
|
|
|
|
|
*/
|
|
|
|
|
if (event.getY() < (event.getX() * (-0.12) + 94)) {
|
|
|
|
|
View view = mNotesListView.getChildAt(mNotesListView.getChildCount() - 1
|
|
|
|
@ -408,6 +488,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 开始异步查询笔记列表
|
|
|
|
|
* 根据当前文件夹ID查询笔记列表
|
|
|
|
|
*/
|
|
|
|
|
private void startAsyncNotesListQuery() {
|
|
|
|
|
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
|
|
|
|
|
: NORMAL_SELECTION;
|
|
|
|
@ -417,11 +501,23 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 后台查询处理器类
|
|
|
|
|
* 处理异步查询操作
|
|
|
|
|
*/
|
|
|
|
|
private final class BackgroundQueryHandler extends AsyncQueryHandler {
|
|
|
|
|
/**
|
|
|
|
|
* 构造函数
|
|
|
|
|
* @param contentResolver 内容解析器
|
|
|
|
|
*/
|
|
|
|
|
public BackgroundQueryHandler(ContentResolver contentResolver) {
|
|
|
|
|
super(contentResolver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询完成回调
|
|
|
|
|
* 处理查询结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
|
|
|
|
|
switch (token) {
|
|
|
|
@ -441,12 +537,20 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示文件夹列表菜单
|
|
|
|
|
* 用于选择目标文件夹进行移动操作
|
|
|
|
|
*/
|
|
|
|
|
private void showFolderListMenu(Cursor cursor) {
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
|
|
|
|
|
builder.setTitle(R.string.menu_title_select_folder);
|
|
|
|
|
final FoldersListAdapter adapter = new FoldersListAdapter(this, cursor);
|
|
|
|
|
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文件夹选择对话框点击事件处理
|
|
|
|
|
* 将选中的笔记移动到目标文件夹
|
|
|
|
|
*/
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
DataUtils.batchMoveToFolder(mContentResolver,
|
|
|
|
|
mNotesListAdapter.getSelectedItemIds(), adapter.getItemId(which));
|
|
|
|
@ -462,6 +566,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
builder.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建新笔记
|
|
|
|
|
* 启动笔记编辑活动创建新笔记
|
|
|
|
|
*/
|
|
|
|
|
private void createNewNote() {
|
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class);
|
|
|
|
|
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
|
|
|
|
@ -469,20 +577,27 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
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())) {
|
|
|
|
|
} 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)) {
|
|
|
|
|
Log.e(TAG, "Move notes to trash folder error, should not happens");
|
|
|
|
@ -491,6 +606,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
return widgets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除操作完成后的处理
|
|
|
|
|
* 更新小部件并结束操作模式
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPostExecute(HashSet<AppWidgetAttribute> widgets) {
|
|
|
|
|
if (widgets != null) {
|
|
|
|
@ -506,6 +625,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除文件夹
|
|
|
|
|
* 删除指定ID的文件夹及其内容
|
|
|
|
|
* @param folderId 要删除的文件夹ID
|
|
|
|
|
*/
|
|
|
|
|
private void deleteFolder(long folderId) {
|
|
|
|
|
if (folderId == Notes.ID_ROOT_FOLDER) {
|
|
|
|
|
Log.e(TAG, "Wrong folder id, should not happen " + folderId);
|
|
|
|
@ -517,10 +641,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
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) {
|
|
|
|
@ -533,6 +657,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打开笔记
|
|
|
|
|
* 启动笔记编辑活动查看笔记内容
|
|
|
|
|
* @param data 笔记数据项
|
|
|
|
|
*/
|
|
|
|
|
private void openNode(NoteItemData data) {
|
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class);
|
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
@ -540,6 +669,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打开文件夹
|
|
|
|
|
* 显示文件夹内的笔记列表
|
|
|
|
|
* @param data 文件夹数据项
|
|
|
|
|
*/
|
|
|
|
|
private void openFolder(NoteItemData data) {
|
|
|
|
|
mCurrentFolderId = data.getId();
|
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
@ -557,6 +691,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
mTitleBar.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 点击事件处理
|
|
|
|
|
* 处理界面上的按钮点击事件
|
|
|
|
|
*/
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
int viewId = v.getId();
|
|
|
|
|
if (viewId == R.id.btn_new_note) {
|
|
|
|
@ -564,6 +702,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示软键盘
|
|
|
|
|
* 强制显示输入法键盘
|
|
|
|
|
*/
|
|
|
|
|
private void showSoftInput() {
|
|
|
|
|
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
if (inputMethodManager != null) {
|
|
|
|
@ -571,11 +713,21 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 隐藏软键盘
|
|
|
|
|
* 从指定视图隐藏输入法键盘
|
|
|
|
|
* @param view 关联的视图
|
|
|
|
|
*/
|
|
|
|
|
private void hideSoftInput(View view) {
|
|
|
|
|
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示创建或修改文件夹对话框
|
|
|
|
|
* 用于创建新文件夹或重命名现有文件夹
|
|
|
|
|
* @param create 是否为创建操作,true表示创建,false表示重命名
|
|
|
|
|
*/
|
|
|
|
|
private void showCreateOrModifyFolderDialog(final boolean create) {
|
|
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
|
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
|
|
|
|
@ -596,6 +748,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
@ -604,6 +760,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
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();
|
|
|
|
@ -638,14 +798,21 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
positive.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* When the name edit text is null, disable the positive button
|
|
|
|
|
* 当名称编辑文本为空时,禁用确认按钮
|
|
|
|
|
*/
|
|
|
|
|
etName.addTextChangedListener(new TextWatcher() {
|
|
|
|
|
/**
|
|
|
|
|
* 文本变化前的回调
|
|
|
|
|
*/
|
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
// TODO 自动生成的方法存根
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文本变化时的回调
|
|
|
|
|
* 根据文本是否为空启用或禁用确认按钮
|
|
|
|
|
*/
|
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
|
if (TextUtils.isEmpty(etName.getText())) {
|
|
|
|
|
positive.setEnabled(false);
|
|
|
|
@ -654,13 +821,20 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文本变化后的回调
|
|
|
|
|
*/
|
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
// TODO 自动生成的方法存根
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理返回按钮事件
|
|
|
|
|
* 根据当前状态决定返回行为
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onBackPressed() {
|
|
|
|
|
switch (mState) {
|
|
|
|
@ -685,6 +859,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新桌面小部件
|
|
|
|
|
* 发送广播通知小部件更新
|
|
|
|
|
* @param appWidgetId 小部件ID
|
|
|
|
|
* @param appWidgetType 小部件类型
|
|
|
|
|
*/
|
|
|
|
|
private void updateWidget(int appWidgetId, int appWidgetType) {
|
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
|
if (appWidgetType == Notes.TYPE_WIDGET_2X) {
|
|
|
|
@ -704,7 +884,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文件夹上下文菜单创建监听器
|
|
|
|
|
* 为文件夹项创建上下文菜单
|
|
|
|
|
*/
|
|
|
|
|
private final OnCreateContextMenuListener mFolderOnCreateContextMenuListener = new OnCreateContextMenuListener() {
|
|
|
|
|
/**
|
|
|
|
|
* 创建上下文菜单
|
|
|
|
|
* 添加查看、删除和重命名菜单项
|
|
|
|
|
*/
|
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
|
|
|
|
if (mFocusNoteDataItem != null) {
|
|
|
|
|
menu.setHeaderTitle(mFocusNoteDataItem.getSnippet());
|
|
|
|
@ -715,6 +903,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 上下文菜单关闭回调
|
|
|
|
|
* 清除上下文菜单创建监听器
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onContextMenuClosed(Menu menu) {
|
|
|
|
|
if (mNotesListView != null) {
|
|
|
|
@ -723,6 +915,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
super.onContextMenuClosed(menu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 上下文菜单项选择处理
|
|
|
|
|
* 处理文件夹的查看、删除和重命名操作
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
|
|
|
|
if (mFocusNoteDataItem == null) {
|
|
|
|
@ -740,6 +936,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
builder.setMessage(getString(R.string.alert_message_delete_folder));
|
|
|
|
|
builder.setPositiveButton(android.R.string.ok,
|
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
/**
|
|
|
|
|
* 确认删除文件夹对话框点击事件处理
|
|
|
|
|
* 执行文件夹删除操作
|
|
|
|
|
*/
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
deleteFolder(mFocusNoteDataItem.getId());
|
|
|
|
|
}
|
|
|
|
@ -757,13 +957,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 准备选项菜单
|
|
|
|
|
* 根据当前状态显示不同的菜单
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
|
menu.clear();
|
|
|
|
|
if (mState == ListEditState.NOTE_LIST) {
|
|
|
|
|
getMenuInflater().inflate(R.menu.note_list, menu);
|
|
|
|
|
// set sync or sync_cancel
|
|
|
|
|
// Temporarily disabled sync functionality
|
|
|
|
|
// 设置同步或取消同步
|
|
|
|
|
// 临时禁用同步功能
|
|
|
|
|
menu.findItem(R.id.menu_sync).setTitle(R.string.menu_sync);
|
|
|
|
|
} else if (mState == ListEditState.SUB_FOLDER) {
|
|
|
|
|
getMenuInflater().inflate(R.menu.sub_folder, menu);
|
|
|
|
@ -775,6 +979,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 选项菜单项选择处理
|
|
|
|
|
* 处理新建文件夹、导出文本、同步等操作
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
int itemId = item.getItemId();
|
|
|
|
@ -783,7 +991,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
} else if (itemId == R.id.menu_export_text) {
|
|
|
|
|
exportNoteToText();
|
|
|
|
|
} else if (itemId == R.id.menu_sync) {
|
|
|
|
|
// Temporarily disabled sync functionality
|
|
|
|
|
// 临时禁用同步功能
|
|
|
|
|
Toast.makeText(this, "Sync functionality temporarily disabled", Toast.LENGTH_SHORT).show();
|
|
|
|
|
startPreferenceActivity();
|
|
|
|
|
} else if (itemId == R.id.menu_setting) {
|
|
|
|
@ -796,21 +1004,36 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 搜索请求处理
|
|
|
|
|
* 启动搜索界面
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onSearchRequested() {
|
|
|
|
|
startSearch(null, false, null /* appData */, false);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导出笔记到文本文件
|
|
|
|
|
* 异步执行导出操作
|
|
|
|
|
*/
|
|
|
|
|
private void exportNoteToText() {
|
|
|
|
|
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) {
|
|
|
|
@ -844,20 +1067,36 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否为同步模式
|
|
|
|
|
* @return 是否启用了同步
|
|
|
|
|
*/
|
|
|
|
|
private boolean isSyncMode() {
|
|
|
|
|
// Temporarily disabled sync functionality
|
|
|
|
|
// 临时禁用同步功能
|
|
|
|
|
return false;
|
|
|
|
|
// 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();
|
|
|
|
@ -897,6 +1136,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 开始查询目标文件夹
|
|
|
|
|
* 用于移动笔记时查询可用的目标文件夹
|
|
|
|
|
*/
|
|
|
|
|
private void startQueryDestinationFolders() {
|
|
|
|
|
String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?";
|
|
|
|
|
selection = (mState == ListEditState.NOTE_LIST) ? selection:
|
|
|
|
@ -915,6 +1158,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 列表项长按事件处理
|
|
|
|
|
* 处理笔记和文件夹的长按操作
|
|
|
|
|
*/
|
|
|
|
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
|
if (view instanceof NotesListItem) {
|
|
|
|
|
mFocusNoteDataItem = ((NotesListItem) view).getItemData();
|
|
|
|
|