Skip to content

Commit

Permalink
[skp] opt: oobe & opt: DualRowSignal show & fix: change languages
Browse files Browse the repository at this point in the history
  • Loading branch information
lingqiqi5211 committed Jan 27, 2025
1 parent 4fa54e9 commit 9f57647
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@
*/
package com.sevtinge.hyperceiler.module.hook.systemui.statusbar.model

import android.telephony.*
import com.sevtinge.hyperceiler.module.base.*
import com.sevtinge.hyperceiler.module.hook.systemui.*
import android.telephony.SubscriptionManager
import com.sevtinge.hyperceiler.module.base.BaseHook
import com.sevtinge.hyperceiler.module.hook.systemui.Dependency
import com.sevtinge.hyperceiler.module.hook.systemui.base.statusbar.icon.MobileClass.miuiCellularIconVM
import com.sevtinge.hyperceiler.module.hook.systemui.base.statusbar.icon.MobilePrefs.card1
import com.sevtinge.hyperceiler.module.hook.systemui.base.statusbar.icon.MobilePrefs.card2
import com.sevtinge.hyperceiler.module.hook.systemui.base.statusbar.icon.MobilePrefs.hideIndicator
import com.sevtinge.hyperceiler.module.hook.systemui.base.statusbar.icon.MobilePrefs.hideRoaming
import com.sevtinge.hyperceiler.module.hook.systemui.base.statusbar.icon.MobilePrefs.isEnableDouble
import com.sevtinge.hyperceiler.utils.*
import com.sevtinge.hyperceiler.utils.MethodHookParam
import com.sevtinge.hyperceiler.utils.StateFlowHelper.newReadonlyStateFlow
import com.sevtinge.hyperceiler.utils.StateFlowHelper.setStateFlowValue
import java.util.function.*
import com.sevtinge.hyperceiler.utils.callMethod
import com.sevtinge.hyperceiler.utils.getObjectField
import com.sevtinge.hyperceiler.utils.getObjectFieldAs
import com.sevtinge.hyperceiler.utils.setObjectField
import java.util.function.Consumer

