func: Textnum

lzk_branch
commit 41d08bde3b

@ -30,6 +30,9 @@
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:icon="@drawable/icon_app"

@ -35,6 +35,8 @@ import android.text.SpannableString;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.style.BackgroundColorSpan;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@ -51,6 +53,9 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Environment;
import android.graphics.Bitmap;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
@ -70,6 +75,11 @@ import java.util.HashSet;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Vector;
import java.io.File;
import java.io.FileOutputStream;
public class NoteEditActivity extends Activity //NOTE: extends--单继承,但可多重继承 @zhoukexing 2023/12/17 23:29
@ -131,6 +141,8 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
private static final String TAG = "NoteEditActivity";
private static int MAX_REVOKE_TIMES = 10;
private HeadViewHolder mNoteHeaderHolder;
private View mHeadViewPanel;
@ -160,6 +172,10 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
private String mUserQuery;
private Pattern mPattern;
// 存储改变的数据
private Vector<SpannableString> mHistory = new Vector<SpannableString>(MAX_REVOKE_TIMES);
private boolean mIsRvoke;
/*--- 以上是此类中的数据区,以下是方法区 ---*/
/**
@ -441,6 +457,13 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
return true;
}
private String textFilter(String oriText){
String newText = oriText;
newText = newText.replace("\n", "");
newText = newText.replace(" ", "");
return newText;
}
private void initResources() {
/**
* @method: initResources
@ -460,6 +483,28 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
mNoteEditor = (EditText) findViewById(R.id.note_edit_view);
mNoteEditor.addTextChangedListener(new TextWatcher() {
int currentLength = 0;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
mNoteHeaderHolder.tvTextNum.setVisibility(View.VISIBLE);
mNoteHeaderHolder.tvTextNum.setText("长度" + String.valueOf(currentLength));
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
currentLength = textFilter(mNoteEditor.getText().toString()).length();
}
@Override
public void afterTextChanged(Editable s) {//储存文本更改的编辑
if(!mIsRvoke) {
saveHistory();
}else {
mIsRvoke = false;
}
mNoteHeaderHolder.tvTextNum.setText("长度" + String.valueOf(currentLength));
}
});
mNoteEditorPanel = findViewById(R.id.sv_note_edit);
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
for (int id : sBgSelectorBtnsMap.keySet()) {
@ -483,6 +528,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
}
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
}
@Override
@ -655,6 +701,10 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
} else if (itemId == R.id.menu_top) {
mWorkingNote.reverseTopState();
showTopHeader();
} else if (itemId == R.id.menu_revoke) {
doRevoke();
} else if (itemId == R.id.menu_screenshot) {
doScreenshot();
}
return true;
}
@ -1050,4 +1100,86 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
private void showToast(int resId, int duration) {
Toast.makeText(this, resId, duration).show();
}
/**
* @method saveHistory
* @description
* @date: 2024-01-08 8:56
* @author:
* @return void
*/
private void saveHistory() {
SpannableString text = new SpannableString(mNoteEditor.getText());
if (mHistory.size() >= MAX_REVOKE_TIMES) {
mHistory.removeElementAt(0);
mHistory.add(text);
}
else {
mHistory.add(text);
}
}
/**
* @method doRevoke
* @description
* @date: 2024-01-08 15:56
* @author:
* @return void
*/
private void doRevoke() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(R.string.tips_of_revoke);
dialog.setCancelable(true);
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
mIsRvoke = true;
if(mHistory.size() <= 1){
dialog.setMessage(R.string.cannot_revoke_anything);
dialog.show();
}
else {
mNoteEditor.setText((CharSequence)mHistory.elementAt(mHistory.size() - 2));
mHistory.removeElementAt(mHistory.size() - 1);
}
}
/**
* @method doScreenshot
* @description
* @date: 2024-01-17 17:20
* @author:
* @return
*/
private void doScreenshot() {
// 调用 getWindow().getDecorView().getRootView() 获取屏幕的根视图
// 使用 getDrawingCache() 获取视图的缓存位图
// 2024-01-17 23:22
View view = getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
// 保存Bitmap对象至文件中
// 2024-01-17 23:21
if (bitmap != null) {
try {
String sdCardPath = Environment.getExternalStorageDirectory().getPath();
String filePath = sdCardPath + File.separator + "screenshot.png";
File file = new File(filePath);
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
// showToast(R.string.success_screenshot_saved);
Toast.makeText(this, "Successfully saved the screenshot to" + filePath, Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e(TAG, "Take a screenshot error");
showToast(R.string.error_screenshot_saved);
}
}
}
} //NOTE: 这一整个文件就是这一个类 @zhoukexing 2023/12/17 23:41

@ -71,6 +71,7 @@
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="8dip"
android:textAppearance="@style/TextAppearanceSecondaryItem" />
/>
<ImageButton

@ -57,4 +57,12 @@
<item
android:id="@+id/menu_top"
android:title="@string/menu_top" />
<item
android:id="@+id/menu_revoke"
android:title="@string/menu_revoke" />
<item
android:id="@+id/menu_screenshot"
android:title="@string/menu_screenshot" />
</menu>

@ -68,6 +68,10 @@
<string name="menu_share">Share</string>
<string name="menu_send_to_desktop">Send to home</string>
<string name="menu_alert">Remind me</string>
<string name="menu_revoke" translatable="false">Revoke text</string>
<string name="tips_of_revoke" translatable="false">Tip</string>
<string name="cannot_revoke_anything" translatable="false">You cannot revoke anything</string>
<string name="menu_screenshot" translatable="false">Screenshot</string>
<string name="menu_remove_remind">Delete reminder</string>
<string name="menu_title_select_folder">Select folder</string>
<string name="menu_move_parent_folder">Parent folder</string>
@ -87,6 +91,8 @@
<string name="error_note_not_exist">The note is not exist</string>
<string name="error_note_empty_for_clock">Sorry, can not set clock on empty note</string>
<string name="error_note_empty_for_send_to_desktop">Sorry, can not send and empty note to home</string>
<string name="success_screenshot_saved" translatable="false">"Successfully saved the screenshot</string>
<string name="error_screenshot_saved" translatable="false">Failed to save screenshot</string>
<string name="success_sdcard_export">Export successful</string>
<string name="failed_sdcard_export">Export fail</string>
<string name="format_exported_file_location">Export text file (%1$s) to SD (%2$s) directory</string>

Loading…
Cancel
Save