Compare commits

...

3 Commits

@ -0,0 +1,6 @@
projectKey=myNotes
serverUrl=http://127.0.0.1:9000
serverVersion=9.5.0.56709
dashboardUrl=http://127.0.0.1:9000/dashboard?id=myNotes
ceTaskId=AYRIh5EzuqDImpFV-sUP
ceTaskUrl=http://127.0.0.1:9000/api/ce/task?id=AYRIh5EzuqDImpFV-sUP

@ -38,6 +38,58 @@
<application
android:icon="@drawable/icon_app"
android:label="@string/app_name" >
<activity
android:name=".ui.SplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.LoginActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/NoteTheme"
android:windowSoftInputMode="adjustPan" >
<!--android:uiOptions="splitActionBarWhenNarrow"-->
<!--<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>-->
</activity>
<activity
android:name=".ui.ChangingPassword"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/NoteTheme"
android:windowSoftInputMode="adjustPan" >
</activity>
<activity
android:name=".ui.SettingPassword"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/NoteTheme"
android:windowSoftInputMode="adjustPan" >
</activity>
<activity
android:name=".ui.DeletingPassword"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/NoteTheme"
android:windowSoftInputMode="adjustPan" >
</activity>
<activity
android:name=".ui.NotesListActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
@ -47,10 +99,10 @@
android:uiOptions="splitActionBarWhenNarrow"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<!--<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</intent-filter>-->
</activity>
<activity

