Backwards compatible to SDK 17

This commit is contained in:
topjohnwu 2018-12-28 05:15:59 +08:00
parent bb2df02dff
commit 496b22026f
37 changed files with 115 additions and 72 deletions

View File

@ -9,6 +9,7 @@ android {
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion 17
applicationId "com.topjohnwu.magisk"
targetSdkVersion rootProject.ext.compileSdkVersion
vectorDrawables.useSupportLibrary = true
@ -41,7 +42,6 @@ android {
productFlavors {
full {
minSdkVersion 21
versionName configProps['appVersion']
versionCode configProps['appVersionCode'] as Integer
javaCompileOptions {
@ -51,7 +51,6 @@ android {
}
}
stub {
minSdkVersion 17
versionCode 1
versionName "stub"
}

View File

@ -32,15 +32,15 @@
</activity>
<activity
android:name="a.d"
android:theme="@style/AppTheme.StatusBar" />
android:theme="@style/AppTheme.NoDrawer" />
<activity
android:name="a.e"
android:theme="@style/AppTheme.StatusBar"/>
android:theme="@style/AppTheme.NoDrawer"/>
<activity
android:name="a.f"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="nosensor"
android:theme="@style/AppTheme.StatusBar" />
android:theme="@style/AppTheme.NoDrawer" />
<!-- Superuser -->

View File

@ -22,7 +22,7 @@ public class w<T extends DelegateWorker> extends Worker {
try {
base = ((Class<T>) ((ParameterizedType) getClass().getGenericSuperclass())
.getActualTypeArguments()[0]).newInstance();
} catch (IllegalAccessException | InstantiationException ignored) {}
} catch (Exception ignored) {}
}
@NonNull

View File

@ -30,7 +30,7 @@ public class AboutActivity extends BaseActivity {
@Override
public int getDarkTheme() {
return R.style.AppTheme_StatusBar_Dark;
return R.style.AppTheme_NoDrawer_Dark;
}
@Override

View File

@ -21,7 +21,7 @@ public class DonationActivity extends BaseActivity {
@Override
public int getDarkTheme() {
return R.style.AppTheme_StatusBar_Dark;
return R.style.AppTheme_NoDrawer_Dark;
}
@Override

View File

@ -85,7 +85,7 @@ public class FlashActivity extends BaseActivity {
@Override
public int getDarkTheme() {
return R.style.AppTheme_StatusBar_Dark;
return R.style.AppTheme_NoDrawer_Dark;
}
@Override

View File

@ -1,6 +1,7 @@
package com.topjohnwu.magisk;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
@ -75,7 +76,9 @@ public class MainActivity extends BaseActivity
}
};
toolbarElevation = toolbar.getElevation();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
toolbarElevation = toolbar.getElevation();
}
drawer.addDrawerListener(toggle);
toggle.syncState();
@ -208,6 +211,8 @@ public class MainActivity extends BaseActivity
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.content_frame, navFragment)
.commitNow();
toolbar.setElevation(setElevation ? toolbarElevation : 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
toolbar.setElevation(setElevation ? toolbarElevation : 0);
}
}
}

View File

