密码锁 #13

Manually merged
pvqfzt5us merged 4 commits from yangtingkai_branch into develop 4 years ago

@ -20,6 +20,8 @@
android:versionCode="1"
android:versionName="0.1" >
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.INTERNET" />
@ -136,6 +138,18 @@
android:theme="@android:style/Theme.Holo.Light" >
</activity>
<activity
android:name="net.micode.notes.ui.SetLockActivity"
android:label="@string/menu_set_password"
android:launchMode="singleTop"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<activity
android:name=".ui.UnlockActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
</activity>
<service
android:name="net.micode.notes.gtask.remote.GTaskSyncService"
android:exported="false" >

@ -62,6 +62,7 @@ public class Notes {
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
public interface NoteColumns {
public static final String PASSCODE = "passcode";
/**
* The unique ID for a row
* <P> Type: INTEGER (long) </P>

@ -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.PASSCODE + " TEXT NOT NULL DEFAULT ''" +
")";
private static final String CREATE_DATA_TABLE_SQL =
@ -80,7 +81,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
"CREATE INDEX IF NOT EXISTS note_id_index ON " +
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
/**
* Increase folder's note count when move note to the folder
@ -322,6 +323,21 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
oldVersion++;
}
if (oldVersion == 4) {
upgradeToV5(db);
oldVersion++;
}
/*
if (oldVersion == 5) {
upgradeToV6(db);
oldVersion++;
}
if (oldVersion == 6) {
upgradeToV7(db);
oldVersion++;
}*/
if (reCreateTriggers) {
reCreateNoteTableTriggers(db);
reCreateDataTableTriggers(db);
@ -359,4 +375,22 @@ 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);
}
/*
private void upgradeToV6(SQLiteDatabase db) {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD CLOUMN" + NoteColumns.TOP
+ " INTEGER NOT NULL DEFAULT 0");
}
private void upgradeToV7(SQLiteDatabase db) {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD CLOUMN" + NoteColumns.CLASSIFICATION
+ " INTEGER NOT NULL DEFAULT 0");
}
*/
}

@ -77,17 +77,9 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
NotesListActivity.class), 0);
}
notification = new Notification.Builder(mContext)
.setContentIntent(pendingIntent)
.setTicker(mContext.getString(R.string.app_name))
.setContentTitle(mContext.getString(R.string.app_name))
.setContentText(content)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.icon_app)
.build();
notification.icon = R.drawable.icon_app;
/*notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content,
pendingIntent);*/
mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
}
@Override

@ -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;

