diff --git a/app/build.gradle b/app/build.gradle index db31066..ced92a5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,18 +1,18 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion '25.0.1' + compileSdkVersion 26 + buildToolsVersion '26.0.2' defaultConfig { applicationId "com.kiminonawa.mydiary" minSdkVersion 17 - targetSdkVersion 25 + targetSdkVersion 26 // versionName rule // version.yyMMDD_BuildCount_OPTION , // BuildCount_OPTION: D = demo , A = alpha, H = hotfix - versionCode 35 - versionName "0.3.0.170424_1_A" + versionCode 36 + versionName "0.3.0.170509_1_AH" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -31,13 +31,13 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) //Android lib - compile 'com.android.support:appcompat-v7:25.3.0' - compile 'com.android.support:design:25.3.0' - compile 'com.android.support:support-v4:25.3.0' - compile 'com.android.support:support-v13:25.3.0' - compile 'com.android.support:recyclerview-v7:25.3.0' - compile 'com.android.support:gridlayout-v7:25.3.0' - compile 'com.android.support:cardview-v7:25.3.0' + compile 'com.android.support:appcompat-v7:26.1.0' + compile 'com.android.support:design:26.1.0' + compile 'com.android.support:support-v4:26.1.0' + compile 'com.android.support:support-v13:26.1.0' + compile 'com.android.support:recyclerview-v7:26.1.0' + compile 'com.android.support:gridlayout-v7:26.1.0' + compile 'com.android.support:cardview-v7:26.1.0' testCompile 'junit:junit:4.12' @@ -48,11 +48,11 @@ dependencies { compile 'commons-io:commons-io:2.5' compile 'de.hdodenhof:circleimageview:2.1.0' compile 'com.marshalchen.ultimaterecyclerview:library:0.7.0' - compile ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.10.4@aar'){ + compile ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0@aar'){ transitive=true } //Fresco photo - compile 'com.facebook.fresco:fresco:1.2.0' + compile 'com.facebook.fresco:fresco:1.8.0' //Year class to check the old devices compile 'com.facebook.device.yearclass:yearclass:2.0.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fa73c25..cfdcf6d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,6 +19,8 @@ android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" + android:resizeableActivity="false" + android:supportsPictureInPicture="false" android:supportsRtl="false" android:theme="@style/AppTheme"> @@ -52,10 +54,10 @@ + android:theme="@style/Theme_NoActionBar_FullScreen" /> + android:screenOrientation="portrait" /> getFragment( return currentFragment; } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase))); + } + + /** * Override the back-button. */ diff --git a/app/src/main/java/com/kiminonawa/mydiary/contacts/ContactsActivity.java b/app/src/main/java/com/kiminonawa/mydiary/contacts/ContactsActivity.java index 45f58f6..50b5212 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/contacts/ContactsActivity.java +++ b/app/src/main/java/com/kiminonawa/mydiary/contacts/ContactsActivity.java @@ -1,5 +1,6 @@ package com.kiminonawa.mydiary.contacts; +import android.content.Context; import android.database.Cursor; import android.graphics.PorterDuff; import android.os.Bundle; @@ -14,6 +15,8 @@ import com.kiminonawa.mydiary.R; import com.kiminonawa.mydiary.db.DBManager; +import com.kiminonawa.mydiary.shared.language.LanguagerHelper; +import com.kiminonawa.mydiary.shared.language.MyContextWrapper; import com.kiminonawa.mydiary.shared.SPFManager; import com.kiminonawa.mydiary.shared.ThemeManager; import com.kiminonawa.mydiary.shared.gui.LetterComparator; @@ -127,6 +130,11 @@ protected void onCreate(Bundle savedInstanceState) { initTopicAdapter(); } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase))); + } + private void initLanguageStr() { EN = Locale.ENGLISH.getLanguage(); JA = Locale.JAPANESE.getLanguage(); diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/DiaryActivity.java b/app/src/main/java/com/kiminonawa/mydiary/entries/DiaryActivity.java index 8b1c8dc..45486df 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/entries/DiaryActivity.java +++ b/app/src/main/java/com/kiminonawa/mydiary/entries/DiaryActivity.java @@ -1,5 +1,6 @@ package com.kiminonawa.mydiary.entries; +import android.content.Context; import android.database.Cursor; import android.os.Bundle; import android.support.annotation.NonNull; @@ -26,6 +27,8 @@ import com.kiminonawa.mydiary.entries.diary.item.IDairyRow; import com.kiminonawa.mydiary.entries.entries.EntriesEntity; import com.kiminonawa.mydiary.entries.entries.EntriesFragment; +import com.kiminonawa.mydiary.shared.language.LanguagerHelper; +import com.kiminonawa.mydiary.shared.language.MyContextWrapper; import com.kiminonawa.mydiary.shared.ThemeManager; import com.kiminonawa.mydiary.shared.statusbar.ChinaPhoneHelper; @@ -121,6 +124,11 @@ protected void onStop() { mGoogleApiClient.disconnect(); } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase))); + } + /** * diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/CopyPhotoTask.java b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/CopyPhotoTask.java index f6ed056..5ac8c33 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/CopyPhotoTask.java +++ b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/CopyPhotoTask.java @@ -8,9 +8,10 @@ import android.util.Log; import com.kiminonawa.mydiary.R; +import com.kiminonawa.mydiary.entries.diary.item.DiaryTextTag; +import com.kiminonawa.mydiary.shared.FileManager; import com.kiminonawa.mydiary.shared.photo.BitmapHelper; import com.kiminonawa.mydiary.shared.photo.ExifUtil; -import com.kiminonawa.mydiary.shared.FileManager; import java.io.FileOutputStream; import java.io.IOException; @@ -23,7 +24,7 @@ public class CopyPhotoTask extends AsyncTask { public interface CopyPhotoCallBack { - void onCopyCompiled(String fileName); + void onCopyCompiled(String fileName, DiaryTextTag tag); } private Uri uri; @@ -34,16 +35,17 @@ public interface CopyPhotoCallBack { private int reqWidth, reqHeight; private FileManager fileManager; private boolean isAddPicture = false; - + private DiaryTextTag tag; /** * From select image */ public CopyPhotoTask(Context context, Uri uri, int reqWidth, int reqHeight, - FileManager fileManager, CopyPhotoCallBack callBack) { + FileManager fileManager, CopyPhotoCallBack callBack, DiaryTextTag tag) { this.uri = uri; - isAddPicture = false; + this.isAddPicture = false; + this.tag = tag; initTask(context, reqWidth, reqHeight, fileManager, callBack); } @@ -54,8 +56,9 @@ public CopyPhotoTask(Context context, Uri uri, */ public CopyPhotoTask(Context context, String srcFileName, int reqWidth, int reqHeight, - FileManager fileManager, CopyPhotoCallBack callBack) { + FileManager fileManager, CopyPhotoCallBack callBack, DiaryTextTag tag) { this.srcFileName = fileManager.getDirAbsolutePath() + "/" + srcFileName; + this.tag = tag; isAddPicture = true; initTask(context, reqWidth, reqHeight, fileManager, callBack); } @@ -103,7 +106,7 @@ protected String doInBackground(Void... params) { protected void onPostExecute(String fileName) { super.onPostExecute(fileName); progressDialog.dismiss(); - callBack.onCopyCompiled(fileName); + callBack.onCopyCompiled(fileName,tag); } diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryFragment.java b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryFragment.java index fd4675c..feee42a 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryFragment.java +++ b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryFragment.java @@ -312,16 +312,16 @@ public void onRequestPermissionsResult(int requestCode, } - private void loadFileFromTemp(String fileName) { + private void loadFileFromTemp(String fileName,DiaryTextTag tag) { try { String tempFileSrc = FileManager.FILE_HEADER + diaryTempFileManager.getDirAbsolutePath() + "/" + fileName; -// Bitmap resizeBmp = BitmapFactory.decodeFile(tempFileSrc); -// if (resizeBmp != null) { DiaryPhoto diaryPhoto = new DiaryPhoto(getActivity()); diaryPhoto.setPhoto(Uri.parse(tempFileSrc), fileName); - DiaryTextTag tag = checkoutOldDiaryContent(); //Check edittext is focused if (tag != null) { + //Delete duplicate text + EditText currentEditText = (EditText) diaryItemHelper.get(tag.getPositionTag()).getView(); + currentEditText.getText().delete(tag.getEdittextIndex(), currentEditText.getText().toString().length()); //Add new edittext DiaryText diaryText = new DiaryText(getActivity()); diaryText.setPosition(tag.getPositionTag()); @@ -343,9 +343,6 @@ private void loadFileFromTemp(String fileName) { diaryItemHelper.createItem(diaryText); diaryText.getView().requestFocus(); } -// } else { -// throw new FileNotFoundException(tempFileSrc + "not found or bitmap is null"); -// } } catch (Exception e) { Log.e(TAG, e.toString()); Toast.makeText(getActivity(), getString(R.string.toast_photo_path_error), Toast.LENGTH_LONG).show(); @@ -589,7 +586,7 @@ public void onProviderDisabled(String provider) { }; private void openPhotoBottomSheet() { - DiaryPhotoBottomSheet diaryPhotoBottomSheet = DiaryPhotoBottomSheet.newInstance(false); + DiaryPhotoBottomSheet diaryPhotoBottomSheet = DiaryPhotoBottomSheet.newInstance(false,checkoutOldDiaryContent()); diaryPhotoBottomSheet.setTargetFragment(this, 0); diaryPhotoBottomSheet.show(getFragmentManager(), "diaryPhotoBottomSheet"); } @@ -605,7 +602,8 @@ private DiaryTextTag checkoutOldDiaryContent() { int index = currentEditText.getSelectionStart(); String nextEditTextStr = currentEditText.getText().toString() .substring(index, currentEditText.getText().toString().length()); - currentEditText.getText().delete(index, currentEditText.getText().toString().length()); + //Set index & text string + tag.setEdittextIndex(index); tag.setNextEditTextStr(nextEditTextStr); } } @@ -614,31 +612,31 @@ private DiaryTextTag checkoutOldDiaryContent() { @Override - public void selectPhoto(Uri uri) { + public void selectPhoto(Uri uri,DiaryTextTag tag) { if (FileManager.isImage( FileManager.getFileNameByUri(getActivity(), uri))) { //1.Copy bitmap to temp for rotating & resize //2.Then Load bitmap call back ; new CopyPhotoTask(getActivity(), uri, DiaryItemHelper.getVisibleWidth(getActivity()), DiaryItemHelper.getVisibleHeight(getActivity()), - diaryTempFileManager, this).execute(); + diaryTempFileManager, this,tag).execute(); } else { Toast.makeText(getActivity(), getString(R.string.toast_not_image), Toast.LENGTH_LONG).show(); } } @Override - public void addPhoto(String fileName) { + public void addPhoto(String fileName,DiaryTextTag tag) { //1.get saved file for rotating & resize from temp //2.Then , Load bitmap in call back ; new CopyPhotoTask(getActivity(), fileName, DiaryItemHelper.getVisibleWidth(getActivity()), DiaryItemHelper.getVisibleHeight(getActivity()), - diaryTempFileManager, this).execute(); + diaryTempFileManager, this,tag).execute(); } @Override - public void onCopyCompiled(String fileName) { - loadFileFromTemp(fileName); + public void onCopyCompiled(String fileName,DiaryTextTag tag) { + loadFileFromTemp(fileName,tag); } diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryPhotoBottomSheet.java b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryPhotoBottomSheet.java index dd8c53f..81bf805 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryPhotoBottomSheet.java +++ b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryPhotoBottomSheet.java @@ -18,6 +18,7 @@ import com.kiminonawa.mydiary.R; import com.kiminonawa.mydiary.entries.DiaryActivity; +import com.kiminonawa.mydiary.entries.diary.item.DiaryTextTag; import com.kiminonawa.mydiary.shared.FileManager; import com.kiminonawa.mydiary.shared.ThemeManager; @@ -32,9 +33,9 @@ public class DiaryPhotoBottomSheet extends BottomSheetDialogFragment implements View.OnClickListener { public interface PhotoCallBack { - void addPhoto(String fileName); + void addPhoto(String fileName, DiaryTextTag tag); - void selectPhoto(Uri uri); + void selectPhoto(Uri uri, DiaryTextTag tag); } private RelativeLayout RL_diary_photo_dialog; @@ -55,10 +56,11 @@ public interface PhotoCallBack { private PhotoCallBack callBack; - public static DiaryPhotoBottomSheet newInstance(boolean isEditMode) { + public static DiaryPhotoBottomSheet newInstance(boolean isEditMode, DiaryTextTag tag) { Bundle args = new Bundle(); DiaryPhotoBottomSheet fragment = new DiaryPhotoBottomSheet(); args.putBoolean("isEditMode", isEditMode); + args.putParcelable("diaryTextTag", tag); fragment.setArguments(args); return fragment; } @@ -101,16 +103,22 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); + + DiaryTextTag tag = null; + if (getArguments().getParcelable("diaryTextTag") instanceof DiaryTextTag) { + tag = getArguments().getParcelable("diaryTextTag"); + } + if (requestCode == REQUEST_START_CAMERA_CODE) { if (resultCode == RESULT_OK) { - callBack.addPhoto(tempFileName); + callBack.addPhoto(tempFileName, tag); } dismiss(); } else if (requestCode == REQUEST_SELECT_IMAGE_CODE) { if (resultCode == RESULT_OK) { //fix the ZenPhone C & HTC 626 crash issues if (data != null && data.getData() != null && callBack != null) { - callBack.selectPhoto(data.getData()); + callBack.selectPhoto(data.getData(), tag); } else { Toast.makeText(getActivity(), getString(R.string.toast_photo_intent_error), Toast.LENGTH_LONG).show(); } diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/SaveDiaryTask.java b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/SaveDiaryTask.java index 43294ac..e1255a7 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/SaveDiaryTask.java +++ b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/SaveDiaryTask.java @@ -114,13 +114,13 @@ protected Integer doInBackground(Long... params) { @Override protected void onPostExecute(Integer result) { super.onPostExecute(result); + progressDialog.dismiss(); if (result == SaveDiaryTask.RESULT_INSERT_SUCCESSFUL) { Toast.makeText(mContext, mContext.getString(R.string.toast_diary_insert_successful), Toast.LENGTH_LONG).show(); + callBack.onDiarySaved(); } else { Toast.makeText(mContext, mContext.getString(R.string.toast_diary_insert_fail), Toast.LENGTH_LONG).show(); } - progressDialog.dismiss(); - callBack.onDiarySaved(); } private void savePhoto(String filename) throws Exception { diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/item/DiaryTextTag.java b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/item/DiaryTextTag.java index e707d3c..3b48bd2 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/item/DiaryTextTag.java +++ b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/item/DiaryTextTag.java @@ -1,18 +1,28 @@ package com.kiminonawa.mydiary.entries.diary.item; +import android.os.Parcel; +import android.os.Parcelable; + /** * Created by daxia on 2016/11/21. * To avoid getting the error focus , and send more data in one method. */ -public class DiaryTextTag { +public class DiaryTextTag implements Parcelable { private int positionTag; + private int edittextIndex; private String nextEditTextStr; public DiaryTextTag(int positionTag) { this.positionTag = positionTag; } + protected DiaryTextTag(Parcel in) { + positionTag = in.readInt(); + edittextIndex = in.readInt(); + nextEditTextStr = in.readString(); + } + public int getPositionTag() { return positionTag; } @@ -28,4 +38,42 @@ public String getNextEditTextStr() { public void setNextEditTextStr(String nextEditTextStr) { this.nextEditTextStr = nextEditTextStr; } + + public int getEdittextIndex() { + return edittextIndex; + } + + public void setEdittextIndex(int edittextIndex) { + this.edittextIndex = edittextIndex; + } + + /* + * Parcel + */ + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(positionTag); + dest.writeInt(edittextIndex); + dest.writeString(nextEditTextStr); + } + + @Override + public int describeContents() { + return 0; + } + + public static final Creator CREATOR = new Creator() { + @Override + public DiaryTextTag createFromParcel(Parcel in) { + return new DiaryTextTag(in); + } + + @Override + public DiaryTextTag[] newArray(int size) { + return new DiaryTextTag[size]; + } + }; + + } diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/entries/DiaryViewerDialogFragment.java b/app/src/main/java/com/kiminonawa/mydiary/entries/entries/DiaryViewerDialogFragment.java index 33ec4cc..aaf319e 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/entries/entries/DiaryViewerDialogFragment.java +++ b/app/src/main/java/com/kiminonawa/mydiary/entries/entries/DiaryViewerDialogFragment.java @@ -641,14 +641,16 @@ private void setIcon(int mood, int weather) { } } - private void loadFileFromTemp(String fileName) { + private void loadFileFromTemp(String fileName, DiaryTextTag tag) { try { String tempFileSrc = FileManager.FILE_HEADER + diaryFileManager.getDirAbsolutePath() + "/" + fileName; DiaryPhoto diaryPhoto = new DiaryPhoto(getActivity()); diaryPhoto.setPhoto(Uri.parse(tempFileSrc), fileName); - DiaryTextTag tag = checkoutOldDiaryContent(); //Check edittext is focused if (tag != null) { + //Delete duplicate text + EditText currentEditText = (EditText) diaryItemHelper.get(tag.getPositionTag()).getView(); + currentEditText.getText().delete(tag.getEdittextIndex(), currentEditText.getText().toString().length()); //Add new edittext DiaryText diaryText = new DiaryText(getActivity()); diaryText.setPosition(tag.getPositionTag()); @@ -689,7 +691,8 @@ private DiaryTextTag checkoutOldDiaryContent() { int index = currentEditText.getSelectionStart(); String nextEditTextStr = currentEditText.getText().toString() .substring(index, currentEditText.getText().toString().length()); - currentEditText.getText().delete(index, currentEditText.getText().toString().length()); + //Set index & text string + tag.setEdittextIndex(index); tag.setNextEditTextStr(nextEditTextStr); } } @@ -713,7 +716,7 @@ private void updateDiary() { } private void openPhotoBottomSheet() { - DiaryPhotoBottomSheet diaryPhotoBottomSheet = DiaryPhotoBottomSheet.newInstance(true); + DiaryPhotoBottomSheet diaryPhotoBottomSheet = DiaryPhotoBottomSheet.newInstance(true, checkoutOldDiaryContent()); diaryPhotoBottomSheet.setTargetFragment(this, 0); diaryPhotoBottomSheet.show(getFragmentManager(), "diaryPhotoBottomSheet"); } @@ -725,31 +728,31 @@ public void onDiaryUpdated() { } @Override - public void selectPhoto(Uri uri) { + public void selectPhoto(Uri uri, DiaryTextTag tag) { if (FileManager.isImage( FileManager.getFileNameByUri(getActivity(), uri))) { //1.Copy bitmap to temp for rotating & resize //2.Then Load bitmap call back ; new CopyPhotoTask(getActivity(), uri, DiaryItemHelper.getVisibleWidth(getActivity()), DiaryItemHelper.getVisibleHeight(getActivity()), - diaryFileManager, this).execute(); + diaryFileManager, this, tag).execute(); } else { Toast.makeText(getActivity(), getString(R.string.toast_not_image), Toast.LENGTH_LONG).show(); } } @Override - public void addPhoto(String fileName) { + public void addPhoto(String fileName, DiaryTextTag tag) { //1.get saved file for rotating & resize from temp //2.Then , Load bitmap in call back ; new CopyPhotoTask(getActivity(), fileName, DiaryItemHelper.getVisibleWidth(getActivity()), DiaryItemHelper.getVisibleHeight(getActivity()), - diaryFileManager, this).execute(); + diaryFileManager, this, tag).execute(); } @Override - public void onCopyCompiled(String fileName) { - loadFileFromTemp(fileName); + public void onCopyCompiled(String fileName, DiaryTextTag tag) { + loadFileFromTemp(fileName, tag); } @@ -772,7 +775,7 @@ public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth setDiaryTime(); TimePickerFragment timePickerFragment = TimePickerFragment.newInstance(calendar.getTimeInMillis()); timePickerFragment.setOnTimeSetListener(this); - timePickerFragment.show(getFragmentManager(), "timePickerFragment"); + timePickerFragment.show(getActivity().getSupportFragmentManager(), "timePickerFragment"); } } @@ -790,11 +793,12 @@ public void onTimeSet(TimePicker view, int hourOfDay, int minute) { @Override public void onCopyToEditCacheCompiled(int result) { if (result == CopyDiaryToEditCacheTask.RESULT_COPY_SUCCESSFUL) { - PB_diary_item_content_hint.setVisibility(View.GONE); initData(); //Open the click listener IV_diary_clear.setOnClickListener(this); IV_diary_save.setOnClickListener(this); + //hide the loading process bar + PB_diary_item_content_hint.setVisibility(View.GONE); } else { dismissAllowingStateLoss(); } @@ -829,7 +833,6 @@ public void onClick(View v) { break; case R.id.IV_diary_photo_delete: int deletePosition = (int) v.getTag(); - Log.e("test", "deletePosition = " + deletePosition); diaryItemHelper.remove(deletePosition); LL_diary_item_content.removeViewAt(deletePosition); diaryItemHelper.mergerAdjacentText(deletePosition); diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoDetailViewerActivity.java b/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoDetailViewerActivity.java index 7b42fb6..cdcbae6 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoDetailViewerActivity.java +++ b/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoDetailViewerActivity.java @@ -1,6 +1,7 @@ package com.kiminonawa.mydiary.entries.photo; import android.annotation.TargetApi; +import android.content.Context; import android.graphics.Color; import android.net.Uri; import android.os.Build; @@ -12,6 +13,8 @@ import android.widget.Toast; import com.kiminonawa.mydiary.R; +import com.kiminonawa.mydiary.shared.language.LanguagerHelper; +import com.kiminonawa.mydiary.shared.language.MyContextWrapper; import com.kiminonawa.mydiary.shared.ScreenHelper; import java.util.ArrayList; @@ -71,6 +74,12 @@ public void onCreate(Bundle savedInstanceState) { } } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase))); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void setStatusBarColor() { Window window = getWindow(); diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoOverviewActivity.java b/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoOverviewActivity.java index 2910900..7d5c563 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoOverviewActivity.java +++ b/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoOverviewActivity.java @@ -1,5 +1,6 @@ package com.kiminonawa.mydiary.entries.photo; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -12,6 +13,8 @@ import com.kiminonawa.mydiary.R; import com.kiminonawa.mydiary.shared.FileManager; +import com.kiminonawa.mydiary.shared.language.LanguagerHelper; +import com.kiminonawa.mydiary.shared.language.MyContextWrapper; import java.io.File; import java.util.ArrayList; @@ -71,6 +74,12 @@ protected void onCreate(Bundle savedInstanceState) { } } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase))); + } + + private void loadDiaryImageData(long topicId, long diaryId) { FileManager diaryRoot = new FileManager(PhotoOverviewActivity.this, DIARY_ROOT_DIR); File topicRootFile; diff --git a/app/src/main/java/com/kiminonawa/mydiary/init/InitActivity.java b/app/src/main/java/com/kiminonawa/mydiary/init/InitActivity.java index 534f434..960ce90 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/init/InitActivity.java +++ b/app/src/main/java/com/kiminonawa/mydiary/init/InitActivity.java @@ -1,6 +1,7 @@ package com.kiminonawa.mydiary.init; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.Handler; @@ -11,6 +12,8 @@ import com.kiminonawa.mydiary.R; import com.kiminonawa.mydiary.main.MainActivity; import com.kiminonawa.mydiary.security.PasswordActivity; +import com.kiminonawa.mydiary.shared.language.LanguagerHelper; +import com.kiminonawa.mydiary.shared.language.MyContextWrapper; import com.kiminonawa.mydiary.shared.MyDiaryApplication; import com.kiminonawa.mydiary.shared.SPFManager; @@ -52,6 +55,11 @@ protected void onPause() { initHandler.removeCallbacksAndMessages(null); } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase))); + } + @Override public void onInitCompiled(boolean showReleaseNote) { diff --git a/app/src/main/java/com/kiminonawa/mydiary/main/AboutActivity.java b/app/src/main/java/com/kiminonawa/mydiary/main/AboutActivity.java index e0ed976..193a5ca 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/main/AboutActivity.java +++ b/app/src/main/java/com/kiminonawa/mydiary/main/AboutActivity.java @@ -1,10 +1,13 @@ package com.kiminonawa.mydiary.main; +import android.content.Context; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; import com.kiminonawa.mydiary.R; +import com.kiminonawa.mydiary.shared.language.LanguagerHelper; +import com.kiminonawa.mydiary.shared.language.MyContextWrapper; import com.kiminonawa.mydiary.shared.statusbar.ChinaPhoneHelper; /** @@ -75,6 +78,12 @@ public void onCreate(Bundle savedInstanceState) { ((TextView) findViewById(R.id.TV_about_text)).setText(license.toString()); } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase))); + } + + public class LicenseObj { public final static int MIT = 0; diff --git a/app/src/main/java/com/kiminonawa/mydiary/main/MainActivity.java b/app/src/main/java/com/kiminonawa/mydiary/main/MainActivity.java index c449dc5..cbb47dd 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/main/MainActivity.java +++ b/app/src/main/java/com/kiminonawa/mydiary/main/MainActivity.java @@ -1,5 +1,6 @@ package com.kiminonawa.mydiary.main; +import android.content.Context; import android.database.Cursor; import android.graphics.PorterDuff; import android.os.Bundle; @@ -34,6 +35,8 @@ import com.kiminonawa.mydiary.main.topic.Memo; import com.kiminonawa.mydiary.oobe.CustomViewTarget; import com.kiminonawa.mydiary.shared.FileManager; +import com.kiminonawa.mydiary.shared.language.LanguagerHelper; +import com.kiminonawa.mydiary.shared.language.MyContextWrapper; import com.kiminonawa.mydiary.shared.SPFManager; import com.kiminonawa.mydiary.shared.ThemeManager; import com.kiminonawa.mydiary.shared.gui.MyDiaryButton; @@ -188,6 +191,12 @@ public void onDestroy() { super.onDestroy(); } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase))); + } + + @Override public void onBackPressed() { if (!isExit) { diff --git a/app/src/main/java/com/kiminonawa/mydiary/main/MainTopicAdapter.java b/app/src/main/java/com/kiminonawa/mydiary/main/MainTopicAdapter.java index e4c8ce0..8c33fc3 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/main/MainTopicAdapter.java +++ b/app/src/main/java/com/kiminonawa/mydiary/main/MainTopicAdapter.java @@ -1,7 +1,6 @@ package com.kiminonawa.mydiary.main; import android.content.Intent; -import android.support.v4.view.ViewCompat; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -14,15 +13,13 @@ import android.widget.TextView; import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemAdapter; -import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemViewHolder; import com.h6ah4i.android.widget.advrecyclerview.draggable.ItemDraggableRange; -import com.h6ah4i.android.widget.advrecyclerview.draggable.annotation.DraggableItemStateFlags; import com.h6ah4i.android.widget.advrecyclerview.swipeable.SwipeableItemAdapter; import com.h6ah4i.android.widget.advrecyclerview.swipeable.SwipeableItemConstants; import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultAction; import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultActionDefault; import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultActionMoveToSwipedDirection; -import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractSwipeableItemViewHolder; +import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableSwipeableItemViewHolder; import com.kiminonawa.mydiary.R; import com.kiminonawa.mydiary.contacts.ContactsActivity; import com.kiminonawa.mydiary.db.DBManager; @@ -50,6 +47,7 @@ public class MainTopicAdapter extends RecyclerView.Adapter topicList, DBManager dbManager) { this.activity = activity; this.dbManager = dbManager; @@ -184,6 +182,10 @@ public int onGetSwipeReactionType(TopicViewHolder holder, int position, int x, i } } + @Override + public void onSwipeItemStarted(TopicViewHolder holder, int position) { + } + @Override public void onSetSwipeBackground(TopicViewHolder holder, int position, int type) { if (type == SwipeableItemConstants.DRAWABLE_SWIPE_NEUTRAL_BACKGROUND) { @@ -213,14 +215,14 @@ public SwipeResultAction onSwipeItem(TopicViewHolder holder, int position, int r @Override public boolean onCheckCanStartDrag(TopicViewHolder holder, int position, int x, int y) { - // x, y --- relative from the itemView's top-left final View containerView = holder.getSwipeableContainerView(); + final View dragHandleView = holder.getDragHandleView(); - final int offsetX = containerView.getLeft() + (int) (ViewCompat.getTranslationX(containerView) + 0.5f); - final int offsetY = containerView.getTop() + (int) (ViewCompat.getTranslationY(containerView) + 0.5f); + final int offsetX = containerView.getLeft() + (int) (containerView.getTranslationX() + 0.5f); + final int offsetY = containerView.getTop() + (int) (containerView.getTranslationY() + 0.5f); - return !topicFilter.isFilter() && ViewTools.hitTest(containerView, x - offsetX, y - offsetY); + return !topicFilter.isFilter() && ViewTools.hitTest(dragHandleView, x - offsetX, y - offsetY); } @Override @@ -233,7 +235,6 @@ public void onMoveItem(int fromPosition, int toPosition) { if (fromPosition == toPosition) { return; } - //modify the original list final ITopic originalItem = originalTopicList.remove(fromPosition); originalTopicList.add(toPosition, originalItem); @@ -242,6 +243,21 @@ public void onMoveItem(int fromPosition, int toPosition) { final ITopic filteredItem = filteredTopicList.remove(fromPosition); filteredTopicList.add(toPosition, filteredItem); + notifyDataSetChanged(false); + } + + @Override + public boolean onCheckCanDrop(int draggingPosition, int dropPosition) { + return true; + } + + @Override + public void onItemDragStarted(int position) { + notifyDataSetChanged(false); + } + + @Override + public void onItemDragFinished(int fromPosition, int toPosition, boolean result) { //save the new topic order int orderNumber = originalTopicList.size(); dbManager.opeDB(); @@ -253,11 +269,6 @@ public void onMoveItem(int fromPosition, int toPosition) { notifyDataSetChanged(false); } - @Override - public boolean onCheckCanDrop(int draggingPosition, int dropPosition) { - return true; - } - private static class SwipeRightResultAction extends SwipeResultActionMoveToSwipedDirection { private MainTopicAdapter mAdapter; private final int mPosition; @@ -328,11 +339,10 @@ protected void onCleanUp() { } - protected class TopicViewHolder extends AbstractSwipeableItemViewHolder implements DraggableItemViewHolder { + public static class TopicViewHolder extends AbstractDraggableSwipeableItemViewHolder { - @DraggableItemStateFlags - private int mDragStateFlags; + private View View_drag_handle; private ImageView IV_topic_icon; private TextView TV_topic_title; private TextView TV_topic_count; @@ -342,8 +352,9 @@ protected class TopicViewHolder extends AbstractSwipeableItemViewHolder implemen private RelativeLayout RL_topic_content; private ImageView IV_topic_left_setting_edit, IV_topic_left_setting_delete; - protected TopicViewHolder(View rootView) { + TopicViewHolder(View rootView) { super(rootView); + this.View_drag_handle = (View) rootView.findViewById(R.id.View_drag_handle); this.RL_topic_content = (RelativeLayout) rootView.findViewById(R.id.RL_topic_content); this.IV_topic_icon = (ImageView) rootView.findViewById(R.id.IV_topic_icon); this.TV_topic_title = (TextView) rootView.findViewById(R.id.TV_topic_title); @@ -355,8 +366,6 @@ protected TopicViewHolder(View rootView) { this.LL_topic_left_setting = (LinearLayout) rootView.findViewById(R.id.LL_topic_left_setting); this.IV_topic_left_setting_edit = (ImageView) rootView.findViewById(R.id.IV_topic_left_setting_edit); this.IV_topic_left_setting_delete = (ImageView) rootView.findViewById(R.id.IV_topic_left_setting_delete); - - } @Override @@ -364,47 +373,39 @@ public View getSwipeableContainerView() { return RL_topic_content; } - @Override - public void setDragStateFlags(@DraggableItemStateFlags int flags) { - mDragStateFlags = flags; - } - - @Override - @DraggableItemStateFlags - public int getDragStateFlags() { - return mDragStateFlags; - } - - protected ImageView getIconView() { + ImageView getIconView() { return IV_topic_icon; } - - protected RelativeLayout getRLTopic() { + RelativeLayout getRLTopic() { return RL_topic_view; } - protected TextView getTitleView() { + TextView getTitleView() { return TV_topic_title; } - protected TextView getTVCount() { + TextView getTVCount() { return TV_topic_count; } - protected ImageView getArrow() { + ImageView getArrow() { return IV_topic_arrow_right; } - protected View getTopicLeftSettingView() { + View getDragHandleView() { + return View_drag_handle; + } + + View getTopicLeftSettingView() { return LL_topic_left_setting; } - protected View getTopicLeftSettingEditView() { + View getTopicLeftSettingEditView() { return IV_topic_left_setting_edit; } - protected View getTopicLeftSettingDeleteView() { + View getTopicLeftSettingDeleteView() { return IV_topic_left_setting_delete; } } diff --git a/app/src/main/java/com/kiminonawa/mydiary/memo/MemoActivity.java b/app/src/main/java/com/kiminonawa/mydiary/memo/MemoActivity.java index dafc39d..982ad1d 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/memo/MemoActivity.java +++ b/app/src/main/java/com/kiminonawa/mydiary/memo/MemoActivity.java @@ -1,5 +1,6 @@ package com.kiminonawa.mydiary.memo; +import android.content.Context; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.FragmentActivity; @@ -13,6 +14,8 @@ import com.kiminonawa.mydiary.R; import com.kiminonawa.mydiary.db.DBManager; +import com.kiminonawa.mydiary.shared.language.LanguagerHelper; +import com.kiminonawa.mydiary.shared.language.MyContextWrapper; import com.kiminonawa.mydiary.shared.ThemeManager; import com.kiminonawa.mydiary.shared.ViewTools; import com.kiminonawa.mydiary.shared.statusbar.ChinaPhoneHelper; @@ -109,6 +112,12 @@ public void onClick(View v) { initTopicAdapter(); } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase))); + } + + private void loadMemo(boolean openDB) { memoList.clear(); if (openDB) { diff --git a/app/src/main/java/com/kiminonawa/mydiary/security/PasswordActivity.java b/app/src/main/java/com/kiminonawa/mydiary/security/PasswordActivity.java index 2ffec78..14fc894 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/security/PasswordActivity.java +++ b/app/src/main/java/com/kiminonawa/mydiary/security/PasswordActivity.java @@ -1,5 +1,6 @@ package com.kiminonawa.mydiary.security; +import android.content.Context; import android.content.Intent; import android.graphics.PorterDuff; import android.os.Bundle; @@ -13,6 +14,8 @@ import com.kiminonawa.mydiary.R; import com.kiminonawa.mydiary.main.MainActivity; import com.kiminonawa.mydiary.shared.Encryption; +import com.kiminonawa.mydiary.shared.language.LanguagerHelper; +import com.kiminonawa.mydiary.shared.language.MyContextWrapper; import com.kiminonawa.mydiary.shared.MyDiaryApplication; import com.kiminonawa.mydiary.shared.SPFManager; import com.kiminonawa.mydiary.shared.ThemeManager; @@ -123,6 +126,12 @@ public void onClick(View v) { initUI(); } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase))); + } + + private void initUI() { IV_password_number_1.requestFocus(); switch (currentMode) { diff --git a/app/src/main/java/com/kiminonawa/mydiary/setting/SettingActivity.java b/app/src/main/java/com/kiminonawa/mydiary/setting/SettingActivity.java index 3d7b64a..a5fcad0 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/setting/SettingActivity.java +++ b/app/src/main/java/com/kiminonawa/mydiary/setting/SettingActivity.java @@ -1,5 +1,6 @@ package com.kiminonawa.mydiary.setting; +import android.content.Context; import android.content.Intent; import android.graphics.BitmapFactory; import android.graphics.drawable.ColorDrawable; @@ -17,6 +18,8 @@ import com.kiminonawa.mydiary.R; import com.kiminonawa.mydiary.shared.ColorTools; import com.kiminonawa.mydiary.shared.FileManager; +import com.kiminonawa.mydiary.shared.language.LanguagerHelper; +import com.kiminonawa.mydiary.shared.language.MyContextWrapper; import com.kiminonawa.mydiary.shared.OldVersionHelper; import com.kiminonawa.mydiary.shared.PermissionHelper; import com.kiminonawa.mydiary.shared.SPFManager; @@ -136,6 +139,12 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase))); + } + + @Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/MyDiaryApplication.java b/app/src/main/java/com/kiminonawa/mydiary/shared/MyDiaryApplication.java index 15d2224..bd3746d 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/shared/MyDiaryApplication.java +++ b/app/src/main/java/com/kiminonawa/mydiary/shared/MyDiaryApplication.java @@ -1,7 +1,6 @@ package com.kiminonawa.mydiary.shared; import android.app.Application; -import android.content.res.Configuration; import android.support.v7.app.AppCompatDelegate; import com.facebook.drawee.backends.pipeline.Fresco; @@ -10,7 +9,6 @@ import com.facebook.imagepipeline.listener.RequestLoggingListener; import java.util.HashSet; -import java.util.Locale; import java.util.Set; /** @@ -45,7 +43,6 @@ public void onCreate() { //init Theme & language initTheme(); - setLocaleLanguage(); } @@ -54,49 +51,6 @@ private void initTheme() { themeManager.setCurrentTheme(SPFManager.getTheme(this)); } - private void setLocaleLanguage() { - Locale locale; - switch (SPFManager.getLocalLanguageCode(this)) { - case 1: - locale = Locale.ENGLISH; - break; - case 2: - locale = Locale.JAPANESE; - break; - case 3: - locale = Locale.TRADITIONAL_CHINESE; - break; - case 4: - locale = Locale.SIMPLIFIED_CHINESE; - break; - case 5: - locale = Locale.KOREAN; - break; - case 6: - locale = new Locale("th", ""); - break; - case 7: - locale = Locale.FRENCH; - break; - case 8: - locale = new Locale("es", ""); - break; - // 0 = default = language of system - default: - locale = Locale.getDefault(); - break; - } - Locale.setDefault(locale); - Configuration config = getBaseContext().getResources().getConfiguration(); - overwriteConfigurationLocale(config, locale); - } - - private void overwriteConfigurationLocale(Configuration config, Locale locale) { - //TODO FIX updateConfiguration on Android N - config.setLocale(locale); - getBaseContext().getResources() - .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); - } public boolean isHasPassword() { diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/ScreenHelper.java b/app/src/main/java/com/kiminonawa/mydiary/shared/ScreenHelper.java index f0bf95e..0c43744 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/shared/ScreenHelper.java +++ b/app/src/main/java/com/kiminonawa/mydiary/shared/ScreenHelper.java @@ -6,11 +6,10 @@ import android.content.res.Resources; import android.os.Build; import android.util.DisplayMetrics; +import android.util.Log; import android.util.TypedValue; import android.view.View; -import java.text.DecimalFormat; - /** * Created by daxia on 2016/9/23. */ @@ -21,8 +20,8 @@ public class ScreenHelper { public static float getScreenRatio(Activity activity) { DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); - DecimalFormat mDecimalFormat = new DecimalFormat("#.##"); - float ScreenRatio = Float.valueOf(mDecimalFormat.format(metrics.heightPixels / metrics.widthPixels)); + float ScreenRatio = (float) metrics.heightPixels / (float) metrics.widthPixels; + Log.e("Test", "screenRation = " + ScreenRatio); return ScreenRatio; } diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/ViewTools.java b/app/src/main/java/com/kiminonawa/mydiary/shared/ViewTools.java index 62663bc..3b960d8 100644 --- a/app/src/main/java/com/kiminonawa/mydiary/shared/ViewTools.java +++ b/app/src/main/java/com/kiminonawa/mydiary/shared/ViewTools.java @@ -5,7 +5,6 @@ import android.graphics.drawable.Drawable; import android.os.Build; import android.support.annotation.DrawableRes; -import android.support.v4.view.ViewCompat; import android.view.View; import android.widget.ScrollView; @@ -47,8 +46,8 @@ public static void setScrollBarColor(Context context, ScrollView scrollView) { } } public static boolean hitTest(View v, int x, int y) { - final int tx = (int) (ViewCompat.getTranslationX(v) + 0.5f); - final int ty = (int) (ViewCompat.getTranslationY(v) + 0.5f); + final int tx = (int) (v.getTranslationX() + 0.5f); + final int ty = (int) (v.getTranslationY() + 0.5f); final int left = v.getLeft() + tx; final int right = v.getRight() + tx; final int top = v.getTop() + ty; diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/language/LanguagerHelper.java b/app/src/main/java/com/kiminonawa/mydiary/shared/language/LanguagerHelper.java new file mode 100644 index 0000000..0054dad --- /dev/null +++ b/app/src/main/java/com/kiminonawa/mydiary/shared/language/LanguagerHelper.java @@ -0,0 +1,57 @@ +package com.kiminonawa.mydiary.shared.language; + +import android.content.Context; +import android.content.res.Configuration; +import android.os.Build; + +import com.kiminonawa.mydiary.shared.SPFManager; + +import java.util.Locale; + +/** + * Created by daxia on 2017/5/15. + */ + +public class LanguagerHelper { + + + public static Locale getLocaleLanguage(Context context) { + Locale locale; + switch (SPFManager.getLocalLanguageCode(context)) { + case 1: + locale = Locale.ENGLISH; + break; + case 2: + locale = Locale.JAPANESE; + break; + case 3: + locale = Locale.TRADITIONAL_CHINESE; + break; + case 4: + locale = Locale.SIMPLIFIED_CHINESE; + break; + case 5: + locale = Locale.KOREAN; + break; + case 6: + locale = new Locale("th", ""); + break; + case 7: + locale = Locale.FRENCH; + break; + case 8: + locale = new Locale("es", ""); + break; + // 0 = default = language of system + default: + Configuration config = context.getResources().getConfiguration(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + locale = MyContextWrapper.getSystemLocale(config); + } else { + locale = MyContextWrapper.getSystemLocaleLegacy(config); + } + break; + } + return locale; + } +} diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/language/MyContextWrapper.java b/app/src/main/java/com/kiminonawa/mydiary/shared/language/MyContextWrapper.java new file mode 100644 index 0000000..72fb3ca --- /dev/null +++ b/app/src/main/java/com/kiminonawa/mydiary/shared/language/MyContextWrapper.java @@ -0,0 +1,57 @@ +package com.kiminonawa.mydiary.shared.language; + +import android.annotation.TargetApi; +import android.content.Context; +import android.content.ContextWrapper; +import android.content.res.Configuration; +import android.os.Build; + +import java.util.Locale; + +/** + * Created by daxia on 2017/5/15. + */ + +public class MyContextWrapper extends ContextWrapper { + + public MyContextWrapper(Context base) { + super(base); + } + + @SuppressWarnings("deprecation") + public static ContextWrapper wrap(Context context, Locale locale) { + Configuration config = context.getResources().getConfiguration(); + Locale.setDefault(locale); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + setSystemLocale(config, locale); + } else { + setSystemLocaleLegacy(config, locale); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + context = context.createConfigurationContext(config); + } else { + context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); + } + return new MyContextWrapper(context); + } + + @SuppressWarnings("deprecation") + public static Locale getSystemLocaleLegacy(Configuration config) { + return config.locale; + } + + @TargetApi(Build.VERSION_CODES.N) + public static Locale getSystemLocale(Configuration config) { + return config.getLocales().get(0); + } + + @SuppressWarnings("deprecation") + public static void setSystemLocaleLegacy(Configuration config, Locale locale) { + config.locale = locale; + } + + @TargetApi(Build.VERSION_CODES.N) + public static void setSystemLocale(Configuration config, Locale locale) { + config.setLocale(locale); + } +} diff --git a/app/src/main/res/layout/fragment_diary.xml b/app/src/main/res/layout/fragment_diary.xml index 83a28cb..2512027 100644 --- a/app/src/main/res/layout/fragment_diary.xml +++ b/app/src/main/res/layout/fragment_diary.xml @@ -71,9 +71,7 @@ + android:layout_height="match_parent"> + + + android:layout_marginLeft="5dp" + android:layout_toRightOf="@id/View_drag_handle" /> Actualizaciónes - **0.3.0.170424_1_A\n + **0.3.0.170509_1_AH\n + -fix bug on editing diary\n\n + **0.3.0.170424_1_A\n -Fix bug\n -Support simple photo function\n -Modify layout\n\n diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 9e1f1aa..9c1e04c 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -3,7 +3,9 @@ Mises à jour - **0.3.0.170424_1_A\n + **0.3.0.170509_1_AH\n + -fix bug on editing diary\n\n + **0.3.0.170424_1_A\n -Fix bug\n -Support simple photo function\n -Modify layout\n\n diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 09cb3ce..bfe84e4 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -3,7 +3,9 @@ アップデート情報 - **0.3.0.170424_1_A\n + **0.3.0.170509_1_AH\n + -fix bug on editing diary\n\n + **0.3.0.170424_1_A\n -Fix bug\n -Support simple photo function\n -Modify layout\n\n diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 16bcb88..9568405 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -3,7 +3,9 @@ 업데이트 정보 - **0.3.0.170424_1_A\n + **0.3.0.170509_1_AH\n + -fix bug on editing diary\n\n + **0.3.0.170424_1_A\n -Fix bug\n -Support simple photo function\n -Modify layout\n\n diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 202d065..74a94dd 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -3,7 +3,9 @@ ข้อมูลการอัพเดท - **0.3.0.170424_1_A\n + **0.3.0.170509_1_AH\n + -fix bug on editing diary\n\n + **0.3.0.170424_1_A\n -Fix bug\n -Support simple photo function\n -Modify layout\n\n diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index b75ee92..b08bcc5 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -3,7 +3,9 @@ 更新日志 - **0.3.0.170424_1_A\n + **0.3.0.170509_1_AH\n + -修复编辑日记bug\n\n + **0.3.0.170424_1_A\n -修复bug\n -支援简单的照片功能\n -调整画面\n\n diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 9d8c525..6393ed2 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -3,7 +3,9 @@ 更新情報 - **0.3.0.170424_1_A\n + **0.3.0.170509_1_AH\n + -修復編輯日記bug\n\n + **0.3.0.170424_1_A\n -修復bug\n -支援簡易的照片功能\n -調整畫面\n\n diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f231dd2..f94d437 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,7 +4,9 @@ Release note - **0.3.0.170424_1_A\n + **0.3.0.170509_1_AH\n + -fix bug on editing diary\n\n + **0.3.0.170424_1_A\n -Fix bug\n -Support simple photo function\n -Modify layout\n\n diff --git a/build.gradle b/build.gradle index 1c3e860..7e01a0a 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:3.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -15,7 +16,7 @@ buildscript { allprojects { repositories { jcenter() - maven { url 'https://jitpack.io' } + google() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ad53bbf..92e27ee 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 diff --git a/lib_module/freso/gestures/build.gradle b/lib_module/freso/gestures/build.gradle index 5377e4e..1236c81 100644 --- a/lib_module/freso/gestures/build.gradle +++ b/lib_module/freso/gestures/build.gradle @@ -11,8 +11,8 @@ dependencies { } android { - compileSdkVersion 25 - buildToolsVersion '25.0.1' + compileSdkVersion 26 + buildToolsVersion '26.0.2' packagingOptions { exclude 'NOTICE' diff --git a/lib_module/freso/zoomable/build.gradle b/lib_module/freso/zoomable/build.gradle index 4f0334d..bdff656 100644 --- a/lib_module/freso/zoomable/build.gradle +++ b/lib_module/freso/zoomable/build.gradle @@ -12,8 +12,8 @@ dependencies { } android { - compileSdkVersion 25 - buildToolsVersion '25.0.1' + compileSdkVersion 26 + buildToolsVersion '26.0.2' packagingOptions { exclude 'NOTICE'