增加了密码保护功能。解决了新增功能与回收站功能的冲突

pull/14/head
AetherPendragon 2 months ago
parent ed8cce084f
commit 851e087711

@ -127,6 +127,12 @@
android:theme="@style/NoteTheme"
android:exported="true" >
</activity>
<activity
android:name=".ui.PasswordInputActivity"
android:label="@string/password_input_title"
android:theme="@style/NoteTheme"
android:exported="false" >
</activity>
<service
android:name="net.micode.notes.gtask.remote.GTaskSyncService"
android:exported="false" >

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/password_input_title"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginBottom="24dp" />
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password_hint"
android:inputType="textPassword"
android:layout_marginBottom="16dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="end">
<Button
android:id="@+id/btn_return"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/return_button"
android:layout_marginEnd="8dp" />
<Button
android:id="@+id/btn_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/confirm_button" />
</LinearLayout>
</LinearLayout>

@ -75,4 +75,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"/>
<ImageView
android:id="@+id/iv_encrypted_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:layout_marginEnd="24dp"
android:visibility="gone"/>
</FrameLayout>

@ -44,10 +44,10 @@
<string name="menu_search">搜索</string>
<string name="menu_trash">回收站</string>
<string name="button_return">返回</string>
<string name="menu_delete">删除</string>
<string name="button_clean_all">清空</string>
<string name="button_recovery">恢复</string>
<string name="menu_success">成功</string>
<string name="menu_delete">删除</string>
<string name="menu_move">移动到文件夹</string>
<string name="menu_select_title">选中了 %d 项</string>
<string name="menu_select_none">没有选中项,操作无效</string>
@ -125,6 +125,17 @@
<string name="search">便签</string>
<string name="datetime_dialog_ok">设置</string>
<string name="datetime_dialog_cancel">取消</string>
<!-- Password protection -->
<string name="password_input_title">请输入密码</string>
<string name="password_hint">密码</string>
<string name="return_button">返回</string>
<string name="confirm_button">确认</string>
<string name="encrypt_note_dialog_title">加密便签</string>
<string name="encrypt_note_dialog_message">是否将此便签设置为加密便签?</string>
<string name="password_set_dialog_title">设置密码</string>
<string name="password_set_dialog_message">请输入密码</string>
<string name="password_error">密码错误,请重试</string>
<string name="password_empty">密码不能为空</string>
<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>

@ -46,13 +46,13 @@
<string name="menu_sync_cancel">Cancel syncing</string>
<string name="menu_setting">Settings</string>
<string name="menu_search">Search</string>
<string name="menu_delete">Delete</string>
<string name="menu_move">Move to folder</string>
<string name="menu_trash">Trash</string>
<string name="button_return">Return</string>
<string name="button_clean_all">Clean All</string>
<string name="button_recovery">Recovery</string>
<string name="menu_success">Success</string>
<string name="menu_delete">Delete</string>
<string name="menu_move">Move to folder</string>
<string name="menu_select_title">%d selected</string>
<string name="menu_select_none">Nothing selected, the operation is invalid</string>
<string name="menu_select_all">Select all</string>
@ -132,6 +132,17 @@
<string name="search">Notes</string>
<string name="datetime_dialog_ok">set</string>
<string name="datetime_dialog_cancel">cancel</string>
<!-- Password protection -->
<string name="password_input_title">Enter your password please</string>
<string name="password_hint">password</string>
<string name="return_button">Return</string>
<string name="confirm_button">Confirm</string>
<string name="encrypt_note_dialog_title">Encrypted note</string>
<string name="encrypt_note_dialog_message">Would you like to set the note as an encrypted note?</string>
<string name="password_set_dialog_title">Set password</string>
<string name="password_set_dialog_message">Enter password please</string>
<string name="password_error">Error, try again</string>
<string name="password_empty">The password can not be empty</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>
<!-- Case of 0 or 2 or more results. -->

@ -59,10 +59,14 @@
</style>
<style name="NoteTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/NoteActionBarStyle</item>
<item name="android:actionBarStyle">@android:style/Widget.Holo.Light.ActionBar</item>
<item name="android:displayOptions">showHome|showTitle|useLogo</item>
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">false</item>
</style>
<style name="NoteActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:visibility">visible</item>
<item name="android:displayOptions" />
<item name="android:visibility">gone</item>
</style>
</resources>

