完善了增加密码功能:

验证密码通过一个Avtivity实现
增加删除密码功能,删除密码需要再次验证密码。
解决了之前版本新建便签时会报错的bug
解决了新建便签仍然需要密码验证且默认密码为0的bug
主要修改:
修改了AndroidManifest.xml文件,增加了一个新的Activity
增加了一个activity_password.xml文件作为验证密码时的布局
对于验证密码、修改密码、设置密码等相关代码打包成了函数。
pull/7/head
xxl 3 years ago
parent acaedfb5c5
commit 1a6ea7fb5e

@ -16,11 +16,12 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="net.micode.notes"
android:versionCode="1"
android:versionName="0.1" >
<uses-sdk android:minSdkVersion="14" />
<!--uses-sdk android:minSdkVersion="14" /-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
@ -41,8 +42,9 @@
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/NoteTheme"
android:uiOptions="splitActionBarWhenNarrow"
android:windowSoftInputMode="adjustPan" >
<!--android:uiOptions="splitActionBarWhenNarrow"-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -79,6 +81,14 @@
android:name="android.app.searchable"
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>
<provider
android:name="net.micode.notes.data.NotesProvider"

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="用户:"/>-->
<!-- <EditText-->
<!-- android:id="@+id/lg_user"-->
<!-- android:layout_width="150dp"-->
<!-- android:layout_height="wrap_content" />-->
<!-- </LinearLayout>-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码:"/>
<EditText
android:id="@+id/password"
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">
<Button
android:id="@+id/set_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确认"/>
<!-- <Button-->
<!-- android:id="@+id/lg_registered"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="注册"/>-->
</LinearLayout>
</LinearLayout>

@ -15,8 +15,7 @@
limitations under the License.
-->
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/list_background"
@ -59,10 +58,9 @@
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/bg_btn_set_color" />
</LinearLayout>
<LinearLayout
@ -73,17 +71,17 @@
<ImageView
android:layout_width="fill_parent"
android:layout_height="49dp"
android:layout_height="7dip"
android:background="@drawable/bg_color_btn_mask" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_gravity="left|top"
android:layout_weight="1"
android:fadingEdgeLength="0dip"
android:scrollbars="none"
android:overScrollMode="never"
android:scrollbars="none">
android:layout_gravity="left|top"
android:fadingEdgeLength="0dip">
<LinearLayout
android:layout_width="fill_parent"
@ -93,43 +91,37 @@
android:id="@+id/note_edit_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="all"
android:background="@null"
android:gravity="left|top"
android:lineSpacingMultiplier="1.2"
android:background="@null"
android:autoLink="all"
android:linksClickable="false"
android:minLines="12"
android:textAppearance="@style/TextAppearancePrimaryItem" />
android:textAppearance="@style/TextAppearancePrimaryItem"
android:lineSpacingMultiplier="1.2" />
<LinearLayout
android:id="@+id/note_edit_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-10dip"
android:orientation="vertical"
android:layout_marginLeft="-10dip"
android:visibility="gone" />
</LinearLayout>
</ScrollView>
<ImageView
android:id="@+id/m_locker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4CAF50"
android:src="@drawable/bg_color_btn_mask"
tools:src="@android:drawable/ic_lock_idle_lock" />
android:layout_width="fill_parent"
android:layout_height="7dip"
android:background="@drawable/bg_color_btn_mask" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/btn_set_bg_color"
android:layout_width="111dp"
android:layout_height="64dp"
android:layout_gravity="top|right"
android:background="@drawable/bg_color_btn_mask" />
android:layout_height="43dip"
android:layout_width="wrap_content"
android:background="@drawable/bg_color_btn_mask"
android:layout_gravity="top|right" />
<LinearLayout
android:id="@+id/note_bg_color_selector"
@ -405,5 +397,4 @@
android:src="@drawable/selected" />
</FrameLayout>
</LinearLayout>
</FrameLayout>

@ -39,13 +39,13 @@
<ListView
android:id="@+id/notes_list"
android:layout_width="464dp"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:cacheColorHint="@null"
android:listSelector="@android:color/transparent"
android:divider="@null"
android:fadingEdge="@null"
android:listSelector="@android:color/transparent" />
android:fadingEdge="@null" />
</LinearLayout>
<Button

