diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java
index 96a9ff8..9bd74f2 100644
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java
+++ b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java
@@ -30,9 +30,11 @@ import android.content.SharedPreferences;
import android.graphics.Paint;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.text.Editable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
+import android.text.TextWatcher;
import android.text.format.DateUtils;
import android.text.style.BackgroundColorSpan;
import android.util.Log;
@@ -130,6 +132,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private EditText mNoteEditor;
+ //字数统计
+ private TextView textView;
+
private View mNoteEditorPanel;
private WorkingNote mWorkingNote;
@@ -159,8 +164,59 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return;
}
initResources();
+ count();
+ }
+ private String Textchange(String oriText){
+ StringBuffer stringBuffer = new StringBuffer(oriText);
+ int Flag1 = -1;
+ int Flag2 = -1;
+ do {//不计入表示图片的字符
+ Flag1 = stringBuffer.indexOf("
");
+ if (Flag1 != -1 && Flag2 != -1) {
+ stringBuffer = stringBuffer.replace(Flag1, Flag2+1, "");
+ }
+ } while (Flag1 != -1 && Flag2 != -1);
+
+ do {//不计入换行字符
+ Flag1 = stringBuffer.indexOf("\n");
+
+ if (Flag1 != -1){
+ stringBuffer = stringBuffer.replace(Flag1, Flag1+1, "");
+ }
+ } while (Flag1 != -1);
+ do {//不计入空格字符
+ Flag1 = stringBuffer.indexOf(" ");
+
+ if (Flag1 != -1) {
+ stringBuffer = stringBuffer.replace(Flag1, Flag1+1, "");
+ }
+ } while (Flag1 != -1);
+ return stringBuffer.toString();
}
+ private void count() {
+ textView = (TextView) findViewById(R.id.text_num);
+ mNoteEditor.addTextChangedListener(new TextWatcher() {
+ int currentLength = 0;
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+ textView.setText(String.format(getString(R.string.word_num), currentLength));
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ currentLength = Textchange(mNoteEditor.getText().toString()).length();
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ textView.setText(String.format(getString(R.string.word_num), currentLength));
+ }
+ });
+ }
/**
* Current activity may be killed when the memory is low. Once it is killed, for another time
* user load this activity, we should restore the former state
diff --git a/src/Notes-master/app/src/main/res/layout/note_edit.xml b/src/Notes-master/app/src/main/res/layout/note_edit.xml
index 10b2aa7..186f636 100644
--- a/src/Notes-master/app/src/main/res/layout/note_edit.xml
+++ b/src/Notes-master/app/src/main/res/layout/note_edit.xml
@@ -46,6 +46,13 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/title_alert" />
+ //统计字数
+
已过期
yyyyMMdd
MM月dd日 kk:mm
+ //字符数
+ 字符数:%1$d
+
+
知道了
查看
呼叫电话
diff --git a/src/Notes-master/app/src/main/res/values/strings.xml b/src/Notes-master/app/src/main/res/values/strings.xml
index 55df868..ad815e6 100644
--- a/src/Notes-master/app/src/main/res/values/strings.xml
+++ b/src/Notes-master/app/src/main/res/values/strings.xml
@@ -35,6 +35,7 @@
Send email
Browse web
Open map
+ count——num:%1$d
/MIUI/notes/
notes_%s.txt