完善维护了密码功能包括:

1、用Activity实现密码检验
2、设置密码和删除密码逻辑的完善
3、加密便签内容不可见和加密标志的添加
pull/9/head
xxl 3 years ago
parent 2a42d48dbb
commit d330687bad

@ -82,12 +82,12 @@
android:resource="@xml/searchable" />
</activity>
<activity
android:name=".ui.PassWordEditActivity"
android:theme="@style/NoteActionBarStyle">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
android:name=".ui.PassWordEditActivity"
android:theme="@style/NoteActionBarStyle">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<provider

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 B

@ -14,10 +14,63 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<EditText
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/et_foler_name"
android:layout_width="fill_parent"
android:hint="@string/hint_foler_name"
android:layout_height="fill_parent" />
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/et_foler_name_old_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="输入原密码:"/>
<EditText
android:id="@+id/et_foler_name_old"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:password="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/et_foler_name_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="输入新建密码:"/>
<EditText
android:id="@+id/et_foler_name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:password="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/et_foler_name_again_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确认密码:"/>
<EditText
android:id="@+id/et_foler_name_again"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:password="true"/>
</LinearLayout>
</LinearLayout>

@ -17,6 +17,7 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/note_item"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
@ -75,4 +76,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"/>
<ImageView
android:id="@+id/iv_locker_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"/>
</FrameLayout>

@ -50,12 +50,9 @@
android:id="@+id/menu_delete_remind"
android:title="@string/menu_remove_remind" />
<item
<<<<<<< HEAD
=======
android:id="@+id/top"
android:title="Top" />
<item
>>>>>>> e012e4479fa528d71d041140775f3e142df8eab2
android:id="@+id/menu_set_passwd"
android:title="Set password" />
<item

@ -62,6 +62,10 @@ public class Notes {
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
public interface NoteColumns {
/**
*
*/
public static final String LOCKER="_locker";
/**
*
*/

@ -61,13 +61,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0," +
<<<<<<< HEAD
NoteColumns.PASSWORD+ " TEXT NOT NULL DEFAULT ''" +
=======
NoteColumns.PASSWORD+ " TEXT NOT NULL DEFAULT ''," +
NoteColumns.TOP+" INTEGER NOT NULL DEFAULT 0"+
NoteColumns.TOP+" INTEGER NOT NULL DEFAULT 0,"+
NoteColumns.LOCKER + " INTEGER NOT NULL DEFAULT 0" +
>>>>>>> e012e4479fa528d71d041140775f3e142df8eab2
//NoteColumns.PASSWORD+ " INTEGER NOT NULL DEFAULT 0" +
")";
@ -333,6 +330,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
upgradeToV5(db);
oldVersion++;
}
if (oldVersion == 5) {
upgradeToV6(db);
oldVersion++;
}
if (reCreateTriggers) {
reCreateNoteTableTriggers(db);
@ -375,5 +376,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.TOP
+ " INTEGER NOT NULL DEFAULT 0");
}
private void upgradeToV6(SQLiteDatabase db){
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.LOCKER
+ " INTEGER NOT NULL DEFAULT 0");
}
}

