|
|
|
@ -158,20 +158,22 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
/**
|
|
|
|
|
* @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) {
|
|
|
|
|
/**
|
|
|
|
|
* @method: onCreate
|
|
|
|
|
* @description: 描述一下方法的作用
|
|
|
|
|
* @date: 2023/12/18 23:22
|
|
|
|
|
* @author: zhoukexing
|
|
|
|
|
* @param: [savedInstanceState]
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
|
// savedInstanceState? @zhoukexing 2023/12/20 23:45
|
|
|
|
|
finish();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -211,6 +213,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
*/
|
|
|
|
|
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 = "";
|
|
|
|
|
|
|
|
|
@ -228,7 +231,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
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);
|
|
|
|
@ -236,20 +239,21 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
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) {
|
|
|
|
@ -259,6 +263,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
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);
|
|
|
|
@ -270,7 +275,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
widgetType, bgResId);
|
|
|
|
|
mWorkingNote.convertToCallNote(phoneNumber, callDate);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
} else { // 没有要显示的电话
|
|
|
|
|
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType,
|
|
|
|
|
bgResId);
|
|
|
|
|
}
|
|
|
|
@ -284,6 +289,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
mWorkingNote.setOnSettingStatusChangedListener(this);
|
|
|
|
|
// this是WorkingNote @zhoukexing 2023/12/21 0:08
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -456,6 +462,13 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
clearSettingState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method updateWidget
|
|
|
|
|
* @description 该方法用于实现与桌面小工具同步的功能
|
|
|
|
|
* @date: 2023-12-18 21:37
|
|
|
|
|
* @author: 郑鲲鹏
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
private void updateWidget() {
|
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
|
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
|
|
|
|
@ -570,12 +583,13 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
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();
|
|
|
|
@ -624,8 +638,19 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
* Share note to apps that support {@link Intent#ACTION_SEND} action
|
|
|
|
|
* and {@text/plain} type
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @method sendTo
|
|
|
|
|
* @description 该方法用于共享便签
|
|
|
|
|
* @date: 2023-12-18 0:57
|
|
|
|
|
* @author: 郑鲲鹏
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
private void sendTo(Context context, String info) {
|
|
|
|
|
// 新建intent消息
|
|
|
|
|
// 2023-12-18 1:00
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
|
// 将要分享的便签内容放入intent中
|
|
|
|
|
// 2023-12-18 1:01
|
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, info);
|
|
|
|
|
intent.setType("text/plain");
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
@ -652,7 +677,14 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
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>();
|
|
|
|
@ -908,6 +940,13 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
return saved;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method sendToDesktop
|
|
|
|
|
* @description 该方法用于将便签发送至桌面,创建快捷方式
|
|
|
|
|
* @date: 2023-12-18 17:27
|
|
|
|
|
* @author: 郑鲲鹏
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
private void sendToDesktop() {
|
|
|
|
|
/**
|
|
|
|
|
* Before send message to home, we should make sure that current
|
|
|
|
@ -919,9 +958,13 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mWorkingNote.getNoteId() > 0) {
|
|
|
|
|
// 新建intent消息,为创建桌面快捷方式的连接器
|
|
|
|
|
// 2023-12-18 17:29
|
|
|
|
|
Intent sender = new Intent();
|
|
|
|
|
Intent shortcutIntent = new Intent(this, NoteEditActivity.class);
|
|
|
|
|
shortcutIntent.setAction(Intent.ACTION_VIEW);
|
|
|
|
|
// 将便签的相关信息添加进intent中
|
|
|
|
|
// 2023-12-18 17:36
|
|
|
|
|
shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
|
sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
|
|
|
|
sender.putExtra(Intent.EXTRA_SHORTCUT_NAME,
|
|
|
|
@ -931,6 +974,8 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
|
|
|
|
|
sender.putExtra("duplicate", true);
|
|
|
|
|
sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
|
|
|
|
showToast(R.string.info_note_enter_desktop);
|
|
|
|
|
// 将便签显示于桌面
|
|
|
|
|
// 2023-12-18 17:38
|
|
|
|
|
sendBroadcast(sender);
|
|
|
|
|
} else {
|
|
|
|
|
/**
|
|
|
|
|