diff --git a/doc/cjn_notes.md b/doc/cjn_notes.md new file mode 100644 index 0000000..e69de29 diff --git a/doc/小米便签泛读报告文档.docx b/doc/小米便签泛读报告文档.docx new file mode 100644 index 0000000..1e627db Binary files /dev/null and b/doc/小米便签泛读报告文档.docx differ diff --git a/src/Notes-master/Notes-master/AndroidManifest.xml b/src/AndroidManifest.xml similarity index 90% rename from src/Notes-master/Notes-master/AndroidManifest.xml rename to src/AndroidManifest.xml index e5c7d47..f6f69d4 100644 --- a/src/Notes-master/Notes-master/AndroidManifest.xml +++ b/src/AndroidManifest.xml @@ -1,5 +1,4 @@ - + + diff --git a/src/Notes-master/Notes-master/.gitignore b/src/Notes-master/Notes-master/.gitignore deleted file mode 100644 index 7df8dff..0000000 --- a/src/Notes-master/Notes-master/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -# generated files -bin/ -gen/ - -# Local configuration file (sdk path, etc) -project.properties -.settings/ -.classpath -.project diff --git a/src/Notes-master/Notes-master/NOTICE b/src/Notes-master/Notes-master/NOTICE deleted file mode 100644 index 9a54521..0000000 --- a/src/Notes-master/Notes-master/NOTICE +++ /dev/null @@ -1,190 +0,0 @@ - - Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - diff --git a/src/Notes-master/Notes-master/README b/src/Notes-master/Notes-master/README deleted file mode 100644 index fc0d824..0000000 --- a/src/Notes-master/Notes-master/README +++ /dev/null @@ -1,23 +0,0 @@ -[中文] - -1. MiCode便签是小米便签的社区开源版,由MIUI团队(www.miui.com) 发起并贡献第一批代码,遵循NOTICE文件所描述的开源协议, - 今后为MiCode社区(www.micode.net) 拥有,并由社区发布和维护。 - -2. Bug反馈和跟踪,请访问Github, - https://github.com/MiCode/Notes/issues?sort=created&direction=desc&state=open - -3. 功能建议和综合讨论,请访问MiCode, - http://micode.net/forum.php?mod=forumdisplay&fid=38 - - -[English] - -1. MiCode Notes is open source edition of XM notepad, it's first initiated and sponsored by MIUI team (www.miui.com). - It's opened under license described by NOTICE file. It's owned by the MiCode community (www.micode.net). In future, - the MiCode community will release and maintain this project. - -2. Regarding issue tracking, please visit Github, - https://github.com/MiCode/Notes/issues?sort=created&direction=desc&state=open - -3. Regarding feature request and general discussion, please visit Micode forum, - http://micode.net/forum.php?mod=forumdisplay&fid=38 diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/tool/BackupUtils.java b/src/Notes-master/Notes-master/src/net/micode/notes/tool/BackupUtils.java deleted file mode 100644 index 39f6ec4..0000000 --- a/src/Notes-master/Notes-master/src/net/micode/notes/tool/BackupUtils.java +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.micode.notes.tool; - -import android.content.Context; -import android.database.Cursor; -import android.os.Environment; -import android.text.TextUtils; -import android.text.format.DateFormat; -import android.util.Log; - -import net.micode.notes.R; -import net.micode.notes.data.Notes; -import net.micode.notes.data.Notes.DataColumns; -import net.micode.notes.data.Notes.DataConstants; -import net.micode.notes.data.Notes.NoteColumns; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; - - -public class BackupUtils { - private static final String TAG = "BackupUtils"; - // Singleton stuff - private static BackupUtils sInstance; - - public static synchronized BackupUtils getInstance(Context context) { - if (sInstance == null) { - sInstance = new BackupUtils(context); - } - return sInstance; - } - - /** - * Following states are signs to represents backup or restore - * status - */ - // Currently, the sdcard is not mounted - public static final int STATE_SD_CARD_UNMOUONTED = 0; - // The backup file not exist - public static final int STATE_BACKUP_FILE_NOT_EXIST = 1; - // The data is not well formated, may be changed by other programs - public static final int STATE_DATA_DESTROIED = 2; - // Some run-time exception which causes restore or backup fails - public static final int STATE_SYSTEM_ERROR = 3; - // Backup or restore success - public static final int STATE_SUCCESS = 4; - - private TextExport mTextExport; - - private BackupUtils(Context context) { - mTextExport = new TextExport(context); - } - - private static boolean externalStorageAvailable() { - return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); - } - - public int exportToText() { - return mTextExport.exportToText(); - } - - public String getExportedTextFileName() { - return mTextExport.mFileName; - } - - public String getExportedTextFileDir() { - return mTextExport.mFileDirectory; - } - - private static class TextExport { - private static final String[] NOTE_PROJECTION = { - NoteColumns.ID, - NoteColumns.MODIFIED_DATE, - NoteColumns.SNIPPET, - NoteColumns.TYPE - }; - - private static final int NOTE_COLUMN_ID = 0; - - private static final int NOTE_COLUMN_MODIFIED_DATE = 1; - - private static final int NOTE_COLUMN_SNIPPET = 2; - - private static final String[] DATA_PROJECTION = { - DataColumns.CONTENT, - DataColumns.MIME_TYPE, - DataColumns.DATA1, - DataColumns.DATA2, - DataColumns.DATA3, - DataColumns.DATA4, - }; - - private static final int DATA_COLUMN_CONTENT = 0; - - private static final int DATA_COLUMN_MIME_TYPE = 1; - - private static final int DATA_COLUMN_CALL_DATE = 2; - - private static final int DATA_COLUMN_PHONE_NUMBER = 4; - - private final String [] TEXT_FORMAT; - private static final int FORMAT_FOLDER_NAME = 0; - private static final int FORMAT_NOTE_DATE = 1; - private static final int FORMAT_NOTE_CONTENT = 2; - - private Context mContext; - private String mFileName; - private String mFileDirectory; - - public TextExport(Context context) { - TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); - mContext = context; - mFileName = ""; - mFileDirectory = ""; - } - - private String getFormat(int id) { - return TEXT_FORMAT[id]; - } - - /** - * Export the folder identified by folder id to text - */ - private void exportFolderToText(String folderId, PrintStream ps) { - // Query notes belong to this folder - Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI, - NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] { - folderId - }, null); - - if (notesCursor != null) { - if (notesCursor.moveToFirst()) { - do { - // Print note's last modified date - ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( - mContext.getString(R.string.format_datetime_mdhm), - notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); - // Query data belong to this note - String noteId = notesCursor.getString(NOTE_COLUMN_ID); - exportNoteToText(noteId, ps); - } while (notesCursor.moveToNext()); - } - notesCursor.close(); - } - } - - /** - * Export note identified by id to a print stream - */ - private void exportNoteToText(String noteId, PrintStream ps) { - Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, - DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { - noteId - }, null); - - if (dataCursor != null) { - if (dataCursor.moveToFirst()) { - do { - String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE); - if (DataConstants.CALL_NOTE.equals(mimeType)) { - // Print phone number - String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER); - long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE); - String location = dataCursor.getString(DATA_COLUMN_CONTENT); - - if (!TextUtils.isEmpty(phoneNumber)) { - ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), - phoneNumber)); - } - // Print call date - ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat - .format(mContext.getString(R.string.format_datetime_mdhm), - callDate))); - // Print call attachment location - if (!TextUtils.isEmpty(location)) { - ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), - location)); - } - } else if (DataConstants.NOTE.equals(mimeType)) { - String content = dataCursor.getString(DATA_COLUMN_CONTENT); - if (!TextUtils.isEmpty(content)) { - ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), - content)); - } - } - } while (dataCursor.moveToNext()); - } - dataCursor.close(); - } - // print a line separator between note - try { - ps.write(new byte[] { - Character.LINE_SEPARATOR, Character.LETTER_NUMBER - }); - } catch (IOException e) { - Log.e(TAG, e.toString()); - } - } - - /** - * Note will be exported as text which is user readable - */ - public int exportToText() { - if (!externalStorageAvailable()) { - Log.d(TAG, "Media was not mounted"); - return STATE_SD_CARD_UNMOUONTED; - } - - PrintStream ps = getExportToTextPrintStream(); - if (ps == null) { - Log.e(TAG, "get print stream error"); - return STATE_SYSTEM_ERROR; - } - // First export folder and its notes - Cursor folderCursor = mContext.getContentResolver().query( - Notes.CONTENT_NOTE_URI, - NOTE_PROJECTION, - "(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND " - + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR " - + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null); - - if (folderCursor != null) { - if (folderCursor.moveToFirst()) { - do { - // Print folder's name - String folderName = ""; - if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) { - folderName = mContext.getString(R.string.call_record_folder_name); - } else { - folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET); - } - if (!TextUtils.isEmpty(folderName)) { - ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName)); - } - String folderId = folderCursor.getString(NOTE_COLUMN_ID); - exportFolderToText(folderId, ps); - } while (folderCursor.moveToNext()); - } - folderCursor.close(); - } - - // Export notes in root's folder - Cursor noteCursor = mContext.getContentResolver().query( - Notes.CONTENT_NOTE_URI, - NOTE_PROJECTION, - NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID - + "=0", null, null); - - if (noteCursor != null) { - if (noteCursor.moveToFirst()) { - do { - ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( - mContext.getString(R.string.format_datetime_mdhm), - noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); - // Query data belong to this note - String noteId = noteCursor.getString(NOTE_COLUMN_ID); - exportNoteToText(noteId, ps); - } while (noteCursor.moveToNext()); - } - noteCursor.close(); - } - ps.close(); - - return STATE_SUCCESS; - } - - /** - * Get a print stream pointed to the file {@generateExportedTextFile} - */ - private PrintStream getExportToTextPrintStream() { - File file = generateFileMountedOnSDcard(mContext, R.string.file_path, - R.string.file_name_txt_format); - if (file == null) { - Log.e(TAG, "create file to exported failed"); - return null; - } - mFileName = file.getName(); - mFileDirectory = mContext.getString(R.string.file_path); - PrintStream ps = null; - try { - FileOutputStream fos = new FileOutputStream(file); - ps = new PrintStream(fos); - } catch (FileNotFoundException e) { - e.printStackTrace(); - return null; - } catch (NullPointerException e) { - e.printStackTrace(); - return null; - } - return ps; - } - } - - /** - * Generate the text file to store imported data - */ - private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { - StringBuilder sb = new StringBuilder(); - sb.append(Environment.getExternalStorageDirectory()); - sb.append(context.getString(filePathResId)); - File filedir = new File(sb.toString()); - sb.append(context.getString( - fileNameFormatResId, - DateFormat.format(context.getString(R.string.format_date_ymd), - System.currentTimeMillis()))); - File file = new File(sb.toString()); - - try { - if (!filedir.exists()) { - filedir.mkdir(); - } - if (!file.exists()) { - file.createNewFile(); - } - return file; - } catch (SecurityException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - return null; - } -} - - diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/tool/DataUtils.java b/src/Notes-master/Notes-master/src/net/micode/notes/tool/DataUtils.java deleted file mode 100644 index 2a14982..0000000 --- a/src/Notes-master/Notes-master/src/net/micode/notes/tool/DataUtils.java +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.micode.notes.tool; - -import android.content.ContentProviderOperation; -import android.content.ContentProviderResult; -import android.content.ContentResolver; -import android.content.ContentUris; -import android.content.ContentValues; -import android.content.OperationApplicationException; -import android.database.Cursor; -import android.os.RemoteException; -import android.util.Log; - -import net.micode.notes.data.Notes; -import net.micode.notes.data.Notes.CallNote; -import net.micode.notes.data.Notes.NoteColumns; -import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; - -import java.util.ArrayList; -import java.util.HashSet; - - -public class DataUtils { - public static final String TAG = "DataUtils"; - public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) { - if (ids == null) { - Log.d(TAG, "the ids is null"); - return true; - } - if (ids.size() == 0) { - Log.d(TAG, "no id is in the hashset"); - return true; - } - - ArrayList operationList = new ArrayList(); - for (long id : ids) { - if(id == Notes.ID_ROOT_FOLDER) { - Log.e(TAG, "Don't delete system folder root"); - continue; - } - ContentProviderOperation.Builder builder = ContentProviderOperation - .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); - operationList.add(builder.build()); - } - try { - ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); - if (results == null || results.length == 0 || results[0] == null) { - Log.d(TAG, "delete notes failed, ids:" + ids.toString()); - return false; - } - return true; - } catch (RemoteException e) { - Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); - } catch (OperationApplicationException e) { - Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); - } - return false; - } - - public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) { - ContentValues values = new ContentValues(); - values.put(NoteColumns.PARENT_ID, desFolderId); - values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId); - values.put(NoteColumns.LOCAL_MODIFIED, 1); - resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); - } - - public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, - long folderId) { - if (ids == null) { - Log.d(TAG, "the ids is null"); - return true; - } - - ArrayList operationList = new ArrayList(); - for (long id : ids) { - ContentProviderOperation.Builder builder = ContentProviderOperation - .newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); - builder.withValue(NoteColumns.PARENT_ID, folderId); - builder.withValue(NoteColumns.LOCAL_MODIFIED, 1); - operationList.add(builder.build()); - } - - try { - ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); - if (results == null || results.length == 0 || results[0] == null) { - Log.d(TAG, "delete notes failed, ids:" + ids.toString()); - return false; - } - return true; - } catch (RemoteException e) { - Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); - } catch (OperationApplicationException e) { - Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); - } - return false; - } - - /** - * Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}} - */ - public static int getUserFolderCount(ContentResolver resolver) { - Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI, - new String[] { "COUNT(*)" }, - NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?", - new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)}, - null); - - int count = 0; - if(cursor != null) { - if(cursor.moveToFirst()) { - try { - count = cursor.getInt(0); - } catch (IndexOutOfBoundsException e) { - Log.e(TAG, "get folder count failed:" + e.toString()); - } finally { - cursor.close(); - } - } - } - return count; - } - - public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { - Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), - null, - NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER, - new String [] {String.valueOf(type)}, - null); - - boolean exist = false; - if (cursor != null) { - if (cursor.getCount() > 0) { - exist = true; - } - cursor.close(); - } - return exist; - } - - public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) { - Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), - null, null, null, null); - - boolean exist = false; - if (cursor != null) { - if (cursor.getCount() > 0) { - exist = true; - } - cursor.close(); - } - return exist; - } - - public static boolean existInDataDatabase(ContentResolver resolver, long dataId) { - Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), - null, null, null, null); - - boolean exist = false; - if (cursor != null) { - if (cursor.getCount() > 0) { - exist = true; - } - cursor.close(); - } - return exist; - } - - public static boolean checkVisibleFolderName(ContentResolver resolver, String name) { - Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null, - NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + - " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + - " AND " + NoteColumns.SNIPPET + "=?", - new String[] { name }, null); - boolean exist = false; - if(cursor != null) { - if(cursor.getCount() > 0) { - exist = true; - } - cursor.close(); - } - return exist; - } - - public static HashSet getFolderNoteWidget(ContentResolver resolver, long folderId) { - Cursor c = resolver.query(Notes.CONTENT_NOTE_URI, - new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, - NoteColumns.PARENT_ID + "=?", - new String[] { String.valueOf(folderId) }, - null); - - HashSet set = null; - if (c != null) { - if (c.moveToFirst()) { - set = new HashSet(); - do { - try { - AppWidgetAttribute widget = new AppWidgetAttribute(); - widget.widgetId = c.getInt(0); - widget.widgetType = c.getInt(1); - set.add(widget); - } catch (IndexOutOfBoundsException e) { - Log.e(TAG, e.toString()); - } - } while (c.moveToNext()); - } - c.close(); - } - return set; - } - - public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { - Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, - new String [] { CallNote.PHONE_NUMBER }, - CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?", - new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE }, - null); - - if (cursor != null && cursor.moveToFirst()) { - try { - return cursor.getString(0); - } catch (IndexOutOfBoundsException e) { - Log.e(TAG, "Get call number fails " + e.toString()); - } finally { - cursor.close(); - } - } - return ""; - } - - public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) { - Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, - new String [] { CallNote.NOTE_ID }, - CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL(" - + CallNote.PHONE_NUMBER + ",?)", - new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber }, - null); - - if (cursor != null) { - if (cursor.moveToFirst()) { - try { - return cursor.getLong(0); - } catch (IndexOutOfBoundsException e) { - Log.e(TAG, "Get call note id fails " + e.toString()); - } - } - cursor.close(); - } - return 0; - } - - public static String getSnippetById(ContentResolver resolver, long noteId) { - Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, - new String [] { NoteColumns.SNIPPET }, - NoteColumns.ID + "=?", - new String [] { String.valueOf(noteId)}, - null); - - if (cursor != null) { - String snippet = ""; - if (cursor.moveToFirst()) { - snippet = cursor.getString(0); - } - cursor.close(); - return snippet; - } - throw new IllegalArgumentException("Note is not found with id: " + noteId); - } - - public static String getFormattedSnippet(String snippet) { - if (snippet != null) { - snippet = snippet.trim(); - int index = snippet.indexOf('\n'); - if (index != -1) { - snippet = snippet.substring(0, index); - } - } - return snippet; - } -} diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/DateTimePickerDialog.java b/src/Notes-master/Notes-master/src/net/micode/notes/ui/DateTimePickerDialog.java deleted file mode 100644 index 2c47ba4..0000000 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/DateTimePickerDialog.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.micode.notes.ui; - -import java.util.Calendar; - -import net.micode.notes.R; -import net.micode.notes.ui.DateTimePicker; -import net.micode.notes.ui.DateTimePicker.OnDateTimeChangedListener; - -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; -import android.text.format.DateFormat; -import android.text.format.DateUtils; - -public class DateTimePickerDialog extends AlertDialog implements OnClickListener { - - private Calendar mDate = Calendar.getInstance(); - private boolean mIs24HourView; - private OnDateTimeSetListener mOnDateTimeSetListener; - private DateTimePicker mDateTimePicker; - - public interface OnDateTimeSetListener { - void OnDateTimeSet(AlertDialog dialog, long date); - } - - public DateTimePickerDialog(Context context, long date) { - super(context); - mDateTimePicker = new DateTimePicker(context); - setView(mDateTimePicker); - mDateTimePicker.setOnDateTimeChangedListener(new OnDateTimeChangedListener() { - public void onDateTimeChanged(DateTimePicker view, int year, int month, - int dayOfMonth, int hourOfDay, int minute) { - mDate.set(Calendar.YEAR, year); - mDate.set(Calendar.MONTH, month); - mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); - mDate.set(Calendar.HOUR_OF_DAY, hourOfDay); - mDate.set(Calendar.MINUTE, minute); - updateTitle(mDate.getTimeInMillis()); - } - }); - mDate.setTimeInMillis(date); - mDate.set(Calendar.SECOND, 0); - mDateTimePicker.setCurrentDate(mDate.getTimeInMillis()); - setButton(context.getString(R.string.datetime_dialog_ok), this); - setButton2(context.getString(R.string.datetime_dialog_cancel), (OnClickListener)null); - set24HourView(DateFormat.is24HourFormat(this.getContext())); - updateTitle(mDate.getTimeInMillis()); - } - - public void set24HourView(boolean is24HourView) { - mIs24HourView = is24HourView; - } - - public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) { - mOnDateTimeSetListener = callBack; - } - - private void updateTitle(long date) { - int flag = - DateUtils.FORMAT_SHOW_YEAR | - DateUtils.FORMAT_SHOW_DATE | - DateUtils.FORMAT_SHOW_TIME; - flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR; - setTitle(DateUtils.formatDateTime(this.getContext(), date, flag)); - } - - public void onClick(DialogInterface arg0, int arg1) { - if (mOnDateTimeSetListener != null) { - mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis()); - } - } - -} \ No newline at end of file diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/FoldersListAdapter.java b/src/Notes-master/Notes-master/src/net/micode/notes/ui/FoldersListAdapter.java deleted file mode 100644 index 96b77da..0000000 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/FoldersListAdapter.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.micode.notes.ui; - -import android.content.Context; -import android.database.Cursor; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CursorAdapter; -import android.widget.LinearLayout; -import android.widget.TextView; - -import net.micode.notes.R; -import net.micode.notes.data.Notes; -import net.micode.notes.data.Notes.NoteColumns; - - -public class FoldersListAdapter extends CursorAdapter { - public static final String [] PROJECTION = { - NoteColumns.ID, - NoteColumns.SNIPPET - }; - - public static final int ID_COLUMN = 0; - public static final int NAME_COLUMN = 1; - - public FoldersListAdapter(Context context, Cursor c) { - super(context, c); - // TODO Auto-generated constructor stub - } - - @Override - public View newView(Context context, Cursor cursor, ViewGroup parent) { - return new FolderListItem(context); - } - - @Override - public void bindView(View view, Context context, Cursor cursor) { - if (view instanceof FolderListItem) { - String folderName = (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context - .getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN); - ((FolderListItem) view).bind(folderName); - } - } - - public String getFolderName(Context context, int position) { - Cursor cursor = (Cursor) getItem(position); - return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context - .getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN); - } - - private class FolderListItem extends LinearLayout { - private TextView mName; - - public FolderListItem(Context context) { - super(context); - inflate(context, R.layout.folder_list_item, this); - mName = (TextView) findViewById(R.id.tv_folder_name); - } - - public void bind(String name) { - mName.setText(name); - } - } - -} diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NoteEditText.java b/src/Notes-master/Notes-master/src/net/micode/notes/ui/NoteEditText.java deleted file mode 100644 index 2afe2a8..0000000 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NoteEditText.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.micode.notes.ui; - -import android.content.Context; -import android.graphics.Rect; -import android.text.Layout; -import android.text.Selection; -import android.text.Spanned; -import android.text.TextUtils; -import android.text.style.URLSpan; -import android.util.AttributeSet; -import android.util.Log; -import android.view.ContextMenu; -import android.view.KeyEvent; -import android.view.MenuItem; -import android.view.MenuItem.OnMenuItemClickListener; -import android.view.MotionEvent; -import android.widget.EditText; - -import net.micode.notes.R; - -import java.util.HashMap; -import java.util.Map; - -public class NoteEditText extends EditText { - private static final String TAG = "NoteEditText"; - private int mIndex; - private int mSelectionStartBeforeDelete; - - private static final String SCHEME_TEL = "tel:" ; - private static final String SCHEME_HTTP = "http:" ; - private static final String SCHEME_EMAIL = "mailto:" ; - - private static final Map sSchemaActionResMap = new HashMap(); - static { - sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel); - sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web); - sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email); - } - - /** - * Call by the {@link NoteEditActivity} to delete or add edit text - */ - public interface OnTextViewChangeListener { - /** - * Delete current edit text when {@link KeyEvent#KEYCODE_DEL} happens - * and the text is null - */ - void onEditTextDelete(int index, String text); - - /** - * Add edit text after current edit text when {@link KeyEvent#KEYCODE_ENTER} - * happen - */ - void onEditTextEnter(int index, String text); - - /** - * Hide or show item option when text change - */ - void onTextChange(int index, boolean hasText); - } - - private OnTextViewChangeListener mOnTextViewChangeListener; - - public NoteEditText(Context context) { - super(context, null); - mIndex = 0; - } - - public void setIndex(int index) { - mIndex = index; - } - - public void setOnTextViewChangeListener(OnTextViewChangeListener listener) { - mOnTextViewChangeListener = listener; - } - - public NoteEditText(Context context, AttributeSet attrs) { - super(context, attrs, android.R.attr.editTextStyle); - } - - public NoteEditText(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - // TODO Auto-generated constructor stub - } - - @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); - } - - @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); - } - - @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 (urls.length == 1) { - 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; - } - }); - } - } - super.onCreateContextMenu(menu); - } -} diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NotesListAdapter.java b/src/Notes-master/Notes-master/src/net/micode/notes/ui/NotesListAdapter.java deleted file mode 100644 index 51c9cb9..0000000 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NotesListAdapter.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.micode.notes.ui; - -import android.content.Context; -import android.database.Cursor; -import android.util.Log; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CursorAdapter; - -import net.micode.notes.data.Notes; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; - - -public class NotesListAdapter extends CursorAdapter { - private static final String TAG = "NotesListAdapter"; - private Context mContext; - private HashMap mSelectedIndex; - private int mNotesCount; - private boolean mChoiceMode; - - public static class AppWidgetAttribute { - public int widgetId; - public int widgetType; - }; - - public NotesListAdapter(Context context) { - super(context, null); - mSelectedIndex = new HashMap(); - mContext = context; - mNotesCount = 0; - } - - @Override - public View newView(Context context, Cursor cursor, ViewGroup parent) { - return new NotesListItem(context); - } - - @Override - public void bindView(View view, Context context, Cursor cursor) { - if (view instanceof NotesListItem) { - NoteItemData itemData = new NoteItemData(context, cursor); - ((NotesListItem) view).bind(context, itemData, mChoiceMode, - isSelectedItem(cursor.getPosition())); - } - } - - public void setCheckedItem(final int position, final boolean checked) { - mSelectedIndex.put(position, checked); - notifyDataSetChanged(); - } - - public boolean isInChoiceMode() { - return mChoiceMode; - } - - public void setChoiceMode(boolean mode) { - mSelectedIndex.clear(); - mChoiceMode = mode; - } - - public void selectAll(boolean checked) { - Cursor cursor = getCursor(); - for (int i = 0; i < getCount(); i++) { - if (cursor.moveToPosition(i)) { - if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) { - setCheckedItem(i, checked); - } - } - } - } - - public HashSet getSelectedItemIds() { - HashSet itemSet = new HashSet(); - for (Integer position : mSelectedIndex.keySet()) { - if (mSelectedIndex.get(position) == true) { - Long id = getItemId(position); - if (id == Notes.ID_ROOT_FOLDER) { - Log.d(TAG, "Wrong item id, should not happen"); - } else { - itemSet.add(id); - } - } - } - - return itemSet; - } - - public HashSet getSelectedWidget() { - HashSet itemSet = new HashSet(); - for (Integer position : mSelectedIndex.keySet()) { - if (mSelectedIndex.get(position) == true) { - Cursor c = (Cursor) getItem(position); - if (c != null) { - AppWidgetAttribute widget = new AppWidgetAttribute(); - NoteItemData item = new NoteItemData(mContext, c); - widget.widgetId = item.getWidgetId(); - widget.widgetType = item.getWidgetType(); - itemSet.add(widget); - /** - * Don't close cursor here, only the adapter could close it - */ - } else { - Log.e(TAG, "Invalid cursor"); - return null; - } - } - } - return itemSet; - } - - public int getSelectedCount() { - Collection values = mSelectedIndex.values(); - if (null == values) { - return 0; - } - Iterator iter = values.iterator(); - int count = 0; - while (iter.hasNext()) { - if (true == iter.next()) { - count++; - } - } - return count; - } - - public boolean isAllSelected() { - int checkedCount = getSelectedCount(); - return (checkedCount != 0 && checkedCount == mNotesCount); - } - - public boolean isSelectedItem(final int position) { - if (null == mSelectedIndex.get(position)) { - return false; - } - return mSelectedIndex.get(position); - } - - @Override - protected void onContentChanged() { - super.onContentChanged(); - calcNotesCount(); - } - - @Override - public void changeCursor(Cursor cursor) { - super.changeCursor(cursor); - calcNotesCount(); - } - - private void calcNotesCount() { - mNotesCount = 0; - for (int i = 0; i < getCount(); i++) { - Cursor c = (Cursor) getItem(i); - if (c != null) { - if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) { - mNotesCount++; - } - } else { - Log.e(TAG, "Invalid cursor"); - return; - } - } - } -} diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NotesListItem.java b/src/Notes-master/Notes-master/src/net/micode/notes/ui/NotesListItem.java deleted file mode 100644 index 1221e80..0000000 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NotesListItem.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.micode.notes.ui; - -import android.content.Context; -import android.text.format.DateUtils; -import android.view.View; -import android.widget.CheckBox; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import net.micode.notes.R; -import net.micode.notes.data.Notes; -import net.micode.notes.tool.DataUtils; -import net.micode.notes.tool.ResourceParser.NoteItemBgResources; - - -public class NotesListItem extends LinearLayout { - private ImageView mAlert; - private TextView mTitle; - private TextView mTime; - private TextView mCallName; - private NoteItemData mItemData; - private CheckBox mCheckBox; - - public NotesListItem(Context context) { - super(context); - inflate(context, R.layout.note_item, this); - mAlert = (ImageView) findViewById(R.id.iv_alert_icon); - mTitle = (TextView) findViewById(R.id.tv_title); - mTime = (TextView) findViewById(R.id.tv_time); - mCallName = (TextView) findViewById(R.id.tv_name); - mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); - } - - public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) { - if (choiceMode && data.getType() == Notes.TYPE_NOTE) { - mCheckBox.setVisibility(View.VISIBLE); - mCheckBox.setChecked(checked); - } else { - mCheckBox.setVisibility(View.GONE); - } - - mItemData = data; - if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) { - 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())); - mAlert.setImageResource(R.drawable.call_record); - } else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) { - mCallName.setVisibility(View.VISIBLE); - mCallName.setText(data.getCallName()); - mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem); - mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); - if (data.hasAlert()) { - mAlert.setImageResource(R.drawable.clock); - mAlert.setVisibility(View.VISIBLE); - } else { - mAlert.setVisibility(View.GONE); - } - } else { - mCallName.setVisibility(View.GONE); - mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); - - if (data.getType() == Notes.TYPE_FOLDER) { - mTitle.setText(data.getSnippet() - + context.getString(R.string.format_folder_files_count, - data.getNotesCount())); - mAlert.setVisibility(View.GONE); - } else { - mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); - if (data.hasAlert()) { - mAlert.setImageResource(R.drawable.clock); - mAlert.setVisibility(View.VISIBLE); - } else { - mAlert.setVisibility(View.GONE); - } - } - } - mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate())); - - setBackground(data); - } - - private void setBackground(NoteItemData data) { - int id = data.getBgColorId(); - 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()); - } - } - - public NoteItemData getItemData() { - return mItemData; - } -} diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NotesPreferenceActivity.java b/src/Notes-master/Notes-master/src/net/micode/notes/ui/NotesPreferenceActivity.java deleted file mode 100644 index 07c5f7e..0000000 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NotesPreferenceActivity.java +++ /dev/null @@ -1,388 +0,0 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.micode.notes.ui; - -import android.accounts.Account; -import android.accounts.AccountManager; -import android.app.ActionBar; -import android.app.AlertDialog; -import android.content.BroadcastReceiver; -import android.content.ContentValues; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.preference.Preference; -import android.preference.Preference.OnPreferenceClickListener; -import android.preference.PreferenceActivity; -import android.preference.PreferenceCategory; -import android.text.TextUtils; -import android.text.format.DateFormat; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; -import android.widget.Toast; - -import net.micode.notes.R; -import net.micode.notes.data.Notes; -import net.micode.notes.data.Notes.NoteColumns; -import net.micode.notes.gtask.remote.GTaskSyncService; - - -public class NotesPreferenceActivity extends PreferenceActivity { - public static final String PREFERENCE_NAME = "notes_preferences"; - - public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name"; - - public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time"; - - public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear"; - - private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key"; - - private static final String AUTHORITIES_FILTER_KEY = "authorities"; - - private PreferenceCategory mAccountCategory; - - private GTaskReceiver mReceiver; - - private Account[] mOriAccounts; - - private boolean mHasAddedAccount; - - @Override - protected void onCreate(Bundle icicle) { - super.onCreate(icicle); - - /* using the app icon for navigation */ - getActionBar().setDisplayHomeAsUpEnabled(true); - - addPreferencesFromResource(R.xml.preferences); - mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY); - mReceiver = new GTaskReceiver(); - IntentFilter filter = new IntentFilter(); - filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME); - registerReceiver(mReceiver, filter); - - mOriAccounts = null; - View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null); - getListView().addHeaderView(header, null, true); - } - - @Override - protected void onResume() { - super.onResume(); - - // need to set sync account automatically if user has added a new - // account - if (mHasAddedAccount) { - Account[] accounts = getGoogleAccounts(); - if (mOriAccounts != null && accounts.length > mOriAccounts.length) { - for (Account accountNew : accounts) { - boolean found = false; - for (Account accountOld : mOriAccounts) { - if (TextUtils.equals(accountOld.name, accountNew.name)) { - found = true; - break; - } - } - if (!found) { - setSyncAccount(accountNew.name); - break; - } - } - } - } - - refreshUI(); - } - - @Override - protected void onDestroy() { - if (mReceiver != null) { - unregisterReceiver(mReceiver); - } - super.onDestroy(); - } - - private void loadAccountPreference() { - mAccountCategory.removeAll(); - - Preference accountPref = new Preference(this); - final String defaultAccount = getSyncAccountName(this); - accountPref.setTitle(getString(R.string.preferences_account_title)); - accountPref.setSummary(getString(R.string.preferences_account_summary)); - accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { - public boolean onPreferenceClick(Preference preference) { - if (!GTaskSyncService.isSyncing()) { - if (TextUtils.isEmpty(defaultAccount)) { - // the first time to set account - showSelectAccountAlertDialog(); - } else { - // if the account has already been set, we need to promp - // user about the risk - showChangeAccountConfirmAlertDialog(); - } - } else { - Toast.makeText(NotesPreferenceActivity.this, - R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT) - .show(); - } - return true; - } - }); - - mAccountCategory.addPreference(accountPref); - } - - private void loadSyncButton() { - Button syncButton = (Button) findViewById(R.id.preference_sync_button); - TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview); - - // set button state - if (GTaskSyncService.isSyncing()) { - syncButton.setText(getString(R.string.preferences_button_sync_cancel)); - syncButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - GTaskSyncService.cancelSync(NotesPreferenceActivity.this); - } - }); - } else { - syncButton.setText(getString(R.string.preferences_button_sync_immediately)); - syncButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - GTaskSyncService.startSync(NotesPreferenceActivity.this); - } - }); - } - syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this))); - - // set last sync time - if (GTaskSyncService.isSyncing()) { - lastSyncTimeView.setText(GTaskSyncService.getProgressString()); - lastSyncTimeView.setVisibility(View.VISIBLE); - } else { - long lastSyncTime = getLastSyncTime(this); - if (lastSyncTime != 0) { - lastSyncTimeView.setText(getString(R.string.preferences_last_sync_time, - DateFormat.format(getString(R.string.preferences_last_sync_time_format), - lastSyncTime))); - lastSyncTimeView.setVisibility(View.VISIBLE); - } else { - lastSyncTimeView.setVisibility(View.GONE); - } - } - } - - private void refreshUI() { - loadAccountPreference(); - loadSyncButton(); - } - - private void showSelectAccountAlertDialog() { - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); - - View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null); - TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title); - titleTextView.setText(getString(R.string.preferences_dialog_select_account_title)); - TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle); - subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips)); - - dialogBuilder.setCustomTitle(titleView); - dialogBuilder.setPositiveButton(null, null); - - Account[] accounts = getGoogleAccounts(); - String defAccount = getSyncAccountName(this); - - mOriAccounts = accounts; - mHasAddedAccount = false; - - if (accounts.length > 0) { - CharSequence[] items = new CharSequence[accounts.length]; - final CharSequence[] itemMapping = items; - int checkedItem = -1; - int index = 0; - for (Account account : accounts) { - if (TextUtils.equals(account.name, defAccount)) { - checkedItem = index; - } - items[index++] = account.name; - } - dialogBuilder.setSingleChoiceItems(items, checkedItem, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - setSyncAccount(itemMapping[which].toString()); - dialog.dismiss(); - refreshUI(); - } - }); - } - - View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null); - dialogBuilder.setView(addAccountView); - - final AlertDialog dialog = dialogBuilder.show(); - addAccountView.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - mHasAddedAccount = true; - Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS"); - intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] { - "gmail-ls" - }); - startActivityForResult(intent, -1); - dialog.dismiss(); - } - }); - } - - private void showChangeAccountConfirmAlertDialog() { - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); - - View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null); - TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title); - titleTextView.setText(getString(R.string.preferences_dialog_change_account_title, - getSyncAccountName(this))); - TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle); - subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg)); - dialogBuilder.setCustomTitle(titleView); - - CharSequence[] menuItemArray = new CharSequence[] { - getString(R.string.preferences_menu_change_account), - getString(R.string.preferences_menu_remove_account), - getString(R.string.preferences_menu_cancel) - }; - dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - if (which == 0) { - showSelectAccountAlertDialog(); - } else if (which == 1) { - removeSyncAccount(); - refreshUI(); - } - } - }); - dialogBuilder.show(); - } - - private Account[] getGoogleAccounts() { - AccountManager accountManager = AccountManager.get(this); - return accountManager.getAccountsByType("com.google"); - } - - private void setSyncAccount(String account) { - if (!getSyncAccountName(this).equals(account)) { - SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = settings.edit(); - if (account != null) { - editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account); - } else { - editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, ""); - } - editor.commit(); - - // clean up last sync time - setLastSyncTime(this, 0); - - // clean up local gtask related info - new Thread(new Runnable() { - public void run() { - ContentValues values = new ContentValues(); - values.put(NoteColumns.GTASK_ID, ""); - values.put(NoteColumns.SYNC_ID, 0); - getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null); - } - }).start(); - - Toast.makeText(NotesPreferenceActivity.this, - getString(R.string.preferences_toast_success_set_accout, account), - Toast.LENGTH_SHORT).show(); - } - } - - private void removeSyncAccount() { - SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = settings.edit(); - if (settings.contains(PREFERENCE_SYNC_ACCOUNT_NAME)) { - editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME); - } - if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) { - editor.remove(PREFERENCE_LAST_SYNC_TIME); - } - editor.commit(); - - // clean up local gtask related info - new Thread(new Runnable() { - public void run() { - ContentValues values = new ContentValues(); - values.put(NoteColumns.GTASK_ID, ""); - values.put(NoteColumns.SYNC_ID, 0); - getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null); - } - }).start(); - } - - public static String getSyncAccountName(Context context) { - SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, - Context.MODE_PRIVATE); - return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, ""); - } - - public static void setLastSyncTime(Context context, long time) { - SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, - Context.MODE_PRIVATE); - SharedPreferences.Editor editor = settings.edit(); - editor.putLong(PREFERENCE_LAST_SYNC_TIME, time); - editor.commit(); - } - - public static long getLastSyncTime(Context context) { - SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, - Context.MODE_PRIVATE); - return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0); - } - - private class GTaskReceiver extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - refreshUI(); - if (intent.getBooleanExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_IS_SYNCING, false)) { - TextView syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview); - syncStatus.setText(intent - .getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG)); - } - - } - } - - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - Intent intent = new Intent(this, NotesListActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(intent); - return true; - default: - return false; - } - } -} diff --git a/src/assets/fonts/FZSTK.ttf b/src/assets/fonts/FZSTK.ttf new file mode 100644 index 0000000..407d370 Binary files /dev/null and b/src/assets/fonts/FZSTK.ttf differ diff --git a/src/assets/fonts/STXINGKA.ttf b/src/assets/fonts/STXINGKA.ttf new file mode 100644 index 0000000..53439a2 Binary files /dev/null and b/src/assets/fonts/STXINGKA.ttf differ diff --git a/src/assets/fonts/VINERITC.ttf b/src/assets/fonts/VINERITC.ttf new file mode 100644 index 0000000..5b7ebaa Binary files /dev/null and b/src/assets/fonts/VINERITC.ttf differ diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/data/Contact.java b/src/java/net/micode/notes/data/Contact.java similarity index 77% rename from src/Notes-master/Notes-master/src/net/micode/notes/data/Contact.java rename to src/java/net/micode/notes/data/Contact.java index d97ac5d..878fe67 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/data/Contact.java +++ b/src/java/net/micode/notes/data/Contact.java @@ -25,6 +25,15 @@ import android.util.Log; import java.util.HashMap; +/** + * + * @ProjectName: minode + * @Package: net.micode.notes.data + * @ClassName: Contact + * @Description: 该类实现建立联系人数据库的功能 + * @Author: 郑鲲鹏 + * @Date: 2023-12-16 17:57 + */ public class Contact { private static HashMap sContactCache; private static final String TAG = "Contact"; @@ -35,18 +44,29 @@ public class Contact { + "(SELECT raw_contact_id " + " FROM phone_lookup" + " WHERE min_match = '+')"; - + /** + * @method getContact + * @description 该方法用于识别电话号码对应的联系人 + * @date: 2023-12-16 19:24 + * @author: 郑鲲鹏 + * @return string + */ public static String getContact(Context context, String phoneNumber) { if(sContactCache == null) { sContactCache = new HashMap(); } + // 查找HashMap中是否有phoneNumber的信息 + // 2023-12-16 19:43 if(sContactCache.containsKey(phoneNumber)) { return sContactCache.get(phoneNumber); } String selection = CALLER_ID_SELECTION.replace("+", PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); + + // 查找数据库中phoneNumber的信息 + // 2023-12-16 19:43 Cursor cursor = context.getContentResolver().query( Data.CONTENT_URI, new String [] { Phone.DISPLAY_NAME }, @@ -54,6 +74,8 @@ public class Contact { new String[] { phoneNumber }, null); + // 检查是否查询到联系人,找到则将相关信息加入HashMap中,未找到则处理异常 + // 2023-12-16 19:41 if (cursor != null && cursor.moveToFirst()) { try { String name = cursor.getString(0); diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/data/Notes.java b/src/java/net/micode/notes/data/Notes.java similarity index 96% rename from src/Notes-master/Notes-master/src/net/micode/notes/data/Notes.java rename to src/java/net/micode/notes/data/Notes.java index f240604..d40776d 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/data/Notes.java +++ b/src/java/net/micode/notes/data/Notes.java @@ -33,7 +33,7 @@ public class Notes { public static final int ID_ROOT_FOLDER = 0; public static final int ID_TEMPARAY_FOLDER = -1; 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_BACKGROUND_ID = "net.micode.notes.background_color_id"; @@ -161,10 +161,16 @@ public class Notes { public static final String GTASK_ID = "gtask_id"; /** - * The version code - *

