Compare commits

...

7 Commits
main ... zzw

@ -1,2 +1,17 @@
# xiaominote_code_analysis # xiaominote_code_analysis
<!-- static void _split_whole_name(const char *whole_name, char *fname, char *ext)
{
const char *p_ext;
p_ext = rindex(whole_name, '.');
if (NULL != p_ext)
{
strcpy(ext, p_ext);
snprintf(fname, p_ext - whole_name + 1, "%s", whole_name);
}
else
{
ext[0] = '\0';
strcpy(f1name, 1whole_name);
}
} -->

@ -0,0 +1 @@
testify

@ -25,6 +25,15 @@ import android.util.Log;
import java.util.HashMap; import java.util.HashMap;
/**
*
* @ProjectName: minode
* @Package: net.micode.notes.data
* @ClassName: Contact
* @Description:
* @Author:
* @Date: 2023-12-16 17:57
*/
public class Contact { public class Contact {
private static HashMap<String, String> sContactCache; private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact"; private static final String TAG = "Contact";
@ -35,18 +44,29 @@ public class Contact {
+ "(SELECT raw_contact_id " + "(SELECT raw_contact_id "
+ " FROM phone_lookup" + " FROM phone_lookup"
+ " WHERE min_match = '+')"; + " WHERE min_match = '+')";
/**
* @method getContact
* @description
* @date: 2023-12-16 19:24
* @author:
* @return string
*/
public static String getContact(Context context, String phoneNumber) { public static String getContact(Context context, String phoneNumber) {
if(sContactCache == null) { if(sContactCache == null) {
sContactCache = new HashMap<String, String>(); sContactCache = new HashMap<String, String>();
} }
// 查找HashMap中是否有phoneNumber的信息
// 2023-12-16 19:43
if(sContactCache.containsKey(phoneNumber)) { if(sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber); return sContactCache.get(phoneNumber);
} }
String selection = CALLER_ID_SELECTION.replace("+", String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
// 查找数据库中phoneNumber的信息
// 2023-12-16 19:43
Cursor cursor = context.getContentResolver().query( Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI, Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME }, new String [] { Phone.DISPLAY_NAME },
@ -54,6 +74,8 @@ public class Contact {
new String[] { phoneNumber }, new String[] { phoneNumber },
null); null);
// 检查是否查询到联系人找到则将相关信息加入HashMap中未找到则处理异常
// 2023-12-16 19:41
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
try { try {
String name = cursor.getString(0); String name = cursor.getString(0);

@ -33,7 +33,7 @@ public class Notes {
public static final int ID_ROOT_FOLDER = 0; public static final int ID_ROOT_FOLDER = 0;
public static final int ID_TEMPARAY_FOLDER = -1; public static final int ID_TEMPARAY_FOLDER = -1;
public static final int ID_CALL_RECORD_FOLDER = -2; public static final int ID_CALL_RECORD_FOLDER = -2;
public static final int ID_TRASH_FOLER = -3; public static final int ID_TRASH_FOLER = -3; // TODO: 2023/12/25 有trash文件夹
public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date"; public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date";
public static final String INTENT_EXTRA_BACKGROUND_ID = "net.micode.notes.background_color_id"; public static final String INTENT_EXTRA_BACKGROUND_ID = "net.micode.notes.background_color_id";
@ -161,10 +161,16 @@ public class Notes {
public static final String GTASK_ID = "gtask_id"; public static final String GTASK_ID = "gtask_id";
/** /**
* The version code * the version code
* <P> Type : INTEGER (long) </P> * <p> type : integer (long) </p>
*/ */
public static final String VERSION = "version"; public static final String VERSION = "version";
/**
* set top state
* <p> type : integer (long) </p>
*/
public static final String TOP = "top";
} }
public interface DataColumns { public interface DataColumns {

@ -30,7 +30,7 @@ import net.micode.notes.data.Notes.NoteColumns;
public class NotesDatabaseHelper extends SQLiteOpenHelper { public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "note.db"; private static final String DB_NAME = "note.db";
private static final int DB_VERSION = 4; private static final int DB_VERSION = 5;
public interface TABLE { public interface TABLE {
public static final String NOTE = "note"; public static final String NOTE = "note";
@ -60,7 +60,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," + NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," + NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," + NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.TOP + " INTEGER NOT NULL DEFAULT 0" +
")"; ")";
private static final String CREATE_DATA_TABLE_SQL = private static final String CREATE_DATA_TABLE_SQL =
@ -322,6 +323,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
oldVersion++; oldVersion++;
} }
if (oldVersion == 4) {
upgradeToV5(db);
oldVersion++;
}
if (reCreateTriggers) { if (reCreateTriggers) {
reCreateNoteTableTriggers(db); reCreateNoteTableTriggers(db);
reCreateDataTableTriggers(db); reCreateDataTableTriggers(db);
@ -359,4 +365,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION
+ " INTEGER NOT NULL DEFAULT 0"); + " INTEGER NOT NULL DEFAULT 0");
} }
private void upgradeToV5(SQLiteDatabase db) {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.TOP
+ " INTEGER NOT NULL DEFAULT 0");
}
} }

@ -48,6 +48,7 @@ public class NotesProvider extends ContentProvider {
private static final int URI_DATA_ITEM = 4; private static final int URI_DATA_ITEM = 4;
private static final int URI_SEARCH = 5; private static final int URI_SEARCH = 5;
private static final int URI_SEARCH_SUGGEST = 6; private static final int URI_SEARCH_SUGGEST = 6;
static { static {

@ -15,7 +15,6 @@
*/ */
package net.micode.notes.gtask.exception; package net.micode.notes.gtask.exception;
public class NetworkFailureException extends Exception { public class NetworkFailureException extends Exception {
private static final long serialVersionUID = 2107610287180234136L; private static final long serialVersionUID = 2107610287180234136L;
@ -26,8 +25,7 @@ public class NetworkFailureException extends Exception {
public NetworkFailureException(String paramString) { public NetworkFailureException(String paramString) {
super(paramString); super(paramString);
} }
public NetworkFailureException(String paramString, Throwable paramThrowable) { public NetworkFailureException(String paramString, Throwable paramThrowable) {
super(paramString, paramThrowable); super(paramString, paramThrowable);
} }
} }

@ -47,7 +47,15 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
/**
*
* @ProjectName: minode
* @Package: net.micode.notes.gtask.remote
* @ClassName: GTaskManager
* @Description: 便便
* @Author:
* @Date: 2023-12-18 0:17
*/
public class GTaskManager { public class GTaskManager {
private static final String TAG = GTaskManager.class.getSimpleName(); private static final String TAG = GTaskManager.class.getSimpleName();
@ -247,6 +255,13 @@ public class GTaskManager {
} }
} }
/**
* @method syncContent
* @description 便
* @date: 2023-12-18 0:01
* @author:
* @return void
*/
private void syncContent() throws NetworkFailureException { private void syncContent() throws NetworkFailureException {
int syncType; int syncType;
Cursor c = null; Cursor c = null;
@ -351,6 +366,13 @@ public class GTaskManager {
} }
/**
* @method syncFolder
* @description
* @date: 2023-12-18 0:04
* @author:
* @return void
*/
private void syncFolder() throws NetworkFailureException { private void syncFolder() throws NetworkFailureException {
Cursor c = null; Cursor c = null;
String gid; String gid;
@ -476,6 +498,13 @@ public class GTaskManager {
GTaskClient.getInstance().commitUpdate(); GTaskClient.getInstance().commitUpdate();
} }
/**
* @method doContentSync
* @description syncType便
* @date: 2023-12-18 0:08
* @author:
* @return void
*/
private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException { private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) { if (mCancelled) {
return; return;

@ -22,7 +22,15 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
/**
*
* @ProjectName: minode
* @Package: net.micode.notes.gtask.remote
* @ClassName: GTaskSyncService
* @Description: Gtask
* @Author:
* @Date: 2023-12-17 23:38
*/
public class GTaskSyncService extends Service { public class GTaskSyncService extends Service {
public final static String ACTION_STRING_NAME = "sync_action_type"; public final static String ACTION_STRING_NAME = "sync_action_type";
@ -42,6 +50,13 @@ public class GTaskSyncService extends Service {
private static String mSyncProgress = ""; private static String mSyncProgress = "";
/**
* @method startSync
* @description Gtask
* @date: 2023-12-17 23:42
* @author:
* @return void
*/
private void startSync() { private void startSync() {
if (mSyncTask == null) { if (mSyncTask == null) {
mSyncTask = new GTaskASyncTask(this, new GTaskASyncTask.OnCompleteListener() { mSyncTask = new GTaskASyncTask(this, new GTaskASyncTask.OnCompleteListener() {
@ -52,10 +67,19 @@ public class GTaskSyncService extends Service {
} }
}); });
sendBroadcast(""); sendBroadcast("");
// 使同步任务以单线程队列方式开启运行
// 2023-12-17 23:46
mSyncTask.execute(); mSyncTask.execute();
} }
} }
/**
* @method cancelSync
* @description Gtask
* @date: 2023-12-17 23:49
* @author:
* @return void
*/
private void cancelSync() { private void cancelSync() {
if (mSyncTask != null) { if (mSyncTask != null) {
mSyncTask.cancelSync(); mSyncTask.cancelSync();
@ -67,11 +91,20 @@ public class GTaskSyncService extends Service {
mSyncTask = null; mSyncTask = null;
} }
/**
* @method onStartCommand
* @description 使GtaskSyncService
* @date: 2023-12-17 23:53
* @author:
* @return int
*/
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
Bundle bundle = intent.getExtras(); Bundle bundle = intent.getExtras();
if (bundle != null && bundle.containsKey(ACTION_STRING_NAME)) { if (bundle != null && bundle.containsKey(ACTION_STRING_NAME)) {
switch (bundle.getInt(ACTION_STRING_NAME, ACTION_INVALID)) { switch (bundle.getInt(ACTION_STRING_NAME, ACTION_INVALID)) {
// 开始同步或取消同步
// 2023-12-17 23:52
case ACTION_START_SYNC: case ACTION_START_SYNC:
startSync(); startSync();
break; break;

@ -70,6 +70,10 @@ public class Note {
mNoteData = new NoteData(); mNoteData = new NoteData();
} }
public void setTopState(String key, int value) {
mNoteDiffValues.put(key, value);
}
public void setNoteValue(String key, String value) { public void setNoteValue(String key, String value) {
mNoteDiffValues.put(key, value); mNoteDiffValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);

@ -52,6 +52,8 @@ public class WorkingNote {
private int mWidgetType; private int mWidgetType;
private int mTop;
private long mFolderId; private long mFolderId;
private Context mContext; private Context mContext;
@ -78,7 +80,8 @@ public class WorkingNote {
NoteColumns.BG_COLOR_ID, NoteColumns.BG_COLOR_ID,
NoteColumns.WIDGET_ID, NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE, NoteColumns.WIDGET_TYPE,
NoteColumns.MODIFIED_DATE NoteColumns.MODIFIED_DATE,
NoteColumns.TOP
}; };
private static final int DATA_ID_COLUMN = 0; private static final int DATA_ID_COLUMN = 0;
@ -101,6 +104,8 @@ public class WorkingNote {
private static final int NOTE_MODIFIED_DATE_COLUMN = 5; private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
private static final int NOTE_TOP_STATE_COLUMN = 6;
// New note construct // New note construct
private WorkingNote(Context context, long folderId) { private WorkingNote(Context context, long folderId) {
mContext = context; mContext = context;
@ -111,6 +116,7 @@ public class WorkingNote {
mNoteId = 0; mNoteId = 0;
mIsDeleted = false; mIsDeleted = false;
mMode = 0; mMode = 0;
mTop = 0;
mWidgetType = Notes.TYPE_WIDGET_INVALIDE; mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
} }
@ -137,6 +143,7 @@ public class WorkingNote {
mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN); mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN);
mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN); mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN);
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN); mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
mTop = cursor.getInt(NOTE_TOP_STATE_COLUMN);
} }
cursor.close(); cursor.close();
} else { } else {
@ -176,6 +183,14 @@ public class WorkingNote {
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) { int widgetType, int defaultBgColorId) {
/**
* @method: createEmptyNote
* @description: 便便
* @date: 2023/12/20 23:55
* @author: zhoukexing
* @param: [context, folderId, widgetId, widgetType, defaultBgColorId]
* @return: net.micode.notes.model.WorkingNote WorkingNote
*/
WorkingNote note = new WorkingNote(context, folderId); WorkingNote note = new WorkingNote(context, folderId);
note.setBgColorId(defaultBgColorId); note.setBgColorId(defaultBgColorId);
note.setWidgetId(widgetId); note.setWidgetId(widgetId);
@ -187,16 +202,24 @@ public class WorkingNote {
return new WorkingNote(context, id, 0); return new WorkingNote(context, id, 0);
} }
public synchronized boolean saveNote() { public synchronized boolean saveNote() {// TODO: 2023/12/19 要仔细溯源看看
if (isWorthSaving()) { /**
if (!existInDatabase()) { * @method: saveNote
* @description: 便true
* @date: 2023/12/19 23:44
* @author: zhoukexing
* @param: []
* @return: boolean
*/
if (isWorthSaving()) { // 判断是否有新内容-->是否值得注释 @zhoukexing 2023/12/19 23:45
if (!existInDatabase()) { // 判断是否在数据库里存在==是新便签还是已有便签 @zhoukexing 2023/12/19 23:45
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) { if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
Log.e(TAG, "Create new note fail with id:" + mNoteId); Log.e(TAG, "Create new note fail with id:" + mNoteId);
return false; return false;
} }
} }
mNote.syncNote(mContext, mNoteId); mNote.syncNote(mContext, mNoteId); // 和远程同步 @zhoukexing 2023/12/19 23:46
/** /**
* Update widget content if there exist any widget of this note * Update widget content if there exist any widget of this note
@ -208,7 +231,7 @@ public class WorkingNote {
} }
return true; return true;
} else { } else {
return false; return false; // 没有需要保存的就返回false @zhoukexing 2023/12/19 23:46
} }
} }
@ -225,20 +248,56 @@ public class WorkingNote {
} }
} }
/**
* @method: setOnSettingStatusChangedListener
* @description: NoteEditActivityNoteSettingChangedListener
* @date: 2023/12/21 0:10
* @author: zhoukexing
* @param: [l] NoteEditActivity
* @return: void
*/
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
//Q: 这里的l是怎么获取的。l是NoteEditActivity @zkx 2023/12/21
mNoteSettingStatusListener = l; mNoteSettingStatusListener = l;
} }
public void reverseTopState() {
mTop ^= 1;
mNote.setTopState(NoteColumns.TOP, mTop);
}
public int getmTop(){
return mTop;
}
/**
* @Method setAlertDate
* @Date 2023/12/13 11:43
* @param date
* @param set
* @Author lenovo
* @Return void
* @Description
*/
public void setAlertDate(long date, boolean set) { public void setAlertDate(long date, boolean set) {
// 更新便签项中的提醒日期
if (date != mAlertDate) { if (date != mAlertDate) {
mAlertDate = date; mAlertDate = date;
mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate)); mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate));
} }
// 设置提醒的监听事件
if (mNoteSettingStatusListener != null) { if (mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onClockAlertChanged(date, set); mNoteSettingStatusListener.onClockAlertChanged(date, set);
} }
} }
/**
* @method: markDeleted
* @description:
* @date: 2023/12/21 0:50
* @author: zhoukexing
* @param: [mark]
* @return: void
*/
public void markDeleted(boolean mark) { public void markDeleted(boolean mark) {
mIsDeleted = mark; mIsDeleted = mark;
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID

@ -80,8 +80,15 @@ public class DataUtils {
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
} }
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids, /**
long folderId) { * @method: batchMoveToFolder
* @description: idsfolderId
* @date: 2024/12/26 3:32
* @author: zhoukexing
* @param: [resolver, ids, folderId]
* @return: boolean
*/
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids, long folderId) {
if (ids == null) { if (ids == null) {
Log.d(TAG, "the ids is null"); Log.d(TAG, "the ids is null");
return true; return true;
@ -135,8 +142,22 @@ public class DataUtils {
} }
return count; return count;
} }
/**
* @Method visibleInNoteDatabase
* @Date 2024/12/13 9:08
* @param resolver
* @param noteId
* @param type
* @Author lenovo
* @Return boolean
* @Description 访 noteId 便
*/
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
/**
* withAppendedId URI ID URI
* query Uri selection
* lenovo 2024/12/13 9:06
*/
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null,
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER, NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
@ -292,4 +313,13 @@ public class DataUtils {
} }
return snippet; return snippet;
} }
}
public static Cursor searchInNoteDatabase(ContentResolver resolver, String query) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String[]{NoteColumns.ID},
Notes.DataColumns.CONTENT + " LIKE'%" + query +"%'",
null,
null);
return cursor;
}
}

@ -37,6 +37,7 @@ public class ResourceParser {
public static final int TEXT_LARGE = 2; public static final int TEXT_LARGE = 2;
public static final int TEXT_SUPER = 3; public static final int TEXT_SUPER = 3;
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
public static class NoteBgResources { public static class NoteBgResources {

@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
@ -14,145 +14,189 @@
* limitations under the License. * limitations under the License.
*/ */
package net.micode.notes.ui; package net.micode.notes.ui;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener; import android.content.DialogInterface.OnDismissListener;
import android.content.Intent; import android.content.Intent;
import android.media.AudioManager; import android.media.AudioManager;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager; import android.os.PowerManager;
import android.provider.Settings; import android.provider.Settings;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import net.micode.notes.R; import net.micode.notes.R;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.DataUtils;
import java.io.IOException; import java.io.IOException;
/**
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener { *
private long mNoteId; */
private String mSnippet; public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
private static final int SNIPPET_PREW_MAX_LEN = 60; private long mNoteId; // 便签的ID
MediaPlayer mPlayer; private String mSnippet; // 便签的摘要信息
private static final int SNIPPET_PREW_MAX_LEN = 60; // 便签摘要信息的最大长度
@Override MediaPlayer mPlayer; // 用于播放闹钟提示音的MediaPlayer对象
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); @Override
requestWindowFeature(Window.FEATURE_NO_TITLE); /**
* @Method onCreate
final Window win = getWindow(); * @Date 2024/12/25 8:15
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); * @param savedInstanceState
* @Author lenovo
if (!isScreenOn()) { * @Return void
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON * @Description
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON */
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON protected void onCreate(Bundle savedInstanceState) {
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR); /**
} * Bundel mapkey-value
* super , onCreate
Intent intent = getIntent(); * lenovo 2024/12/25 8:39
*/
try { super.onCreate(savedInstanceState);
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1)); requestWindowFeature(Window.FEATURE_NO_TITLE); // 请求无标题栏窗口
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0, final Window win = getWindow();
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info) // 在屏幕锁定时显示
: mSnippet; win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
} catch (IllegalArgumentException e) {
e.printStackTrace(); // 锁屏时到闹钟提示时间后,点亮屏幕
return; if (!isScreenOn()) {
} win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
mPlayer = new MediaPlayer(); | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) { | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
showActionDialog(); }
playAlarmSound();
} else { Intent intent = getIntent(); // 获取启动该活动的Intent对象
finish();
} try {
} // 从Intent中获取便签的ID
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));
private boolean isScreenOn() { // 根据便签ID获取便签的摘要信息
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
return pm.isScreenOn(); // 如果摘要信息长度超过最大长度,则截取并添加省略号
} mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)
private void playAlarmSound() { : mSnippet;
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM); } catch (IllegalArgumentException e) {
e.printStackTrace(); // 打印异常信息
int silentModeStreams = Settings.System.getInt(getContentResolver(), return; // 如果获取便签ID或摘要信息失败则直接返回
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0); }
if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) { mPlayer = new MediaPlayer(); // 创建MediaPlayer对象
mPlayer.setAudioStreamType(silentModeStreams); // 查找数据库中有没有 mNoteId 的便签, 如果有则激发对话框 + 闹钟提示音
} else { if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); showActionDialog(); // 显示提醒对话框
} playAlarmSound(); // 播放闹钟提示音
try { } else {
mPlayer.setDataSource(this, url); finish(); // 如果数据库中没有该便签,则结束该活动
mPlayer.prepare(); }
mPlayer.setLooping(true); }
mPlayer.start();
} catch (IllegalArgumentException e) { /**
// TODO Auto-generated catch block *
e.printStackTrace(); * @return
} catch (SecurityException e) { */
// TODO Auto-generated catch block private boolean isScreenOn() {
e.printStackTrace(); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); // 获取电源管理服务
} catch (IllegalStateException e) { return pm.isScreenOn(); // 返回屏幕是否处于点亮状态
// TODO Auto-generated catch block }
e.printStackTrace();
} catch (IOException e) { /**
// TODO Auto-generated catch block *
e.printStackTrace(); */
} private void playAlarmSound() {
} Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM); // 获取默认闹钟提示音的URI
private void showActionDialog() { int silentModeStreams = Settings.System.getInt(getContentResolver(),
AlertDialog.Builder dialog = new AlertDialog.Builder(this); Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0); // 获取静音模式影响的音频流类型
dialog.setTitle(R.string.app_name);
dialog.setMessage(mSnippet); if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
dialog.setPositiveButton(R.string.notealert_ok, this); mPlayer.setAudioStreamType(silentModeStreams); // 设置MediaPlayer的音频流类型为静音模式影响的音频流类型
if (isScreenOn()) { } else {
dialog.setNegativeButton(R.string.notealert_enter, this); mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); // 设置MediaPlayer的音频流类型为闹钟音频流类型
} }
dialog.show().setOnDismissListener(this); try {
} mPlayer.setDataSource(this, url); // 设置MediaPlayer的数据源为默认闹钟提示音的URI
mPlayer.prepare(); // 准备MediaPlayer
public void onClick(DialogInterface dialog, int which) { mPlayer.setLooping(true); // 设置MediaPlayer为循环播放
switch (which) { mPlayer.start(); // 开始播放MediaPlayer
case DialogInterface.BUTTON_NEGATIVE: } catch (IllegalArgumentException e) {
Intent intent = new Intent(this, NoteEditActivity.class); // TODO Auto-generated catch block
intent.setAction(Intent.ACTION_VIEW); e.printStackTrace(); // 打印异常信息
intent.putExtra(Intent.EXTRA_UID, mNoteId); } catch (SecurityException e) {
startActivity(intent); // TODO Auto-generated catch block
break; e.printStackTrace(); // 打印异常信息
default: } catch (IllegalStateException e) {
break; // TODO Auto-generated catch block
} e.printStackTrace(); // 打印异常信息
} } catch (IOException e) {
// TODO Auto-generated catch block
public void onDismiss(DialogInterface dialog) { e.printStackTrace(); // 打印异常信息
stopAlarmSound(); }
finish(); }
}
/**
private void stopAlarmSound() { *
if (mPlayer != null) { */
mPlayer.stop(); private void showActionDialog() {
mPlayer.release(); AlertDialog.Builder dialog = new AlertDialog.Builder(this); // 创建AlertDialog构建器
mPlayer = null; dialog.setTitle(R.string.app_name); // 设置对话框标题为应用名称
} dialog.setMessage(mSnippet); // 设置对话框消息为便签的摘要信息
} dialog.setPositiveButton(R.string.notealert_ok, this); // 设置对话框的确定按钮,并指定点击事件监听器为当前对象
} if (isScreenOn()) {
dialog.setNegativeButton(R.string.notealert_enter, this); // 如果屏幕处于点亮状态,则设置对话框的取消按钮,并指定点击事件监听器为当前对象
}
dialog.show().setOnDismissListener(this); // 显示对话框,并设置对话框消失事件监听器为当前对象
}
/**
*
* @param dialog
* @param which
*/
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_NEGATIVE:
// 如果点击了取消按钮则启动便签编辑活动并传入便签的ID
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_UID, mNoteId);
startActivity(intent);
break;
default:
break;
}
}
/**
*
* @param dialog
*/
public void onDismiss(DialogInterface dialog) {
stopAlarmSound(); // 停止播放闹钟提示音
finish(); // 结束该活动
}
/**
*
*/
private void stopAlarmSound() {
if (mPlayer != null) {
mPlayer.stop(); // 停止MediaPlayer
mPlayer.release(); // 释放MediaPlayer资源
mPlayer = null; // 将MediaPlayer对象置为null
}
}
}