@ -42,6 +42,9 @@ public class WorkingNote {
// Note mode
private int mMode;
/**记录便签已设置密码*/
private String mPasscode;
private long mAlertDate;
private long mModifiedDate;
@ -54,6 +57,7 @@ public class WorkingNote {
private long mFolderId;
private Context mContext;
private static final String TAG = "WorkingNote";
@ -78,7 +82,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 +106,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;
@ -112,6 +118,7 @@ public class WorkingNote {
mIsDeleted = false;
mMode = 0;
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
mPasscode = ""; //save note's password
}
// Existing note construct
@ -137,6 +144,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); //get password from database
}
cursor.close();
} else {
@ -342,6 +350,22 @@ public class WorkingNote {
return mWidgetType;
}
/**判断是否已经设置密码*/
public boolean hasPasscode() {
return !mPasscode.equals("");
}
/**设置便签访问密码,并存入数据库*/
public void setPasscode(String passcode) {
mPasscode = passcode;
mNote.setNoteValue(NoteColumns.PASSCODE, passcode);
}
/**获取设置的密码*/
public String getPasscode() {
return mPasscode;
}
public interface NoteSettingChangedListener {
/**
* Called when the background color of current note has just changed

@ -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;
}
}

@ -0,0 +1,385 @@
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.util.Log;
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;
// 声明鼠标移动的xy坐标
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<Point> mPointList = new ArrayList<Point>();
// 实例化鼠标点
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;
}
}

@ -30,9 +30,11 @@ import android.content.SharedPreferences;
import android.graphics.Paint;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.format.DateUtils;
import android.text.style.BackgroundColorSpan;
import android.util.Log;
@ -141,6 +143,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');
@ -148,6 +153,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private String mUserQuery;
private Pattern mPattern;
private boolean Locked; /* 用以判断是否已解锁 */
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -259,6 +265,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return false;
}
mWorkingNote.setOnSettingStatusChangedListener(this);
Locked = mWorkingNote.hasPasscode();//设置便签解锁状态;
if (intent.hasExtra("lock")) {
Locked = false;
}
return true;
}
@ -293,6 +303,15 @@ 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() {
@ -502,6 +521,12 @@ 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_password).setVisible(false);
} else {
menu.findItem(R.id.menu_remove_password).setVisible(false);
}
return true;
}
@ -547,12 +572,43 @@ public class NoteEditActivity extends Activity implements OnClickListener,
case R.id.menu_delete_remind:
mWorkingNote.setAlertDate(0, false);
break;
//设置密码
case R.id.menu_set_password:
setPasscode();
break;
//删除密码
case R.id.menu_remove_password:
deletePasscode();
break;
default:
break;
}
return true;
}
/**
*
*/
private void setPasscode() {
//确保笔记已写入数据库
saveNote();
//初始化一个新的意图,用以跳转至设置密码界面
Intent intent = new Intent(this,SetLockActivity.class);
//给意图传入当前便签的id参数便于从设置密码活动中跳转回编辑便签活动
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();
}
private void setReminder() {
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {

@ -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;
@ -69,6 +71,7 @@ public class NoteItemData {
private int mWidgetType;
private String mName;
private String mPhoneNumber;
private String mPasscode;
private boolean mIsLastItem;
private boolean mIsFirstItem;
@ -92,6 +95,7 @@ public class NoteItemData {
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) {
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId);
@ -221,4 +225,8 @@ public class NoteItemData {
public static int getNoteType(Cursor cursor) {
return cursor.getInt(TYPE_COLUMN);
}
public boolean hasLock() {
return !mPasscode.equals("");
}
}

@ -16,6 +16,7 @@
package net.micode.notes.ui;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@ -29,6 +30,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Editable;
@ -78,163 +80,165 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener {
private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;
public class NotesListActivity<Params> extends Activity implements OnClickListener, OnItemLongClickListener {
private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;
private static final int FOLDER_LIST_QUERY_TOKEN = 1;
private static final int FOLDER_LIST_QUERY_TOKEN = 1;
private static final int MENU_FOLDER_DELETE = 0;
private static final int MENU_FOLDER_DELETE = 0;
private static final int MENU_FOLDER_VIEW = 1;
private static final int MENU_FOLDER_VIEW = 1;
private static final int MENU_FOLDER_CHANGE_NAME = 2;
private static final int MENU_FOLDER_CHANGE_NAME = 2;
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
};
private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
};
private ListEditState mState;
private ListEditState mState;
private BackgroundQueryHandler mBackgroundQueryHandler;
private BackgroundQueryHandler mBackgroundQueryHandler;
private NotesListAdapter mNotesListAdapter;
private NotesListAdapter mNotesListAdapter;
private ListView mNotesListView;
private ListView mNotesListView;
private Button mAddNewNote;
private Button mAddNewNote;
private boolean mDispatch;
private boolean mDispatch;
private int mOriginY;
private int mOriginY;
private int mDispatchY;
private int mDispatchY;
private TextView mTitleBar;
private TextView mTitleBar;
private long mCurrentFolderId;
private long mCurrentFolderId;
private ContentResolver mContentResolver;
private ContentResolver mContentResolver;
private ModeCallback mModeCallBack;
private ModeCallback mModeCallBack;
private static final String TAG = "NotesListActivity";
private static final String TAG = "NotesListActivity";
public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;
public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;
private NoteItemData mFocusNoteDataItem;
private NoteItemData mFocusNoteDataItem;
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>"
+ Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)" + " OR ("
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER + " AND "
+ NoteColumns.NOTES_COUNT + ">0)";
private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>"
+ Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)" + " OR ("
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER + " AND "
+ NoteColumns.NOTES_COUNT + ">0)";
private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103;
private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.note_list);
initResources();
@Override//创建activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.note_list);
//getWindow().setBackgroundDrawableResource(R.drawable.list_background_light);
initResources();
/**
* Insert an introduction when user firstly use this application
*/
setAppInfoFromRawRes();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
mNotesListAdapter.changeCursor(null);
} else {
super.onActivityResult(requestCode, resultCode, data);
/**
* Insert an introduction when user firstly use this application
*/
setAppInfoFromRawRes();
}
}
private void setAppInfoFromRawRes() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
StringBuilder sb = new StringBuilder();
InputStream in = null;
try {
in = getResources().openRawResource(R.raw.introduction);
if (in != null) {
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
char [] buf = new char[1024];
int len = 0;
while ((len = br.read(buf)) > 0) {
sb.append(buf, 0, len);
//对子模块进行数据分析
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
mNotesListAdapter.changeCursor(null);
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
//从Res/Raw/下的introduction文件里导入资源
@TargetApi(Build.VERSION_CODES.KITKAT)
private void setAppInfoFromRawRes() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
StringBuilder sb = new StringBuilder();
InputStream in = null;
try {
in = getResources().openRawResource(R.raw.introduction); //加载软件自带的第一条便签内容
if (in != null) {
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
char [] buf = new char[1024];
int len = 0;
while ((len = br.read(buf)) > 0) {
sb.append(buf, 0, len);
}
} else {
Log.e(TAG, "Read introduction file error");
return;
}
} else {
Log.e(TAG, "Read introduction file error");
} catch (IOException e) {
e.printStackTrace();
return;
}
} catch (IOException e) {
e.printStackTrace();
return;
} finally {
if(in != null) {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if(in != null) {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
ResourceParser.RED);
note.setWorkingText(sb.toString());
if (note.saveNote()) {
sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
} else {
Log.e(TAG, "Save introduction note error");
return;
WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
ResourceParser.RED);
note.setWorkingText(sb.toString());
if (note.saveNote()) {
sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
} else {
Log.e(TAG, "Save introduction note error");
return;
}
}
}
}
@Override
protected void onStart() {
super.onStart();
startAsyncNotesListQuery();
}
private void initResources() {
mContentResolver = this.getContentResolver();
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mNotesListView = (ListView) findViewById(R.id.notes_list);
mNotesListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.note_list_footer, null),
null, false);
mNotesListView.setOnItemClickListener(new OnListItemClickListener());
mNotesListView.setOnItemLongClickListener(this);
mNotesListAdapter = new NotesListAdapter(this);
mNotesListView.setAdapter(mNotesListAdapter);
mAddNewNote = (Button) findViewById(R.id.btn_new_note);
mAddNewNote.setOnClickListener(this);
mAddNewNote.setOnTouchListener(new NewNoteOnTouchListener());
mDispatch = false;
mDispatchY = 0;
mOriginY = 0;
mTitleBar = (TextView) findViewById(R.id.tv_title_bar);
mState = ListEditState.NOTE_LIST;
mModeCallBack = new ModeCallback();
}
@Override
protected void onStart() {
super.onStart();
startAsyncNotesListQuery();
}
//加载原始资源,如界面背景、图标等
private void initResources() {
mContentResolver = this.getContentResolver();
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mNotesListView = (ListView) findViewById(R.id.notes_list);
mNotesListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.note_list_footer, null),
null, false);
mNotesListView.setOnItemClickListener(new OnListItemClickListener());
mNotesListView.setOnItemLongClickListener(this);
mNotesListAdapter = new NotesListAdapter(this);
mNotesListView.setAdapter(mNotesListAdapter);
mAddNewNote = (Button) findViewById(R.id.btn_new_note);
mAddNewNote.setOnClickListener(this);
mAddNewNote.setOnTouchListener(new NewNoteOnTouchListener());
mDispatch = false;
mDispatchY = 0;
mOriginY = 0;
mTitleBar = (TextView) findViewById(R.id.tv_title_bar);
mState = ListEditState.NOTE_LIST;
mModeCallBack = new ModeCallback();
}
//下拉菜单的实现
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
private DropdownMenu mDropDownMenu;
private ActionMode mActionMode;
private MenuItem mMoveMenu;
private DropdownMenu mDropDownMenu;//下拉菜单
private ActionMode mActionMode;//为用户提供一个action菜单
private MenuItem mMoveMenu;//菜单中不同的功能
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
getMenuInflater().inflate(R.menu.note_list_options, menu);
@ -271,7 +275,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private void updateMenu() {
int selectedCount = mNotesListAdapter.getSelectedCount();
// Update dropdown menu
// Update dropdown menu 更新下拉菜单
String format = getResources().getString(R.string.menu_select_title, selectedCount);
mDropDownMenu.setTitle(format);
MenuItem item = mDropDownMenu.findItem(R.id.action_select_all);
@ -440,7 +444,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
}
//文件夹相关操作
private void showFolderListMenu(Cursor cursor) {
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(R.string.menu_title_select_folder);
@ -452,7 +456,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mNotesListAdapter.getSelectedItemIds(), adapter.getItemId(which));
Toast.makeText(
NotesListActivity.this,
getString(R.string.format_move_notes_to_folder,
getString(R.string.format_move_notes_to_folder,
mNotesListAdapter.getSelectedCount(),
adapter.getFolderName(NotesListActivity.this, which)),
Toast.LENGTH_SHORT).show();
@ -461,17 +465,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
});
builder.show();
}
//新建便签
private void createNewNote() {
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mCurrentFolderId);
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
}
//删除便签
private void batchDelete() {
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
new AsyncTask<Params, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Params... unused) {
HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget();
if (!isSyncMode()) {
// if not synced, delete notes directly
@ -505,7 +509,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}.execute();
}
//删除文件夹
private void deleteFolder(long folderId) {
if (folderId == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Wrong folder id, should not happen " + folderId);
@ -539,7 +543,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
intent.putExtra(Intent.EXTRA_UID, data.getId());
this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
}
//打开文件夹
private void openFolder(NoteItemData data) {
mCurrentFolderId = data.getId();
startAsyncNotesListQuery();
@ -556,7 +560,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
mTitleBar.setVisibility(View.VISIBLE);
}
//监听是否点击新建便签的按钮
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_new_note:
@ -566,19 +570,19 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
break;
}
}
//显示软键盘
private void showSoftInput() {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
}
//隐藏软键盘
private void hideSoftInput(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
//创建或修改文件夹
private void showCreateOrModifyFolderDialog(final boolean create) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
@ -687,7 +691,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
break;
}
}
//更新微件(在桌面显示的便签微件)
private void updateWidget(int appWidgetId, int appWidgetType) {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
if (appWidgetType == Notes.TYPE_WIDGET_2X) {
@ -706,7 +710,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
sendBroadcast(intent);
setResult(RESULT_OK, intent);
}
//文件夹的查看、改名、删除
private final OnCreateContextMenuListener mFolderOnCreateContextMenuListener = new OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
if (mFocusNoteDataItem != null) {
@ -759,7 +763,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true;
}
//右上角菜单栏
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
@ -817,13 +821,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
return true;
}
//搜索便签
@Override
public boolean onSearchRequested() {
startSearch(null, false, null /* appData */, false);
return true;
}
//将便签导出为txt
private void exportNoteToText() {
final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
new AsyncTask<Void, Void, Integer>() {
@ -869,7 +873,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
}
//小米便签设置
private void startPreferenceActivity() {
Activity from = getParent() != null ? getParent() : this;
Intent intent = new Intent(from, NotesPreferenceActivity.class);
@ -916,7 +920,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
//查询目标文件夹
private void startQueryDestinationFolders() {
String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?";
selection = (mState == ListEditState.NOTE_LIST) ? selection:

@ -37,6 +37,7 @@ public class NotesListItem extends LinearLayout {
private TextView mCallName;
private NoteItemData mItemData;
private CheckBox mCheckBox;
private ImageView mLock;
public NotesListItem(Context context) {
super(context);
@ -46,6 +47,7 @@ public class NotesListItem extends LinearLayout {
mTime = (TextView) findViewById(R.id.tv_time);
mCallName = (TextView) findViewById(R.id.tv_name);
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
mLock = (ImageView) findViewById(R.id.iv_lock);
}
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
@ -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,6 +102,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);
}
}
}
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));

