|
|
|
|
@ -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) {
|
|
|
|
|
/**
|
|
|
|
|
|