@ -170,6 +170,12 @@ public class Notes {
* <P> Type : INTEGER (long) </P>
*/
public static final String VERSION = "version";
/**
* Whether the note is encrypted
* <P> Type : INTEGER (0 = not encrypted, 1 = encrypted) </P>
*/
public static final String IS_ENCRYPTED = "is_encrypted";
}
public interface TrashColumns extends NoteColumns {

@ -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 = 5;
private static final int DB_VERSION = 6;
public interface TABLE {
public static final String NOTE = "note";
@ -38,6 +38,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
public static final String DATA = "data";
public static final String TRASH = "trash_note";
public static final String ENCRYPTED_NOTE_PASSWORD = "encrypted_note_password";
}
private static final String TAG = "NotesDatabaseHelper";
@ -62,7 +64,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.IS_ENCRYPTED + " INTEGER NOT NULL DEFAULT 0" +
")";
private static final String CREATE_DATA_TABLE_SQL =
@ -103,9 +106,17 @@ 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.IS_ENCRYPTED + " INTEGER NOT NULL DEFAULT 0," +
"deleted_date INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)" +
")";
private static final String CREATE_ENCRYPTED_NOTE_PASSWORD_TABLE_SQL =
"CREATE TABLE " + TABLE.ENCRYPTED_NOTE_PASSWORD + "(" +
NoteColumns.ID + " INTEGER PRIMARY KEY," +
"password TEXT NOT NULL," +
"FOREIGN KEY(" + NoteColumns.ID + ") REFERENCES " + TABLE.NOTE + "(" + NoteColumns.ID + ") ON DELETE CASCADE" +
")";
/**
* Increase folder's note count when move note to the folder
*/
@ -316,7 +327,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER);
}
static synchronized NotesDatabaseHelper getInstance(Context context) {
public static synchronized NotesDatabaseHelper getInstance(Context context) {
if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context);
}
@ -328,6 +339,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
createNoteTable(db);
createDataTable(db);
createTrashTable(db);
createEncryptedNotePasswordTable(db);
}
@Override
@ -357,6 +369,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
oldVersion++;
}
if (oldVersion == 5) {
upgradeToV6(db);
oldVersion++;
}
if (reCreateTriggers) {
reCreateNoteTableTriggers(db);
reCreateDataTableTriggers(db);
@ -399,4 +416,26 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
createTrashTable(db);
Log.d(TAG, "Upgraded to version 5: created trash_note table");
}
private void upgradeToV6(SQLiteDatabase db) {
// 添加is_encrypted字段到note表
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.IS_ENCRYPTED
+ " INTEGER NOT NULL DEFAULT 0");
// 添加is_encrypted字段到trash_note表如果表已存在
try {
db.execSQL("ALTER TABLE " + TABLE.TRASH + " ADD COLUMN " + NoteColumns.IS_ENCRYPTED
+ " INTEGER NOT NULL DEFAULT 0");
} catch (Exception e) {
// 如果表不存在或字段已存在,忽略错误
Log.d(TAG, "trash_note table may not exist or column already exists: " + e.getMessage());
}
// 创建加密便签密码表
createEncryptedNotePasswordTable(db);
Log.d(TAG, "Upgraded to version 6: added is_encrypted column and encrypted_note_password table");
}
public void createEncryptedNotePasswordTable(SQLiteDatabase db) {
db.execSQL(CREATE_ENCRYPTED_NOTE_PASSWORD_TABLE_SQL);
Log.d(TAG, "encrypted_note_password table has been created");
}
}