@ -45,4 +45,10 @@
<item
android:id="@+id/menu_delete_remind"
android:title="@string/menu_remove_remind" />
<item
android:id="@+id/menu_set_passwd"
android:title="Set password" />
<item
android:id="@+id/menu_delete_passwd"
android:title="Delete password" />
</menu>

@ -49,4 +49,10 @@
<item
android:id="@+id/menu_delete_remind"
android:title="@string/menu_remove_remind" />
<item
android:id="@+id/menu_set_passwd"
android:title="Set password" />
<item
android:id="@+id/menu_delete_passwd"
android:title="Delete password" />
</menu>

@ -61,7 +61,8 @@ 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," +
NoteColumns.PASSWORD+ " INTEGER NOT NULL DEFAULT 0" +
NoteColumns.PASSWORD+ " TEXT NOT NULL DEFAULT ''" +
//NoteColumns.PASSWORD+ " INTEGER NOT NULL DEFAULT 0" +
")";
private static final String CREATE_DATA_TABLE_SQL =

@ -17,14 +17,12 @@
package net.micode.notes.gtask.remote;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import net.micode.notes.R;
import net.micode.notes.ui.NotesListActivity;
@ -65,7 +63,6 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
});
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void showNotification(int tickerId, String content) {
Notification notification = new Notification(R.drawable.notification, mContext
.getString(tickerId), System.currentTimeMillis());
@ -80,17 +77,8 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
NotesListActivity.class), 0);
}
//notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content,
// pendingIntent);
notification = new Notification.Builder(mContext)
.setContentIntent(pendingIntent)
.setTicker(mContext.getString(R.string.app_name))
.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);
}

@ -64,19 +64,6 @@ public class WorkingNote {
//新添加的密码变量
private String mPassword;
/**
* 便访
* @param password 访
*/
public void setPassword(String password){
//将该类的mPassword属性设置为新的访问密码
mPassword = password;
//将修改后的便签密码写入到便签数据库中
mNote.setNoteValue(NoteColumns.PASSWORD,mPassword);
}
public String getmPassword(){
return mPassword;
}
public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
DataColumns.CONTENT,
@ -117,8 +104,41 @@ public class WorkingNote {
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
//密码
//密码
private static final int NOTE_PASSWORD_COLUMN=6;
/**
* 便访
* @param password 访
*/
public void setPassword(String password){
//将该类的mPassword属性设置为新的访问密码
mPassword = password;
//将修改后的便签密码写入到便签数据库中
mNote.setNoteValue(NoteColumns.PASSWORD,mPassword);
}
public boolean hasPassword()
{
if (mPassword!=null && mPassword.length()!=0)
//if (!mPassword.equals(""))
{
Log.d("密码是:", String.valueOf(true));
Log.d("密码是",mPassword);
return true;
}
else{
Log.d("密码是:", String.valueOf(false));
return false;
}
}
//获取密码
public String getmPassword(){
return mPassword;
}
// New note construct
private WorkingNote(Context context, long folderId) {
mContext = context;
@ -130,6 +150,8 @@ public class WorkingNote {
mIsDeleted = false;
mMode = 0;
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
//导入便签
loadNote();
}
// Existing note construct

@ -78,7 +78,6 @@ public class DateTimePickerDialog extends AlertDialog implements OnClickListener
DateUtils.FORMAT_SHOW_DATE |
DateUtils.FORMAT_SHOW_TIME;
flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR;
//flag =DateUtils.FORMAT_24HOUR;
setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));
}