@ -25,6 +25,7 @@ import com.topjohnwu.magisk.utils.SuConnector;
import java.io.IOException;
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import butterknife.BindView;
public class SuRequestActivity extends BaseActivity {
@ -125,7 +126,8 @@ public class SuRequestActivity extends BaseActivity {
appIcon.setImageDrawable(policy.info.loadIcon(pm));
appNameView.setText(policy.appName);
packageNameView.setText(policy.packageName);
warning.setCompoundDrawablesRelativeWithIntrinsicBounds(getDrawable(R.drawable.ic_warning), null, null, null);
warning.setCompoundDrawablesRelativeWithIntrinsicBounds(
AppCompatResources.getDrawable(this, R.drawable.ic_warning), null, null, null);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.allow_timeout, android.R.layout.simple_spinner_item);

View File

@ -20,6 +20,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@ -33,6 +34,10 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Au
private ActivityResultListener activityResultListener;
public App app = App.self;
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
@Override
public int[] getSubscribedTopics() {
return EMPTY_INT_ARRAY;

View File

@ -1,6 +1,7 @@
package com.topjohnwu.magisk.fragments;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -27,7 +28,9 @@ public class LogFragment extends BaseFragment {
View v = inflater.inflate(R.layout.fragment_log, container, false);
unbinder = new LogFragment_ViewBinding(this, v);
((MainActivity) requireActivity()).toolbar.setElevation(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
((MainActivity) requireActivity()).toolbar.setElevation(0);
}
TabFragmentAdapter adapter = new TabFragmentAdapter(getChildFragmentManager());

View File

@ -37,7 +37,7 @@ import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceGroupAdapter;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
import androidx.preference.SwitchPreference;
import androidx.preference.SwitchPreferenceCompat;
import androidx.recyclerview.widget.RecyclerView;
public class SettingsFragment extends PreferenceFragmentCompat
@ -105,8 +105,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
suNotification = (ListPreference) findPreference(Const.Key.SU_NOTIFICATION);
multiuserConfig = (ListPreference) findPreference(Const.Key.SU_MULTIUSER_MODE);
nsConfig = (ListPreference) findPreference(Const.Key.SU_MNT_NS);
SwitchPreference reauth = (SwitchPreference) findPreference(Const.Key.SU_REAUTH);
SwitchPreference fingerprint = (SwitchPreference) findPreference(Const.Key.SU_FINGERPRINT);
SwitchPreferenceCompat reauth = (SwitchPreferenceCompat) findPreference(Const.Key.SU_REAUTH);
SwitchPreferenceCompat fingerprint = (SwitchPreferenceCompat) findPreference(Const.Key.SU_FINGERPRINT);
updateChannel.setOnPreferenceChangeListener((p, o) -> {
String prev =String.valueOf(Data.updateChannel);
@ -182,7 +182,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
int i = 1;
for (Locale locale : LocaleManager.locales) {
entries[i] = locale.getDisplayName(locale);
entryValues[i++] = locale.toLanguageTag();
entryValues[i++] = LocaleManager.toLanguageTag(locale);
}
lp.setEntries(entries);
lp.setEntryValues(entryValues);
@ -264,10 +264,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
String key = preference.getKey();
switch (key) {
case Const.Key.SU_FINGERPRINT:
boolean checked = ((SwitchPreference) preference).isChecked();
((SwitchPreference) preference).setChecked(!checked);
boolean checked = ((SwitchPreferenceCompat) preference).isChecked();
((SwitchPreferenceCompat) preference).setChecked(!checked);
FingerprintHelper.showAuthDialog(requireActivity(), () -> {
((SwitchPreference) preference).setChecked(checked);
((SwitchPreferenceCompat) preference).setChecked(checked);
app.mDB.setSettings(key, checked ? 1 : 0);
});
break;

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 893 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -39,7 +39,7 @@
android:padding="16dp">
<ImageView
app:srcCompat="@drawable/ic_logo"
app:srcCompat="@drawable/ic_launcher"
android:layout_width="72dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical" />

View File

@ -343,7 +343,7 @@
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp"
app:srcCompat="@drawable/ic_logo" />
app:srcCompat="@drawable/ic_launcher" />
<TextView
android:id="@+id/install_text"

View File

@ -3,6 +3,7 @@
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -68,7 +69,7 @@
android:layout_height="wrap_content"
android:focusable="false"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_menu_overflow_material"
app:srcCompat="@drawable/ic_menu_overflow_material"
android:checked="false" />
</LinearLayout>

View File

@ -6,7 +6,7 @@
android:gravity="center_vertical"
android:paddingStart="16dp"
android:textAllCaps="true"
android:textColor="?android:colorAccent"
android:textColor="?colorAccent"
android:background="@android:color/transparent"
android:textSize="16sp"
android:id="@+id/section_text"

View File

@ -4,6 +4,7 @@
<item
android:id="@+id/repo_sort"
android:title=""
android:icon="@drawable/ic_sort"
app:showAsAction="always"/>

View File

@ -1,17 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme.StatusBar" parent="AppTheme">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<style name="AppTheme.NoDrawer" parent="AppTheme">
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="AppTheme.StatusBar.Dark" parent="AppTheme.Dark">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<style name="AppTheme.NoDrawer.Dark" parent="AppTheme.Dark">
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/ic_splash_activity</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="AppTheme.Dark" parent="AppTheme.Dark.Base">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>

View File

@ -1,42 +1,35 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="colorAccentFallback">@color/accentFallback</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="cardStyle">@style/CardViewStyle.Light</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="imageColorTint">@android:color/secondary_text_light</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>
<style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Dark.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorAccent">@color/accent</item>
<item name="colorAccentFallback">@color/accentFallback</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="cardStyle">@style/CardViewStyle.Dark</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:textColorSecondary">@color/dark_secondary_text</item>
<item name="imageColorTint">@color/dark_secondary_text</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>
<style name="AppTheme.Translucent" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>
<style name="AppTheme.Dark" parent="AppTheme.Dark.Base"/>
<style name="AppTheme.NoDrawer" parent="AppTheme.Base"/>
<style name="AppTheme.NoDrawer.Dark" parent="AppTheme.Dark.Base"/>
<style name="CardViewStyle.Dark" parent="CardView">
<item name="cardBackgroundColor">@color/card_background_color_dark</item>
@ -46,18 +39,8 @@
<item name="cardBackgroundColor">@color/card_background_color_light</item>
</style>
<style name="AppTheme.StatusBar" parent="AppTheme">
<item name="android:statusBarColor">?attr/colorPrimaryDark</item>
</style>
<style name="AppTheme.StatusBar.Dark" parent="AppTheme.Dark">
<item name="android:statusBarColor">?attr/colorPrimaryDark</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/ic_splash_activity</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="SuRequest" parent="Theme.AppCompat.Light.Dialog">

View File

@ -1,10 +1,10 @@
<PreferenceScreen
<androidx.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="general"
android:title="@string/settings_general_category">
<SwitchPreference
<SwitchPreferenceCompat
android:key="dark_theme"
android:title="@string/settings_dark_theme_title"
android:summary="@string/settings_dark_theme_summary" />
@ -35,7 +35,7 @@
android:key="update"
android:title="@string/settings_update">
<SwitchPreference
<SwitchPreferenceCompat
android:key="check_update"
android:defaultValue="true"
android:title="@string/settings_check_update_title"
@ -61,12 +61,12 @@
android:key="magisk"
android:title="@string/magisk">
<SwitchPreference
<SwitchPreferenceCompat
android:key="disable"
android:title="@string/settings_core_only_title"
android:summary="@string/settings_core_only_summary" />
<SwitchPreference
<SwitchPreferenceCompat
android:key="magiskhide"
android:title="@string/magiskhide"
android:summary="@string/settings_magiskhide_summary" />
@ -118,16 +118,16 @@
android:entries="@array/su_notification"
android:entryValues="@array/value_array" />
<SwitchPreference
<SwitchPreferenceCompat
android:key="su_fingerprint"
android:title="@string/settings_su_fingerprint_title"
android:summary="@string/settings_su_fingerprint_summary"/>
<SwitchPreference
<SwitchPreferenceCompat
android:key="su_reauth"
android:title="@string/settings_su_reauth_title"
android:summary="@string/settings_su_reauth_summary"/>
</PreferenceCategory>
</PreferenceScreen>
</androidx.preference.PreferenceScreen>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="ic_launcher">@drawable/ic_logo</drawable>
</resources>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="ic_launcher">@android:drawable/sym_def_app_icon</drawable>
</resources>

View File

@ -52,6 +52,40 @@ public class LocaleManager {
}
}
public static String toLanguageTag(Locale loc) {
if (Build.VERSION.SDK_INT >= 21) {
return loc.toLanguageTag();
} else {
String language = loc.getLanguage();
String country = loc.getCountry();
String variant = loc.getVariant();
if (language.isEmpty() || !language.matches("\\p{Alpha}{2,8}")) {
language = "und"; // Follow the Locale#toLanguageTag() implementation
} else if (language.equals("iw")) {
language = "he"; // correct deprecated "Hebrew"
} else if (language.equals("in")) {
language = "id"; // correct deprecated "Indonesian"
} else if (language.equals("ji")) {
language = "yi"; // correct deprecated "Yiddish"
}
// ensure valid country code, if not well formed, it's omitted
if (!country.matches("\\p{Alpha}{2}|\\p{Digit}{3}")) {
country = "";
}
// variant subtags that begin with a letter must be at least 5 characters long
if (!variant.matches("\\p{Alnum}{5,8}|\\p{Digit}\\p{Alnum}{3}")) {
variant = "";
}
StringBuilder tag = new StringBuilder(language);
if (!country.isEmpty())
tag.append('-').append(country);
if (!variant.isEmpty())
tag.append('-').append(variant);
return tag.toString();
}
}
public static void setLocale(App app) {
String localeConfig = app.prefs.getString(Const.Key.LOCALE, "");
if (localeConfig.isEmpty()) {