@ -56,6 +56,7 @@ public class WorkingNote {
private static final String TAG = "WorkingNote"; // 日志标签
private boolean mIsDeleted; // 是否已删除
private NoteSettingChangedListener mNoteSettingStatusListener; // 笔记设置变化监听器
private String mPassword; // 密码(仅在创建时使用)
@ -234,6 +235,12 @@ public class WorkingNote {
mNote.syncNote(mContext, mNoteId);
// 如果设置了密码,保存密码
if (mPassword != null && !mPassword.isEmpty()) {
net.micode.notes.tool.PasswordUtils.savePassword(mContext, mNoteId, mPassword);
mPassword = null; // 清除密码,避免重复保存
}
// 如果该笔记存在小部件,更新小部件内容
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE
@ -257,15 +264,26 @@ public class WorkingNote {
/**
*
*
* 使
* @return truefalse
*/
private boolean isWorthSaving() {
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) {
if (mIsDeleted) {
return false;
} else {
}
// 如果设置了密码,说明用户想要创建加密便签,即使内容为空也应该保存
if (mPassword != null && !mPassword.isEmpty()) {
return true;
}
// 如果便签不存在于数据库中且内容为空,且没有本地修改,不值得保存
if (!existInDatabase() && TextUtils.isEmpty(mContent) && !mNote.isLocalModified()) {
return false;
}
// 如果便签存在于数据库中但未被修改,不值得保存
if (existInDatabase() && !mNote.isLocalModified()) {
return false;
}
return true;
}
/**
@ -471,6 +489,38 @@ public class WorkingNote {
return mWidgetType;
}
/**
* 便
* @param encrypted
*/
public void setEncrypted(boolean encrypted) {
mNote.setNoteValue(NoteColumns.IS_ENCRYPTED, encrypted ? "1" : "0");
}
/**
* 使
* @param password
*/
public void setPassword(String password) {
mPassword = password;
}
/**
* 便
* @return
*/
public boolean isEncrypted() {
Cursor cursor = mContext.getContentResolver().query(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId),
new String[]{NoteColumns.IS_ENCRYPTED}, null, null, null);
boolean encrypted = false;
if (cursor != null && cursor.moveToFirst()) {
encrypted = cursor.getInt(0) == 1;
cursor.close();
}
return encrypted;
}
/**
*
*

@ -0,0 +1,145 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.tool;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper;
/**
*
* 便
*/
public class PasswordUtils {
private static final String TAG = "PasswordUtils";
/**
* 便
* @param context
* @param noteId 便ID
* @param password
* @return
*/
public static boolean savePassword(Context context, long noteId, String password) {
if (noteId <= 0 || password == null || password.isEmpty()) {
Log.e(TAG, "Invalid noteId or password");
return false;
}
SQLiteDatabase db = NotesDatabaseHelper.getInstance(context).getWritableDatabase();
ContentValues values = new ContentValues();
values.put(NoteColumns.ID, noteId);
values.put("password", password);
// 先删除旧密码(如果存在)
db.delete(NotesDatabaseHelper.TABLE.ENCRYPTED_NOTE_PASSWORD,
NoteColumns.ID + "=?", new String[]{String.valueOf(noteId)});
// 插入新密码
long result = db.insert(NotesDatabaseHelper.TABLE.ENCRYPTED_NOTE_PASSWORD, null, values);
return result != -1;
}
/**
* 便
* @param context
* @param noteId 便ID
* @return null
*/
public static String getPassword(Context context, long noteId) {
if (noteId <= 0) {
return null;
}
SQLiteDatabase db = NotesDatabaseHelper.getInstance(context).getReadableDatabase();
Cursor cursor = db.query(NotesDatabaseHelper.TABLE.ENCRYPTED_NOTE_PASSWORD,
new String[]{"password"},
NoteColumns.ID + "=?",
new String[]{String.valueOf(noteId)},
null, null, null);
String password = null;
if (cursor != null && cursor.moveToFirst()) {
password = cursor.getString(0);
cursor.close();
}
return password;
}
/**
*
* @param context
* @param noteId 便ID
* @param inputPassword
* @return
*/
public static boolean verifyPassword(Context context, long noteId, String inputPassword) {
String savedPassword = getPassword(context, noteId);
if (savedPassword == null) {
return false;
}
return savedPassword.equals(inputPassword);
}
/**
* 便
* @param context
* @param noteId 便ID
* @return
*/
public static boolean deletePassword(Context context, long noteId) {
if (noteId <= 0) {
return false;
}
SQLiteDatabase db = NotesDatabaseHelper.getInstance(context).getWritableDatabase();
int result = db.delete(NotesDatabaseHelper.TABLE.ENCRYPTED_NOTE_PASSWORD,
NoteColumns.ID + "=?",
new String[]{String.valueOf(noteId)});
return result > 0;
}
/**
* 便
* @param context
* @param noteId 便ID
* @return
*/
public static boolean isNoteEncrypted(Context context, long noteId) {
if (noteId <= 0) {
return false;
}
Cursor cursor = context.getContentResolver().query(
android.content.ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
new String[]{NoteColumns.IS_ENCRYPTED},
null, null, null);
boolean isEncrypted = false;
if (cursor != null && cursor.moveToFirst()) {
isEncrypted = cursor.getInt(0) == 1;
cursor.close();
}
return isEncrypted;
}
}

@ -273,6 +273,17 @@ public class NoteEditActivity extends Activity implements OnClickListener,
bgResId);
}
// 处理加密便签
boolean isEncrypted = intent.getBooleanExtra("is_encrypted", false);
if (isEncrypted) {
String password = intent.getStringExtra("password");
if (password != null && !password.isEmpty()) {
mWorkingNote.setEncrypted(true);
// 保存密码(需要在便签保存后)
mWorkingNote.setPassword(password);
}
}
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