@ -33,13 +33,14 @@ import net.micode.notes.R;
import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
import net.micode.notes.gtask.data.SqlNote;
public class NotesProvider extends ContentProvider {
private static final UriMatcher mMatcher;
private NotesDatabaseHelper mHelper;
//创建帮助找到下了锁的对应的便签
private static NotesDatabaseHelper mFind_Locker_Helper;
private static final String TAG = "NotesProvider";
private static final int URI_NOTE = 1;
@ -82,6 +83,7 @@ public class NotesProvider extends ContentProvider {
@Override
public boolean onCreate() {
mHelper = NotesDatabaseHelper.getInstance(getContext());
mFind_Locker_Helper=NotesDatabaseHelper.getInstance(getContext());
return true;
}
@ -301,5 +303,25 @@ public class NotesProvider extends ContentProvider {
// TODO Auto-generated method stub
return null;
}
//判断是否上锁
public static boolean isLockedNote(Long id) {
SQLiteDatabase db = mFind_Locker_Helper.getReadableDatabase();
Cursor cursor = null;
cursor = db.query(NotesDatabaseHelper.TABLE.NOTE, null, null, null, null, null, null);
//判断游标是否为空
System.out.println(cursor.getCount());
if (cursor.moveToFirst()) {
//遍历游标
for (int index = 1; index < cursor.getCount(); index++) {
if (cursor.getLong(SqlNote.ID_COLUMN) == id && !cursor.getString(SqlNote.LOCKER_COLUMN).equals("0")) {
cursor.close();
return true;
}
cursor.moveToNext();
}
}
cursor.close();
return false;
}
}

@ -49,7 +49,7 @@ public class SqlNote {
NoteColumns.NOTES_COUNT, NoteColumns.PARENT_ID, NoteColumns.SNIPPET, NoteColumns.TYPE,
NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, NoteColumns.SYNC_ID,
NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID,
NoteColumns.VERSION
NoteColumns.VERSION,NoteColumns.LOCKER
};
public static final int ID_COLUMN = 0;
@ -85,6 +85,7 @@ public class SqlNote {
public static final int GTASK_ID_COLUMN = 15;
public static final int VERSION_COLUMN = 16;
public static final int LOCKER_COLUMN = 17;
private Context mContext;

@ -64,6 +64,8 @@ public class WorkingNote {
private NoteSettingChangedListener mNoteSettingStatusListener;
//新添加的密码变量
private String mPassword;
//添加密码标志
private String mLocker;
public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
@ -84,10 +86,8 @@ public class WorkingNote {
NoteColumns.MODIFIED_DATE,
//增加一个密码项
NoteColumns.PASSWORD,
<<<<<<< HEAD
=======
NoteColumns.TOP,
>>>>>>> e012e4479fa528d71d041140775f3e142df8eab2
NoteColumns.LOCKER,
};
private static final int DATA_ID_COLUMN = 0;
@ -111,6 +111,8 @@ public class WorkingNote {
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
//密码
private static final int NOTE_PASSWORD_COLUMN=6;
//密码标志
private static final int NOTE_LOCKER_COLUMN=8;
/**
@ -143,6 +145,11 @@ public class WorkingNote {
public String getmPassword(){
return mPassword;
}
//设置密码标志
public void setLocker(String mlocker){
mLocker=mlocker;//1标志为上锁了 0标志为没有上锁
mNote.setNoteValue(NoteColumns.LOCKER,mLocker);
}
// New note construct
private WorkingNote(Context context, long folderId) {
@ -186,6 +193,8 @@ public class WorkingNote {
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
//密码
mPassword= cursor.getString(NOTE_PASSWORD_COLUMN);
//密码标志
mLocker=cursor.getString(NOTE_LOCKER_COLUMN);
}
cursor.close();
} else {

@ -25,10 +25,14 @@ import android.content.OperationApplicationException;
import android.database.Cursor;
import android.os.RemoteException;
import android.util.Log;
import android.widget.Toast;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.CallNote;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesProvider;
import net.micode.notes.ui.NoteEditActivity;
import net.micode.notes.ui.NotesListActivity;
import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import java.util.ArrayList;
@ -53,6 +57,12 @@ public class DataUtils {
Log.e(TAG, "Don't delete system folder root");
continue;
}
/**
*
*/
if (NotesProvider.isLockedNote(id)){
continue;
}
ContentProviderOperation.Builder builder = ContentProviderOperation
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
operationList.add(builder.build());

@ -45,10 +45,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
<<<<<<< HEAD
=======
import android.widget.Button;
>>>>>>> e012e4479fa528d71d041140775f3e142df8eab2
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
@ -154,6 +151,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private String mUserQuery;
private Pattern mPattern;
//private int flag=0;//作为判断删除密码时有无验证通过
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -282,16 +280,23 @@ public class NoteEditActivity extends Activity implements OnClickListener,
//创建dialog插入edittext用户输入密码并做出检验。
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
//编辑Text
//编辑dialog界面
final EditText etNameOld= (EditText)view.findViewById(R.id.et_foler_name_old);//只需要验证原密码
final EditText etName = (EditText) view.findViewById(R.id.et_foler_name);
etName.setText("");
etName.setHint("请输入密码");
etName.setVisibility(view.GONE);
final TextView etName_View=(TextView)view.findViewById(R.id.et_foler_name_view);
etName_View.setVisibility(view.GONE);
final EditText etNameAgain = (EditText) view.findViewById(R.id.et_foler_name_again);
etNameAgain.setVisibility(view.GONE);
final TextView etNameAgain_View=(TextView)view.findViewById(R.id.et_foler_name_again_view);
etNameAgain_View.setVisibility(view.GONE);
//
builder.setTitle("密码检验");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//获取输入的字符串
String password = etName.getText().toString();
String password = etNameOld.getText().toString();
Log.d("mPassword: ", mPassword);
Log.d("password: ", password);
//判断密码正确性
@ -299,25 +304,24 @@ public class NoteEditActivity extends Activity implements OnClickListener,
Log.d("密码不正确,正确密码是:",mPassword);
Toast.makeText(NoteEditActivity.this, "密码错误", Toast.LENGTH_SHORT).show();
dialog.dismiss();
onBackPressed();
<<<<<<< HEAD
=======
//onBackPressed();
//关闭软键盘
InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(etName.getWindowToken(),0);
>>>>>>> e012e4479fa528d71d041140775f3e142df8eab2
}
else{
Toast.makeText(NoteEditActivity.this, "密码正确", Toast.LENGTH_SHORT).show();
//flag=1;//密码验证正确的标志
deletePassword();
Toast.makeText(NoteEditActivity.this, "密码正确,删除密码成功。", Toast.LENGTH_SHORT).show();
return;
}
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
onBackPressed();
finish();
}
});
final Dialog dialog = builder.setView(view).show();
@ -584,9 +588,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
deleteCurrentNote();
finish();
}
if (!mWorkingNote.hasPassword()) {//判断有无密码,有密码则无法删除
deleteCurrentNote();
finish();
}
else{
Toast.makeText(NoteEditActivity.this, "无法删除设密便签", Toast.LENGTH_SHORT).show();
return;
}
}
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.show();
@ -619,15 +629,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
//删除密码
case R.id.menu_delete_passwd:
//删除密码前要检验密码
checkPassword();
deletePassword();
checkPassword();//并且在里边一并执行deletepassword函数
break;
<<<<<<< HEAD
=======
case R.id.top:
mWorkingNote.setTop((mWorkingNote.getTopId()) == 1 ? "0" : "1");
break;
>>>>>>> e012e4479fa528d71d041140775f3e142df8eab2
default:
break;
}
@ -638,17 +644,59 @@ public class NoteEditActivity extends Activity implements OnClickListener,
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
final View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text,null);
//编辑Text
final EditText etName = (EditText)view.findViewById(R.id.et_foler_name);
final EditText etNameOld= (EditText)view.findViewById(R.id.et_foler_name_old);//如果设置了密码,这是原密码
etNameOld.setVisibility(view.GONE);
final TextView etNameOld_View=(TextView)view.findViewById(R.id.et_foler_name_old_view);
etNameOld_View.setVisibility(view.GONE);
if (mWorkingNote.hasPassword()){//如果设置了密码
etNameOld.setVisibility(view.VISIBLE);
etNameOld_View.setVisibility(view.VISIBLE);
etNameOld.setText("");
etNameOld.setHint("请输入原密码");
}
final EditText etName = (EditText)view.findViewById(R.id.et_foler_name);//要设置的密码
final EditText etNameAgain=(EditText)view.findViewById(R.id.et_foler_name_again);//确认密码
//final EditText finalEtNameOld = etNameOld;
etName.setText("");
etName.setHint("请输入密码");
builder.setTitle("为便签设置新密码");
etNameAgain.setText("");
etNameAgain.setHint("请确认密码");
builder.setTitle("设置密码");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//获取输入的字符串
String password = etName.getText().toString();
String password_again=etNameAgain.getText().toString();
String password_old = null;
if (mWorkingNote.hasPassword()){
password_old= etNameOld.getText().toString();
}
//当输入原密码不对时
if (mWorkingNote.hasPassword()) {
if(!password_old.equals(mWorkingNote.getmPassword())) {
Toast.makeText(NoteEditActivity.this, "原密码错误", Toast.LENGTH_SHORT).show();
return;
}
}
//当设置的密码为空的时候
if (password==null || password.length()==0){
//关闭软键盘
InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(etName.getWindowToken(),0);
dialog.dismiss();
Toast.makeText(NoteEditActivity.this, "密码不能为空", Toast.LENGTH_SHORT).show();
return;
}
//当确认密码不对时
if (!password.equals(password_again)){
Toast.makeText(NoteEditActivity.this, "密码不一致", Toast.LENGTH_SHORT).show();
return;
}
//设置密码
mWorkingNote.setPassword(password);
mWorkingNote.setLocker("1");//设置密码标志为上锁
//设置密码成功提示
Toast.makeText(NoteEditActivity.this, "密码设置成功", Toast.LENGTH_SHORT).show();
//关闭软键盘
@ -675,10 +723,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public void deletePassword()
{
mWorkingNote.setPassword("");
<<<<<<< HEAD
=======
mWorkingNote.setLocker("0");//设置密码标志为没有锁
//onBackPressed();
>>>>>>> e012e4479fa528d71d041140775f3e142df8eab2
}
private void setReminder() {

@ -19,6 +19,7 @@ package net.micode.notes.ui;
import android.content.Context;
import android.database.Cursor;
import android.text.TextUtils;
import android.util.Log;
import net.micode.notes.data.Contact;
import net.micode.notes.data.Notes;
@ -40,6 +41,7 @@ public class NoteItemData {
NoteColumns.TYPE,
NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE,
NoteColumns.LOCKER,
};
private static final int ID_COLUMN = 0;
@ -54,6 +56,8 @@ 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 LOCKER_COLUMN=12;
private long mId;
private long mAlertDate;
@ -69,6 +73,8 @@ public class NoteItemData {
private int mWidgetType;
private String mName;
private String mPhoneNumber;
//密码标志
private String mLocker;
private boolean mIsLastItem;
private boolean mIsFirstItem;
@ -76,6 +82,17 @@ public class NoteItemData {
private boolean mIsOneNoteFollowingFolder;
private boolean mIsMultiNotesFollowingFolder;
//判断是否上锁
public boolean isLocked(){
if(mLocker.equals("0")) {
Log.d("标志是", mLocker);
return false;
}else {
Log.d("标志是", mLocker);
return true;
}
}
public NoteItemData(Context context, Cursor cursor) {
mId = cursor.getLong(ID_COLUMN);
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);
@ -91,6 +108,7 @@ public class NoteItemData {
mType = cursor.getInt(TYPE_COLUMN);
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
mLocker = cursor.getString(LOCKER_COLUMN);
mPhoneNumber = "";
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {

@ -910,7 +910,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
case SUB_FOLDER:
case CALL_RECORD_FOLDER:
if (item.getType() == Notes.TYPE_NOTE) {
openNode(item);
//打开PassWordEditAcitivity类并传递noteid
Intent intent = new Intent(NotesListActivity.this, PassWordEditActivity.class);
long noteId = item.getId();
intent.putExtra("noteId", noteId);
startActivity(intent);
//
//openNode(item);
} else {
Log.e(TAG, "Wrong note type in SUB_FOLDER");
}

@ -37,7 +37,7 @@ public class NotesListItem extends LinearLayout {
private TextView mCallName;
private NoteItemData mItemData;
private CheckBox mCheckBox;
private ImageView mLocker;
public NotesListItem(Context context) {
super(context);
inflate(context, R.layout.note_item, this);
@ -46,6 +46,8 @@ 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);
//添加锁的标志
mLocker =(ImageView)findViewById(R.id.iv_locker_icon);
}
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.isLocked()){
mLocker.setImageResource(R.drawable.ic_lock_idle_lock);
mLocker.setVisibility(View.VISIBLE);
} else{
mLocker.setVisibility(View.GONE);
}
*/
} else {
mCallName.setVisibility(View.GONE);
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
@ -92,6 +102,16 @@ public class NotesListItem extends LinearLayout {
} else {
mAlert.setVisibility(View.GONE);
}
//设置密码标志以及使加密便签内容不可见,未加密则可见。
if(data.isLocked()){
mLocker.setImageResource(R.drawable.ic_lock_idle_lock);
mLocker.setVisibility(View.VISIBLE);
String text = "已加密";
mTitle.setText(text);
} else{
mLocker.setVisibility(View.GONE);
}
//
}
}
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));

@ -9,10 +9,6 @@ import android.widget.Button;
import android.widget.EditText;
import android.os.Bundle;
import android.widget.Toast;
<<<<<<< HEAD
=======
>>>>>>> e012e4479fa528d71d041140775f3e142df8eab2
import net.micode.notes.R;
import net.micode.notes.model.WorkingNote;
@ -33,10 +29,6 @@ public class PassWordEditActivity extends Activity {
finish();
return;
}
<<<<<<< HEAD
=======
>>>>>>> e012e4479fa528d71d041140775f3e142df8eab2
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_password);
//不知道作用
@ -44,12 +36,6 @@ public class PassWordEditActivity extends Activity {
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//
<<<<<<< HEAD
=======
>>>>>>> e012e4479fa528d71d041140775f3e142df8eab2
boolean User_boolean = mWorkingNote.hasPassword();//获取用户是否设置了密码
if(!User_boolean) //User_boolean = false时没有设置密码直接跳转到便签主界面
{
@ -97,9 +83,4 @@ public class PassWordEditActivity extends Activity {
}
return false;
}
<<<<<<< HEAD
=======
>>>>>>> e012e4479fa528d71d041140775f3e142df8eab2
}

Loading…
Cancel
Save