class MobilePublicHookV : BaseHook() {
override fun init() {
Expand All @@ -53,6 +57,7 @@ class MobilePublicHookV : BaseHook() {
if (isEnableDouble) {
val isVisible = newReadonlyStateFlow(false)
cellularIcon.setObjectField("isVisible", isVisible)
if (!hideRoaming) cellularIcon.setObjectField("smallRoamVisible", newReadonlyStateFlow(false))

val activeSubId = Dependency.mMiuiLegacyDependency
?.getObjectField("mOperatorCustomizedPolicy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import android.content.res.Configuration;
import android.content.res.Resources;

import com.sevtinge.hyperceiler.utils.log.AndroidLogUtils;

import java.util.Locale;

public class LanguageHelper {
public static final String[] appLanguages = {
"en", "zh_CN", "zh_TW", "zh_HK", "ja_JP", "pl_PL", "ru_RU", "ar_SA", "es_ES", "pt_BR", "in_ID", "tr_TR", "vi_VN", "it_IT", "zh_ME"
"en", "zh_CN", "zh_TW", "zh_HK", "ja_JP", "pl_PL", "ru_RU", "ar_SA", "es_ES", "pt_BR", "id_ID", "tr_TR", "vi_VN", "it_IT", "zh_ME"
};

public static void setLanguage(Context context, String language) {
Expand Down Expand Up @@ -99,7 +101,7 @@ public static void setIndexLanguage(Activity activity, int index, boolean recrea
if (recreate) activity.recreate();
}
case 10 -> {
LanguageHelper.setLanguage(activity.getBaseContext(), "in", "ID");
LanguageHelper.setLanguage(activity.getBaseContext(), "id", "ID");
if (recreate) activity.recreate();
}
case 11 -> {
Expand All @@ -123,11 +125,15 @@ public static void setIndexLanguage(Activity activity, int index, boolean recrea

public static String getLanguage(Context context) {
Resources resources = context.getResources();
String country = resources.getConfiguration().getLocales().get(0).getCountry();
Locale locale = resources.getConfiguration().getLocales().isEmpty() ? null : resources.getConfiguration().getLocales().get(0);
if (locale == null) {
return "";
}
String country = locale.getCountry();
if (country.isEmpty()) {
return resources.getConfiguration().getLocales().get(0).getLanguage();
return locale.getLanguage();
}
return resources.getConfiguration().getLocales().get(0).getLanguage() + "_" + country;
return locale.getLanguage() + "_" + country;
}

public static String newLanguage(String language, String country) {
Expand All @@ -138,23 +144,30 @@ public static String newLanguage(String language, String country) {
}

public static int resultIndex(String[] languages, String value) {

String targetLanguage = value.split("_")[0];
String[] parts = value.split("_");
String targetLanguage = parts[0];
String countryLanguage = parts.length > 1 ? parts[1] : "";

for (int i = 0; i < languages.length; i++) {
String currentLang = languages[i];
if (currentLang == null) continue;

if (currentLang.equals(value)) {
AndroidLogUtils.logI("Language", "Match found: " + currentLang + " at index " + i);
return i;
}

String currentLanguage = currentLang.split("_")[0];
if (targetLanguage.equals(currentLanguage)) {
return i; // Language匹配成功
String[] currentParts = currentLang.split("_");
String currentLanguage = currentParts[0];
String currentCountry = currentParts.length > 1 ? currentParts[1] : "";

if (targetLanguage.equals(currentLanguage) && countryLanguage.equals(currentCountry)) {
AndroidLogUtils.logI("Language", "Match found: " + currentLang + " at index " + i);
return i;
}
}
return -1;
AndroidLogUtils.logE("Language", "No match found for: " + value);
return 0; // 遇到错误就切回英语,防止崩溃
}

public static boolean isUpperCase(String string) {
Expand Down
1 change: 0 additions & 1 deletion provision/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
Expand All @@ -26,6 +28,7 @@
import com.sevtinge.provision.utils.PageIntercepHelper;
import com.sevtinge.provision.utils.ProvisionStateHolder;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;

public class ProvisionActivity extends ProvisionBaseActivity {
Expand All @@ -39,9 +42,7 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!isDeviceIsProvisioned()) {
PageIntercepHelper.getInstance().register(this);
PageIntercepHelper.getInstance().setCallback((requestCode, resultCode, data) -> {
ProvisionActivity.this.onActivityResult(requestCode, resultCode, data);
});
PageIntercepHelper.getInstance().setCallback(ProvisionActivity.this::onActivityResult);

mStateMachine = new StateMachine(this);
mStateMachine.start(savedInstanceState == null ||
Expand Down Expand Up @@ -95,7 +96,7 @@ public void finishSetup() {
}

@Override
public void onSaveInstanceState(Bundle bundle) {
public void onSaveInstanceState(@NonNull Bundle bundle) {
super.onSaveInstanceState(bundle);
bundle.putBoolean("com.android.provision:state_enter_currentstate", mStateMachine.mCurrentState instanceof StartupState);
}
Expand Down Expand Up @@ -150,7 +151,7 @@ public boolean hasTitle() {

@Override
public void onBackPressed() {

super.onBackPressed();
}

public static class StartupState extends State implements IKeyEvent, IOnFocusListener {
Expand Down Expand Up @@ -468,7 +469,7 @@ private void restoreState() {
state = null;
try {
state = prefState.getString("com.android.provision.STATE_" + i, null);
} catch (Exception unused) {}
} catch (Exception _) {}
if (state != null) {
if (i != 0) {
mStateStack.add(mCurrentState);
Expand Down Expand Up @@ -510,7 +511,7 @@ public static class State {
public String mClassName;
public Class<?> mTargetClass;

protected Handler mHandler = new Handler();
protected Handler mHandler = new Handler(Looper.getMainLooper());

public boolean canBackTo() {
return true;
Expand All @@ -524,10 +525,14 @@ public void onLeave() {}

public static State create(String name) {
try {
return (State) Class.forName(PREFIX + name).newInstance();
return (State) Class.forName(PREFIX + name).getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
Log.e(TAG, String.valueOf(e));
return null;
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion provision/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<item name="android:listDivider">@null</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="preferenceTheme">@style/ThemeOverlay.Preference.DayNight</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>

0 comments on commit 9f57647

Please sign in to comment.