@ -35,6 +35,8 @@ import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.text.style.BackgroundColorSpan; import android.text.style.BackgroundColorSpan;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -51,6 +53,10 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.os.Environment;
import android.graphics.Bitmap;
import android.graphics.Typeface; // 自带四种字体
import net.micode.notes.R; import net.micode.notes.R;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
@ -65,15 +71,27 @@ import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
import net.micode.notes.widget.NoteWidgetProvider_2x; import net.micode.notes.widget.NoteWidgetProvider_2x;
import net.micode.notes.widget.NoteWidgetProvider_4x; import net.micode.notes.widget.NoteWidgetProvider_4x;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.Vector;
import java.io.File;
import java.io.FileOutputStream;
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 {
private Intent intent; //NOTE: implements--实现接口 @zhoukexing 2023/12/17 23:24
/** NOTE:
*
* @zhoukexing 2023/12/17 23:39
*/
private class HeadViewHolder { private class HeadViewHolder {
public TextView tvModified; public TextView tvModified;
@ -81,6 +99,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public TextView tvAlertDate; public TextView tvAlertDate;
// 顶部置顶文本
public TextView tvTopText;
// 顶部长度统计文本
public TextView tvTextNum;
public ImageView ibSetBgColor; public ImageView ibSetBgColor;
} }
@ -118,8 +142,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select); sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select);
} }
private static final String TAG = "NoteEditActivity"; private static final String TAG = "NoteEditActivity";
private static int mMaxRevokeTimes = 10;
private HeadViewHolder mNoteHeaderHolder; private HeadViewHolder mNoteHeaderHolder;
private View mHeadViewPanel; private View mHeadViewPanel;
@ -136,8 +165,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private SharedPreferences mSharedPrefs; private SharedPreferences mSharedPrefs;
private int mFontSizeId; private int mFontSizeId;
private int mFontStyleId;
private static final String PREFERENCE_FONT_SIZE = "pref_font_size"; private static final String PREFERENCE_FONT_SIZE = "pref_font_size";
private static final String PREFERENCE_FONT_STYLE = "pref_font_style";
private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10; private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10;
@ -149,15 +180,36 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private String mUserQuery; private String mUserQuery;
private Pattern mPattern; private Pattern mPattern;
// 存储改变的数据
private Vector<SpannableString> mHistory = new Vector<SpannableString>(mMaxRevokeTimes);
private boolean mIsRvoke;
/*--- 以上是此类中的数据区,以下是方法区 ---*/
/**
* @zkx 2023/12/18 ActivityonCreate
*/
/**
* @method: onCreate
* @description: list便
* allinall
*
* @date: 2023/12/18 23:22
* @author: zhoukexing
* @param: [savedInstanceState]
* @return: void
*/
@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())) {
// 表示之前保存的状态,用于还原数据 @lzk 2024/1/3 23:33
finish(); finish();
return; return;
} }
// 初始化资源。我要的设置字体就在这儿
initResources(); initResources();
} }
@ -180,18 +232,26 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
private boolean initActivityState(Intent intent) { private boolean initActivityState(Intent intent) {
/**
* @method: initActivityState
* @description: intentKey-Value便
* @date: 2023/12/18 23:31
* @author: zhoukexing
* @param: [intent]
* @return: boolean callloadintent
*/
/** /**
* 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,
* then jump to the NotesListActivity * then jump to the NotesListActivity
*/ */
mWorkingNote = null; mWorkingNote = null;
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) { if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
// 进入场景:点进一个已有便签 @zhoukexing 2023/12/21 0:14
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0); long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
mUserQuery = "";
/** /**
* Starting from the searched result * Starting from the searched result
*/ */
// 高亮搜索内容 @lzk 2024/1/3 10:10
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);
@ -203,7 +263,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
showToast(R.string.error_note_not_exist); showToast(R.string.error_note_not_exist);
finish(); finish();
return false; return false;
} else { }
else {// 如果在数据库里存在就根据noteId从数据库中加载到工作便签里来 @zhoukexing 2023/12/21 0:16
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);
@ -211,20 +272,22 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return false; return false;
} }
} }
getWindow().setSoftInputMode( getWindow().setSoftInputMode(// 猜:平滑地展示便签内容 @zhoukexing 2023/12/21 0:18
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())) { }
// New note 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);
int widgetType = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, 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, 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); 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) {
@ -234,6 +297,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
long noteId = 0; long noteId = 0;
if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(), if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(),
phoneNumber, callDate)) > 0) { phoneNumber, callDate)) > 0) {
// TODO: 2023/12/20
mWorkingNote = WorkingNote.load(this, noteId); mWorkingNote = WorkingNote.load(this, noteId);
if (mWorkingNote == null) { if (mWorkingNote == null) {
Log.e(TAG, "load call note failed with note id" + noteId); Log.e(TAG, "load call note failed with note id" + noteId);
@ -245,7 +309,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
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);
} }
@ -253,12 +318,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
getWindow().setSoftInputMode( getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); | WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
} else { }
else {
Log.e(TAG, "Intent not specified action, should not support"); Log.e(TAG, "Intent not specified action, should not support");
finish(); finish();
return false; return false;
} }
mWorkingNote.setOnSettingStatusChangedListener(this); mWorkingNote.setOnSettingStatusChangedListener(this);
// this是WorkingNote @zhoukexing 2023/12/21 0:08
return true; return true;
} }
@ -268,9 +335,20 @@ public class NoteEditActivity extends Activity implements OnClickListener,
initNoteScreen(); initNoteScreen();
} }
private void showTopHeader(){
if(mWorkingNote.getmTop() == 1){
mNoteHeaderHolder.tvTopText.setText("已置顶");
mNoteHeaderHolder.tvTopText.setVisibility(View.VISIBLE);
}
else{
mNoteHeaderHolder.tvTopText.setVisibility(View.GONE);
}
}
private void initNoteScreen() { private void initNoteScreen() {
mNoteEditor.setTextAppearance(this, TextAppearanceResources mNoteEditor.setTextAppearance(this, TextAppearanceResources
.getTexAppearanceResource(mFontSizeId)); .getTexAppearanceResource(mFontSizeId));
initFontStyle(mNoteEditor, mFontStyleId);
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) { if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
switchToListMode(mWorkingNote.getContent()); switchToListMode(mWorkingNote.getContent());
} else { } else {
@ -293,17 +371,57 @@ public class NoteEditActivity extends Activity implements OnClickListener,
* is not ready * is not ready
*/ */
showAlertHeader(); showAlertHeader();
showTopHeader();
} }
private void initFontStyle(EditText edit, int i) {
if (i == 0) {
edit.setTypeface(Typeface.DEFAULT);
} else if (i == 1) {
edit.setTypeface(Typeface.DEFAULT_BOLD);
} else if (i == 2) {
edit.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC));
} else if (i == 3) {
edit.setTypeface(Typeface.SERIF);
} else if (i == 4) {
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/FZSTK.ttf");
edit.setTypeface(tf);
} else if (i == 5) {
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/STXINGKA.ttf");
edit.setTypeface(tf);
} else if (i == 6) {
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/VINERITC.ttf");
edit.setTypeface(tf);
}
}
/**
* @Method showAlertHeader
* @Date 2023/12/13 11:32
* @Author lenovo
* @Return void
* @Description 便
*/
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()) {
// 闹钟时间大于当前时间, 显示 "Expired" 闹钟失效
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));
} }
/**
* setVisibility()
*
* VISIBLE
* INVISIBLE
* GNONE
* lenovo 2023/12/13 11:28
*/
mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE); mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE);
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE); mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE);
} else { } else {
@ -315,7 +433,15 @@ 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); // 若为搜索事件则设置高亮
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
mUserQuery = intent.getStringExtra(SearchManager.QUERY);
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
mNoteEditor.setSelection(mNoteEditor.getText().length());
}
else if(!initActivityState(intent)) {
Log.e(TAG, "Intent Type Error");
};
} }
@Override @Override
@ -363,15 +489,61 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true; return true;
} }
/**
* @Method textFilter
* @Date 2024/1/18 9:45
* @param oriText
* @Author lenovo
* @Return java.lang.String
* @Description
*/
private String textFilter(String oriText){
String newText = oriText;
newText = newText.replaceAll("\\s", "");
return newText;
}
/**
* @method: initResources
* @description: onCreate
* @date: 2023/12/18 23:36
* @author: zhoukexing
* @param: []
* @return: void
*/
private void initResources() { private void initResources() {
mHeadViewPanel = findViewById(R.id.note_title); mHeadViewPanel = findViewById(R.id.note_title);
mNoteHeaderHolder = new HeadViewHolder(); mNoteHeaderHolder = new HeadViewHolder();
mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date); mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date);
mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon); mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date); mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
mNoteHeaderHolder.tvTopText = (TextView) findViewById(R.id.tv_top_text);
mNoteHeaderHolder.tvTextNum = (TextView) findViewById(R.id.tv_text_num);
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color); mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this); mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
mNoteEditor = (EditText) findViewById(R.id.note_edit_view); mNoteEditor = (EditText) findViewById(R.id.note_edit_view);
mNoteEditor.addTextChangedListener(new TextWatcher() {
int currentLength = 0;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
mNoteHeaderHolder.tvTextNum.setVisibility(View.VISIBLE);
mNoteHeaderHolder.tvTextNum.setText("长度" + String.valueOf(currentLength));
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
currentLength = textFilter(mNoteEditor.getText().toString()).length();
}
@Override
public void afterTextChanged(Editable s) {//储存文本更改的编辑
if(!mIsRvoke) {
saveHistory();
}else {
mIsRvoke = false;
}
mNoteHeaderHolder.tvTextNum.setText("长度" + String.valueOf(currentLength));
}
});
mNoteEditorPanel = findViewById(R.id.sv_note_edit); mNoteEditorPanel = findViewById(R.id.sv_note_edit);
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector); mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
for (int id : sBgSelectorBtnsMap.keySet()) { for (int id : sBgSelectorBtnsMap.keySet()) {
@ -394,6 +566,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if(mFontSizeId >= TextAppearanceResources.getResourcesSize()) { if(mFontSizeId >= TextAppearanceResources.getResourcesSize()) {
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE; mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
} }
mFontStyleId = mSharedPrefs.getInt(PREFERENCE_FONT_STYLE, 0); // defult style id--0,即对应“默认”字体 @zkx
if(mFontStyleId >= 7) {
mFontStyleId = 0;
}
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list); mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
} }
@ -406,6 +582,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
clearSettingState(); clearSettingState();
} }
/**
* @method updateWidget
* @description
* @date: 2023-12-18 21:37
* @author:
* @return void
*/
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) {
@ -430,7 +613,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if (id == R.id.btn_set_bg_color) { if (id == R.id.btn_set_bg_color) {
mNoteBgColorSelector.setVisibility(View.VISIBLE); mNoteBgColorSelector.setVisibility(View.VISIBLE);
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
- View.VISIBLE); View.VISIBLE);
} else if (sBgSelectorBtnsMap.containsKey(id)) { } else if (sBgSelectorBtnsMap.containsKey(id)) {
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.GONE); View.GONE);
@ -442,13 +625,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mSharedPrefs.edit().putInt(PREFERENCE_FONT_SIZE, mFontSizeId).commit(); mSharedPrefs.edit().putInt(PREFERENCE_FONT_SIZE, mFontSizeId).commit();
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE); findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) { if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
getWorkingText(); getWorkingText(); // DONE切换到清单模式后字体保留
switchToListMode(mWorkingNote.getContent()); switchToListMode(mWorkingNote.getContent());
} else { } else {
mNoteEditor.setTextAppearance(this, mNoteEditor.setTextAppearance(this,
TextAppearanceResources.getTexAppearanceResource(mFontSizeId)); TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
initFontStyle(mNoteEditor, mFontStyleId); // 因为上面的操作会覆盖掉style的显示所以在这里重新设置一下 @zkx
} }
mFontSizeSelector.setVisibility(View.GONE); mFontSizeSelector.setVisibility(View.GONE);
} }
} }
@ -502,59 +687,122 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} else { } else {
menu.findItem(R.id.menu_delete_remind).setVisible(false); menu.findItem(R.id.menu_delete_remind).setVisible(false);
} }
if(mWorkingNote.getmTop() == 1){
menu.findItem(R.id.menu_top).setTitle(R.string.cancel_top);
}
else{
menu.findItem(R.id.menu_top).setTitle(R.string.menu_top);
}
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { /**
case R.id.menu_new_note: * @method: onOptionsItemSelected
createNewNote(); * @description: Activity.javaonOptionsItemSelected线menu-->item
break; * item
case R.id.menu_delete: * @date: 2023/12/19 23:35
AlertDialog.Builder builder = new AlertDialog.Builder(this); * @author: zhoukexing
builder.setTitle(getString(R.string.alert_title_delete)); * @param: [item]
builder.setIcon(android.R.drawable.ic_dialog_alert); * @return: boolean
builder.setMessage(getString(R.string.alert_message_delete_note)); */
builder.setPositiveButton(android.R.string.ok, int itemId = item.getItemId();
new DialogInterface.OnClickListener() { if (itemId == R.id.menu_new_note) { // 从item到itemid用itemid导向对应的不同的动作 @zhoukexing 2023/12/19 23:38
public void onClick(DialogInterface dialog, int which) { createNewNote();
deleteCurrentNote(); } else if (itemId == R.id.menu_delete) {
finish(); // 构建一个警告⚠对话框,让用户确认是否真的要删除便签 @zhoukexing 2023/12/21 0:41
} AlertDialog.Builder builder = new AlertDialog.Builder(this);
}); builder.setTitle(getString(R.string.alert_title_delete));
builder.setNegativeButton(android.R.string.cancel, null); builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.show(); builder.setMessage(getString(R.string.alert_message_delete_note));
break; builder.setPositiveButton(android.R.string.ok,
case R.id.menu_font_size: new DialogInterface.OnClickListener() {// TODO: 2023/12/21 传入了一个函数作为参数?
mFontSizeSelector.setVisibility(View.VISIBLE); public void onClick(DialogInterface dialog, int which) {
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE); deleteCurrentNote(); //TODO: 修改这里达成“在便签内点删除进回收站”
break; finish();
case R.id.menu_list_mode: }
mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ? });
TextNote.MODE_CHECK_LIST : 0); builder.setNegativeButton(android.R.string.cancel, null);
break; builder.show();
case R.id.menu_share: } else if (itemId == R.id.menu_font_size) {
getWorkingText(); mFontSizeSelector.setVisibility(View.VISIBLE);
sendTo(this, mWorkingNote.getContent()); findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
break; } else if (itemId == R.id.menu_list_mode) {
case R.id.menu_send_to_desktop: mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ?
sendToDesktop(); TextNote.MODE_CHECK_LIST : 0);
break; } else if (itemId == R.id.menu_share) {
case R.id.menu_alert: getWorkingText();
setReminder(); sendTo(this, mWorkingNote.getContent());
break; } else if (itemId == R.id.menu_send_to_desktop) {
case R.id.menu_delete_remind: sendToDesktop();
mWorkingNote.setAlertDate(0, false); } else if (itemId == R.id.menu_alert) {
break; setReminder();
default: } else if (itemId == R.id.menu_delete_remind) {
break; mWorkingNote.setAlertDate(0, false);
} else if (itemId == R.id.menu_search) {
onSearchRequested();
} else if (itemId == R.id.menu_top) {
mWorkingNote.reverseTopState();
showTopHeader();
} else if (itemId == R.id.menu_revoke) {
doRevoke();
} else if (itemId == R.id.menu_screenshot) {
doScreenshot();
} else if (itemId == R.id.menu_font_select) {
setFontStyle();
} }
return true; return true;
} }
public boolean onSearchRequested() {
startSearch(null, false, null /* appData */, false);
return true;
}
private void setFontStyle() {
final String[] items = {"普通", "加粗", "斜体", "等宽", "方正舒体", "行楷", "VINERITC-en"};
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("设置字体");
dialog.setCancelable(true);
dialog.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
mFontStyleId = i;
}
});
dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
mSharedPrefs.edit().putInt(PREFERENCE_FONT_STYLE, mFontStyleId).commit();
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
getWorkingText(); // DONE切换到清单模式后字体保留
switchToListMode(mWorkingNote.getContent());
} else {
initFontStyle(mNoteEditor, mFontStyleId);
}
}
});
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
}
});
dialog.show();
}
/**
* @Method setReminder
* @Date 2023/12/13 12:52
* @Author lenovo
* @Return void
* @Description
*/
private void setReminder() { private void setReminder() {
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis()); DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
// 设置时间选择器的监听事件,当选中 date 之后调用 setAlertDate 设置提醒时间
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);
@ -567,25 +815,53 @@ public class NoteEditActivity extends Activity implements OnClickListener,
* 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
*/ */
/**
* @method sendTo
* @description 便
* @date: 2023-12-18 0:57
* @author:
* @return void
*/
private void sendTo(Context context, String info) { private void sendTo(Context context, String info) {
// 新建intent消息
// 2023-12-18 1:00
Intent intent = new Intent(Intent.ACTION_SEND); Intent intent = new Intent(Intent.ACTION_SEND);
// 将要分享的便签内容放入intent中
// 2023-12-18 1:01
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() {
/**
* @method: createNewNote
* @description: add note便
* 便NoteEditActivityintent
* intent
* @date: 2023/12/19 23:03
* @author: zhoukexing
* @param: []
* @return: void
*/
// Firstly, save current editing notes // Firstly, save current editing notes
saveNote(); saveNote();
// For safety, start a new NoteEditActivity // For safety, start a new NoteEditActivity
finish(); finish();
Intent intent = new Intent(this, NoteEditActivity.class); Intent intent = new Intent(this, NoteEditActivity.class); //Q: 在类的内部,还没有实现完全时,启动这个类自己?@zkx 2023/12/17
intent.setAction(Intent.ACTION_INSERT_OR_EDIT); intent.setAction(Intent.ACTION_INSERT_OR_EDIT); // 创建便签后要插入或者编辑。Q: 为什么要插入 @zhoukexing 2023/12/19 22:57
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId()); intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId());
startActivity(intent); startActivity(intent);
} }
/**
* @method: deleteCurrentNote
* @description: 便
* @date: 2023/12/21 0:48
* @author: zhoukexing
* @param: []
* @return: void
*/
private void deleteCurrentNote() { private void deleteCurrentNote() {
if (mWorkingNote.existInDatabase()) { if (mWorkingNote.existInDatabase()) {
HashSet<Long> ids = new HashSet<Long>(); HashSet<Long> ids = new HashSet<Long>();
@ -595,11 +871,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} else { } else {
Log.d(TAG, "Wrong note id, should not happen"); Log.d(TAG, "Wrong note id, should not happen");
} }
if (!isSyncMode()) { if (mWorkingNote.getFolderId() == Notes.ID_TRASH_FOLER) {
if (!DataUtils.batchDeleteNotes(getContentResolver(), ids)) { if (!DataUtils.batchDeleteNotes(getContentResolver(), ids)) {
Log.e(TAG, "Delete Note error"); Log.e(TAG, "Delete Note error");
} }
} else { } else {
if (!DataUtils.batchMoveToFolder(getContentResolver(), ids, Notes.ID_TRASH_FOLER)) { if (!DataUtils.batchMoveToFolder(getContentResolver(), ids, Notes.ID_TRASH_FOLER)) {
Log.e(TAG, "Move notes to trash folder error, should not happens"); Log.e(TAG, "Move notes to trash folder error, should not happens");
} }
@ -612,6 +888,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0; return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
} }
/**
* @Method onClockAlertChanged
* @Date 2023/12/13 9:52
* @param date
* @param set 0 1
* @Author lenovo
* @Return void
* @Description
*/
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
@ -627,8 +912,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE)); AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));
showAlertHeader(); showAlertHeader();
if(!set) { if(!set) {
// 取消监听事件
alarmManager.cancel(pendingIntent); alarmManager.cancel(pendingIntent);
} else { } else {
// 设置监听事件,到时间启动提醒
alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent); alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent);
} }
} else { } else {
@ -691,7 +978,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
} }
private void switchToListMode(String text) { private void switchToListMode(String text) { // TODO: 在清单模式下设置的字体大小、样式没法保留
mEditTextList.removeAllViews(); mEditTextList.removeAllViews();
String[] items = text.split("\n"); String[] items = text.split("\n");
int index = 0; int index = 0;
@ -729,6 +1016,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
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);
edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId)); edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
initFontStyle(edit, mFontStyleId);
CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item)); CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item));
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -806,8 +1094,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
private boolean saveNote() { private boolean saveNote() {
/**
* @method: saveNote
* @description: 便便list
* @date: 2023/12/19 23:50
* @author: zhoukexing
* @param: []
* @return: boolean
*/
getWorkingText(); getWorkingText();
boolean saved = mWorkingNote.saveNote(); boolean saved = mWorkingNote.saveNote();// TODO: 2023/12/19 工作便签下的saveNote
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,
@ -816,11 +1112,19 @@ 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
*/ */
setResult(RESULT_OK); setResult(RESULT_OK); // RESULT_OK指示将该便签保存到list界面的顶端因为这是新建的便签 @zhoukexing 2023/12/19 23:41
//Q: 这个setResult只在这里调用了怎么实现的 @zkx 2023/12/19
} }
return saved; return saved;
} }
/**
* @method sendToDesktop
* @description 便
* @date: 2023-12-18 17:27
* @author:
* @return void
*/
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
@ -832,9 +1136,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
if (mWorkingNote.getNoteId() > 0) { if (mWorkingNote.getNoteId() > 0) {
// 新建intent消息为创建桌面快捷方式的连接器
// 2023-12-18 17:29
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);
// 将便签的相关信息添加进intent中
// 2023-12-18 17:36
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,
@ -844,6 +1152,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sender.putExtra("duplicate", true); sender.putExtra("duplicate", true);
sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
showToast(R.string.info_note_enter_desktop); showToast(R.string.info_note_enter_desktop);
// 将便签显示于桌面
// 2023-12-18 17:38
sendBroadcast(sender); sendBroadcast(sender);
} else { } else {
/** /**
@ -870,4 +1180,86 @@ public class NoteEditActivity extends Activity implements OnClickListener,
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();
} }
}
/**
* @method saveHistory
* @description
* @date: 2024-01-08 8:56
* @author:
* @return void
*/
private void saveHistory() {
SpannableString text = new SpannableString(mNoteEditor.getText());
if (mHistory.size() >= mMaxRevokeTimes) {
mHistory.removeElementAt(0);
mHistory.add(text);
}
else {
mHistory.add(text);
}
}
/**
* @method doRevoke
* @description
* @date: 2024-01-08 15:56
* @author:
* @return void
*/
private void doRevoke() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(R.string.tips_of_revoke);
dialog.setCancelable(true);
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
mIsRvoke = true;
if(mHistory.size() <= 1){
dialog.setMessage(R.string.cannot_revoke_anything);
dialog.show();
}
else {
mNoteEditor.setText((CharSequence)mHistory.elementAt(mHistory.size() - 2));
mHistory.removeElementAt(mHistory.size() - 1);
}
}
/**
* @method doScreenshot
* @description
* @date: 2024-01-17 17:20
* @author:
* @return
*/
private void doScreenshot() {
// 调用 getWindow().getDecorView().getRootView() 获取屏幕的根视图
// 使用 getDrawingCache() 获取视图的缓存位图
// 2024-01-17 23:22
View view = getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
// 保存Bitmap对象至文件中
// 2024-01-17 23:21
if (bitmap != null) {
try {
String sdCardPath = Environment.getExternalStorageDirectory().getPath();
String filePath = sdCardPath + File.separator + "screenshot.png";
File file = new File(filePath);
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
// showToast(R.string.success_screenshot_saved);
Toast.makeText(this, "Successfully saved the screenshot to" + filePath, Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e(TAG, "Take a screenshot error");
showToast(R.string.error_screenshot_saved);
}
}
}
} //NOTE: 这一整个文件就是这一个类 @zhoukexing 2023/12/17 23:41

