|
|
@ -16,11 +16,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.Dialog;
|
|
|
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.app.SearchManager;
|
|
|
|
import android.app.SearchManager;
|
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
@ -31,12 +29,10 @@ import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.graphics.Typeface;
|
|
|
|
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
@ -44,17 +40,14 @@ import android.os.Environment;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.provider.DocumentsContract;
|
|
|
|
import android.provider.DocumentsContract;
|
|
|
|
import android.provider.MediaStore;
|
|
|
|
import android.provider.MediaStore;
|
|
|
|
import android.speech.tts.TextToSpeech;
|
|
|
|
|
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
|
|
|
|
import android.text.format.DateUtils;
|
|
|
|
import android.text.format.DateUtils;
|
|
|
|
import android.text.style.BackgroundColorSpan;
|
|
|
|
import android.text.style.BackgroundColorSpan;
|
|
|
|
import android.text.style.ImageSpan;
|
|
|
|
import android.text.style.ImageSpan;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.MenuItem;
|
|
|
@ -62,8 +55,6 @@ import android.view.MotionEvent;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
|
@ -73,16 +64,6 @@ import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.baidu.speech.EventListener;
|
|
|
|
|
|
|
|
import com.baidu.speech.EventManager;
|
|
|
|
|
|
|
|
import com.baidu.speech.EventManagerFactory;
|
|
|
|
|
|
|
|
import com.baidu.speech.asr.SpeechConstant;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
import net.micode.notes.R;
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
@ -97,24 +78,16 @@ import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_2x;
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_2x;
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_4x;
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_4x;
|
|
|
|
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.text.BreakIterator;
|
|
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener, EventListener {
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
private AlertDialog alertDialog2;
|
|
|
|
|
|
|
|
private class HeadViewHolder {
|
|
|
|
private class HeadViewHolder {
|
|
|
|
public TextView tvModified;
|
|
|
|
public TextView tvModified;
|
|
|
|
|
|
|
|
|
|
|
@ -123,12 +96,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
public TextView tvAlertDate;
|
|
|
|
public TextView tvAlertDate;
|
|
|
|
|
|
|
|
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
public BreakIterator text_num;
|
|
|
|
|
|
|
|
public TextView text_nums;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED);
|
|
|
@ -138,7 +108,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.RED, R.id.iv_bg_red_select);
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.RED, R.id.iv_bg_red_select);
|
|
|
@ -148,7 +117,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL);
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL);
|
|
|
@ -157,7 +125,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select);
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select);
|
|
|
@ -196,71 +163,18 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
private String mUserQuery;
|
|
|
|
private String mUserQuery;
|
|
|
|
private Pattern mPattern;
|
|
|
|
private Pattern mPattern;
|
|
|
|
|
|
|
|
|
|
|
|
private static final int GET_STORAGE_PERMISSION = 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final int PHOTO_REQUEST = 1;//请求码
|
|
|
|
private final int PHOTO_REQUEST = 1;//请求码
|
|
|
|
|
|
|
|
|
|
|
|
private static final int REQUEST_SET_PASSCODE = 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int REQUEST_UNLOCK = 3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean Locked; /* 用以判断是否已解锁 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private EditText editText;
|
|
|
|
|
|
|
|
private TextView textView;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected EditText txtResult;//识别结果
|
|
|
|
|
|
|
|
protected Button startBtn;//开始识别 一直不说话会自动停止,需要再次打开
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private EventManager asr;//语音识别核心库
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
|
|
|
|
finish();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
editText = (EditText) findViewById(R.id.note_edit_view);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
initResources();
|
|
|
|
initResources();
|
|
|
|
speech_sum();
|
|
|
|
|
|
|
|
initView();
|
|
|
|
|
|
|
|
txtResult = findViewById(R.id.note_edit_view);
|
|
|
|
|
|
|
|
asr = EventManagerFactory.create(this, "asr");
|
|
|
|
|
|
|
|
//注册自己的输出事件类
|
|
|
|
|
|
|
|
asr.registerListener(this); // EventListener 中 onEvent方法
|
|
|
|
|
|
|
|
startBtn.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
|
|
|
|
int action = event.getAction();
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
|
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
|
|
|
|
|
start();
|
|
|
|
|
|
|
|
/*mStartSpeechButton.setBackgroundResource(
|
|
|
|
|
|
|
|
R.drawable.bdspeech_btn_orangelight_pressed);*/
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
|
|
|
|
|
stop();
|
|
|
|
|
|
|
|
/*mStartSpeechButton.setBackgroundResource(
|
|
|
|
|
|
|
|
R.drawable.bdspeech_btn_orangelight_normal);*/
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//根据id获取添加图片按钮
|
|
|
|
//根据id获取添加图片按钮
|
|
|
@ -269,10 +183,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
add_img_btn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
add_img_btn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (ContextCompat.checkSelfPermission(NoteEditActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
|
|
|
//没有授权进行权限申请
|
|
|
|
|
|
|
|
ActivityCompat.requestPermissions(NoteEditActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, GET_STORAGE_PERMISSION);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Log.d(TAG, "onClick: click add image button");
|
|
|
|
Log.d(TAG, "onClick: click add image button");
|
|
|
|
//ACTION_GET_CONTENT: 允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音)
|
|
|
|
//ACTION_GET_CONTENT: 允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音)
|
|
|
|
Intent loadImage = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
|
Intent loadImage = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
@ -282,112 +192,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
loadImage.setType("image/*");
|
|
|
|
loadImage.setType("image/*");
|
|
|
|
startActivityForResult(loadImage, PHOTO_REQUEST);
|
|
|
|
startActivityForResult(loadImage, PHOTO_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void speech_sum(){
|
|
|
|
|
|
|
|
EditText editable = findViewById(R.id.note_edit_view);
|
|
|
|
|
|
|
|
//Toast.makeText(NoteEditActivity.this, editable.getText().toString(), Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
final Button speak = findViewById(R.id.iatBtn);
|
|
|
|
|
|
|
|
final int[] tmp = new int[1];
|
|
|
|
|
|
|
|
final TextToSpeech[] tts = new TextToSpeech[1];
|
|
|
|
|
|
|
|
tts[0] = new TextToSpeech(NoteEditActivity.this, new TextToSpeech.OnInitListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onInit(int status) {
|
|
|
|
|
|
|
|
tts[0].setLanguage(Locale.US);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
editable.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) {
|
|
|
|
|
|
|
|
tmp[0] = cutOfimage(operateText(s.toString())).length();
|
|
|
|
|
|
|
|
TextView number_word = findViewById(R.id.text_nums);
|
|
|
|
|
|
|
|
number_word.setText("字符数:"+ tmp[0]);
|
|
|
|
|
|
|
|
final String temp = cutOfimage(s.toString());
|
|
|
|
|
|
|
|
speak.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
tts[0].speak(temp.toString(),TextToSpeech.QUEUE_FLUSH,null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String operateText(String str){
|
|
|
|
|
|
|
|
String dest = "";
|
|
|
|
|
|
|
|
Pattern p = Pattern.compile("\\s*|t|r|n");
|
|
|
|
|
|
|
|
Matcher m = p.matcher(str);
|
|
|
|
|
|
|
|
dest = m.replaceAll("");
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String cutOfimage(String str){
|
|
|
|
|
|
|
|
String dest = str;
|
|
|
|
|
|
|
|
int index1 = dest.indexOf("[local]");
|
|
|
|
|
|
|
|
int index2 = dest.indexOf("[/local]");
|
|
|
|
|
|
|
|
while(index1 != -1 && index2 != -1){
|
|
|
|
|
|
|
|
dest = dest.substring(0,index1) + dest.substring(index2+8);
|
|
|
|
|
|
|
|
index1 = dest.indexOf("[local]");
|
|
|
|
|
|
|
|
index2 = dest.indexOf("[/local]");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String Textchange(String oriText){
|
|
|
|
|
|
|
|
StringBuffer stringBuffer = new StringBuffer(oriText);
|
|
|
|
|
|
|
|
int Flag1 = -1;
|
|
|
|
|
|
|
|
int Flag2 = -1;
|
|
|
|
|
|
|
|
do {//不计入表示图片的字符
|
|
|
|
|
|
|
|
Flag1 = stringBuffer.indexOf("<img");
|
|
|
|
|
|
|
|
Flag2 = 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();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
|
|
|
|
|
switch (requestCode) {
|
|
|
|
|
|
|
|
case GET_STORAGE_PERMISSION:
|
|
|
|
|
|
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
|
|
|
Intent loadImage = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
|
|
|
|
|
//Category属性用于指定当前动作(Action)被执行的环境.
|
|
|
|
|
|
|
|
//CATEGORY_OPENABLE; 用来指示一个ACTION_GET_CONTENT的intent
|
|
|
|
|
|
|
|
loadImage.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
|
|
|
|
|
loadImage.setType("image/*");
|
|
|
|
|
|
|
|
startActivityForResult(loadImage, PHOTO_REQUEST);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Toast.makeText(this, "You denied the permission", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
@ -483,10 +290,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mWorkingNote.setOnSettingStatusChangedListener(this);
|
|
|
|
mWorkingNote.setOnSettingStatusChangedListener(this);
|
|
|
|
Locked = mWorkingNote.hasPassword();//设置便签解锁状态;
|
|
|
|
|
|
|
|
if (intent.hasExtra("lock")) {
|
|
|
|
|
|
|
|
Locked = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -514,21 +317,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE
|
|
|
|
mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE
|
|
|
|
| DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME
|
|
|
|
| DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME
|
|
|
|
| DateUtils.FORMAT_SHOW_YEAR));
|
|
|
|
| DateUtils.FORMAT_SHOW_YEAR));
|
|
|
|
|
|
|
|
|
|
|
|
showAlertHeader();
|
|
|
|
showAlertHeader();
|
|
|
|
//将有图片路径的位置转换为图片
|
|
|
|
//将有图片路径的位置转换为图片
|
|
|
|
convertToImage();
|
|
|
|
convertToImage();
|
|
|
|
unlockNote();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void unlockNote(){
|
|
|
|
|
|
|
|
//如果设置了密码,启动输入密码页面
|
|
|
|
|
|
|
|
if (mWorkingNote.hasPassword() && Locked) {
|
|
|
|
|
|
|
|
saveNote();
|
|
|
|
|
|
|
|
Intent intent = new Intent(this,UnlockActivity.class);
|
|
|
|
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
|
|
|
|
startActivityForResult(intent,REQUEST_SET_PASSCODE);
|
|
|
|
|
|
|
|
finish();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void showAlertHeader() {
|
|
|
|
private void showAlertHeader() {
|
|
|
@ -545,8 +337,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//路径字符串格式 转换为 图片image格式
|
|
|
|
//路径字符串格式 转换为 图片image格式
|
|
|
@ -648,7 +439,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
mNoteHeaderHolder = new HeadViewHolder();
|
|
|
|
mNoteHeaderHolder = new HeadViewHolder();
|
|
|
|
mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date);
|
|
|
|
mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);
|
|
|
|
mNoteHeaderHolder.text_nums = (TextView) findViewById(R.id.text_nums);
|
|
|
|
|
|
|
|
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
|
|
|
|
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
|
|
|
|
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
|
|
|
|
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
|
|
|
|
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
|
|
|
|
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
|
|
|
@ -664,8 +454,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
for (int id : sFontSizeBtnsMap.keySet()) {
|
|
|
|
for (int id : sFontSizeBtnsMap.keySet()) {
|
|
|
|
View view = findViewById(id);
|
|
|
|
View view = findViewById(id);
|
|
|
|
view.setOnClickListener(this);
|
|
|
|
view.setOnClickListener(this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
;
|
|
|
|
|
|
|
|
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
|
|
|
|
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -786,38 +575,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
menu.findItem(R.id.menu_delete_remind).setVisible(false);
|
|
|
|
menu.findItem(R.id.menu_delete_remind).setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//如果一设置密码,显示删除密码选项,否则,显示设置密码选项
|
|
|
|
|
|
|
|
if (mWorkingNote.hasPassword()) {
|
|
|
|
|
|
|
|
menu.findItem(R.id.menu_set_passcode).setVisible(false);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
menu.findItem(R.id.menu_delete_passcode).setVisible(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 弹出设置密码界面
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void setPassword() {
|
|
|
|
|
|
|
|
//确保笔记已写入数据库
|
|
|
|
|
|
|
|
saveNote();
|
|
|
|
|
|
|
|
//初始化一个新的意图,用以跳转至设置密码界面
|
|
|
|
|
|
|
|
Intent intent = new Intent(this,SetLockActivity.class);
|
|
|
|
|
|
|
|
//给意图传入当前便签的id参数,便于从设置密码活动中跳转回编辑便签活动
|
|
|
|
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
finish();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 删除便签密码
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void deletePassword() {
|
|
|
|
|
|
|
|
mWorkingNote.setPassword("");
|
|
|
|
|
|
|
|
saveNote();
|
|
|
|
|
|
|
|
Toast.makeText(NoteEditActivity.this,R.string.note_passcode_deleted,Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
@ -861,19 +621,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
case R.id.menu_delete_remind:
|
|
|
|
case R.id.menu_delete_remind:
|
|
|
|
mWorkingNote.setAlertDate(0, false);
|
|
|
|
mWorkingNote.setAlertDate(0, false);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case R.id.menu_font_select:
|
|
|
|
|
|
|
|
showSingleAlertDiglog();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R.id.menu_set_passcode:
|
|
|
|
|
|
|
|
setPassword();
|
|
|
|
|
|
|
|
//设置提示
|
|
|
|
|
|
|
|
Toast.makeText(NoteEditActivity.this, "设置密码成功", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R.id.menu_delete_passcode:
|
|
|
|
|
|
|
|
deletePassword();
|
|
|
|
|
|
|
|
//设置提示
|
|
|
|
|
|
|
|
Toast.makeText(NoteEditActivity.this, "解除密码成功", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1272,7 +1020,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
return getDataColumn(context, contentUri, null, null);
|
|
|
|
return getDataColumn(context, contentUri, null, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// MediaProvider
|
|
|
|
// MediaProvider
|
|
|
|
else if (isMediaDocument(uri)) {
|
|
|
|
else
|
|
|
|
|
|
|
|
if (isMediaDocument(uri)) {
|
|
|
|
final String docId = DocumentsContract.getDocumentId(uri);
|
|
|
|
final String docId = DocumentsContract.getDocumentId(uri);
|
|
|
|
final String[] split = docId.split(":");
|
|
|
|
final String[] split = docId.split(":");
|
|
|
|
final String type = split[0];
|
|
|
|
final String type = split[0];
|
|
|
@ -1335,93 +1084,4 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
public boolean isMediaDocument(Uri uri) {
|
|
|
|
public boolean isMediaDocument(Uri uri) {
|
|
|
|
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
|
|
|
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void showSingleAlertDiglog(){
|
|
|
|
|
|
|
|
final String[] items={"仿宋","黑体","楷体","宋体","新宋体"};
|
|
|
|
|
|
|
|
AlertDialog.Builder alertBuilder=new AlertDialog.Builder(this);
|
|
|
|
|
|
|
|
alertBuilder.setTitle("字体选择");
|
|
|
|
|
|
|
|
alertBuilder.setSingleChoiceItems(items,0,(dialogInterface, i) -> {
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
Typeface typeface0 = Typeface.createFromAsset(getAssets(), "Fonts/simfang.ttf");
|
|
|
|
|
|
|
|
mNoteEditor.setTypeface(typeface0);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
Typeface typeface1 = Typeface.createFromAsset(getAssets(), "Fonts/simhei.ttf");
|
|
|
|
|
|
|
|
mNoteEditor.setTypeface(typeface1);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
Typeface typeface2 = Typeface.createFromAsset(getAssets(), "Fonts/simkai.ttf");
|
|
|
|
|
|
|
|
mNoteEditor.setTypeface(typeface2);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
Typeface typeface3 = Typeface.createFromAsset(getAssets(), "Fonts/simsunb.ttf");
|
|
|
|
|
|
|
|
mNoteEditor.setTypeface(typeface3);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
Typeface typeface4 = Typeface.createFromAsset(getAssets(), "Fonts/simsun.ttc");
|
|
|
|
|
|
|
|
mNoteEditor.setTypeface(typeface4);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Toast.makeText(NoteEditActivity.this,items[i],Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
alertBuilder.setPositiveButton("确定",(dialogInterface, i) -> {
|
|
|
|
|
|
|
|
alertDialog2.dismiss();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
alertBuilder.setNegativeButton("取消",(dialogInterface, i) -> {
|
|
|
|
|
|
|
|
alertDialog2.dismiss();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
alertDialog2=alertBuilder.create();
|
|
|
|
|
|
|
|
alertDialog2.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void start() {
|
|
|
|
|
|
|
|
Toast.makeText(NoteEditActivity.this, "请开始说话", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
Map<String, Object> params = new LinkedHashMap<>();//传递Map<String,Object>的参数,会将Map自动序列化为json
|
|
|
|
|
|
|
|
String event = null;
|
|
|
|
|
|
|
|
event = SpeechConstant.ASR_START;
|
|
|
|
|
|
|
|
params.put(SpeechConstant.ACCEPT_AUDIO_VOLUME, false);//回调当前音量
|
|
|
|
|
|
|
|
String json = null;
|
|
|
|
|
|
|
|
json = new JSONObject(params).toString();//demo用json数据来做数据交换的方式
|
|
|
|
|
|
|
|
asr.send(event, json, null, 0, 0);// 初始化EventManager对象,这个实例只能创建一次,就是我们上方创建的asr,此处开始传入
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void stop() {
|
|
|
|
|
|
|
|
//txtResult.append("停止识别:ASR_STOP");
|
|
|
|
|
|
|
|
asr.send(SpeechConstant.ASR_STOP, null, null, 0, 0);//此处停止
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
|
|
|
asr.send(SpeechConstant.ASR_CANCEL, "{}", null, 0, 0);
|
|
|
|
|
|
|
|
asr.unregisterListener(this);//退出事件管理器
|
|
|
|
|
|
|
|
// 必须与registerListener成对出现,否则可能造成内存泄露
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void onEvent(String name, String params, byte[] data, int offset, int length) {
|
|
|
|
|
|
|
|
String resultTxt = null;
|
|
|
|
|
|
|
|
//Log.i(TAG, params);
|
|
|
|
|
|
|
|
if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL)) {//识别结果参数
|
|
|
|
|
|
|
|
if (params.contains("\"final_result\"")) {//语义结果值
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
JSONObject json = new JSONObject(params);
|
|
|
|
|
|
|
|
String result = json.getString("best_result");//取得key的识别结果
|
|
|
|
|
|
|
|
resultTxt = result;
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resultTxt != null) {
|
|
|
|
|
|
|
|
resultTxt += "\n";
|
|
|
|
|
|
|
|
txtResult.append(resultTxt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initView() {
|
|
|
|
|
|
|
|
txtResult = findViewById(R.id.note_edit_view);
|
|
|
|
|
|
|
|
startBtn = findViewById(R.id.listen);
|
|
|
|
|
|
|
|
//stopBtn = findViewById(R.id.stop);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|