@ -19,6 +19,7 @@ package net.micode.notes.ui;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.PendingIntent;
import android.app.SearchManager;
import android.appwidget.AppWidgetManager;
@ -43,6 +44,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
@ -62,11 +64,6 @@ import net.micode.notes.tool.ResourceParser;
import net.micode.notes.tool.ResourceParser.TextAppearanceResources;
import net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener;
import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
import net.micode.notes.ui.PasswordView;
import android.app.Dialog;
import android.view.inputmethod.InputMethodManager;
import net.micode.notes.widget.NoteWidgetProvider_2x;
import net.micode.notes.widget.NoteWidgetProvider_4x;
@ -87,10 +84,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public TextView tvAlertDate;
public ImageView ibSetBgColor;
//方便后边增加一个点击监听器
public ImageView ibSetBgLocker;
}
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
@ -137,7 +130,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private View mFontSizeSelector;
private EditText mNoteEditor;
private View mNoteEditorPanel;
@ -158,8 +150,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private String mUserQuery;
private Pattern mPattern;
//密码
private String mPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -279,11 +269,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
super.onResume();
initNoteScreen();
}
private void initNoteScreen() {
//检验密码
private void checkPassword(){
//读密码
final String mPassword=mWorkingNote.getmPassword();
//密码验证
mPassword = mWorkingNote.getmPassword();
if (mPassword!=null) {
if (mPassword!=null && mPassword.length()!=0) {
//创建dialog插入edittext用户输入密码并做出检验。
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
@ -321,7 +312,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
final Dialog dialog = builder.setView(view).show();
dialog.show();
}
}
private void initNoteScreen() {
//检验密码
//checkPassword();
mNoteEditor.setTextAppearance(this, TextAppearanceResources
.getTexAppearanceResource(mFontSizeId));
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
@ -348,8 +342,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
showAlertHeader();
}
private void showAlertHeader() {
if (mWorkingNote.hasClockAlert()) {
long time = System.currentTimeMillis();
@ -425,10 +417,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
//增加一个监听器
mNoteHeaderHolder.ibSetBgLocker= (ImageView) findViewById(R.id.m_locker);
mNoteHeaderHolder.ibSetBgLocker.setOnClickListener(this);
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
mNoteEditor = (EditText) findViewById(R.id.note_edit_view);
mNoteEditorPanel = findViewById(R.id.sv_note_edit);
@ -437,6 +425,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
ImageView iv = (ImageView) findViewById(id);
iv.setOnClickListener(this);
}
mFontSizeSelector = findViewById(R.id.font_size_selector);
for (int id : sFontSizeBtnsMap.keySet()) {
View view = findViewById(id);
@ -487,10 +476,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
int id = v.getId();
if (id == R.id.btn_set_bg_color) {
mNoteBgColorSelector.setVisibility(View.VISIBLE);
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.VISIBLE);
}
else if (sBgSelectorBtnsMap.containsKey(id)) {
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(View.VISIBLE);
} else if (sBgSelectorBtnsMap.containsKey(id)) {
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.GONE);
mWorkingNote.setBgColorId(sBgSelectorBtnsMap.get(id));
@ -509,44 +496,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
mFontSizeSelector.setVisibility(View.GONE);
}
//添加设置密码的点击
if (id==R.id.m_locker){
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);
etName.setText("");
etName.setHint("请输入密码");
builder.setTitle("为便签设置新密码");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//获取输入的字符串
String password = etName.getText().toString();
//设置密码
mWorkingNote.setPassword(password);
//设置密码成功提示
Toast.makeText(NoteEditActivity.this, "密码设置成功", Toast.LENGTH_SHORT).show();
//关闭软键盘
InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(etName.getWindowToken(),0);
//关闭dialog
dialog.dismiss();
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//关闭软键盘
InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(etName.getWindowToken(),0);
}
});
final Dialog dialog = builder.setView(view).show();
dialog.show();
}
}
@Override
@ -554,6 +503,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if(clearSettingState()) {
return;
}
saveNote();
super.onBackPressed();
}
@ -598,6 +548,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} else {
menu.findItem(R.id.menu_delete_remind).setVisible(false);
}
//如果一设置密码,显示删除密码选项,否则,显示设置密码选项
/**if (mWorkingNote.hasPassword()) {
menu.findItem(R.id.menu_set_passwd).setVisible(false);
} else {
menu.findItem(R.id.menu_delete_passwd).setVisible(false);
}*/
return true;
}
@ -643,11 +599,64 @@ public class NoteEditActivity extends Activity implements OnClickListener,
case R.id.menu_delete_remind:
mWorkingNote.setAlertDate(0, false);
break;
//设置密码
case R.id.menu_set_passwd:
setPassword();
break;
//删除密码
case R.id.menu_delete_passwd:
//删除密码前要检验密码
checkPassword();
deletePassword();
break;
default:
break;
}
return true;
}
//设置密码函数
public void setPassword(){
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);
etName.setText("");
etName.setHint("请输入密码");
builder.setTitle("为便签设置新密码");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//获取输入的字符串
String password = etName.getText().toString();
//设置密码
mWorkingNote.setPassword(password);
//设置密码成功提示
Toast.makeText(NoteEditActivity.this, "密码设置成功", Toast.LENGTH_SHORT).show();
//关闭软键盘
InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(etName.getWindowToken(),0);
//关闭dialog
dialog.dismiss();
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//关闭软键盘
InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(etName.getWindowToken(),0);
}
});
final Dialog dialog = builder.setView(view).show();
dialog.show();
}
//删除密码函数
public void deletePassword()
{
mWorkingNote.setPassword("");
}
private void setReminder() {
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());