@ -0,0 +1,94 @@
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);
}
}

@ -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;
public 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;
}
});
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 841 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 904 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 536 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 670 B

@ -0,0 +1,36 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<group android:scaleX="1.01"
android:scaleY="1.01"
android:translateX="-0.54"
android:translateY="-0.54">
<path
android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:startY="49.59793"
android:startX="42.9492"
android:endY="92.4963"
android:endX="85.84757"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:strokeWidth="1"
android:strokeColor="#00000000"/>
</group>
</vector>

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z"/>
<path android:fillColor="#00000000" android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
</vector>

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="net.micode.notes.ui.UnlockActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:gravity="center"
android:text="请输入手势密码"
android:textSize="24sp"/>
<include layout="@layout/widget_lock_view"/>
</LinearLayout>

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="net.micode.notes.ui.UnlockActivity">
<TextView
android:id="@+id/tv_activity_set_lock_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:gravity="center"
android:text="设置手势密码\n(至少三个点)"
android:textSize="24sp"/>
<include layout="@layout/widget_lock_view"/>
<Button
android:id="@+id/btn_password_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_margin="24dp"
android:text="重新设置"
android:visibility="gone"/>
</LinearLayout>

@ -40,6 +40,14 @@
android:layout_marginRight="8dip"
android:textAppearance="@style/TextAppearanceSecondaryItem" />
<TextView
android:id="@+id/text_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="8dip"
/>
<ImageView
android:id="@+id/iv_alert_icon"
android:layout_width="wrap_content"
@ -56,6 +64,15 @@
android:layout_marginRight="8dip"
android:textAppearance="@style/TextAppearanceSecondaryItem" />
<TextView
android:id="@+id/tv_top_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dip"
android:layout_marginRight="20dip"
android:textAppearance="@style/TextAppearanceSecondaryItem" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"