@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
@ -14,204 +14,268 @@
* limitations under the License. * limitations under the License.
*/ */
package net.micode.notes.ui; package net.micode.notes.ui;
import android.content.Context; import android.content.Context;
import android.graphics.Rect; import android.graphics.Rect;
import android.text.Layout; import android.text.Layout;
import android.text.Selection; import android.text.Selection;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.URLSpan; import android.text.style.URLSpan;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener; import android.view.MenuItem.OnMenuItemClickListener;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.widget.EditText; import android.widget.EditText;
import net.micode.notes.R; import net.micode.notes.R;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class NoteEditText extends EditText { /**
private static final String TAG = "NoteEditText"; * 便EditText便
private int mIndex; */
private int mSelectionStartBeforeDelete; public class NoteEditText extends EditText {
private static final String TAG = "NoteEditText"; // 日志标签
private static final String SCHEME_TEL = "tel:" ; private int mIndex; // 当前文本框的索引
private static final String SCHEME_HTTP = "http:" ; private int mSelectionStartBeforeDelete; // 删除前的文本选择起始位置
private static final String SCHEME_EMAIL = "mailto:" ;
// 定义几种常见的URL协议前缀
private static final Map<String, Integer> sSchemaActionResMap = new HashMap<String, Integer>(); private static final String SCHEME_TEL = "tel:" ;
static { private static final String SCHEME_HTTP = "http:" ;
sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel); private static final String SCHEME_EMAIL = "mailto:" ;
sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web);
sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email); // 定义一个映射表用于将URL协议前缀映射到对应的字符串资源ID
} private static final Map<String, Integer> sSchemaActionResMap = new HashMap<String, Integer>();
static {
/** sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel);
* Call by the {@link NoteEditActivity} to delete or add edit text sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web);
*/ sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email);
public interface OnTextViewChangeListener { }
/**
* Delete current edit text when {@link KeyEvent#KEYCODE_DEL} happens /**
* and the text is null * 便
*/ */
void onEditTextDelete(int index, String text); public interface OnTextViewChangeListener {
/**
/** *
* Add edit text after current edit text when {@link KeyEvent#KEYCODE_ENTER} * @param index
* happen * @param text
*/ */
void onEditTextEnter(int index, String text); void onEditTextDelete(int index, String text);
/** /**
* Hide or show item option when text change *
*/ * @param index
void onTextChange(int index, boolean hasText); * @param text
} */
void onEditTextEnter(int index, String text);
private OnTextViewChangeListener mOnTextViewChangeListener;
/**
public NoteEditText(Context context) { *
super(context, null); * @param index
mIndex = 0; * @param hasText
} */
void onTextChange(int index, boolean hasText);
public void setIndex(int index) { }
mIndex = index;
} private OnTextViewChangeListener mOnTextViewChangeListener; // 监听器实例
public void setOnTextViewChangeListener(OnTextViewChangeListener listener) { /**
mOnTextViewChangeListener = listener; * 便
} * @param context
*/
public NoteEditText(Context context, AttributeSet attrs) { public NoteEditText(Context context) {
super(context, attrs, android.R.attr.editTextStyle); super(context, null);
} mIndex = 0; // 默认索引为0
}
public NoteEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); /**
// TODO Auto-generated constructor stub *
} * @param index
*/
@Override public void setIndex(int index) {
public boolean onTouchEvent(MotionEvent event) { mIndex = index;
switch (event.getAction()) { }
case MotionEvent.ACTION_DOWN:
/**
int x = (int) event.getX(); * 便
int y = (int) event.getY(); * @param listener
x -= getTotalPaddingLeft(); */
y -= getTotalPaddingTop(); public void setOnTextViewChangeListener(OnTextViewChangeListener listener) {
x += getScrollX(); mOnTextViewChangeListener = listener;
y += getScrollY(); }
Layout layout = getLayout(); /**
int line = layout.getLineForVertical(y); * 便
int off = layout.getOffsetForHorizontal(line, x); * @param context
Selection.setSelection(getText(), off); * @param attrs
break; */
} public NoteEditText(Context context, AttributeSet attrs) {
super(context, attrs, android.R.attr.editTextStyle);
return super.onTouchEvent(event); }
}
/**
@Override * 便
public boolean onKeyDown(int keyCode, KeyEvent event) { * @param context
switch (keyCode) { * @param attrs
case KeyEvent.KEYCODE_ENTER: * @param defStyle
if (mOnTextViewChangeListener != null) { */
return false; public NoteEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
/**
*
* @param event
* @return
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// 计算触摸点在文本框中的实际位置
int x = (int) event.getX();
int y = (int) event.getY();
x -= getTotalPaddingLeft();
y -= getTotalPaddingTop();
x += getScrollX();
y += getScrollY();
Layout layout = getLayout(); // 获取文本布局
int line = layout.getLineForVertical(y); // 计算触摸点所在的行
int off = layout.getOffsetForHorizontal(line, x); // 计算触摸点所在的偏移量
Selection.setSelection(getText(), off); // 设置文本选择
break;
}
return super.onTouchEvent(event);
}
/**
*
* @param keyCode
* @param event
* @return
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_ENTER:
// 如果监听器不为空,则不处理回车键事件
if (mOnTextViewChangeListener != null) {
return false;
}
break;
case KeyEvent.KEYCODE_DEL:
// 记录删除前的文本选择起始位置
mSelectionStartBeforeDelete = getSelectionStart();
break;
default:
break;
}
return super.onKeyDown(keyCode, event);
}
/**
*
* @param keyCode
* @param event
* @return
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch(keyCode) {
case KeyEvent.KEYCODE_DEL: // delete键的代码为67
// 如果监听器不为空且删除前的文本选择起始位置为0且当前文本框的索引不为0则通知监听器删除当前文本框
if (mOnTextViewChangeListener != null) {
if (0 == mSelectionStartBeforeDelete && mIndex != 0) {
mOnTextViewChangeListener.onEditTextDelete(mIndex, getText().toString());
return true;
}
} else {
Log.d(TAG, "OnTextViewChangeListener was not seted"); // 打印日志
}
break;
case KeyEvent.KEYCODE_ENTER: // enter键的代码为66
// 如果监听器不为空,则通知监听器在当前文本框后面添加一个新的文本框
if (mOnTextViewChangeListener != null) {
int selectionStart = getSelectionStart();
String text = getText().subSequence(selectionStart, length()).toString();
setText(getText().subSequence(0, selectionStart));
mOnTextViewChangeListener.onEditTextEnter(mIndex + 1, text);
} else {
Log.d(TAG, "OnTextViewChangeListener was not seted"); // 打印日志
}
break;
default:
break;
}
return super.onKeyUp(keyCode, event);
}
/**
*
* @param focused
* @param direction
* @param previouslyFocusedRect
*/
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
// 如果监听器不为空,则通知监听器文本框的文本变化
if (mOnTextViewChangeListener != null) {
if (!focused && TextUtils.isEmpty(getText())) {
mOnTextViewChangeListener.onTextChange(mIndex, false);
} else {
mOnTextViewChangeListener.onTextChange(mIndex, true);
}
}
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
/**
*
* @param menu
*/
@Override
protected void onCreateContextMenu(ContextMenu menu) {
if (getText() instanceof Spanned) {
int selStart = getSelectionStart();
int selEnd = getSelectionEnd();
int min = Math.min(selStart, selEnd);
int max = Math.max(selStart, selEnd);
// 获取选中文本中的URL
final URLSpan[] urls = ((Spanned) getText()).getSpans(min, max, URLSpan.class);
if (urls.length == 1) {
int defaultResId = 0;
// 根据URL的协议前缀获取对应的字符串资源ID
for(String schema: sSchemaActionResMap.keySet()) {
if(urls[0].getURL().indexOf(schema) >= 0) {
defaultResId = sSchemaActionResMap.get(schema);
break;
} }
break;
case KeyEvent.KEYCODE_DEL:
mSelectionStartBeforeDelete = getSelectionStart();
break;
default:
break;
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch(keyCode) {
case KeyEvent.KEYCODE_DEL:
if (mOnTextViewChangeListener != null) {
if (0 == mSelectionStartBeforeDelete && mIndex != 0) {
mOnTextViewChangeListener.onEditTextDelete(mIndex, getText().toString());
return true;
}
} else {
Log.d(TAG, "OnTextViewChangeListener was not seted");
}
break;
case KeyEvent.KEYCODE_ENTER:
if (mOnTextViewChangeListener != null) {
int selectionStart = getSelectionStart();
String text = getText().subSequence(selectionStart, length()).toString();
setText(getText().subSequence(0, selectionStart));
mOnTextViewChangeListener.onEditTextEnter(mIndex + 1, text);
} else {
Log.d(TAG, "OnTextViewChangeListener was not seted");
}
break;
default:
break;
}
return super.onKeyUp(keyCode, event);
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if (mOnTextViewChangeListener != null) {
if (!focused && TextUtils.isEmpty(getText())) {
mOnTextViewChangeListener.onTextChange(mIndex, false);
} else {
mOnTextViewChangeListener.onTextChange(mIndex, true);
} }
}
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
@Override
protected void onCreateContextMenu(ContextMenu menu) {
if (getText() instanceof Spanned) {
int selStart = getSelectionStart();
int selEnd = getSelectionEnd();
int min = Math.min(selStart, selEnd);
int max = Math.max(selStart, selEnd);
final URLSpan[] urls = ((Spanned) getText()).getSpans(min, max, URLSpan.class); if (defaultResId == 0) {
if (urls.length == 1) { defaultResId = R.string.note_link_other; // 如果没有匹配的协议前缀则使用默认的字符串资源ID
int defaultResId = 0;
for(String schema: sSchemaActionResMap.keySet()) {
if(urls[0].getURL().indexOf(schema) >= 0) {
defaultResId = sSchemaActionResMap.get(schema);
break;
}
}
if (defaultResId == 0) {
defaultResId = R.string.note_link_other;
}
menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener(
new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
// goto a new intent
urls[0].onClick(NoteEditText.this);
return true;
}
});
} }
// 添加一个菜单项用于打开URL
menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener(
new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
// 打开URL
urls[0].onClick(NoteEditText.this);
return true;
}
});
} }
super.onCreateContextMenu(menu);
} }
} super.onCreateContextMenu(menu);
}

