diff --git a/MiNote/app/src/main/java/net/micode/notes/data/Contact.java b/MiNote/app/src/main/java/net/micode/notes/data/Contact.java index d97ac5d..6fcd914 100644 --- a/MiNote/app/src/main/java/net/micode/notes/data/Contact.java +++ b/MiNote/app/src/main/java/net/micode/notes/data/Contact.java @@ -25,10 +25,12 @@ import android.util.Log; import java.util.HashMap; +// 联系人 public class Contact { private static HashMap sContactCache; private static final String TAG = "Contact"; + // 定义字符串CALLER_ID_SELECTION private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER + ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'" + " AND " + Data.RAW_CONTACT_ID + " IN " @@ -36,17 +38,20 @@ public class Contact { + " FROM phone_lookup" + " WHERE min_match = '+')"; + // 获取联系人 public static String getContact(Context context, String phoneNumber) { if(sContactCache == null) { sContactCache = new HashMap(); } + // 查找HashMap中是否已有phoneNumber信息 if(sContactCache.containsKey(phoneNumber)) { return sContactCache.get(phoneNumber); } String selection = CALLER_ID_SELECTION.replace("+", PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); + // 查找数据库中phoneNumber的信息 Cursor cursor = context.getContentResolver().query( Data.CONTENT_URI, new String [] { Phone.DISPLAY_NAME }, @@ -54,17 +59,21 @@ public class Contact { new String[] { phoneNumber }, null); + // 判定查询结果 + // moveToFirst() 返回第一条 if (cursor != null && cursor.moveToFirst()) { try { String name = cursor.getString(0); sContactCache.put(phoneNumber, name); return name; + // 异常 } catch (IndexOutOfBoundsException e) { Log.e(TAG, " Cursor get string error " + e.toString()); return null; } finally { cursor.close(); } + // 未找到相关信息 } else { Log.d(TAG, "No contact matched with number:" + phoneNumber); return null; diff --git a/MiNote/app/src/main/java/net/micode/notes/data/Notes.java b/MiNote/app/src/main/java/net/micode/notes/data/Notes.java index f240604..00a0878 100644 --- a/MiNote/app/src/main/java/net/micode/notes/data/Notes.java +++ b/MiNote/app/src/main/java/net/micode/notes/data/Notes.java @@ -20,6 +20,8 @@ import android.net.Uri; public class Notes { public static final String AUTHORITY = "micode_notes"; public static final String TAG = "Notes"; + + // 以下三个常量在设置NoteColumns.TYPE的时会用到 public static final int TYPE_NOTE = 0; public static final int TYPE_FOLDER = 1; public static final int TYPE_SYSTEM = 2; @@ -54,13 +56,17 @@ public class Notes { /** * Uri to query all notes and folders */ - public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note"); + // 定义查询便签和文件夹的指针 + public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");// /** * Uri to query data */ + // 定义查找数据的指针 public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); + // 定义NoteColumns的常量,用于后面创建数据库的表头 + // 这些常量主要用于定义便签的属性 public interface NoteColumns { /** * The unique ID for a row @@ -167,6 +173,8 @@ public class Notes { public static final String VERSION = "version"; } + // 定义DataColumns的常量,用于后面创建数据库的表头 + // 主要用于定义储存便签内容数据 public interface DataColumns { /** * The unique ID for a row @@ -241,6 +249,7 @@ public class Notes { public static final String DATA5 = "data5"; } + // 文本内容的数据结构 public static final class TextNote implements DataColumns { /** * Mode to indicate the text in check list mode or not @@ -257,6 +266,7 @@ public class Notes { public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note"); } + // 电话内容的数据结构 public static final class CallNote implements DataColumns { /** * Call date for this record diff --git a/MiNote/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java b/MiNote/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java index ffe5d57..1f4e4f2 100644 --- a/MiNote/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java +++ b/MiNote/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java @@ -16,22 +16,23 @@ package net.micode.notes.data; -import android.content.ContentValues; -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; +import android.content.ContentValues;// 用于保存数据信息,这些信息可以被数据库操作时使用 +import android.content.Context;// 加载和访问资源 +import android.database.sqlite.SQLiteDatabase;// 主要提供了用于添加、删除、更新、查询的操作方法:insert(), delete(), update()和query()。配合content.values使用 +import android.database.sqlite.SQLiteOpenHelper;// 用于管理数据的创建和版本更新 import android.util.Log; import net.micode.notes.data.Notes.DataColumns; import net.micode.notes.data.Notes.DataConstants; import net.micode.notes.data.Notes.NoteColumns; - +// 数据库操作,用于SQLOpenHelper,对一些note和文件进行数据库的操作,比如删除文件时删除对应的note public class NotesDatabaseHelper extends SQLiteOpenHelper { private static final String DB_NAME = "note.db"; private static final int DB_VERSION = 4; + // 接口,分为note和data public interface TABLE { public static final String NOTE = "note"; @@ -42,6 +43,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { private static NotesDatabaseHelper mInstance; + // 数据库中需要存储的项目的名称,创建表头内容 private static final String CREATE_NOTE_TABLE_SQL = "CREATE TABLE " + TABLE.NOTE + "(" + NoteColumns.ID + " INTEGER PRIMARY KEY," + @@ -63,6 +65,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" + ")"; + // 同上,存储项目不同 private static final String CREATE_DATA_TABLE_SQL = "CREATE TABLE " + TABLE.DATA + "(" + DataColumns.ID + " INTEGER PRIMARY KEY," + @@ -78,6 +81,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" + ")"; + // 存储便签编号的数据表格 private static final String CREATE_DATA_NOTE_ID_INDEX_SQL = "CREATE INDEX IF NOT EXISTS note_id_index ON " + TABLE.DATA + "(" + DataColumns.NOTE_ID + ");"; @@ -85,6 +89,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Increase folder's note count when move note to the folder */ + // 在文件夹中移入一个Note之后需要更改的数据表格 private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = "CREATE TRIGGER increase_folder_count_on_update "+ " AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE + @@ -97,6 +102,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Decrease folder's note count when move note from folder */ + // 在文件夹中移出一个Note之后需要更改的数据表格 private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = "CREATE TRIGGER decrease_folder_count_on_update " + " AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE + @@ -110,6 +116,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Increase folder's note count when insert new note to the folder */ + // 在文件夹中插入一个Note之后需要更改的数据表格 private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER = "CREATE TRIGGER increase_folder_count_on_insert " + " AFTER INSERT ON " + TABLE.NOTE + @@ -122,6 +129,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Decrease folder's note count when delete note from the folder */ + // 在文件夹中删除一个Note之后需要更改的数据表格 private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER = "CREATE TRIGGER decrease_folder_count_on_delete " + " AFTER DELETE ON " + TABLE.NOTE + @@ -135,6 +143,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Update note's content when insert data with type {@link DataConstants#NOTE} */ + // 在文件夹中对于一个Note导入新的数据之后需要更改的数据表格 private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER = "CREATE TRIGGER update_note_content_on_insert " + " AFTER INSERT ON " + TABLE.DATA + @@ -148,6 +157,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Update note's content when data with {@link DataConstants#NOTE} type has changed */ + // Note数据被更改后需要修改的数据表格 private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER = "CREATE TRIGGER update_note_content_on_update " + " AFTER UPDATE ON " + TABLE.DATA + @@ -161,6 +171,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Update note's content when data with {@link DataConstants#NOTE} type has deleted */ + // Note数据被删除后需要修改的数据表格 private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER = "CREATE TRIGGER update_note_content_on_delete " + " AFTER delete ON " + TABLE.DATA + @@ -174,6 +185,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Delete datas belong to note which has been deleted */ + // 删除已删除的Note数据后需要修改的数据表格 private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER = "CREATE TRIGGER delete_data_on_delete " + " AFTER DELETE ON " + TABLE.NOTE + @@ -185,6 +197,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Delete notes belong to folder which has been deleted */ + // 删除已删除的文件夹的Note后需要修改的数据表格 private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER = "CREATE TRIGGER folder_delete_notes_on_delete " + " AFTER DELETE ON " + TABLE.NOTE + @@ -196,6 +209,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Move notes belong to folder which has been moved to trash folder */ + // 还原垃圾桶中Note后需要更改的数据表格 private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER = "CREATE TRIGGER folder_move_notes_on_trash " + " AFTER UPDATE ON " + TABLE.NOTE + @@ -206,10 +220,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + " END"; + // 构造函数,传入数据库的名称和版本 public NotesDatabaseHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); } + // 创建表格(用于存储标签属性) public void createNoteTable(SQLiteDatabase db) { db.execSQL(CREATE_NOTE_TABLE_SQL); reCreateNoteTableTriggers(db); @@ -217,6 +233,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { Log.d(TAG, "note table has been created"); } + /* + execSQL是数据库操作的API,主要是更改行为的SQL语句 + 在这里主要是用于重新创建上述定义表格,先删除原有的数据库的触发器再重新创建新的数据库 + */ private void reCreateNoteTableTriggers(SQLiteDatabase db) { db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update"); db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update"); @@ -235,6 +255,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER); } + // 创建系统文件夹 private void createSystemFolder(SQLiteDatabase db) { ContentValues values = new ContentValues(); @@ -270,6 +291,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); } + // 创建表格(用于存储标签内容) public void createDataTable(SQLiteDatabase db) { db.execSQL(CREATE_DATA_TABLE_SQL); reCreateDataTableTriggers(db); diff --git a/MiNote/app/src/main/java/net/micode/notes/ui/NotesListActivity.java b/MiNote/app/src/main/java/net/micode/notes/ui/NotesListActivity.java index 77a30b8..b1c77cc 100644 --- a/MiNote/app/src/main/java/net/micode/notes/ui/NotesListActivity.java +++ b/MiNote/app/src/main/java/net/micode/notes/ui/NotesListActivity.java @@ -81,6 +81,8 @@ import java.io.InputStreamReader; import java.util.HashSet; public class NotesListActivity extends AppCompatActivity implements OnClickListener, OnItemLongClickListener { +// 首页界面切换 + private int mode = 1; private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0; private static final int FOLDER_LIST_QUERY_TOKEN = 1; @@ -93,6 +95,8 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction"; + public static int secret_mode = 0; + private enum ListEditState { NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER }; @@ -141,6 +145,7 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.note_list); + getWindow().setBackgroundDrawableResource(R.drawable.flower); initResources(); /** @@ -413,10 +418,35 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe private void startAsyncNotesListQuery() { String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION : NORMAL_SELECTION; - 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"); + if(secret_mode == 0) { + 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"); + } + else{ + String str1 = "11111"; + String [] PROJECTION = new String [] { //定义一个新的PROJECTION数组,只换掉SNIPPET + NoteColumns.ID, + NoteColumns.ALERTED_DATE, + NoteColumns.BG_COLOR_ID, + NoteColumns.CREATED_DATE, + NoteColumns.HAS_ATTACHMENT, + NoteColumns.MODIFIED_DATE, + NoteColumns.NOTES_COUNT, + NoteColumns.PARENT_ID, +// NoteColumns.SNIPPET, + str1, + NoteColumns.TYPE, + NoteColumns.WIDGET_ID, + NoteColumns.WIDGET_TYPE, + }; + mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null, + Notes.CONTENT_NOTE_URI, PROJECTION, selection, new String[]{ + String.valueOf(mCurrentFolderId) + }, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC"); + + } } private final class BackgroundQueryHandler extends AsyncQueryHandler { @@ -765,8 +795,13 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe @Override public boolean onPrepareOptionsMenu(Menu menu) { menu.clear(); + if (mState == ListEditState.NOTE_LIST) { getMenuInflater().inflate(R.menu.note_list, menu); + if (secret_mode == 1) + menu.findItem(R.id.menu_secret).setVisible(false); + else + menu.findItem(R.id.menu_quit_secret).setVisible(false); // set sync or sync_cancel menu.findItem(R.id.menu_sync).setTitle( GTaskSyncService.isSyncing() ? R.string.menu_sync_cancel : R.string.menu_sync); @@ -777,6 +812,14 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe } else { Log.e(TAG, "Wrong state:" + mState); } + + if (mode == 1) { + menu.findItem(R.id.menu_flower).setVisible(false); + } else if (mode == 0) { + menu.findItem(R.id.menu_saying).setVisible(false); + } else if (mode == -1) { + menu.findItem(R.id.menu_water).setVisible(false); + } return true; } @@ -811,9 +854,75 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe createNewNote(); break; } - case R.id.menu_search: + case R.id.menu_search: { onSearchRequested(); break; + } + case R.id.menu_secret: { //进入私密模式 + + AlertDialog.Builder dialog = new AlertDialog.Builder(NotesListActivity.this); + dialog.setTitle("重要提醒"); + dialog.setMessage("您确认进入私密模式吗?"); + dialog.setCancelable(false); + dialog.setPositiveButton("确认", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + secret_mode = 1; + startAsyncNotesListQuery(); + Toast.makeText(NotesListActivity.this,"您已进入私密模式",Toast.LENGTH_SHORT).show(); + } + }); + dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which){ + secret_mode = 0; + startAsyncNotesListQuery(); + } + }); + dialog.show(); + +// Toast.makeText(this,"您已进入私密模式",Toast.LENGTH_SHORT).show(); + break; + } + case R.id.menu_quit_secret:{ //退出私密模式 + + AlertDialog.Builder dialog = new AlertDialog.Builder(NotesListActivity.this); + dialog.setTitle("重要提醒"); + dialog.setMessage("您确认退出私密模式吗?"); + dialog.setCancelable(false); + dialog.setPositiveButton("确认", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + secret_mode = 0; + startAsyncNotesListQuery(); + Toast.makeText(NotesListActivity.this,"您已退出私密模式",Toast.LENGTH_SHORT).show(); + } + }); + dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which){ + secret_mode = 1; + startAsyncNotesListQuery(); + } + }); + dialog.show(); + break; + } + case R.id.menu_flower:{ + mode = 1; + getWindow().setBackgroundDrawableResource(R.drawable.flower); + break; + } + case R.id.menu_saying:{ + mode = 0; + getWindow().setBackgroundDrawableResource(R.drawable.mountain); + break; + } + case R.id.menu_water:{ + mode = -1; + getWindow().setBackgroundDrawableResource(R.drawable.water); + break; + } default: break; } diff --git a/MiNote/app/src/main/res/drawable-hdpi/flower.jpg b/MiNote/app/src/main/res/drawable-hdpi/flower.jpg new file mode 100644 index 0000000..7d9e3da Binary files /dev/null and b/MiNote/app/src/main/res/drawable-hdpi/flower.jpg differ diff --git a/MiNote/app/src/main/res/drawable-hdpi/mountain.jpg b/MiNote/app/src/main/res/drawable-hdpi/mountain.jpg new file mode 100644 index 0000000..875a470 Binary files /dev/null and b/MiNote/app/src/main/res/drawable-hdpi/mountain.jpg differ diff --git a/MiNote/app/src/main/res/drawable-hdpi/saying.jpg b/MiNote/app/src/main/res/drawable-hdpi/saying.jpg new file mode 100644 index 0000000..1ec26af Binary files /dev/null and b/MiNote/app/src/main/res/drawable-hdpi/saying.jpg differ diff --git a/MiNote/app/src/main/res/drawable-hdpi/water.jpg b/MiNote/app/src/main/res/drawable-hdpi/water.jpg new file mode 100644 index 0000000..75176ee Binary files /dev/null and b/MiNote/app/src/main/res/drawable-hdpi/water.jpg differ diff --git a/MiNote/app/src/main/res/layout/note_list.xml b/MiNote/app/src/main/res/layout/note_list.xml index 6b25d38..23989cb 100644 --- a/MiNote/app/src/main/res/layout/note_list.xml +++ b/MiNote/app/src/main/res/layout/note_list.xml @@ -18,8 +18,8 @@ + android:layout_height="fill_parent"> + + + + + + + + + + + diff --git a/MiNote/app/src/main/res/menu/sub_folder.xml b/MiNote/app/src/main/res/menu/sub_folder.xml index b00de26..a6efc07 100644 --- a/MiNote/app/src/main/res/menu/sub_folder.xml +++ b/MiNote/app/src/main/res/menu/sub_folder.xml @@ -21,4 +21,12 @@ + + + + \ No newline at end of file diff --git a/MiNote/app/src/main/res/values-zh-rCN/strings.xml b/MiNote/app/src/main/res/values-zh-rCN/strings.xml index 09f75ed..fcb02e5 100644 --- a/MiNote/app/src/main/res/values-zh-rCN/strings.xml +++ b/MiNote/app/src/main/res/values-zh-rCN/strings.xml @@ -36,6 +36,8 @@ 浏览网页 打开地图 + 私密模式 + 退出私密模式 新建文件夹 导出文本 同步 diff --git a/MiNote/app/src/main/res/values-zh-rTW/strings.xml b/MiNote/app/src/main/res/values-zh-rTW/strings.xml index 3c41894..d0b5f7a 100644 --- a/MiNote/app/src/main/res/values-zh-rTW/strings.xml +++ b/MiNote/app/src/main/res/values-zh-rTW/strings.xml @@ -37,6 +37,8 @@ 打開地圖 已將所選 %1$d 便籤移到 %2$s 文件夾 + 私密模式 + 退出私密模式 新建文件夾 導出文本 同步 diff --git a/MiNote/app/src/main/res/values/strings.xml b/MiNote/app/src/main/res/values/strings.xml index 55df868..55b1d4c 100644 --- a/MiNote/app/src/main/res/values/strings.xml +++ b/MiNote/app/src/main/res/values/strings.xml @@ -39,6 +39,11 @@ /MIUI/notes/ notes_%s.txt + Background: Flower + Background: Mountain + Background: Water + secret model + quit secret model (%d) New Folder Export text diff --git a/testfile b/testfile deleted file mode 100644 index d8ce13e..0000000 --- a/testfile +++ /dev/null @@ -1 +0,0 @@ -Laotie666