Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加始终中文语言选项,新版10.5.53不工作问题修复 #422

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.widget.ProgressBar;
import android.widget.Toast;
import pansong291.xposed.quickenergy.R;
import pansong291.xposed.quickenergy.util.LanguageUtil;

public class HtmlViewerActivity extends Activity {
MyWebView mWebView;
Expand All @@ -22,6 +23,7 @@ public class HtmlViewerActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LanguageUtil.setLocale(this);
setContentView(R.layout.activity_html_viewer);

mWebView = findViewById(R.id.mwv_webview);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import pansong291.xposed.quickenergy.R;
import pansong291.xposed.quickenergy.data.RuntimeInfo;
import pansong291.xposed.quickenergy.entity.FriendWatch;
import pansong291.xposed.quickenergy.util.Config;
import pansong291.xposed.quickenergy.util.FileUtils;
import pansong291.xposed.quickenergy.util.LanguageUtil;
import pansong291.xposed.quickenergy.util.PermissionUtil;
import pansong291.xposed.quickenergy.util.Statistics;

import java.util.ArrayList;
import java.util.Locale;

public class MainActivity extends Activity {
TextView tvStatistics;
Expand Down Expand Up @@ -63,6 +67,7 @@ private static boolean isExpModuleActive(Context context) {
}
return isExp;
}

/**
* 判断当前应用是否是debug状态
*/
Expand All @@ -78,6 +83,7 @@ public static boolean isApkInDebug(Context context) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LanguageUtil.setLocale(this);
setContentView(R.layout.activity_main);
RuntimeInfo.process = "app";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
Expand All @@ -12,6 +13,9 @@
import android.widget.Switch;
import android.widget.TabHost;
import android.widget.Toast;

import java.util.Locale;

import pansong291.xposed.quickenergy.R;
import pansong291.xposed.quickenergy.entity.*;
import pansong291.xposed.quickenergy.util.*;
Expand All @@ -30,7 +34,7 @@ public class SettingsActivity extends Activity {
private Animation slideRightIn;
private Animation slideRightOut;

Switch sw_immediateEffect, sw_recordLog, sw_showToast, sw_stayAwake, sw_timeoutRestart, sw_startAt7,
Switch sw_immediateEffect, sw_recordLog, sw_showToast, sw_stayAwake, sw_timeoutRestart, sw_startAt7, sw_language_simplified_chinese,
sw_collectWateringBubble, sw_collectProp, sw_collectEnergy, sw_helpFriendCollect, sw_receiveForestTaskAward,
sw_cooperateWater, sw_energyRain, sw_enableFarm, sw_rewardFriend, sw_sendBackAnimal,
sw_receiveFarmToolReward, sw_useNewEggTool, sw_harvestProduce, sw_donation, sw_answerQuestion,
Expand All @@ -47,6 +51,7 @@ public class SettingsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LanguageUtil.setLocale(this);
setContentView(R.layout.activity_settings);
setTitle(R.string.settings);

Expand All @@ -61,8 +66,10 @@ protected void onCreate(Bundle savedInstanceState) {
BeachIdMap.shouldReload = true;

initSwitch();

}


@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
Expand Down Expand Up @@ -98,7 +105,7 @@ private void initFlipper() {
gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
float velocityY) {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
int lastView = tabHost.getCurrentTab();
Expand Down Expand Up @@ -159,6 +166,7 @@ private void initSwitch() {
sw_startAt7 = findViewById(R.id.sw_startAt7);
sw_enableOnGoing = findViewById(R.id.sw_enableOnGoing);
sw_backupRuntime = findViewById(R.id.sw_backupRuntime);
sw_language_simplified_chinese = findViewById(R.id.sw_languageSimplifiedChinese);

sw_collectEnergy = findViewById(R.id.sw_collectEnergy);
sw_collectWateringBubble = findViewById(R.id.sw_collectWateringBubble);
Expand Down Expand Up @@ -233,6 +241,7 @@ protected void onResume() {
sw_startAt7.setChecked(Config.startAt7());
sw_enableOnGoing.setChecked(Config.enableOnGoing());
sw_backupRuntime.setChecked(Config.backupRuntime());
sw_language_simplified_chinese.setChecked(Config.languageSimplifiedChinese());

sw_collectEnergy.setChecked(Config.collectEnergy());
sw_collectWateringBubble.setChecked(Config.collectWateringBubble());
Expand Down Expand Up @@ -333,6 +342,12 @@ public void onClick(View v) {
Config.setBackupRuntime(sw.isChecked());
break;

case R.id.sw_languageSimplifiedChinese:
Config.setLanguageSimplifiedChinese(sw.isChecked());
// 提示需要重启 language_simplified_chinese_need_restart
Toast.makeText(this, R.string.language_simplified_chinese_need_restart, Toast.LENGTH_SHORT).show();
break;

case R.id.sw_collectEnergy:
Config.setCollectEnergy(sw.isChecked());
break;
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/pansong291/xposed/quickenergy/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public CharSequence nickName() {
public static final String jn_startAt7 = "startAt7";
public static final String jn_enableOnGoing = "enableOnGoing";
public static final String jn_backupRuntime = "backupRuntime";
public static final String jn_languageSimplifiedChinese = "languageSimplifiedChinese";

/* forest */
public static final String jn_collectEnergy = "collectEnergy";
Expand Down Expand Up @@ -163,6 +164,8 @@ public CharSequence nickName() {
private boolean startAt7;
private boolean enableOnGoing;
private boolean backupRuntime;
private boolean languageSimplifiedChinese;


/* forest */
private boolean collectEnergy;
Expand Down Expand Up @@ -395,10 +398,19 @@ public static void setBackupRuntime(boolean b) {
hasChanged = true;
}

public static void setLanguageSimplifiedChinese(boolean b) {
getConfig().languageSimplifiedChinese = b;
hasChanged = true;
}

public static boolean backupRuntime() {
return getConfig().backupRuntime;
}

public static boolean languageSimplifiedChinese() {
return getConfig().languageSimplifiedChinese;
}

/* forest */
public static void setCollectEnergy(boolean b) {
getConfig().collectEnergy = b;
Expand Down Expand Up @@ -1324,6 +1336,7 @@ public static Config defInit() {
c.startAt7 = false;
c.enableOnGoing = false;
c.backupRuntime = false;
c.languageSimplifiedChinese = false;

c.collectEnergy = false;
c.collectWateringBubble = true;
Expand Down Expand Up @@ -1507,6 +1520,9 @@ public static Config json2Config(String json) {
config.backupRuntime = jo.optBoolean(jn_backupRuntime, false);
//Log.i(TAG, jn_backupRuntime + ":" + config.backupRuntime);

config.languageSimplifiedChinese = jo.optBoolean(jn_languageSimplifiedChinese, false);
//Log.i(TAG, jn_languageSimplifiedChinese + ":" + config.languageSimplifiedChinese);

/* forest */
config.collectEnergy = jo.optBoolean(jn_collectEnergy, false);
//Log.i(TAG, jn_collectEnergy + ":" + config.collectEnergy);
Expand Down Expand Up @@ -1998,6 +2014,8 @@ public static String config2Json(Config config) {

jo.put(jn_backupRuntime, config.backupRuntime);

jo.put(jn_languageSimplifiedChinese, config.languageSimplifiedChinese);

/* forest */
jo.put(jn_collectEnergy, config.collectEnergy);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.os.Environment;
import pansong291.xposed.quickenergy.AntForestToast;
import pansong291.xposed.quickenergy.data.RuntimeInfo;
import pansong291.xposed.quickenergy.hook.ClassMember;

import java.io.Closeable;
import java.io.File;
Expand Down Expand Up @@ -49,7 +50,8 @@ private static void copyFile(File srcDir, File dstDir, String filename) {
@SuppressWarnings("deprecation")
public static File getMainDirectoryFile() {
if (mainDirectory == null) {
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
String storageDirStr = Environment.getExternalStorageDirectory() + File.separator + "Android" + File.separator + "media" + File.separator + ClassMember.PACKAGE_NAME;
File storageDir = new File(storageDirStr);
if (!storageDir.exists()) {
storageDir.mkdirs();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pansong291.xposed.quickenergy.util;

import android.content.res.Configuration;

import java.util.Locale;

import android.content.Context;


public class LanguageUtil {
public static void setLocale(Context context) {
if (Config.languageSimplifiedChinese()) {
// 忽略系统语言,强制使用简体中文
Locale locale = new Locale("zh", "CN"); // 简体中文的区域代码
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@
android:onClick="onClick"
android:minHeight="50dp"
android:id="@+id/sw_backupRuntime" />

<Switch
android:paddingStart="@dimen/setting_item_padding"
android:paddingEnd="@dimen/setting_item_padding"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/language_simplified_chinese"
android:onClick="onClick"
android:minHeight="50dp"
android:id="@+id/sw_languageSimplifiedChinese" />
</LinearLayout>
<!--森林设置-->
<LinearLayout
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
<string name="ins_blue_bean_exchange">安心豆兑换时光加速器</string>
<string name="enable_on_going">开启状态栏禁删</string>
<string name="backup_runtime_log">备份runtime日志</string>
<string name="language_simplified_chinese">界面始终使用中文</string>
<string name="language_simplified_chinese_need_restart">重启当前app生效</string>
<string name="ant_orchard">施肥</string>
<string name="receive_orchard_task_award">收取施肥任务奖励</string>
<string name="orchard_spread_manure_count">施肥次数</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
<string name="ins_blue_bean_exchange">Ins blue bean exchange</string>
<string name="enable_on_going">Enable on going</string>
<string name="backup_runtime_log">Backup runtime log</string>
<string name="language_simplified_chinese">Chinese Language</string>
<string name="language_simplified_chinese_need_restart">Need to restart the app to take effect</string>
<string name="ant_orchard">Ant orchard</string>
<string name="receive_orchard_task_award">Receive orchard task award</string>
<string name="orchard_spread_manure_count">Orchard spread manure count</string>
Expand Down