@ -75,4 +75,11 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"/>
<ImageView
android:id="@+id/iv_lock"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"/>
</FrameLayout>

@ -37,6 +37,7 @@
android:textColor="#FFEAD1AE"
android:textSize="@dimen/text_font_size_medium" />
<ListView
android:id="@+id/notes_list"
android:layout_width="fill_parent"

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android">
<net.micode.notes.ui.LockPatternView
android:id="@+id/lockView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</merge>

@ -45,4 +45,12 @@
<item
android:id="@+id/menu_delete_remind"
android:title="@string/menu_remove_remind" />
<item
android:id="@+id/menu_set_password"
android:title="@string/menu_set_password" />
<item
android:id="@+id/menu_remove_password"
android:title="@string/menu_remove_password" />
</menu>

@ -17,11 +17,11 @@
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<!--
<item
android:id="@+id/menu_new_note"
android:title="@string/notelist_menu_new"/>
-->
<item
android:id="@+id/menu_delete"
android:title="@string/menu_delete"/>
@ -49,4 +49,13 @@
<item
android:id="@+id/menu_delete_remind"
android:title="@string/menu_remove_remind" />
<item
android:id="@+id/menu_set_password"
android:title="@string/menu_set_passcode" />
<item
android:id="@+id/menu_remove_password"
android:title="@string/menu_delete_passcode" />
</menu>

