|
|
|
@ -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
|
|
|
|
|