diff --git a/src/Notes-master/app/src/main/AndroidManifest.xml b/src/Notes-master/app/src/main/AndroidManifest.xml index 21e9edd..1580abe 100644 --- a/src/Notes-master/app/src/main/AndroidManifest.xml +++ b/src/Notes-master/app/src/main/AndroidManifest.xml @@ -1,25 +1,9 @@ - - - - + android:versionName="0.1"> @@ -33,43 +17,51 @@ + android:label="@string/app_name"> + //开启画面 + + + + + /> + - - - - - + android:windowSoftInputMode="adjustPan"> - - - + android:theme="@style/NoteTheme"> + + + - + + - + @@ -79,13 +71,13 @@ + android:label="@string/app_widget2x2"> @@ -98,8 +90,7 @@ - + android:label="@string/app_widget4x4"> @@ -110,39 +101,39 @@ android:name="android.appwidget.provider" android:resource="@xml/widget_4x_info" /> - - + - - + android:name=".ui.AlarmReceiver" + android:process=":remote"> - - + android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar"> - + android:theme="@android:style/Theme.Holo.Light"> + + - + android:name=".gtask.remote.GTaskSyncService" + android:exported="false"> - + + \ No newline at end of file diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/Notes.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/Notes.java index f240604..b0e7164 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/data/Notes.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/data/Notes.java @@ -165,6 +165,13 @@ public class Notes { *

Type : INTEGER (long)

