增加了便签字数实时统计和便签标题编辑功能 #11

Merged
pr9ixgmc2 merged 1 commits from cuijiaxiang_branch into master 1 month ago

@ -247,6 +247,18 @@ public class Notes {
* <P> : TEXT </P>
*/
public static final String NUMERIC_PASSWORD = "numeric_password";
/**
* 便
* <P> : TEXT </P>
*/
public static final String TITLE = "title";
/**
*
* <P> : INTEGER </P>
*/
public static final int TITLE_MAX_LENGTH = 50;
}
/**

@ -36,7 +36,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "note.db";
// 数据库版本号
private static final int DB_VERSION = 7;
private static final int DB_VERSION = 8;
// 数据库表名定义
public interface TABLE {
@ -432,6 +432,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
oldVersion++;
}
if (oldVersion == 7) {
upgradeToV8(db);
oldVersion++;
}
if (reCreateTriggers) {
reCreateNoteTableTriggers(db);
reCreateDataTableTriggers(db);
@ -530,4 +535,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.NUMERIC_PASSWORD
+ " TEXT NOT NULL DEFAULT ''");
}
/**
* v7v8
* 便
* @param db SQLite
*/
private void upgradeToV8(SQLiteDatabase db) {
// 为笔记表添加标题字段
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.TITLE
+ " TEXT NOT NULL DEFAULT ''");
}
}