@ -40,6 +40,7 @@ public class NoteItemData {
NoteColumns.TYPE, NoteColumns.TYPE,
NoteColumns.WIDGET_ID, NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE, NoteColumns.WIDGET_TYPE,
NoteColumns.TOP,
}; };
private static final int ID_COLUMN = 0; private static final int ID_COLUMN = 0;
@ -54,7 +55,11 @@ public class NoteItemData {
private static final int TYPE_COLUMN = 9; private static final int TYPE_COLUMN = 9;
private static final int WIDGET_ID_COLUMN = 10; private static final int WIDGET_ID_COLUMN = 10;
private static final int WIDGET_TYPE_COLUMN = 11; private static final int WIDGET_TYPE_COLUMN = 11;
private static final int TOP_STATE_COLUMN = 12;
/** NotesDatabaseHelper.java
*
* @zhoukexing 2023/12/25 20:22 */
private long mId; private long mId;
private long mAlertDate; private long mAlertDate;
private int mBgColorId; private int mBgColorId;
@ -67,6 +72,7 @@ public class NoteItemData {
private int mType; private int mType;
private int mWidgetId; private int mWidgetId;
private int mWidgetType; private int mWidgetType;
private int mTop;
private String mName; private String mName;
private String mPhoneNumber; private String mPhoneNumber;
@ -76,8 +82,16 @@ public class NoteItemData {
private boolean mIsOneNoteFollowingFolder; private boolean mIsOneNoteFollowingFolder;
private boolean mIsMultiNotesFollowingFolder; private boolean mIsMultiNotesFollowingFolder;
public NoteItemData(Context context, Cursor cursor) { /**
mId = cursor.getLong(ID_COLUMN); * @method: NoteItemData
* @description:
* @date: 2023/12/25 19:58
* @author: zhoukexing
* @param: [context, cursor]
* @return:
*/
public NoteItemData(Context context, Cursor cursor) { // 把cursor理解为这样一个指针指向一个表格 @zhoukexing 2023/12/25 20:12
mId = cursor.getLong(ID_COLUMN); // 可以根据传入的列号获取到表格里对应列的值 @zhoukexing 2023/12/25 20:12
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN); mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);
mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN); mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN);
mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN); mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN);
@ -91,10 +105,12 @@ public class NoteItemData {
mType = cursor.getInt(TYPE_COLUMN); mType = cursor.getInt(TYPE_COLUMN);
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN); mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN); mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
mTop = cursor.getInt(TOP_STATE_COLUMN);
mPhoneNumber = ""; mPhoneNumber = "";
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) { if (mParentId == Notes.ID_CALL_RECORD_FOLDER) { //Q: 文件夹为什么有电话记录之说?怎么是通过一个便签的父文件夹来判断便签内有无电话号码?@zkx 2023/12/25
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId); mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId);
// 根据电话号码锁定联系人名称,若不在联系人里,直接使用电话号码 @zhoukexing 2023/12/25 20:17
if (!TextUtils.isEmpty(mPhoneNumber)) { if (!TextUtils.isEmpty(mPhoneNumber)) {
mName = Contact.getContact(context, mPhoneNumber); mName = Contact.getContact(context, mPhoneNumber);
if (mName == null) { if (mName == null) {
@ -158,6 +174,10 @@ public class NoteItemData {
return mIsOnlyOneItem; return mIsOnlyOneItem;
} }
public int getTop(){
return mTop;
}
public long getId() { public long getId() {
return mId; return mId;
} }

@ -16,9 +16,11 @@
package net.micode.notes.ui; package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.SearchManager;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.content.AsyncQueryHandler; import android.content.AsyncQueryHandler;
import android.content.ContentResolver; import android.content.ContentResolver;
@ -77,7 +79,19 @@ 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;
import java.util.Queue;
/**
* @Package: net.micode.notes.ui
* @ClassName: NotesListActivity
* @Description: 便
* @Author: zhoukexing
* @CreateDate: 2024/1/18 15:25
* @UpdateUser: none
* @UpdateDate: 2024/1/18 15:25
* @UpdateRemark: none
* @Version: 1.0
*/
public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener { 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;
@ -89,11 +103,15 @@ 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 int DAY_MODE = 0;
private static final int NIGHT_MODE = 1;
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction"; private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
private static final String SEARCH_RESULTS = "Search Results: ";
private enum ListEditState { private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER, TRASH_FOLDER
}; } //NOTE: 三种编辑状态@zhoukexing 2024/1/2 19:31 新增一个
private ListEditState mState; private ListEditState mState;
@ -135,12 +153,23 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private final static int REQUEST_CODE_OPEN_NODE = 102; private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103; private final static int REQUEST_CODE_NEW_NODE = 103;
private String mTitle;
private String mMessage;
private int mBackground = 2;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.note_list); setContentView(R.layout.note_list);
if (mBackground == DAY_MODE) {
getWindow().setBackgroundDrawableResource(R.drawable.list_day_mode_background);
} else if (mBackground == NIGHT_MODE) {
getWindow().setBackgroundDrawableResource(R.drawable.list_night_mode_background);
} else {
getWindow().setBackgroundDrawableResource(R.drawable.list_background);
}
initResources(); initResources();
/** /**
* Insert an introduction when user firstly use this application * Insert an introduction when user firstly use this application
*/ */
@ -204,9 +233,26 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} }
@Override @Override
/**
* @Method onStart
* @Date 2024/1/4 8:56
* @Author lenovo
* @Return void
* @Description
*/
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
startAsyncNotesListQuery(); Intent intent = getIntent();
// 如果是搜索引起的实体创建,说明需要展示搜索页面
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
mTitleBar.setText(SEARCH_RESULTS + query);
mTitleBar.setVisibility(View.VISIBLE);
mAddNewNote.setVisibility(View.GONE);
// 将搜索数据同步
startAsyncNotesSearchListQuery(query);
}
else startAsyncNotesListQuery();
} }
private void initResources() { private void initResources() {
@ -218,7 +264,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
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, null);
mNotesListView.setAdapter(mNotesListAdapter); mNotesListView.setAdapter(mNotesListAdapter);
mAddNewNote = (Button) findViewById(R.id.btn_new_note); mAddNewNote = (Button) findViewById(R.id.btn_new_note);
mAddNewNote.setOnClickListener(this); mAddNewNote.setOnClickListener(this);
@ -319,28 +365,41 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true; return true;
} }
switch (item.getItemId()) { int itemId = item.getItemId();
case R.id.delete: if (itemId == R.id.delete) {
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this); switch (mState) {
builder.setTitle(getString(R.string.alert_title_delete)); case SUB_FOLDER:
builder.setIcon(android.R.drawable.ic_dialog_alert); case CALL_RECORD_FOLDER:
builder.setMessage(getString(R.string.alert_message_delete_notes, case NOTE_LIST:
mNotesListAdapter.getSelectedCount())); mTitle = getString(R.string.alert_title_delete);
builder.setPositiveButton(android.R.string.ok, mMessage = getString(R.string.alert_message_delete_notes,
new DialogInterface.OnClickListener() { mNotesListAdapter.getSelectedCount());
public void onClick(DialogInterface dialog, break;
int which) { case TRASH_FOLDER:
batchDelete(); mTitle = getString(R.string.alert_title_delete_true);
} mMessage = getString(R.string.alert_message_delete_notes_true,
}); mNotesListAdapter.getSelectedCount());
builder.setNegativeButton(android.R.string.cancel, null); break;
builder.show(); default:
break; break;
case R.id.move: }
startQueryDestinationFolders(); AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
break; builder.setTitle(mTitle);
default: builder.setIcon(android.R.drawable.ic_dialog_alert);
return false; builder.setMessage(mMessage);
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
batchDelete();
}
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.show();
} else if (itemId == R.id.move) {
startQueryDestinationFolders();
} else {
return false;
} }
return true; return true;
} }
@ -359,7 +418,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
/** /**
* Minus TitleBar's height * Minus TitleBar's height
*/ */
if (mState == ListEditState.SUB_FOLDER) { if (mState == ListEditState.SUB_FOLDER ||
mState == ListEditState.TRASH_FOLDER) {
// 回收站的ui显示 @zkx
eventY -= mTitleBar.getHeight(); eventY -= mTitleBar.getHeight();
start -= mTitleBar.getHeight(); start -= mTitleBar.getHeight();
} }
@ -407,14 +468,33 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} }
}; };
/**
* @Method startAsyncNotesListQuery
* @Date 2023/12/19 8:34
* @Author lenovo
* @Return void
* @Description 便便
*/
private void startAsyncNotesListQuery() { private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
: NORMAL_SELECTION; : NORMAL_SELECTION;
// 按照 Top 降序
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.TOP + " DESC," + NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
// DESC 降序
}
private void startAsyncNotesSearchListQuery(String query) {
// 模糊匹配 query
String selection = NoteColumns.SNIPPET + " LIKE'%" + query +"%'";
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
Notes.CONTENT_NOTE_URI,
NoteItemData.PROJECTION,
selection,
null,
NoteColumns.TOP + " DESC," + NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
} }
private final class BackgroundQueryHandler extends AsyncQueryHandler { private final class BackgroundQueryHandler extends AsyncQueryHandler {
@ -469,20 +549,29 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE); this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
} }
/**
* @method: batchDelete
* @description: 便
* NotesListAdaptermSelectedIndex
* @date: 2024/1/3 23:02
* @author: zhoukexing
* @param: []
* @return: void
*/
private void batchDelete() { private void batchDelete() {
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() { new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
@SuppressLint("StaticFieldLeak")
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) { protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget(); HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget();
if (!isSyncMode()) { if (mCurrentFolderId == Notes.ID_TRASH_FOLER){
// if not synced, delete notes directly // if in trash, really delete notes
if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
.getSelectedItemIds())) { .getSelectedItemIds())) {
} else { } else {
Log.e(TAG, "Delete notes error, should not happens"); Log.e(TAG, "Delete notes error, should not happens");
} }
} else { } else {
// in sync mode, we'll move the deleted note into the trash // move notes to trash
// folder
if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
.getSelectedItemIds(), Notes.ID_TRASH_FOLER)) { .getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
Log.e(TAG, "Move notes to trash folder error, should not happens"); Log.e(TAG, "Move notes to trash folder error, should not happens");
@ -495,8 +584,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
protected void onPostExecute(HashSet<AppWidgetAttribute> widgets) { protected void onPostExecute(HashSet<AppWidgetAttribute> widgets) {
if (widgets != null) { if (widgets != null) {
for (AppWidgetAttribute widget : widgets) { for (AppWidgetAttribute widget : widgets) {
// widget挂件的Id和Type都不是非法的《==》存在这个widget挂件 @zkx
if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) { && widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) {
// ==》 删除这个挂件
updateWidget(widget.widgetId, widget.widgetType); updateWidget(widget.widgetId, widget.widgetType);
} }
} }
@ -506,6 +597,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}.execute(); }.execute();
} }
/**
* @Method deleteFolder
* @Date 2023/12/19 8:37
* @param folderId
* @Author lenovo
* @Return void
* @Description (sync mode )
*/
private void deleteFolder(long folderId) { private void deleteFolder(long folderId) {
if (folderId == Notes.ID_ROOT_FOLDER) { if (folderId == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Wrong folder id, should not happen " + folderId); Log.e(TAG, "Wrong folder id, should not happen " + folderId);
@ -514,15 +613,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
HashSet<Long> ids = new HashSet<Long>(); HashSet<Long> ids = new HashSet<Long>();
ids.add(folderId); ids.add(folderId);
// 所有与要删除文件夹相关的 widgets
HashSet<AppWidgetAttribute> widgets = DataUtils.getFolderNoteWidget(mContentResolver, HashSet<AppWidgetAttribute> widgets = DataUtils.getFolderNoteWidget(mContentResolver,
folderId); folderId);
if (!isSyncMode()) { if (mCurrentFolderId == Notes.ID_TRASH_FOLER) {
// if not synced, delete folder directly // if in trash, delete folder directly
DataUtils.batchDeleteNotes(mContentResolver, ids); DataUtils.batchDeleteNotes(mContentResolver, ids);
} else { } else {
// in sync mode, we'll move the deleted folder into the trash folder // move the deleted folder into the trash folder
DataUtils.batchMoveToFolder(mContentResolver, ids, Notes.ID_TRASH_FOLER); DataUtils.batchMoveToFolder(mContentResolver, ids, Notes.ID_TRASH_FOLER);
} }
// 更新 widgets
if (widgets != null) { if (widgets != null) {
for (AppWidgetAttribute widget : widgets) { for (AppWidgetAttribute widget : widgets) {
if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
@ -540,33 +641,47 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE); this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
} }
/**
* @Method openFolder
* @Date 2023/12/19 7:55
* @param data
* @Author lenovo
* @Return void
* @Description
*/
private void openFolder(NoteItemData data) { private void openFolder(NoteItemData data) {
mCurrentFolderId = data.getId(); mCurrentFolderId = data.getId();
startAsyncNotesListQuery(); startAsyncNotesListQuery();
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) { if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
// TODO store all records 暂时没太搞明白这个代表什么
mState = ListEditState.CALL_RECORD_FOLDER; mState = ListEditState.CALL_RECORD_FOLDER;
mAddNewNote.setVisibility(View.GONE); mAddNewNote.setVisibility(View.GONE);
} else { } else {
// 正常打开文件夹
mState = ListEditState.SUB_FOLDER; mState = ListEditState.SUB_FOLDER;
} }
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) { if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
mTitleBar.setText(R.string.call_record_folder_name); mTitleBar.setText(R.string.call_record_folder_name);
} else { } else {
// 将顶部栏设置为 data.getSnippet 文件夹名称
mTitleBar.setText(data.getSnippet()); mTitleBar.setText(data.getSnippet());
} }
mTitleBar.setVisibility(View.VISIBLE); mTitleBar.setVisibility(View.VISIBLE);
} }
public void onClick(View v) { public void onClick(View v) {
switch (v.getId()) { if (v.getId() == R.id.btn_new_note) {
case R.id.btn_new_note: createNewNote();
createNewNote();
break;
default:
break;
} }
} }
/**
* @Method showSoftInput
* @Date 2023/12/17 23:46
* @Author lenovo
* @Return void
* @Description
*/
private void showSoftInput() { private void showSoftInput() {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) { if (inputMethodManager != null) {
@ -579,14 +694,23 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
} }
/**
* @Method showCreateOrModifyFolderDialog
* @Date 2023/12/17 22:32
* @param create true false
* @Author lenovo
* @Return void
* @Description
*/
private void showCreateOrModifyFolderDialog(final boolean create) { private void showCreateOrModifyFolderDialog(final boolean create) {
// final 关键字, 初始化之后无法修改 (const)
final AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null); View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
final EditText etName = (EditText) view.findViewById(R.id.et_foler_name); final EditText etName = (EditText) view.findViewById(R.id.et_foler_name);
showSoftInput(); showSoftInput();
if (!create) { if (!create) {
if (mFocusNoteDataItem != null) { if (mFocusNoteDataItem != null) {
etName.setText(mFocusNoteDataItem.getSnippet()); etName.setText(mFocusNoteDataItem.getSnippet()); // 显示之前的名称
builder.setTitle(getString(R.string.menu_folder_change_name)); builder.setTitle(getString(R.string.menu_folder_change_name));
} else { } else {
Log.e(TAG, "The long click data item is null"); Log.e(TAG, "The long click data item is null");
@ -596,7 +720,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
etName.setText(""); etName.setText("");
builder.setTitle(this.getString(R.string.menu_create_folder)); builder.setTitle(this.getString(R.string.menu_create_folder));
} }
/**
* OK
* Cancel
* lenovo 2023/12/18 0:03
*/
builder.setPositiveButton(android.R.string.ok, null); builder.setPositiveButton(android.R.string.ok, null);
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -610,12 +738,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
public void onClick(View v) { public void onClick(View v) {
hideSoftInput(etName); hideSoftInput(etName);
String name = etName.getText().toString(); String name = etName.getText().toString();
// 如果该名称已经存在
if (DataUtils.checkVisibleFolderName(mContentResolver, name)) { if (DataUtils.checkVisibleFolderName(mContentResolver, name)) {
Toast.makeText(NotesListActivity.this, getString(R.string.folder_exist, name), Toast.makeText(NotesListActivity.this, getString(R.string.folder_exist, name),
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
etName.setSelection(0, etName.length()); etName.setSelection(0, etName.length()); //全选输入文件名(准备修改/删除)
return; return;
} }
// 更新数据库中文件夹名称 插入/修改
if (!create) { if (!create) {
if (!TextUtils.isEmpty(name)) { if (!TextUtils.isEmpty(name)) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
@ -633,6 +763,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
values.put(NoteColumns.TYPE, Notes.TYPE_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
mContentResolver.insert(Notes.CONTENT_NOTE_URI, values); mContentResolver.insert(Notes.CONTENT_NOTE_URI, values);
} }
//关闭对话框
dialog.dismiss(); dialog.dismiss();
} }
}); });
@ -646,7 +777,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
etName.addTextChangedListener(new TextWatcher() { etName.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
@ -659,21 +789,25 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
}); });
} }
@Override @Override
public void onBackPressed() { public void onBackPressed() {
// 在list清单界面按回退键就会被捕捉到这里执行这个函数 @zhoukexing 2024/1/2 19:33
switch (mState) { switch (mState) {
case SUB_FOLDER: case SUB_FOLDER: // 当前状态是子文件夹,要回退到主文件夹 @zkx
// 特殊情况子文件夹是“回收站”要显式地说明展示底部栏模仿下面的call_record_folder @zkx
// 添加mAddNewNote.setVisibility(View.VISIBLE);此行后,
// sub_folder 和 call_record_folder 两种情况无差别,无需分开处理
mCurrentFolderId = Notes.ID_ROOT_FOLDER; mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST; mState = ListEditState.NOTE_LIST;
startAsyncNotesListQuery();
mTitleBar.setVisibility(View.GONE); mTitleBar.setVisibility(View.GONE);
startAsyncNotesListQuery();
break; break;
case CALL_RECORD_FOLDER: case CALL_RECORD_FOLDER:
case TRASH_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);
@ -688,8 +822,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} }
} }
/**
* @method updateWidget
* @description
* @date: 2023-12-18 21:37
* @author:
* @return void
*/
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);
// 根据不同大小类型的widget更新Widget
// 2023-12-18 21:41
if (appWidgetType == Notes.TYPE_WIDGET_2X) { if (appWidgetType == Notes.TYPE_WIDGET_2X) {
intent.setClass(this, NoteWidgetProvider_2x.class); intent.setClass(this, NoteWidgetProvider_2x.class);
} else if (appWidgetType == Notes.TYPE_WIDGET_4X) { } else if (appWidgetType == Notes.TYPE_WIDGET_4X) {
@ -726,6 +869,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
super.onContextMenuClosed(menu); super.onContextMenuClosed(menu);
} }
/**
* @Method onContextItemSelected
* @Date 2023/12/17 23:51
* @param item
* @Author lenovo
* @Return boolean
* @Description
*/
@Override @Override
public boolean onContextItemSelected(MenuItem item) { public boolean onContextItemSelected(MenuItem item) {
if (mFocusNoteDataItem == null) { if (mFocusNoteDataItem == null) {
@ -739,7 +890,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
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.divider_horizontal_dark);
builder.setMessage(getString(R.string.alert_message_delete_folder)); builder.setMessage(getString(R.string.alert_message_delete_folder));
builder.setPositiveButton(android.R.string.ok, builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@ -770,72 +921,170 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
GTaskSyncService.isSyncing() ? R.string.menu_sync_cancel : R.string.menu_sync); GTaskSyncService.isSyncing() ? R.string.menu_sync_cancel : R.string.menu_sync);
} else if (mState == ListEditState.SUB_FOLDER) { } else if (mState == ListEditState.SUB_FOLDER) {
getMenuInflater().inflate(R.menu.sub_folder, menu); getMenuInflater().inflate(R.menu.sub_folder, menu);
} else if (mState == ListEditState.TRASH_FOLDER) {
getMenuInflater().inflate(R.menu.trash_folder, menu);
} else if (mState == ListEditState.CALL_RECORD_FOLDER) { } else if (mState == ListEditState.CALL_RECORD_FOLDER) {
getMenuInflater().inflate(R.menu.call_record_folder, menu); getMenuInflater().inflate(R.menu.call_record_folder, menu);
} else { } else {
Log.e(TAG, "Wrong state:" + mState); Log.e(TAG, "Wrong state:" + mState);
} }
// 实现交替显示白天和夜间模式
// 2024-01-18 9:09
if (mBackground == DAY_MODE) {
menu.findItem(R.id.menu_day_mode).setVisible(false);
} else if (mBackground == NIGHT_MODE) {
menu.findItem(R.id.menu_night_mode).setVisible(false);
}
return true; return true;
} }
/**
* @Method onOptionsItemSelected
* @Date 2023/12/17 23:49
* @param item
* @Author lenovo
* @Return boolean
* @Description
*/
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { int itemId = item.getItemId();
case R.id.menu_new_folder: { if (itemId == R.id.menu_new_folder) {
showCreateOrModifyFolderDialog(true); showCreateOrModifyFolderDialog(true);
break; } else if (itemId == R.id.menu_export_text) {
} exportNoteToText();
case R.id.menu_export_text: { } else if (itemId == R.id.menu_sync) {
exportNoteToText(); if (isSyncMode()) {
break; if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) {
} GTaskSyncService.startSync(this);
case R.id.menu_sync: {
if (isSyncMode()) {
if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) {
GTaskSyncService.startSync(this);
} else {
GTaskSyncService.cancelSync(this);
}
} else { } else {
startPreferenceActivity(); GTaskSyncService.cancelSync(this);
} }
break; } else {
}
case R.id.menu_setting: {
startPreferenceActivity(); startPreferenceActivity();
break;
}
case R.id.menu_new_note: {
createNewNote();
break;
} }
case R.id.menu_search: } else if (itemId == R.id.menu_setting) {
onSearchRequested(); startPreferenceActivity();
break; } else if (itemId == R.id.menu_new_note) {
default: createNewNote();
break; } else if (itemId == R.id.menu_search) {
onSearchRequested();
} else if (itemId == R.id.menu_trash) {
openTrashFolder();
} else if (itemId == R.id.menu_empty_trash) {
emptyTrashFolder();
} else if (itemId == R.id.menu_count_notes) {
countTotalNotes();
} else if (itemId == R.id.menu_day_mode) {
mBackground = DAY_MODE;
getWindow().setBackgroundDrawableResource(R.drawable.list_day_mode_background);
} else if (itemId == R.id.menu_night_mode) {
mBackground = NIGHT_MODE;
getWindow().setBackgroundDrawableResource(R.drawable.list_night_mode_background);
} }
return true; return true;
} }
private void countTotalNotes() {
AlertDialog.Builder btr =new AlertDialog.Builder(this);
btr.setTitle("目前便签数");
btr.setMessage("目前有 "+Integer.toString(mNotesListAdapter.getMNotesCount())+"个便签");
btr.show();
}
/**
* @method: emptyTrashFolder
* @description: 便
* @date: 2024/1/3 22:59
* @author: zhoukexing
* @param: []
* @return: void
*/
private void emptyTrashFolder() {
// 利用已有函数,在数据结构上“选中”所有便签 @zkx
mNotesListAdapter.selectAll(true);
// 模仿选中R.id.delete构建对话框
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(getString(R.string.alert_title_delete_true));
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setMessage(getString(R.string.alert_message_delete_notes_true,
mNotesListAdapter.getMNotesCount()));
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
// 这里体现了【层次化/模块化】的软件哲学。
// 当时实现这个功能有两条路可以走,
// 一条是修改已有batchDelete里的select函数改为选中所有实现一个alldelete函数
// 一条是利用batchDelete的功能删除选中的便签在进入batchDelete前选中所有
// 后者是更好的。前者需要修改方法,是侵入式的,而且会造成许多代码的重复,没有做到方法与方法之间的低耦合。
batchDelete();
}
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.show();
}
/**
* @method: openTrashFolder
* @description: todo30
* @date: 2024/1/2 19:04
* @author: zhoukexing
* @param: []
* @return: void
*/
private void openTrashFolder() {
mCurrentFolderId = Notes.ID_TRASH_FOLER;
startAsyncNotesListQuery();
// 正常打开文件夹
mState = ListEditState.TRASH_FOLDER;
// 将顶部栏设置为 data.getSnippet 文件夹名称
mTitleBar.setText(NotesListActivity.this
.getString(R.string.menu_trash));
// 不显示底部的“写便签” todoclosed:从子文件夹回到主页面时,展示底部栏
mAddNewNote.setVisibility(View.GONE);
mTitleBar.setVisibility(View.VISIBLE);
}
@Override @Override
/**
* @Method onSearchRequested
* @Date 2023/12/19 8:53
* @Author lenovo
* @Return boolean
* @Description
*/
public boolean onSearchRequested() { public boolean onSearchRequested() {
startSearch(null, false, null /* appData */, false); startSearch(null, false, null /* appData */, false);
return true; return true;
} }
/**
* @Method exportNoteToText
* @Date 2023/12/19 8:44
* @Author lenovo
* @Return void
* @Description 便
*/
private void exportNoteToText() { private void exportNoteToText() {
final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this); final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
/**
* UI 线
* Warning: deprecated in API level 30
* would cause Context leaks, missed callbacks, or crashes on configuration changes.
* lenovo 2023/12/19 9:04
*/
new AsyncTask<Void, Void, Integer>() { new AsyncTask<Void, Void, Integer>() {
@Override @Override
// 后台运行导出文本
protected Integer doInBackground(Void... unused) { protected Integer doInBackground(Void... unused) {
return backup.exportToText(); return backup.exportToText();
} }
@Override @Override
// 线程运行结束后的结果处理程序
protected void onPostExecute(Integer result) { protected void onPostExecute(Integer result) {
if (result == BackupUtils.STATE_SD_CARD_UNMOUONTED) { if (result == BackupUtils.STATE_SD_CARD_UNMOUONTED) { // 没插 SD 卡
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(NotesListActivity.this builder.setTitle(NotesListActivity.this
.getString(R.string.failed_sdcard_export)); .getString(R.string.failed_sdcard_export));
@ -903,6 +1152,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
break; break;
case SUB_FOLDER: case SUB_FOLDER:
case CALL_RECORD_FOLDER: case CALL_RECORD_FOLDER:
case TRASH_FOLDER:
if (item.getType() == Notes.TYPE_NOTE) { if (item.getType() == Notes.TYPE_NOTE) {
openNode(item); openNode(item);
} else { } else {
@ -917,6 +1167,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} }
/**
* @Method startQueryDestinationFolders
* @Date 2023/12/19 8:59
* @Author lenovo
* @Return void
* @Description
*/
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:

@ -16,12 +16,14 @@
package net.micode.notes.ui; package net.micode.notes.ui;
import android.text.TextUtils;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CursorAdapter; import android.widget.CursorAdapter;
import android.widget.LinearLayout;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
@ -34,22 +36,41 @@ import java.util.Iterator;
public class NotesListAdapter extends CursorAdapter { public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter"; private static final String TAG = "NotesListAdapter";
private Context mContext; private Context mContext;
/** 键-值对值为true时表示被选中 @zhoukexing 2024/1/2 20:50 */
private HashMap<Integer, Boolean> mSelectedIndex; private HashMap<Integer, Boolean> mSelectedIndex;
// private HashMap<Integer, String> mSnippetPosition;
private int mNotesCount; private int mNotesCount;
private boolean mChoiceMode; private boolean mChoiceMode;
// private String mQuery; // 搜索串
public static class AppWidgetAttribute { public static class AppWidgetAttribute {
public int widgetId; public int widgetId;
public int widgetType; public int widgetType;
}; }
public NotesListAdapter(Context context) { public NotesListAdapter(Context context, Cursor cursor) {
super(context, null); super(context, cursor);
mSelectedIndex = new HashMap<Integer, Boolean>(); mSelectedIndex = new HashMap<Integer, Boolean>();
// mSnippetPosition = new HashMap<Integer, String>();
mContext = context; mContext = context;
mNotesCount = 0; mNotesCount = 0;
// mQuery="";
} }
// @Override
// public View getView(int position, View convertView, ViewGroup parent) {
// View view = super.getView(position, convertView, parent);
// // 仅显示便签项中包含搜索串的便签
// String snippet = mSnippetPosition.get(position);
// Log.e(TAG, snippet);
// if(!TextUtils.isEmpty(mQuery) && !mSnippetPosition.get(position).contains(mQuery)) {
// view.setVisibility(View.GONE);
// LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(0,1);
// view.setLayoutParams(param);
// }
// return view;
// }
@Override @Override
public View newView(Context context, Cursor cursor, ViewGroup parent) { public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new NotesListItem(context); return new NotesListItem(context);
@ -78,6 +99,17 @@ public class NotesListAdapter extends CursorAdapter {
mChoiceMode = mode; mChoiceMode = mode;
} }
/**
* @method: selectAll
* @description: boolean
* setCheckedItemmSelectedIndex
*
* or
* @date: 2024/1/3 22:36
* @author: zhoukexing
* @param: [checked]
* @return: void
*/
public void selectAll(boolean checked) { public void selectAll(boolean checked) {
Cursor cursor = getCursor(); Cursor cursor = getCursor();
for (int i = 0; i < getCount(); i++) { for (int i = 0; i < getCount(); i++) {
@ -143,11 +175,27 @@ public class NotesListAdapter extends CursorAdapter {
return count; return count;
} }
public int getMNotesCount() {
return mNotesCount;
}
/**
* @method: isAllSelected
* @description: truefalse
* @date: 2024/1/2 20:47
* @author: zhoukexing
* @param: []
* @return: boolean
*/
public boolean isAllSelected() { public boolean isAllSelected() {
int checkedCount = getSelectedCount(); int checkedCount = getSelectedCount();
return (checkedCount != 0 && checkedCount == mNotesCount); return (checkedCount != 0 && checkedCount == mNotesCount);
} }
// public void setmQuery(String Query) {
// mQuery = Query;
// }
public boolean isSelectedItem(final int position) { public boolean isSelectedItem(final int position) {
if (null == mSelectedIndex.get(position)) { if (null == mSelectedIndex.get(position)) {
return false; return false;
@ -159,14 +207,46 @@ public class NotesListAdapter extends CursorAdapter {
protected void onContentChanged() { protected void onContentChanged() {
super.onContentChanged(); super.onContentChanged();
calcNotesCount(); calcNotesCount();
// updateSnippetMap(); // 在数据发生改变时更新 Snippet 到 Position 的映射
} }
/**
* @Method changeCursor
* @Date 2024/1/18 15:36
* @param cursor
* @Author lenovo
* @Return void
* @Description cursor
*/
@Override @Override
public void changeCursor(Cursor cursor) { public void changeCursor(Cursor cursor) {
super.changeCursor(cursor); super.changeCursor(cursor);
calcNotesCount(); calcNotesCount();
// updateSnippetMap(); // 在数据发生改变时更新 Snippet 到 Position 的映射
} }
// private void updateSnippetMap() {
// mSnippetPosition = new HashMap<Integer, String>();
// for (int i = 0; i < getCount(); i++) {
// Cursor c = (Cursor) getItem(i);
// if (c != null) {
// int position = c.getPosition();
// NoteItemData item = new NoteItemData(mContext, c);
// mSnippetPosition.put(position, item.getSnippet());
// } else {
// Log.e(TAG, "Invalid cursor");
// break;
// }
// }
// }
/**
* @Method calcNotesCount
* @Date 2024/1/18 15:36
* @Author lenovo
* @Return void
* @Description 便
*/
private void calcNotesCount() { private void calcNotesCount() {
mNotesCount = 0; mNotesCount = 0;
for (int i = 0; i < getCount(); i++) { for (int i = 0; i < getCount(); i++) {

@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
@ -14,109 +14,154 @@
* limitations under the License. * limitations under the License.
*/ */
package net.micode.notes.ui; package net.micode.notes.ui;
import android.content.Context; import android.content.Context;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.view.View; import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import net.micode.notes.R; import net.micode.notes.R;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.DataUtils;
import net.micode.notes.tool.ResourceParser.NoteItemBgResources; import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
/**
public class NotesListItem extends LinearLayout { * @Package: net.micode.notes.ui
private ImageView mAlert; * @Class: NotesListItem
private TextView mTitle; * @Author: lenovo
private TextView mTime; * @Date: 2024/1/18 15:43
private TextView mCallName; * @Description: 便便便
private NoteItemData mItemData; */
private CheckBox mCheckBox; public class NotesListItem extends LinearLayout {
private ImageView mAlert; // 用于显示提醒图标的ImageView
public NotesListItem(Context context) { private ImageView mTop; // 用于显示置顶图标的ImageView
super(context); private TextView mTitle; // 用于显示便签标题的TextView
inflate(context, R.layout.note_item, this); private TextView mTime; // 用于显示便签修改时间的TextView
mAlert = (ImageView) findViewById(R.id.iv_alert_icon); private TextView mCallName; // 用于显示通话记录名称的TextView
mTitle = (TextView) findViewById(R.id.tv_title); private NoteItemData mItemData; // 当前便签项的数据
mTime = (TextView) findViewById(R.id.tv_time); private CheckBox mCheckBox; // 用于显示选择框的CheckBox
mCallName = (TextView) findViewById(R.id.tv_name);
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); /**
} * 便
* @param context
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) { */
if (choiceMode && data.getType() == Notes.TYPE_NOTE) { public NotesListItem(Context context) {
mCheckBox.setVisibility(View.VISIBLE); super(context);
mCheckBox.setChecked(checked); inflate(context, R.layout.note_item, this); // 加载便签项布局
} else { mAlert = (ImageView) findViewById(R.id.iv_alert_icon); // 获取提醒图标
mCheckBox.setVisibility(View.GONE); mTop = (ImageView) findViewById(R.id.iv_top_icon); // 获取置顶图标
} mTitle = (TextView) findViewById(R.id.tv_title); // 获取便签标题
mTime = (TextView) findViewById(R.id.tv_time); // 获取便签修改时间
mItemData = data; mCallName = (TextView) findViewById(R.id.tv_name); // 获取通话记录名称
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) { mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); // 获取选择框
mCallName.setVisibility(View.GONE); }
mAlert.setVisibility(View.VISIBLE);
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); /**
mTitle.setText(context.getString(R.string.call_record_folder_name) * 便
+ context.getString(R.string.format_folder_files_count, data.getNotesCount())); * @param context
mAlert.setImageResource(R.drawable.call_record); * @param data 便
} else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) { * @param choiceMode
mCallName.setVisibility(View.VISIBLE); * @param checked
mCallName.setText(data.getCallName()); */
mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem); public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); if (choiceMode && data.getType() == Notes.TYPE_NOTE) {
if (data.hasAlert()) { mCheckBox.setVisibility(View.VISIBLE); // 如果处于选择模式且是便签类型,则显示选择框
mAlert.setImageResource(R.drawable.clock); mCheckBox.setChecked(checked); // 设置选择框的选中状态
mAlert.setVisibility(View.VISIBLE); } else {
} else { mCheckBox.setVisibility(View.GONE); // 否则隐藏选择框
mAlert.setVisibility(View.GONE); }
}
} else { mItemData = data; // 设置当前便签项的数据
mCallName.setVisibility(View.GONE); if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); // 如果是通话记录文件夹
mCallName.setVisibility(View.GONE); // 隐藏通话记录名称
if (data.getType() == Notes.TYPE_FOLDER) { mAlert.setVisibility(View.VISIBLE); // 显示提醒图标
mTitle.setText(data.getSnippet() mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); // 设置便签标题的样式
+ context.getString(R.string.format_folder_files_count, mTitle.setText(context.getString(R.string.call_record_folder_name)
data.getNotesCount())); + context.getString(R.string.format_folder_files_count, data.getNotesCount())); // 设置便签标题为通话记录文件夹名称和文件数量
mAlert.setVisibility(View.GONE); mAlert.setImageResource(R.drawable.call_record); // 设置提醒图标为通话记录图标
} else { } else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); // 如果是通话记录
if (data.hasAlert()) { mCallName.setVisibility(View.VISIBLE); // 显示通话记录名称
mAlert.setImageResource(R.drawable.clock); mCallName.setText(data.getCallName()); // 设置通话记录名称
mAlert.setVisibility(View.VISIBLE); mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem); // 设置便签标题的样式
} else { mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); // 设置便签标题为格式化的摘要信息
mAlert.setVisibility(View.GONE); if (data.hasAlert()) {
} mAlert.setImageResource(R.drawable.clock); // 如果有提醒,则设置提醒图标为时钟图标
} mAlert.setVisibility(View.VISIBLE); // 显示提醒图标
} } else {
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate())); mAlert.setVisibility(View.GONE); // 否则隐藏提醒图标
}
setBackground(data); } else {
} mCallName.setVisibility(View.GONE); // 隐藏通话记录名称
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); // 设置便签标题的样式
private void setBackground(NoteItemData data) {
int id = data.getBgColorId(); if (data.getType() == Notes.TYPE_FOLDER) {
if (data.getType() == Notes.TYPE_NOTE) { // 如果是文件夹
if (data.isSingle() || data.isOneFollowingFolder()) { mTitle.setText(data.getSnippet()
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id)); + context.getString(R.string.format_folder_files_count,
} else if (data.isLast()) { data.getNotesCount())); // 设置便签标题为文件夹名称和文件数量
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id)); mAlert.setVisibility(View.GONE); // 隐藏提醒图标
} else if (data.isFirst() || data.isMultiFollowingFolder()) { } else {
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id)); // 如果是便签
} else { mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); // 设置便签标题为格式化的摘要信息
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id)); if (data.hasAlert()) {
} mAlert.setImageResource(R.drawable.clock); // 如果有提醒,则设置提醒图标为时钟图标
} else { mAlert.setVisibility(View.VISIBLE); // 显示提醒图标
setBackgroundResource(NoteItemBgResources.getFolderBgRes()); } else {
} mAlert.setVisibility(View.GONE); // 否则隐藏提醒图标
} }
}
public NoteItemData getItemData() { }
return mItemData; mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate())); // 设置便签修改时间为相对时间字符串
} // 设置置顶图标
} if(data.getTop() == 1){
mTop.setImageResource(R.drawable.set_top); // 如果便签置顶,则设置置顶图标为置顶图标
mTop.setVisibility(View.VISIBLE); // 显示置顶图标
}
else{
mTop.setVisibility(View.GONE); // 否则隐藏置顶图标
}
setBackground(data); // 设置便签项的背景
}
/**
* 便
* @param data 便
*/
private void setBackground(NoteItemData data) {
int id = data.getBgColorId(); // 获取便签项的背景颜色ID
if (data.getType() == Notes.TYPE_NOTE) {
// 如果是便签
if (data.isSingle() || data.isOneFollowingFolder()) {
// 如果是单个便签或紧跟在文件夹后面的便签
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id)); // 设置背景为单个便签背景
} else if (data.isLast()) {
// 如果是最后一个便签
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id)); // 设置背景为最后一个便签背景
} else if (data.isFirst() || data.isMultiFollowingFolder()) {
// 如果是第一个便签或紧跟在多个文件夹后面的便签
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id)); // 设置背景为第一个便签背景
} else {
// 如果是普通便签
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id)); // 设置背景为普通便签背景
}
} else {
// 如果是文件夹
setBackgroundResource(NoteItemBgResources.getFolderBgRes()); // 设置背景为文件夹背景
}
}
/**
* 便
* @return 便
*/
public NoteItemData getItemData() {
return mItemData;
}
}