@ -36,4 +36,5 @@
<item
android:id="@+id/menu_search"
android:title="@string/menu_search"/>
</menu>

@ -0,0 +1,7 @@
<resources>
<style name="ThemeOverlay.Notesmaster.FullscreenContainer" parent="">
<item name="fullscreenBackgroundColor">@color/light_blue_900</item>
<item name="fullscreenTextColor">@color/light_blue_A400</item>
</style>
</resources>

@ -63,6 +63,8 @@
<string name="menu_send_to_desktop">发送到桌面</string>
<string name="menu_alert">提醒我</string>
<string name="menu_remove_remind">删除提醒</string>
<string name="menu_set_password">设置密码</string>
<string name="menu_remove_password">删除密码</string>
<string name="menu_title_select_folder">选择文件夹</string>
<string name="menu_move_parent_folder">上一级文件夹</string>
<string name="info_note_enter_desktop">已添加到桌面</string>
@ -122,5 +124,19 @@
<plurals name="search_results_title">
<item quantity="other"><xliff:g id="NUMBER">%1$s</xliff:g> 条符合“<xliff:g id="SEARCH">%2$s</xliff:g>”的搜索结果</item>
</plurals>
<string name="light_mode">亮背景</string>
<string name="night_mode">暗背景</string>
<string name="settings_short_label">设置</string>
<string name="settings_long_label">设置</string>
<string name="settings_disabled_message">打开设置失败</string>
<string name="add_note_short_label">新建便签</string>
<string name="add_note_long_label">新建便签</string>
<string name="add_note_disabled_message">新建便签失败</string>
<string name="menu_set_passcode">设置密码</string>
<string name="menu_delete_passcode">删除密码</string>
<string name="note_passcode_deleted">密码已删除</string>
<string name="menu_set_top">设置置顶</string>
<string name="menu_classify">分类</string>
<string name="menu_cancel_classify">取消分类</string>
</resources>