@ -128,6 +128,11 @@ public class WorkingNote {
*/
private String mNumericPassword;
/**
* 便
*/
private String mTitle;
/**
* 便
*/
@ -154,7 +159,8 @@ public class WorkingNote {
NoteColumns.IS_LOCKED, // 锁定状态
NoteColumns.LOCK_PASSWORD, // 锁定密码
NoteColumns.PASSWORD_TYPE, // 密码类型
NoteColumns.NUMERIC_PASSWORD // 数字密码
NoteColumns.NUMERIC_PASSWORD, // 数字密码
NoteColumns.TITLE // 标题
};
/**
@ -164,7 +170,6 @@ public class WorkingNote {
private static final int DATA_CONTENT_COLUMN = 1; // 数据内容列索引
private static final int DATA_MIME_TYPE_COLUMN = 2; // 数据类型列索引
private static final int DATA_MODE_COLUMN = 3; // 数据模式列索引
/**
* 便
*/
@ -178,6 +183,7 @@ public class WorkingNote {
private static final int NOTE_LOCK_PASSWORD_COLUMN = 7; // 锁定密码列索引
private static final int NOTE_PASSWORD_TYPE_COLUMN = 8; // 密码类型列索引
private static final int NOTE_NUMERIC_PASSWORD_COLUMN = 9; // 数字密码列索引
private static final int NOTE_TITLE_COLUMN = 10; // 标题列索引
/**
* 便
@ -234,6 +240,7 @@ public class WorkingNote {
mLockPassword = cursor.getString(NOTE_LOCK_PASSWORD_COLUMN);
mPasswordType = cursor.getString(NOTE_PASSWORD_TYPE_COLUMN);
mNumericPassword = cursor.getString(NOTE_NUMERIC_PASSWORD_COLUMN);
mTitle = cursor.getString(NOTE_TITLE_COLUMN);
}
cursor.close();
} else {
@ -645,6 +652,25 @@ public class WorkingNote {
return mNumericPassword;
}
/**
*
* @param title
*/
public void setTitle(String title) {
if (!TextUtils.equals(mTitle, title)) {
mTitle = title;
mNote.setNoteValue(NoteColumns.TITLE, title);
}
}
/**
*
* @return
*/
public String getTitle() {
return mTitle;
}
/**
* 便
* 便

@ -147,6 +147,32 @@ public class ResourceParser {
public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id];
}
/**
* 便
* <p>
* IDID
* </p>
*
* @param id ID
* @return ID
*/
public static int getNoteTextColor(int id) {
switch (id) {
case ResourceParser.YELLOW:
return R.color.note_text_yellow;
case ResourceParser.BLUE:
return R.color.note_text_blue;
case ResourceParser.WHITE:
return R.color.note_text_white;
case ResourceParser.GREEN:
return R.color.note_text_green;
case ResourceParser.RED:
return R.color.note_text_red;
default:
return R.color.note_text_white;
}
}
}
/**

@ -32,6 +32,8 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextWatcher;
import android.text.Editable;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.style.BackgroundColorSpan;
@ -96,6 +98,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public ImageView ivAlertIcon; // 提醒图标
public TextView tvAlertDate; // 提醒日期显示
public ImageView ibSetBgColor; // 设置背景色按钮
public TextView tvTitleHint; // 标题提示文字
public EditText etTitle; // 标题输入框
public TextView tvTitleCount; // 字符数提示
public View titleArea; // 标题区域
public TextView tvWordCountLabel; // 字数统计标签
public TextView tvWordCount; // 字数统计数字
}
/**
@ -335,6 +343,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mNoteEditor.setTextAppearance(this, TextAppearanceResources
.getTexAppearanceResource(mFontSizeId));
// 加载标题内容
String title = mWorkingNote.getTitle();
if (title != null && !title.isEmpty()) {
mNoteHeaderHolder.etTitle.setText(title);
mNoteHeaderHolder.tvTitleCount.setText(title.length() + "/" + Notes.NoteColumns.TITLE_MAX_LENGTH);
} else {
mNoteHeaderHolder.etTitle.setText("");
mNoteHeaderHolder.tvTitleCount.setText("0/" + Notes.NoteColumns.TITLE_MAX_LENGTH);
}
// 根据便签模式显示内容
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
// 切换到列表模式
@ -354,6 +372,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
// 设置头部和编辑器背景
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
mNoteHeaderHolder.titleArea.setBackgroundResource(mWorkingNote.getTitleBgResId());
int textColor = ResourceParser.NoteBgResources.getNoteTextColor(mWorkingNote.getBgColorId());
mNoteHeaderHolder.tvWordCountLabel.setTextColor(getResources().getColor(textColor));
mNoteHeaderHolder.tvWordCount.setTextColor(getResources().getColor(textColor));
// 设置修改时间
mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(this,
@ -363,6 +386,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
// 显示提醒头部
showAlertHeader();
// 更新字数统计
updateWordCount();
}
/**
@ -495,6 +521,34 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
mNoteHeaderHolder.tvTitleHint = (TextView) findViewById(R.id.tv_title_hint);
mNoteHeaderHolder.etTitle = (EditText) findViewById(R.id.et_title);
mNoteHeaderHolder.etTitle.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String title = s.toString();
int length = title.length();
if (length > Notes.NoteColumns.TITLE_MAX_LENGTH) {
mNoteHeaderHolder.tvTitleCount.setText(length + "/" + Notes.NoteColumns.TITLE_MAX_LENGTH);
mNoteHeaderHolder.tvTitleCount.setTextColor(getResources().getColor(R.color.warning_text));
} else {
mNoteHeaderHolder.tvTitleCount.setText(length + "/" + Notes.NoteColumns.TITLE_MAX_LENGTH);
mNoteHeaderHolder.tvTitleCount.setTextColor(getResources().getColor(R.color.secondary_text_dark));
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
mNoteHeaderHolder.tvTitleCount = (TextView) findViewById(R.id.tv_title_count);
mNoteHeaderHolder.titleArea = findViewById(R.id.note_title_area);
mNoteHeaderHolder.tvWordCountLabel = (TextView) findViewById(R.id.tv_word_count_label);
mNoteHeaderHolder.tvWordCount = (TextView) findViewById(R.id.tv_word_count);
// 初始化编辑器
mNoteEditor = (EditText) findViewById(R.id.note_edit_view);
@ -525,6 +579,22 @@ public class NoteEditActivity extends Activity implements OnClickListener,
// 初始化编辑列表
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
// 添加编辑器文本监听器,实现实时字数更新
mNoteEditor.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
updateWordCount();
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
/**
@ -648,6 +718,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
View.VISIBLE);
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
mNoteHeaderHolder.titleArea.setBackgroundResource(mWorkingNote.getTitleBgResId());
int textColor = ResourceParser.NoteBgResources.getNoteTextColor(mWorkingNote.getBgColorId());
mNoteHeaderHolder.tvWordCountLabel.setTextColor(getResources().getColor(textColor));
mNoteHeaderHolder.tvWordCount.setTextColor(getResources().getColor(textColor));
}
/**
@ -1088,11 +1163,42 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} else {
mWorkingNote.setWorkingText(mNoteEditor.getText().toString());
}
updateWordCount();
return hasChecked;
}
private void updateWordCount() {
String content = "";
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
View view = mEditTextList.getChildAt(i);
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
if (!TextUtils.isEmpty(edit.getText())) {
sb.append(edit.getText()).append("\n");
}
}
content = sb.toString();
} else {
content = mNoteEditor.getText().toString();
}
int wordCount = content != null ? content.length() : 0;
mNoteHeaderHolder.tvWordCount.setText(String.valueOf(wordCount));
if (wordCount > 5000) {
mNoteHeaderHolder.tvWordCount.setTextColor(getResources().getColor(R.color.warning_text));
} else if (wordCount > 1000) {
mNoteHeaderHolder.tvWordCount.setTextColor(getResources().getColor(R.color.alert_text));
} else {
mNoteHeaderHolder.tvWordCount.setTextColor(getResources().getColor(R.color.secondary_text_dark));
}
}
private boolean saveNote() {
getWorkingText();
String title = mNoteHeaderHolder.etTitle.getText().toString();
mWorkingNote.setTitle(title);
boolean saved = mWorkingNote.saveNote();
if (saved) {
/**

@ -49,6 +49,7 @@ public class NoteItemData {
NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE,
NoteColumns.IS_LOCKED,
NoteColumns.TITLE,
};
/**
@ -111,6 +112,10 @@ public class NoteItemData {
*
*/
private static final int IS_LOCKED_COLUMN = 14;
/**
*
*/
private static final int TITLE_COLUMN = 15;
/**
* ID
@ -172,6 +177,10 @@ public class NoteItemData {
*
*/
private boolean mIsLocked;
/**
*
*/
private String mTitle;
/**
*
*/
@ -226,6 +235,7 @@ public class NoteItemData {
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
mIsLocked = (cursor.getInt(IS_LOCKED_COLUMN) > 0);
mTitle = cursor.getString(TITLE_COLUMN);
mPhoneNumber = "";
// 如果是通话记录文件夹,获取电话号码和联系人姓名
@ -447,6 +457,14 @@ public class NoteItemData {
return mSnippet;
}
/**
*
* @return
*/
public String getTitle() {
return mTitle;
}
/**
*
* @return

@ -137,7 +137,19 @@ public class NotesListItem extends LinearLayout {
mAlert.setVisibility(View.GONE);
} else {
// 普通笔记
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
String title = data.getTitle();
if (title != null && !title.isEmpty()) {
// 如果有标题,显示标题
mTitle.setText(title);
} else {
// 如果没有标题显示正文前20个字符
String snippet = data.getSnippet();
if (snippet != null && snippet.length() > 20) {
mTitle.setText(snippet.substring(0, 20) + "...");
} else {
mTitle.setText(snippet);
}
}
// 设置提醒图标
if (data.hasAlert()) {
mAlert.setImageResource(R.drawable.clock);

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#E0FFFFFF" />
<corners android:radius="4dp" />
</shape>

@ -65,6 +65,53 @@
android:background="@drawable/bg_btn_set_color" />
</LinearLayout>
<LinearLayout
android:id="@+id/note_title_area"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="@android:color/transparent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dp">
<TextView
android:id="@+id/tv_title_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/note_title_hint"
android:textSize="12sp"
android:textColor="#999999"
android:layout_marginRight="8dp" />
<EditText
android:id="@+id/et_title"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/note_title_placeholder"
android:maxLength="50"
android:textSize="18sp"
android:textColor="#333333"
android:background="@null"
android:padding="8dp"
android:singleLine="true" />
<TextView
android:id="@+id/tv_title_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0/50"
android:textSize="12sp"
android:textColor="#999999"
android:layout_marginLeft="8dp" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#E0E0E0" />
</LinearLayout>
<LinearLayout
android:id="@+id/sv_note_edit"
android:layout_width="fill_parent"
@ -399,4 +446,34 @@
android:src="@drawable/selected" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/word_count_area"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="8dp"
android:background="@drawable/bg_word_count_panel">
<TextView
android:id="@+id/tv_word_count_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/word_count_label"
android:textSize="20sp"
android:layout_marginRight="8dp"
android:gravity="center_vertical" />
<TextView
android:id="@+id/tv_word_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="20sp"
android:gravity="center_vertical" />
</LinearLayout>
</FrameLayout>

@ -17,4 +17,13 @@
<resources>
<color name="user_query_highlight">#335b5b5b</color>
<color name="warning_text">#FF5252</color>
<color name="alert_text">#FF9800</color>
<!-- Note text colors for different backgrounds -->
<color name="note_text_yellow">#5D4037</color>
<color name="note_text_blue">#0D47A1</color>
<color name="note_text_white">#424242</color>
<color name="note_text_green">#2E7D32</color>
<color name="note_text_red">#C62828</color>
</resources>

@ -199,4 +199,19 @@
<string name="toast_empty_trash_success">Trash emptied</string>
<string name="toast_empty_trash_failed">Failed to empty trash</string>
<!-- Note title strings -->
<string name="note_title_hint">Title</string>
<string name="note_title_placeholder">Please enter title</string>
<string name="note_title_max_length">Title max 50 characters</string>
<string name="note_title_warning">Title has reached maximum length</string>
<string name="menu_bold">Bold</string>
<string name="menu_italic">Italic</string>
<string name="menu_normal">Normal</string>
<!-- Word count strings -->
<string name="word_count_label">Word count: </string>
<string name="word_count_normal">Word count normal</string>
<string name="word_count_warning">Word count large</string>
<string name="word_count_large">Word count too large</string>
</resources>

Loading…
Cancel
Save