|
|
@ -1,19 +1,3 @@
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Activity;
|
|
|
@ -77,8 +61,12 @@ 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 Activity implements OnClickListener, OnItemLongClickListener {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @author k
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
|
|
@ -89,7 +77,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
|
|
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"; //单行超过80个字符
|
|
|
|
|
|
|
|
|
|
|
|
private enum ListEditState {
|
|
|
|
private enum ListEditState {
|
|
|
|
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
|
|
|
|
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
|
|
|
@ -136,8 +124,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
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) {
|
|
|
|
// 创建类
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
protected void onCreate(final Bundle savedInstanceState) { //需要是final类型 根据程序上下文环境,Java关键字final有“这是无法改变的”或者“终态的”含义,它可以修饰非抽象类、非抽象类成员方法和变量。你可能出于两种理解而需要阻止改变:设计或效率。
|
|
|
|
|
|
|
|
// final类不能被继承,没有子类,final类中的方法默认是final的。
|
|
|
|
|
|
|
|
//final方法不能被子类的方法覆盖,但可以被继承。
|
|
|
|
|
|
|
|
//final成员变量表示常量,只能被赋值一次,赋值后值不再改变。
|
|
|
|
|
|
|
|
//final不能用于修饰构造方法。
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState); // 调用父类的onCreate函数
|
|
|
|
setContentView(R.layout.note_list);
|
|
|
|
setContentView(R.layout.note_list);
|
|
|
|
initResources();
|
|
|
|
initResources();
|
|
|
|
|
|
|
|
|
|
|
@ -148,26 +141,32 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
|
|
|
|
// 返回一些子模块完成的数据交给主Activity处理
|
|
|
|
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
|
|
|
|
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
|
|
|
|
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
|
|
|
|
mNotesListAdapter.changeCursor(null);
|
|
|
|
mNotesListAdapter.changeCursor(null);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
|
|
|
// 调用 Activity 的onActivityResult()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setAppInfoFromRawRes() {
|
|
|
|
private void setAppInfoFromRawRes() {
|
|
|
|
|
|
|
|
// Android平台给我们提供了一个SharedPreferences类,它是一个轻量级的存储类,特别适合用于保存软件配置参数。
|
|
|
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
|
|
|
|
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
InputStream in = null;
|
|
|
|
InputStream in = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
in = getResources().openRawResource(R.raw.introduction);
|
|
|
|
// 把资源文件放到应用程序的/raw/raw下,那么就可以在应用中使用getResources获取资源后,
|
|
|
|
|
|
|
|
// 以openRawResource方法(不带后缀的资源文件名)打开这个文件。
|
|
|
|
|
|
|
|
in = getResources().openRawResource(R.raw.introduction);
|
|
|
|
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);
|
|
|
|
char [] buf = new char[1024];
|
|
|
|
char [] buf = new char[1024]; // 自行定义的数值,使用者不知道有什么意义
|
|
|
|
int len = 0;
|
|
|
|
int len = 0;
|
|
|
|
while ((len = br.read(buf)) > 0) {
|
|
|
|
while ((len = br.read(buf)) > 0) {
|
|
|
|
sb.append(buf, 0, len);
|
|
|
|
sb.append(buf, 0, len);
|
|
|
@ -180,7 +179,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if(in != null) {
|
|
|
|
if (in != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
in.close();
|
|
|
|
in.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
@ -190,11 +189,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建空的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");
|
|
|
@ -209,18 +210,21 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
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;
|
|
|
|
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
|
|
|
|
mNotesListView = (ListView) findViewById(R.id.notes_list);
|
|
|
|
|
|
|
|
|
|
|
|
// findViewById 是安卓编程的定位函数,主要是引用.R文件里的引用名
|
|
|
|
|
|
|
|
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());
|
|
|
|
mNotesListView.setOnItemLongClickListener(this);
|
|
|
|
mNotesListView.setOnItemLongClickListener(this);
|
|
|
|
mNotesListAdapter = new NotesListAdapter(this);
|
|
|
|
mNotesListAdapter = new NotesListAdapter(this);
|
|
|
|
mNotesListView.setAdapter(mNotesListAdapter);
|
|
|
|
mNotesListView.setAdapter(mNotesListAdapter);
|
|
|
|
mAddNewNote = (Button) findViewById(R.id.btn_new_note);
|
|
|
|
mAddNewNote = (Button) findViewById(R.id.btn_new_note);// 在activity中要获取该按钮
|
|
|
|
mAddNewNote.setOnClickListener(this);
|
|
|
|
mAddNewNote.setOnClickListener(this);
|
|
|
|
mAddNewNote.setOnTouchListener(new NewNoteOnTouchListener());
|
|
|
|
mAddNewNote.setOnTouchListener(new NewNoteOnTouchListener());
|
|
|
|
mDispatch = false;
|
|
|
|
mDispatch = false;
|
|
|
@ -231,6 +235,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
mModeCallBack = new ModeCallback();
|
|
|
|
mModeCallBack = new 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;
|
|
|
@ -259,7 +264,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
(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(final MenuItem item) {
|
|
|
|
mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
|
|
|
|
mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
|
|
|
|
updateMenu();
|
|
|
|
updateMenu();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -269,11 +274,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新菜单
|
|
|
|
private void updateMenu() {
|
|
|
|
private void updateMenu() {
|
|
|
|
int selectedCount = mNotesListAdapter.getSelectedCount();
|
|
|
|
int selectedCount = mNotesListAdapter.getSelectedCount();
|
|
|
|
// Update dropdown menu
|
|
|
|
// 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);
|
|
|
|
if (item != null) {
|
|
|
|
if (item != null) {
|
|
|
|
if (mNotesListAdapter.isAllSelected()) {
|
|
|
|
if (mNotesListAdapter.isAllSelected()) {
|
|
|
@ -307,7 +313,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -347,52 +353,58 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
private class NewNoteOnTouchListener implements OnTouchListener {
|
|
|
|
private class NewNoteOnTouchListener implements OnTouchListener {
|
|
|
|
|
|
|
|
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
int action = event.getAction();
|
|
|
|
switch (event.getAction()) {
|
|
|
|
if (action == 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();
|
|
|
|
int start = screenHeight - newNoteViewHeight;
|
|
|
|
int start = screenHeight - newNoteViewHeight;
|
|
|
|
int eventY = start + (int) event.getY();
|
|
|
|
int eventY = start + (int) event.getY();
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Minus TitleBar's height
|
|
|
|
* Minus TitleBar's height
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
if (mState == ListEditState.SUB_FOLDER) {
|
|
|
|
if (mState == ListEditState.SUB_FOLDER) {
|
|
|
|
eventY -= mTitleBar.getHeight();
|
|
|
|
eventY -= mTitleBar.getHeight();
|
|
|
|
start -= 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锛圲nit:pixel锛<EFBFBD>
|
|
|
|
|
|
|
|
* 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());
|
|
|
|
|
|
|
|
if (view != null && view.getBottom() > start
|
|
|
|
|
|
|
|
&& (view.getTop() < (start + 94))) {
|
|
|
|
|
|
|
|
mOriginY = (int) event.getY();
|
|
|
|
|
|
|
|
mDispatchY = eventY;
|
|
|
|
|
|
|
|
event.setLocation(event.getX(), mDispatchY);
|
|
|
|
|
|
|
|
mDispatch = true;
|
|
|
|
|
|
|
|
return mNotesListView.dispatchTouchEvent(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
case MotionEvent.ACTION_MOVE: {
|
|
|
|
* HACKME:When click the transparent part of "New Note" button, dispatch
|
|
|
|
if (mDispatch) {
|
|
|
|
* the event to the list view behind this button. The transparent part of
|
|
|
|
mDispatchY += (int) event.getY() - mOriginY;
|
|
|
|
* "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());
|
|
|
|
|
|
|
|
if (view != null && view.getBottom() > start
|
|
|
|
|
|
|
|
&& (view.getTop() < (start + 94))) {
|
|
|
|
|
|
|
|
mOriginY = (int) event.getY();
|
|
|
|
|
|
|
|
mDispatchY = eventY;
|
|
|
|
|
|
|
|
event.setLocation(event.getX(), mDispatchY);
|
|
|
|
event.setLocation(event.getX(), mDispatchY);
|
|
|
|
mDispatch = true;
|
|
|
|
|
|
|
|
return mNotesListView.dispatchTouchEvent(event);
|
|
|
|
return mNotesListView.dispatchTouchEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (action == MotionEvent.ACTION_MOVE) {
|
|
|
|
default: {
|
|
|
|
if (mDispatch) {
|
|
|
|
if (mDispatch) {
|
|
|
|
mDispatchY += (int) event.getY() - mOriginY;
|
|
|
|
event.setLocation(event.getX(), mDispatchY);
|
|
|
|
event.setLocation(event.getX(), mDispatchY);
|
|
|
|
mDispatch = false;
|
|
|
|
return mNotesListView.dispatchTouchEvent(event);
|
|
|
|
return mNotesListView.dispatchTouchEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
if (mDispatch) {
|
|
|
|
|
|
|
|
event.setLocation(event.getX(), mDispatchY);
|
|
|
|
|
|
|
|
mDispatch = false;
|
|
|
|
|
|
|
|
return mNotesListView.dispatchTouchEvent(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -405,7 +417,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
: NORMAL_SELECTION;
|
|
|
|
: NORMAL_SELECTION;
|
|
|
|
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
|
|
|
|
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
|
|
|
|
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {
|
|
|
|
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {
|
|
|
|
String.valueOf(mCurrentFolderId)
|
|
|
|
String.valueOf(mCurrentFolderId)
|
|
|
|
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -612,7 +624,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
values.put(NoteColumns.LOCAL_MODIFIED, 1);
|
|
|
|
values.put(NoteColumns.LOCAL_MODIFIED, 1);
|
|
|
|
mContentResolver.update(Notes.CONTENT_NOTE_URI, values, NoteColumns.ID
|
|
|
|
mContentResolver.update(Notes.CONTENT_NOTE_URI, values, NoteColumns.ID
|
|
|
|
+ "=?", new String[] {
|
|
|
|
+ "=?", new String[] {
|
|
|
|
String.valueOf(mFocusNoteDataItem.getId())
|
|
|
|
String.valueOf(mFocusNoteDataItem.getId())
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!TextUtils.isEmpty(name)) {
|
|
|
|
} else if (!TextUtils.isEmpty(name)) {
|
|
|
@ -652,30 +664,38 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
|
|
|
* @see android.app.Activity#onBackPressed()
|
|
|
|
|
|
|
|
* 按返回键时根据情况更改类中的数据
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
public void onBackPressed() { switch (mState) {
|
|
|
|
switch (mState) {
|
|
|
|
case SUB_FOLDER:
|
|
|
|
case 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:
|
|
|
|
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);
|
|
|
|
mTitleBar.setVisibility(View.GONE);
|
|
|
|
mTitleBar.setVisibility(View.GONE);
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case NOTE_LIST:
|
|
|
|
case NOTE_LIST:
|
|
|
|
super.onBackPressed();
|
|
|
|
super.onBackPressed();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param appWidgetId
|
|
|
|
|
|
|
|
* @param appWidgetType
|
|
|
|
|
|
|
|
* 根据不同类型的widget更新插件,通过intent传送数据
|
|
|
|
|
|
|
|
*/
|
|
|
|
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) {
|
|
|
@ -688,13 +708,16 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
|
|
|
|
appWidgetId
|
|
|
|
appWidgetId
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
sendBroadcast(intent);
|
|
|
|
sendBroadcast(intent);
|
|
|
|
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) {
|
|
|
|
if (mFocusNoteDataItem != null) {
|
|
|
|
if (mFocusNoteDataItem != null) {
|
|
|
@ -714,6 +737,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
super.onContextMenuClosed(menu);
|
|
|
|
super.onContextMenuClosed(menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
|
|
|
* @see android.app.Activity#onContextItemSelected(android.view.MenuItem)
|
|
|
|
|
|
|
|
* 针对menu中不同的选择进行不同的处理,里面详细注释
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
|
|
|
if (mFocusNoteDataItem == null) {
|
|
|
|
if (mFocusNoteDataItem == null) {
|
|
|
@ -722,10 +749,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case MENU_FOLDER_VIEW:
|
|
|
|
case MENU_FOLDER_VIEW:
|
|
|
|
openFolder(mFocusNoteDataItem);
|
|
|
|
openFolder(mFocusNoteDataItem);//打开对应文件
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case MENU_FOLDER_DELETE:
|
|
|
|
case 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);
|
|
|
|
builder.setMessage(getString(R.string.alert_message_delete_folder));
|
|
|
|
builder.setMessage(getString(R.string.alert_message_delete_folder));
|
|
|
@ -736,7 +763,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
|
|
|
builder.show();
|
|
|
|
builder.show();//显示对话框
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case MENU_FOLDER_CHANGE_NAME:
|
|
|
|
case MENU_FOLDER_CHANGE_NAME:
|
|
|
|
showCreateOrModifyFolderDialog(false);
|
|
|
|
showCreateOrModifyFolderDialog(false);
|
|
|
@ -793,12 +820,19 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
|
|
|
* @see android.app.Activity#onSearchRequested()
|
|
|
|
|
|
|
|
* 直接调用startSearch函数
|
|
|
|
|
|
|
|
*/
|
|
|
|
@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() {
|
|
|
|
final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
|
|
|
|
final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
|
|
|
|
new AsyncTask<Void, Void, Integer>() {
|
|
|
|
new AsyncTask<Void, Void, Integer>() {
|
|
|
@ -841,16 +875,27 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
}.execute();
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
* 功能:判断是否正在同步
|
|
|
|
|
|
|
|
*/
|
|
|
|
private boolean isSyncMode() {
|
|
|
|
private boolean isSyncMode() {
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 功能:跳转到PreferenceActivity界面
|
|
|
|
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @author k
|
|
|
|
|
|
|
|
* 函数功能:实现对便签列表项的点击事件(短按)
|
|
|
|
|
|
|
|
*/
|
|
|
|
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) {
|
|
|
@ -892,10 +937,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 查询目标文件
|
|
|
|
|
|
|
|
*/
|
|
|
|
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:
|
|
|
|
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,
|
|
|
@ -910,6 +958,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
|
|
|
* @see android.widget.AdapterView.OnItemLongClickListener#onItemLongClick(android.widget.AdapterView, android.view.View, int, long)
|
|
|
|
|
|
|
|
* 长按某一项时进行的操作
|
|
|
|
|
|
|
|
* 如果长按的是便签,则通过ActionMode菜单实现;如果长按的是文件夹,则通过ContextMenu菜单实现;
|
|
|
|
|
|
|
|
* 具体ActionMOde菜单和ContextMenu菜单的详细见精度笔记
|
|
|
|
|
|
|
|
*/
|
|
|
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
if (view instanceof NotesListItem) {
|
|
|
|
if (view instanceof NotesListItem) {
|
|
|
|
mFocusNoteDataItem = ((NotesListItem) view).getItemData();
|
|
|
|
mFocusNoteDataItem = ((NotesListItem) view).getItemData();
|
|
|
|