From 62acc17e42114ad165ee548a063be7350653c676 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 2 Feb 2019 05:06:13 -0500 Subject: [PATCH] Support API 16 (Android 4.1) Because why not --- .../topjohnwu/magisk/utils/LocaleManager.java | 12 ++- .../com/topjohnwu/magisk/utils/Utils.java | 2 +- .../topjohnwu/magisk/SuRequestActivity.java | 10 ++- .../magisk/adapters/StringListAdapter.java | 2 +- .../magisk/fragments/SettingsFragment.java | 4 + app/src/full/res/layout/activity_request.xml | 77 ++++++++++--------- app/src/full/res/layout/fragment_magisk.xml | 25 +++--- app/src/full/res/layout/info_item_row.xml | 39 +++++----- app/src/full/res/layout/list_item_policy.xml | 13 ++-- app/src/full/res/layout/list_item_repo.xml | 17 ++-- .../full/res/layout/list_item_sulog_group.xml | 1 + app/src/full/res/layout/section.xml | 9 ++- app/src/full/res/layout/update_card.xml | 7 +- build.gradle | 2 +- scripts/flash_script.sh | 2 +- 15 files changed, 125 insertions(+), 97 deletions(-) diff --git a/app-core/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java b/app-core/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java index 3b0d4a3b64d7..39535fff73f1 100644 --- a/app-core/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java +++ b/app-core/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java @@ -100,9 +100,13 @@ public static void setLocale(ContextWrapper wrapper) { } public static Context getLocaleContext(Context context, Locale locale) { - Configuration config = new Configuration(context.getResources().getConfiguration()); - config.setLocale(locale); - return context.createConfigurationContext(config); + if (Build.VERSION.SDK_INT >= 17) { + Configuration config = new Configuration(context.getResources().getConfiguration()); + config.setLocale(locale); + return context.createConfigurationContext(config); + } else { + return context; + } } public static Context getLocaleContext(Locale locale) { @@ -114,6 +118,8 @@ public static String getString(Locale locale, @StringRes int id) { } public static void loadAvailableLocales(@StringRes int compareId) { + if (Build.VERSION.SDK_INT < 17) + return; Shell.EXECUTOR.execute(() -> { locales = new ArrayList<>(); HashSet set = new HashSet<>(); diff --git a/app-core/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app-core/src/main/java/com/topjohnwu/magisk/utils/Utils.java index d2cb23f548b4..23a47f641483 100644 --- a/app-core/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app-core/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -77,7 +77,7 @@ public static String fmt(String fmt, Object... args) { public static String getAppLabel(ApplicationInfo info, PackageManager pm) { try { - if (info.labelRes > 0) { + if (info.labelRes > 0 && Build.VERSION.SDK_INT >= 17) { Resources res = pm.getResourcesForApplication(info); Configuration config = new Configuration(); config.setLocale(LocaleManager.locale); diff --git a/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java b/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java index 6fad4e562e09..4dec0471ffdf 100644 --- a/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java @@ -4,6 +4,7 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.hardware.fingerprint.FingerprintManager; +import android.os.Build; import android.os.Bundle; import android.os.CountDownTimer; import android.text.TextUtils; @@ -127,8 +128,13 @@ protected void onResponse() throws IOException { appIcon.setImageDrawable(policy.info.loadIcon(pm)); appNameView.setText(policy.appName); packageNameView.setText(policy.packageName); - warning.setCompoundDrawablesRelativeWithIntrinsicBounds( - AppCompatResources.getDrawable(this, R.drawable.ic_warning), null, null, null); + if (Build.VERSION.SDK_INT >= 17) { + warning.setCompoundDrawablesRelativeWithIntrinsicBounds( + AppCompatResources.getDrawable(this, R.drawable.ic_warning), null, null, null); + } else { + warning.setCompoundDrawablesWithIntrinsicBounds( + AppCompatResources.getDrawable(this, R.drawable.ic_warning), null, null, null); + } ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.allow_timeout, android.R.layout.simple_spinner_item); diff --git a/app/src/full/java/com/topjohnwu/magisk/adapters/StringListAdapter.java b/app/src/full/java/com/topjohnwu/magisk/adapters/StringListAdapter.java index 0aacad2e83ae..b2cd680e0edd 100644 --- a/app/src/full/java/com/topjohnwu/magisk/adapters/StringListAdapter.java +++ b/app/src/full/java/com/topjohnwu/magisk/adapters/StringListAdapter.java @@ -73,7 +73,7 @@ public void onAttachedToRecyclerView(@NonNull RecyclerView rv) { ((Activity) rv.getContext()).getWindowManager() .getDefaultDisplay().getMetrics(displayMetrics); screenWidth = displayMetrics.widthPixels; - padding = rv.getPaddingStart() + rv.getPaddingEnd(); + padding = rv.getPaddingLeft() + rv.getPaddingRight(); this.rv = rv; } diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java index c709c8764870..fe502e414db8 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java @@ -111,6 +111,10 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setSummary(); + // Remove language setting when API < 17 + if (Build.VERSION.SDK_INT < 17) + generalCatagory.removePreference(findPreference(Config.Key.LOCALE)); + // Disable dangerous settings in secondary user if (Const.USER_ID > 0) { suCategory.removePreference(multiuserConfig); diff --git a/app/src/full/res/layout/activity_request.xml b/app/src/full/res/layout/activity_request.xml index d8a9bd9e26f4..f25d25905d5b 100644 --- a/app/src/full/res/layout/activity_request.xml +++ b/app/src/full/res/layout/activity_request.xml @@ -1,110 +1,111 @@ - + tools:context=".SuRequestActivity"> + android:layout_marginBottom="5dp" + android:gravity="center_horizontal" + android:text="@string/su_request_title" + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:paddingEnd="10dp"> + android:layout_marginLeft="5dp" + android:layout_marginEnd="10dp" + android:layout_marginRight="10dp" + android:layout_weight="0" /> + android:gravity="center_vertical" + android:orientation="vertical"> + android:textColor="?android:textColorPrimary" /> + android:minWidth="200dp" + android:textColor="?android:textColorSecondary" /> + android:drawablePadding="10dp" + android:text="@string/su_warning" + android:textColor="?android:textColorSecondary" />