九宫格加密

pull/3/head
JackyMa 3 years ago
parent 13544b513d
commit 4cea143bbe

@ -169,6 +169,8 @@ public class Notes {
public static final String TOP = "top";
public static final String STAR = "star";
public static final String PASSCODE = "passcode";
}
public interface DataColumns {

@ -62,7 +62,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT 1," +
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.TOP + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.STAR + " INTEGER NOT NULL DEFAULT 0" +
NoteColumns.STAR + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.PASSCODE + " TEXT NOT NULL DEFAULT ''"+
")";
private static final String CREATE_DATA_TABLE_SQL =

@ -61,8 +61,15 @@ public class WorkingNote {
private boolean mIsDeleted;
/**记录便签已设置密码*/
private String mPasscode = "";
/**记录已置顶便签*/
private String mTop = "0";
/**记录便签所属类别*/
private int mClass;
private String mStar = "0";
private NoteSettingChangedListener mNoteSettingStatusListener;
@ -86,6 +93,7 @@ public class WorkingNote {
NoteColumns.MODIFIED_DATE,
NoteColumns.TOP,
NoteColumns.STAR,
NoteColumns.PASSCODE,
};
private static final int DATA_ID_COLUMN = 0;
@ -112,6 +120,8 @@ public class WorkingNote {
private static final int NOTE_STAR_COLUMN = 7;
private static final int NOTE_PASSCODE_COLUMN = 8;
// New note construct
private WorkingNote(Context context, long folderId) {
mContext = context;
@ -125,6 +135,7 @@ public class WorkingNote {
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
mTop = String.valueOf(getTopId());
mStar = String.valueOf(getStarId());
mPasscode = String.valueOf(getPasscode());
}
// Existing note construct
@ -152,6 +163,7 @@ public class WorkingNote {
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
mTop = cursor.getString(NOTE_TOP_COLUMN);
mStar = cursor.getString(NOTE_STAR_COLUMN);
mPasscode = cursor.getString(NOTE_PASSCODE_COLUMN);
}
cursor.close();
} else {
@ -268,6 +280,7 @@ public class WorkingNote {
}
public void setAlertDate(long date, boolean set) {
if (date != mAlertDate) {
mAlertDate = date;
@ -337,6 +350,22 @@ public class WorkingNote {
return (mAlertDate > 0 ? true : false);
}
/**判断是否已经设置密码*/
public boolean hasPasscode() {
return !mPasscode.equals("");
}
/**设置便签访问密码,并存入数据库*/
public void setPasscode(String passcode) {
mPasscode = passcode;
mNote.setNoteValue(NoteColumns.PASSCODE, passcode);
}
/**获取设置的密码*/
public String getPasscode() {
return mPasscode;
}
public int getTopId() {
if (mTop.equals("1")) {
return 1;

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

@ -523,6 +523,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_passcode).setVisible(false);
} else {
menu.findItem(R.id.menu_delete_passcode).setVisible(false);
}
return true;
}
@ -534,15 +540,20 @@ public class NoteEditActivity extends Activity implements OnClickListener,
break;
case R.id.menu_set_top:
mWorkingNote.setTop((mWorkingNote.getTopId())==1 ? "0" : "1");
finish();
break;
case R.id.menu_cancel_top:
mWorkingNote.setTop((mWorkingNote.getTopId())==0 ? "1" : "0");
finish();
break;
case R.id.menu_set_star:
mWorkingNote.setStar(mWorkingNote.getStarId()==1? "0" : "1");
finish();
break;
//设置密码
case R.id.menu_set_passcode:
setPasscode();
break;
//删除密码
case R.id.menu_delete_passcode:
deletePasscode();
break;
case R.id.menu_delete:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
@ -658,9 +669,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
* User could set clock to an unsaved note, so before setting the
* alert clock, we should save the note first
*/
if (!mWorkingNote.existInDatabase()) {
saveNote();
}
saveNote();
if (mWorkingNote.getNoteId() > 0) {
showTopHeader();
} else {
@ -679,9 +688,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
* User could set clock to an unsaved note, so before setting the
* alert clock, we should save the note first
*/
if (!mWorkingNote.existInDatabase()) {
saveNote();
}
saveNote();
}
public void onClockAlertChanged(long date, boolean set) {
@ -893,6 +900,29 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return saved;
}
/**
*
*/
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 sendToDesktop() {
/**
* Before send message to home, we should make sure that current

@ -42,6 +42,7 @@ public class NoteItemData {
NoteColumns.WIDGET_TYPE,
NoteColumns.TOP,
NoteColumns.STAR,
NoteColumns.PASSCODE,
};
private static final int ID_COLUMN = 0;
@ -58,6 +59,7 @@ public class NoteItemData {
private static final int WIDGET_TYPE_COLUMN = 11;
private static final int TOP_ID_COLUMN = 12;
private static final int STAR_ID_COLUMN = 13;
private static final int PASSCODE_COLUMN = 14;
private long mId;
private long mAlertDate;
@ -75,6 +77,7 @@ public class NoteItemData {
private String mPhoneNumber;
private String mTop;
private String mStar;
private String mPasscode;
private boolean mIsLastItem;
private boolean mIsFirstItem;
@ -99,6 +102,7 @@ public class NoteItemData {
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
mTop = cursor.getString(TOP_ID_COLUMN);
mStar = cursor.getString(STAR_ID_COLUMN);
mPasscode = cursor.getString(PASSCODE_COLUMN);
mPhoneNumber = "";
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {
@ -186,6 +190,8 @@ public class NoteItemData {
return mId;
}
public boolean hasLock() { return !mPasscode.equals(""); }
public long getAlertDate() {
return mAlertDate;
}

@ -39,6 +39,7 @@ public class NotesListItem extends LinearLayout {
private CheckBox mCheckBox;
private ImageView mTop;
private ImageView mStar;
private ImageView mLock;
public NotesListItem(Context context) {
super(context);
@ -50,6 +51,7 @@ public class NotesListItem extends LinearLayout {
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
mTop = (ImageView) findViewById(R.id.iv_top_icon);
mStar =(ImageView) findViewById(R.id.iv_star_icon);
mLock = (ImageView) findViewById(R.id.iv_lock);
}
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
@ -107,6 +109,14 @@ public class NotesListItem extends LinearLayout {
} else{
mStar.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,95 @@
package net.micode.notes.ui;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.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 androidx.appcompat.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;
}
});
}
}

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)

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: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

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

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:background="@drawable/splash"
android:theme="@style/ThemeOverlay.Notesmaster.FullscreenContainer"
tools:context=".ui.SplashActivity">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<TextView
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:text="@string/dummy_content"
android:textColor="?attr/fullscreenTextColor"
android:textSize="50sp"
android:textStyle="bold" />
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/fullscreen_content_controls"
style="@style/Widget.Theme.Notesmaster.ButtonBar.Fullscreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button
android:id="@+id/dummy_button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/dummy_button" />
</LinearLayout>
</FrameLayout>
</FrameLayout>

@ -89,4 +89,11 @@
android:layout_height="17dp"
android:layout_gravity="top|right"
android:layout_marginRight="20sp" />
<ImageView
android:id="@+id/iv_lock"
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_gravity="top|left"
android:layout_marginRight="15sp" />
</FrameLayout>

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

@ -34,6 +34,14 @@
android:id="@+id/menu_set_star"
android:title="@string/menu_set_star"/>
<item
android:id="@+id/menu_set_passcode"
android:title="@string/menu_set_passcode"/>
<item
android:id="@+id/menu_delete_passcode"
android:title="@string/menu_delete_passcode"/>
<item
android:id="@+id/menu_delete"
android:title="@string/menu_delete"/>

@ -67,6 +67,9 @@
<string name="menu_cancel_top">取消置顶</string>
<string name="menu_set_star">星标</string>
<string name="menu_delete_star">删除星标</string>
<string name="menu_set_passcode">加密</string>
<string name="menu_delete_passcode">取消加密</string>
<string name="note_passcode_deleted">密码已删除</string>
<string name="menu_title_select_folder">选择文件夹</string>
<string name="menu_move_parent_folder">上一级文件夹</string>
<string name="info_note_enter_desktop">已添加到桌面</string>

@ -68,6 +68,9 @@
<string name="menu_cancel_top">取消置顶</string>
<string name="menu_set_star">星标</string>
<string name="menu_delete_star">删除星标</string>
<string name="menu_set_passcode">加密</string>
<string name="menu_delete_passcode">取消加密</string>
<string name="note_passcode_deleted">密码已删除</string>
<string name="menu_title_select_folder">選擇文件夾</string>
<string name="menu_move_parent_folder">上一級文件夾</string>
<string name="info_note_enter_desktop">已添加到桌面</string>

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

@ -17,6 +17,8 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="dummy_content">DUMMY\nCONTENT</string>
<string name="dummy_button">Dummy Button</string>
<string name="app_name">Notes</string>
<string name="app_widget2x2">Notes 2x2</string>
<string name="app_widget4x4">Notes 4x4</string>
@ -71,6 +73,9 @@
<string name="menu_cancel_top">Cancel Top</string>
<string name="menu_set_star">Star</string>
<string name="menu_delete_star">Delete Star</string>
<string name="menu_set_passcode">Lock</string>
<string name="menu_delete_passcode">Delete Lock</string>
<string name="note_passcode_deleted">Passcode has deleted</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>

@ -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: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>
Loading…
Cancel
Save