@ -19,7 +19,6 @@ 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;
@ -41,7 +40,6 @@ public class NoteItemData {
NoteColumns.TYPE,
NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE,
NoteColumns.PASSWORD,//密码
};
private static final int ID_COLUMN = 0;
@ -56,8 +54,6 @@ 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 PASSWORD_COLUMN=12;
private long mId;
private long mAlertDate;
@ -73,8 +69,6 @@ public class NoteItemData {
private int mWidgetType;
private String mName;
private String mPhoneNumber;
//密码
private String mPassword;
private boolean mIsLastItem;
private boolean mIsFirstItem;
@ -98,10 +92,6 @@ public class NoteItemData {
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
//增加读取密码
mPassword= cursor.getString(PASSWORD_COLUMN);
mPhoneNumber = "";
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId);
@ -118,24 +108,6 @@ public class NoteItemData {
}
checkPostion(cursor);
}
//读取对应小米便签的密码
public String getPassword(){
String password=mPassword;
//System.out(password);
Log.d("getPassword密码是",password);
return password;
}
//判断是否设置了密码
public boolean hasPassword(){
String password=mPassword;
//System.out(password);
Log.d("hasPassword密码是",password);
Object o = "";
if (password.equals(o)){
return false;
}
return true;
}
private void checkPostion(Cursor cursor) {
mIsLastItem = cursor.isLast() ? true : false;

@ -875,7 +875,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
Intent intent = new Intent(from, NotesPreferenceActivity.class);
from.startActivityIfNeeded(intent, -1);
}
//修改为继承Activity便于包含Context。Builder函数的参数要求是Context。extends Activity
private class OnListItemClickListener implements OnItemClickListener {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@ -895,10 +895,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
if (item.getType() == Notes.TYPE_FOLDER
|| item.getType() == Notes.TYPE_SYSTEM) {
openFolder(item);
}
//判断为点击的是便签
else if (item.getType() == Notes.TYPE_NOTE) {
openNode(item);
} else if (item.getType() == Notes.TYPE_NOTE) {
//打开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 NOTE_LIST");
}

@ -0,0 +1,93 @@
package net.micode.notes.ui;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.os.Bundle;
import android.widget.Toast;
import net.micode.notes.R;
import net.micode.notes.model.WorkingNote;
//这是一个检验密码的Activity之后会添加其他。
public class PassWordEditActivity extends Activity {
//用来输入密码和一个按钮
EditText passWord;
Button set_password;
//储存要验证的便签的密码
String mPassword;
//要验证的便签
WorkingNote mWorkingNote=null;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
intent = getIntent();
if (savedInstanceState == null && !initActivityState()) {
finish();
return;
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_password);
//不知道作用
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//
boolean User_boolean = mWorkingNote.hasPassword();//获取用户是否设置了密码
if(!User_boolean) //User_boolean = false时没有设置密码直接跳转到便签主界面
{
Intent intent=new Intent(PassWordEditActivity.this,NoteEditActivity.class);
intent.setAction("android.intent.action.VIEW");
intent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId());
startActivity(intent);
PassWordEditActivity.this.finish();
}
passWord=(EditText) findViewById(R.id.password);
set_password=(Button)findViewById(R.id.set_password);
set_password.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//获取输入密码
String password=passWord.getText().toString();
if(password.equals(mPassword)){
Intent intent=new Intent(PassWordEditActivity.this,NoteEditActivity.class);
intent.setAction("android.intent.action.VIEW");
intent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId());
startActivity(intent);
finish();
}
else{
Toast.makeText(PassWordEditActivity.this, "密码错误", Toast.LENGTH_SHORT).show();
passWord.setText("");//把密码框内输入过的错误密码清空
}
}
}
);
}
private boolean initActivityState() {
mWorkingNote = null;
long noteId = intent.getLongExtra("noteId",-1);
if (noteId!=-1) {
//得到要验证的便签
mWorkingNote = WorkingNote.load(PassWordEditActivity.this, noteId);
//获取该便签密码
mPassword=mWorkingNote.getmPassword();
return true;
}
return false;
}
}
Loading…
Cancel
Save