Type : INTEGER (long)

+ * the version code + *

type : integer (long)

*/ public static final String VERSION = "version"; + + /** + * set top state + *

type : integer (long)

+ */ + public static final String TOP = "top"; } public interface DataColumns { diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java b/src/java/net/micode/notes/data/NotesDatabaseHelper.java similarity index 96% rename from src/Notes-master/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java rename to src/java/net/micode/notes/data/NotesDatabaseHelper.java index ffe5d57..a96128b 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java +++ b/src/java/net/micode/notes/data/NotesDatabaseHelper.java @@ -30,7 +30,7 @@ import net.micode.notes.data.Notes.NoteColumns; public class NotesDatabaseHelper extends SQLiteOpenHelper { 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 static final String NOTE = "note"; @@ -60,7 +60,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," + NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," + 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 = @@ -322,6 +323,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { oldVersion++; } + if (oldVersion == 4) { + upgradeToV5(db); + oldVersion++; + } + if (reCreateTriggers) { reCreateNoteTableTriggers(db); reCreateDataTableTriggers(db); @@ -359,4 +365,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION + " 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"); + } } diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/data/NotesProvider.java b/src/java/net/micode/notes/data/NotesProvider.java similarity index 99% rename from src/Notes-master/Notes-master/src/net/micode/notes/data/NotesProvider.java rename to src/java/net/micode/notes/data/NotesProvider.java index edb0a60..8b23d6e 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/data/NotesProvider.java +++ b/src/java/net/micode/notes/data/NotesProvider.java @@ -48,6 +48,7 @@ public class NotesProvider extends ContentProvider { private static final int URI_DATA_ITEM = 4; private static final int URI_SEARCH = 5; + private static final int URI_SEARCH_SUGGEST = 6; static { diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/data/MetaData.java b/src/java/net/micode/notes/gtask/data/MetaData.java similarity index 100% rename from src/Notes-master/Notes-master/src/net/micode/notes/gtask/data/MetaData.java rename to src/java/net/micode/notes/gtask/data/MetaData.java diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/data/Node.java b/src/java/net/micode/notes/gtask/data/Node.java similarity index 100% rename from src/Notes-master/Notes-master/src/net/micode/notes/gtask/data/Node.java rename to src/java/net/micode/notes/gtask/data/Node.java diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/data/SqlData.java b/src/java/net/micode/notes/gtask/data/SqlData.java similarity index 100% rename from src/Notes-master/Notes-master/src/net/micode/notes/gtask/data/SqlData.java rename to src/java/net/micode/notes/gtask/data/SqlData.java diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/data/SqlNote.java b/src/java/net/micode/notes/gtask/data/SqlNote.java similarity index 100% rename from src/Notes-master/Notes-master/src/net/micode/notes/gtask/data/SqlNote.java rename to src/java/net/micode/notes/gtask/data/SqlNote.java diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/data/Task.java b/src/java/net/micode/notes/gtask/data/Task.java similarity index 100% rename from src/Notes-master/Notes-master/src/net/micode/notes/gtask/data/Task.java rename to src/java/net/micode/notes/gtask/data/Task.java diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/data/TaskList.java b/src/java/net/micode/notes/gtask/data/TaskList.java similarity index 100% rename from src/Notes-master/Notes-master/src/net/micode/notes/gtask/data/TaskList.java rename to src/java/net/micode/notes/gtask/data/TaskList.java diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/exception/ActionFailureException.java b/src/java/net/micode/notes/gtask/exception/ActionFailureException.java similarity index 100% rename from src/Notes-master/Notes-master/src/net/micode/notes/gtask/exception/ActionFailureException.java rename to src/java/net/micode/notes/gtask/exception/ActionFailureException.java diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/exception/NetworkFailureException.java b/src/java/net/micode/notes/gtask/exception/NetworkFailureException.java similarity index 99% rename from src/Notes-master/Notes-master/src/net/micode/notes/gtask/exception/NetworkFailureException.java rename to src/java/net/micode/notes/gtask/exception/NetworkFailureException.java index b08cfb1..437a55e 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/exception/NetworkFailureException.java +++ b/src/java/net/micode/notes/gtask/exception/NetworkFailureException.java @@ -15,7 +15,6 @@ */ package net.micode.notes.gtask.exception; - public class NetworkFailureException extends Exception { private static final long serialVersionUID = 2107610287180234136L; @@ -26,8 +25,7 @@ public class NetworkFailureException extends Exception { public NetworkFailureException(String paramString) { super(paramString); } - public NetworkFailureException(String paramString, Throwable paramThrowable) { super(paramString, paramThrowable); } -} +} \ No newline at end of file diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/remote/GTaskASyncTask.java b/src/java/net/micode/notes/gtask/remote/GTaskASyncTask.java similarity index 100% rename from src/Notes-master/Notes-master/src/net/micode/notes/gtask/remote/GTaskASyncTask.java rename to src/java/net/micode/notes/gtask/remote/GTaskASyncTask.java diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/remote/GTaskClient.java b/src/java/net/micode/notes/gtask/remote/GTaskClient.java similarity index 100% rename from src/Notes-master/Notes-master/src/net/micode/notes/gtask/remote/GTaskClient.java rename to src/java/net/micode/notes/gtask/remote/GTaskClient.java diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/remote/GTaskManager.java b/src/java/net/micode/notes/gtask/remote/GTaskManager.java similarity index 96% rename from src/Notes-master/Notes-master/src/net/micode/notes/gtask/remote/GTaskManager.java rename to src/java/net/micode/notes/gtask/remote/GTaskManager.java index d2b4082..74e5b7e 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/remote/GTaskManager.java +++ b/src/java/net/micode/notes/gtask/remote/GTaskManager.java @@ -47,7 +47,15 @@ import java.util.HashSet; import java.util.Iterator; 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 { 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 { int syncType; 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 { Cursor c = null; String gid; @@ -476,6 +498,13 @@ public class GTaskManager { 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 { if (mCancelled) { return; diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/remote/GTaskSyncService.java b/src/java/net/micode/notes/gtask/remote/GTaskSyncService.java similarity index 77% rename from src/Notes-master/Notes-master/src/net/micode/notes/gtask/remote/GTaskSyncService.java rename to src/java/net/micode/notes/gtask/remote/GTaskSyncService.java index cca36f7..6cd7f61 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/gtask/remote/GTaskSyncService.java +++ b/src/java/net/micode/notes/gtask/remote/GTaskSyncService.java @@ -22,7 +22,15 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; 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 final static String ACTION_STRING_NAME = "sync_action_type"; @@ -42,6 +50,13 @@ public class GTaskSyncService extends Service { private static String mSyncProgress = ""; + /** + * @method startSync + * @description 该方法用于开启Gtask备忘录同步工作 + * @date: 2023-12-17 23:42 + * @author: 郑鲲鹏 + * @return void + */ private void startSync() { if (mSyncTask == null) { mSyncTask = new GTaskASyncTask(this, new GTaskASyncTask.OnCompleteListener() { @@ -52,10 +67,19 @@ public class GTaskSyncService extends Service { } }); sendBroadcast(""); + // 使同步任务以单线程队列方式开启运行 + // 2023-12-17 23:46 mSyncTask.execute(); } } + /** + * @method cancelSync + * @description 该方法用于取消Gtask备忘录同步工作 + * @date: 2023-12-17 23:49 + * @author: 郑鲲鹏 + * @return void + */ private void cancelSync() { if (mSyncTask != null) { mSyncTask.cancelSync(); @@ -67,11 +91,20 @@ public class GTaskSyncService extends Service { mSyncTask = null; } + /** + * @method onStartCommand + * @description 该方法用于接受其他组件传递的消息使之重启GtaskSyncService + * @date: 2023-12-17 23:53 + * @author: 郑鲲鹏 + * @return int + */ @Override public int onStartCommand(Intent intent, int flags, int startId) { Bundle bundle = intent.getExtras(); if (bundle != null && bundle.containsKey(ACTION_STRING_NAME)) { switch (bundle.getInt(ACTION_STRING_NAME, ACTION_INVALID)) { + // 开始同步或取消同步 + // 2023-12-17 23:52 case ACTION_START_SYNC: startSync(); break; diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/model/Note.java b/src/java/net/micode/notes/model/Note.java similarity index 98% rename from src/Notes-master/Notes-master/src/net/micode/notes/model/Note.java rename to src/java/net/micode/notes/model/Note.java index 6706cf6..c3caaff 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/model/Note.java +++ b/src/java/net/micode/notes/model/Note.java @@ -70,6 +70,10 @@ public class Note { mNoteData = new NoteData(); } + public void setTopState(String key, int value) { + mNoteDiffValues.put(key, value); + } + public void setNoteValue(String key, String value) { mNoteDiffValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/model/WorkingNote.java b/src/java/net/micode/notes/model/WorkingNote.java similarity index 81% rename from src/Notes-master/Notes-master/src/net/micode/notes/model/WorkingNote.java rename to src/java/net/micode/notes/model/WorkingNote.java index be081e4..a42559b 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/model/WorkingNote.java +++ b/src/java/net/micode/notes/model/WorkingNote.java @@ -52,6 +52,8 @@ public class WorkingNote { private int mWidgetType; + private int mTop; + private long mFolderId; private Context mContext; @@ -78,7 +80,8 @@ public class WorkingNote { NoteColumns.BG_COLOR_ID, NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, - NoteColumns.MODIFIED_DATE + NoteColumns.MODIFIED_DATE, + NoteColumns.TOP }; 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_TOP_STATE_COLUMN = 6; + // New note construct private WorkingNote(Context context, long folderId) { mContext = context; @@ -111,6 +116,7 @@ public class WorkingNote { mNoteId = 0; mIsDeleted = false; mMode = 0; + mTop = 0; mWidgetType = Notes.TYPE_WIDGET_INVALIDE; } @@ -137,6 +143,7 @@ public class WorkingNote { mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN); mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN); mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN); + mTop = cursor.getInt(NOTE_TOP_STATE_COLUMN); } cursor.close(); } else { @@ -176,6 +183,14 @@ public class WorkingNote { public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, 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); note.setBgColorId(defaultBgColorId); note.setWidgetId(widgetId); @@ -187,16 +202,24 @@ public class WorkingNote { return new WorkingNote(context, id, 0); } - public synchronized boolean saveNote() { - if (isWorthSaving()) { - if (!existInDatabase()) { + public synchronized boolean saveNote() {// TODO: 2023/12/19 要仔细溯源看看 + /** + * @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) { Log.e(TAG, "Create new note fail with id:" + mNoteId); 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 @@ -208,7 +231,7 @@ public class WorkingNote { } return true; } else { - return false; + return false; // 没有需要保存的,就返回false @zhoukexing 2023/12/19 23:46 } } @@ -225,20 +248,56 @@ public class WorkingNote { } } + /** + * @method: setOnSettingStatusChangedListener + * @description: 将工作目录里的NoteEditActivity项设置为NoteSettingChangedListener + * @date: 2023/12/21 0:10 + * @author: zhoukexing + * @param: [l] NoteEditActivity + * @return: void + */ public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { + //Q: 这里的l是怎么获取的。l是NoteEditActivity @zkx 2023/12/21 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) { + // 更新便签项中的提醒日期 if (date != mAlertDate) { mAlertDate = date; mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate)); } + // 设置提醒的监听事件 if (mNoteSettingStatusListener != null) { mNoteSettingStatusListener.onClockAlertChanged(date, set); } } - + /** + * @method: markDeleted + * @description: 描述一下方法的作用 + * @date: 2023/12/21 0:50 + * @author: zhoukexing + * @param: [mark] + * @return: void + */ public void markDeleted(boolean mark) { mIsDeleted = mark; if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID diff --git a/src/java/net/micode/notes/tool/BackupUtils.java b/src/java/net/micode/notes/tool/BackupUtils.java new file mode 100644 index 0000000..32eb5af --- /dev/null +++ b/src/java/net/micode/notes/tool/BackupUtils.java @@ -0,0 +1,329 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package net.micode.notes.tool; + + public class BackupUtils { + private static final String TAG = "BackupUtils"; + // Singleton stuff + private static BackupUtils sInstance; //类里面为什么可以定义自身类的对象? + + public static synchronized BackupUtils getInstance(Context context) { + //ynchronized 关键字,代表这个方法加锁,相当于不管哪一个线程(例如线程A) + //运行到这个方法时,都要检查有没有其它线程B(或者C、 D等)正在用这个方法(或者该类的其他同步方法),有的话要等正在使用synchronized方法的线程B(或者C 、D)运行完这个方法后再运行此线程A,没有的话,锁定调用者,然后直接运行。 + //它包括两种用法:synchronized 方法和 synchronized 块。 + if (sInstance == null) { + //如果当前备份不存在,则新声明一个 + sInstance = new BackupUtils(context); + } + return sInstance; + } + + /** + * Following states are signs to represents backup or restore + * status + */ + // Currently, the sdcard is not mounted SD卡没有被装入手机 + public static final int STATE_SD_CARD_UNMOUONTED = 0; + // The backup file not exist 备份文件夹不存在 + public static final int STATE_BACKUP_FILE_NOT_EXIST = 1; + // The data is not well formated, may be changed by other programs 数据已被破坏,可能被修改 + public static final int STATE_DATA_DESTROIED = 2; + // Some run-time exception which causes restore or backup fails 超时异常 + public static final int STATE_SYSTEM_ERROR = 3; + // Backup or restore success 成功存储 + public static final int STATE_SUCCESS = 4; + + private TextExport mTextExport; + + private BackupUtils(Context context) { //初始化函数 + mTextExport = new TextExport(context); + } + + private static boolean externalStorageAvailable() { //外部存储功能是否可用 + return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); + } + + public int exportToText() { + return mTextExport.exportToText(); + } + + public String getExportedTextFileName() { + return mTextExport.mFileName; + } + + public String getExportedTextFileDir() { + return mTextExport.mFileDirectory; + } + + private static class TextExport { + private static final String[] NOTE_PROJECTION = { + NoteColumns.ID, + NoteColumns.MODIFIED_DATE, + NoteColumns.SNIPPET, + NoteColumns.TYPE + }; + + private static final int NOTE_COLUMN_ID = 0; + + private static final int NOTE_COLUMN_MODIFIED_DATE = 1; + + private static final int NOTE_COLUMN_SNIPPET = 2; + + private static final String[] DATA_PROJECTION = { + DataColumns.CONTENT, + DataColumns.MIME_TYPE, + DataColumns.DATA1, + DataColumns.DATA2, + DataColumns.DATA3, + DataColumns.DATA4, + }; + + private static final int DATA_COLUMN_CONTENT = 0; + + private static final int DATA_COLUMN_MIME_TYPE = 1; + + private static final int DATA_COLUMN_CALL_DATE = 2; + + private static final int DATA_COLUMN_PHONE_NUMBER = 4; + + private final String [] TEXT_FORMAT; + private static final int FORMAT_FOLDER_NAME = 0; + private static final int FORMAT_NOTE_DATE = 1; + private static final int FORMAT_NOTE_CONTENT = 2; + + private Context mContext; + private String mFileName; + private String mFileDirectory; + + public TextExport(Context context) { + TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); + mContext = context; + mFileName = ""; //为什么为空? + mFileDirectory = ""; + } + + private String getFormat(int id) { //获取文本的组成部分 + return TEXT_FORMAT[id]; + } + + /** + * Export the folder identified by folder id to text + */ + private void exportFolderToText(String folderId, PrintStream ps) { + // Query notes belong to this folder 通过查询parent id是文件夹id的note来选出制定ID文件夹下的Note + Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI, + NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] { + folderId + }, null); + + if (notesCursor != null) { + if (notesCursor.moveToFirst()) { + do { + // Print note's last modified date ps里面保存有这份note的日期 + ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( + mContext.getString(R.string.format_datetime_mdhm), + notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); + // Query data belong to this note + String noteId = notesCursor.getString(NOTE_COLUMN_ID); + exportNoteToText(noteId, ps); //将文件导出到text + } while (notesCursor.moveToNext()); + } + notesCursor.close(); + } + } + + /** + * Export note identified by id to a print stream + */ + private void exportNoteToText(String noteId, PrintStream ps) { + Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, + DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { + noteId + }, null); + + if (dataCursor != null) { //利用光标来扫描内容,区别为callnote和note两种,靠ps.printline输出 + if (dataCursor.moveToFirst()) { + do { + String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE); + if (DataConstants.CALL_NOTE.equals(mimeType)) { + // Print phone number + String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER); + long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE); + String location = dataCursor.getString(DATA_COLUMN_CONTENT); + + if (!TextUtils.isEmpty(phoneNumber)) { //判断是否为空字符 + ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), + phoneNumber)); + } + // Print call date + ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat + .format(mContext.getString(R.string.format_datetime_mdhm), + callDate))); + // Print call attachment location + if (!TextUtils.isEmpty(location)) { + ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), + location)); + } + } else if (DataConstants.NOTE.equals(mimeType)) { + String content = dataCursor.getString(DATA_COLUMN_CONTENT); + if (!TextUtils.isEmpty(content)) { + ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), + content)); + } + } + } while (dataCursor.moveToNext()); + } + dataCursor.close(); + } + // print a line separator between note + try { + ps.write(new byte[] { + Character.LINE_SEPARATOR, Character.LETTER_NUMBER + }); + } catch (IOException e) { + Log.e(TAG, e.toString()); + } + } + + /** + * Note will be exported as text which is user readable + */ + public int exportToText() { //总函数,调用上面的exportFolder和exportNote + if (!externalStorageAvailable()) { + Log.d(TAG, "Media was not mounted"); + return STATE_SD_CARD_UNMOUONTED; + } + + PrintStream ps = getExportToTextPrintStream(); + if (ps == null) { + Log.e(TAG, "get print stream error"); + return STATE_SYSTEM_ERROR; + } + // First export folder and its notes 导出文件夹,就是导出里面包含的便签 + Cursor folderCursor = mContext.getContentResolver().query( + Notes.CONTENT_NOTE_URI, + NOTE_PROJECTION, + "(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND " + + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR " + + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null); + + if (folderCursor != null) { + if (folderCursor.moveToFirst()) { + do { + // Print folder's name + String folderName = ""; + if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) { + folderName = mContext.getString(R.string.call_record_folder_name); + } else { + folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET); + } + if (!TextUtils.isEmpty(folderName)) { + ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName)); + } + String folderId = folderCursor.getString(NOTE_COLUMN_ID); + exportFolderToText(folderId, ps); + } while (folderCursor.moveToNext()); + } + folderCursor.close(); + } + + // Export notes in root's folder 将根目录里的便签导出(由于不属于任何文件夹,因此无法通过文件夹导出来实现这一部分便签的导出) + Cursor noteCursor = mContext.getContentResolver().query( + Notes.CONTENT_NOTE_URI, + NOTE_PROJECTION, + NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID + + "=0", null, null); + + if (noteCursor != null) { + if (noteCursor.moveToFirst()) { + do { + ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( + mContext.getString(R.string.format_datetime_mdhm), + noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); + // Query data belong to this note + String noteId = noteCursor.getString(NOTE_COLUMN_ID); + exportNoteToText(noteId, ps); + } while (noteCursor.moveToNext()); + } + noteCursor.close(); + } + ps.close(); + + return STATE_SUCCESS; + } + + /** + * Get a print stream pointed to the file {@generateExportedTextFile} + */ + private PrintStream getExportToTextPrintStream() { + File file = generateFileMountedOnSDcard(mContext, R.string.file_path, + R.string.file_name_txt_format); + if (file == null) { + Log.e(TAG, "create file to exported failed"); + return null; + } + mFileName = file.getName(); + mFileDirectory = mContext.getString(R.string.file_path); + PrintStream ps = null; + try { + FileOutputStream fos = new FileOutputStream(file); + ps = new PrintStream(fos); //将ps输出流输出到特定的文件,目的就是导出到文件,而不是直接输出 + } catch (FileNotFoundException e) { + e.printStackTrace(); + return null; + } catch (NullPointerException e) { + e.printStackTrace(); + return null; + } + return ps; + } + } + + /** + * Generate the text file to store imported data + */ + private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { + StringBuilder sb = new StringBuilder(); + sb.append(Environment.getExternalStorageDirectory()); //外部(SD卡)的存储路径 + sb.append(context.getString(filePathResId)); //文件的存储路径 + File filedir = new File(sb.toString()); //filedir应该就是用来存储路径信息 + sb.append(context.getString( + fileNameFormatResId, + DateFormat.format(context.getString(R.string.format_date_ymd), + System.currentTimeMillis()))); + File file = new File(sb.toString()); + + try { //如果这些文件不存在,则新建 + if (!filedir.exists()) { + filedir.mkdir(); + } + if (!file.exists()) { + file.createNewFile(); + } + return file; + } catch (SecurityException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + // try catch 异常处理 + return null; + } + } + + + diff --git a/src/java/net/micode/notes/tool/DataUtils.java b/src/java/net/micode/notes/tool/DataUtils.java new file mode 100644 index 0000000..a9c6a48 --- /dev/null +++ b/src/java/net/micode/notes/tool/DataUtils.java @@ -0,0 +1,385 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*该类定义在 net.micode.notes.tool 包下,并导入了Android和Java的一些核心类。这些导入的类提供了对内容提供者操作、日志记录、游标以及存储值的支持。 */ +package net.micode.notes.tool; +/*定义了一个公共类 DataUtils,并创建了一个常量 TAG 用于日志记录。 */ +import android.content.ContentProviderOperation; +import android.content.ContentProviderResult; +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.OperationApplicationException; +import android.database.Cursor; +import android.os.RemoteException; +import android.util.Log; + +import net.micode.notes.data.Notes; +import net.micode.notes.data.Notes.CallNote; +import net.micode.notes.data.Notes.NoteColumns; +import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; + +import java.util.ArrayList; +import java.util.HashSet; + +/*这个方法实现了根据一组ID批量删除笔记的功能。 +它首先检查ID集合是否为空,并创建一个操作列表。 +通过 ContentResolver 执行删除操作,成功后返回 true,失败则返回 false。 */ +public class DataUtils { + public static final String TAG = "DataUtils"; + public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) { + if (ids == null) { + Log.d(TAG, "the ids is null"); + return true; + } + if (ids.size() == 0) { + Log.d(TAG, "no id is in the hashset"); + return true; + } + + ArrayList operationList = new ArrayList(); + for (long id : ids) { + if(id == Notes.ID_ROOT_FOLDER) { + Log.e(TAG, "Don't delete system folder root"); + continue; + } + ContentProviderOperation.Builder builder = ContentProviderOperation + .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); + operationList.add(builder.build()); + } + try { + ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); + if (results == null || results.length == 0 || results[0] == null) { + Log.d(TAG, "delete notes failed, ids:" + ids.toString()); + return false; + } + return true; + } catch (RemoteException e) { + Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); + } catch (OperationApplicationException e) { + Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); + } + return false; + } +/*此方法将指定的笔记移动到目标文件夹。 +更新笔记的父文件夹ID并标记为本地修改。 */ +/*查询非系统文件夹的数量。异常处理用于确保在查询失败时释放游标资源。 */ + public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) { + ContentValues values = new ContentValues(); + values.put(NoteColumns.PARENT_ID, desFolderId); + values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId); + values.put(NoteColumns.LOCAL_MODIFIED, 1); + resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); + } + + /** + * @method: batchMoveToFolder + * @description: 将ids里标注的文件移至folderId指定的文件夹 + * @date: 2024/12/26 3:32 + * @author: zhoukexing + * @param: [resolver, ids, folderId] + * @return: boolean + */ + /*检查数据库中是否存在特定类型的可见笔记。 */ +/** + * 批量将便签移动到指定文件夹 + * @param resolver ContentResolver对象 + * @param ids 需要移动的便签ID集合 + * @param folderId 目标文件夹ID + * @return 是否移动成功 + */ +public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, long folderId) { + if (ids == null) { + Log.d(TAG, "the ids is null"); + return true; + } + + ArrayList operationList = new ArrayList(); + for (long id : ids) { + ContentProviderOperation.Builder builder = ContentProviderOperation + .newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); + builder.withValue(NoteColumns.PARENT_ID, folderId); + builder.withValue(NoteColumns.LOCAL_MODIFIED, 1); + operationList.add(builder.build()); + } + + try { + ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); + if (results == null || results.length == 0 || results[0] == null) { + Log.d(TAG, "delete notes failed, ids:" + ids.toString()); + return false; + } + return true; + } catch (RemoteException e) { + Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); + } catch (OperationApplicationException e) { + Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); + } + return false; +} + +/** + * 获取用户文件夹的数量(不包括系统文件夹) + * @param resolver ContentResolver对象 + * @return 用户文件夹的数量 + */ +public static int getUserFolderCount(ContentResolver resolver) { + Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI, + new String[] { "COUNT(*)" }, + NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?", + new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)}, + null); + + int count = 0; + if(cursor != null) { + if(cursor.moveToFirst()) { + try { + count = cursor.getInt(0); + } catch (IndexOutOfBoundsException e) { + Log.e(TAG, "get folder count failed:" + e.toString()); + } finally { + cursor.close(); + } + } + } + return count; +} + +/** + * 检查数据库中是否存在指定ID和类型的便签 + * @param resolver ContentResolver对象 + * @param noteId 便签ID + * @param type 便签类型 + * @return 是否存在 + */ +public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { + Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), + null, + NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER, + new String [] {String.valueOf(type)}, + null); + + boolean exist = false; + if (cursor != null) { + if (cursor.getCount() > 0) { + exist = true; + } + cursor.close(); + } + return exist; +} + +/** + * 检查数据库中是否存在指定ID的便签 + * @param resolver ContentResolver对象 + * @param noteId 便签ID + * @return 是否存在 + */ +public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) { + Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), + null, null, null, null); + + boolean exist = false; + if (cursor != null) { + if (cursor.getCount() > 0) { + exist = true; + } + cursor.close(); + } + return exist; +} + +/** + * 检查数据库中是否存在指定ID的数据 + * @param resolver ContentResolver对象 + * @param dataId 数据ID + * @return 是否存在 + */ +public static boolean existInDataDatabase(ContentResolver resolver, long dataId) { + Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), + null, null, null, null); + + boolean exist = false; + if (cursor != null) { + if (cursor.getCount() > 0) { + exist = true; + } + cursor.close(); + } + return exist; +} + +/** + * 检查数据库中是否存在指定名称的可见文件夹 + * @param resolver ContentResolver对象 + * @param name 文件夹名称 + * @return 是否存在 + */ +public static boolean checkVisibleFolderName(ContentResolver resolver, String name) { + Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null, + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + + " AND " + NoteColumns.SNIPPET + "=?", + new String[] { name }, null); + boolean exist = false; + if(cursor != null) { + if(cursor.getCount() > 0) { + exist = true; + } + cursor.close(); + } + return exist; +} + +/** + * 获取指定文件夹中的小部件属性集合 + * @param resolver ContentResolver对象 + * @param folderId 文件夹ID + * @return 小部件属性集合 + */ +public static HashSet getFolderNoteWidget(ContentResolver resolver, long folderId) { + Cursor c = resolver.query(Notes.CONTENT_NOTE_URI, + new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, + NoteColumns.PARENT_ID + "=?", + new String[] { String.valueOf(folderId) }, + null); + + HashSet set = null; + if (c != null) { + if (c.moveToFirst()) { + set = new HashSet(); + do { + try { + AppWidgetAttribute widget = new AppWidgetAttribute(); + widget.widgetId = c.getInt(0); + widget.widgetType = c.getInt(1); + set.add(widget); + } catch (IndexOutOfBoundsException e) { + Log.e(TAG, e.toString()); + } + } while (c.moveToNext()); + } + c.close(); + } + return set; +} + +/** + * 根据便签ID获取电话号码 + * @param resolver ContentResolver对象 + * @param noteId 便签ID + * @return 电话号码 + */ +public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { + Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, + new String [] { CallNote.PHONE_NUMBER }, + CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?", + new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE }, + null); + + if (cursor != null && cursor.moveToFirst()) { + try { + return cursor.getString(0); + } catch (IndexOutOfBoundsException e) { + Log.e(TAG, "Get call number fails " + e.toString()); + } finally { + cursor.close(); + } + } + return ""; +} + +/** + * 根据电话号码和通话日期获取便签ID + * @param resolver ContentResolver对象 + * @param phoneNumber 电话号码 + * @param callDate 通话日期 + * @return 便签ID + */ +public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) { + Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, + new String [] { CallNote.NOTE_ID }, + CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL(" + + CallNote.PHONE_NUMBER + ",?)", + new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber }, + null); + + if (cursor != null) { + if (cursor.moveToFirst()) { + try { + return cursor.getLong(0); + } catch (IndexOutOfBoundsException e) { + Log.e(TAG, "Get call note id fails " + e.toString()); + } + } + cursor.close(); + } + return 0; +} + +/** + * 根据便签ID获取便签摘要 + * @param resolver ContentResolver对象 + * @param noteId 便签ID + * @return 便签摘要 + */ +public static String getSnippetById(ContentResolver resolver, long noteId) { + Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, + new String [] { NoteColumns.SNIPPET }, + NoteColumns.ID + "=?", + new String [] { String.valueOf(noteId)}, + null); + + if (cursor != null) { + String snippet = ""; + if (cursor.moveToFirst()) { + snippet = cursor.getString(0); + } + cursor.close(); + return snippet; + } + throw new IllegalArgumentException("Note is not found with id: " + noteId); +} + +/** + * 格式化便签摘要 + * @param snippet 便签摘要 + * @return 格式化后的便签摘要 + */ +public static String getFormattedSnippet(String snippet) { + if (snippet != null) { + snippet = snippet.trim(); + int index = snippet.indexOf('\n'); + if (index != -1) { + snippet = snippet.substring(0, index); + } + } + return snippet; +} + +/** + * 在数据库中搜索包含指定查询内容的便签 + * @param resolver ContentResolver对象 + * @param query 查询内容 + * @return 包含查询结果的Cursor对象 + */ +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; +} \ No newline at end of file diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java b/src/java/net/micode/notes/tool/GTaskStringUtils.java similarity index 98% rename from src/Notes-master/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java rename to src/java/net/micode/notes/tool/GTaskStringUtils.java index 666b729..694d849 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java +++ b/src/java/net/micode/notes/tool/GTaskStringUtils.java @@ -16,6 +16,7 @@ package net.micode.notes.tool; +// 该类用于定义 Google 任务相关的 JSON 字段常量 public class GTaskStringUtils { public final static String GTASK_JSON_ACTION_ID = "action_id"; @@ -110,4 +111,4 @@ public class GTaskStringUtils { public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; -} +} \ No newline at end of file diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/tool/ResourceParser.java b/src/java/net/micode/notes/tool/ResourceParser.java similarity index 90% rename from src/Notes-master/Notes-master/src/net/micode/notes/tool/ResourceParser.java rename to src/java/net/micode/notes/tool/ResourceParser.java index 1ad3ad6..0fc6a61 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/tool/ResourceParser.java +++ b/src/java/net/micode/notes/tool/ResourceParser.java @@ -22,6 +22,7 @@ import android.preference.PreferenceManager; import net.micode.notes.R; import net.micode.notes.ui.NotesPreferenceActivity; +// 资源解析器类 public class ResourceParser { public static final int YELLOW = 0; @@ -37,8 +38,10 @@ public class ResourceParser { public static final int TEXT_LARGE = 2; public static final int TEXT_SUPER = 3; + public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; + // 备忘录背景资源类 public static class NoteBgResources { private final static int [] BG_EDIT_RESOURCES = new int [] { R.drawable.edit_yellow, @@ -56,15 +59,18 @@ public class ResourceParser { R.drawable.edit_title_red }; + // 获取备忘录背景资源 public static int getNoteBgResource(int id) { return BG_EDIT_RESOURCES[id]; } + // 获取备忘录标题背景资源 public static int getNoteTitleBgResource(int id) { return BG_EDIT_TITLE_RESOURCES[id]; } } + // 获取默认背景ID public static int getDefaultBgId(Context context) { if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) { @@ -74,6 +80,7 @@ public class ResourceParser { } } + // 备忘录项目背景资源类 public static class NoteItemBgResources { private final static int [] BG_FIRST_RESOURCES = new int [] { R.drawable.list_yellow_up, @@ -107,27 +114,33 @@ public class ResourceParser { R.drawable.list_red_single }; + // 获取备忘录第一个背景资源 public static int getNoteBgFirstRes(int id) { return BG_FIRST_RESOURCES[id]; } + // 获取备忘录最后一个背景资源 public static int getNoteBgLastRes(int id) { return BG_LAST_RESOURCES[id]; } + // 获取备忘录单独背景资源 public static int getNoteBgSingleRes(int id) { return BG_SINGLE_RESOURCES[id]; } + // 获取备忘录正常背景资源 public static int getNoteBgNormalRes(int id) { return BG_NORMAL_RESOURCES[id]; } + // 获取文件夹背景资源 public static int getFolderBgRes() { return R.drawable.list_folder; } } + // 小部件背景资源类 public static class WidgetBgResources { private final static int [] BG_2X_RESOURCES = new int [] { R.drawable.widget_2x_yellow, @@ -137,6 +150,7 @@ public class ResourceParser { R.drawable.widget_2x_red, }; + // 获取2x小部件背景资源 public static int getWidget2xBgResource(int id) { return BG_2X_RESOURCES[id]; } @@ -149,11 +163,13 @@ public class ResourceParser { R.drawable.widget_4x_red }; + // 获取4x小部件背景资源 public static int getWidget4xBgResource(int id) { return BG_4X_RESOURCES[id]; } } + // 文本外观资源类 public static class TextAppearanceResources { private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] { R.style.TextAppearanceNormal, @@ -162,6 +178,7 @@ public class ResourceParser { R.style.TextAppearanceSuper }; + // 获取文本外观资源 public static int getTexAppearanceResource(int id) { /** * HACKME: Fix bug of store the resource id in shared preference. @@ -174,8 +191,9 @@ public class ResourceParser { return TEXTAPPEARANCE_RESOURCES[id]; } + // 获取资源大小 public static int getResourcesSize() { return TEXTAPPEARANCE_RESOURCES.length; } } -} +} \ No newline at end of file diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/AlarmAlertActivity.java b/src/java/net/micode/notes/ui/AlarmAlertActivity.java similarity index 65% rename from src/Notes-master/Notes-master/src/net/micode/notes/ui/AlarmAlertActivity.java rename to src/java/net/micode/notes/ui/AlarmAlertActivity.java index 85723be..a124eed 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/AlarmAlertActivity.java +++ b/src/java/net/micode/notes/ui/AlarmAlertActivity.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// 导入必要的类和接口 package net.micode.notes.ui; import android.app.Activity; @@ -39,61 +40,85 @@ import net.micode.notes.tool.DataUtils; import java.io.IOException; - +// AlarmAlertActivity类,继承自Activity,实现OnClickListener和OnDismissListener接口 public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener { - private long mNoteId; - private String mSnippet; + private long mNoteId; //文本在数据库存储中的ID号 + private String mSnippet; //闹钟提示时出现的文本片段 private static final int SNIPPET_PREW_MAX_LEN = 60; MediaPlayer mPlayer; - + @Override - protected void onCreate(Bundle savedInstanceState) { + protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + //Bundle类型的数据与Map类型的数据相似,都是以key-value的形式存储数据的 + //onsaveInstanceState方法是用来保存Activity的状态的 + //能从onCreate的参数savedInsanceState中获得状态数据 requestWindowFeature(Window.FEATURE_NO_TITLE); - + //界面显示——无标题 + final Window win = getWindow(); win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); - + if (!isScreenOn()) { win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON + //保持窗体点亮 | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON + //将窗体点亮 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON + //允许窗体点亮时锁屏 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR); - } - + }//在手机锁屏后如果到了闹钟提示时间,点亮屏幕 + Intent intent = getIntent(); - + try { mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1)); mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId); + //根据ID从数据库中获取标签的内容; + //getContentResolver()是实现数据共享,实例存储。 mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0, SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info) : mSnippet; + //判断标签片段是否达到符合长度 } catch (IllegalArgumentException e) { e.printStackTrace(); return; } - + /* + try + { + // 代码区 + } + catch(Exception e) + { + // 异常处理 + } + 代码区如果有错误,就会返回所写异常的处理。*/ mPlayer = new MediaPlayer(); if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) { showActionDialog(); + //弹出对话框 playAlarmSound(); + //闹钟提示音激发 } else { finish(); + //完成闹钟动作 } } - + private boolean isScreenOn() { + //判断屏幕是否锁屏,调用系统函数判断,最后返回值是布尔类型 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); return pm.isScreenOn(); } - + private void playAlarmSound() { + //闹钟提示音激发 Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM); - + //调用系统的铃声管理URI,得到闹钟提示音 int silentModeStreams = Settings.System.getInt(getContentResolver(), Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0); - + if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) { mPlayer.setAudioStreamType(silentModeStreams); } else { @@ -101,12 +126,19 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD } try { mPlayer.setDataSource(this, url); + //方法:setDataSource(Context context, Uri uri) + //解释:无返回值,设置多媒体数据来源【根据 Uri】 mPlayer.prepare(); + //准备同步 mPlayer.setLooping(true); + //设置是否循环播放 mPlayer.start(); + //开始播放 } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); + //e.printStackTrace()函数功能是抛出异常, 还将显示出更深的调用信息 + //System.out.println(e),这个方法打印出异常,并且输出在哪里出现的异常 } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -118,41 +150,61 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD e.printStackTrace(); } } - + private void showActionDialog() { AlertDialog.Builder dialog = new AlertDialog.Builder(this); + //AlertDialog的构造方法全部是Protected的 + //所以不能直接通过new一个AlertDialog来创建出一个AlertDialog。 + //要创建一个AlertDialog,就要用到AlertDialog.Builder中的create()方法 + //如这里的dialog就是新建了一个AlertDialog dialog.setTitle(R.string.app_name); + //为对话框设置标题 dialog.setMessage(mSnippet); + //为对话框设置内容 dialog.setPositiveButton(R.string.notealert_ok, this); + //给对话框添加"Yes"按钮 if (isScreenOn()) { dialog.setNegativeButton(R.string.notealert_enter, this); - } + }//对话框添加"No"按钮 dialog.show().setOnDismissListener(this); } - + public void onClick(DialogInterface dialog, int which) { switch (which) { + //用which来选择click后下一步的操作 case DialogInterface.BUTTON_NEGATIVE: + //这是取消操作 Intent intent = new Intent(this, NoteEditActivity.class); + //实现两个类间的数据传输 intent.setAction(Intent.ACTION_VIEW); + //设置动作属性 intent.putExtra(Intent.EXTRA_UID, mNoteId); + //实现key-value对 + //EXTRA_UID为key;mNoteId为键 startActivity(intent); + //开始动作 break; default: + //这是确定操作 break; } } - + public void onDismiss(DialogInterface dialog) { + //忽略 stopAlarmSound(); + //停止闹钟声音 finish(); + //完成该动作 } - + private void stopAlarmSound() { if (mPlayer != null) { mPlayer.stop(); + //停止播放 mPlayer.release(); + //释放MediaPlayer对象 mPlayer = null; } } -} +} \ No newline at end of file diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/AlarmInitReceiver.java b/src/java/net/micode/notes/ui/AlarmInitReceiver.java similarity index 53% rename from src/Notes-master/Notes-master/src/net/micode/notes/ui/AlarmInitReceiver.java rename to src/java/net/micode/notes/ui/AlarmInitReceiver.java index f221202..0a023c7 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/AlarmInitReceiver.java +++ b/src/java/net/micode/notes/ui/AlarmInitReceiver.java @@ -30,36 +30,60 @@ import net.micode.notes.data.Notes.NoteColumns; public class AlarmInitReceiver extends BroadcastReceiver { + // 定义查询数据库时要获取的列 private static final String [] PROJECTION = new String [] { - NoteColumns.ID, - NoteColumns.ALERTED_DATE + NoteColumns.ID, // 笔记的ID + NoteColumns.ALERTED_DATE // 笔记的提醒日期 }; + // 定义列的索引,以便在Cursor中快速访问 private static final int COLUMN_ID = 0; private static final int COLUMN_ALERTED_DATE = 1; @Override public void onReceive(Context context, Intent intent) { - long currentDate = System.currentTimeMillis(); + long currentDate = System.currentTimeMillis(); // 获取当前的系统时间(毫秒) + + // 从内容提供者中查询需要提醒的笔记 + // Notes.CONTENT_NOTE_URI 是内容提供者的URI + // PROJECTION 指定了要查询的列 + // 查询条件是提醒日期大于当前日期,且笔记类型为普通笔记(Notes.TYPE_NOTE) Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI, PROJECTION, NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE, - new String[] { String.valueOf(currentDate) }, - null); + new String[] { String.valueOf(currentDate) }, // 查询参数,这里只有当前日期 + null); // 不需要排序 + // 检查Cursor是否为null if (c != null) { + // 如果Cursor不为空,移动到第一条记录 if (c.moveToFirst()) { + // 开始遍历Cursor中的所有记录 do { + // 获取当前笔记的提醒日期 long alertDate = c.getLong(COLUMN_ALERTED_DATE); + + // 创建一个Intent,目标组件是AlarmReceiver Intent sender = new Intent(context, AlarmReceiver.class); + + // 为Intent设置数据URI,这里使用ContentUris.withAppendedId方法将笔记ID附加到Notes的内容URI上 sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID))); + + // 创建一个PendingIntent,这里使用getBroadcast方法,因为AlarmReceiver是一个BroadcastReceiver + // 注意:这里使用的请求码(第二个参数)为0,这可能导致如果有多个相同的Intent被发送时,PendingIntent会被覆盖 PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0); - AlarmManager alermManager = (AlarmManager) context - .getSystemService(Context.ALARM_SERVICE); + + // 获取AlarmManager服务 + AlarmManager alermManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + + // 设置一个闹钟,当到达提醒日期时,触发PendingIntent(即发送广播给AlarmReceiver) + // AlarmManager.RTC_WAKEUP表示在指定时间唤醒设备并发送广播 alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent); - } while (c.moveToNext()); + + } while (c.moveToNext()); // 移动到下一条记录,继续循环 } + // 关闭Cursor c.close(); } } -} +} \ No newline at end of file diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/AlarmReceiver.java b/src/java/net/micode/notes/ui/AlarmReceiver.java similarity index 50% rename from src/Notes-master/Notes-master/src/net/micode/notes/ui/AlarmReceiver.java rename to src/java/net/micode/notes/ui/AlarmReceiver.java index 54e503b..53e46fa 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/AlarmReceiver.java +++ b/src/java/net/micode/notes/ui/AlarmReceiver.java @@ -14,17 +14,30 @@ * limitations under the License. */ +// 指定类所在的包名 package net.micode.notes.ui; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; +// 导入所需的类 +import android.content.BroadcastReceiver; // 广播接收器基类 +import android.content.Context; // 提供应用环境信息的类 +import android.content.Intent; // 用于组件间通信的消息传递对象 +// 定义一个公开类AlarmReceiver,它继承自BroadcastReceiver public class AlarmReceiver extends BroadcastReceiver { + + // 重写onReceive方法,当接收到广播时调用此方法 @Override public void onReceive(Context context, Intent intent) { + // 设置intent的目标组件为AlarmAlertActivity类 + // 这意味着当这个广播接收器接收到广播时,它希望启动AlarmAlertActivity活动 intent.setClass(context, AlarmAlertActivity.class); + + // 为intent添加FLAG_ACTIVITY_NEW_TASK标志 + // 这通常用于从非活动上下文中启动活动时,确保活动作为新的任务启动 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + // 使用context对象调用startActivity方法来启动由intent指定的活动 + // 由于intent已经被设置为启动AlarmAlertActivity,这行代码的作用就是启动AlarmAlertActivity活动 context.startActivity(intent); } -} +} \ No newline at end of file diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/DateTimePicker.java b/src/java/net/micode/notes/ui/DateTimePicker.java similarity index 84% rename from src/Notes-master/Notes-master/src/net/micode/notes/ui/DateTimePicker.java rename to src/java/net/micode/notes/ui/DateTimePicker.java index 496b0cd..bc4dd63 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/DateTimePicker.java +++ b/src/java/net/micode/notes/ui/DateTimePicker.java @@ -14,8 +14,10 @@ * limitations under the License. */ + // 指定类所在的包名 package net.micode.notes.ui; +// 导入所需的Java和Android类 import java.text.DateFormatSymbols; import java.util.Calendar; @@ -27,11 +29,13 @@ import android.text.format.DateFormat; import android.view.View; import android.widget.FrameLayout; import android.widget.NumberPicker; - +// 定义一个名为DateTimePicker的类,它继承自FrameLayout + public class DateTimePicker extends FrameLayout { - + //FrameLayout是布局模板之一 + //所有的子元素全部在屏幕的右上方 private static final boolean DEFAULT_ENABLE_STATE = true; - + private static final int HOURS_IN_HALF_DAY = 12; private static final int HOURS_IN_ALL_DAY = 24; private static final int DAYS_IN_ALL_WEEK = 7; @@ -45,25 +49,27 @@ public class DateTimePicker extends FrameLayout { private static final int MINUT_SPINNER_MAX_VAL = 59; private static final int AMPM_SPINNER_MIN_VAL = 0; private static final int AMPM_SPINNER_MAX_VAL = 1; - + //初始化控件 private final NumberPicker mDateSpinner; private final NumberPicker mHourSpinner; private final NumberPicker mMinuteSpinner; private final NumberPicker mAmPmSpinner; + //NumberPicker是数字选择器 + //这里定义的四个变量全部是在设置闹钟时需要选择的变量(如日期、时、分、上午或者下午) private Calendar mDate; - + //定义了Calendar类型的变量mDate,用于操作时间 private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK]; - + private boolean mIsAm; - + private boolean mIs24HourView; - + private boolean mIsEnabled = DEFAULT_ENABLE_STATE; - + private boolean mInitialising; - + private OnDateTimeChangedListener mOnDateTimeChangedListener; - + private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { @@ -71,41 +77,49 @@ public class DateTimePicker extends FrameLayout { updateDateControl(); onDateTimeChanged(); } - }; - + };//OnValueChangeListener,这是时间改变监听器,这里主要是对日期的监听 + //将现在日期的值传递给mDate;updateDateControl是同步操作 + private NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() { - @Override + //这里是对 小时(Hour) 的监听 + @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { boolean isDateChanged = false; Calendar cal = Calendar.getInstance(); + //声明一个Calendar的变量cal,便于后续的操作 if (!mIs24HourView) { if (!mIsAm && oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) { cal.setTimeInMillis(mDate.getTimeInMillis()); cal.add(Calendar.DAY_OF_YEAR, 1); isDateChanged = true; + //这里是对于12小时制时,晚上11点和12点交替时对日期的更改 } else if (mIsAm && oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) { cal.setTimeInMillis(mDate.getTimeInMillis()); cal.add(Calendar.DAY_OF_YEAR, -1); isDateChanged = true; - } + } + //这里是对于12小时制时,凌晨11点和12点交替时对日期的更改 if (oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY || oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) { mIsAm = !mIsAm; updateAmPmControl(); - } + }//这里是对于12小时制时,中午11点和12点交替时对AM和PM的更改 } else { if (oldVal == HOURS_IN_ALL_DAY - 1 && newVal == 0) { cal.setTimeInMillis(mDate.getTimeInMillis()); cal.add(Calendar.DAY_OF_YEAR, 1); isDateChanged = true; + //这里是对于24小时制时,晚上11点和12点交替时对日期的更改 } else if (oldVal == 0 && newVal == HOURS_IN_ALL_DAY - 1) { cal.setTimeInMillis(mDate.getTimeInMillis()); cal.add(Calendar.DAY_OF_YEAR, -1); isDateChanged = true; } - } + } //这里是对于12小时制时,凌晨11点和12点交替时对日期的更改 int newHour = mHourSpinner.getValue() % HOURS_IN_HALF_DAY + (mIsAm ? 0 : HOURS_IN_HALF_DAY); + //通过数字选择器对newHour的赋值 mDate.set(Calendar.HOUR_OF_DAY, newHour); + //通过set函数将新的Hour值传给mDate onDateTimeChanged(); if (isDateChanged) { setCurrentYear(cal.get(Calendar.YEAR)); @@ -114,18 +128,22 @@ public class DateTimePicker extends FrameLayout { } } }; - + private NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() { @Override + //这里是对 分钟(Minute)改变的监听 public void onValueChange(NumberPicker picker, int oldVal, int newVal) { int minValue = mMinuteSpinner.getMinValue(); int maxValue = mMinuteSpinner.getMaxValue(); int offset = 0; + //设置offset,作为小时改变的一个记录数据 if (oldVal == maxValue && newVal == minValue) { offset += 1; } else if (oldVal == minValue && newVal == maxValue) { offset -= 1; } + //如果原值为59,新值为0,则offset加1 + //如果原值为0,新值为59,则offset减1 if (offset != 0) { mDate.add(Calendar.HOUR_OF_DAY, offset); mHourSpinner.setValue(getCurrentHour()); @@ -143,9 +161,10 @@ public class DateTimePicker extends FrameLayout { onDateTimeChanged(); } }; - + private NumberPicker.OnValueChangeListener mOnAmPmChangedListener = new NumberPicker.OnValueChangeListener() { - @Override + //对AM和PM的监听 + @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { mIsAm = !mIsAm; if (mIsAm) { @@ -157,63 +176,66 @@ public class DateTimePicker extends FrameLayout { onDateTimeChanged(); } }; - + public interface OnDateTimeChangedListener { void onDateTimeChanged(DateTimePicker view, int year, int month, int dayOfMonth, int hourOfDay, int minute); } - + public DateTimePicker(Context context) { this(context, System.currentTimeMillis()); - } - + }//通过对数据库的访问,获取当前的系统时间 + public DateTimePicker(Context context, long date) { this(context, date, DateFormat.is24HourFormat(context)); - } - + }//上面函数的得到的是一个天文数字(1970至今的秒数),需要DateFormat将其变得有意义 + public DateTimePicker(Context context, long date, boolean is24HourView) { super(context); + //获取系统时间 mDate = Calendar.getInstance(); mInitialising = true; mIsAm = getCurrentHourOfDay() >= HOURS_IN_HALF_DAY; inflate(context, R.layout.datetime_picker, this); - + //如果当前Activity里用到别的layout,比如对话框layout + //还要设置这个layout上的其他组件的内容,就必须用inflate()方法先将对话框的layout找出来 + //然后再用findViewById()找到它上面的其它组件 mDateSpinner = (NumberPicker) findViewById(R.id.date); mDateSpinner.setMinValue(DATE_SPINNER_MIN_VAL); mDateSpinner.setMaxValue(DATE_SPINNER_MAX_VAL); mDateSpinner.setOnValueChangedListener(mOnDateChangedListener); - + mHourSpinner = (NumberPicker) findViewById(R.id.hour); mHourSpinner.setOnValueChangedListener(mOnHourChangedListener); - mMinuteSpinner = (NumberPicker) findViewById(R.id.minute); - mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL); + mMinuteSpinner = (NumberPicker) findViewById(R.id.minute); + mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL); mMinuteSpinner.setMaxValue(MINUT_SPINNER_MAX_VAL); mMinuteSpinner.setOnLongPressUpdateInterval(100); mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener); - + String[] stringsForAmPm = new DateFormatSymbols().getAmPmStrings(); mAmPmSpinner = (NumberPicker) findViewById(R.id.amPm); mAmPmSpinner.setMinValue(AMPM_SPINNER_MIN_VAL); mAmPmSpinner.setMaxValue(AMPM_SPINNER_MAX_VAL); mAmPmSpinner.setDisplayedValues(stringsForAmPm); mAmPmSpinner.setOnValueChangedListener(mOnAmPmChangedListener); - + // update controls to initial state updateDateControl(); updateHourControl(); updateAmPmControl(); - + set24HourView(is24HourView); - + // set to current time setCurrentDate(date); - + setEnabled(isEnabled()); - + // set the content descriptions mInitialising = false; } - + @Override public void setEnabled(boolean enabled) { if (mIsEnabled == enabled) { @@ -226,12 +248,14 @@ public class DateTimePicker extends FrameLayout { mAmPmSpinner.setEnabled(enabled); mIsEnabled = enabled; } - + //存在疑问!!!!!!!!!!!!!setEnabled的作用 + //下面的代码通过原程序的注释已经比较清晰,另外可以通过函数名来判断 + //下面的各函数主要是对上面代码引用到的各函数功能的实现 @Override public boolean isEnabled() { return mIsEnabled; } - + /** * Get the current date in millis * @@ -239,8 +263,8 @@ public class DateTimePicker extends FrameLayout { */ public long getCurrentDateInTimeMillis() { return mDate.getTimeInMillis(); - } - + }//实现函数——得到当前的秒数 + /** * Set the current date * @@ -251,8 +275,8 @@ public class DateTimePicker extends FrameLayout { cal.setTimeInMillis(date); setCurrentDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE)); - } - + }//实现函数功能——设置当前的时间,参数是date + /** * Set the current date * @@ -269,17 +293,18 @@ public class DateTimePicker extends FrameLayout { setCurrentDay(dayOfMonth); setCurrentHour(hourOfDay); setCurrentMinute(minute); - } - + }//实现函数功能——设置当前的时间,参数是各详细的变量 + /** * Get current year * * @return The current year */ + //下面是得到year、month、day等值 public int getCurrentYear() { return mDate.get(Calendar.YEAR); } - + /** * Set current year * @@ -293,7 +318,7 @@ public class DateTimePicker extends FrameLayout { updateDateControl(); onDateTimeChanged(); } - + /** * Get current month in the year * @@ -302,7 +327,7 @@ public class DateTimePicker extends FrameLayout { public int getCurrentMonth() { return mDate.get(Calendar.MONTH); } - + /** * Set current month in the year * @@ -316,7 +341,7 @@ public class DateTimePicker extends FrameLayout { updateDateControl(); onDateTimeChanged(); } - + /** * Get current day of the month * @@ -325,7 +350,7 @@ public class DateTimePicker extends FrameLayout { public int getCurrentDay() { return mDate.get(Calendar.DAY_OF_MONTH); } - + /** * Set current day of the month * @@ -339,7 +364,7 @@ public class DateTimePicker extends FrameLayout { updateDateControl(); onDateTimeChanged(); } - + /** * Get current hour in 24 hour mode, in the range (0~23) * @return The current hour in 24 hour mode @@ -347,7 +372,7 @@ public class DateTimePicker extends FrameLayout { public int getCurrentHourOfDay() { return mDate.get(Calendar.HOUR_OF_DAY); } - + private int getCurrentHour() { if (mIs24HourView){ return getCurrentHourOfDay(); @@ -360,7 +385,7 @@ public class DateTimePicker extends FrameLayout { } } } - + /** * Set current hour in 24 hour mode, in the range (0~23) * @@ -388,7 +413,7 @@ public class DateTimePicker extends FrameLayout { mHourSpinner.setValue(hourOfDay); onDateTimeChanged(); } - + /** * Get currentMinute * @@ -397,7 +422,7 @@ public class DateTimePicker extends FrameLayout { public int getCurrentMinute() { return mDate.get(Calendar.MINUTE); } - + /** * Set current minute */ @@ -409,14 +434,14 @@ public class DateTimePicker extends FrameLayout { mDate.set(Calendar.MINUTE, minute); onDateTimeChanged(); } - + /** * @return true if this is in 24 hour view else false. */ public boolean is24HourView () { return mIs24HourView; } - + /** * Set whether in 24 hour or AM/PM mode. * @@ -433,7 +458,7 @@ public class DateTimePicker extends FrameLayout { setCurrentHour(hour); updateAmPmControl(); } - + private void updateDateControl() { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(mDate.getTimeInMillis()); @@ -446,8 +471,8 @@ public class DateTimePicker extends FrameLayout { mDateSpinner.setDisplayedValues(mDateDisplayValues); mDateSpinner.setValue(DAYS_IN_ALL_WEEK / 2); mDateSpinner.invalidate(); - } - + }// 对于星期几的算法 + private void updateAmPmControl() { if (mIs24HourView) { mAmPmSpinner.setVisibility(View.GONE); @@ -455,9 +480,9 @@ public class DateTimePicker extends FrameLayout { int index = mIsAm ? Calendar.AM : Calendar.PM; mAmPmSpinner.setValue(index); mAmPmSpinner.setVisibility(View.VISIBLE); - } + }// 对于上下午操作的算法 } - + private void updateHourControl() { if (mIs24HourView) { mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW); @@ -465,9 +490,9 @@ public class DateTimePicker extends FrameLayout { } else { mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW); mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW); - } + }// 对与小时的算法 } - + /** * Set the callback that indicates the 'Set' button has been pressed. * @param callback the callback, if null will do nothing @@ -475,11 +500,11 @@ public class DateTimePicker extends FrameLayout { public void setOnDateTimeChangedListener(OnDateTimeChangedListener callback) { mOnDateTimeChangedListener = callback; } - + private void onDateTimeChanged() { if (mOnDateTimeChangedListener != null) { mOnDateTimeChangedListener.onDateTimeChanged(this, getCurrentYear(), getCurrentMonth(), getCurrentDay(), getCurrentHourOfDay(), getCurrentMinute()); - } + } } -} +} \ No newline at end of file diff --git a/src/java/net/micode/notes/ui/DateTimePickerDialog.java b/src/java/net/micode/notes/ui/DateTimePickerDialog.java new file mode 100644 index 0000000..236960d --- /dev/null +++ b/src/java/net/micode/notes/ui/DateTimePickerDialog.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package net.micode.notes.ui; + + import java.util.Calendar; + + import net.micode.notes.R; + import net.micode.notes.ui.DateTimePicker; + import net.micode.notes.ui.DateTimePicker.OnDateTimeChangedListener; + + import android.app.AlertDialog; + import android.content.Context; + import android.content.DialogInterface; + import android.content.DialogInterface.OnClickListener; + import android.text.format.DateFormat; + import android.text.format.DateUtils; + + public class DateTimePickerDialog extends AlertDialog implements OnClickListener { + + private Calendar mDate = Calendar.getInstance(); + //创建一个Calendar类型的变量 mDate,方便时间的操作 + private boolean mIs24HourView; + private OnDateTimeSetListener mOnDateTimeSetListener; + //声明一个时间日期滚动选择控件 mOnDateTimeSetListener + private DateTimePicker mDateTimePicker; + //DateTimePicker控件,控件一般用于让用户可以从日期列表中选择单个值。 + //运行时,单击控件边上的下拉箭头,会显示为两个部分:一个下拉列表,一个用于选择日期的 + + public interface OnDateTimeSetListener { + void OnDateTimeSet(AlertDialog dialog, long date); + } + + public DateTimePickerDialog(Context context, long date) { + //对该界面对话框的实例化 + super(context); + //对数据库的操作 + mDateTimePicker = new DateTimePicker(context); + setView(mDateTimePicker); + //添加一个子视图 + mDateTimePicker.setOnDateTimeChangedListener(new OnDateTimeChangedListener() { + public void onDateTimeChanged(DateTimePicker view, int year, int month, + int dayOfMonth, int hourOfDay, int minute) { + mDate.set(Calendar.YEAR, year); + mDate.set(Calendar.MONTH, month); + mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); + mDate.set(Calendar.HOUR_OF_DAY, hourOfDay); + mDate.set(Calendar.MINUTE, minute); + //将视图中的各选项设置为系统当前时间 + updateTitle(mDate.getTimeInMillis()); + } + }); + mDate.setTimeInMillis(date); + //得到系统时间 + mDate.set(Calendar.SECOND, 0); + //将秒数设置为0 + mDateTimePicker.setCurrentDate(mDate.getTimeInMillis()); + setButton(context.getString(R.string.datetime_dialog_ok), this); + setButton2(context.getString(R.string.datetime_dialog_cancel), (OnClickListener)null); + //设置按钮 + set24HourView(DateFormat.is24HourFormat(this.getContext())); + //时间标准化打印 + updateTitle(mDate.getTimeInMillis()); + } + + public void set24HourView(boolean is24HourView) { + mIs24HourView = is24HourView; + } + + public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) { + mOnDateTimeSetListener = callBack; + }//将时间日期滚动选择控件实例化 + + private void updateTitle(long date) { + int flag = + DateUtils.FORMAT_SHOW_YEAR | + DateUtils.FORMAT_SHOW_DATE | + DateUtils.FORMAT_SHOW_TIME; + flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR; + setTitle(DateUtils.formatDateTime(this.getContext(), date, flag)); + }//android开发中常见日期管理工具类(API)——DateUtils:按照上下午显示时间 + + public void onClick(DialogInterface arg0, int arg1) { + if (mOnDateTimeSetListener != null) { + mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis()); + } + }//第一个参数arg0是接收到点击事件的对话框 + //第二个参数arg1是该对话框上的按钮 +} \ No newline at end of file diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/DropdownMenu.java b/src/java/net/micode/notes/ui/DropdownMenu.java similarity index 84% rename from src/Notes-master/Notes-master/src/net/micode/notes/ui/DropdownMenu.java rename to src/java/net/micode/notes/ui/DropdownMenu.java index 613dc74..a5520b2 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/DropdownMenu.java +++ b/src/java/net/micode/notes/ui/DropdownMenu.java @@ -15,7 +15,7 @@ */ package net.micode.notes.ui; - + import android.content.Context; import android.view.Menu; import android.view.MenuItem; @@ -24,38 +24,42 @@ import android.view.View.OnClickListener; import android.widget.Button; import android.widget.PopupMenu; import android.widget.PopupMenu.OnMenuItemClickListener; - + import net.micode.notes.R; - + public class DropdownMenu { private Button mButton; private PopupMenu mPopupMenu; + //声明一个下拉菜单 private Menu mMenu; - + public DropdownMenu(Context context, Button button, int menuId) { mButton = button; mButton.setBackgroundResource(R.drawable.dropdown_icon); + //设置这个view的背景 mPopupMenu = new PopupMenu(context, mButton); mMenu = mPopupMenu.getMenu(); mPopupMenu.getMenuInflater().inflate(menuId, mMenu); + //MenuInflater是用来实例化Menu目录下的Menu布局文件 + //根据ID来确认menu的内容选项 mButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mPopupMenu.show(); } }); } - + public void setOnDropdownMenuItemClickListener(OnMenuItemClickListener listener) { if (mPopupMenu != null) { mPopupMenu.setOnMenuItemClickListener(listener); - } + }//设置菜单的监听 } - + public MenuItem findItem(int id) { return mMenu.findItem(id); - } - + }//对于菜单选项的初始化,根据索引搜索菜单需要的选项 + public void setTitle(CharSequence title) { mButton.setText(title); - } -} + }//布局文件,设置标题 +} \ No newline at end of file diff --git a/src/java/net/micode/notes/ui/FoldersListAdapter.java b/src/java/net/micode/notes/ui/FoldersListAdapter.java new file mode 100644 index 0000000..9f46784 --- /dev/null +++ b/src/java/net/micode/notes/ui/FoldersListAdapter.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package net.micode.notes.ui; + + import android.content.Context; + import android.database.Cursor; + import android.view.View; + import android.view.ViewGroup; + import android.widget.CursorAdapter; + import android.widget.LinearLayout; + import android.widget.TextView; + + import net.micode.notes.R; + import net.micode.notes.data.Notes; + import net.micode.notes.data.Notes.NoteColumns; + + + public class FoldersListAdapter extends CursorAdapter { + //CursorAdapter是Cursor和ListView的接口 + //FoldersListAdapter继承了CursorAdapter的类 + //主要作用是便签数据库和用户的交互 + //这里就是用folder(文件夹)的形式展现给用户 + public static final String [] PROJECTION = { + NoteColumns.ID, + NoteColumns.SNIPPET + };//调用数据库中便签的ID和片段 + + public static final int ID_COLUMN = 0; + public static final int NAME_COLUMN = 1; + + public FoldersListAdapter(Context context, Cursor c) { + super(context, c); + // TODO Auto-generated constructor stub + }//数据库操作 + + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) { + //ViewGroup是容器 + return new FolderListItem(context); + }//创建一个文件夹,对于各文件夹中子标签的初始化 + + @Override + public void bindView(View view, Context context, Cursor cursor) { + if (view instanceof FolderListItem) { + String folderName = (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context + .getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN); + ((FolderListItem) view).bind(folderName); + } + }//将各个布局文件绑定起来 + + public String getFolderName(Context context, int position) { + Cursor cursor = (Cursor) getItem(position); + return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context + .getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN); + }//根据数据库中标签的ID得到标签的各项内容 + + private class FolderListItem extends LinearLayout { + private TextView mName; + + public FolderListItem(Context context) { + super(context); + //操作数据库 + inflate(context, R.layout.folder_list_item, this); + //根据布局文件的名字等信息将其找出来 + mName = (TextView) findViewById(R.id.tv_folder_name); + } + + public void bind(String name) { + mName.setText(name); + } + } + + } \ No newline at end of file diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NoteEditActivity.java b/src/java/net/micode/notes/ui/NoteEditActivity.java similarity index 62% rename from src/Notes-master/Notes-master/src/net/micode/notes/ui/NoteEditActivity.java rename to src/java/net/micode/notes/ui/NoteEditActivity.java index 96a9ff8..7915c4e 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NoteEditActivity.java +++ b/src/java/net/micode/notes/ui/NoteEditActivity.java @@ -35,6 +35,8 @@ import android.text.SpannableString; import android.text.TextUtils; import android.text.format.DateUtils; import android.text.style.BackgroundColorSpan; +import android.text.Editable; +import android.text.TextWatcher; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -51,6 +53,10 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; 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.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_4x; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.Map; import java.util.regex.Matcher; 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 { public TextView tvModified; @@ -81,6 +99,12 @@ public class NoteEditActivity extends Activity implements OnClickListener, public TextView tvAlertDate; + // 顶部置顶文本 + public TextView tvTopText; + + // 顶部长度统计文本 + public TextView tvTextNum; + public ImageView ibSetBgColor; } @@ -118,8 +142,13 @@ public class NoteEditActivity extends Activity implements OnClickListener, sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select); } + + + private static final String TAG = "NoteEditActivity"; + private static int mMaxRevokeTimes = 10; + private HeadViewHolder mNoteHeaderHolder; private View mHeadViewPanel; @@ -136,8 +165,10 @@ public class NoteEditActivity extends Activity implements OnClickListener, private SharedPreferences mSharedPrefs; private int mFontSizeId; + private int mFontStyleId; 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; @@ -149,15 +180,36 @@ public class NoteEditActivity extends Activity implements OnClickListener, private String mUserQuery; private Pattern mPattern; + // 存储改变的数据 + private Vector mHistory = new Vector(mMaxRevokeTimes); + private boolean mIsRvoke; + + /*--- 以上是此类中的数据区,以下是方法区 ---*/ + + /** + * @zkx 2023/12/18 复写了Activity类中的onCreate函数,当用户点击创建时,会进入这个函数 + */ + /** + * @method: onCreate + * @description: 进入场景:在list页面,点击“写便签”时进入;在挂件页面,生成挂件时不进入,点进挂件时才进入;…… + * allinall:在进入编辑页面前都会进入 + * 创建一个编辑活动 + * @date: 2023/12/18 23:22 + * @author: zhoukexing + * @param: [savedInstanceState] + * @return: void + */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.note_edit); if (savedInstanceState == null && !initActivityState(getIntent())) { + // 表示之前保存的状态,用于还原数据 @lzk 2024/1/3 23:33 finish(); return; } + // 初始化资源。我要的设置字体就在这儿 initResources(); } @@ -180,18 +232,26 @@ public class NoteEditActivity extends Activity implements OnClickListener, } private boolean initActivityState(Intent intent) { + /** + * @method: initActivityState + * @description: 根据intent(Key-Value)内容,初始化一个便签活动 + * @date: 2023/12/18 23:31 + * @author: zhoukexing + * @param: [intent] + * @return: boolean 为真则初始化成功,为假则失败。失败原因:不存在、(call)load失败、intent内容错误 + */ /** * If the user specified the {@link Intent#ACTION_VIEW} but not provided with id, * then jump to the NotesListActivity */ mWorkingNote = null; if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) { + // 进入场景:点进一个已有便签 @zhoukexing 2023/12/21 0:14 long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0); - mUserQuery = ""; - /** * Starting from the searched result */ + // 高亮搜索内容 @lzk 2024/1/3 10:10 if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) { noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY)); mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY); @@ -203,7 +263,8 @@ public class NoteEditActivity extends Activity implements OnClickListener, showToast(R.string.error_note_not_exist); finish(); return false; - } else { + } + else {// 如果在数据库里存在,就根据noteId从数据库中加载到工作便签里来 @zhoukexing 2023/12/21 0:16 mWorkingNote = WorkingNote.load(this, noteId); if (mWorkingNote == null) { Log.e(TAG, "load note failed with note id" + noteId); @@ -211,20 +272,22 @@ public class NoteEditActivity extends Activity implements OnClickListener, return false; } } - getWindow().setSoftInputMode( + getWindow().setSoftInputMode(// 猜:平滑地展示便签内容 @zhoukexing 2023/12/21 0:18 WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); - } else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) { - // New note + } + else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) { + // 进入场景:一个New note long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0); int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); int widgetType = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, - Notes.TYPE_WIDGET_INVALIDE); + Notes.TYPE_WIDGET_INVALIDE); // widgetType=0: 新建的挂件,空的 @zhoukexing 2023/12/21 0:02 int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, - ResourceParser.getDefaultBgId(this)); + ResourceParser.getDefaultBgId(this));// TODO: 2023/12/21 背景色的设置 - // Parse call-record note + // Parse call-record note todo + // 解析文档,看是否有号码存在,以便展示的时候渲染 @zhoukexing 2023/12/20 23:49 String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0); if (callDate != 0 && phoneNumber != null) { @@ -234,6 +297,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, long noteId = 0; if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(), phoneNumber, callDate)) > 0) { + // TODO: 2023/12/20 mWorkingNote = WorkingNote.load(this, noteId); if (mWorkingNote == null) { Log.e(TAG, "load call note failed with note id" + noteId); @@ -245,7 +309,8 @@ public class NoteEditActivity extends Activity implements OnClickListener, widgetType, bgResId); mWorkingNote.convertToCallNote(phoneNumber, callDate); } - } else { + } + else { // 没有要显示的电话 mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType, bgResId); } @@ -253,12 +318,14 @@ public class NoteEditActivity extends Activity implements OnClickListener, getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); - } else { + } + else { Log.e(TAG, "Intent not specified action, should not support"); finish(); return false; } mWorkingNote.setOnSettingStatusChangedListener(this); + // this是WorkingNote @zhoukexing 2023/12/21 0:08 return true; } @@ -268,9 +335,20 @@ public class NoteEditActivity extends Activity implements OnClickListener, 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() { mNoteEditor.setTextAppearance(this, TextAppearanceResources .getTexAppearanceResource(mFontSizeId)); + initFontStyle(mNoteEditor, mFontStyleId); if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) { switchToListMode(mWorkingNote.getContent()); } else { @@ -293,17 +371,57 @@ public class NoteEditActivity extends Activity implements OnClickListener, * is not ready */ 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() { if (mWorkingNote.hasClockAlert()) { long time = System.currentTimeMillis(); if (time > mWorkingNote.getAlertDate()) { + // 闹钟时间大于当前时间, 显示 "Expired", 闹钟失效 mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired); } else { + // 显示正常闹钟信息 mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString( mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS)); } + /** + * setVisibility() + * 用于设置空间的可见性 + * VISIBLE 可见 + * INVISIBLE 不可见,但是占用一个位置 + * GNONE 不可见且不占用位置 + * lenovo 2023/12/13 11:28 + */ mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE); mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE); } else { @@ -315,7 +433,15 @@ public class NoteEditActivity extends Activity implements OnClickListener, @Override protected void onNewIntent(Intent 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 @@ -363,15 +489,61 @@ public class NoteEditActivity extends Activity implements OnClickListener, 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() { mHeadViewPanel = findViewById(R.id.note_title); mNoteHeaderHolder = new HeadViewHolder(); mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date); mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon); 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.setOnClickListener(this); 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); mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector); for (int id : sBgSelectorBtnsMap.keySet()) { @@ -394,6 +566,10 @@ public class NoteEditActivity extends Activity implements OnClickListener, if(mFontSizeId >= TextAppearanceResources.getResourcesSize()) { 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); } @@ -406,6 +582,13 @@ public class NoteEditActivity extends Activity implements OnClickListener, clearSettingState(); } + /** + * @method updateWidget + * @description 该方法用于实现与桌面小工具同步的功能 + * @date: 2023-12-18 21:37 + * @author: 郑鲲鹏 + * @return void + */ private void updateWidget() { Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) { @@ -430,7 +613,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, if (id == R.id.btn_set_bg_color) { mNoteBgColorSelector.setVisibility(View.VISIBLE); findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( - - View.VISIBLE); + View.VISIBLE); } else if (sBgSelectorBtnsMap.containsKey(id)) { findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( View.GONE); @@ -442,13 +625,15 @@ public class NoteEditActivity extends Activity implements OnClickListener, mSharedPrefs.edit().putInt(PREFERENCE_FONT_SIZE, mFontSizeId).commit(); findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE); if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) { - getWorkingText(); + getWorkingText(); // DONE:切换到清单模式后,字体保留 switchToListMode(mWorkingNote.getContent()); } else { mNoteEditor.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId)); + initFontStyle(mNoteEditor, mFontStyleId); // 因为上面的操作会覆盖掉style的显示,所以在这里重新设置一下 @zkx } mFontSizeSelector.setVisibility(View.GONE); + } } @@ -502,59 +687,122 @@ public class NoteEditActivity extends Activity implements OnClickListener, } else { 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; } @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_new_note: - createNewNote(); - break; - case R.id.menu_delete: - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(getString(R.string.alert_title_delete)); - builder.setIcon(android.R.drawable.ic_dialog_alert); - builder.setMessage(getString(R.string.alert_message_delete_note)); - builder.setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - deleteCurrentNote(); - finish(); - } - }); - builder.setNegativeButton(android.R.string.cancel, null); - builder.show(); - break; - case R.id.menu_font_size: - mFontSizeSelector.setVisibility(View.VISIBLE); - findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE); - break; - case R.id.menu_list_mode: - mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ? - TextNote.MODE_CHECK_LIST : 0); - break; - case R.id.menu_share: - getWorkingText(); - sendTo(this, mWorkingNote.getContent()); - break; - case R.id.menu_send_to_desktop: - sendToDesktop(); - break; - case R.id.menu_alert: - setReminder(); - break; - case R.id.menu_delete_remind: - mWorkingNote.setAlertDate(0, false); - break; - default: - break; + /** + * @method: onOptionsItemSelected + * @description: 覆写了Activity.java里的onOptionsItemSelected,路线是menu-->item, + * 这里就是处理识别到的item + * @date: 2023/12/19 23:35 + * @author: zhoukexing + * @param: [item] + * @return: boolean + */ + int itemId = item.getItemId(); + if (itemId == R.id.menu_new_note) { // 从item到itemid,用itemid导向对应的不同的动作 @zhoukexing 2023/12/19 23:38 + createNewNote(); + } else if (itemId == R.id.menu_delete) { + // 构建一个警告⚠对话框,让用户确认是否真的要删除便签 @zhoukexing 2023/12/21 0:41 + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(getString(R.string.alert_title_delete)); + builder.setIcon(android.R.drawable.ic_dialog_alert); + builder.setMessage(getString(R.string.alert_message_delete_note)); + builder.setPositiveButton(android.R.string.ok, + new DialogInterface.OnClickListener() {// TODO: 2023/12/21 传入了一个函数作为参数? + public void onClick(DialogInterface dialog, int which) { + deleteCurrentNote(); //TODO: 修改这里达成“在便签内点删除进回收站” + finish(); + } + }); + builder.setNegativeButton(android.R.string.cancel, null); + builder.show(); + } else if (itemId == R.id.menu_font_size) { + mFontSizeSelector.setVisibility(View.VISIBLE); + findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE); + } else if (itemId == R.id.menu_list_mode) { + mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ? + TextNote.MODE_CHECK_LIST : 0); + } else if (itemId == R.id.menu_share) { + getWorkingText(); + sendTo(this, mWorkingNote.getContent()); + } else if (itemId == R.id.menu_send_to_desktop) { + sendToDesktop(); + } else if (itemId == R.id.menu_alert) { + setReminder(); + } else if (itemId == R.id.menu_delete_remind) { + 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; } + 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() { DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis()); + // 设置时间选择器的监听事件,当选中 date 之后调用 setAlertDate 设置提醒时间 d.setOnDateTimeSetListener(new OnDateTimeSetListener() { public void OnDateTimeSet(AlertDialog dialog, long date) { 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 * and {@text/plain} type */ + /** + * @method sendTo + * @description 该方法用于共享便签 + * @date: 2023-12-18 0:57 + * @author: 郑鲲鹏 + * @return void + */ private void sendTo(Context context, String info) { + // 新建intent消息 + // 2023-12-18 1:00 Intent intent = new Intent(Intent.ACTION_SEND); + // 将要分享的便签内容放入intent中 + // 2023-12-18 1:01 intent.putExtra(Intent.EXTRA_TEXT, info); intent.setType("text/plain"); context.startActivity(intent); } private void createNewNote() { + /** + * @method: createNewNote + * @description: 从编辑页面,点击“add note”会进入这个创建便签的方法。 + * 此方法会保存并结束当前便签,用NoteEditActivity类实例化一个新的intent(活动意图), + * 设置行为和指定报错对象后,启动intent活动意图 + * @date: 2023/12/19 23:03 + * @author: zhoukexing + * @param: [] + * @return: void + */ // Firstly, save current editing notes saveNote(); // For safety, start a new NoteEditActivity finish(); - Intent intent = new Intent(this, NoteEditActivity.class); - intent.setAction(Intent.ACTION_INSERT_OR_EDIT); + Intent intent = new Intent(this, NoteEditActivity.class); //Q: 在类的内部,还没有实现完全时,启动这个类自己?@zkx 2023/12/17 + intent.setAction(Intent.ACTION_INSERT_OR_EDIT); // 创建便签后,要插入或者编辑。Q: 为什么要插入 @zhoukexing 2023/12/19 22:57 intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId()); startActivity(intent); } - + /** + * @method: deleteCurrentNote + * @description: 删除当前便签。如果在数据库里,还要进一步判断是否在根目录下,是否为同步模式 + * @date: 2023/12/21 0:48 + * @author: zhoukexing + * @param: [] + * @return: void + */ private void deleteCurrentNote() { if (mWorkingNote.existInDatabase()) { HashSet ids = new HashSet(); @@ -595,11 +871,11 @@ public class NoteEditActivity extends Activity implements OnClickListener, } else { Log.d(TAG, "Wrong note id, should not happen"); } - if (!isSyncMode()) { - if (!DataUtils.batchDeleteNotes(getContentResolver(), ids)) { - Log.e(TAG, "Delete Note error"); - } - } else { + if (mWorkingNote.getFolderId() == Notes.ID_TRASH_FOLER) { + if (!DataUtils.batchDeleteNotes(getContentResolver(), ids)) { + Log.e(TAG, "Delete Note error"); + } + } else { if (!DataUtils.batchMoveToFolder(getContentResolver(), ids, Notes.ID_TRASH_FOLER)) { 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; } + /** + * @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) { /** * 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)); showAlertHeader(); if(!set) { + // 取消监听事件 alarmManager.cancel(pendingIntent); } else { + // 设置监听事件,到时间启动提醒 alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent); } } 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(); String[] items = text.split("\n"); 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); final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text); edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId)); + initFontStyle(edit, mFontStyleId); CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item)); cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -806,8 +1094,16 @@ public class NoteEditActivity extends Activity implements OnClickListener, } private boolean saveNote() { + /** + * @method: saveNote + * @description: 获取工作文本,调用真正的保存便签的方法,设置便签在list界面的位置 + * @date: 2023/12/19 23:50 + * @author: zhoukexing + * @param: [] + * @return: boolean + */ getWorkingText(); - boolean saved = mWorkingNote.saveNote(); + boolean saved = mWorkingNote.saveNote();// TODO: 2023/12/19 工作便签下的saveNote if (saved) { /** * There are two modes from List view to edit view, open one note, @@ -816,11 +1112,19 @@ public class NoteEditActivity extends Activity implements OnClickListener, * new node requires to the top of the list. This code * {@link #RESULT_OK} is used to identify the create/edit state */ - setResult(RESULT_OK); + setResult(RESULT_OK); // RESULT_OK指示将该便签保存到list界面的顶端(因为这是新建的便签) @zhoukexing 2023/12/19 23:41 + //Q: 这个setResult只在这里调用了,怎么实现的 @zkx 2023/12/19 } return saved; } + /** + * @method sendToDesktop + * @description 该方法用于将便签发送至桌面,创建快捷方式 + * @date: 2023-12-18 17:27 + * @author: 郑鲲鹏 + * @return void + */ private void sendToDesktop() { /** * Before send message to home, we should make sure that current @@ -832,9 +1136,13 @@ public class NoteEditActivity extends Activity implements OnClickListener, } if (mWorkingNote.getNoteId() > 0) { + // 新建intent消息,为创建桌面快捷方式的连接器 + // 2023-12-18 17:29 Intent sender = new Intent(); Intent shortcutIntent = new Intent(this, NoteEditActivity.class); shortcutIntent.setAction(Intent.ACTION_VIEW); + // 将便签的相关信息添加进intent中 + // 2023-12-18 17:36 shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId()); sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); sender.putExtra(Intent.EXTRA_SHORTCUT_NAME, @@ -844,6 +1152,8 @@ public class NoteEditActivity extends Activity implements OnClickListener, sender.putExtra("duplicate", true); sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); showToast(R.string.info_note_enter_desktop); + // 将便签显示于桌面 + // 2023-12-18 17:38 sendBroadcast(sender); } else { /** @@ -870,4 +1180,86 @@ public class NoteEditActivity extends Activity implements OnClickListener, private void showToast(int resId, int duration) { 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 diff --git a/src/java/net/micode/notes/ui/NoteEditText.java b/src/java/net/micode/notes/ui/NoteEditText.java new file mode 100644 index 0000000..8662681 --- /dev/null +++ b/src/java/net/micode/notes/ui/NoteEditText.java @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package net.micode.notes.ui; + + import android.content.Context; + import android.graphics.Rect; + import android.text.Layout; + import android.text.Selection; + import android.text.Spanned; + import android.text.TextUtils; + import android.text.style.URLSpan; + import android.util.AttributeSet; + import android.util.Log; + import android.view.ContextMenu; + import android.view.KeyEvent; + import android.view.MenuItem; + import android.view.MenuItem.OnMenuItemClickListener; + import android.view.MotionEvent; + import android.widget.EditText; + + import net.micode.notes.R; + + import java.util.HashMap; + import java.util.Map; + + //继承edittext,设置便签设置文本框 + public class NoteEditText extends EditText { + private static final String TAG = "NoteEditText"; + private int mIndex; + private int mSelectionStartBeforeDelete; + + private static final String SCHEME_TEL = "tel:" ; + private static final String SCHEME_HTTP = "http:" ; + private static final String SCHEME_EMAIL = "mailto:" ; + + ///建立一个字符和整数的hash表,用于链接电话,网站,还有邮箱 + private static final Map sSchemaActionResMap = new HashMap(); + static { + sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel); + sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web); + sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email); + } + + /** + * Call by the {@link NoteEditActivity} to delete or add edit text + */ + //在NoteEditActivity中删除或添加文本的操作,可以看做是一个文本是否被变的标记,英文注释已说明的很清楚 + public interface OnTextViewChangeListener { + /** + * Delete current edit text when {@link KeyEvent#KEYCODE_DEL} happens + * and the text is null + */ + //处理删除按键时的操作 + void onEditTextDelete(int index, String text); + + /** + * Add edit text after current edit text when {@link KeyEvent#KEYCODE_ENTER} + * happen + */ + //处理进入按键时的操作 + void onEditTextEnter(int index, String text); + + /** + * Hide or show item option when text change + */ + void onTextChange(int index, boolean hasText); + } + + private OnTextViewChangeListener mOnTextViewChangeListener; + + //根据context设置文本 + public NoteEditText(Context context) { + super(context, null);//用super引用父类变量 + mIndex = 0; + } + + //设置当前光标 + public void setIndex(int index) { + mIndex = index; + } + + //初始化文本修改标记 + public void setOnTextViewChangeListener(OnTextViewChangeListener listener) { + mOnTextViewChangeListener = listener; + } + + //AttributeSet 百度了一下是自定义空控件属性,用于维护便签动态变化的属性 + //初始化便签 + public NoteEditText(Context context, AttributeSet attrs) { + super(context, attrs, android.R.attr.editTextStyle); + } + + // 根据defstyle自动初始化 + public NoteEditText(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + // TODO Auto-generated construct or stub + } + + @Override + //view里的函数,处理手机屏幕的所有事件 + /*参数event为手机屏幕触摸事件封装类的对象,其中封装了该事件的所有信息, + 例如触摸的位置、触摸的类型以及触摸的时间等。该对象会在用户触摸手机屏幕时被创建。*/ + 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根据x,y的新值设置新的位置 + Layout layout = getLayout(); + int line = layout.getLineForVertical(y); + int off = layout.getOffsetForHorizontal(line, x); + + //更新光标新的位置 + Selection.setSelection(getText(), off); + break; + } + + return super.onTouchEvent(event); + } + + @Override + /* + * 函数功能:处理用户按下一个键盘按键时会触发 的事件 + * 实现过程:如下注释 + */ + public boolean onKeyDown(int keyCode, KeyEvent event) { + switch (keyCode) { + //根据按键的 Unicode 编码值来处理 + case KeyEvent.KEYCODE_ENTER: + //“进入”按键 + if (mOnTextViewChangeListener != null) { + return false; + } + 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) { + //根据按键的 Unicode 编码值来处理,有删除和进入2种操作 + case KeyEvent.KEYCODE_DEL: + if (mOnTextViewChangeListener != null) { + //若是被修改过 + if (0 == mSelectionStartBeforeDelete && mIndex != 0) { + //若之前有被修改并且文档不为空 + mOnTextViewChangeListener.onEditTextDelete(mIndex, getText().toString()); + //利用上文OnTextViewChangeListener对KEYCODE_DEL按键情况的删除函数进行删除 + return true; + } + } else { + Log.d(TAG, "OnTextViewChangeListener was not seted"); + //其他情况报错,文档的改动监听器并没有建立 + } + break; + case KeyEvent.KEYCODE_ENTER: + //同上也是分为监听器是否建立2种情况 + if (mOnTextViewChangeListener != null) { + int selectionStart = getSelectionStart(); + //获取当前位置 + String text = getText().subSequence(selectionStart, length()).toString(); + //获取当前文本 + setText(getText().subSequence(0, selectionStart)); + //根据获取的文本设置当前文本 + mOnTextViewChangeListener.onEditTextEnter(mIndex + 1, text); + //当{@link KeyEvent#KEYCODE_ENTER}添加新文本 + } else { + Log.d(TAG, "OnTextViewChangeListener was not seted"); + //其他情况报错,文档的改动监听器并没有建立 + } + break; + default: + break; + } + //继续执行父类的其他按键弹起的事件 + return super.onKeyUp(keyCode, event); + } + + @Override + /* + * 函数功能:当焦点发生变化时,会自动调用该方法来处理焦点改变的事件 + * 实现方式:如下注释 + * 参数:focused表示触发该事件的View是否获得了焦点,当该控件获得焦点时,Focused等于true,否则等于false。 + direction表示焦点移动的方向,用数值表示 + Rect:表示在触发事件的View的坐标系中,前一个获得焦点的矩形区域,即表示焦点是从哪里来的。如果不可用则为null + */ + protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { + if (mOnTextViewChangeListener != null) { + //若监听器已经建立 + if (!focused && TextUtils.isEmpty(getText())) { + //获取到焦点并且文本不为空 + mOnTextViewChangeListener.onTextChange(mIndex, false); + //mOnTextViewChangeListener子函数,置false隐藏事件选项 + } else { + mOnTextViewChangeListener.onTextChange(mIndex, true); + //mOnTextViewChangeListener子函数,置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); + //设置url的信息的范围值 + if (urls.length == 1) { + int defaultResId = 0; + for(String schema: sSchemaActionResMap.keySet()) { + //获取计划表中所有的key值 + if(urls[0].getURL().indexOf(schema) >= 0) { + //若url可以添加则在添加后将defaultResId置为key所映射的值 + defaultResId = sSchemaActionResMap.get(schema); + break; + } + } + + if (defaultResId == 0) { + //defaultResId == 0则说明url并没有添加任何东西,所以置为连接其他SchemaActionResMap的值 + 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; + } + }); + } + } + //继续执行父类的其他菜单创建的事件 + super.onCreateContextMenu(menu); + } + } \ No newline at end of file diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NoteItemData.java b/src/java/net/micode/notes/ui/NoteItemData.java similarity index 84% rename from src/Notes-master/Notes-master/src/net/micode/notes/ui/NoteItemData.java rename to src/java/net/micode/notes/ui/NoteItemData.java index 0f5a878..bd04f74 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NoteItemData.java +++ b/src/java/net/micode/notes/ui/NoteItemData.java @@ -40,6 +40,7 @@ public class NoteItemData { NoteColumns.TYPE, NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, + NoteColumns.TOP, }; 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 WIDGET_ID_COLUMN = 10; 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 mAlertDate; private int mBgColorId; @@ -67,6 +72,7 @@ public class NoteItemData { private int mType; private int mWidgetId; private int mWidgetType; + private int mTop; private String mName; private String mPhoneNumber; @@ -76,8 +82,16 @@ public class NoteItemData { private boolean mIsOneNoteFollowingFolder; 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); mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN); mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN); @@ -91,10 +105,12 @@ public class NoteItemData { mType = cursor.getInt(TYPE_COLUMN); mWidgetId = cursor.getInt(WIDGET_ID_COLUMN); mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN); + mTop = cursor.getInt(TOP_STATE_COLUMN); 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); + // 根据电话号码锁定联系人名称,若不在联系人里,直接使用电话号码 @zhoukexing 2023/12/25 20:17 if (!TextUtils.isEmpty(mPhoneNumber)) { mName = Contact.getContact(context, mPhoneNumber); if (mName == null) { @@ -158,6 +174,10 @@ public class NoteItemData { return mIsOnlyOneItem; } + public int getTop(){ + return mTop; + } + public long getId() { return mId; } diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NotesListActivity.java b/src/java/net/micode/notes/ui/NotesListActivity.java similarity index 71% rename from src/Notes-master/Notes-master/src/net/micode/notes/ui/NotesListActivity.java rename to src/java/net/micode/notes/ui/NotesListActivity.java index e843aec..fb7b0f5 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/ui/NotesListActivity.java +++ b/src/java/net/micode/notes/ui/NotesListActivity.java @@ -16,9 +16,11 @@ package net.micode.notes.ui; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; +import android.app.SearchManager; import android.appwidget.AppWidgetManager; import android.content.AsyncQueryHandler; import android.content.ContentResolver; @@ -77,7 +79,19 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; 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 { 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 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 SEARCH_RESULTS = "Search Results: "; 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; @@ -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_NEW_NODE = 103; + private String mTitle; + private String mMessage; + + private int mBackground = 2; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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(); - /** * Insert an introduction when user firstly use this application */ @@ -204,9 +233,26 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt } @Override + /** + * @Method onStart + * @Date 2024/1/4 8:56 + * @Author lenovo + * @Return void + * @Description 仅在启动时调用,用于加载页面数据,展现页面内容。 + */ protected void 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() { @@ -218,7 +264,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt null, false); mNotesListView.setOnItemClickListener(new OnListItemClickListener()); mNotesListView.setOnItemLongClickListener(this); - mNotesListAdapter = new NotesListAdapter(this); + mNotesListAdapter = new NotesListAdapter(this, null); mNotesListView.setAdapter(mNotesListAdapter); mAddNewNote = (Button) findViewById(R.id.btn_new_note); mAddNewNote.setOnClickListener(this); @@ -319,28 +365,41 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt return true; } - switch (item.getItemId()) { - case R.id.delete: - AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this); - builder.setTitle(getString(R.string.alert_title_delete)); - builder.setIcon(android.R.drawable.ic_dialog_alert); - builder.setMessage(getString(R.string.alert_message_delete_notes, - mNotesListAdapter.getSelectedCount())); - 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(); - break; - case R.id.move: - startQueryDestinationFolders(); - break; - default: - return false; + int itemId = item.getItemId(); + if (itemId == R.id.delete) { + switch (mState) { + case SUB_FOLDER: + case CALL_RECORD_FOLDER: + case NOTE_LIST: + mTitle = getString(R.string.alert_title_delete); + mMessage = getString(R.string.alert_message_delete_notes, + mNotesListAdapter.getSelectedCount()); + break; + case TRASH_FOLDER: + mTitle = getString(R.string.alert_title_delete_true); + mMessage = getString(R.string.alert_message_delete_notes_true, + mNotesListAdapter.getSelectedCount()); + break; + default: + break; + } + AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this); + builder.setTitle(mTitle); + builder.setIcon(android.R.drawable.ic_dialog_alert); + 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; } @@ -359,7 +418,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt /** * Minus TitleBar's height */ - if (mState == ListEditState.SUB_FOLDER) { + if (mState == ListEditState.SUB_FOLDER || + mState == ListEditState.TRASH_FOLDER) { + // 回收站的ui显示 @zkx eventY -= 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() { String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION : NORMAL_SELECTION; + // 按照 Top 降序 mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null, Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] { 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 { @@ -469,20 +549,29 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE); } + /** + * @method: batchDelete + * @description: 删除若干个选中的便签。 + * 根据NotesListAdapter里的mSelectedIndex数据成员里的标记,为真表示选中,予以删除。 + * @date: 2024/1/3 23:02 + * @author: zhoukexing + * @param: [] + * @return: void + */ private void batchDelete() { new AsyncTask>() { + @SuppressLint("StaticFieldLeak") protected HashSet doInBackground(Void... unused) { HashSet widgets = mNotesListAdapter.getSelectedWidget(); - if (!isSyncMode()) { - // if not synced, delete notes directly + if (mCurrentFolderId == Notes.ID_TRASH_FOLER){ + // if in trash, really delete notes if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter .getSelectedItemIds())) { } else { Log.e(TAG, "Delete notes error, should not happens"); } } else { - // in sync mode, we'll move the deleted note into the trash - // folder + // move notes to trash if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter .getSelectedItemIds(), Notes.ID_TRASH_FOLER)) { 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 widgets) { if (widgets != null) { for (AppWidgetAttribute widget : widgets) { + // widget挂件的Id和Type都不是非法的《==》存在这个widget挂件 @zkx if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID && widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) { + // ==》 删除这个挂件 updateWidget(widget.widgetId, widget.widgetType); } } @@ -506,6 +597,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt }.execute(); } + /** + * @Method deleteFolder + * @Date 2023/12/19 8:37 + * @param folderId + * @Author lenovo + * @Return void + * @Description 删除文件夹 (sync mode 会删除进回收站) + */ private void deleteFolder(long folderId) { if (folderId == Notes.ID_ROOT_FOLDER) { Log.e(TAG, "Wrong folder id, should not happen " + folderId); @@ -514,15 +613,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt HashSet ids = new HashSet(); ids.add(folderId); + // 所有与要删除文件夹相关的 widgets HashSet widgets = DataUtils.getFolderNoteWidget(mContentResolver, folderId); - if (!isSyncMode()) { - // if not synced, delete folder directly + if (mCurrentFolderId == Notes.ID_TRASH_FOLER) { + // if in trash, delete folder directly DataUtils.batchDeleteNotes(mContentResolver, ids); } 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); } + // 更新 widgets if (widgets != null) { for (AppWidgetAttribute widget : widgets) { 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); } + /** + * @Method openFolder + * @Date 2023/12/19 7:55 + * @param data + * @Author lenovo + * @Return void + * @Description 打开文件夹 + */ private void openFolder(NoteItemData data) { mCurrentFolderId = data.getId(); startAsyncNotesListQuery(); if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) { + // TODO store all records 暂时没太搞明白这个代表什么 mState = ListEditState.CALL_RECORD_FOLDER; mAddNewNote.setVisibility(View.GONE); } else { + // 正常打开文件夹 mState = ListEditState.SUB_FOLDER; } if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) { mTitleBar.setText(R.string.call_record_folder_name); } else { + // 将顶部栏设置为 data.getSnippet 文件夹名称 mTitleBar.setText(data.getSnippet()); } mTitleBar.setVisibility(View.VISIBLE); } public void onClick(View v) { - switch (v.getId()) { - case R.id.btn_new_note: - createNewNote(); - break; - default: - break; + if (v.getId() == R.id.btn_new_note) { + createNewNote(); } } + /** + * @Method showSoftInput + * @Date 2023/12/17 23:46 + * @Author lenovo + * @Return void + * @Description 显示软键盘 + */ private void showSoftInput() { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (inputMethodManager != null) { @@ -579,14 +694,23 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt 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) { + // final 关键字, 初始化之后无法修改 (const) final AlertDialog.Builder builder = new AlertDialog.Builder(this); View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null); final EditText etName = (EditText) view.findViewById(R.id.et_foler_name); showSoftInput(); if (!create) { if (mFocusNoteDataItem != null) { - etName.setText(mFocusNoteDataItem.getSnippet()); + etName.setText(mFocusNoteDataItem.getSnippet()); // 显示之前的名称 builder.setTitle(getString(R.string.menu_folder_change_name)); } else { Log.e(TAG, "The long click data item is null"); @@ -596,7 +720,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt etName.setText(""); 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.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { @@ -610,12 +738,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt public void onClick(View v) { hideSoftInput(etName); String name = etName.getText().toString(); + // 如果该名称已经存在 if (DataUtils.checkVisibleFolderName(mContentResolver, name)) { Toast.makeText(NotesListActivity.this, getString(R.string.folder_exist, name), Toast.LENGTH_LONG).show(); - etName.setSelection(0, etName.length()); + etName.setSelection(0, etName.length()); //全选输入文件名(准备修改/删除) return; } + // 更新数据库中文件夹名称 插入/修改 if (!create) { if (!TextUtils.isEmpty(name)) { ContentValues values = new ContentValues(); @@ -633,6 +763,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt values.put(NoteColumns.TYPE, Notes.TYPE_FOLDER); mContentResolver.insert(Notes.CONTENT_NOTE_URI, values); } + //关闭对话框 dialog.dismiss(); } }); @@ -646,7 +777,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt etName.addTextChangedListener(new TextWatcher() { public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub - } 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) { // TODO Auto-generated method stub - } }); } @Override public void onBackPressed() { + // 在list(清单界面)按回退键就会被捕捉到这里,执行这个函数 @zhoukexing 2024/1/2 19:33 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; mState = ListEditState.NOTE_LIST; - startAsyncNotesListQuery(); mTitleBar.setVisibility(View.GONE); + startAsyncNotesListQuery(); break; case CALL_RECORD_FOLDER: + case TRASH_FOLDER: mCurrentFolderId = Notes.ID_ROOT_FOLDER; mState = ListEditState.NOTE_LIST; 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) { Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); + // 根据不同大小类型的widget更新Widget + // 2023-12-18 21:41 if (appWidgetType == Notes.TYPE_WIDGET_2X) { intent.setClass(this, NoteWidgetProvider_2x.class); } else if (appWidgetType == Notes.TYPE_WIDGET_4X) { @@ -726,6 +869,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt super.onContextMenuClosed(menu); } + /** + * @Method onContextItemSelected + * @Date 2023/12/17 23:51 + * @param item + * @Author lenovo + * @Return boolean + * @Description 长按文件夹之后显示的文件夹菜单对应的后台程序 + */ @Override public boolean onContextItemSelected(MenuItem item) { if (mFocusNoteDataItem == null) { @@ -739,7 +890,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt case MENU_FOLDER_DELETE: AlertDialog.Builder builder = new AlertDialog.Builder(this); 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.setPositiveButton(android.R.string.ok, 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); } else if (mState == ListEditState.SUB_FOLDER) { 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) { getMenuInflater().inflate(R.menu.call_record_folder, menu); } else { 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; } + /** + * @Method onOptionsItemSelected + * @Date 2023/12/17 23:49 + * @param item + * @Author lenovo + * @Return boolean + * @Description 主界面菜单对应的后台程序 + */ @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_new_folder: { - showCreateOrModifyFolderDialog(true); - break; - } - case R.id.menu_export_text: { - exportNoteToText(); - break; - } - case R.id.menu_sync: { - if (isSyncMode()) { - if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) { - GTaskSyncService.startSync(this); - } else { - GTaskSyncService.cancelSync(this); - } + int itemId = item.getItemId(); + if (itemId == R.id.menu_new_folder) { + showCreateOrModifyFolderDialog(true); + } else if (itemId == R.id.menu_export_text) { + exportNoteToText(); + } else if (itemId == R.id.menu_sync) { + if (isSyncMode()) { + if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) { + GTaskSyncService.startSync(this); } else { - startPreferenceActivity(); + GTaskSyncService.cancelSync(this); } - break; - } - case R.id.menu_setting: { + } else { startPreferenceActivity(); - break; - } - case R.id.menu_new_note: { - createNewNote(); - break; } - case R.id.menu_search: - onSearchRequested(); - break; - default: - break; + } else if (itemId == R.id.menu_setting) { + startPreferenceActivity(); + } else if (itemId == R.id.menu_new_note) { + createNewNote(); + } 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; } + 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: 打开回收站 todo:添加30天后自动删除【时间】 + * @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 + /** + * @Method onSearchRequested + * @Date 2023/12/19 8:53 + * @Author lenovo + * @Return boolean + * @Description 打开搜索小部件 + */ public boolean onSearchRequested() { startSearch(null, false, null /* appData */, false); return true; } + /** + * @Method exportNoteToText + * @Date 2023/12/19 8:44 + * @Author lenovo + * @Return void + * @Description 将便签导出成文本 + */ private void exportNoteToText() { 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() { @Override + // 后台运行导出文本 protected Integer doInBackground(Void... unused) { return backup.exportToText(); } @Override + // 线程运行结束后的结果处理程序 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); builder.setTitle(NotesListActivity.this .getString(R.string.failed_sdcard_export)); @@ -903,6 +1152,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt break; case SUB_FOLDER: case CALL_RECORD_FOLDER: + case TRASH_FOLDER: if (item.getType() == Notes.TYPE_NOTE) { openNode(item); } 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() { String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?"; selection = (mState == ListEditState.NOTE_LIST) ? selection: diff --git a/src/java/net/micode/notes/ui/NotesListAdapter.java b/src/java/net/micode/notes/ui/NotesListAdapter.java new file mode 100644 index 0000000..7695caf --- /dev/null +++ b/src/java/net/micode/notes/ui/NotesListAdapter.java @@ -0,0 +1,273 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package net.micode.notes.ui; + + import android.content.Context; + import android.database.Cursor; + import android.util.Log; + import android.view.View; + import android.view.ViewGroup; + import android.widget.CursorAdapter; + + + import net.micode.notes.data.Notes; + + import java.util.Collection; + import java.util.HashMap; + import java.util.HashSet; + import java.util.Iterator; + + + /* + * 功能:直译为便签表连接器,继承了CursorAdapter,它为cursor和ListView提供了连接的桥梁。 + * 所以NotesListAdapter实现的是鼠标和编辑便签链接的桥梁 + */ + public class NotesListAdapter extends CursorAdapter { + private static final String TAG = "NotesListAdapter"; + private Context mContext; + private HashMap mSelectedIndex; + private int mNotesCount; //便签数 + private boolean mChoiceMode; //选择模式标记 + + /* + * 桌面widget的属性,包括编号和类型 + */ + public static class AppWidgetAttribute { + public int widgetId; + public int widgetType; + }; + + /* + * 函数功能:初始化便签链接器 + * 函数实现:根据传进来的内容设置相关变量 + */ + public NotesListAdapter(Context context) { + super(context, null); //父类对象置空 + mSelectedIndex = new HashMap(); //新建选项下标的hash表 + mContext = context; + mNotesCount = 0; + } + + @Override + /* + * 函数功能:新建一个视图来存储光标所指向的数据 + * 函数实现:使用兄弟类NotesListItem新建一个项目选项 + */ + public View newView(Context context, Cursor cursor, ViewGroup parent) { + return new NotesListItem(context); + } + + /* + * 函数功能:将已经存在的视图和鼠标指向的数据进行捆绑 + * 函数实现:如下注释 + */ + @Override + public void bindView(View view, Context context, Cursor cursor) { + if (view instanceof NotesListItem) { + //若view是NotesListItem的一个实例 + NoteItemData itemData = new NoteItemData(context, cursor); + ((NotesListItem) view).bind(context, itemData, mChoiceMode, + isSelectedItem(cursor.getPosition())); + //则新建一个项目选项并且用bind跟将view和鼠标,内容,便签数据捆绑在一起 + } + } + + /* + * 函数功能:设置勾选框 + * 函数实现:如下注释 + */ + public void setCheckedItem(final int position, final boolean checked) { + mSelectedIndex.put(position, checked); + //根据定位和是否勾选设置下标 + notifyDataSetChanged(); + //在修改后刷新activity + } + + /* + * 函数功能:判断单选按钮是否勾选 + */ + public boolean isInChoiceMode() { + return mChoiceMode; + } + + /* + * 函数功能:设置单项选项框 + * 函数实现:重置下标并且根据参数mode设置选项 + */ + public void setChoiceMode(boolean mode) { + mSelectedIndex.clear(); + mChoiceMode = mode; + } + + /* + * 函数功能:选择全部选项 + * 函数实现:如下注释 + */ + public void selectAll(boolean checked) { + Cursor cursor = getCursor(); + //获取光标位置 + for (int i = 0; i < getCount(); i++) { + if (cursor.moveToPosition(i)) { + if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) { + setCheckedItem(i, checked); + } + } + } + //遍历所有光标可用的位置在判断为便签类型之后勾选单项框 + } + + /* + * 函数功能:建立选择项的下标列表 + * 函数实现:如下注释 + */ + public HashSet getSelectedItemIds() { + HashSet itemSet = new HashSet(); + //建立hash表 + for (Integer position : mSelectedIndex.keySet()) { + //遍历所有的关键 + if (mSelectedIndex.get(position) == true) { + //若光标位置可用 + Long id = getItemId(position); + if (id == Notes.ID_ROOT_FOLDER) { + //原文件不需要添加 + Log.d(TAG, "Wrong item id, should not happen"); + } else { + itemSet.add(id); + } + //则将id该下标假如选项集合中 + + } + } + + return itemSet; + } + + /* + * 函数功能:建立桌面Widget的选项表 + * 函数实现:如下注释 + */ + public HashSet getSelectedWidget() { + HashSet itemSet = new HashSet(); + for (Integer position : mSelectedIndex.keySet()) { + if (mSelectedIndex.get(position) == true) { + Cursor c = (Cursor) getItem(position); + //以上4句和getSelectedItemIds一样,不再重复 + if (c != null) { + //光标位置可用的话就建立新的Widget属性并编辑下标和类型,最后添加到选项集中 + AppWidgetAttribute widget = new AppWidgetAttribute(); + NoteItemData item = new NoteItemData(mContext, c); + widget.widgetId = item.getWidgetId(); + widget.widgetType = item.getWidgetType(); + itemSet.add(widget); + /** + * Don't close cursor here, only the adapter could close it + */ + } else { + Log.e(TAG, "Invalid cursor"); + return null; + } + } + } + return itemSet; + } + + /* + * 函数功能:获取选项个数 + * 函数实现:如下注释 + */ + public int getSelectedCount() { + Collection values = mSelectedIndex.values(); + //首先获取选项下标的值 + if (null == values) { + return 0; + } + Iterator iter = values.iterator(); + //初始化叠加器 + int count = 0; + while (iter.hasNext()) { + if (true == iter.next()) { + //若value值为真计数+1 + count++; + } + } + return count; + } + + /* + * 函数功能:判断是否全部选中 + * 函数实现:如下注释 + */ + public boolean isAllSelected() { + int checkedCount = getSelectedCount(); + return (checkedCount != 0 && checkedCount == mNotesCount); + //获取选项数看是否等于便签的个数 + } + + /* + * 函数功能:判断是否为选项表 + * 函数实现:通过传递的下标来确定 + */ + public boolean isSelectedItem(final int position) { + if (null == mSelectedIndex.get(position)) { + return false; + } + return mSelectedIndex.get(position); + } + + @Override + /* + * 函数功能:在activity内容发生局部变动的时候回调该函数计算便签的数量 + * 函数实现:如下注释 + */ + protected void onContentChanged() { + super.onContentChanged(); + //执行基类函数 + calcNotesCount(); + } + + @Override + /* + * 函数功能:在activity光标发生局部变动的时候回调该函数计算便签的数量 + */ + public void changeCursor(Cursor cursor) { + super.changeCursor(cursor); + //执行基类函数 + calcNotesCount(); + } + + /* + * 函数功能:计算便签数量 + * + */ + private void calcNotesCount() { + mNotesCount = 0; + for (int i = 0; i < getCount(); i++) { + //获取总数同时遍历 + Cursor c = (Cursor) getItem(i); + if (c != null) { + if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) { + mNotesCount++; + //若该位置不为空并且文本类型为便签就+1 + } + } else { + Log.e(TAG, "Invalid cursor"); + return; + } + //否则报错 + } + } + } diff --git a/src/java/net/micode/notes/ui/NotesListItem.java b/src/java/net/micode/notes/ui/NotesListItem.java new file mode 100644 index 0000000..dcf695a --- /dev/null +++ b/src/java/net/micode/notes/ui/NotesListItem.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package net.micode.notes.ui; + + import android.content.Context; + import android.text.format.DateUtils; + import android.view.View; + import android.widget.CheckBox; + import android.widget.ImageView; + import android.widget.LinearLayout; + import android.widget.TextView; + + import net.micode.notes.R; + import net.micode.notes.data.Notes; + import net.micode.notes.tool.DataUtils; + import net.micode.notes.tool.ResourceParser.NoteItemBgResources; + + + //创建便签列表项目选项 + public class NotesListItem extends LinearLayout { + private ImageView mAlert;//闹钟图片 + private TextView mTitle; //标题 + private TextView mTime; //时间 + private TextView mCallName; // + private NoteItemData mItemData; //标签数据 + private CheckBox mCheckBox; //打钩框 + + /*初始化基本信息*/ + public NotesListItem(Context context) { + super(context); //super()它的主要作用是调整调用父类构造函数的顺序 + inflate(context, R.layout.note_item, this);//Inflate可用于将一个xml中定义的布局控件找出来,这里的xml是r。layout + //findViewById用于从contentView中查找指定ID的View,转换出来的形式根据需要而定; + mAlert = (ImageView) findViewById(R.id.iv_alert_icon); + mTitle = (TextView) findViewById(R.id.tv_title); + mTime = (TextView) findViewById(R.id.tv_time); + mCallName = (TextView) findViewById(R.id.tv_name); + mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); + } + ///根据data的属性对各个控件的属性的控制,主要是可见性Visibility,内容setText,格式setTextAppearance + public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) { + if (choiceMode && data.getType() == Notes.TYPE_NOTE) { + mCheckBox.setVisibility(View.VISIBLE); ///设置可见行为可见 + mCheckBox.setChecked(checked); ///格子打钩 + } else { + mCheckBox.setVisibility(View.GONE); + } + + mItemData = data; + ///设置控件属性,一共三种情况,由data的id和父id是否与保存到文件夹的id一致来决定 + if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) { + mCallName.setVisibility(View.GONE); + mAlert.setVisibility(View.VISIBLE); + //设置该textview的style + mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); + //settext为设置内容 + mTitle.setText(context.getString(R.string.call_record_folder_name) + + context.getString(R.string.format_folder_files_count, data.getNotesCount())); + mAlert.setImageResource(R.drawable.call_record); + } else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) { + mCallName.setVisibility(View.VISIBLE); + mCallName.setText(data.getCallName()); + mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem); + mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); + ///关于闹钟的设置 + if (data.hasAlert()) { + mAlert.setImageResource(R.drawable.clock);//图片来源的设置 + mAlert.setVisibility(View.VISIBLE); + } else { + mAlert.setVisibility(View.GONE); + } + } else { + mCallName.setVisibility(View.GONE); + mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); + ///设置title格式 + if (data.getType() == Notes.TYPE_FOLDER) { + mTitle.setText(data.getSnippet() + + context.getString(R.string.format_folder_files_count, + data.getNotesCount())); + mAlert.setVisibility(View.GONE); + } else { + mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); + if (data.hasAlert()) { + mAlert.setImageResource(R.drawable.clock);///设置图片来源 + mAlert.setVisibility(View.VISIBLE); + } else { + mAlert.setVisibility(View.GONE); + } + } + } + ///设置内容,获取相关时间,从data里编辑的日期中获取 + mTime. setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate())); + + setBackground(data); + } + //根据data的文件属性来设置背景 + private void setBackground(NoteItemData data) { + int id = data.getBgColorId(); + //,若是note型文件,则4种情况,对于4种不同情况的背景来源 + 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 { + //若不是note直接调用文件夹的背景来源 + setBackgroundResource(NoteItemBgResources.getFolderBgRes()); + } + } + public NoteItemData getItemData() { + return mItemData; + } + } diff --git a/src/java/net/micode/notes/ui/NotesPreferenceActivity.java b/src/java/net/micode/notes/ui/NotesPreferenceActivity.java new file mode 100644 index 0000000..4efd25e --- /dev/null +++ b/src/java/net/micode/notes/ui/NotesPreferenceActivity.java @@ -0,0 +1,530 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package net.micode.notes.ui; + + import android.accounts.Account; + import android.accounts.AccountManager; + import android.app.ActionBar; + import android.app.AlertDialog; + import android.content.BroadcastReceiver; + import android.content.ContentValues; + import android.content.Context; + import android.content.DialogInterface; + import android.content.Intent; + import android.content.IntentFilter; + import android.content.SharedPreferences; + import android.os.Bundle; + import android.preference.Preference; + import android.preference.Preference.OnPreferenceClickListener; + import android.preference.PreferenceActivity; + import android.preference.PreferenceCategory; + import android.text.TextUtils; + import android.text.format.DateFormat; + import android.view.LayoutInflater; + import android.view.Menu; + import android.view.MenuItem; + import android.view.View; + import android.widget.Button; + import android.widget.TextView; + import android.widget.Toast; + + import net.micode.notes.R; + import net.micode.notes.data.Notes; + import net.micode.notes.data.Notes.NoteColumns; + import net.micode.notes.gtask.remote.GTaskSyncService; + + /* + *该类功能:NotesPreferenceActivity,在小米便签中主要实现的是对背景颜色和字体大小的数据储存。 + * 继承了PreferenceActivity主要功能为对系统信息和配置进行自动保存的Activity + */ + public class NotesPreferenceActivity extends PreferenceActivity { + public static final String PREFERENCE_NAME = "notes_preferences"; + //优先名 + public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name"; + //同步账号 + public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time"; + //同步时间 + public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear"; + + private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key"; + //同步密码 + private static final String AUTHORITIES_FILTER_KEY = "authorities"; + //本地密码 + private PreferenceCategory mAccountCategory; + //账户分组 + private GTaskReceiver mReceiver; + //同步任务接收器 + private Account[] mOriAccounts; + //账户 + private boolean mHasAddedAccount; + //账户的hash标记 + + @Override + /* + *函数功能:创建一个activity,在函数里要完成所有的正常静态设置 + *参数:Bundle icicle:存放了 activity 当前的状态 + *函数实现:如下注释 + */ + protected void onCreate(Bundle icicle) { + //先执行父类的创建函数 + super.onCreate(icicle); + + /* using the app icon for navigation */ + getActionBar().setDisplayHomeAsUpEnabled(true); + //给左上角图标的左边加上一个返回的图标 + + addPreferencesFromResource(R.xml.preferences); + //添加xml来源并显示 xml + mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY); + //根据同步账户关键码来初始化分组 + mReceiver = new GTaskReceiver(); + IntentFilter filter = new IntentFilter(); + filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME); + registerReceiver(mReceiver, filter); + //初始化同步组件 + + mOriAccounts = null; + View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null); + //获取listvivew,ListView的作用:用于列出所有选择 + getListView().addHeaderView(header, null, true); + //在listview组件上方添加其他组件 + } + + @Override + /* + * 函数功能:activity交互功能的实现,用于接受用户的输入 + * 函数实现:如下注释 + */ + protected void onResume() { + //先执行父类 的交互实现 + super.onResume(); + + // need to set sync account automatically if user has added a new + // account + if (mHasAddedAccount) { + //若用户新加了账户则自动设置同步账户 + Account[] accounts = getGoogleAccounts(); + //获取google同步账户 + if (mOriAccounts != null && accounts.length > mOriAccounts.length) { + //若原账户不为空且当前账户有增加 + for (Account accountNew : accounts) { + boolean found = false; + for (Account accountOld : mOriAccounts) { + if (TextUtils.equals(accountOld.name, accountNew.name)) { + //更新账户 + found = true; + break; + } + } + if (!found) { + setSyncAccount(accountNew.name); + //若是没有找到旧的账户,那么同步账号中就只添加新账户 + break; + } + } + } + } + + refreshUI(); + //刷新标签界面 + } + + @Override + /* + * 函数功能:销毁一个activity + * 函数实现:如下注释 + */ + protected void onDestroy() { + if (mReceiver != null) { + unregisterReceiver(mReceiver); + //注销接收器 + } + super.onDestroy(); + //执行父类的销毁动作 + } + + /* + * 函数功能:重新设置账户信息 + * 函数实现:如下注释 + */ + private void loadAccountPreference() { + mAccountCategory.removeAll(); + //销毁所有的分组 + Preference accountPref = new Preference(this); + //建立首选项 + final String defaultAccount = getSyncAccountName(this); + accountPref.setTitle(getString(R.string.preferences_account_title)); + accountPref.setSummary(getString(R.string.preferences_account_summary)); + //设置首选项的大标题和小标题 + accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { + public boolean onPreferenceClick(Preference preference) { + //建立监听器 + if (!GTaskSyncService.isSyncing()) { + if (TextUtils.isEmpty(defaultAccount)) { + // the first time to set account + //若是第一次建立账户显示选择账户提示对话框 + showSelectAccountAlertDialog(); + } else { + // if the account has already been set, we need to promp + // user about the risk + //若是已经建立则显示修改对话框并进行修改操作 + showChangeAccountConfirmAlertDialog(); + } + } else { + //若在没有同步的情况下,则在toast中显示不能修改 + Toast.makeText(NotesPreferenceActivity.this, + R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT) + .show(); + } + return true; + } + }); + + //根据新建首选项编辑新的账户分组 + mAccountCategory.addPreference(accountPref); + } + + /* + *函数功能:设置按键的状态和最后同步的时间 + *函数实现:如下注释 + */ + private void loadSyncButton() { + Button syncButton = (Button) findViewById(R.id.preference_sync_button); + TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview); + //获取同步按钮控件和最终同步时间的的窗口 + // set button state + //设置按钮的状态 + if (GTaskSyncService.isSyncing()) { + //若是在同步状态下 + syncButton.setText(getString(R.string.preferences_button_sync_cancel)); + syncButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + GTaskSyncService.cancelSync(NotesPreferenceActivity.this); + } + }); + //设置按钮显示的文本为“取消同步”以及监听器 + } else { + syncButton.setText(getString(R.string.preferences_button_sync_immediately)); + syncButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + GTaskSyncService.startSync(NotesPreferenceActivity.this); + } + }); + //若是不同步则设置按钮显示的文本为“立即同步”以及对应监听器 + } + syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this))); + //设置按键可用还是不可用 + + // set last sync time + // 设置最终同步时间 + if (GTaskSyncService.isSyncing()) { + //若是在同步的情况下 + lastSyncTimeView.setText(GTaskSyncService.getProgressString()); + lastSyncTimeView.setVisibility(View.VISIBLE); + // 根据当前同步服务器设置时间显示框的文本以及可见性 + } else { + //若是非同步情况 + long lastSyncTime = getLastSyncTime(this); + if (lastSyncTime != 0) { + lastSyncTimeView.setText(getString(R.string.preferences_last_sync_time, + DateFormat.format(getString(R.string.preferences_last_sync_time_format), + lastSyncTime))); + lastSyncTimeView.setVisibility(View.VISIBLE); + //则根据最后同步时间的信息来编辑时间显示框的文本内容和可见性 + } else { + //若时间为空直接设置为不可见状态 + lastSyncTimeView.setVisibility(View.GONE); + } + } + } + /* + *函数功能:刷新标签界面 + *函数实现:调用上文设置账号和设置按键两个函数来实现 + */ + private void refreshUI() { + loadAccountPreference(); + loadSyncButton(); + } + + /* + * 函数功能:显示账户选择的对话框并进行账户的设置 + * 函数实现:如下注释 + */ + private void showSelectAccountAlertDialog() { + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); + //创建一个新的对话框 + + View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null); + TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title); + titleTextView.setText(getString(R.string.preferences_dialog_select_account_title)); + TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle); + subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips)); + //设置标题以及子标题的内容 + dialogBuilder.setCustomTitle(titleView); + dialogBuilder.setPositiveButton(null, null); + //设置对话框的自定义标题,建立一个YES的按钮 + Account[] accounts = getGoogleAccounts(); + String defAccount = getSyncAccountName(this); + //获取同步账户信息 + mOriAccounts = accounts; + mHasAddedAccount = false; + + if (accounts.length > 0) { + //若账户不为空 + CharSequence[] items = new CharSequence[accounts.length]; + final CharSequence[] itemMapping = items; + int checkedItem = -1; + int index = 0; + for (Account account : accounts) { + if (TextUtils.equals(account.name, defAccount)) { + checkedItem = index; + //在账户列表中查询到所需账户 + } + items[index++] = account.name; + } + dialogBuilder.setSingleChoiceItems(items, checkedItem, + //在对话框建立一个单选的复选框 + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + setSyncAccount(itemMapping[which].toString()); + dialog.dismiss(); + //取消对话框 + refreshUI(); + } + //设置点击后执行的事件,包括检录新同步账户和刷新标签界面 + }); + //建立对话框网络版的监听器 + } + + View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null); + dialogBuilder.setView(addAccountView); + //给新加账户对话框设置自定义样式 + + final AlertDialog dialog = dialogBuilder.show(); + //显示对话框 + addAccountView.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + mHasAddedAccount = true; + //将新加账户的hash置true + Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS"); + //建立网络建立组件 + intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] { + "gmail-ls" + }); + startActivityForResult(intent, -1); + //跳回上一个选项 + dialog.dismiss(); + } + }); + //建立新加账户对话框的监听器 + } + + /* + * 函数功能:显示账户选择对话框和相关账户操作 + * 函数实现:如下注释 + */ + private void showChangeAccountConfirmAlertDialog() { + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); + //创建一个新的对话框 + View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null); + TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title); + titleTextView.setText(getString(R.string.preferences_dialog_change_account_title, + getSyncAccountName(this))); + TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle); + subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg)); + //根据同步修改的账户信息设置标题以及子标题的内容 + dialogBuilder.setCustomTitle(titleView); + //设置对话框的自定义标题 + CharSequence[] menuItemArray = new CharSequence[] { + getString(R.string.preferences_menu_change_account), + getString(R.string.preferences_menu_remove_account), + getString(R.string.preferences_menu_cancel) + }; + //定义一些标记字符串 + dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() { + //设置对话框要显示的一个list,用于显示几个命令时,即change,remove,cancel + public void onClick(DialogInterface dialog, int which) { + //按键功能,由which来决定 + if (which == 0) { + //进入账户选择对话框 + showSelectAccountAlertDialog(); + } else if (which == 1) { + //删除账户并且跟新便签界面 + removeSyncAccount(); + refreshUI(); + } + } + }); + dialogBuilder.show(); + //显示对话框 + } + + /* + *函数功能:获取谷歌账户 + *函数实现:通过账户管理器直接获取 + */ + private Account[] getGoogleAccounts() { + AccountManager accountManager = AccountManager.get(this); + return accountManager.getAccountsByType("com.google"); + } + + /* + * 函数功能:设置同步账户 + * 函数实现:如下注释: + */ + private void setSyncAccount(String account) { + if (!getSyncAccountName(this).equals(account)) { + //假如该账号不在同步账号列表中 + SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = settings.edit(); + //编辑共享的首选项 + if (account != null) { + editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account); + } else { + editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, ""); + } + //将该账号加入到首选项中 + + editor.commit(); + //提交修改的数据 + + + setLastSyncTime(this, 0); + //将最后同步时间清零 + + // clean up local gtask related info + new Thread(new Runnable() { + public void run() { + ContentValues values = new ContentValues(); + values.put(NoteColumns.GTASK_ID, ""); + values.put(NoteColumns.SYNC_ID, 0); + getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null); + } + }).start(); + //重置当地同步任务的信息 + + Toast.makeText(NotesPreferenceActivity.this, + getString(R.string.preferences_toast_success_set_accout, account), + Toast.LENGTH_SHORT).show(); + //将toast的文本信息置为“设置账户成功”并显示出来 + } + } + /* + * 函数功能:删除同步账户 + * 函数实现:如下注释: + */ + private void removeSyncAccount() { + SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = settings.edit(); + //设置共享首选项 + + if (settings.contains(PREFERENCE_SYNC_ACCOUNT_NAME)) { + editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME); + //假如当前首选项中有账户就删除 + } + if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) { + editor.remove(PREFERENCE_LAST_SYNC_TIME); + //删除当前首选项中有账户时间 + } + editor.commit(); + //提交更新后的数据 + + // clean up local gtask related info + new Thread(new Runnable() { + public void run() { + ContentValues values = new ContentValues(); + values.put(NoteColumns.GTASK_ID, ""); + values.put(NoteColumns.SYNC_ID, 0); + getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null); + } + }).start(); + //重置当地同步任务的信息 + } + + /* + * 函数功能:获取同步账户名称 + * 函数实现:通过共享的首选项里的信息直接获取 + */ + public static String getSyncAccountName(Context context) { + SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, + Context.MODE_PRIVATE); + return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, ""); + } + + /* + * 函数功能:设置最终同步的时间 + * 函数实现:如下注释 + */ + public static void setLastSyncTime(Context context, long time) { + SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, + Context.MODE_PRIVATE); + SharedPreferences.Editor editor = settings.edit(); + // 从共享首选项中找到相关账户并获取其编辑器 + editor.putLong(PREFERENCE_LAST_SYNC_TIME, time); + editor.commit(); + //编辑最终同步时间并提交更新 + } + /* + * 函数功能:获取最终同步时间 + * 函数实现:通过共享的首选项里的信息直接获取 + */ + public static long getLastSyncTime(Context context) { + SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, + Context.MODE_PRIVATE); + return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0); + } + + /* + * 函数功能:接受同步信息 + * 函数实现:继承BroadcastReceiver + */ + private class GTaskReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + refreshUI(); + if (intent.getBooleanExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_IS_SYNCING, false)) { + //获取随广播而来的Intent中的同步服务的数据 + TextView syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview); + syncStatus.setText(intent + .getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG)); + //通过获取的数据在设置系统的状态 + } + + } + } + + /* + * 函数功能:处理菜单的选项 + * 函数实现:如下注释 + * 参数:MenuItem菜单选项 + */ + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + //根据选项的id选择,这里只有一个主页 + case android.R.id.home: + Intent intent = new Intent(this, NotesListActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); + return true; + //在主页情况下在创建连接组件intent,发出清空的信号并开始一个相应的activity + default: + return false; + } + } + } + diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider.java b/src/java/net/micode/notes/widget/NoteWidgetProvider.java similarity index 88% rename from src/Notes-master/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider.java rename to src/java/net/micode/notes/widget/NoteWidgetProvider.java index ec6f819..e5659bc 100644 --- a/src/Notes-master/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider.java +++ b/src/java/net/micode/notes/widget/NoteWidgetProvider.java @@ -32,11 +32,20 @@ import net.micode.notes.tool.ResourceParser; import net.micode.notes.ui.NoteEditActivity; 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 static final String [] PROJECTION = new String [] { - NoteColumns.ID, - NoteColumns.BG_COLOR_ID, - NoteColumns.SNIPPET + NoteColumns.ID, + NoteColumns.BG_COLOR_ID, + NoteColumns.SNIPPET }; public static final int COLUMN_ID = 0; @@ -45,6 +54,12 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { private static final String TAG = "NoteWidgetProvider"; + /** + * @method onDeleted + * @description 该方法用于删除Widget + * @date: 2024-12-18 21:18 + * @return void + */ @Override public void onDeleted(Context context, int[] appWidgetIds) { ContentValues values = new ContentValues(); @@ -65,12 +80,18 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { null); } + /** + * @method update + * @description 该方法用于添加或更新Widget + * @date: 2024-12-18 21:11 + * @return void + */ protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { update(context, appWidgetManager, appWidgetIds, false); } private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, - boolean privacyMode) { + boolean privacyMode) { for (int i = 0; i < appWidgetIds.length; i++) { if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) { int bgId = ResourceParser.getDefaultBgId(context); diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_2x.java b/src/java/net/micode/notes/widget/NoteWidgetProvider_2x.java similarity index 100% rename from src/Notes-master/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_2x.java rename to src/java/net/micode/notes/widget/NoteWidgetProvider_2x.java diff --git a/src/Notes-master/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_4x.java b/src/java/net/micode/notes/widget/NoteWidgetProvider_4x.java similarity index 100% rename from src/Notes-master/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_4x.java rename to src/java/net/micode/notes/widget/NoteWidgetProvider_4x.java diff --git a/src/Notes-master/Notes-master/res/color/primary_text_dark.xml b/src/res/color/primary_text_dark.xml similarity index 94% rename from src/Notes-master/Notes-master/res/color/primary_text_dark.xml rename to src/res/color/primary_text_dark.xml index 7c85459..8ad98e3 100644 --- a/src/Notes-master/Notes-master/res/color/primary_text_dark.xml +++ b/src/res/color/primary_text_dark.xml @@ -1,4 +1,4 @@ - + + + + + + \ No newline at end of file diff --git a/src/Notes-master/Notes-master/res/raw-zh-rCN/introduction b/src/res/raw-zh-rCN/introduction similarity index 100% rename from src/Notes-master/Notes-master/res/raw-zh-rCN/introduction rename to src/res/raw-zh-rCN/introduction diff --git a/src/Notes-master/Notes-master/res/raw/introduction b/src/res/raw/introduction similarity index 100% rename from src/Notes-master/Notes-master/res/raw/introduction rename to src/res/raw/introduction diff --git a/src/Notes-master/Notes-master/res/values-zh-rCN/arrays.xml b/src/res/values-zh-rCN/arrays.xml similarity index 100% rename from src/Notes-master/Notes-master/res/values-zh-rCN/arrays.xml rename to src/res/values-zh-rCN/arrays.xml diff --git a/src/Notes-master/Notes-master/res/values-zh-rCN/strings.xml b/src/res/values-zh-rCN/strings.xml similarity index 83% rename from src/Notes-master/Notes-master/res/values-zh-rCN/strings.xml rename to src/res/values-zh-rCN/strings.xml index 09f75ed..a27a57b 100644 --- a/src/Notes-master/Notes-master/res/values-zh-rCN/strings.xml +++ b/src/res/values-zh-rCN/strings.xml @@ -42,7 +42,11 @@ 取消同步 设置 搜索 + 回收站 删除 + 白天模式 + 夜间模式 + 清空回收站 移动到文件夹 选中了 %d 项 没有选中项,操作无效 @@ -62,14 +66,22 @@ 分享 发送到桌面 提醒我 + 撤回 + 提示 + 无法撤回任何文本 + 截图 删除提醒 选择文件夹 上一级文件夹 已添加到桌面 删除 - 确认要删除所选的 %d 条便签吗? - 确认要删除该条便签吗? - 确认删除文件夹及所包含的便签吗? + 确认要删除所选的 %d 条便签吗?(将在回收站保存30天) + 确认要删除该条便签吗?(将在回收站保存30天) + 确认删除文件夹及所包含的便签吗?(将在回收站保存30天) + 确认删除文件夹及所包含的便签吗? + 删除 + 确认要删除所选的 %d 条便签吗? + 确认要删除该条便签吗? 已将所选 %1$d 条便签移到 %2$s 文件夹 SD卡被占用,不能操作 @@ -77,6 +89,8 @@ 要查看的便签不存在 不能为空便签设置闹钟提醒 不能将空便签发送到桌面 + "成功保存截图至 + 保存截图失败 导出成功 导出失败 已将文本文件(%1$s)输出至SD卡(%2$s)目录 @@ -113,6 +127,11 @@ 删除 通话便签 请输入名称 + + 长度 + 置顶 + 置顶 + 取消置顶 正在搜索便签 搜索便签 便签中的文字 @@ -122,5 +141,7 @@ %1$s 条符合“%2$s”的搜索结果 + 统计便签个数 + 设置字体 diff --git a/src/Notes-master/Notes-master/res/values-zh-rTW/arrays.xml b/src/res/values-zh-rTW/arrays.xml similarity index 100% rename from src/Notes-master/Notes-master/res/values-zh-rTW/arrays.xml rename to src/res/values-zh-rTW/arrays.xml diff --git a/src/Notes-master/Notes-master/res/values-zh-rTW/strings.xml b/src/res/values-zh-rTW/strings.xml similarity index 83% rename from src/Notes-master/Notes-master/res/values-zh-rTW/strings.xml rename to src/res/values-zh-rTW/strings.xml index 3c41894..f90fc9b 100644 --- a/src/Notes-master/Notes-master/res/values-zh-rTW/strings.xml +++ b/src/res/values-zh-rTW/strings.xml @@ -1,4 +1,4 @@ - + 新建文件夾 @@ -43,7 +47,9 @@ 取消同步 設置 搜尋 + 回收站 刪除 + 清空回收站 移動到文件夾 選中了 %d 項 沒有選中項,操作無效 @@ -63,14 +69,18 @@ 分享 發送到桌面 提醒我 + 撤销 + 提示 + 没有可撤销的内容 + 截屏 刪除提醒 選擇文件夾 上一級文件夾 已添加到桌面 刪除 - 确认要刪除所選的 %d 條便籤嗎? - 确认要删除該條便籤嗎? - 確認刪除檔夾及所包含的便簽嗎? + 确认要删除所选的 %d 条便签吗?(将在回收站保存30天) + 确认要删除该条便签吗?(将在回收站保存30天) + 确认删除文件夹及所包含的便签吗?(将在回收站保存30天) SD卡被佔用,不能操作 導出TXT時發生錯誤,請檢查SD卡 要查看的便籤不存在 @@ -114,6 +124,11 @@ 通話便籤 請輸入名稱 + + 長度 + 置頂 + 置頂 + 取消置頂 正在搜索便籤 搜索便籤 便籤中的文字 @@ -123,5 +138,7 @@ %1$s 條符合”%2$s“的搜尋結果 + 统计便签个数 + 设置字体 diff --git a/src/Notes-master/Notes-master/res/values/arrays.xml b/src/res/values/arrays.xml similarity index 100% rename from src/Notes-master/Notes-master/res/values/arrays.xml rename to src/res/values/arrays.xml diff --git a/src/Notes-master/Notes-master/res/values/colors.xml b/src/res/values/colors.xml similarity index 100% rename from src/Notes-master/Notes-master/res/values/colors.xml rename to src/res/values/colors.xml diff --git a/src/Notes-master/Notes-master/res/values/dimens.xml b/src/res/values/dimens.xml similarity index 100% rename from src/Notes-master/Notes-master/res/values/dimens.xml rename to src/res/values/dimens.xml diff --git a/src/Notes-master/Notes-master/res/values/strings.xml b/src/res/values/strings.xml similarity index 82% rename from src/Notes-master/Notes-master/res/values/strings.xml rename to src/res/values/strings.xml index 55df868..645a3b7 100644 --- a/src/Notes-master/Notes-master/res/values/strings.xml +++ b/src/res/values/strings.xml @@ -36,17 +36,22 @@ Browse web Open map - /MIUI/notes/ - notes_%s.txt + /MIUI/notes/ + notes_%s.txt - (%d) + (%d) New Folder Export text Sync Cancel syncing Settings Search + Trash Folder + Count Notes + Day Mode + Night Mode Delete + Empty Trash Move to folder %d selected Nothing selected, the operation is invalid @@ -66,6 +71,11 @@ Share Send to home Remind me + Revoke text + Tip + You cannot revoke anything + Screenshot + Set font style Delete reminder Select folder Parent folder @@ -74,6 +84,10 @@ Delete selected notes Confirm to delete the selected %d notes? Confirm to delete this note? + Confirm to delete folder and its notes? + Delete selected notes + Confirm to delete the selected %d notes? + Confirm to delete this note? Have moved selected %1$d notes to %2$s folder SD card busy, not available now @@ -81,6 +95,8 @@ The note is not exist Sorry, can not set clock on empty note Sorry, can not send and empty note to home + "Successfully saved the screenshot to + Failed to save screenshot Export successful Export fail Export text file (%1$s) to SD (%2$s) directory @@ -101,7 +117,7 @@ Sync account Sync notes with google task Last sync time %1$s - yyyy-MM-dd hh:mm:ss + yyyy-MM-dd hh:mm:ss Add account Change sync account Remove sync account @@ -120,6 +136,11 @@ Call notes Input name + + Length + Set Top + Set Top + Canel Top Searching Notes Search notes Text in your notes diff --git a/src/Notes-master/Notes-master/res/values/styles.xml b/src/res/values/styles.xml similarity index 95% rename from src/Notes-master/Notes-master/res/values/styles.xml rename to src/res/values/styles.xml index d750e65..16bebc2 100644 --- a/src/Notes-master/Notes-master/res/values/styles.xml +++ b/src/res/values/styles.xml @@ -63,7 +63,7 @@ \ No newline at end of file diff --git a/src/Notes-master/Notes-master/res/xml/preferences.xml b/src/res/xml/preferences.xml similarity index 100% rename from src/Notes-master/Notes-master/res/xml/preferences.xml rename to src/res/xml/preferences.xml diff --git a/src/Notes-master/Notes-master/res/xml/searchable.xml b/src/res/xml/searchable.xml similarity index 100% rename from src/Notes-master/Notes-master/res/xml/searchable.xml rename to src/res/xml/searchable.xml diff --git a/src/Notes-master/Notes-master/res/xml/widget_2x_info.xml b/src/res/xml/widget_2x_info.xml similarity index 100% rename from src/Notes-master/Notes-master/res/xml/widget_2x_info.xml rename to src/res/xml/widget_2x_info.xml diff --git a/src/Notes-master/Notes-master/res/xml/widget_4x_info.xml b/src/res/xml/widget_4x_info.xml similarity index 100% rename from src/Notes-master/Notes-master/res/xml/widget_4x_info.xml rename to src/res/xml/widget_4x_info.xml