|
|
@ -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;
|
|
|
@ -74,6 +58,8 @@ import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
|
|
|
|
//该类主要是针对标签的编辑
|
|
|
|
|
|
|
|
//继承了系统内部许多和监听有关的类
|
|
|
|
private class HeadViewHolder {
|
|
|
|
private class HeadViewHolder {
|
|
|
|
public TextView tvModified;
|
|
|
|
public TextView tvModified;
|
|
|
|
|
|
|
|
|
|
|
@ -83,7 +69,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//使用Map实现数据存储
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
@ -123,19 +109,22 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
private HeadViewHolder mNoteHeaderHolder;
|
|
|
|
private HeadViewHolder mNoteHeaderHolder;
|
|
|
|
|
|
|
|
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
|
|
|
|
//私有化一个界面操作mHeadViewPanel,对表头的操作
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
|
|
|
|
//私有化一个界面操作mNoteBgColorSelector,对背景颜色的操作
|
|
|
|
private View mFontSizeSelector;
|
|
|
|
private View mFontSizeSelector;
|
|
|
|
|
|
|
|
//私有化一个界面操作mFontSizeSelector,对标签字体的操作
|
|
|
|
private EditText mNoteEditor;
|
|
|
|
private EditText mNoteEditor;
|
|
|
|
|
|
|
|
//声明编辑控件,对文本操作
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
|
|
|
|
//私有化一个界面操作mNoteEditorPanel,文本编辑的控制板
|
|
|
|
private WorkingNote mWorkingNote;
|
|
|
|
public WorkingNote mWorkingNote;
|
|
|
|
|
|
|
|
//对模板WorkingNote的初始化
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
|
|
|
|
|
//私有化SharedPreferences的数据存储方式
|
|
|
|
|
|
|
|
//它的本质是基于XML文件存储key-value键值对数据
|
|
|
|
private int mFontSizeId;
|
|
|
|
private int mFontSizeId;
|
|
|
|
|
|
|
|
//用于操作字体的大小
|
|
|
|
|
|
|
|
|
|
|
|
private static final String PREFERENCE_FONT_SIZE = "pref_font_size";
|
|
|
|
private static final String PREFERENCE_FONT_SIZE = "pref_font_size";
|
|
|
|
|
|
|
|
|
|
|
@ -153,7 +142,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
|
|
|
|
//对数据库的访问操作
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -176,9 +165,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Log.d(TAG, "Restoring from killed activity");
|
|
|
|
Log.d(TAG, "Restoring from killed activity");
|
|
|
|
}
|
|
|
|
}//为防止内存不足时程序的终止,在这里有一个保存现场的函数
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean initActivityState(Intent intent) {
|
|
|
|
private boolean initActivityState(Intent intent) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* If the user specified the {@link Intent#ACTION_VIEW} but not provided with id,
|
|
|
|
* If the user specified the {@link Intent#ACTION_VIEW} but not provided with id,
|
|
|
@ -188,34 +178,42 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
|
|
|
|
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
|
|
|
|
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
|
|
|
|
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
|
|
|
|
mUserQuery = "";
|
|
|
|
mUserQuery = "";
|
|
|
|
|
|
|
|
//如果用户实例化标签时,系统并未给出标签ID
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Starting from the searched result
|
|
|
|
* Starting from the searched result
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
//根据键值查找ID
|
|
|
|
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
|
|
|
|
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
|
|
|
|
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
|
|
|
|
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
|
|
|
|
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
|
|
|
|
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//如果ID在数据库中未找到
|
|
|
|
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
|
|
|
|
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
|
|
|
|
Intent jump = new Intent(this, NotesListActivity.class);
|
|
|
|
Intent jump = new Intent(this, NotesListActivity.class);
|
|
|
|
startActivity(jump);
|
|
|
|
startActivity(jump);
|
|
|
|
|
|
|
|
//程序将跳转到上面声明的intent——jump
|
|
|
|
showToast(R.string.error_note_not_exist);
|
|
|
|
showToast(R.string.error_note_not_exist);
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
//ID在数据库中找到
|
|
|
|
|
|
|
|
else {
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);
|
|
|
|
if (mWorkingNote == null) {
|
|
|
|
if (mWorkingNote == null) {
|
|
|
|
Log.e(TAG, "load note failed with note id" + noteId);
|
|
|
|
Log.e(TAG, "load note failed with note id" + noteId);
|
|
|
|
|
|
|
|
//打印出红色的错误信息
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//setSoftInputMode——软键盘输入模式
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
|
|
|
|
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
|
|
|
|
// New note
|
|
|
|
// intent.getAction()
|
|
|
|
|
|
|
|
// 大多用于broadcast发送广播时给机制(intent)设置一个action,就是一个字符串
|
|
|
|
|
|
|
|
// 用户可以通过receive(接受)intent,通过 getAction得到的字符串,来决定做什么
|
|
|
|
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
|
|
|
|
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
|
|
|
|
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
|
|
|
|
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
|
|
|
|
AppWidgetManager.INVALID_APPWIDGET_ID);
|
|
|
|
AppWidgetManager.INVALID_APPWIDGET_ID);
|
|
|
@ -223,7 +221,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
Notes.TYPE_WIDGET_INVALIDE);
|
|
|
|
Notes.TYPE_WIDGET_INVALIDE);
|
|
|
|
int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,
|
|
|
|
int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,
|
|
|
|
ResourceParser.getDefaultBgId(this));
|
|
|
|
ResourceParser.getDefaultBgId(this));
|
|
|
|
|
|
|
|
// intent.getInt(Long、String)Extra是对各变量的语法分析
|
|
|
|
// Parse call-record note
|
|
|
|
// Parse call-record note
|
|
|
|
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
|
|
|
|
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
|
|
|
|
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
|
|
|
|
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
|
|
|
@ -240,15 +238,17 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//将电话号码与手机的号码簿相关
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId,
|
|
|
|
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId,
|
|
|
|
widgetType, bgResId);
|
|
|
|
widgetType, bgResId);
|
|
|
|
mWorkingNote.convertToCallNote(phoneNumber, callDate);
|
|
|
|
mWorkingNote.convertToCallNote(phoneNumber, callDate);
|
|
|
|
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType,
|
|
|
|
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType,
|
|
|
|
bgResId);
|
|
|
|
bgResId);
|
|
|
|
}
|
|
|
|
}//创建一个新的WorkingNote
|
|
|
|
|
|
|
|
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
|
|
|
@ -262,15 +262,19 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
super.onResume();
|
|
|
|
initNoteScreen();
|
|
|
|
initNoteScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initNoteScreen() {
|
|
|
|
private void initNoteScreen() {
|
|
|
|
|
|
|
|
//对界面的初始化操作
|
|
|
|
mNoteEditor.setTextAppearance(this, TextAppearanceResources
|
|
|
|
mNoteEditor.setTextAppearance(this, TextAppearanceResources
|
|
|
|
.getTexAppearanceResource(mFontSizeId));
|
|
|
|
.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
|
|
|
//设置外观
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -295,29 +299,33 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
showAlertHeader();
|
|
|
|
showAlertHeader();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置闹钟的显示
|
|
|
|
private void showAlertHeader() {
|
|
|
|
private void showAlertHeader() {
|
|
|
|
if (mWorkingNote.hasClockAlert()) {
|
|
|
|
if (mWorkingNote.hasClockAlert()) {
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
if (time > mWorkingNote.getAlertDate()) {
|
|
|
|
if (time > mWorkingNote.getAlertDate()) {
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired);
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
//如果系统时间大于了闹钟设置的时间,那么闹钟失效
|
|
|
|
|
|
|
|
else {
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString(
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString(
|
|
|
|
mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS));
|
|
|
|
mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE);
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
//显示闹钟开启的图标
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
initActivityState(intent);
|
|
|
|
initActivityState(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
@ -329,26 +337,27 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
if (!mWorkingNote.existInDatabase()) {
|
|
|
|
if (!mWorkingNote.existInDatabase()) {
|
|
|
|
saveNote();
|
|
|
|
saveNote();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//在创建一个新的标签时,先在数据库中匹配
|
|
|
|
|
|
|
|
//如果不存在,那么先在数据库中存储
|
|
|
|
outState.putLong(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
outState.putLong(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
|
|
|
|
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
|
|
|
|
&& !inRangeOfView(mNoteBgColorSelector, ev)) {
|
|
|
|
&& !inRangeOfView(mNoteBgColorSelector, ev)) {
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}//颜色选择器在屏幕上可见
|
|
|
|
|
|
|
|
|
|
|
|
if (mFontSizeSelector.getVisibility() == View.VISIBLE
|
|
|
|
if (mFontSizeSelector.getVisibility() == View.VISIBLE
|
|
|
|
&& !inRangeOfView(mFontSizeSelector, ev)) {
|
|
|
|
&& !inRangeOfView(mFontSizeSelector, ev)) {
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}//字体大小选择器在屏幕上可见
|
|
|
|
return super.dispatchTouchEvent(ev);
|
|
|
|
return super.dispatchTouchEvent(ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//对屏幕触控的坐标进行操作
|
|
|
|
private boolean inRangeOfView(View view, MotionEvent ev) {
|
|
|
|
private boolean inRangeOfView(View view, MotionEvent ev) {
|
|
|
|
int []location = new int[2];
|
|
|
|
int []location = new int[2];
|
|
|
|
view.getLocationOnScreen(location);
|
|
|
|
view.getLocationOnScreen(location);
|
|
|
@ -357,9 +366,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
if (ev.getX() < x
|
|
|
|
if (ev.getX() < x
|
|
|
|
|| ev.getX() > (x + view.getWidth())
|
|
|
|
|| ev.getX() > (x + view.getWidth())
|
|
|
|
|| ev.getY() < y
|
|
|
|
|| ev.getY() < y
|
|
|
|
|| ev.getY() > (y + view.getHeight())) {
|
|
|
|
|| ev.getY() > (y + view.getHeight()))
|
|
|
|
return false;
|
|
|
|
//如果触控的位置超出了给定的范围,返回false
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -405,7 +416,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clearSettingState();
|
|
|
|
clearSettingState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//和桌面小工具的同步
|
|
|
|
private void updateWidget() {
|
|
|
|
private void updateWidget() {
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
|
|
|
|
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
|
|
|
@ -418,13 +429,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
|
|
|
|
mWorkingNote.getWidgetId()
|
|
|
|
mWorkingNote.getWidgetId()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
sendBroadcast(intent);
|
|
|
|
sendBroadcast(intent);
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
public void onClick(View v) {
|
|
|
|
int id = v.getId();
|
|
|
|
int id = v.getId();
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
@ -472,14 +484,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void onBackgroundColorChanged() {
|
|
|
|
public void onBackgroundColorChanged() {
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
View.VISIBLE);
|
|
|
|
View.VISIBLE);
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//对选择菜单的准备
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
if (isFinishing()) {
|
|
|
|
if (isFinishing()) {
|
|
|
@ -504,13 +515,19 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:动态改变菜单选项内容
|
|
|
|
|
|
|
|
* 函数实现:如下注释
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
int itemId = item.getItemId();
|
|
|
|
int itemId = item.getItemId();
|
|
|
|
|
|
|
|
//创建便签
|
|
|
|
if (itemId == R.id.menu_new_note) {
|
|
|
|
if (itemId == R.id.menu_new_note) {
|
|
|
|
createNewNote();
|
|
|
|
createNewNote();
|
|
|
|
} else if (itemId == R.id.menu_delete) {
|
|
|
|
}
|
|
|
|
|
|
|
|
//删除便签
|
|
|
|
|
|
|
|
else if (itemId == R.id.menu_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);
|
|
|
@ -543,27 +560,37 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:建立事件提醒器
|
|
|
|
|
|
|
|
* 函数实现:如下注释
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void setReminder() {
|
|
|
|
private void setReminder() {
|
|
|
|
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
|
|
|
|
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
|
|
|
|
|
|
|
|
// 建立修改时间日期的对话框
|
|
|
|
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
|
|
|
|
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
|
|
|
|
public void OnDateTimeSet(AlertDialog dialog, long date) {
|
|
|
|
public void OnDateTimeSet(AlertDialog dialog, long date) {
|
|
|
|
mWorkingNote.setAlertDate(date , true);
|
|
|
|
mWorkingNote.setAlertDate(date , true);
|
|
|
|
|
|
|
|
//选择提醒的日期
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
//建立时间日期的监听器
|
|
|
|
d.show();
|
|
|
|
d.show();
|
|
|
|
|
|
|
|
//显示对话框
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Share note to apps that support {@link Intent#ACTION_SEND} action
|
|
|
|
* Share note to apps that support {@link Intent#ACTION_SEND} action
|
|
|
|
* and {@text/plain} type
|
|
|
|
* and {@text/plain} type
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
//共享便签
|
|
|
|
private void sendTo(Context context, String info) {
|
|
|
|
private void sendTo(Context context, String info) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, info);
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, info);
|
|
|
|
intent.setType("text/plain");
|
|
|
|
intent.setType("text/plain");
|
|
|
|
context.startActivity(intent);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//创建便签
|
|
|
|
private void createNewNote() {
|
|
|
|
private void createNewNote() {
|
|
|
|
// Firstly, save current editing notes
|
|
|
|
// Firstly, save current editing notes
|
|
|
|
saveNote();
|
|
|
|
saveNote();
|
|
|
@ -575,7 +602,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId());
|
|
|
|
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId());
|
|
|
|
startActivity(intent);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//删除便签
|
|
|
|
private void deleteCurrentNote() {
|
|
|
|
private void deleteCurrentNote() {
|
|
|
|
if (mWorkingNote.existInDatabase()) {
|
|
|
|
if (mWorkingNote.existInDatabase()) {
|
|
|
|
HashSet<Long> ids = new HashSet<Long>();
|
|
|
|
HashSet<Long> ids = new HashSet<Long>();
|
|
|
@ -597,11 +624,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mWorkingNote.markDeleted(true);
|
|
|
|
mWorkingNote.markDeleted(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//判断是否同步
|
|
|
|
private boolean isSyncMode() {
|
|
|
|
private boolean isSyncMode() {
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//设置提醒时间
|
|
|
|
public void onClockAlertChanged(long date, boolean set) {
|
|
|
|
public void onClockAlertChanged(long date, boolean set) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* User could set clock to an unsaved note, so before setting the
|
|
|
|
* User could set clock to an unsaved note, so before setting the
|
|
|
@ -631,11 +658,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
showToast(R.string.error_note_empty_for_clock);
|
|
|
|
showToast(R.string.error_note_empty_for_clock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//widget改变更新widget
|
|
|
|
public void onWidgetChanged() {
|
|
|
|
public void onWidgetChanged() {
|
|
|
|
updateWidget();
|
|
|
|
updateWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//删除编辑文本框触发的事件
|
|
|
|
public void onEditTextDelete(int index, String text) {
|
|
|
|
public void onEditTextDelete(int index, String text) {
|
|
|
|
int childCount = mEditTextList.getChildCount();
|
|
|
|
int childCount = mEditTextList.getChildCount();
|
|
|
|
if (childCount == 1) {
|
|
|
|
if (childCount == 1) {
|
|
|
@ -661,7 +688,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
edit.requestFocus();
|
|
|
|
edit.requestFocus();
|
|
|
|
edit.setSelection(length);
|
|
|
|
edit.setSelection(length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//进入编辑文本框所触发的事件
|
|
|
|
public void onEditTextEnter(int index, String text) {
|
|
|
|
public void onEditTextEnter(int index, String text) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Should not happen, check for debug
|
|
|
|
* Should not happen, check for debug
|
|
|
@ -680,7 +707,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
.setIndex(i);
|
|
|
|
.setIndex(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:切换至列表模式
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void switchToListMode(String text) {
|
|
|
|
private void switchToListMode(String text) {
|
|
|
|
mEditTextList.removeAllViews();
|
|
|
|
mEditTextList.removeAllViews();
|
|
|
|
String[] items = text.split("\n");
|
|
|
|
String[] items = text.split("\n");
|
|
|
@ -697,7 +726,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
mNoteEditor.setVisibility(View.GONE);
|
|
|
|
mNoteEditor.setVisibility(View.GONE);
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:获取高亮效果的反馈情况
|
|
|
|
|
|
|
|
* 函数实现:如下注释
|
|
|
|
|
|
|
|
*/
|
|
|
|
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
|
|
|
|
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
|
|
|
|
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
|
|
|
|
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
|
|
|
|
if (!TextUtils.isEmpty(userQuery)) {
|
|
|
|
if (!TextUtils.isEmpty(userQuery)) {
|
|
|
@ -714,7 +746,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return spannable;
|
|
|
|
return spannable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:获取列表项
|
|
|
|
|
|
|
|
* 函数实现:如下注释
|
|
|
|
|
|
|
|
*/
|
|
|
|
private View getListItem(String item, int index) {
|
|
|
|
private View getListItem(String item, int index) {
|
|
|
|
View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
|
|
|
|
View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
|
|
|
|
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
@ -745,7 +780,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
edit.setText(getHighlightQueryResult(item, mUserQuery));
|
|
|
|
edit.setText(getHighlightQueryResult(item, mUserQuery));
|
|
|
|
return view;
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:便签内容发生改变所 触发的事件
|
|
|
|
|
|
|
|
* 函数实现:如下注释
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void onTextChange(int index, boolean hasText) {
|
|
|
|
public void onTextChange(int index, boolean hasText) {
|
|
|
|
if (index >= mEditTextList.getChildCount()) {
|
|
|
|
if (index >= mEditTextList.getChildCount()) {
|
|
|
|
Log.e(TAG, "Wrong index, should not happen");
|
|
|
|
Log.e(TAG, "Wrong index, should not happen");
|
|
|
@ -758,46 +796,70 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:检查模式和列表模式的切换
|
|
|
|
|
|
|
|
* 函数实现:如下注释
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void onCheckListModeChanged(int oldMode, int newMode) {
|
|
|
|
public void onCheckListModeChanged(int oldMode, int newMode) {
|
|
|
|
if (newMode == TextNote.MODE_CHECK_LIST) {
|
|
|
|
if (newMode == TextNote.MODE_CHECK_LIST) {
|
|
|
|
switchToListMode(mNoteEditor.getText().toString());
|
|
|
|
switchToListMode(mNoteEditor.getText().toString());
|
|
|
|
|
|
|
|
//检查模式切换到列表模式
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (!getWorkingText()) {
|
|
|
|
if (!getWorkingText()) {
|
|
|
|
mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ",
|
|
|
|
mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ",
|
|
|
|
""));
|
|
|
|
""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//若是获取到文本就改变其检查标记
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
//修改文本编辑器的内容和可见性
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:设置勾选选项表并返回是否勾选的标记
|
|
|
|
|
|
|
|
* 函数实现:如下注释
|
|
|
|
|
|
|
|
*/
|
|
|
|
private boolean getWorkingText() {
|
|
|
|
private boolean getWorkingText() {
|
|
|
|
boolean hasChecked = false;
|
|
|
|
boolean hasChecked = false;
|
|
|
|
|
|
|
|
//初始化check标记
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
|
|
|
// 若模式为CHECK_LIST
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
//创建可变字符串
|
|
|
|
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
View view = mEditTextList.getChildAt(i);
|
|
|
|
View view = mEditTextList.getChildAt(i);
|
|
|
|
|
|
|
|
//遍历所有子编辑框的视图
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
if (!TextUtils.isEmpty(edit.getText())) {
|
|
|
|
if (!TextUtils.isEmpty(edit.getText())) {
|
|
|
|
|
|
|
|
//若文本不为空
|
|
|
|
if (((CheckBox) view.findViewById(R.id.cb_edit_item)).isChecked()) {
|
|
|
|
if (((CheckBox) view.findViewById(R.id.cb_edit_item)).isChecked()) {
|
|
|
|
|
|
|
|
//该选项框已打钩
|
|
|
|
sb.append(TAG_CHECKED).append(" ").append(edit.getText()).append("\n");
|
|
|
|
sb.append(TAG_CHECKED).append(" ").append(edit.getText()).append("\n");
|
|
|
|
hasChecked = true;
|
|
|
|
hasChecked = true;
|
|
|
|
|
|
|
|
//扩展字符串为已打钩并把标记置true
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
sb.append(TAG_UNCHECKED).append(" ").append(edit.getText()).append("\n");
|
|
|
|
sb.append(TAG_UNCHECKED).append(" ").append(edit.getText()).append("\n");
|
|
|
|
|
|
|
|
//扩展字符串添加未打钩
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mWorkingNote.setWorkingText(sb.toString());
|
|
|
|
mWorkingNote.setWorkingText(sb.toString());
|
|
|
|
|
|
|
|
//利用编辑好的字符串设置运行便签的内容
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
mWorkingNote.setWorkingText(mNoteEditor.getText().toString());
|
|
|
|
mWorkingNote.setWorkingText(mNoteEditor.getText().toString());
|
|
|
|
|
|
|
|
// 若不是该模式直接用编辑器中的内容设置运行中标签的内容
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasChecked;
|
|
|
|
return hasChecked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:保存便签
|
|
|
|
|
|
|
|
* 函数实现:如下注释
|
|
|
|
|
|
|
|
*/
|
|
|
|
private boolean saveNote() {
|
|
|
|
private boolean saveNote() {
|
|
|
|
getWorkingText();
|
|
|
|
getWorkingText();
|
|
|
|
boolean saved = mWorkingNote.saveNote();
|
|
|
|
boolean saved = mWorkingNote.saveNote();
|
|
|
|
|
|
|
|
//运行 getWorkingText()之后保存
|
|
|
|
if (saved) {
|
|
|
|
if (saved) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* There are two modes from List view to edit view, open one note,
|
|
|
|
* There are two modes from List view to edit view, open one note,
|
|
|
@ -806,11 +868,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* new node requires to the top of the list. This code
|
|
|
|
* new node requires to the top of the list. This code
|
|
|
|
* {@link #RESULT_OK} is used to identify the create/edit state
|
|
|
|
* {@link #RESULT_OK} is used to identify the create/edit state
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
//如英文注释所说链接RESULT_OK是为了识别保存的2种情况,一是创建后保存,二是修改后保存
|
|
|
|
setResult(RESULT_OK);
|
|
|
|
setResult(RESULT_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return saved;
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:将便签发送至桌面
|
|
|
|
|
|
|
|
* 函数实现:如下注释
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void sendToDesktop() {
|
|
|
|
private void sendToDesktop() {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Before send message to home, we should make sure that current
|
|
|
|
* Before send message to home, we should make sure that current
|
|
|
@ -819,12 +886,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
if (!mWorkingNote.existInDatabase()) {
|
|
|
|
if (!mWorkingNote.existInDatabase()) {
|
|
|
|
saveNote();
|
|
|
|
saveNote();
|
|
|
|
|
|
|
|
//若不存在数据也就是新的标签就保存起来先
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mWorkingNote.getNoteId() > 0) {
|
|
|
|
if (mWorkingNote.getNoteId() > 0) {
|
|
|
|
|
|
|
|
//若是有内容
|
|
|
|
Intent sender = new Intent();
|
|
|
|
Intent sender = new Intent();
|
|
|
|
Intent shortcutIntent = new Intent(this, NoteEditActivity.class);
|
|
|
|
Intent shortcutIntent = new Intent(this, NoteEditActivity.class);
|
|
|
|
|
|
|
|
//建立发送到桌面的连接器
|
|
|
|
shortcutIntent.setAction(Intent.ACTION_VIEW);
|
|
|
|
shortcutIntent.setAction(Intent.ACTION_VIEW);
|
|
|
|
|
|
|
|
//链接为一个视图
|
|
|
|
shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
|
|
|
sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
|
|
|
sender.putExtra(Intent.EXTRA_SHORTCUT_NAME,
|
|
|
|
sender.putExtra(Intent.EXTRA_SHORTCUT_NAME,
|
|
|
@ -832,9 +903,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
sender.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
|
|
|
|
sender.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
|
|
|
|
Intent.ShortcutIconResource.fromContext(this, R.drawable.icon_app));
|
|
|
|
Intent.ShortcutIconResource.fromContext(this, R.drawable.icon_app));
|
|
|
|
sender.putExtra("duplicate", true);
|
|
|
|
sender.putExtra("duplicate", true);
|
|
|
|
|
|
|
|
//将便签的相关信息都添加到要发送的文件里
|
|
|
|
sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
|
|
|
sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
|
|
|
|
|
|
|
//设置sneder的行为是发送
|
|
|
|
showToast(R.string.info_note_enter_desktop);
|
|
|
|
showToast(R.string.info_note_enter_desktop);
|
|
|
|
sendBroadcast(sender);
|
|
|
|
sendBroadcast(sender);
|
|
|
|
|
|
|
|
//显示到桌面
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* There is the condition that user has input nothing (the note is
|
|
|
|
* There is the condition that user has input nothing (the note is
|
|
|
@ -843,20 +917,28 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
Log.e(TAG, "Send to desktop error");
|
|
|
|
Log.e(TAG, "Send to desktop error");
|
|
|
|
showToast(R.string.error_note_empty_for_send_to_desktop);
|
|
|
|
showToast(R.string.error_note_empty_for_send_to_desktop);
|
|
|
|
|
|
|
|
//空便签直接报错
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:编辑小图标的标题
|
|
|
|
|
|
|
|
*/
|
|
|
|
private String makeShortcutIconTitle(String content) {
|
|
|
|
private String makeShortcutIconTitle(String content) {
|
|
|
|
content = content.replace(TAG_CHECKED, "");
|
|
|
|
content = content.replace(TAG_CHECKED, "");
|
|
|
|
content = content.replace(TAG_UNCHECKED, "");
|
|
|
|
content = content.replace(TAG_UNCHECKED, "");
|
|
|
|
return content.length() > SHORTCUT_ICON_TITLE_MAX_LEN ? content.substring(0,
|
|
|
|
return content.length() > SHORTCUT_ICON_TITLE_MAX_LEN ? content.substring(0,
|
|
|
|
SHORTCUT_ICON_TITLE_MAX_LEN) : content;
|
|
|
|
SHORTCUT_ICON_TITLE_MAX_LEN) : content;
|
|
|
|
|
|
|
|
//直接设置为content中的内容并返回,有勾选和未勾选2种
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:显示提示的视图
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void showToast(int resId) {
|
|
|
|
private void showToast(int resId) {
|
|
|
|
showToast(resId, Toast.LENGTH_SHORT);
|
|
|
|
showToast(resId, Toast.LENGTH_SHORT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 函数功能:持续显示提示的视图
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|