@ -32,11 +32,20 @@ import net.micode.notes.tool.ResourceParser;
import net.micode.notes.ui.NoteEditActivity; import net.micode.notes.ui.NoteEditActivity;
import net.micode.notes.ui.NotesListActivity; import net.micode.notes.ui.NotesListActivity;
/**
*
* @ProjectName: minode
* @Package: net.micode.notes.widget
* @ClassName: NoteWidgetProvider
* @Description: AppWidgetProvider
* @Date: 2024-12-18 21:13
*/
public abstract class NoteWidgetProvider extends AppWidgetProvider { public abstract class NoteWidgetProvider extends AppWidgetProvider {
public static final String [] PROJECTION = new String [] { public static final String [] PROJECTION = new String [] {
NoteColumns.ID, NoteColumns.ID,
NoteColumns.BG_COLOR_ID, NoteColumns.BG_COLOR_ID,
NoteColumns.SNIPPET NoteColumns.SNIPPET
}; };
public static final int COLUMN_ID = 0; public static final int COLUMN_ID = 0;
@ -45,6 +54,12 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
private static final String TAG = "NoteWidgetProvider"; private static final String TAG = "NoteWidgetProvider";
/**
* @method onDeleted
* @description Widget
* @date: 2024-12-18 21:18
* @return void
*/
@Override @Override
public void onDeleted(Context context, int[] appWidgetIds) { public void onDeleted(Context context, int[] appWidgetIds) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
@ -65,12 +80,18 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
null); null);
} }
/**
* @method update
* @description Widget
* @date: 2024-12-18 21:11
* @return void
*/
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
update(context, appWidgetManager, appWidgetIds, false); update(context, appWidgetManager, appWidgetIds, false);
} }
private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
boolean privacyMode) { boolean privacyMode) {
for (int i = 0; i < appWidgetIds.length; i++) { for (int i = 0; i < appWidgetIds.length; i++) {
if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) { if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
int bgId = ResourceParser.getDefaultBgId(context); int bgId = ResourceParser.getDefaultBgId(context);

Loading…
Cancel
Save