mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-18 17:15:40 -04:00
Changes
- [Custom controls] Fix special buttons index. - [Language changer] change behavior
This commit is contained in:
parent
dd6d080b4e
commit
9e71ff6aaa
@ -1,7 +1,9 @@
|
|||||||
package net.kdt.pojavlaunch;
|
package net.kdt.pojavlaunch;
|
||||||
|
|
||||||
import android.support.v7.app.*;
|
import android.content.*;
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
|
import android.support.v7.app.*;
|
||||||
|
import net.kdt.pojavlaunch.utils.*;
|
||||||
|
|
||||||
public class BaseActivity extends AppCompatActivity
|
public class BaseActivity extends AppCompatActivity
|
||||||
{
|
{
|
||||||
@ -11,4 +13,9 @@ public class BaseActivity extends AppCompatActivity
|
|||||||
Tools.setFullscreen(this);
|
Tools.setFullscreen(this);
|
||||||
Tools.updateWindowSize(this);
|
Tools.updateWindowSize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void attachBaseContext(Context base) {
|
||||||
|
super.attachBaseContext(LocaleUtils.setLocale(base));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ public class CustomControlsActivity extends BaseActivity
|
|||||||
|
|
||||||
selectedName = new File(path).getName();
|
selectedName = new File(path).getName();
|
||||||
// Remove `.json`
|
// Remove `.json`
|
||||||
selectedName = selectedName.substring(0, selectedName.length() - 5);
|
selectedName = selectedName.substring(0, selectedName.length() - ControlData.getSpecialButtons().length);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Tools.showError(CustomControlsActivity.this, e);
|
Tools.showError(CustomControlsActivity.this, e);
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,18 @@
|
|||||||
package net.kdt.pojavlaunch;
|
package net.kdt.pojavlaunch;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.*;
|
||||||
import android.os.*;
|
|
||||||
import android.content.pm.PackageManager.*;
|
|
||||||
import android.content.pm.*;
|
|
||||||
import android.support.v7.preference.*;
|
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
|
import android.content.pm.*;
|
||||||
|
import android.content.res.*;
|
||||||
|
import android.os.*;
|
||||||
import android.support.v4.app.*;
|
import android.support.v4.app.*;
|
||||||
|
import android.support.v7.preference.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.time.*;
|
|
||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import net.kdt.pojavlaunch.prefs.*;
|
import net.kdt.pojavlaunch.prefs.*;
|
||||||
import net.kdt.pojavlaunch.customcontrols.*;
|
import net.kdt.pojavlaunch.utils.*;
|
||||||
|
|
||||||
public class PojavApplication extends Application
|
public class PojavApplication extends Application
|
||||||
{
|
{
|
||||||
@ -67,9 +64,6 @@ public class PojavApplication extends Application
|
|||||||
case "x86": Tools.currentArch = "x86/i*86"; break;
|
case "x86": Tools.currentArch = "x86/i*86"; break;
|
||||||
case "x86_64": Tools.currentArch = "x86_64/amd64"; break;
|
case "x86_64": Tools.currentArch = "x86_64/amd64"; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
LauncherPreferences.DEFAULT_PREF = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
LauncherPreferences.loadPreferences();
|
|
||||||
|
|
||||||
FontChanger.initFonts(this);
|
FontChanger.initFonts(this);
|
||||||
} catch (Throwable th) {
|
} catch (Throwable th) {
|
||||||
@ -78,4 +72,15 @@ public class PojavApplication extends Application
|
|||||||
startActivity(ferrorIntent);
|
startActivity(ferrorIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void attachBaseContext(Context base) {
|
||||||
|
super.attachBaseContext(LocaleUtils.setLocale(base));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
|
super.onConfigurationChanged(newConfig);
|
||||||
|
LocaleUtils.setLocale(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,22 +45,15 @@ public class PojavLoginActivity extends BaseActivity
|
|||||||
|
|
||||||
private SharedPreferences firstLaunchPrefs;
|
private SharedPreferences firstLaunchPrefs;
|
||||||
|
|
||||||
private Locale mDefaultLocale;
|
private boolean isSkipInit = false;
|
||||||
|
|
||||||
// private final String PREF_IS_DONOTSHOWAGAIN_WARN = "isWarnDoNotShowAgain";
|
// private final String PREF_IS_DONOTSHOWAGAIN_WARN = "isWarnDoNotShowAgain";
|
||||||
public static final String PREF_IS_INSTALLED_JAVARUNTIME = "isJavaRuntimeInstalled";
|
public static final String PREF_IS_INSTALLED_JAVARUNTIME = "isJavaRuntimeInstalled";
|
||||||
|
|
||||||
private boolean isInitCalled = false;
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState){
|
protected void onCreate(Bundle savedInstanceState){
|
||||||
super.onCreate(savedInstanceState); // false);
|
super.onCreate(savedInstanceState); // false);
|
||||||
|
|
||||||
mDefaultLocale = Locale.getDefault();
|
|
||||||
|
|
||||||
if (!LauncherPreferences.PREF_LANGUAGE.equals("default")) {
|
|
||||||
setLocale(new Locale(LauncherPreferences.PREF_LANGUAGE));
|
|
||||||
}
|
|
||||||
|
|
||||||
Tools.updateWindowSize(this);
|
Tools.updateWindowSize(this);
|
||||||
|
|
||||||
ControlData.pixelOf2dp = (int) Tools.dpToPx(this, 2);
|
ControlData.pixelOf2dp = (int) Tools.dpToPx(this, 2);
|
||||||
@ -74,18 +67,13 @@ public class PojavLoginActivity extends BaseActivity
|
|||||||
specialButtons[3].name = getString(R.string.control_secondary);
|
specialButtons[3].name = getString(R.string.control_secondary);
|
||||||
specialButtons[4].name = getString(R.string.control_mouse);
|
specialButtons[4].name = getString(R.string.control_mouse);
|
||||||
|
|
||||||
if (!isInitCalled) {
|
|
||||||
init();
|
|
||||||
isInitCalled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
firstLaunchPrefs = getSharedPreferences("pojav_extract", MODE_PRIVATE);
|
firstLaunchPrefs = getSharedPreferences("pojav_extract", MODE_PRIVATE);
|
||||||
new InitTask().execute();
|
new InitTask().execute(isSkipInit);
|
||||||
|
|
||||||
|
isSkipInit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class InitTask extends AsyncTask<Void, String, Integer>{
|
private class InitTask extends AsyncTask<Boolean, String, Integer>{
|
||||||
private AlertDialog startAle;
|
private AlertDialog startAle;
|
||||||
private ProgressBar progress;
|
private ProgressBar progress;
|
||||||
|
|
||||||
@ -120,8 +108,12 @@ public class PojavLoginActivity extends BaseActivity
|
|||||||
private int revokeCount = -1;
|
private int revokeCount = -1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Integer doInBackground(Void[] p1)
|
protected Integer doInBackground(Boolean[] params) {
|
||||||
{
|
// If trigger a quick restart
|
||||||
|
if (params[0] == true) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
@ -209,12 +201,12 @@ public class PojavLoginActivity extends BaseActivity
|
|||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
String defaultLang = mDefaultLocale.getDisplayName();
|
String defaultLang = LocaleUtils.DEFAULT_LOCALE.getDisplayName();
|
||||||
SpannableString defaultLangChar = new SpannableString(defaultLang);
|
SpannableString defaultLangChar = new SpannableString(defaultLang);
|
||||||
defaultLangChar.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, defaultLang.length(), 0);
|
defaultLangChar.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, defaultLang.length(), 0);
|
||||||
|
|
||||||
final ArrayAdapter<DisplayableLocale> langAdapter = new ArrayAdapter<DisplayableLocale>(this, android.R.layout.simple_spinner_item);
|
final ArrayAdapter<DisplayableLocale> langAdapter = new ArrayAdapter<DisplayableLocale>(this, android.R.layout.simple_spinner_item);
|
||||||
langAdapter.add(new DisplayableLocale(mDefaultLocale, defaultLangChar));
|
langAdapter.add(new DisplayableLocale(LocaleUtils.DEFAULT_LOCALE, defaultLangChar));
|
||||||
langAdapter.add(new DisplayableLocale(Locale.ENGLISH));
|
langAdapter.add(new DisplayableLocale(Locale.ENGLISH));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -248,7 +240,13 @@ public class PojavLoginActivity extends BaseActivity
|
|||||||
} else {
|
} else {
|
||||||
locale = langAdapter.getItem(position).mLocale;
|
locale = langAdapter.getItem(position).mLocale;
|
||||||
}
|
}
|
||||||
setLocale(locale);
|
|
||||||
|
LauncherPreferences.PREF_LANGUAGE = locale.getLanguage();
|
||||||
|
LauncherPreferences.DEFAULT_PREF.edit().putString("language", LauncherPreferences.PREF_LANGUAGE).commit();
|
||||||
|
|
||||||
|
// Restart to apply language change
|
||||||
|
finish();
|
||||||
|
startActivity(getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -288,16 +286,6 @@ public class PojavLoginActivity extends BaseActivity
|
|||||||
// Clear current profile
|
// Clear current profile
|
||||||
PojavProfile.setCurrentProfile(this, null);
|
PojavProfile.setCurrentProfile(this, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLocale(Locale locale) {
|
|
||||||
LauncherPreferences.PREF_LANGUAGE = locale.getLanguage();
|
|
||||||
LauncherPreferences.DEFAULT_PREF.edit().putString("language", LauncherPreferences.PREF_LANGUAGE).commit();
|
|
||||||
Locale.setDefault(locale);
|
|
||||||
Configuration config = getResources().getConfiguration();
|
|
||||||
config.setLocale(locale);
|
|
||||||
// TODO replace deprecated
|
|
||||||
getResources().updateConfiguration(config, getResources().getDisplayMetrics());
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isJavaRuntimeInstalled() {
|
private boolean isJavaRuntimeInstalled() {
|
||||||
return firstLaunchPrefs.getBoolean(PREF_IS_INSTALLED_JAVARUNTIME, false);
|
return firstLaunchPrefs.getBoolean(PREF_IS_INSTALLED_JAVARUNTIME, false);
|
||||||
|
@ -43,9 +43,10 @@ public class ControlData implements Cloneable
|
|||||||
new ControlData("Keyboard", SPECIALBTN_KEYBOARD, "${margin} * 3 + ${width} * 2", "${margin}", false),
|
new ControlData("Keyboard", SPECIALBTN_KEYBOARD, "${margin} * 3 + ${width} * 2", "${margin}", false),
|
||||||
new ControlData("GUI", SPECIALBTN_TOGGLECTRL, "${margin}", "${bottom} - ${margin}"),
|
new ControlData("GUI", SPECIALBTN_TOGGLECTRL, "${margin}", "${bottom} - ${margin}"),
|
||||||
new ControlData("PRI", SPECIALBTN_MOUSEPRI, "${margin}", "${screen_height} - ${margin} * 3 - ${height} * 3"),
|
new ControlData("PRI", SPECIALBTN_MOUSEPRI, "${margin}", "${screen_height} - ${margin} * 3 - ${height} * 3"),
|
||||||
new ControlData("MID", SPECIALBTN_MOUSEMID, "${margin}", "${margin}"),
|
|
||||||
new ControlData("SEC", SPECIALBTN_MOUSESEC, "${margin} * 3 + ${width} * 2", "${screen_height} - ${margin} * 3 - ${height} * 3"),
|
new ControlData("SEC", SPECIALBTN_MOUSESEC, "${margin} * 3 + ${width} * 2", "${screen_height} - ${margin} * 3 - ${height} * 3"),
|
||||||
new ControlData("Mouse", SPECIALBTN_VIRTUALMOUSE, "${right}", "${margin}", false)
|
new ControlData("Mouse", SPECIALBTN_VIRTUALMOUSE, "${right}", "${margin}", false),
|
||||||
|
|
||||||
|
new ControlData("MID", SPECIALBTN_MOUSEMID, "${margin}", "${margin}")
|
||||||
};
|
};
|
||||||
SPECIAL_BUTTONS = specialButtons;
|
SPECIAL_BUTTONS = specialButtons;
|
||||||
}
|
}
|
||||||
|
31
app/src/main/java/net/kdt/pojavlaunch/utils/LocaleUtils.java
Normal file
31
app/src/main/java/net/kdt/pojavlaunch/utils/LocaleUtils.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package net.kdt.pojavlaunch.utils;
|
||||||
|
|
||||||
|
import android.content.*;
|
||||||
|
import android.content.res.*;
|
||||||
|
import android.support.v7.preference.*;
|
||||||
|
import java.util.*;
|
||||||
|
import net.kdt.pojavlaunch.prefs.*;
|
||||||
|
|
||||||
|
public class LocaleUtils {
|
||||||
|
public static final Locale DEFAULT_LOCALE;
|
||||||
|
|
||||||
|
static {
|
||||||
|
DEFAULT_LOCALE = Locale.getDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Context setLocale(Context context) {
|
||||||
|
if (LauncherPreferences.DEFAULT_PREF == null) {
|
||||||
|
LauncherPreferences.DEFAULT_PREF = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
LauncherPreferences.loadPreferences();
|
||||||
|
}
|
||||||
|
|
||||||
|
Locale locale = new Locale(LauncherPreferences.PREF_LANGUAGE);
|
||||||
|
Locale.setDefault(locale);
|
||||||
|
|
||||||
|
Resources res = context.getResources();
|
||||||
|
Configuration config = new Configuration(res.getConfiguration());
|
||||||
|
config.setLocale(locale);
|
||||||
|
context = context.createConfigurationContext(config);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user