|
|
|
@ -72,8 +72,12 @@ import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
|
public class NoteEditActivity extends Activity //NOTE: extends--单继承,但可多重继承 @zhoukexing 2023/12/17 23:29
|
|
|
|
|
implements OnClickListener, NoteSettingChangedListener, OnTextViewChangeListener { //NOTE: implements--实现接口 @zhoukexing 2023/12/17 23:24
|
|
|
|
|
/** NOTE:
|
|
|
|
|
*
|
|
|
|
|
* @zhoukexing 2023/12/17 23:39
|
|
|
|
|
*/
|
|
|
|
|
private class HeadViewHolder {
|
|
|
|
|
public TextView tvModified;
|
|
|
|
|
|
|
|
|
@ -149,12 +153,27 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
private String mUserQuery;
|
|
|
|
|
private Pattern mPattern;
|
|
|
|
|
|
|
|
|
|
/*--- 以上是此类中的数据区,以下是方法区 ---*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @zkx 2023/12/18 复写了Activity类中的onCreate函数,当用户点击创建时,会进入这个函数
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @method: onCreate
|
|
|
|
|
* @description: 进入场景:在list页面,点击“写便签”时进入;在挂件页面,生成挂件时不进入,点进挂件时才进入;……
|
|
|
|
|
* allinall:在进入编辑页面前都会进入
|
|
|
|
|
* @date: 2023/12/18 23:22
|
|
|
|
|
* @author: zhoukexing
|
|
|
|
|
* @param: [savedInstanceState]
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
|
// savedInstanceState? @zhoukexing 2023/12/20 23:45
|
|
|
|
|
finish();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -180,12 +199,21 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean initActivityState(Intent intent) {
|
|
|
|
|
/**
|
|
|
|
|
* @method: initActivityState
|
|
|
|
|
* @description: 根据intent(Key-Value)内容,初始化一个便签编辑活动
|
|
|
|
|
* @date: 2023/12/18 23:31
|
|
|
|
|
* @author: zhoukexing
|
|
|
|
|
* @param: [intent]
|
|
|
|
|
* @return: boolean 为真则初始化成功,为假则失败。失败原因:不存在、(call)load失败、intent内容错误
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* If the user specified the {@link Intent#ACTION_VIEW} but not provided with id,
|
|
|
|
|
* then jump to the NotesListActivity
|
|
|
|
|
*/
|
|
|
|
|
mWorkingNote = null;
|
|
|
|
|
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
|
|
|
|
|
// 进入场景:点进一个已有便签 @zhoukexing 2023/12/21 0:14
|
|
|
|
|
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
|
|
|
|
|
mUserQuery = "";
|
|
|
|
|
|
|
|
|
@ -203,7 +231,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
showToast(R.string.error_note_not_exist);
|
|
|
|
|
finish();
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
} else {// 如果在数据库里存在,就根据noteId从数据库中加载到工作便签里来 @zhoukexing 2023/12/21 0:16
|
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);
|
|
|
|
|
if (mWorkingNote == null) {
|
|
|
|
|
Log.e(TAG, "load note failed with note id" + noteId);
|
|
|
|
@ -211,20 +239,21 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
|
getWindow().setSoftInputMode(// 猜:平滑地展示便签内容 @zhoukexing 2023/12/21 0:18
|
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
|
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
|
|
|
|
|
// New note
|
|
|
|
|
// 进入场景:一个New note
|
|
|
|
|
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
|
|
|
|
|
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
|
|
|
|
|
AppWidgetManager.INVALID_APPWIDGET_ID);
|
|
|
|
|
int widgetType = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_TYPE,
|
|
|
|
|
Notes.TYPE_WIDGET_INVALIDE);
|
|
|
|
|
Notes.TYPE_WIDGET_INVALIDE); // widgetType=0: 新建的挂件,空的 @zhoukexing 2023/12/21 0:02
|
|
|
|
|
int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,
|
|
|
|
|
ResourceParser.getDefaultBgId(this));
|
|
|
|
|
ResourceParser.getDefaultBgId(this));// TODO: 2023/12/21 背景色的设置
|
|
|
|
|
|
|
|
|
|
// Parse call-record note
|
|
|
|
|
// Parse call-record note todo
|
|
|
|
|
// 解析文档,看是否有号码存在,以便展示的时候渲染 @zhoukexing 2023/12/20 23:49
|
|
|
|
|
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
|
|
|
|
|
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
|
|
|
|
|
if (callDate != 0 && phoneNumber != null) {
|
|
|
|
@ -234,6 +263,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
long noteId = 0;
|
|
|
|
|
if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(),
|
|
|
|
|
phoneNumber, callDate)) > 0) {
|
|
|
|
|
// TODO: 2023/12/20
|
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);
|
|
|
|
|
if (mWorkingNote == null) {
|
|
|
|
|
Log.e(TAG, "load call note failed with note id" + noteId);
|
|
|
|
@ -245,7 +275,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
widgetType, bgResId);
|
|
|
|
|
mWorkingNote.convertToCallNote(phoneNumber, callDate);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
} else { // 没有要显示的电话
|
|
|
|
|
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType,
|
|
|
|
|
bgResId);
|
|
|
|
|
}
|
|
|
|
@ -259,6 +289,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
mWorkingNote.setOnSettingStatusChangedListener(this);
|
|
|
|
|
// this是WorkingNote @zhoukexing 2023/12/21 0:08
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -381,6 +412,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initResources() {
|
|
|
|
|
/**
|
|
|
|
|
* @method: initResources
|
|
|
|
|
* @description: 初始化资源。被onCreate唯一调用
|
|
|
|
|
* @date: 2023/12/18 23:36
|
|
|
|
|
* @author: zhoukexing
|
|
|
|
|
* @param: []
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
mHeadViewPanel = findViewById(R.id.note_title);
|
|
|
|
|
mNoteHeaderHolder = new HeadViewHolder();
|
|
|
|
|
mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date);
|
|
|
|
@ -454,7 +493,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.VISIBLE);
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
|
- View.VISIBLE);
|
|
|
|
|
View.VISIBLE);
|
|
|
|
|
} else if (sBgSelectorBtnsMap.containsKey(id)) {
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
|
View.GONE);
|
|
|
|
@ -531,16 +570,26 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
/**
|
|
|
|
|
* @method: onOptionsItemSelected
|
|
|
|
|
* @description: 覆写了Activity.java里的onOptionsItemSelected,路线是menu-->item,
|
|
|
|
|
* 这里就是处理识别到的item
|
|
|
|
|
* @date: 2023/12/19 23:35
|
|
|
|
|
* @author: zhoukexing
|
|
|
|
|
* @param: [item]
|
|
|
|
|
* @return: boolean
|
|
|
|
|
*/
|
|
|
|
|
int itemId = item.getItemId();
|
|
|
|
|
if (itemId == R.id.menu_new_note) {
|
|
|
|
|
if (itemId == R.id.menu_new_note) { // 从item到itemid,用itemid导向对应的不同的动作 @zhoukexing 2023/12/19 23:38
|
|
|
|
|
createNewNote();
|
|
|
|
|
} else if (itemId == R.id.menu_delete) {
|
|
|
|
|
// 构建一个警告⚠对话框,让用户确认是否真的要删除便签 @zhoukexing 2023/12/21 0:41
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
|
builder.setTitle(getString(R.string.alert_title_delete));
|
|
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
|
builder.setMessage(getString(R.string.alert_message_delete_note));
|
|
|
|
|
builder.setPositiveButton(android.R.string.ok,
|
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
new DialogInterface.OnClickListener() {// TODO: 2023/12/21 传入了一个函数作为参数?
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
deleteCurrentNote();
|
|
|
|
|
finish();
|
|
|
|
@ -608,17 +657,34 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createNewNote() {
|
|
|
|
|
/**
|
|
|
|
|
* @method: createNewNote
|
|
|
|
|
* @description: 从编辑页面,点击“add note”会进入这个创建便签的方法。
|
|
|
|
|
* 此方法会保存并结束当前便签,用NoteEditActivity类实例化一个新的intent(活动意图),
|
|
|
|
|
* 设置行为和指定报错对象后,启动intent活动意图
|
|
|
|
|
* @date: 2023/12/19 23:03
|
|
|
|
|
* @author: zhoukexing
|
|
|
|
|
* @param: []
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
// Firstly, save current editing notes
|
|
|
|
|
saveNote();
|
|
|
|
|
|
|
|
|
|
// For safety, start a new NoteEditActivity
|
|
|
|
|
finish();
|
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class);
|
|
|
|
|
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
|
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class); //Q: 在类的内部,还没有实现完全时,启动这个类自己?@zkx 2023/12/17
|
|
|
|
|
intent.setAction(Intent.ACTION_INSERT_OR_EDIT); // 创建便签后,要插入或者编辑。Q: 为什么要插入 @zhoukexing 2023/12/19 22:57
|
|
|
|
|
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId());
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method: deleteCurrentNote
|
|
|
|
|
* @description: 删除当前便签。如果在数据库里,还要进一步判断是否在根目录下,是否为同步模式
|
|
|
|
|
* @date: 2023/12/21 0:48
|
|
|
|
|
* @author: zhoukexing
|
|
|
|
|
* @param: []
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
private void deleteCurrentNote() {
|
|
|
|
|
if (mWorkingNote.existInDatabase()) {
|
|
|
|
|
HashSet<Long> ids = new HashSet<Long>();
|
|
|
|
@ -850,8 +916,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean saveNote() {
|
|
|
|
|
/**
|
|
|
|
|
* @method: saveNote
|
|
|
|
|
* @description: 获取工作文本,调用真正的保存便签的方法,设置便签在list界面的位置
|
|
|
|
|
* @date: 2023/12/19 23:50
|
|
|
|
|
* @author: zhoukexing
|
|
|
|
|
* @param: []
|
|
|
|
|
* @return: boolean
|
|
|
|
|
*/
|
|
|
|
|
getWorkingText();
|
|
|
|
|
boolean saved = mWorkingNote.saveNote();
|
|
|
|
|
boolean saved = mWorkingNote.saveNote();// TODO: 2023/12/19 工作便签下的saveNote
|
|
|
|
|
if (saved) {
|
|
|
|
|
/**
|
|
|
|
|
* There are two modes from List view to edit view, open one note,
|
|
|
|
@ -860,7 +934,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
* new node requires to the top of the list. This code
|
|
|
|
|
* {@link #RESULT_OK} is used to identify the create/edit state
|
|
|
|
|
*/
|
|
|
|
|
setResult(RESULT_OK);
|
|
|
|
|
setResult(RESULT_OK); // RESULT_OK指示将该便签保存到list界面的顶端(因为这是新建的便签) @zhoukexing 2023/12/19 23:41
|
|
|
|
|
//Q: 这个setResult只在这里调用了,怎么实现的 @zkx 2023/12/19
|
|
|
|
|
}
|
|
|
|
|
return saved;
|
|
|
|
|
}
|
|
|
|
@ -927,4 +1002,4 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} //NOTE: 这一整个文件就是这一个类 @zhoukexing 2023/12/17 23:41
|
|
|
|
|