|
|
@ -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;
|
|
|
@ -71,9 +55,21 @@ import java.util.Map;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Package: net.micode.notes.ui
|
|
|
|
|
|
|
|
* @ClassName: NoteEditActivity
|
|
|
|
|
|
|
|
* @Description:
|
|
|
|
|
|
|
|
* 该类主要是针对标签的编辑
|
|
|
|
|
|
|
|
* 继承了系统内部许多和监听有关的类
|
|
|
|
|
|
|
|
* @Author: YangYizhe
|
|
|
|
|
|
|
|
* @CreateDate: 12/21/2023 12:47 AM
|
|
|
|
|
|
|
|
* @Version: 1.0
|
|
|
|
|
|
|
|
*/
|
|
|
|
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 +79,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
@ -119,21 +114,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "NoteEditActivity";
|
|
|
|
private static final String TAG = "NoteEditActivity";
|
|
|
|
|
|
|
|
|
|
|
|
private HeadViewHolder mNoteHeaderHolder;
|
|
|
|
private HeadViewHolder mNoteHeaderHolder;
|
|
|
|
|
|
|
|
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
|
|
|
|
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
|
|
|
|
|
|
|
|
private View mFontSizeSelector;
|
|
|
|
private View mFontSizeSelector;
|
|
|
|
|
|
|
|
|
|
|
|
private EditText mNoteEditor;
|
|
|
|
private EditText mNoteEditor;
|
|
|
|
|
|
|
|
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
|
|
|
|
public WorkingNote mWorkingNote;
|
|
|
|
private WorkingNote mWorkingNote;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
|
private int mFontSizeId;
|
|
|
|
private int mFontSizeId;
|
|
|
|
|
|
|
|
|
|
|
@ -148,12 +135,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
|
|
private String mUserQuery;
|
|
|
|
private String mUserQuery;
|
|
|
|
private Pattern mPattern;
|
|
|
|
private Pattern mPattern;
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
*在 Activity 创建时进行一些初始化工作,包括设置布局、初始化状态和资源等操作
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
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;
|
|
|
@ -179,6 +167,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,25 +177,29 @@ 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 = "";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -215,7 +208,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
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
|
|
|
|
|
|
|
|
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,8 +215,6 @@ 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));
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
if (callDate != 0 && phoneNumber != null) {
|
|
|
|
if (callDate != 0 && phoneNumber != null) {
|
|
|
@ -262,12 +252,14 @@ 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));
|
|
|
@ -300,7 +292,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -312,12 +305,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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);
|
|
|
@ -332,7 +325,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
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
|
|
|
@ -357,7 +349,8 @@ 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;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -405,7 +398,6 @@ 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) {
|
|
|
@ -425,6 +417,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
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 +465,12 @@ 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 +495,13 @@ 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);
|
|
|
@ -548,11 +539,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
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
|
|
|
@ -563,7 +556,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
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 +567,6 @@ 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 +588,9 @@ 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 +620,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
showToast(R.string.error_note_empty_for_clock);
|
|
|
|
showToast(R.string.error_note_empty_for_clock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 +648,6 @@ 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 +666,6 @@ 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 +682,6 @@ 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 +698,6 @@ 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 +728,6 @@ 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");
|
|
|
@ -761,43 +743,59 @@ 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,6 +804,7 @@ 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;
|
|
|
@ -845,18 +844,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|