@ -36,9 +36,11 @@ public class Contact {
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
private Contact(){}
public static String getContact(Context context, String phoneNumber) {
if(sContactCache == null) {
sContactCache = new HashMap<String, String>();
sContactCache = new HashMap<>();
}
if(sContactCache.containsKey(phoneNumber)) {

@ -20,6 +20,7 @@ import android.net.Uri;
public class Notes {
public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes";
public static final String CONTENT_ = "content://";
public static final int TYPE_NOTE = 0;
public static final int TYPE_FOLDER = 1;
public static final int TYPE_SYSTEM = 2;
@ -47,6 +48,7 @@ public class Notes {
public static final int TYPE_WIDGET_4X = 1;
public static class DataConstants {
private DataConstants(){}
public static final String NOTE = TextNote.CONTENT_ITEM_TYPE;
public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE;
}
@ -54,12 +56,12 @@ public class Notes {
/**
* Uri to query all notes and folders
*/
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
public static final Uri CONTENT_NOTE_URI = Uri.parse(CONTENT_ + AUTHORITY + "/note");
/**
* Uri to query data
*/
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
public static final Uri CONTENT_DATA_URI = Uri.parse(CONTENT_ + AUTHORITY + "/data");
public interface NoteColumns {
/**
@ -206,6 +208,8 @@ public class Notes {
*/
public static final String CONTENT = "content";
public static final String LOCATION = "location";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
@ -248,6 +252,8 @@ public class Notes {
* Mode to indicate the text in check list mode or not
* <P> Type: Integer 1:check list mode 0: normal mode </P>
*/
private TextNote(){}
public static final String MODE = DATA1;
public static final int MODE_CHECK_LIST = 1;
@ -256,7 +262,7 @@ public class Notes {
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
public static final Uri CONTENT_URI = Uri.parse(CONTENT_ + AUTHORITY + "/text_note");
}
public static final class CallNote implements DataColumns {
@ -264,6 +270,9 @@ public class Notes {
* Call date for this record
* <P> Type: INTEGER (long) </P>
*/
private CallNote(){}
public static final String CALL_DATE = DATA1;
/**
@ -276,6 +285,6 @@ public class Notes {
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");
public static final Uri CONTENT_URI = Uri.parse(CONTENT_ + AUTHORITY + "/call_note");
}
}

@ -76,7 +76,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
DataColumns.DATA2 + " INTEGER," +
DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +
DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''," +
DataColumns.LOCATION + " TEXT NOT NULL DEFAULT ''" +
")";
private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
@ -328,6 +329,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
oldVersion++;
}
if (oldVersion == 5) {
upgradeToV6(db);
oldVersion++;
}
if (reCreateTriggers) {
reCreateNoteTableTriggers(db);
reCreateDataTableTriggers(db);
@ -371,4 +377,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
+ " INTEGER NOT NULL DEFAULT 0");
}
private void upgradeToV6(SQLiteDatabase db) {
db.execSQL("ALTER TABLE " + TABLE.DATA + " ADD COLUMN " + DataColumns.LOCATION
+ "TEXT NOT NULL DEFAULT ''");
}
}

@ -0,0 +1,69 @@
package net.micode.notes.ui;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import net.micode.notes.R;
public class ChangingPassword extends Activity {
EditText OldPassword;
EditText NewPassword;
EditText AckPassword;
Button Acknowledged;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_change_password);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
OldPassword=(EditText) findViewById(R.id.old_password);
NewPassword=(EditText) findViewById(R.id.new_password);
AckPassword=(EditText) findViewById(R.id.ack_password);
Acknowledged=(Button)findViewById(R.id.Acknowledged);
Acknowledged.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String old_password = OldPassword.getText().toString();
String new_password = NewPassword.getText().toString();
String ack_password = AckPassword.getText().toString();
SharedPreferences pref=getSharedPreferences("user management",MODE_PRIVATE);
String login_password=pref.getString("password","");
if(old_password.equals("")==true || new_password.equals("")==true || ack_password.equals("")==true) {
Toast.makeText(ChangingPassword.this, "密码不能为空", Toast.LENGTH_SHORT).show();
}else if (new_password.equals(ack_password) == false) {
Toast.makeText(ChangingPassword.this, "新建密码与重复密码不匹配,请重新输入密码", Toast.LENGTH_SHORT).show();
AckPassword.setText("");
}else if(old_password.equals(login_password) == false){
Toast.makeText(ChangingPassword.this, "原有密码错误,请重新输入密码", Toast.LENGTH_SHORT).show();
OldPassword.setText("");
}
else if (new_password.equals(ack_password) == true && old_password.equals(login_password) == true){
SharedPreferences.Editor editor=getSharedPreferences("user management", MODE_PRIVATE).edit();
editor.putString("password",new_password);
editor.apply();
Toast.makeText(ChangingPassword.this, "修改密码成功", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(ChangingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}
});
}
@Override
public void onBackPressed() {
Intent intent=new Intent(ChangingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}

@ -0,0 +1,63 @@
package net.micode.notes.ui;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import net.micode.notes.R;
public class DeletingPassword extends Activity {
EditText Dt_password;
Button Acknowledged;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_delete_password);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
Dt_password=(EditText) findViewById(R.id.thepassword);
Acknowledged=(Button)findViewById(R.id.Dt_Acknowledged);
Acknowledged.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text02 = Dt_password.getText().toString();
if(text02.equals("")==true)
Toast.makeText(DeletingPassword.this, "密码不能为空", Toast.LENGTH_SHORT).show();
SharedPreferences pref=getSharedPreferences("user management",MODE_PRIVATE);
String password = pref.getString("password","");
if(password.equals("")==false&&password.equals(text02)==true){
SharedPreferences.Editor editor=getSharedPreferences("user management",
MODE_PRIVATE).edit();
editor.putBoolean("user",false);//false表示已经设置登录密码
editor.putString("password","");
editor.apply();
Toast.makeText(DeletingPassword.this, "已经删除登录密码", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(DeletingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
else{
Toast.makeText(DeletingPassword.this, "密码错误", Toast.LENGTH_SHORT).show();
Dt_password.setText("");//把密码框内输入过的错误密码清空
}
}
});
}
@Override
public void onBackPressed() {
Intent intent=new Intent(DeletingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}

@ -0,0 +1,57 @@
package net.micode.notes.ui;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import net.micode.notes.R;
public class LoginActivity extends Activity {
EditText lg_password;
Button lg_login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences pref=getSharedPreferences("user management",MODE_PRIVATE);
boolean User_boolean = pref.getBoolean("user",false);//获取用户是否设置了密码
if(!User_boolean) //User_boolean = false时没有设置密码直接跳转到便签主界面
{
Intent intent=new Intent(LoginActivity.this,NotesListActivity.class);
startActivity(intent);
finish();
}
setContentView(R.layout.activity_login);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
lg_password=(EditText) findViewById(R.id.lg_password);
lg_login=(Button)findViewById(R.id.login);
lg_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences pref=getSharedPreferences("user management",MODE_PRIVATE);
String password=pref.getString("password","");
if(password.equals("")==false&&password.equals(lg_password.getText().toString())==true){
Intent intent=new Intent(LoginActivity.this,NotesListActivity.class);
startActivity(intent);
finish();
}
else{
Toast.makeText(LoginActivity.this, "密码错误", Toast.LENGTH_SHORT).show();
lg_password.setText("");//把密码框内输入过的错误密码清空
}
}
}
);
}
}

@ -103,6 +103,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -135,6 +136,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
}
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
static {
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED);
@ -144,6 +146,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
}
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
static {
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
sBgSelectorSelectionMap.put(ResourceParser.RED, R.id.iv_bg_red_select);
@ -153,6 +156,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
}
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
static {
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL);
@ -161,6 +165,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
}
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
static {
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select);
@ -188,7 +193,6 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
private int mFontSizeId;
private static final String PREFERENCE_FONT_SIZE = "pref_font_size";
private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10;
@ -200,7 +204,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
public static final int CHOOSE_PHOTO = 2;
private final int PHOTO_SUCCESS = 3;
private final int CAMERA_SUCCESS = 4;
// TextToSpeech tts;
// TextToSpeech tts;
TextView num_word;
TextView location;
public static final int LOCATION_CODE = 301;
@ -210,6 +214,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
private AlertDialog alertDialog2;
private CharSequence restore_translate = null;
private boolean mIsRvoke = false;
private LinearLayout mEditTextList;
@ -244,9 +249,6 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
}
/**
* 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
@ -300,7 +302,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
} else if (TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
// New note
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
@ -400,11 +402,11 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
}
}
private void showTopHeader(){
private void showTopHeader() {
mNoteHeaderHolder.tvToptext.setText(R.string.menu_set_top);
if(mWorkingNote.getTopId()==1){
if (mWorkingNote.getTopId() == 1) {
mNoteHeaderHolder.tvToptext.setVisibility(View.VISIBLE);
} else{
} else {
mNoteHeaderHolder.tvToptext.setVisibility(View.GONE);
}
}
@ -447,7 +449,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
}
private boolean inRangeOfView(View view, MotionEvent ev) {
int []location = new int[2];
int[] location = new int[2];
view.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
@ -468,8 +470,28 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
mNoteHeaderHolder.tvToptext = (TextView) findViewById(R.id.tv_set_top);
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() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {//文本更改后
if (!mIsRvoke) {
saveMyChanged();
} else {
mIsRvoke = false;
}
}
});
mNoteEditorPanel = findViewById(R.id.sv_note_edit);
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
for (int id : sBgSelectorBtnsMap.keySet()) {
@ -481,7 +503,8 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
for (int id : sFontSizeBtnsMap.keySet()) {
View view = findViewById(id);
view.setOnClickListener(this);
};
}
;
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
/**
@ -489,7 +512,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
* * The id may larger than the length of resources, in this case,
* * return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/
if(mFontSizeId >= TextAppearanceResources.getResourcesSize()) {
if (mFontSizeId >= TextAppearanceResources.getResourcesSize()) {
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
}
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
@ -498,12 +521,13 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
speech_sum();
local_sel();
translate();
}
@Override
protected void onPause() {
super.onPause();
if(saveNote()) {
if (saveNote()) {
Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length());
}
clearSettingState();
@ -511,7 +535,6 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
}
private void updateWidget() {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
@ -523,7 +546,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
return;
}
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{
mWorkingNote.getWidgetId()
});
@ -560,7 +583,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
@Override
public void onBackPressed() {
if(clearSettingState()) {
if (clearSettingState()) {
return;
}
@ -598,9 +621,9 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
} else {
getMenuInflater().inflate(R.menu.note_edit, menu);
}
if (mWorkingNote.getTopId() == 1 ) {
if (mWorkingNote.getTopId() == 1) {
menu.findItem(R.id.menu_set_top).setVisible(false);
} else if(mWorkingNote.getTopId() == 0){
} else if (mWorkingNote.getTopId() == 0) {
menu.findItem(R.id.menu_cancel_top).setVisible(false);
}
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
@ -622,11 +645,14 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
case R.id.menu_new_note:
createNewNote();
break;
case R.id.menu_revoke:
doRevoke();
break;
case R.id.menu_set_top:
mWorkingNote.setTop((mWorkingNote.getTopId())==1 ? "0" : "1");
mWorkingNote.setTop((mWorkingNote.getTopId()) == 1 ? "0" : "1");
break;
case R.id.menu_cancel_top:
mWorkingNote.setTop((mWorkingNote.getTopId())==0 ? "1" : "0");
mWorkingNote.setTop((mWorkingNote.getTopId()) == 0 ? "1" : "0");
break;
case R.id.menu_delete:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
@ -667,6 +693,21 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
case R.id.menu_font_select:
showSingleAlertDiglog();
break;
case R.id.menu_count_word://数字统计
AlertDialog.Builder builder1 = new AlertDialog.Builder(this);//对话框对象
builder1.setIcon(android.R.drawable.ic_dialog_alert);//对话框图标
TextView content = (TextView) findViewById(R.id.note_edit_view);
int c = content.length();
builder1.setMessage("带符号字数总和统计为:" + c);
builder1.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});//确定按钮
builder1.setNegativeButton(android.R.string.cancel, null);//取消按钮
builder1.show();//对话框启动
break;
default:
break;
}
@ -677,7 +718,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
public void OnDateTimeSet(AlertDialog dialog, long date) {
mWorkingNote.setAlertDate(date , true);
mWorkingNote.setAlertDate(date, true);
}
});
d.show();
@ -732,7 +773,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
}
public void onTopChanged(String Top){
public void onTopChanged(String Top) {
/**
* User could set clock to an unsaved note, so before setting the
* alert clock, we should save the note first
@ -766,7 +807,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));
showAlertHeader();
if(!set) {
if (!set) {
alarmManager.cancel(pendingIntent);
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent);
@ -799,7 +840,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
mEditTextList.removeViewAt(index);
NoteEditText edit = null;
if(index == 0) {
if (index == 0) {
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
R.id.et_edit_text);
} else {
@ -816,7 +857,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
/**
* Should not happen, check for debug
*/
if(index > mEditTextList.getChildCount()) {
if (index > mEditTextList.getChildCount()) {
Log.e(TAG, "Index out of mEditTextList boundrary, should not happen");
}
@ -836,7 +877,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
String[] items = text.split("\n");
int index = 0;
for (String item : items) {
if(!TextUtils.isEmpty(item)) {
if (!TextUtils.isEmpty(item)) {
mEditTextList.addView(getListItem(item, index));
index++;
}
@ -901,7 +942,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
Log.e(TAG, "Wrong index, should not happen");
return;
}
if(hasText) {
if (hasText) {
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE);
} else {
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);
@ -1012,158 +1053,155 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
}
private String getLocation() {
//1.获取位置管理器
String city = null;
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//2.获取位置提供器GPS或是NetWork
List<String> providers = locationManager.getProviders(true);
private String getLocation(){
//1.获取位置管理器
String city = null;
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//2.获取位置提供器GPS或是NetWork
List<String> providers = locationManager.getProviders(true);
if (providers.contains(LocationManager.GPS_PROVIDER)) {
//如果是GPS
locationProvider = LocationManager.GPS_PROVIDER;
Log.v("TAG", "定位方式GPS");
} else if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
//如果是Network
locationProvider = LocationManager.NETWORK_PROVIDER;
Log.v("TAG", "定位方式Network");
}else {
Toast.makeText(this, "没有可用的位置提供器", Toast.LENGTH_SHORT).show();
return null;
}
if (providers.contains(LocationManager.GPS_PROVIDER)) {
//如果是GPS
locationProvider = LocationManager.GPS_PROVIDER;
Log.v("TAG", "定位方式GPS");
} else if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
//如果是Network
locationProvider = LocationManager.NETWORK_PROVIDER;
Log.v("TAG", "定位方式Network");
} else {
Toast.makeText(this, "没有可用的位置提供器", Toast.LENGTH_SHORT).show();
return null;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//获取权限(如果没有开启权限,会弹出对话框,询问是否开启权限)
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED ||
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
//请求权限
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION}, LOCATION_CODE);
} else {
//3.获取上次的位置一般第一次运行此值为null
Location location = locationManager.getLastKnownLocation(locationProvider);
if (location!=null){
Toast.makeText(this, location.getLongitude() + " " +
location.getLatitude() + "",Toast.LENGTH_SHORT).show();
Log.v("TAG", "获取上次的位置-经纬度:"+location.getLongitude()+" "+location.getLatitude());
city=getAddress(location);
}else{
//监视地理位置变化第二个和第三个参数分别为更新的最短时间minTime和最短距离minDistace
locationManager.requestLocationUpdates(locationProvider, 3000, 1,locationListener);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//获取权限(如果没有开启权限,会弹出对话框,询问是否开启权限)
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED ||
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
//请求权限
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION}, LOCATION_CODE);
} else {
//3.获取上次的位置一般第一次运行此值为null
Location location = locationManager.getLastKnownLocation(locationProvider);
if (location!=null){
if (location != null) {
Toast.makeText(this, location.getLongitude() + " " +
location.getLatitude() + "", Toast.LENGTH_SHORT).show();
Log.v("TAG", "获取上次的位置-经纬度:"+location.getLongitude()+" "+location.getLatitude());
city=getAddress(location);
Log.v("TAG", "获取上次的位置-经纬度:" + location.getLongitude() + " " + location.getLatitude());
city = getAddress(location);
}else{
} else {
//监视地理位置变化第二个和第三个参数分别为更新的最短时间minTime和最短距离minDistace
locationManager.requestLocationUpdates(locationProvider, 3000, 1,locationListener);
locationManager.requestLocationUpdates(locationProvider, 3000, 1, locationListener);
}
}
return city;
}
} else {
Location location = locationManager.getLastKnownLocation(locationProvider);
if (location != null) {
Toast.makeText(this, location.getLongitude() + " " +
location.getLatitude() + "", Toast.LENGTH_SHORT).show();
Log.v("TAG", "获取上次的位置-经纬度:" + location.getLongitude() + " " + location.getLatitude());
city = getAddress(location);
public LocationListener locationListener = new LocationListener() {
// Provider的状态在可用、暂时不可用和无服务三个状态直接切换时触发此函数
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
// Provider被enable时触发此函数比如GPS被打开
@Override
public void onProviderEnabled(String provider) {
}
// Provider被disable时触发此函数比如GPS被关闭
@Override
public void onProviderDisabled(String provider) {
}
//当坐标改变时触发此函数如果Provider传进相同的坐标它就不会被触发
@Override
public void onLocationChanged(Location location) {
if (location != null) {
//如果位置发生变化,重新显示地理位置经纬度
Toast.makeText(NoteEditActivity.this, location.getLongitude() + " " +
location.getLatitude() + "", Toast.LENGTH_SHORT).show();
Log.v("TAG", "监视地理位置变化-经纬度:"+location.getLongitude()+" "+location.getLatitude());
}
} else {
//监视地理位置变化第二个和第三个参数分别为更新的最短时间minTime和最短距离minDistace
locationManager.requestLocationUpdates(locationProvider, 3000, 1, locationListener);
}
};
}
return city;
}
public LocationListener locationListener = new LocationListener() {
// Provider的状态在可用、暂时不可用和无服务三个状态直接切换时触发此函数
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case LOCATION_CODE:
if(grantResults.length > 0 && grantResults[0] == getPackageManager().PERMISSION_GRANTED
&& grantResults[1] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "申请权限", Toast.LENGTH_LONG).show();
try {
List<String> providers = locationManager.getProviders(true);
if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
//如果是Network
locationProvider = LocationManager.NETWORK_PROVIDER;
}else if (providers.contains(LocationManager.GPS_PROVIDER)) {
//如果是GPS
locationProvider = LocationManager.GPS_PROVIDER;
}
Location location = locationManager.getLastKnownLocation(locationProvider);
if (location!=null){
Toast.makeText(this, location.getLongitude() + " " +
location.getLatitude() + "", Toast.LENGTH_SHORT).show();
Log.v("TAG", "获取上次的位置-经纬度:"+location.getLongitude()+" "+location.getLatitude());
}else{
// 监视地理位置变化第二个和第三个参数分别为更新的最短时间minTime和最短距离minDistace
locationManager.requestLocationUpdates(locationProvider, 0, 0,locationListener);
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}catch (SecurityException e){
e.printStackTrace();
}
} else {
Toast.makeText(this, "缺少权限", Toast.LENGTH_LONG).show();
finish();
}
break;
}
// Provider被enable时触发此函数比如GPS被打开
@Override
public void onProviderEnabled(String provider) {
}
//获取地址信息:城市、街道等信息
private String getAddress(Location location) {
List<Address> result = null;
String city = null;
try {
if (location != null) {
Geocoder gc = new Geocoder(this, Locale.getDefault());
result = gc.getFromLocation(location.getLatitude(),
location.getLongitude(), 1);
city = result.get(0).getAddressLine(0).toString();
Toast.makeText(this, "获取地址信息:"+city, Toast.LENGTH_LONG).show();
Log.v("TAG", "获取地址信息:"+city);
}
} catch (Exception e) {
e.printStackTrace();
}
Log.e(TAG, city);
return city;
// Provider被disable时触发此函数比如GPS被关闭
@Override
public void onProviderDisabled(String provider) {
}
//当坐标改变时触发此函数如果Provider传进相同的坐标它就不会被触发
@Override
public void onLocationChanged(Location location) {
if (location != null) {
//如果位置发生变化,重新显示地理位置经纬度
Toast.makeText(NoteEditActivity.this, location.getLongitude() + " " +
location.getLatitude() + "", Toast.LENGTH_SHORT).show();
Log.v("TAG", "监视地理位置变化-经纬度:" + location.getLongitude() + " " + location.getLatitude());
}
}
};
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case LOCATION_CODE:
if (grantResults.length > 0 && grantResults[0] == getPackageManager().PERMISSION_GRANTED
&& grantResults[1] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "申请权限", Toast.LENGTH_LONG).show();
try {
List<String> providers = locationManager.getProviders(true);
if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
//如果是Network
locationProvider = LocationManager.NETWORK_PROVIDER;
} else if (providers.contains(LocationManager.GPS_PROVIDER)) {
//如果是GPS
locationProvider = LocationManager.GPS_PROVIDER;
}
Location location = locationManager.getLastKnownLocation(locationProvider);
if (location != null) {
Toast.makeText(this, location.getLongitude() + " " +
location.getLatitude() + "", Toast.LENGTH_SHORT).show();
Log.v("TAG", "获取上次的位置-经纬度:" + location.getLongitude() + " " + location.getLatitude());
} else {
// 监视地理位置变化第二个和第三个参数分别为更新的最短时间minTime和最短距离minDistace
locationManager.requestLocationUpdates(locationProvider, 0, 0, locationListener);
}
} catch (SecurityException e) {
e.printStackTrace();
}
} else {
Toast.makeText(this, "缺少权限", Toast.LENGTH_LONG).show();
finish();
}
break;
}
}
//获取地址信息:城市、街道等信息
private String getAddress(Location location) {
List<Address> result = null;
String city = null;
try {
if (location != null) {
Geocoder gc = new Geocoder(this, Locale.getDefault());
result = gc.getFromLocation(location.getLatitude(),
location.getLongitude(), 1);
city = result.get(0).getAddressLine(0).toString();
Toast.makeText(this, "获取地址信息:" + city, Toast.LENGTH_LONG).show();
Log.v("TAG", "获取地址信息:" + city);
}
} catch (Exception e) {
e.printStackTrace();
}
Log.e(TAG, city);
return city;
}
private void local_sel(){
private void local_sel() {
final Button get_local = findViewById(R.id.location);
get_local.setOnClickListener(new OnClickListener() {
@Override
@ -1188,9 +1226,9 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
String city = null;
city = getLocation();
if(city == null) {
if (city == null) {
get_local.setText("点击获得地理信息");
} else{
} else {
get_local.setText(city);
}
}
@ -1212,7 +1250,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
});
}
public void speech_sum(){
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);
@ -1228,26 +1266,28 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
@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.num_word);
number_word.setText("字符数:"+ tmp[0]);
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);
tts[0].speak(temp.toString(), TextToSpeech.QUEUE_FLUSH, null);
}
});
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
public String operateText(String str){
public String operateText(String str) {
String dest = "";
Pattern p = Pattern.compile("\\s*|t|r|n");
Matcher m = p.matcher(str);
@ -1255,40 +1295,39 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
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;
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 void convertToImage() {
NoteEditText noteEditText = (NoteEditText) findViewById(R.id.note_edit_view);
Editable editable = noteEditText.getText();
String noteText = editable.toString();
int length = editable.length();
for(int i = 0; i < length; i++) {
for(int j = i; j < length; j++) {
String img_fragment = noteText.substring(i, j+1);
if(img_fragment.length() > 15 && img_fragment.endsWith("[/local]") && img_fragment.startsWith("[local]")){
for (int i = 0; i < length; i++) {
for (int j = i; j < length; j++) {
String img_fragment = noteText.substring(i, j + 1);
if (img_fragment.length() > 15 && img_fragment.endsWith("[/local]") && img_fragment.startsWith("[local]")) {
int limit = 7;
int len = img_fragment.length()-15;
String path = img_fragment.substring(limit,limit+len);
int len = img_fragment.length() - 15;
String path = img_fragment.substring(limit, limit + len);
Bitmap bitmap = null;
Log.d(TAG, "图片的路径是:"+path);
Log.d(TAG, "图片的路径是:" + path);
try {
bitmap = BitmapFactory.decodeFile(path);
} catch (Exception e) {
e.printStackTrace();
}
if(bitmap!=null){
if (bitmap != null) {
Log.d(TAG, "图片不为null");
ImageSpan imageSpan = new ImageSpan(NoteEditActivity.this, bitmap);
String ss = "[local]" + path + "[/local]";
@ -1296,7 +1335,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
spannableString.setSpan(imageSpan, 0, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d(TAG, "Create spannable string success!");
Editable edit_text = noteEditText.getEditableText();
edit_text.delete(i,i+len+15);
edit_text.delete(i, i + len + 15);
edit_text.insert(i, spannableString);
}
}
@ -1305,7 +1344,6 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
@ -1321,11 +1359,11 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
e.printStackTrace();
}
if(bitmap != null){
if (bitmap != null) {
Log.d(TAG, "onActivityResult: bitmap is not null");
ImageSpan imageSpan = new ImageSpan(NoteEditActivity.this, bitmap);
String path = getPath(this,originalUri);
String img_fragment= "[local]" + path + "[/local]";
String path = getPath(this, originalUri);
String img_fragment = "[local]" + path + "[/local]";
SpannableString spannableString = new SpannableString(img_fragment);
spannableString.setSpan(imageSpan, 0, img_fragment.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
NoteEditText e = (NoteEditText) findViewById(R.id.note_edit_view);
@ -1337,13 +1375,13 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
ContentResolver contentResolver = getContentResolver();
ContentValues contentValues = new ContentValues();
final long id = mWorkingNote.getNoteId();
contentValues.put("snippet",mWorkingNote.getContent());
contentResolver.update(Uri.parse("content://micode_notes/note"), contentValues,"_id=?",new String[]{""+id});
contentValues.put("snippet", mWorkingNote.getContent());
contentResolver.update(Uri.parse("content://micode_notes/note"), contentValues, "_id=?", new String[]{"" + id});
ContentValues contentValues1 = new ContentValues();
contentValues1.put("content",mWorkingNote.getContent());
contentResolver.update(Uri.parse("content://micode_notes/data"), contentValues1,"mime_type=? and note_id=?", new String[]{"vnd.android.cursor.item/text_note",""+id});
contentValues1.put("content", mWorkingNote.getContent());
contentResolver.update(Uri.parse("content://micode_notes/data"), contentValues1, "mime_type=? and note_id=?", new String[]{"vnd.android.cursor.item/text_note", "" + id});
}else{
} else {
Toast.makeText(NoteEditActivity.this, "获取图片失败", Toast.LENGTH_SHORT).show();
}
break;
@ -1409,8 +1447,8 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
}
public void showSingleAlertDiglog(){
final String[] items = {"默认-普通","默认-非衬线","默认-衬线","默认-等宽","仿宋","黑体","楷体","姚体","隶书","行楷","新魏","中宋"};
public void showSingleAlertDiglog() {
final String[] items = {"默认-普通", "默认-非衬线", "默认-衬线", "默认-等宽", "仿宋", "黑体", "楷体", "姚体", "隶书", "行楷", "新魏", "中宋"};
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setTitle("选择字体");
alertBuilder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
@ -1465,7 +1503,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
Toast.makeText(NoteEditActivity.this, items[i], Toast.LENGTH_SHORT).show();
}
});
alertBuilder.setPositiveButton("确定",new DialogInterface.OnClickListener() {
alertBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
alertDialog2.dismiss();
@ -1484,7 +1522,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
alertDialog2.show();
}
public void translate(){
public void translate() {
final EditText editable = findViewById(R.id.note_edit_view);
final Button get_local = findViewById(R.id.translate);
get_local.setOnClickListener(new OnClickListener() {
@ -1525,9 +1563,9 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
trans3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(restore_translate == null || restore_translate.toString().equals(editable.getText().toString())){
if (restore_translate == null || restore_translate.toString().equals(editable.getText().toString())) {
Toast.makeText(NoteEditActivity.this, "无可还原内容", Toast.LENGTH_SHORT).show();
}else {
} else {
editable.setText(restore_translate);
Toast.makeText(NoteEditActivity.this, "已还原", Toast.LENGTH_SHORT).show();
}
@ -1541,7 +1579,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
public void translate_z2u() {
final EditText editable = findViewById(R.id.note_edit_view);
String word = editable.getText().toString();
word = word.replaceAll("\\n","//");
word = word.replaceAll("\\n", "//");
String from = "auto";
String to = "en";
String appid = "20221021001406789";
@ -1555,7 +1593,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
.baseUrl("https://fanyi-api.baidu.com/api/trans/vip/")
.addConverterFactory(GsonConverterFactory.create())
.build();
BaiduTranslateService baiduTranslateService =retrofitBaidu.create(BaiduTranslateService.class);
BaiduTranslateService baiduTranslateService = retrofitBaidu.create(BaiduTranslateService.class);
retrofit2.Call<RespondBean> call = baiduTranslateService.translate(word, from, to, appid, salt, sign);
call.enqueue(new Callback<RespondBean>() {
@Override
@ -1566,6 +1604,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
editable.setText(result);
Log.d(TAG, "中译英结果" + result);
}
@Override
public void onFailure(retrofit2.Call<RespondBean> call, Throwable t) {
Log.d(TAG, "onResponse: 请求失败 " + t);
@ -1576,7 +1615,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
public void translate_u2z() {
final EditText editable = findViewById(R.id.note_edit_view);
String word = editable.getText().toString();
word = word.replaceAll("\\n","//");
word = word.replaceAll("\\n", "//");
Log.d(TAG, word);
String from = "auto";
String to = "zh";
@ -1591,7 +1630,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
.baseUrl("https://fanyi-api.baidu.com/api/trans/vip/")
.addConverterFactory(GsonConverterFactory.create())
.build();
BaiduTranslateService baiduTranslateService =retrofitBaidu.create(BaiduTranslateService.class);
BaiduTranslateService baiduTranslateService = retrofitBaidu.create(BaiduTranslateService.class);
retrofit2.Call<RespondBean> call = baiduTranslateService.translate(word, from, to, appid, salt, sign);
call.enqueue(new Callback<RespondBean>() {
@Override
@ -1602,6 +1641,7 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
editable.setText(result);
Log.d(TAG, "中译英结果" + result);
}
@Override
public void onFailure(retrofit2.Call<RespondBean> call, Throwable t) {
Log.d(TAG, "onResponse: 请求失败 " + t);
@ -1609,9 +1649,41 @@ public class NoteEditActivity<关闭> extends AppCompatActivity implements OnCli
});
}
private static final int MAX_TIME_OF_RVOKE_TIME = 100;
private int MAX_OF_RVOKE_TIME = 100;
private Vector<SpannableString> mChanged = new Vector<SpannableString>(MAX_OF_RVOKE_TIME);
private void saveMyChanged() {
SpannableString text = new SpannableString(mNoteEditor.getText());//用getText方法获取每次编辑的内容
if (mChanged.size() >= MAX_TIME_OF_RVOKE_TIME) {//如果栈中的数据大于最大撤销次数,就把第一次修改的内容删除
mChanged.removeElementAt(0);
}
mChanged.add(text);//然后把本次修改的内容加入栈中
}
}
private void doRevoke() {
int size = mChanged.size();//获取当前栈大小
AlertDialog.Builder dialog = new AlertDialog.Builder(this);//创建一个alertdialog窗口
dialog.setTitle(R.string.tips_of_revoke);//设置title信息
dialog.setCancelable(true);//设置为可取消
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {//只需要设置一个OK键即可
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
mIsRvoke = true;//把是否已执行撤销的标记设置为true
if (size <= 1) {//如果栈中元素过少,打印提示信息
dialog.setMessage(R.string.have_not_input_anything);//提示用户您还没有输入任何信息
dialog.show();//显示当前alertdialog
return;
} else {
mNoteEditor.setText((CharSequence) mChanged.elementAt(size - 2));//在textview中设置撤销的内容
mNoteEditor.setSelection(mNoteEditor.length());
mChanged.removeElementAt(size - 1);//删除元素
if (size == 2) {
dialog.setMessage(R.string.can_not_revoke);//如果只有一次操作,那么提示用户不能再撤销了
dialog.show();//显示当前alertdialog
}
}
}
}

@ -16,6 +16,7 @@
package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.app.AlertDialog;
@ -80,6 +81,8 @@ import java.io.InputStreamReader;
import java.util.HashSet;
public class NotesListActivity extends AppCompatActivity implements OnClickListener, OnItemLongClickListener {
public static int secret_mode = 0;
private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;
private static final int FOLDER_LIST_QUERY_TOKEN = 1;
@ -416,10 +419,34 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
: NORMAL_SELECTION;
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {
String.valueOf(mCurrentFolderId)
}, NoteColumns.TOP+ " DESC,"+ NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
String str1 = "0123456789";
String[] PROJECTION = new String[]{ //定义一个新的PROJECTION数组只换掉SNIPPET
NoteColumns.ID,
NoteColumns.ALERTED_DATE,
NoteColumns.BG_COLOR_ID,
NoteColumns.CREATED_DATE,
NoteColumns.HAS_ATTACHMENT,
NoteColumns.MODIFIED_DATE,
NoteColumns.NOTES_COUNT,
NoteColumns.PARENT_ID,
// NoteColumns.SNIPPET,
str1,
NoteColumns.TYPE,
NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE,
NoteColumns.TOP,
};
if (secret_mode == 0) {
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[]{
String.valueOf(mCurrentFolderId)
}, NoteColumns.TOP + " DESC," + NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
} else {
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
Notes.CONTENT_NOTE_URI, PROJECTION, selection, new String[]{
String.valueOf(mCurrentFolderId)
}, NoteColumns.TOP + " DESC," + NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
}
}
private final class BackgroundQueryHandler extends AsyncQueryHandler {
@ -452,6 +479,7 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
final FoldersListAdapter adapter = new FoldersListAdapter(this, cursor);
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
@SuppressLint("StringFormatInvalid")
public void onClick(DialogInterface dialog, int which) {
DataUtils.batchMoveToFolder(mContentResolver,
mNotesListAdapter.getSelectedItemIds(), adapter.getItemId(which));
@ -612,6 +640,7 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
final Dialog dialog = builder.setView(view).show();
final Button positive = (Button)dialog.findViewById(android.R.id.button1);
positive.setOnClickListener(new OnClickListener() {
@SuppressLint("StringFormatInvalid")
public void onClick(View v) {
hideSoftInput(etName);
String name = etName.getText().toString();
@ -817,6 +846,61 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
case R.id.menu_search:
onSearchRequested();
break;
case R.id.LoginSetting: { //设置登录密码功能
SharedPreferences pref=getSharedPreferences("user management",MODE_PRIVATE);
String password=pref.getString("password","");
if(password.equals(""))//没有设置密码
set_the_password();
else if(!password.equals(""))//已经设置密码
change_the_password();
break;
}
case R.id.delete_password:{
delete_the_password();
break;
}
case R.id.menu_secret: { //进入私密模式
secret_mode = 1;
AlertDialog.Builder dialog = new AlertDialog.Builder(NotesListActivity.this);
dialog.setTitle("重要提醒");
dialog.setMessage("您确认进入私密模式吗?");
dialog.setCancelable(false);
dialog.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startAsyncNotesListQuery();
Toast.makeText(NotesListActivity.this,"您已进入私密模式",Toast.LENGTH_SHORT).show();
}
});
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which){}
});
dialog.show();
startAsyncNotesListQuery();
Toast.makeText(this,"您已进入私密模式",Toast.LENGTH_SHORT).show();
break;
}
case R.id.menu_quit_secret:{ //退出私密模式
secret_mode = 0;
AlertDialog.Builder dialog = new AlertDialog.Builder(NotesListActivity.this);
dialog.setTitle("重要提醒");
dialog.setMessage("您确认退出私密模式吗?");
dialog.setCancelable(false);
dialog.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startAsyncNotesListQuery();
Toast.makeText(NotesListActivity.this,"您已退出私密模式",Toast.LENGTH_SHORT).show();
}
});
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which){}
});
dialog.show();
break;
}
default:
break;
}
@ -956,4 +1040,20 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
}
return false;
}
private void set_the_password() {
Intent intent=new Intent(NotesListActivity.this,SettingPassword.class);
startActivity(intent);
finish();
}
private void change_the_password() {
Intent intent=new Intent(NotesListActivity.this,ChangingPassword.class);
startActivity(intent);
finish();
}
private void delete_the_password() {
Intent intent=new Intent(NotesListActivity.this,DeletingPassword.class);
startActivity(intent);
finish();
}
}

@ -0,0 +1,67 @@
package net.micode.notes.ui;
import static android.content.Context.MODE_PRIVATE;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import net.micode.notes.R;
public class SettingPassword extends Activity {
EditText password;
EditText password_ack;
Button acknowledge;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_loginpassword);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
password=(EditText) findViewById(R.id.password);
password_ack=(EditText) findViewById(R.id.password_ack);
acknowledge=(Button)findViewById(R.id.acknowledge);
acknowledge.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text02 = password.getText().toString();
String text03 = password_ack.getText().toString();
if(text02.equals("")==true) {
Toast.makeText(SettingPassword.this, "密码不能为空", Toast.LENGTH_SHORT).show();
}else if (text02.equals(text03) == false) {
Toast.makeText(SettingPassword.this, "密码不匹配,请重新输入密码", Toast.LENGTH_SHORT).show();
password_ack.setText("");
}else if (text02.equals(text03) == true){
SharedPreferences.Editor editor=getSharedPreferences("user management",
MODE_PRIVATE).edit();
editor.putBoolean("user",true);//true表示已经设置登录密码
editor.putString("password",text02);
editor.apply();
Log.d("RegisterLoginPassword","password is "+text02);
Toast.makeText(SettingPassword.this, "设置密码成功", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(SettingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}
});
}
@Override
public void onBackPressed() {
Intent intent=new Intent(SettingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}

@ -0,0 +1,31 @@
package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowInsets;
import net.micode.notes.R;
public class SplashActivity extends AppCompatActivity {
Handler mHandler=new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //加载启动界面
setContentView(R.layout.activity_splash); //加载启动
// 当计时结束时跳转至NotesListActivity
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent=new Intent();
intent.setClass(SplashActivity.this, LoginActivity.class);
startActivity(intent);
finish(); //销毁欢迎页面
}}, 2000); // 2 秒后跳转}
}
}

@ -2,7 +2,7 @@ package net.micode.notes.ui.translate_demo;
import java.util.List;
public class RespondBean {
public class RespondBean {
/**
* from : zh

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Before

Width:  |  Height:  |  Size: 554 KiB

After

Width:  |  Height:  |  Size: 554 KiB

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save