@ -64,6 +64,8 @@
<string name="menu_send_to_desktop">發送到桌面</string>
<string name="menu_alert">提醒我</string>
<string name="menu_remove_remind">刪除提醒</string>
<string name="menu_set_password">设置密码</string>
<string name="menu_remove_password">删除密码</string>
<string name="menu_title_select_folder">選擇文件夾</string>
<string name="menu_move_parent_folder">上一級文件夾</string>
<string name="info_note_enter_desktop">已添加到桌面</string>
@ -123,5 +125,19 @@
<plurals name="search_results_title">
<item quantity="other"><xliff:g id="NUMBER">%1$s</xliff:g> 條符合”<xliff:g id="SEARCH">%2$s</xliff:g>“的搜尋結果</item>
</plurals>
<string name="light_mode">亮背景</string>
<string name="night_mode">暗背景</string>
<string name="settings_short_label">設置</string>
<string name="settings_long_label">設置</string>
<string name="settings_disabled_message">打开設置失敗</string>
<string name="add_note_short_label">新建便簽</string>
<string name="add_note_long_label">新建便簽</string>
<string name="add_note_disabled_message">新建便簽失敗</string>
<string name="menu_set_passcode">設置密码</string>
<string name="menu_delete_passcode">删除密码</string>
<string name="note_passcode_deleted">密码已删除</string>
<string name="menu_set_top">設置置頂</string>
<string name="menu_classify">分類</string>
<string name="menu_cancel_classify">取消分類</string>
</resources>

@ -0,0 +1,6 @@
<resources>
<declare-styleable name="FullscreenAttrs">
<attr name="fullscreenBackgroundColor" format="color" />
<attr name="fullscreenTextColor" format="color" />
</declare-styleable>
</resources>

@ -17,4 +17,9 @@
<resources>
<color name="user_query_highlight">#335b5b5b</color>
<color name="light_blue_600">#FF039BE5</color>
<color name="light_blue_900">#FF01579B</color>
<color name="light_blue_A200">#FF40C4FF</color>
<color name="light_blue_A400">#FF00B0FF</color>
<color name="black_overlay">#66000000</color>
</resources>