@ -48,6 +48,7 @@ public class NoteItemData {
NoteColumns.TYPE, // 笔记类型
NoteColumns.WIDGET_ID, // 小部件ID
NoteColumns.WIDGET_TYPE, // 小部件类型
NoteColumns.IS_ENCRYPTED, // 是否加密
};
/** 笔记ID列索引 */
@ -74,6 +75,8 @@ public class NoteItemData {
private static final int WIDGET_ID_COLUMN = 10;
/** 小部件类型列索引 */
private static final int WIDGET_TYPE_COLUMN = 11;
/** 是否加密列索引 */
private static final int IS_ENCRYPTED_COLUMN = 12;
/** 笔记ID */
private long mId;
@ -99,6 +102,8 @@ public class NoteItemData {
private int mWidgetId;
/** 小部件类型 */
private int mWidgetType;
/** 是否加密 */
private boolean mIsEncrypted;
/** 联系人姓名(用于通话记录) */
private String mName;
/** 电话号码(用于通话记录) */
@ -136,6 +141,7 @@ public class NoteItemData {
mType = cursor.getInt(TYPE_COLUMN);
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
mIsEncrypted = cursor.getInt(IS_ENCRYPTED_COLUMN) == 1;
mPhoneNumber = "";
// 如果是通话记录文件夹中的笔记,获取电话号码和联系人姓名
@ -364,4 +370,12 @@ public class NoteItemData {
public static int getNoteType(Cursor cursor) {
return cursor.getInt(TYPE_COLUMN);
}
/**
*
* @return truefalse
*/
public boolean isEncrypted() {
return mIsEncrypted;
}
}

@ -463,12 +463,81 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
private void createNewNote() {
// 弹出对话框询问是否加密
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.encrypt_note_dialog_title);
builder.setMessage(R.string.encrypt_note_dialog_message);
builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 用户选择加密,弹出密码输入对话框
showPasswordInputDialog();
}
});
builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 用户选择不加密,直接创建便签
createNoteWithoutEncryption();
}
});
builder.show();
}
private void showPasswordInputDialog() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
final EditText etPassword = (EditText) view.findViewById(R.id.et_foler_name);
etPassword.setHint(R.string.password_hint);
etPassword.setInputType(android.text.InputType.TYPE_CLASS_TEXT |
android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
builder.setTitle(R.string.password_set_dialog_title);
builder.setView(view);
builder.setPositiveButton(android.R.string.ok, null);
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 取消,直接创建不加密的便签
createNoteWithoutEncryption();
}
});
final Dialog dialog = builder.create();
dialog.show();
final Button positive = (Button) dialog.findViewById(android.R.id.button1);
positive.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String password = etPassword.getText().toString();
if (TextUtils.isEmpty(password)) {
Toast.makeText(NotesListActivity.this,
R.string.password_empty, Toast.LENGTH_SHORT).show();
return;
}
dialog.dismiss();
// 创建加密便签
createNoteWithEncryption(password);
}
});
}
private void createNoteWithoutEncryption() {
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 createNoteWithEncryption(String password) {
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mCurrentFolderId);
intent.putExtra("is_encrypted", true);
intent.putExtra("password", password);
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
}
private void batchDelete() {
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
@ -534,10 +603,21 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
private void openNode(NoteItemData data) {
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_UID, data.getId());
this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
// 检查是否为加密便签
// 使用PasswordUtils检查因为数据库中的值可能更准确
boolean isEncrypted = net.micode.notes.tool.PasswordUtils.isNoteEncrypted(this, data.getId());
if (isEncrypted) {
// 跳转到密码输入界面
Intent intent = new Intent(this, PasswordInputActivity.class);
intent.putExtra(PasswordInputActivity.EXTRA_NOTE_ID, data.getId());
startActivity(intent);
} else {
// 普通便签,直接打开
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_UID, data.getId());
this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
}
}
private void openFolder(NoteItemData data) {

@ -40,6 +40,8 @@ import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
public class NotesListItem extends LinearLayout {
/** 提醒图标 */
private ImageView mAlert;
/** 加密图标 */
private ImageView mEncryptedIcon;
/** 笔记标题文本视图 */
private TextView mTitle;
/** 时间文本视图 */
@ -61,6 +63,7 @@ public class NotesListItem extends LinearLayout {
inflate(context, R.layout.note_item, this);
// 获取视图组件
mAlert = (ImageView) findViewById(R.id.iv_alert_icon);
mEncryptedIcon = (ImageView) findViewById(R.id.iv_encrypted_icon);
mTitle = (TextView) findViewById(R.id.tv_title);
mTime = (TextView) findViewById(R.id.tv_time);
mCallName = (TextView) findViewById(R.id.tv_name);
@ -133,6 +136,14 @@ public class NotesListItem extends LinearLayout {
// 设置修改时间
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
// 显示加密图标
if (data.isEncrypted()) {
mEncryptedIcon.setVisibility(View.VISIBLE);
mEncryptedIcon.setImageResource(android.R.drawable.ic_lock_lock);
} else {
mEncryptedIcon.setVisibility(View.GONE);
}
// 设置背景
setBackground(data);
}

@ -0,0 +1,101 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.ui;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import net.micode.notes.R;
import net.micode.notes.tool.PasswordUtils;
/**
* Activity
* 便
*/
public class PasswordInputActivity extends Activity {
private static final String TAG = "PasswordInputActivity";
public static final String EXTRA_NOTE_ID = "note_id";
private EditText mPasswordEditText;
private Button mReturnButton;
private Button mConfirmButton;
private long mNoteId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_password_input);
mNoteId = getIntent().getLongExtra(EXTRA_NOTE_ID, 0);
if (mNoteId <= 0) {
Toast.makeText(this, R.string.error_note_not_exist, Toast.LENGTH_SHORT).show();
finish();
return;
}
initViews();
}
private void initViews() {
mPasswordEditText = (EditText) findViewById(R.id.et_password);
mReturnButton = (Button) findViewById(R.id.btn_return);
mConfirmButton = (Button) findViewById(R.id.btn_confirm);
mReturnButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 返回主界面
finish();
}
});
mConfirmButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String password = mPasswordEditText.getText().toString();
if (TextUtils.isEmpty(password)) {
Toast.makeText(PasswordInputActivity.this,
R.string.password_empty, Toast.LENGTH_SHORT).show();
return;
}
// 验证密码
if (PasswordUtils.verifyPassword(PasswordInputActivity.this, mNoteId, password)) {
// 密码正确,跳转到便签编辑界面
Intent intent = new Intent(PasswordInputActivity.this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_UID, mNoteId);
startActivity(intent);
finish();
} else {
// 密码错误
Toast.makeText(PasswordInputActivity.this,
R.string.password_error, Toast.LENGTH_SHORT).show();
mPasswordEditText.setText("");
}
}
});
}
}
Loading…
Cancel
Save