修改心愿单生成
This commit is contained in:
@@ -60,6 +60,10 @@
|
||||
<activity
|
||||
android:name=".activity.SettingActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".activity.LanguageSettingActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:configChanges="locale|layoutDirection|keyboard" />
|
||||
<activity
|
||||
android:name=".activity.SearchActivity"
|
||||
android:screenOrientation="portrait"
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.yunbao.main.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.yunbao.common.activity.AbsActivity;
|
||||
import com.yunbao.common.utils.AppManager;
|
||||
import com.yunbao.common.views.weight.ViewClicksAntiShake;
|
||||
import com.yunbao.main.R;
|
||||
import com.yunbao.main.utils.LanguageUtil;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Stack;
|
||||
|
||||
public class LanguageSettingActivity extends AbsActivity {
|
||||
private LinearLayout traditionalChinese, english;
|
||||
private ImageView imgTraditionalChinese, imgEnglish;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_language_sett;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void main() {
|
||||
super.main();
|
||||
traditionalChinese = findViewById(R.id.traditional_chinese);
|
||||
english = findViewById(R.id.english);
|
||||
imgEnglish = findViewById(R.id.img_english);
|
||||
imgTraditionalChinese = findViewById(R.id.img_traditional_chinese);
|
||||
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.live_photo_btn_cancel), () -> onBackPressed());
|
||||
ViewClicksAntiShake.clicksAntiShake(traditionalChinese, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
changeAllActivitysLanguage(Locale.SIMPLIFIED_CHINESE);
|
||||
}
|
||||
});
|
||||
ViewClicksAntiShake.clicksAntiShake(english, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
changeAllActivitysLanguage(Locale.US);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void changeAllActivitysLanguage(Locale locale) {
|
||||
Stack<Activity> allActivityStacks = AppManager.getInstance().getAllActivityStacks();
|
||||
for (int i = 0; i < allActivityStacks.size(); i++) {
|
||||
LanguageUtil.shiftLanguage(locale, allActivityStacks.get(i),mContext);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -144,6 +144,13 @@ public class SettingActivity extends AbsActivity implements OnItemClickListener<
|
||||
startActivity(new Intent(SettingActivity.this, MsgSettActivity.class));
|
||||
}
|
||||
});
|
||||
//语言设置
|
||||
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.language_setting), new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
startActivity(new Intent(SettingActivity.this, LanguageSettingActivity.class));
|
||||
}
|
||||
});
|
||||
//屏蔽礼物特效
|
||||
ViewClicksAntiShake.clicksAntiShake(studioGiftEffects, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
|
||||
95
main/src/main/java/com/yunbao/main/utils/LanguageUtil.java
Normal file
95
main/src/main/java/com/yunbao/main/utils/LanguageUtil.java
Normal file
@@ -0,0 +1,95 @@
|
||||
package com.yunbao.main.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.backup.BackupManager;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import com.yunbao.main.activity.MainActivity;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LanguageUtil {
|
||||
|
||||
/**
|
||||
* 这个方法虽然更新了资源但是只能以后的界面生效,之前没有finish的页面还是保留原来的语言
|
||||
*
|
||||
* @param locale
|
||||
* @param context
|
||||
*/
|
||||
public static void shiftLanguage(Locale locale, Context context) {
|
||||
Resources resources = context.getResources();
|
||||
Configuration config = resources.getConfiguration();
|
||||
DisplayMetrics dm = resources.getDisplayMetrics();
|
||||
config.locale = locale;
|
||||
resources.updateConfiguration(config, dm);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 这个方法是为了让全部的activity都修改语言
|
||||
*
|
||||
* @param locale
|
||||
* @param activity
|
||||
* @param context
|
||||
*/
|
||||
public static void shiftLanguage(Locale locale, Activity activity, Context context) {
|
||||
Resources resources = context.getResources();
|
||||
Configuration config = resources.getConfiguration();
|
||||
DisplayMetrics dm = resources.getDisplayMetrics();
|
||||
config.locale = locale;
|
||||
resources.updateConfiguration(config, dm);
|
||||
if (!(activity instanceof MainActivity)) {
|
||||
activity.recreate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void updateLanguage(Locale locale) {
|
||||
try {
|
||||
Object objIActMag, objActMagNative;
|
||||
Class clzIActMag = Class.forName("android.app.IActivityManager");
|
||||
|
||||
Class clzActMagNative = Class
|
||||
.forName("android.app.ActivityManagerNative");
|
||||
//amn = ActivityManagerNative.getDefault();
|
||||
Method mtdActMagNative$getDefault = clzActMagNative
|
||||
.getDeclaredMethod("getDefault");
|
||||
objIActMag = mtdActMagNative$getDefault.invoke(clzActMagNative);
|
||||
// objIActMag = amn.getConfiguration();
|
||||
Method mtdIActMag$getConfiguration = clzIActMag
|
||||
.getDeclaredMethod("getConfiguration");
|
||||
Configuration config = (Configuration) mtdIActMag$getConfiguration.invoke(objIActMag);
|
||||
// set the locale to the new value
|
||||
config.locale = locale;
|
||||
|
||||
//持久化 config.userSetLocale = true;
|
||||
Class clzConfig = Class
|
||||
.forName("android.content.res.Configuration");
|
||||
java.lang.reflect.Field userSetLocale = clzConfig
|
||||
.getField("userSetLocale");
|
||||
userSetLocale.set(config, true);
|
||||
|
||||
//如果有阿拉伯语,必须加上,否则阿拉伯语与其它语言切换时,布局与文字方向不会改变
|
||||
Method setLayoutDirection = clzConfig
|
||||
.getDeclaredMethod("setLayoutDirection", Locale.class);
|
||||
setLayoutDirection.invoke(config, locale);
|
||||
|
||||
// 此处需要声明权限:android.permission.CHANGE_CONFIGURATION
|
||||
// 会重新调用 onCreate();
|
||||
Class[] clzParams = {Configuration.class};
|
||||
// objIActMag.updateConfiguration(config);
|
||||
Method mtdIActMag$updateConfiguration = clzIActMag
|
||||
.getDeclaredMethod("updateConfiguration", clzParams);
|
||||
|
||||
mtdIActMag$updateConfiguration.invoke(objIActMag, config);
|
||||
BackupManager.dataChanged("com.android.providers.settings");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
9
main/src/main/res/drawable/background_language.xml
Normal file
9
main/src/main/res/drawable/background_language.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="12dp" />
|
||||
<solid android:color="#FFC821" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
BIN
main/src/main/res/drawable/icon_xuanzhong.png
Normal file
BIN
main/src/main/res/drawable/icon_xuanzhong.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
107
main/src/main/res/layout/activity_language_sett.xml
Normal file
107
main/src/main/res/layout/activity_language_sett.xml
Normal file
@@ -0,0 +1,107 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="24dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/live_photo_btn_cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="14dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:padding="2dp"
|
||||
android:text="@string/live_photo_btn_cancel"
|
||||
android:textColor="#666666"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="11dp"
|
||||
android:text="@string/live_language_setting"
|
||||
android:textColor="#333333"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:background="@drawable/background_language"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:text="@string/complete"
|
||||
android:textColor="@color/white" />
|
||||
</FrameLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0.5dp"
|
||||
android:background="#E9EDF0" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/traditional_chinese"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="16dp"
|
||||
android:text="@string/traditional_chinese"
|
||||
android:textColor="#333333" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/img_traditional_chinese"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:background="@drawable/icon_xuanzhong" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0.5dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:background="#E9EDF0" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/english"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="16dp"
|
||||
android:text="English"
|
||||
android:textColor="#333333" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/img_english"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:background="@drawable/icon_xuanzhong" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@@ -155,6 +155,37 @@
|
||||
android:src="@mipmap/icon_arrow_right" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/language_setting"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:visibility="gone"
|
||||
android:paddingTop="15dp"
|
||||
android:paddingBottom="25dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="25dp"
|
||||
android:text="@string/live_language_setting"
|
||||
android:textColor="#1E1F20"
|
||||
android:textSize="16sp" />
|
||||
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="17dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginEnd="26.33dp"
|
||||
android:src="@mipmap/icon_arrow_right" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
||||
Reference in New Issue
Block a user