@ -15,8 +15,7 @@
limitations under the License.
-->
<resources xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name">Notes</string>
<string name="app_widget2x2">Notes 2x2</string>
<string name="app_widget4x4">Notes 4x4</string>
@ -67,6 +66,8 @@
<string name="menu_send_to_desktop">Send to home</string>
<string name="menu_alert">Remind me</string>
<string name="menu_remove_remind">Delete reminder</string>
<string name="menu_set_password">Set password</string>
<string name="menu_remove_password">Remove password</string>
<string name="menu_title_select_folder">Select folder</string>
<string name="menu_move_parent_folder">Parent folder</string>
<string name="info_note_enter_desktop">Note added to home</string>
@ -127,9 +128,26 @@
<string name="datetime_dialog_ok">set</string>
<string name="datetime_dialog_cancel">cancel</string>
<plurals name="search_results_title">
<item quantity="one"><xliff:g id="number" example="1">%1$s</xliff:g> result for \"<xliff:g id="search" example="???">%2$s</xliff:g>\"</item>
<item quantity="one"><xliff:g example="1" id="number">%1$s</xliff:g> result for \"<xliff:g example="???" id="search">%2$s</xliff:g>\"</item>
<!-- Case of 0 or 2 or more results. -->
<item quantity="other"><xliff:g id="number" example="15">%1$s</xliff:g> results for \"<xliff:g id="search" example="???">%2$s</xliff:g>\"</item>
<item quantity="other"><xliff:g example="15" id="number">%1$s</xliff:g> results for \"<xliff:g example="???" id="search">%2$s</xliff:g>\"</item>
</plurals>
<string name="title_activity_splash">FullscreenActivity</string>
<string name="dummy_button">Dummy Button</string>
<string name="dummy_content">DUMMY\nCONTENT</string>
<string name="light_mode">light mode</string>
<string name="night_mode">night mode</string>
<string name="settings_short_label">Settings</string>
<string name="settings_long_label">Settings</string>
<string name="settings_disabled_message">unavailable</string>
<string name="add_note_short_label">Add note</string>
<string name="add_note_long_label">Add note</string>
<string name="add_note_disabled_message">Failed to add note</string>
<string name="menu_set_passcode">Set passcode</string>
<string name="menu_delete_passcode">Delete passcode</string>
<string name="note_passcode_deleted">passcode deleted</string>
<string name="menu_set_top">Set top</string>
<string name="menu_classify">Classify</string>
<string name="menu_cancel_classify">Cancel classification</string>
</resources>

@ -16,18 +16,22 @@
-->
<resources>
<style name="TextAppearanceSuper">
<item name="android:textSize">@dimen/text_font_size_super</item>
<item name="android:textColorLink">#0000ff</item>
</style>
<style name="TextAppearanceLarge">
<item name="android:textSize">@dimen/text_font_size_large</item>
<item name="android:textColorLink">#0000ff</item>
</style>
<style name="TextAppearanceMedium">
<item name="android:textSize">@dimen/text_font_size_medium</item>
<item name="android:textColorLink">#0000ff</item>
</style>
<style name="TextAppearanceNormal">
<item name="android:textSize">@dimen/text_font_size_normal</item>
<item name="android:textColorLink">#0000ff</item>
@ -49,7 +53,7 @@
</style>
<style name="HighlightTextAppearancePrimary">
<item name="android:textSize">@dimen/text_font_size_normal</item>
<item name="android:textSize">@dimen/text_font_size_normal</item>
<item name="android:textColor">@color/primary_text_dark</item>
</style>
@ -63,7 +67,16 @@
</style>
<style name="NoteActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:displayOptions" />
<item name="android:visibility">gone</item>
<!-- <item name="android:displayOptions" />-->
<item name="android:visibility">visible</item>
</style>
<style name="Widget.Theme.Notesmaster.ActionBar.Fullscreen" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/black_overlay</item>
</style>
<style name="Widget.Theme.Notesmaster.ButtonBar.Fullscreen" parent="">
<item name="android:background">@color/black_overlay</item>
<item name="android:buttonBarStyle">?android:attr/buttonBarStyle</item>
</style>
</resources>

@ -0,0 +1,16 @@
<resources>
<style name="Theme.Notesmaster" parent="Theme.AppCompat.Light" />
<style name="Theme.Notesmaster.Fullscreen" parent="Theme.Notesmaster">
<item name="android:actionBarStyle">@style/Widget.Theme.Notesmaster.ActionBar.Fullscreen
</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">@null</item>
</style>
<style name="ThemeOverlay.Notesmaster.FullscreenContainer" parent="">
<item name="fullscreenBackgroundColor">@color/light_blue_600</item>
<item name="fullscreenTextColor">@color/light_blue_A200</item>
</style>
</resources>

@ -0,0 +1 @@
这是杨廷楷的branch
Loading…
Cancel
Save