*/ public static final String VERSION = "version"; + + + /** + * create a password for a note + *

Type: TEXT

+ */ + public static final String PASSCODE = "passcode"; } public interface DataColumns { diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java index ffe5d57..81e685c 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java +++ b/src/Notes-master/app/src/main/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"; @@ -43,168 +43,169 @@ 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," + - NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," + - NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," + - NoteColumns.BG_COLOR_ID + " INTEGER NOT NULL DEFAULT 0," + - NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + - NoteColumns.HAS_ATTACHMENT + " INTEGER NOT NULL DEFAULT 0," + - NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + - NoteColumns.NOTES_COUNT + " INTEGER NOT NULL DEFAULT 0," + - NoteColumns.SNIPPET + " TEXT NOT NULL DEFAULT ''," + - NoteColumns.TYPE + " INTEGER NOT NULL DEFAULT 0," + - NoteColumns.WIDGET_ID + " INTEGER NOT NULL DEFAULT 0," + - NoteColumns.WIDGET_TYPE + " INTEGER NOT NULL DEFAULT -1," + - NoteColumns.SYNC_ID + " INTEGER NOT NULL DEFAULT 0," + - 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" + - ")"; + "CREATE TABLE " + TABLE.NOTE + "(" + + NoteColumns.ID + " INTEGER PRIMARY KEY," + + NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.BG_COLOR_ID + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + + NoteColumns.HAS_ATTACHMENT + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + + NoteColumns.NOTES_COUNT + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.SNIPPET + " TEXT NOT NULL DEFAULT ''," + + NoteColumns.TYPE + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.WIDGET_ID + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.WIDGET_TYPE + " INTEGER NOT NULL DEFAULT -1," + + NoteColumns.SYNC_ID + " INTEGER NOT NULL DEFAULT 0," + + 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.PASSCODE + " TEXT NOT NULL DEFAULT ''"+ + ")"; private static final String CREATE_DATA_TABLE_SQL = - "CREATE TABLE " + TABLE.DATA + "(" + - DataColumns.ID + " INTEGER PRIMARY KEY," + - DataColumns.MIME_TYPE + " TEXT NOT NULL," + - DataColumns.NOTE_ID + " INTEGER NOT NULL DEFAULT 0," + - NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + - NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + - DataColumns.CONTENT + " TEXT NOT NULL DEFAULT ''," + - DataColumns.DATA1 + " INTEGER," + - DataColumns.DATA2 + " INTEGER," + - DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," + - DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," + - DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" + - ")"; + "CREATE TABLE " + TABLE.DATA + "(" + + DataColumns.ID + " INTEGER PRIMARY KEY," + + DataColumns.MIME_TYPE + " TEXT NOT NULL," + + DataColumns.NOTE_ID + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + + NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + + DataColumns.CONTENT + " TEXT NOT NULL DEFAULT ''," + + DataColumns.DATA1 + " INTEGER," + + DataColumns.DATA2 + " INTEGER," + + DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," + + DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," + + 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 + ");"; + "CREATE INDEX IF NOT EXISTS note_id_index ON " + + TABLE.DATA + "(" + DataColumns.NOTE_ID + ");"; /** * Increase folder's note count when move note to the folder */ 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 + - " BEGIN " + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" + - " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" + - " END"; + "CREATE TRIGGER increase_folder_count_on_update "+ + " AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE + + " BEGIN " + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" + + " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" + + " END"; /** * Decrease folder's note count when move note from folder */ 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 + - " BEGIN " + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" + - " WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID + - " AND " + NoteColumns.NOTES_COUNT + ">0" + ";" + - " END"; + "CREATE TRIGGER decrease_folder_count_on_update " + + " AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE + + " BEGIN " + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" + + " WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID + + " AND " + NoteColumns.NOTES_COUNT + ">0" + ";" + + " END"; /** * Increase folder's note count when insert new note to the folder */ private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER = - "CREATE TRIGGER increase_folder_count_on_insert " + - " AFTER INSERT ON " + TABLE.NOTE + - " BEGIN " + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" + - " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" + - " END"; + "CREATE TRIGGER increase_folder_count_on_insert " + + " AFTER INSERT ON " + TABLE.NOTE + + " BEGIN " + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" + + " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" + + " END"; /** * Decrease folder's note count when delete note from the folder */ private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER = - "CREATE TRIGGER decrease_folder_count_on_delete " + - " AFTER DELETE ON " + TABLE.NOTE + - " BEGIN " + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" + - " WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID + - " AND " + NoteColumns.NOTES_COUNT + ">0;" + - " END"; + "CREATE TRIGGER decrease_folder_count_on_delete " + + " AFTER DELETE ON " + TABLE.NOTE + + " BEGIN " + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" + + " WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID + + " AND " + NoteColumns.NOTES_COUNT + ">0;" + + " END"; /** * Update note's content when insert data with type {@link DataConstants#NOTE} */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER = - "CREATE TRIGGER update_note_content_on_insert " + - " AFTER INSERT ON " + TABLE.DATA + - " WHEN new." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + - " BEGIN" + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT + - " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" + - " END"; + "CREATE TRIGGER update_note_content_on_insert " + + " AFTER INSERT ON " + TABLE.DATA + + " WHEN new." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + + " BEGIN" + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT + + " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" + + " END"; /** * Update note's content when data with {@link DataConstants#NOTE} type has changed */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER = - "CREATE TRIGGER update_note_content_on_update " + - " AFTER UPDATE ON " + TABLE.DATA + - " WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + - " BEGIN" + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT + - " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" + - " END"; + "CREATE TRIGGER update_note_content_on_update " + + " AFTER UPDATE ON " + TABLE.DATA + + " WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + + " BEGIN" + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT + + " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" + + " END"; /** * Update note's content when data with {@link DataConstants#NOTE} type has deleted */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER = - "CREATE TRIGGER update_note_content_on_delete " + - " AFTER delete ON " + TABLE.DATA + - " WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + - " BEGIN" + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.SNIPPET + "=''" + - " WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" + - " END"; + "CREATE TRIGGER update_note_content_on_delete " + + " AFTER delete ON " + TABLE.DATA + + " WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + + " BEGIN" + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.SNIPPET + "=''" + + " WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" + + " END"; /** * Delete datas belong to note which has been deleted */ private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER = - "CREATE TRIGGER delete_data_on_delete " + - " AFTER DELETE ON " + TABLE.NOTE + - " BEGIN" + - " DELETE FROM " + TABLE.DATA + - " WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" + - " END"; + "CREATE TRIGGER delete_data_on_delete " + + " AFTER DELETE ON " + TABLE.NOTE + + " BEGIN" + + " DELETE FROM " + TABLE.DATA + + " WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" + + " END"; /** * Delete notes belong to folder which has been deleted */ private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER = - "CREATE TRIGGER folder_delete_notes_on_delete " + - " AFTER DELETE ON " + TABLE.NOTE + - " BEGIN" + - " DELETE FROM " + TABLE.NOTE + - " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + - " END"; + "CREATE TRIGGER folder_delete_notes_on_delete " + + " AFTER DELETE ON " + TABLE.NOTE + + " BEGIN" + + " DELETE FROM " + TABLE.NOTE + + " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + + " END"; /** * Move notes belong to folder which has been moved to trash folder */ private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER = - "CREATE TRIGGER folder_move_notes_on_trash " + - " AFTER UPDATE ON " + TABLE.NOTE + - " WHEN new." + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER + - " BEGIN" + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER + - " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + - " END"; + "CREATE TRIGGER folder_move_notes_on_trash " + + " AFTER UPDATE ON " + TABLE.NOTE + + " WHEN new." + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER + + " BEGIN" + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER + + " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + + " END"; public NotesDatabaseHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); @@ -322,6 +323,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { oldVersion++; } + if (oldVersion == 4) { + upgradeToV5(db); + oldVersion++; + } + + if (reCreateTriggers) { reCreateNoteTableTriggers(db); reCreateDataTableTriggers(db); @@ -359,4 +366,12 @@ 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("DROP TABLE IF EXISTS " + TABLE.NOTE); + db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA); + createNoteTable(db); + createDataTable(db); + } + } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java index 0de0038..e2dabbb 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java @@ -77,8 +77,6 @@ public class GTaskASyncTask extends AsyncTask { pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, NotesListActivity.class), 0); } -// notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content, -// pendingIntent); notification = new Notification.Builder(mContext) .setContentIntent(pendingIntent) .setTicker(mContext.getString(R.string.app_name)) diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/model/Note.java b/src/Notes-master/app/src/main/java/net/micode/notes/model/Note.java index 6706cf6..5459358 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/model/Note.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/model/Note.java @@ -50,6 +50,7 @@ public class Note { values.put(NoteColumns.TYPE, Notes.TYPE_NOTE); values.put(NoteColumns.LOCAL_MODIFIED, 1); values.put(NoteColumns.PARENT_ID, folderId); + values.put(NoteColumns.PASSCODE, ""); Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values); long noteId = 0; diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/model/WorkingNote.java b/src/Notes-master/app/src/main/java/net/micode/notes/model/WorkingNote.java index be081e4..b85f762 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/model/WorkingNote.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/model/WorkingNote.java @@ -41,6 +41,8 @@ public class WorkingNote { private String mContent; // Note mode private int mMode; + // Note passcode + private String mPasscode; private long mAlertDate; @@ -78,7 +80,8 @@ public class WorkingNote { NoteColumns.BG_COLOR_ID, NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, - NoteColumns.MODIFIED_DATE + NoteColumns.MODIFIED_DATE, + NoteColumns.PASSCODE }; private static final int DATA_ID_COLUMN = 0; @@ -101,6 +104,7 @@ public class WorkingNote { private static final int NOTE_MODIFIED_DATE_COLUMN = 5; + private static final int NOTE_PASSCODE_COLUMN = 6; // New note construct private WorkingNote(Context context, long folderId) { mContext = context; @@ -111,6 +115,7 @@ public class WorkingNote { mNoteId = 0; mIsDeleted = false; mMode = 0; + mPasscode = ""; //save note's password mWidgetType = Notes.TYPE_WIDGET_INVALIDE; } @@ -137,6 +142,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); + mPasscode = cursor.getString(NOTE_PASSCODE_COLUMN); } cursor.close(); } else { @@ -365,4 +371,19 @@ public class WorkingNote { */ void onCheckListModeChanged(int oldMode, int newMode); } + /**判断是否已经设置密码*/ + public boolean hasPasscode() { + return !mPasscode.equals(""); + } + + /**设置单个便签密码*/ + public void setPasscode(String passcode) { + mPasscode = passcode; + mNote.setNoteValue(NoteColumns.PASSCODE, passcode); + } + + /**获取已经设置的密码*/ + public String getPasscode() { + return mPasscode; + } } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/tool/Point.java b/src/Notes-master/app/src/main/java/net/micode/notes/tool/Point.java new file mode 100644 index 0000000..f3d8e4e --- /dev/null +++ b/src/Notes-master/app/src/main/java/net/micode/notes/tool/Point.java @@ -0,0 +1,113 @@ +package net.micode.notes.tool; + +public class Point { + public static int BITMAP_NORMAL = 0; // 正常 + public static int BITMAP_ERROR = 1; // 错误 + public static int BITMAP_PRESS = 2; // 按下 + + //九宫格中的点的下标(即每个点代表一个值) + private String index; + //点的状态 + private int state; + //点的坐标 + private float x; + private float y; + + public Point() { + super(); + } + + public Point(int x, int y) { + this.x = x; + this.y = y; + } + + public String getIndex() { + return index; + } + + public int getState() { + return state; + } + + public float getX() { + return x; + } + + public float getY() { + return y; + } + + public void setIndex(String index) { + this.index = index; + } + + public void setState(int state) { + this.state = state; + } + + public void setX(float x) { + this.x = x; + } + + public void setY(float y) { + this.y = y; + } + + /** + * 判断屏幕上的九宫格中的点能否可以进行连线 + * + * @param a + * @param moveX + * @param moveY + * @param radius 点bitmap的半径 + * @return 布尔型 + */ + public boolean isWith(Point a, float moveX, float moveY, float radius) { + float result = (float) Math.sqrt((a.getX() - moveX) + * (a.getX() - moveX) + (a.getY() - moveY) + * (a.getY() - moveY)); + if (result < 5 * radius / 4) { + return true; + } + return false; + } + + public static float getDegrees(Point a, Point b) { + float degrees = 0; + float ax = a.getX(); + float ay = a.getY(); + float bx = b.getX(); + float by = b.getY(); + + if (ax == bx) { + if (by > ay) { + degrees = 90; + } else { + degrees = 270; + } + } else if (by == ay) { + if (ax > bx) { + degrees = 180; + } else { + degrees = 0; + } + } else { + if (ax > bx) { + if (ay > by) { // 第三象限 + degrees = 180 + (float) (Math.atan2(ay - by, ax - bx) * 180 / Math.PI); + } else { // 第二象限 + degrees = 180 - (float) (Math.atan2(by - ay, ax - bx) * 180 / Math.PI); + } + } else { + if (ay > by) { // 第四象限 + degrees = 360 - (float) (Math.atan2(ay - by, bx - ax) * 180 / Math.PI); + } else { // 第一象限 + degrees = (float) (Math.atan2(by - ay, bx - ax) * 180 / Math.PI); + } + } + } + return degrees; + } +} + diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/LockPatternView.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/LockPatternView.java new file mode 100644 index 0000000..36a0937 --- /dev/null +++ b/src/Notes-master/app/src/main/java/net/micode/notes/ui/LockPatternView.java @@ -0,0 +1,384 @@ +package net.micode.notes.ui; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; + +import net.micode.notes.R; +import net.micode.notes.tool.Point; + +import java.util.ArrayList; +import java.util.List; + + +public class LockPatternView extends View { + //判断线的状态 + private static boolean isLineState = true; + //判断点是否被实例化了 + private static boolean isInitPoint = false; + //判断手指是否离开屏幕 + private static boolean isFinish = false; + //判断手指点击屏幕时是否选中了九宫格中的点 + private static boolean isSelect = false; + // 创建MyPoint的数组 + private Point[][] mPoints = new Point[3][3]; + // 声明屏幕的宽和高 + private int mScreenHeight; + private int mScreenWidth; + // 声明点线的图片的半径 + private float mPointRadius; + // 声明线的图片的高(即是半径) + private float mLineHeight; + // 声明鼠标移动的x,y坐标 + private float mMoveX, mMoveY; + // 声明屏幕上的宽和高的偏移量 + private int mScreenHeightOffSet = 0; + private int mScreenWidthOffSet = 0; + // 创建一个画笔 + private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); + // 声明资源图片 + private Bitmap mBitmapNormal; + private Bitmap mBitmapPressed; + private Bitmap mBitmapError; + private Bitmap mLinePressed; + private Bitmap mLineError; + // 创建一个矩阵 + private Matrix mMatrix = new Matrix(); + // 创建MyPoint的列表 + private List mPointList = new ArrayList(); + // 实例化鼠标点 + private Point mMousePoint = new Point(); + // 用获取从activity中传过来的密码字符串 + private String mPassword = ""; + private final static String TAG = "LockPatternView"; + + private Context mContext; + private OnLockListener mListener; + + public LockPatternView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + mContext = context; + } + + public LockPatternView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public LockPatternView(Context context) { + super(context); + } + + /** + * 画点和画线 + */ + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if (!isInitPoint) { + initPoint(); // 先初始化 + } + + canvasPoint(canvas); // 开始画点 + + // 开始画线 + if (mPointList.size() > 0) { + Point b = null; + Point a = mPointList.get(0); + for (int i = 1; i < mPointList.size(); i++) { + b = mPointList.get(i); + canvasLine(a, b, canvas); + a = b; + } + if (!isFinish) { + canvasLine(a, mMousePoint, canvas); + } + } + } + + /** + * 手指点击手机屏幕 + */ + @Override + public boolean onTouchEvent(MotionEvent event) { + mMoveX = event.getX(); + mMoveY = event.getY(); + // 设置移动点的坐标 + mMousePoint.setX(mMoveX); + mMousePoint.setY(mMoveY); + Point mPoint = null; + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + isLineState = true; + isFinish = false; + // 每次点击时就会将pointList中元素设置转化成正常状态 + for (int i = 0; i < mPointList.size(); i++) { + mPointList.get(i).setState(Point.BITMAP_NORMAL); + } + // 将pointList中的元素清除掉 + mPointList.clear(); + // 判断是否点中了九宫格中的点 + mPoint = getIsSelectedPoint(mMoveX, mMoveY); + if (mPoint != null) { + isSelect = true; + } + break; + case MotionEvent.ACTION_MOVE: + if (isSelect == true) { + mPoint = getIsSelectedPoint(mMoveX, mMoveY); + } + + break; + case MotionEvent.ACTION_UP: + isFinish = true; + isSelect = false; + // 规定至少要有4个点被连线才有可能是正确 + // 其他种情况都是错误的 + if (mPointList.size() >= 4) {// 正确情况 + for (int j = 0; j < mPointList.size(); j++) { + mPassword += mPointList.get(j).getIndex(); + } + //将连线后得到的密码传给activity + mListener.getStringPassword(mPassword); + mPassword = ""; + //经过activity判断传过来是否正确 + if (mListener.isPassword()) { + for (int i = 0; i < mPointList.size(); i++) { + mPointList.get(i).setState(Point.BITMAP_PRESS); + } + } else { + for (int i = 0; i < mPointList.size(); i++) { + mPointList.get(i).setState(Point.BITMAP_ERROR); + } + isLineState = false; + } + // 错误情况 + } else if (mPointList.size() < 4 && mPointList.size() > 1) { + for (int i = 0; i < mPointList.size(); i++) { + mPointList.get(i).setState(Point.BITMAP_ERROR); + } + isLineState = false; + // 如果只有一个点被点中时为正常情况 + } else if (mPointList.size() == 1) { + for (int i = 0; i < mPointList.size(); i++) { + mPointList.get(i).setState(Point.BITMAP_NORMAL); + } + } + break; + } + // 将mPoint添加到pointList中 + if (isSelect && mPoint != null) { + if (mPoint.getState() == Point.BITMAP_NORMAL) { + mPoint.setState(Point.BITMAP_PRESS); + mPointList.add(mPoint); + } + } + // 每次发生OnTouchEvent()后都刷新View + postInvalidate(); + return true; + } + + /** + * 判断九宫格中的某个点是否被点中了,或者某个点能否被连线 + * + * @param moveX + * @param moveY + * @return + */ + private Point getIsSelectedPoint(float moveX, float moveY) { + Point myPoint = null; + for (int i = 0; i < mPoints.length; i++) { + for (int j = 0; j < mPoints[i].length; j++) { + if (mPoints[i][j].isWith(mPoints[i][j], moveX, moveY, + mPointRadius)) { + myPoint = mPoints[i][j]; + } + } + } + + return myPoint; + } + + /** + * 画线 + * + * @param a 起始点 + * @param b 目的点 + * @param canvas 画布 + */ + private void canvasLine(Point a, Point b, Canvas canvas) { + // Math.sqrt(平方+平方) + float abInstance = (float) Math.sqrt( + (a.getX() - b.getX()) * (a.getX() - b.getX()) + + (a.getY() - b.getY()) * (a.getY() - b.getY()) + ); + canvas.rotate(Point.getDegrees(a, b), a.getX(), a.getY()); + + mMatrix.setScale(abInstance / mLineHeight, 1); + mMatrix.postTranslate(a.getX(), a.getY()); + if (isLineState) { + canvas.drawBitmap(mLinePressed, mMatrix, mPaint); + } else { + canvas.drawBitmap(mLineError, mMatrix, mPaint); + } + + canvas.rotate(-Point.getDegrees(a, b), a.getX(), a.getY()); + } + + /** + * 画点 + * + * @param canvas + */ + private void canvasPoint(Canvas canvas) { + for (int i = 0; i < mPoints.length; i++) { + for (int j = 0; j < mPoints[i].length; j++) { + if (mPoints[i][j]==null) { + //重启view时,new的变量被销毁,其他未被销毁,导致设置一次开启app,第二次进入时 + //isinitpoint 变量已为true,可是点实例未初始化; + initPoint(); + } + if (mPoints[i][j].getState() == Point.BITMAP_NORMAL) { + canvas.drawBitmap(mBitmapNormal, + mPoints[i][j].getX() - mPointRadius, + mPoints[i][j].getY() - mPointRadius, mPaint); + } else if (mPoints[i][j].getState() == Point.BITMAP_PRESS) { + canvas.drawBitmap(mBitmapPressed, + mPoints[i][j].getX() - mPointRadius, + mPoints[i][j].getY() - mPointRadius, mPaint); + } else { + canvas.drawBitmap(mBitmapError, + mPoints[i][j].getX() - mPointRadius, + mPoints[i][j].getY() - mPointRadius, mPaint); + } + } + } + } + + private void minitPoint(){ + /** + * 开始实例化九宫格中点 + */ + mPoints[0][0] = new Point(mScreenWidthOffSet + mScreenWidth / 4, + mScreenHeightOffSet + mScreenHeight / 4); + mPoints[0][1] = new Point(mScreenWidthOffSet + mScreenWidth / 2, + mScreenHeightOffSet + mScreenHeight / 4); + mPoints[0][2] = new Point(mScreenWidthOffSet + mScreenWidth * 3 / 4, + mScreenHeightOffSet + mScreenHeight / 4); + + mPoints[1][0] = new Point(mScreenWidthOffSet + mScreenWidth / 4, + mScreenHeightOffSet + mScreenHeight / 2); + mPoints[1][1] = new Point(mScreenWidthOffSet + mScreenWidth / 2, + mScreenHeightOffSet + mScreenHeight / 2); + mPoints[1][2] = new Point(mScreenWidthOffSet + mScreenWidth * 3 / 4, + mScreenHeightOffSet + mScreenHeight / 2); + + mPoints[2][0] = new Point(mScreenWidthOffSet + mScreenWidth / 4, + mScreenHeightOffSet + mScreenHeight * 3 / 4); + mPoints[2][1] = new Point(mScreenWidthOffSet + mScreenWidth / 2, + mScreenHeightOffSet + mScreenHeight * 3 / 4); + mPoints[2][2] = new Point(mScreenWidthOffSet + mScreenWidth * 3 / 4, + mScreenHeightOffSet + mScreenHeight * 3 / 4); + + + // 设置九宫格中的各个index + int index = 1; + for (int i = 0; i < mPoints.length; i++) { + for (int j = 0; j < mPoints[i].length; j++) { + mPoints[i][j].setIndex(index + ""); + // 在没有任何操作的情况下默認点的状态 + mPoints[i][j].setState(Point.BITMAP_NORMAL); + index++; + } + } + } + + /** + * 实例化九宫格中所有点和所有的资源图片 + */ + private void initPoint() { + // 获取View的宽高 + mScreenWidth = getWidth(); + mScreenHeight = getHeight(); + if (mScreenHeight > mScreenWidth) { + // 获取y轴上的偏移量 + mScreenHeightOffSet = (mScreenHeight - mScreenWidth) / 2; + // 将屏幕高的变量设置成与宽相等,目的是为了new Point(x,y)时方便操作 + mScreenHeight = mScreenWidth; + } else { + // 获取x轴上的偏移量 + mScreenWidthOffSet = (mScreenWidth - mScreenHeight) / 2; + // 将屏幕宽的变量设置成与高相等,目的是为了new Point(x,y)时方便操作 + mScreenWidth = mScreenHeight; + } + + /** + * 实例化所有的资源图片 + */ + mBitmapError = BitmapFactory.decodeResource(getResources(), R.drawable.bitmap_error); + mBitmapNormal = BitmapFactory.decodeResource(getResources(), R.drawable.bitmap_normal); + mBitmapPressed = BitmapFactory.decodeResource(getResources(), R.drawable.bitmap_pressed); + mLineError = BitmapFactory.decodeResource(getResources(), R.drawable.line_error); + mLinePressed = BitmapFactory.decodeResource(getResources(), R.drawable.line_pressed); + + mPointRadius = mBitmapNormal.getWidth() / 2; + mLineHeight = mLinePressed.getHeight(); + + /** + * 开始实例化九宫格中点 + */ + mPoints[0][0] = new Point(mScreenWidthOffSet + mScreenWidth / 4, + mScreenHeightOffSet + mScreenHeight / 4); + mPoints[0][1] = new Point(mScreenWidthOffSet + mScreenWidth / 2, + mScreenHeightOffSet + mScreenHeight / 4); + mPoints[0][2] = new Point(mScreenWidthOffSet + mScreenWidth * 3 / 4, + mScreenHeightOffSet + mScreenHeight / 4); + + mPoints[1][0] = new Point(mScreenWidthOffSet + mScreenWidth / 4, + mScreenHeightOffSet + mScreenHeight / 2); + mPoints[1][1] = new Point(mScreenWidthOffSet + mScreenWidth / 2, + mScreenHeightOffSet + mScreenHeight / 2); + mPoints[1][2] = new Point(mScreenWidthOffSet + mScreenWidth * 3 / 4, + mScreenHeightOffSet + mScreenHeight / 2); + + mPoints[2][0] = new Point(mScreenWidthOffSet + mScreenWidth / 4, + mScreenHeightOffSet + mScreenHeight * 3 / 4); + mPoints[2][1] = new Point(mScreenWidthOffSet + mScreenWidth / 2, + mScreenHeightOffSet + mScreenHeight * 3 / 4); + mPoints[2][2] = new Point(mScreenWidthOffSet + mScreenWidth * 3 / 4, + mScreenHeightOffSet + mScreenHeight * 3 / 4); + + + // 设置九宫格中的各个index + int index = 1; + for (int i = 0; i < mPoints.length; i++) { + for (int j = 0; j < mPoints[i].length; j++) { + mPoints[i][j].setIndex(index + ""); + // 在没有任何操作的情况下默認点的状态 + mPoints[i][j].setState(Point.BITMAP_NORMAL); + index++; + } + } + + // 将isInitPoint设置为true + isInitPoint = true; + } + + public interface OnLockListener { + public void getStringPassword(String password); + + public boolean isPassword(); + } + + + public void setLockListener(OnLockListener listener) { + this.mListener = listener; + } + +} + diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 9bd74f2..10490f0 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -146,6 +146,9 @@ public class NoteEditActivity extends Activity implements OnClickListener, private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10; + private static final int REQUEST_SET_PASSCODE = 0; + private static final int REQUEST_UNLOCK = 1; + public static final String TAG_CHECKED = String.valueOf('\u221A'); public static final String TAG_UNCHECKED = String.valueOf('\u25A1'); @@ -153,6 +156,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, private String mUserQuery; private Pattern mPattern; + private boolean Locked; @Override protected void onCreate(Bundle savedInstanceState) { @@ -315,6 +319,9 @@ public class NoteEditActivity extends Activity implements OnClickListener, return false; } mWorkingNote.setOnSettingStatusChangedListener(this); + if (intent.hasExtra("lock")){ + Locked = false; + } return true; } @@ -324,6 +331,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, initNoteScreen(); } + //初始化编辑界面 private void initNoteScreen() { mNoteEditor.setTextAppearance(this, TextAppearanceResources .getTexAppearanceResource(mFontSizeId)); @@ -349,6 +357,14 @@ public class NoteEditActivity extends Activity implements OnClickListener, * is not ready */ showAlertHeader(); + + if (mWorkingNote.hasPasscode() && Locked) { + saveNote(); + Intent intent = new Intent(this,UnlockActivity.class); + intent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId()); + startActivityForResult(intent,REQUEST_SET_PASSCODE); + finish(); + } } private void showAlertHeader() { @@ -486,7 +502,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); @@ -558,6 +574,11 @@ public class NoteEditActivity extends Activity implements OnClickListener, } else { menu.findItem(R.id.menu_delete_remind).setVisible(false); } + if (mWorkingNote.hasPasscode()) { + menu.findItem(R.id.menu_set_passcode).setVisible(false); + } else { + menu.findItem(R.id.menu_delete_passcode).setVisible(false); + } return true; } @@ -570,7 +591,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, 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.setIcon(R.drawable.bitmap_pressed); builder.setMessage(getString(R.string.alert_message_delete_note)); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @@ -603,6 +624,12 @@ public class NoteEditActivity extends Activity implements OnClickListener, case R.id.menu_delete_remind: mWorkingNote.setAlertDate(0, false); break; + case R.id.menu_set_passcode: + setPasscode(); + break; + case R.id.menu_delete_passcode: + deletePasscode(); + break; default: break; } @@ -619,6 +646,30 @@ public class NoteEditActivity extends Activity implements OnClickListener, d.show(); } + /** + * 设置密码 + */ + private void setPasscode() { + //先保存当前内容 + saveNote(); + //intent消息来跳转到密码界面 + Intent intent = new Intent(this, SetLockActivity.class); + intent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId()); + startActivity(intent); + //关闭当前界面 + finish(); + } + + /** + * 删除密码 + */ + private void deletePasscode() { + mWorkingNote.setPasscode(""); + saveNote(); + //不会获取用户焦点显示已经删除信息,显示两秒 + Toast.makeText(NoteEditActivity.this, R.string.note_passcode_deleted, Toast.LENGTH_SHORT).show(); + } + /** * Share note to apps that support {@link Intent#ACTION_SEND} action * and {@text/plain} type diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteItemData.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteItemData.java index 0f5a878..d6dff9a 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteItemData.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteItemData.java @@ -40,6 +40,7 @@ public class NoteItemData { NoteColumns.TYPE, NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, + NoteColumns.PASSCODE }; private static final int ID_COLUMN = 0; @@ -54,6 +55,7 @@ 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 PASSCODE_COLUMN = 12; private long mId; private long mAlertDate; @@ -67,6 +69,7 @@ public class NoteItemData { private int mType; private int mWidgetId; private int mWidgetType; + private String mPasscode; private String mName; private String mPhoneNumber; @@ -91,6 +94,7 @@ public class NoteItemData { mType = cursor.getInt(TYPE_COLUMN); mWidgetId = cursor.getInt(WIDGET_ID_COLUMN); mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN); + mPasscode = cursor.getString(PASSCODE_COLUMN); mPhoneNumber = ""; if (mParentId == Notes.ID_CALL_RECORD_FOLDER) { @@ -221,4 +225,8 @@ public class NoteItemData { public static int getNoteType(Cursor cursor) { return cursor.getInt(TYPE_COLUMN); } + + public boolean hasLock() { + return !mPasscode.equals(""); + } } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListItem.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListItem.java index 1221e80..f9c07d0 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListItem.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListItem.java @@ -32,6 +32,7 @@ import net.micode.notes.tool.ResourceParser.NoteItemBgResources; public class NotesListItem extends LinearLayout { private ImageView mAlert; + private ImageView mLock; private TextView mTitle; private TextView mTime; private TextView mCallName; @@ -42,6 +43,7 @@ public class NotesListItem extends LinearLayout { super(context); inflate(context, R.layout.note_item, this); mAlert = (ImageView) findViewById(R.id.iv_alert_icon); + mLock = (ImageView) findViewById(R.id.iv_lock_icon); mTitle = (TextView) findViewById(R.id.tv_title); mTime = (TextView) findViewById(R.id.tv_time); mCallName = (TextView) findViewById(R.id.tv_name); @@ -58,12 +60,12 @@ public class NotesListItem extends LinearLayout { 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); + 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()); @@ -75,6 +77,14 @@ public class NotesListItem extends LinearLayout { } else { mAlert.setVisibility(View.GONE); } + if(data.hasLock()) { + mLock.setImageResource(R.drawable.lock); + mLock.setVisibility(View.VISIBLE); + String text = "已加密"; + mTitle.setText(text); + } else { + mLock.setVisibility(View.GONE); + } } else { mCallName.setVisibility(View.GONE); mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); @@ -92,8 +102,18 @@ public class NotesListItem extends LinearLayout { } else { mAlert.setVisibility(View.GONE); } + if(data.hasLock()) { + mLock.setImageResource(R.drawable.lock); + mLock.setVisibility(View.VISIBLE); + String text = "已加密"; + mTitle.setText(text); + } else { + mLock.setVisibility(View.GONE); + } } } + + mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate())); setBackground(data); diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/SetLockActivity.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/SetLockActivity.java new file mode 100644 index 0000000..feb2bea --- /dev/null +++ b/src/Notes-master/app/src/main/java/net/micode/notes/ui/SetLockActivity.java @@ -0,0 +1,95 @@ +package net.micode.notes.ui; + + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import net.micode.notes.model.WorkingNote; +import net.micode.notes.R; +import net.micode.notes.ui.LockPatternView; + +public class SetLockActivity extends AppCompatActivity { + + private TextView mTitleTv; + private LockPatternView mLockPatternView; + // private LinearLayout mBottomLayout; + private Button mClearBtn; +// private Button mConfirmBtn; + + private String mPassword; + /** + * 是否是第一次输入密码 + */ + private boolean isFirst = true; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_set_lock); + + initViews(); + initEvents(); + } + + private void initEvents() { + mLockPatternView.setLockListener(new LockPatternView.OnLockListener() { + @Override + public void getStringPassword(String password) { + if (isFirst) { + mPassword = password; + mTitleTv.setText("再次输入手势密码"); + isFirst = false; + mClearBtn.setVisibility(View.VISIBLE); + } else { + if (password.equals(mPassword)) { + Intent pre = getIntent(); + //将密码写入数据库 + long noteId = pre.getLongExtra(Intent.EXTRA_UID, 0); + WorkingNote mWorkingNote = WorkingNote.load(SetLockActivity.this,noteId); + mWorkingNote.setPasscode(password); + boolean saved = mWorkingNote.saveNote();//保存便签 + Intent intent = new Intent(SetLockActivity.this, NoteEditActivity.class); + intent.setAction(Intent.ACTION_VIEW); + intent.putExtra("lock",0); + intent.putExtra(Intent.EXTRA_UID, noteId); + startActivity(intent); + SetLockActivity.this.finish(); + }else { + Toast.makeText(SetLockActivity.this,"两次密码不一致,请重新设置",Toast.LENGTH_SHORT).show(); + mPassword = ""; + mTitleTv.setText("设置手势密码"); + isFirst = true; + mClearBtn.setVisibility(View.GONE); + } + } + } + + @Override + public boolean isPassword() { + return false; + } + }); + + mClearBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mPassword = ""; + isFirst = true; + mClearBtn.setVisibility(View.GONE); + } + }); + + } + + + private void initViews() { + mTitleTv = (TextView) findViewById(R.id.tv_activity_set_lock_title); + mLockPatternView = (LockPatternView) findViewById(R.id.lockView); + mClearBtn = (Button) findViewById(R.id.btn_password_clear); + } +} diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/SplashActivity.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/SplashActivity.java new file mode 100644 index 0000000..22f12fe --- /dev/null +++ b/src/Notes-master/app/src/main/java/net/micode/notes/ui/SplashActivity.java @@ -0,0 +1,34 @@ +package net.micode.notes.ui; + + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.os.Handler; + +import net.micode.notes.R; + +/** + * An example full-screen activity that shows and hides the system UI (i.e. + * status bar and navigation/system bar) with user interaction. + */ +public class SplashActivity extends AppCompatActivity { + Handler mHandler=new Handler(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); //加载启动界面 + setContentView(R.layout.activity_splash); //加载启动图片 + + // 当计时结束时,跳转至NotesListActivity + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + Intent intent=new Intent(); + intent.setClass(SplashActivity.this, NotesListActivity.class); + startActivity(intent); + finish(); //销毁欢迎页面 + } + }, 2000); // 2 秒后跳转 + } +} \ No newline at end of file diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/UnLockActivity.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/UnLockActivity.java new file mode 100644 index 0000000..6740e73 --- /dev/null +++ b/src/Notes-master/app/src/main/java/net/micode/notes/ui/UnLockActivity.java @@ -0,0 +1,56 @@ +package net.micode.notes.ui; + + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.widget.Toast; + +import net.micode.notes.model.WorkingNote; +import net.micode.notes.R; +import net.micode.notes.ui.LockPatternView; + +class UnlockActivity extends AppCompatActivity { + + private LockPatternView mLockPatternView; + private String mPasswordStr; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_lock); + + mLockPatternView = (LockPatternView) findViewById(R.id.lockView); + Intent pre = getIntent(); + final Long noteId = pre.getLongExtra(Intent.EXTRA_UID, 0); + + mLockPatternView.setLockListener(new LockPatternView.OnLockListener() { + WorkingNote mWorkingNote = WorkingNote.load(UnlockActivity.this,noteId); + String password = mWorkingNote.getPasscode(); + @Override + public void getStringPassword(String password) { + mPasswordStr = password; + } + + @Override + public boolean isPassword() { + if (mPasswordStr.equals(password)) { + Toast.makeText(UnlockActivity.this, "密码正确", Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(UnlockActivity.this, NoteEditActivity.class); + intent.setAction(Intent.ACTION_VIEW); + intent.putExtra("lock",0); + intent.putExtra(Intent.EXTRA_UID, noteId); + startActivity(intent); + UnlockActivity.this.finish(); + //TODO comment or not + //return true; + } else { + Toast.makeText(UnlockActivity.this, "密码不正确", Toast.LENGTH_SHORT).show(); + } + return false; + } + }); + + } + +} diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/bitmap_error.png b/src/Notes-master/app/src/main/res/drawable-hdpi/bitmap_error.png new file mode 100644 index 0000000..72424a8 Binary files /dev/null and b/src/Notes-master/app/src/main/res/drawable-hdpi/bitmap_error.png differ diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/bitmap_normal.png b/src/Notes-master/app/src/main/res/drawable-hdpi/bitmap_normal.png new file mode 100644 index 0000000..8de7524 Binary files /dev/null and b/src/Notes-master/app/src/main/res/drawable-hdpi/bitmap_normal.png differ diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/bitmap_pressed.png b/src/Notes-master/app/src/main/res/drawable-hdpi/bitmap_pressed.png new file mode 100644 index 0000000..f5773c0 Binary files /dev/null and b/src/Notes-master/app/src/main/res/drawable-hdpi/bitmap_pressed.png differ diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/line_error.png b/src/Notes-master/app/src/main/res/drawable-hdpi/line_error.png new file mode 100644 index 0000000..93f8799 Binary files /dev/null and b/src/Notes-master/app/src/main/res/drawable-hdpi/line_error.png differ diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/line_pressed.png b/src/Notes-master/app/src/main/res/drawable-hdpi/line_pressed.png new file mode 100644 index 0000000..9ab92d1 Binary files /dev/null and b/src/Notes-master/app/src/main/res/drawable-hdpi/line_pressed.png differ diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/lock.png b/src/Notes-master/app/src/main/res/drawable-hdpi/lock.png new file mode 100644 index 0000000..7729ffc Binary files /dev/null and b/src/Notes-master/app/src/main/res/drawable-hdpi/lock.png differ diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/welcome.jpeg b/src/Notes-master/app/src/main/res/drawable-hdpi/welcome.jpeg new file mode 100644 index 0000000..0d9a1dd Binary files /dev/null and b/src/Notes-master/app/src/main/res/drawable-hdpi/welcome.jpeg differ diff --git a/src/Notes-master/app/src/main/res/layout/activity_lock.xml b/src/Notes-master/app/src/main/res/layout/activity_lock.xml new file mode 100644 index 0000000..f26cd81 --- /dev/null +++ b/src/Notes-master/app/src/main/res/layout/activity_lock.xml @@ -0,0 +1,20 @@ + + + + + + + + diff --git a/src/Notes-master/app/src/main/res/layout/activity_set_lock.xml b/src/Notes-master/app/src/main/res/layout/activity_set_lock.xml new file mode 100644 index 0000000..2d5f203 --- /dev/null +++ b/src/Notes-master/app/src/main/res/layout/activity_set_lock.xml @@ -0,0 +1,32 @@ + + + + + + + + +