Skip to content

Commit

Permalink
Support API 16 (Android 4.1)
Browse files Browse the repository at this point in the history
Because why not
  • Loading branch information
topjohnwu committed Feb 2, 2019
1 parent 9fbe589 commit 62acc17
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<String> set = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.allow_timeout, android.R.layout.simple_spinner_item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
77 changes: 39 additions & 38 deletions app/src/full/res/layout/activity_request.xml
Original file line number Diff line number Diff line change
@@ -1,110 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/su_popup"
tools:context=".SuRequestActivity"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:minWidth="350dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="?attr/colorBackgroundFloating"
android:minWidth="350dp"
android:orientation="vertical"
android:background="?attr/colorBackgroundFloating">
tools:context=".SuRequestActivity">

<TextView
android:text="@string/su_request_title"
android:id="@+id/request_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/request_title"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp"/>
android:layout_marginBottom="5dp"
android:gravity="center_horizontal"
android:text="@string/su_request_title"
android:textAppearance="?android:attr/textAppearanceLarge" />

<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:layout_gravity="center_horizontal">
android:paddingEnd="10dp">

<ImageView
android:id="@+id/app_icon"
android:layout_weight="0"
android:layout_marginEnd="10dp"
android:layout_height="50dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp"
android:layout_gravity="center_vertical" />
android:layout_marginLeft="5dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_weight="0" />

<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:layout_gravity="center_vertical">
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:id="@+id/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="200dp"
android:ellipsize="end"
android:maxWidth="300dp"
android:maxLines="1"
android:ellipsize="end"
android:textColor="?android:textColorPrimary"
android:minWidth="200dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/app_name" />
android:textColor="?android:textColorPrimary" />

<TextView
android:id="@+id/package_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="200dp"
android:ellipsize="end"
android:maxWidth="300dp"
android:maxLines="1"
android:ellipsize="end"
android:textColor="?android:textColorSecondary"
android:id="@+id/package_name" />
android:minWidth="200dp"
android:textColor="?android:textColorSecondary" />
</LinearLayout>
</LinearLayout>

<Spinner
android:id="@+id/timeout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timeout"
android:layout_gravity="center_horizontal" />

<TextView
android:id="@+id/warning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:text="@string/su_warning"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:drawablePadding="10dp" />
android:drawablePadding="10dp"
android:text="@string/su_warning"
android:textColor="?android:textColorSecondary" />

<LinearLayout
style="?android:buttonBarStyle"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="horizontal"
android:paddingLeft="30dp"
android:paddingRight="30dp">

<Button
android:id="@+id/deny_btn"
style="?android:buttonBarButtonStyle"
android:text="@string/deny_with_str"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/deny_btn"
android:layout_weight="1" />
android:layout_weight="1"
android:text="@string/deny_with_str" />

<Button
android:id="@+id/grant_btn"
Expand Down
25 changes: 15 additions & 10 deletions app/src/full/res/layout/fragment_magisk.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
Expand Down Expand Up @@ -42,6 +41,7 @@
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="@+id/app_name"
app:layout_constraintEnd_toStartOf="@+id/app_name"
app:layout_constraintHorizontal_bias="0.42"
Expand Down Expand Up @@ -110,6 +110,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:tint="?attr/imageColorTint"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/title"
Expand Down Expand Up @@ -173,6 +174,7 @@
android:layout_height="30dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:layout_marginBottom="12dp"
android:tint="@color/green500"
app:layout_constraintBottom_toBottomOf="parent"
Expand All @@ -198,6 +200,7 @@
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/safetyNet_status"
app:layout_constraintTop_toTopOf="parent"
Expand Down Expand Up @@ -226,6 +229,7 @@
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="@+id/cts_status"
app:layout_constraintEnd_toStartOf="@+id/cts_status"
app:layout_constraintTop_toTopOf="@+id/cts_status" />
Expand All @@ -245,6 +249,7 @@
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="@+id/basic_status"
app:layout_constraintEnd_toStartOf="@+id/basic_status"
app:layout_constraintTop_toTopOf="@+id/basic_status" />
Expand Down Expand Up @@ -286,11 +291,11 @@
android:id="@+id/paypal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="horizontal"
app:layout_constraintEnd_toStartOf="@+id/patreon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
Expand All @@ -317,11 +322,11 @@
android:id="@+id/patreon"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/paypal"
app:layout_constraintTop_toTopOf="parent">
Expand Down Expand Up @@ -380,9 +385,9 @@
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:tint="?attr/imageColorTint"
android:layout_gravity="center_horizontal"
app:srcCompat="@drawable/ic_github" />

</FrameLayout>
Expand All @@ -401,9 +406,9 @@
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:tint="?attr/imageColorTint"
android:layout_gravity="center_horizontal"
app:srcCompat="@drawable/ic_xda" />

</FrameLayout>
Expand Down
Loading

0 comments on commit 62acc17

Please sign in to comment.