|
|
|
@ -78,60 +78,52 @@ 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_LIST_QUERY_TOKEN = 1;
|
|
|
|
|
|
|
|
|
|
private static final int MENU_FOLDER_DELETE = 0;
|
|
|
|
|
|
|
|
|
|
private static final int MENU_FOLDER_VIEW = 1;
|
|
|
|
|
|
|
|
|
|
private static final int MENU_FOLDER_CHANGE_NAME = 2;
|
|
|
|
|
|
|
|
|
|
private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0; // 笔记列表查询令牌
|
|
|
|
|
private static final int FOLDER_LIST_QUERY_TOKEN = 1; // 文件夹列表查询令牌
|
|
|
|
|
private static final int MENU_FOLDER_DELETE = 0; // 文件夹删除菜单项ID
|
|
|
|
|
private static final int MENU_FOLDER_VIEW = 1; // 文件夹查看菜单项ID
|
|
|
|
|
private static final int MENU_FOLDER_CHANGE_NAME = 2; // 文件夹重命名菜单项ID
|
|
|
|
|
|
|
|
|
|
// 首次使用应用的偏好设置键
|
|
|
|
|
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 列表编辑状态枚举
|
|
|
|
|
private enum ListEditState {
|
|
|
|
|
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
|
|
|
|
|
NOTE_LIST, // 根笔记列表状态
|
|
|
|
|
SUB_FOLDER, // 子文件夹状态
|
|
|
|
|
CALL_RECORD_FOLDER // 通话记录文件夹状态
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private ListEditState mState;
|
|
|
|
|
|
|
|
|
|
private BackgroundQueryHandler mBackgroundQueryHandler;
|
|
|
|
|
|
|
|
|
|
private NotesListAdapter mNotesListAdapter;
|
|
|
|
|
|
|
|
|
|
private ListView mNotesListView;
|
|
|
|
|
|
|
|
|
|
private Button mAddNewNote;
|
|
|
|
|
|
|
|
|
|
private boolean mDispatch;
|
|
|
|
|
|
|
|
|
|
private int mOriginY;
|
|
|
|
|
|
|
|
|
|
private int mDispatchY;
|
|
|
|
|
|
|
|
|
|
private TextView mTitleBar;
|
|
|
|
|
|
|
|
|
|
private long mCurrentFolderId;
|
|
|
|
|
|
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
|
|
|
|
|
|
|
private ModeCallback mModeCallBack;
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "NotesListActivity";
|
|
|
|
|
|
|
|
|
|
public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;
|
|
|
|
|
|
|
|
|
|
private NoteItemData mFocusNoteDataItem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ListEditState mState; // 当前列表编辑状态
|
|
|
|
|
private BackgroundQueryHandler mBackgroundQueryHandler;// 后台查询处理器
|
|
|
|
|
private NotesListAdapter mNotesListAdapter; // 笔记列表适配器
|
|
|
|
|
private ListView mNotesListView; // 笔记列表视图
|
|
|
|
|
private Button mAddNewNote; // 添加新笔记按钮
|
|
|
|
|
private boolean mDispatch; // 触摸事件分发标志
|
|
|
|
|
private int mOriginY; // 触摸事件原始Y坐标
|
|
|
|
|
private int mDispatchY; // 触摸事件分发Y坐标
|
|
|
|
|
private TextView mTitleBar; // 标题栏文本
|
|
|
|
|
private long mCurrentFolderId; // 当前文件夹ID
|
|
|
|
|
private ContentResolver mContentResolver; // 内容解析器
|
|
|
|
|
private ModeCallback mModeCallBack; // 操作模式回调
|
|
|
|
|
private static final String TAG = "NotesListActivity"; // 日志标签
|
|
|
|
|
public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;// 列表视图滚动速率
|
|
|
|
|
private NoteItemData mFocusNoteDataItem; // 聚焦的笔记数据项
|
|
|
|
|
|
|
|
|
|
// 查询条件常量
|
|
|
|
|
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
|
|
|
|
|
|
|
|
|
|
private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>"
|
|
|
|
|
+ Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)" + " OR ("
|
|
|
|
|
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER + " AND "
|
|
|
|
|
+ NoteColumns.NOTES_COUNT + ">0)";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 活动结果请求码
|
|
|
|
|
private final static int REQUEST_CODE_OPEN_NODE = 102;
|
|
|
|
|
private final static int REQUEST_CODE_NEW_NODE = 103;
|
|
|
|
|
|
|
|
|
@ -140,15 +132,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
setContentView(R.layout.note_list);
|
|
|
|
|
initResources();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Insert an introduction when user firstly use this application
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 首次使用应用时插入介绍笔记
|
|
|
|
|
setAppInfoFromRawRes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
// 处理打开或新建笔记的结果
|
|
|
|
|
if (resultCode == RESULT_OK
|
|
|
|
|
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
|
|
|
|
|
mNotesListAdapter.changeCursor(null);
|
|
|
|
@ -157,6 +148,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从原始资源文件读取应用介绍并保存为笔记
|
|
|
|
|
*/
|
|
|
|
|
private void setAppInfoFromRawRes() {
|
|
|
|
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
|
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
|
|
|
|
@ -165,6 +159,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
try {
|
|
|
|
|
in = getResources().openRawResource(R.raw.introduction);
|
|
|
|
|
if (in != null) {
|
|
|
|
|
// 读取介绍内容
|
|
|
|
|
InputStreamReader isr = new InputStreamReader(in);
|
|
|
|
|
BufferedReader br = new BufferedReader(isr);
|
|
|
|
|
char [] buf = new char[1024];
|
|
|
|
@ -184,12 +179,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
try {
|
|
|
|
|
in.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建并保存介绍笔记
|
|
|
|
|
WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
|
|
|
|
|
AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
|
|
|
|
|
ResourceParser.RED);
|
|
|
|
@ -206,23 +201,37 @@ 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());
|
|
|
|
|
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
|
|
|
|
|
mNotesListView = (ListView) findViewById(R.id.notes_list);
|
|
|
|
|
|
|
|
|
|
// 添加列表页脚
|
|
|
|
|
mNotesListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.note_list_footer, null),
|
|
|
|
|
null, false);
|
|
|
|
|
|
|
|
|
|
// 设置列表项点击和长按监听器
|
|
|
|
|
mNotesListView.setOnItemClickListener(new OnListItemClickListener());
|
|
|
|
|
mNotesListView.setOnItemLongClickListener(this);
|
|
|
|
|
|
|
|
|
|
// 设置列表适配器
|
|
|
|
|
mNotesListAdapter = new NotesListAdapter(this);
|
|
|
|
|
mNotesListView.setAdapter(mNotesListAdapter);
|
|
|
|
|
|
|
|
|
|
// 初始化添加新笔记按钮
|
|
|
|
|
mAddNewNote = (Button) findViewById(R.id.btn_new_note);
|
|
|
|
|
mAddNewNote.setOnClickListener(this);
|
|
|
|
|
mAddNewNote.setOnTouchListener(new NewNoteOnTouchListener());
|
|
|
|
|
|
|
|
|
|
// 初始化状态变量
|
|
|
|
|
mDispatch = false;
|
|
|
|
|
mDispatchY = 0;
|
|
|
|
|
mOriginY = 0;
|
|
|
|
@ -231,14 +240,25 @@ 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 DropdownMenu mDropDownMenu; // 下拉菜单
|
|
|
|
|
private ActionMode mActionMode; // 操作模式
|
|
|
|
|
|
|
|
|
|
// 操作菜单项,用于移动笔记
|
|
|
|
|
private MenuItem mMoveMenu;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建操作模式时调用
|
|
|
|
|
*/
|
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
|
// Inflate菜单资源
|
|
|
|
|
getMenuInflater().inflate(R.menu.note_list_options, menu);
|
|
|
|
|
menu.findItem(R.id.delete).setOnMenuItemClickListener(this);
|
|
|
|
|
|
|
|
|
|
// 初始化移动菜单项
|
|
|
|
|
mMoveMenu = menu.findItem(R.id.move);
|
|
|
|
|
if (mFocusNoteDataItem.getParentId() == Notes.ID_CALL_RECORD_FOLDER
|
|
|
|
|
|| DataUtils.getUserFolderCount(mContentResolver) == 0) {
|
|
|
|
@ -247,11 +267,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
mMoveMenu.setVisible(true);
|
|
|
|
|
mMoveMenu.setOnMenuItemClickListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mActionMode = mode;
|
|
|
|
|
mNotesListAdapter.setChoiceMode(true);
|
|
|
|
|
mNotesListView.setLongClickable(false);
|
|
|
|
|
mAddNewNote.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
|
|
// 设置自定义操作模式视图
|
|
|
|
|
View customView = LayoutInflater.from(NotesListActivity.this).inflate(
|
|
|
|
|
R.layout.note_list_dropdown_menu, null);
|
|
|
|
|
mode.setCustomView(customView);
|
|
|
|
@ -264,14 +286,16 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
updateMenu();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
@ -287,15 +311,16 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 销毁操作模式时调用
|
|
|
|
|
*/
|
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
|
|
|
|
mNotesListAdapter.setChoiceMode(false);
|
|
|
|
|
mNotesListView.setLongClickable(true);
|
|
|
|
@ -306,12 +331,18 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
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),
|
|
|
|
@ -321,6 +352,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case R.id.delete:
|
|
|
|
|
// 显示删除确认对话框
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
|
|
|
|
|
builder.setTitle(getString(R.string.alert_title_delete));
|
|
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
@ -337,6 +369,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
builder.show();
|
|
|
|
|
break;
|
|
|
|
|
case R.id.move:
|
|
|
|
|
// 启动目标文件夹查询
|
|
|
|
|
startQueryDestinationFolders();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
@ -346,32 +379,27 @@ 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: {
|
|
|
|
|
// 获取屏幕和按钮尺寸
|
|
|
|
|
Display display = getWindowManager().getDefaultDisplay();
|
|
|
|
|
int screenHeight = display.getHeight();
|
|
|
|
|
int newNoteViewHeight = mAddNewNote.getHeight();
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 处理按钮透明区域的触摸事件分发
|
|
|
|
|
if (event.getY() < (event.getX() * (-0.12) + 94)) {
|
|
|
|
|
View view = mNotesListView.getChildAt(mNotesListView.getChildCount() - 1
|
|
|
|
|
- mNotesListView.getFooterViewsCount());
|
|
|
|
@ -387,6 +415,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case MotionEvent.ACTION_MOVE: {
|
|
|
|
|
// 处理移动事件的分发
|
|
|
|
|
if (mDispatch) {
|
|
|
|
|
mDispatchY += (int) event.getY() - mOriginY;
|
|
|
|
|
event.setLocation(event.getX(), mDispatchY);
|
|
|
|
@ -395,6 +424,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
// 处理事件结束
|
|
|
|
|
if (mDispatch) {
|
|
|
|
|
event.setLocation(event.getX(), mDispatchY);
|
|
|
|
|
mDispatch = false;
|
|
|
|
@ -405,10 +435,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 启动异步笔记列表查询
|
|
|
|
|
*/
|
|
|
|
|
private void startAsyncNotesListQuery() {
|
|
|
|
|
// 根据当前文件夹ID设置查询条件
|
|
|
|
|
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
|
|
|
|
|
: NORMAL_SELECTION;
|
|
|
|
|
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
|
|
|
|
@ -417,6 +450,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 后台查询处理器,处理异步查询结果
|
|
|
|
|
*/
|
|
|
|
|
private final class BackgroundQueryHandler extends AsyncQueryHandler {
|
|
|
|
|
public BackgroundQueryHandler(ContentResolver contentResolver) {
|
|
|
|
|
super(contentResolver);
|
|
|
|
@ -424,6 +460,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
|
|
|
|
|
// 处理不同类型的查询结果
|
|
|
|
|
switch (token) {
|
|
|
|
|
case FOLDER_NOTE_LIST_QUERY_TOKEN:
|
|
|
|
|
mNotesListAdapter.changeCursor(cursor);
|
|
|
|
@ -441,13 +478,16 @@ 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));
|
|
|
|
|
Toast.makeText(
|
|
|
|
@ -462,6 +502,9 @@ 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 +512,23 @@ 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");
|
|
|
|
@ -493,6 +539,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPostExecute(HashSet<AppWidgetAttribute> widgets) {
|
|
|
|
|
// 更新相关小部件
|
|
|
|
|
if (widgets != null) {
|
|
|
|
|
for (AppWidgetAttribute widget : widgets) {
|
|
|
|
|
if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
|
|
|
@ -506,6 +553,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除文件夹
|
|
|
|
|
*/
|
|
|
|
|
private void deleteFolder(long folderId) {
|
|
|
|
|
if (folderId == Notes.ID_ROOT_FOLDER) {
|
|
|
|
|
Log.e(TAG, "Wrong folder id, should not happen " + folderId);
|
|
|
|
@ -514,15 +564,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
HashSet<Long> ids = new HashSet<Long>();
|
|
|
|
|
ids.add(folderId);
|
|
|
|
|
// 获取文件夹中笔记关联的小部件
|
|
|
|
|
HashSet<AppWidgetAttribute> widgets = DataUtils.getFolderNoteWidget(mContentResolver,
|
|
|
|
|
folderId);
|
|
|
|
|
if (!isSyncMode()) {
|
|
|
|
|
// if not synced, delete folder directly
|
|
|
|
|
// 非同步模式下直接删除文件夹
|
|
|
|
|
DataUtils.batchDeleteNotes(mContentResolver, ids);
|
|
|
|
|
} else {
|
|
|
|
|
// in sync mode, we'll move the deleted folder into the trash folder
|
|
|
|
|
// 同步模式下将删除的文件夹移动到废纸篓
|
|
|
|
|
DataUtils.batchMoveToFolder(mContentResolver, ids, Notes.ID_TRASH_FOLER);
|
|
|
|
|
}
|
|
|
|
|
// 更新相关小部件
|
|
|
|
|
if (widgets != null) {
|
|
|
|
|
for (AppWidgetAttribute widget : widgets) {
|
|
|
|
|
if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
|
|
|
@ -533,6 +585,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打开笔记详情
|
|
|
|
|
*/
|
|
|
|
|
private void openNode(NoteItemData data) {
|
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class);
|
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
@ -540,6 +595,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打开文件夹
|
|
|
|
|
*/
|
|
|
|
|
private void openFolder(NoteItemData data) {
|
|
|
|
|
mCurrentFolderId = data.getId();
|
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
@ -549,6 +607,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
} else {
|
|
|
|
|
mState = ListEditState.SUB_FOLDER;
|
|
|
|
|
}
|
|
|
|
|
// 设置标题栏显示文件夹名称
|
|
|
|
|
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
mTitleBar.setText(R.string.call_record_folder_name);
|
|
|
|
|
} else {
|
|
|
|
@ -557,6 +616,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
mTitleBar.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 视图点击事件处理
|
|
|
|
|
*/
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
switch (v.getId()) {
|
|
|
|
|
case R.id.btn_new_note:
|
|
|
|
@ -567,6 +629,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示软键盘
|
|
|
|
|
*/
|
|
|
|
|
private void showSoftInput() {
|
|
|
|
|
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
if (inputMethodManager != null) {
|
|
|
|
@ -574,16 +639,24 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 隐藏软键盘
|
|
|
|
|
*/
|
|
|
|
|
private void hideSoftInput(View view) {
|
|
|
|
|
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示创建或修改文件夹对话框
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
final EditText etName = (EditText) view.findViewById(R.id.et_foler_name);
|
|
|
|
|
showSoftInput();
|
|
|
|
|
|
|
|
|
|
// 设置对话框标题和初始文本
|
|
|
|
|
if (!create) {
|
|
|
|
|
if (mFocusNoteDataItem != null) {
|
|
|
|
|
etName.setText(mFocusNoteDataItem.getSnippet());
|
|
|
|
@ -610,12 +683,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
hideSoftInput(etName);
|
|
|
|
|
String name = etName.getText().toString();
|
|
|
|
|
// 检查文件夹名称是否已存在
|
|
|
|
|
if (DataUtils.checkVisibleFolderName(mContentResolver, name)) {
|
|
|
|
|
Toast.makeText(NotesListActivity.this, getString(R.string.folder_exist, name),
|
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
etName.setSelection(0, etName.length());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 创建或更新文件夹
|
|
|
|
|
if (!create) {
|
|
|
|
|
if (!TextUtils.isEmpty(name)) {
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
@ -637,17 +712,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 根据输入框内容启用/禁用确定按钮
|
|
|
|
|
if (TextUtils.isEmpty(etName.getText())) {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
|
|
|
|
|
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
|
if (TextUtils.isEmpty(etName.getText())) {
|
|
|
|
@ -657,15 +727,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void afterTextChanged(Editable s) {}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBackPressed() {
|
|
|
|
|
// 处理返回键,根据当前状态导航到上级目录
|
|
|
|
|
switch (mState) {
|
|
|
|
|
case SUB_FOLDER:
|
|
|
|
|
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
|
|
|
|
@ -688,8 +756,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新小部件
|
|
|
|
|
*/
|
|
|
|
|
private void updateWidget(int appWidgetId, int appWidgetType) {
|
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
|
// 根据小部件类型设置目标类
|
|
|
|
|
if (appWidgetType == Notes.TYPE_WIDGET_2X) {
|
|
|
|
|
intent.setClass(this, NoteWidgetProvider_2x.class);
|
|
|
|
|
} else if (appWidgetType == Notes.TYPE_WIDGET_4X) {
|
|
|
|
@ -707,6 +779,9 @@ 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) {
|
|
|
|
@ -732,11 +807,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
Log.e(TAG, "The long click data item is null");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// 处理文件夹上下文菜单项点击
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case MENU_FOLDER_VIEW:
|
|
|
|
|
openFolder(mFocusNoteDataItem);
|
|
|
|
|
break;
|
|
|
|
|
case MENU_FOLDER_DELETE:
|
|
|
|
|
// 显示删除文件夹确认对话框
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
|
builder.setTitle(getString(R.string.alert_title_delete));
|
|
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
@ -756,16 +833,16 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
// 设置同步/取消同步菜单项标题
|
|
|
|
|
menu.findItem(R.id.menu_sync).setTitle(
|
|
|
|
|
GTaskSyncService.isSyncing() ? R.string.menu_sync_cancel : R.string.menu_sync);
|
|
|
|
|
} else if (mState == ListEditState.SUB_FOLDER) {
|
|
|
|
@ -780,6 +857,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
// 处理选项菜单点击事件
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case R.id.menu_new_folder: {
|
|
|
|
|
showCreateOrModifyFolderDialog(true);
|
|
|
|
@ -791,6 +869,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
case R.id.menu_sync: {
|
|
|
|
|
if (isSyncMode()) {
|
|
|
|
|
// 切换同步/取消同步
|
|
|
|
|
if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) {
|
|
|
|
|
GTaskSyncService.startSync(this);
|
|
|
|
|
} else {
|
|
|
|
@ -824,10 +903,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
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();
|
|
|
|
@ -835,6 +916,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPostExecute(Integer result) {
|
|
|
|
|
// 显示导出结果
|
|
|
|
|
if (result == BackupUtils.STATE_SD_CARD_UNMOUONTED) {
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
|
|
|
|
|
builder.setTitle(NotesListActivity.this
|
|
|
|
@ -862,26 +944,34 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
builder.show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否处于同步模式
|
|
|
|
|
*/
|
|
|
|
|
private boolean isSyncMode() {
|
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 启动偏好设置活动
|
|
|
|
|
*/
|
|
|
|
|
private void startPreferenceActivity() {
|
|
|
|
|
Activity from = getParent() != null ? getParent() : this;
|
|
|
|
|
Intent intent = new Intent(from, NotesPreferenceActivity.class);
|
|
|
|
|
from.startActivityIfNeeded(intent, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 列表项点击监听器
|
|
|
|
|
*/
|
|
|
|
|
private class OnListItemClickListener implements OnItemClickListener {
|
|
|
|
|
|
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
|
if (view instanceof NotesListItem) {
|
|
|
|
|
NoteItemData item = ((NotesListItem) view).getItemData();
|
|
|
|
|
if (mNotesListAdapter.isInChoiceMode()) {
|
|
|
|
|
// 多选模式下处理选中状态
|
|
|
|
|
if (item.getType() == Notes.TYPE_NOTE) {
|
|
|
|
|
position = position - mNotesListView.getHeaderViewsCount();
|
|
|
|
|
mModeCallBack.onItemCheckedStateChanged(null, position, id,
|
|
|
|
@ -890,6 +980,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据当前状态处理不同类型的项点击
|
|
|
|
|
switch (mState) {
|
|
|
|
|
case NOTE_LIST:
|
|
|
|
|
if (item.getType() == Notes.TYPE_FOLDER
|
|
|
|
@ -914,11 +1005,14 @@ 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:
|
|
|
|
|
"(" + selection + ") OR (" + NoteColumns.ID + "=" + Notes.ID_ROOT_FOLDER + ")";
|
|
|
|
|
|
|
|
|
@ -935,10 +1029,14 @@ 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();
|
|
|
|
|
if (mFocusNoteDataItem.getType() == Notes.TYPE_NOTE && !mNotesListAdapter.isInChoiceMode()) {
|
|
|
|
|
// 启动多选操作模式
|
|
|
|
|
if (mNotesListView.startActionMode(mModeCallBack) != null) {
|
|
|
|
|
mModeCallBack.onItemCheckedStateChanged(null, position, id, true);
|
|
|
|
|
mNotesListView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
|
|
|
@ -946,9 +1044,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
Log.e(TAG, "startActionMode fails");
|
|
|
|
|
}
|
|
|
|
|
} else if (mFocusNoteDataItem.getType() == Notes.TYPE_FOLDER) {
|
|
|
|
|
// 为文件夹设置上下文菜单
|
|
|
|
|
mNotesListView.setOnCreateContextMenuListener(mFolderOnCreateContextMenuListener);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|