|
|
|
@ -78,17 +78,20 @@ 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 String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
|
|
|
|
|
|
|
|
|
|
private enum ListEditState {
|
|
|
|
@ -99,6 +102,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
private BackgroundQueryHandler mBackgroundQueryHandler;
|
|
|
|
|
|
|
|
|
|
//便签列表适配器
|
|
|
|
|
private NotesListAdapter mNotesListAdapter;
|
|
|
|
|
|
|
|
|
|
private ListView mNotesListView;
|
|
|
|
@ -113,10 +117,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
private TextView mTitleBar;
|
|
|
|
|
|
|
|
|
|
//当前文件夹id
|
|
|
|
|
private long mCurrentFolderId;
|
|
|
|
|
|
|
|
|
|
//内容解析程序
|
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
|
|
|
|
|
|
|
//模式回调
|
|
|
|
|
private ModeCallback mModeCallBack;
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "NotesListActivity";
|
|
|
|
@ -136,43 +143,64 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
private final static int REQUEST_CODE_NEW_NODE = 103;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//创建类 第一次创建时系统调用此方法
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
|
|
//保存的实例状态
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
//设置内容视图
|
|
|
|
|
setContentView(R.layout.note_list);
|
|
|
|
|
//初始化资源
|
|
|
|
|
initResources();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Insert an introduction when user firstly use this application
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//调用 setAppInfoFromRawRes 方法来插入应用程序介绍 当用户第一次使用此应用程序时
|
|
|
|
|
setAppInfoFromRawRes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
|
|
// 返回一些子模块完成的数据交给主Activity处理
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
if (resultCode == RESULT_OK
|
|
|
|
|
//如果结果代码和结果OK值相等 且(requestCode 满足 请求代码打开节点或请求代码新建节点)
|
|
|
|
|
if (resultCode == RESULT_OK
|
|
|
|
|
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
|
|
|
|
|
mNotesListAdapter.changeCursor(null);
|
|
|
|
|
} else {
|
|
|
|
|
//否则调用父亲onActivityResult方法
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//从原始资源中读取介绍文件并将其内容存储在一个StringBuilder对象中
|
|
|
|
|
private void setAppInfoFromRawRes() {
|
|
|
|
|
// Android平台给我们提供了一个SharedPreferences类,它是一个轻量级的存储类,特别适合用于保存软件配置参数。
|
|
|
|
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
|
//查SharedPreferences对象中是否存在一个名为PREFERENCE_ADD_INTRODUCTION的布尔值。
|
|
|
|
|
//如果该值不存在或为假,则执行以下操作
|
|
|
|
|
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
|
|
|
|
|
//创建一个名为sb的新的StringBuilder对象
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
InputStream in = null;
|
|
|
|
|
try {
|
|
|
|
|
//声明一个名为in的输入流变量并初始化为null
|
|
|
|
|
//使用getResources().openRawResource(R.raw.introduction)打开原始资源中名为“introduction”的文件
|
|
|
|
|
//并将其存储在输入流变量in中
|
|
|
|
|
in = getResources().openRawResource(R.raw.introduction);
|
|
|
|
|
if (in != null) {
|
|
|
|
|
if (in != null) {//如果in非空
|
|
|
|
|
InputStreamReader isr = new InputStreamReader(in);
|
|
|
|
|
BufferedReader br = new BufferedReader(isr);
|
|
|
|
|
char [] buf = new char[1024];
|
|
|
|
|
int len = 0;
|
|
|
|
|
//表示将字符数组buf中从索引0开始,
|
|
|
|
|
//长度为len的子数组添加到StringBuilder对象sb的末尾
|
|
|
|
|
while ((len = br.read(buf)) > 0) {
|
|
|
|
|
sb.append(buf, 0, len);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
} else {//否则使用Log.e方法记录一条错误消息并返回
|
|
|
|
|
Log.e(TAG, "Read introduction file error");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -181,6 +209,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
return;
|
|
|
|
|
} finally {
|
|
|
|
|
if(in != null) {
|
|
|
|
|
//若不为空尝试关闭输入流且捕捉可能发生的IOException异常
|
|
|
|
|
try {
|
|
|
|
|
in.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
@ -190,11 +219,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建空的WorkingNote
|
|
|
|
|
WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
|
|
|
|
|
AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
|
|
|
|
|
ResourceParser.RED);
|
|
|
|
|
note.setWorkingText(sb.toString());
|
|
|
|
|
if (note.saveNote()) {
|
|
|
|
|
// 更新保存note的信息
|
|
|
|
|
sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
|
|
|
|
|
} else {
|
|
|
|
|
Log.e(TAG, "Save introduction note error");
|
|
|
|
@ -204,22 +235,33 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//先调用父类onStart方法
|
|
|
|
|
//然后调用startAsyncNotesListQuery方法
|
|
|
|
|
protected void onStart() {
|
|
|
|
|
super.onStart();
|
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initResources() {
|
|
|
|
|
//获取内容解析器(ContentResolve)的数据,得到类似数据表的东西
|
|
|
|
|
mContentResolver = this.getContentResolver();
|
|
|
|
|
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
|
|
|
|
|
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
|
|
|
|
|
|
|
|
|
|
// findViewById 是安卓编程的定位函数,主要是引用.R文件里的引用名
|
|
|
|
|
mNotesListView = (ListView) findViewById(R.id.notes_list);
|
|
|
|
|
mNotesListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.note_list_footer, null),
|
|
|
|
|
null, false);
|
|
|
|
|
|
|
|
|
|
//为ListView设置OnItemClickListener和OnItemLongClickListener监听器
|
|
|
|
|
mNotesListView.setOnItemClickListener(new OnListItemClickListener());
|
|
|
|
|
mNotesListView.setOnItemLongClickListener(this);
|
|
|
|
|
//创建一个新的NotesListAdapter对象并将其存储在名为mNotesListAdapter的变量中
|
|
|
|
|
mNotesListAdapter = new NotesListAdapter(this);
|
|
|
|
|
mNotesListView.setAdapter(mNotesListAdapter);
|
|
|
|
|
|
|
|
|
|
//获取布局文件activity中ID为btn_new_note的按钮(Button)对象
|
|
|
|
|
mAddNewNote = (Button) findViewById(R.id.btn_new_note);
|
|
|
|
|
mAddNewNote.setOnClickListener(this);
|
|
|
|
|
mAddNewNote.setOnTouchListener(new NewNoteOnTouchListener());
|
|
|
|
@ -231,11 +273,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
mModeCallBack = new ModeCallback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 实现了ListView.MultiChoiceModeListener 和 OnMenuItemClickListener接口
|
|
|
|
|
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
|
|
|
|
|
//包含三个私有变量
|
|
|
|
|
private DropdownMenu mDropDownMenu;
|
|
|
|
|
private ActionMode mActionMode;
|
|
|
|
|
private MenuItem mMoveMenu;
|
|
|
|
|
|
|
|
|
|
//创建ActionMode
|
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
|
getMenuInflater().inflate(R.menu.note_list_options, menu);
|
|
|
|
|
menu.findItem(R.id.delete).setOnMenuItemClickListener(this);
|
|
|
|
@ -266,16 +311,19 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
//创建成功则返回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);
|
|
|
|
|
mDropDownMenu.setTitle(format);//设置标题
|
|
|
|
|
MenuItem item = mDropDownMenu.findItem(R.id.action_select_all);
|
|
|
|
|
if (item != null) {
|
|
|
|
|
if (item != null) { //若项目非空
|
|
|
|
|
//检查列表适配器是否已经选择了所有列表项
|
|
|
|
|
if (mNotesListAdapter.isAllSelected()) {
|
|
|
|
|
item.setChecked(true);
|
|
|
|
|
item.setTitle(R.string.menu_deselect_all);
|
|
|
|
@ -302,23 +350,31 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
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) {
|
|
|
|
|
//如果等于0则使用Toast.makeText方法显示一条提示消息
|
|
|
|
|
//返回true
|
|
|
|
|
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//检测菜单ID
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case R.id.delete:
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
|
|
|
|
@ -342,10 +398,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
//返回true表示已经成功处理了菜单点击事件
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//已有注释
|
|
|
|
|
private class NewNoteOnTouchListener implements OnTouchListener {
|
|
|
|
|
|
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
@ -408,6 +467,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//启动异步笔记列表查询
|
|
|
|
|
private void startAsyncNotesListQuery() {
|
|
|
|
|
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
|
|
|
|
|
: NORMAL_SELECTION;
|
|
|
|
@ -417,12 +477,16 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//BackgroundQueryHandler类可能用于执行后台查询操
|
|
|
|
|
private final class BackgroundQueryHandler extends AsyncQueryHandler {
|
|
|
|
|
public BackgroundQueryHandler(ContentResolver contentResolver) {
|
|
|
|
|
//调用父类的构造函数
|
|
|
|
|
//后续代码可以使用ContentResolver对象来执行异步查询
|
|
|
|
|
super(contentResolver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//处理查询结果
|
|
|
|
|
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
|
|
|
|
|
switch (token) {
|
|
|
|
|
case FOLDER_NOTE_LIST_QUERY_TOKEN:
|
|
|
|
@ -441,6 +505,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//显示文件夹列表菜单 接受一个Cursor对象
|
|
|
|
|
private void showFolderListMenu(Cursor cursor) {
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
|
|
|
|
|
builder.setTitle(R.string.menu_title_select_folder);
|
|
|
|
@ -462,6 +527,7 @@ 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,12 +535,14 @@ 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 {
|
|
|
|
@ -482,18 +550,22 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
} 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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//返回小部件
|
|
|
|
|
return widgets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPostExecute(HashSet<AppWidgetAttribute> widgets) {
|
|
|
|
|
if (widgets != null) {
|
|
|
|
|
//应用程序微件属性
|
|
|
|
|
//遍历这些对象并检查每个对象的 widgetId 和 widgetType 属性
|
|
|
|
|
for (AppWidgetAttribute widget : widgets) {
|
|
|
|
|
if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
|
|
|
|
&& widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) {
|
|
|
|
@ -501,11 +573,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//结束操作模式
|
|
|
|
|
mModeCallBack.finishActionMode();
|
|
|
|
|
}
|
|
|
|
|
}.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除文件夹
|
|
|
|
|
private void deleteFolder(long folderId) {
|
|
|
|
|
if (folderId == Notes.ID_ROOT_FOLDER) {
|
|
|
|
|
Log.e(TAG, "Wrong folder id, should not happen " + folderId);
|
|
|
|
@ -518,9 +592,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
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 +609,7 @@ 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,25 +617,35 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//打开菜单
|
|
|
|
|
private void openFolder(NoteItemData data) {
|
|
|
|
|
//获取当前文件夹id
|
|
|
|
|
mCurrentFolderId = data.getId();
|
|
|
|
|
//调用异步查询
|
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
|
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {//如果是
|
|
|
|
|
//将 mState 设置为 ListEditState.CALL_RECORD_FOLDER
|
|
|
|
|
//并将 mAddNewNote 视图设置为不可见
|
|
|
|
|
mState = ListEditState.CALL_RECORD_FOLDER;
|
|
|
|
|
mAddNewNote.setVisibility(View.GONE);
|
|
|
|
|
} else {
|
|
|
|
|
} else {//否则
|
|
|
|
|
//将 mState 设置为 ListEditState.SUB_FOLDER
|
|
|
|
|
mState = ListEditState.SUB_FOLDER;
|
|
|
|
|
}
|
|
|
|
|
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {//如果等于
|
|
|
|
|
//则将标题栏的文本设置为字符串资源 R.string.call_record_folder_name
|
|
|
|
|
mTitleBar.setText(R.string.call_record_folder_name);
|
|
|
|
|
} else {
|
|
|
|
|
} else {//否则获取代码段
|
|
|
|
|
mTitleBar.setText(data.getSnippet());
|
|
|
|
|
}
|
|
|
|
|
//最后,将标题栏设置为可见
|
|
|
|
|
mTitleBar.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
switch (v.getId()) {
|
|
|
|
|
//如果id等于R.id.btn_new_note
|
|
|
|
|
//创建新便签
|
|
|
|
|
case R.id.btn_new_note:
|
|
|
|
|
createNewNote();
|
|
|
|
|
break;
|
|
|
|
@ -567,6 +654,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//显示软输入
|
|
|
|
|
private void showSoftInput() {
|
|
|
|
|
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
if (inputMethodManager != null) {
|
|
|
|
@ -574,11 +662,13 @@ 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);
|
|
|
|
@ -642,7 +732,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
@ -651,8 +744,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
|
if (TextUtils.isEmpty(etName.getText())) {
|
|
|
|
|
//设置关闭
|
|
|
|
|
positive.setEnabled(false);
|
|
|
|
|
} else {
|
|
|
|
|
} else {//设置启用
|
|
|
|
|
positive.setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -665,34 +759,47 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//按下返回键时调用
|
|
|
|
|
//按返回键时根据情况更改类中的数据
|
|
|
|
|
public void onBackPressed() {
|
|
|
|
|
switch (mState) {
|
|
|
|
|
case SUB_FOLDER:
|
|
|
|
|
case SUB_FOLDER: //等于SUB_FOLDER
|
|
|
|
|
//将 mCurrentFolderId 设置为 Notes.ID_ROOT_FOLDER
|
|
|
|
|
//将 mState 设置为 ListEditState.NOTE_LIST
|
|
|
|
|
//调用 startAsyncNotesListQuery 方法来启动异步查询
|
|
|
|
|
//并将标题栏设置为不可见
|
|
|
|
|
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
|
|
|
|
|
mState = ListEditState.NOTE_LIST;
|
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
|
mTitleBar.setVisibility(View.GONE);
|
|
|
|
|
break;
|
|
|
|
|
case CALL_RECORD_FOLDER:
|
|
|
|
|
case CALL_RECORD_FOLDER: //等于CALL_RECORD_FOLDER(通话记录文件夹)
|
|
|
|
|
//则将 mCurrentFolderId 设置为 Notes.ID_ROOT_FOLDER
|
|
|
|
|
//将 mState 设置为 ListEditState.NOTE_LIST
|
|
|
|
|
//将 mAddNewNote 视图设置为可见,将标题栏设置为不可见
|
|
|
|
|
//并调用 startAsyncNotesListQuery 方法来启动异步查询
|
|
|
|
|
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
|
|
|
|
|
mState = ListEditState.NOTE_LIST;
|
|
|
|
|
mAddNewNote.setVisibility(View.VISIBLE);
|
|
|
|
|
mTitleBar.setVisibility(View.GONE);
|
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
|
break;
|
|
|
|
|
case NOTE_LIST:
|
|
|
|
|
case NOTE_LIST: //等于NOTE_LIST,调用父类的 onBackPressed 方法
|
|
|
|
|
super.onBackPressed();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
default: //否则,不执行任何操作
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新widget
|
|
|
|
|
private void updateWidget(int appWidgetId, int appWidgetType) {
|
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
|
if (appWidgetType == Notes.TYPE_WIDGET_2X) {
|
|
|
|
|
//放大两倍
|
|
|
|
|
intent.setClass(this, NoteWidgetProvider_2x.class);
|
|
|
|
|
} else if (appWidgetType == Notes.TYPE_WIDGET_4X) {
|
|
|
|
|
//放大四倍
|
|
|
|
|
intent.setClass(this, NoteWidgetProvider_4x.class);
|
|
|
|
|
} else {
|
|
|
|
|
Log.e(TAG, "Unspported widget type");
|
|
|
|
@ -707,6 +814,8 @@ 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) {
|
|
|
|
@ -719,6 +828,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//上下文菜单关闭时调用
|
|
|
|
|
public void onContextMenuClosed(Menu menu) {
|
|
|
|
|
if (mNotesListView != null) {
|
|
|
|
|
mNotesListView.setOnCreateContextMenuListener(null);
|
|
|
|
@ -727,16 +837,21 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//选择某个上下文菜单时被调用
|
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
|
|
|
|
if (mFocusNoteDataItem == null) {
|
|
|
|
|
if (mFocusNoteDataItem == null) { //如果为空输出The long click data item is null"并返回false
|
|
|
|
|
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:
|
|
|
|
|
//如果等于"MENU_FOLDER_DELETE"
|
|
|
|
|
//则创建一个警告对话框来提示用户删除文件夹
|
|
|
|
|
//并在用户确认删除后调用 deleteFolder 方法来删除文件夹
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
|
builder.setTitle(getString(R.string.alert_title_delete));
|
|
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
@ -748,12 +863,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
|
|
|
|
builder.show();
|
|
|
|
|
builder.show();//显示对话框
|
|
|
|
|
break;
|
|
|
|
|
case MENU_FOLDER_CHANGE_NAME:
|
|
|
|
|
showCreateOrModifyFolderDialog(false);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
//否则不执行操作
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -761,11 +877,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
@ -779,6 +897,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//所选选项项
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case R.id.menu_new_folder: {
|
|
|
|
@ -801,15 +920,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case R.id.menu_setting: {
|
|
|
|
|
case R.id.menu_setting: {//启动首选项活动
|
|
|
|
|
startPreferenceActivity();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case R.id.menu_new_note: {
|
|
|
|
|
case R.id.menu_new_note: {//创建新便签
|
|
|
|
|
createNewNote();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case R.id.menu_search:
|
|
|
|
|
case R.id.menu_search: //已请求搜索
|
|
|
|
|
onSearchRequested();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
@ -819,11 +938,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//调用startSearch函数
|
|
|
|
|
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>() {
|
|
|
|
@ -866,16 +987,19 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断是否正在同步
|
|
|
|
|
private boolean isSyncMode() {
|
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//跳转到PreferenceActivity界面
|
|
|
|
|
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) {
|
|
|
|
@ -917,6 +1041,7 @@ 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:
|
|
|
|
@ -935,6 +1060,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 长按某一项时进行的操作
|
|
|
|
|
// 如果长按的是便签,则通过ActionMode菜单实现;如果长按的是文件夹,则通过ContextMenu菜单实现;
|
|
|
|
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
|
if (view instanceof NotesListItem) {
|
|
|
|
|
mFocusNoteDataItem = ((NotesListItem) view).getItemData();
|
|
|
|
|