From cd5f6b6e6a7987bcb61dc661c15a149aa49608f1 Mon Sep 17 00:00:00 2001 From: Fox2Code Date: Thu, 24 Feb 2022 20:27:10 +0100 Subject: [PATCH 1/4] Fix landscape even more, make blur disabled by default (new strings) --- .../java/com/fox2code/mmm/MainActivity.java | 30 +++- .../com/fox2code/mmm/MainApplication.java | 31 ++-- .../mmm/androidacy/AndroidacyActivity.java | 1 + .../mmm/androidacy/AndroidacyWebAPI.java | 7 +- .../fox2code/mmm/compat/CompatActivity.java | 58 ++++++- .../mmm/compat/CompatApplication.java | 144 ++++++++++++++++++ .../mmm/compat/CompatThemeWrapper.java | 43 ++++++ .../mmm/installer/InstallerActivity.java | 4 + .../mmm/settings/SettingsActivity.java | 11 +- .../res/drawable/ic_baseline_blur_on_24.xml | 8 + app/src/main/res/layout/installer.xml | 5 +- app/src/main/res/layout/installer_wrap.xml | 5 +- app/src/main/res/layout/markdown_view.xml | 5 +- .../main/res/layout/markdown_view_safe.xml | 10 -- app/src/main/res/layout/webview.xml | 7 +- app/src/main/res/values/arrays.xml | 1 + app/src/main/res/values/colors.xml | 4 +- app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/themes.xml | 4 + app/src/main/res/xml/root_preferences.xml | 7 + 20 files changed, 343 insertions(+), 45 deletions(-) create mode 100644 app/src/main/java/com/fox2code/mmm/compat/CompatApplication.java create mode 100644 app/src/main/res/drawable/ic_baseline_blur_on_24.xml delete mode 100644 app/src/main/res/layout/markdown_view_safe.xml diff --git a/app/src/main/java/com/fox2code/mmm/MainActivity.java b/app/src/main/java/com/fox2code/mmm/MainActivity.java index 7e7c8ac..2b9558b 100644 --- a/app/src/main/java/com/fox2code/mmm/MainActivity.java +++ b/app/src/main/java/com/fox2code/mmm/MainActivity.java @@ -3,12 +3,15 @@ package com.fox2code.mmm; import androidx.annotation.NonNull; import androidx.appcompat.widget.SearchView; import androidx.cardview.widget.CardView; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import android.content.res.Configuration; import android.content.res.Resources; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; import android.os.Build; import android.os.Bundle; import android.util.Log; @@ -47,6 +50,7 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O private int overScrollInsetBottom; private TextView actionBarPadding; private BlurView actionBarBlur; + private ColorDrawable actionBarBackground; private RecyclerView moduleList; private CardView searchCard; private SearchView searchView; @@ -81,6 +85,7 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O } this.actionBarPadding = findViewById(R.id.action_bar_padding); this.actionBarBlur = findViewById(R.id.action_bar_blur); + this.actionBarBackground = new ColorDrawable(Color.TRANSPARENT); this.progressIndicator = findViewById(R.id.progress_bar); this.swipeRefreshLayout = findViewById(R.id.swipe_refresh); this.swipeRefreshLayoutOrigStartOffset = @@ -97,11 +102,13 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O this.moduleList.setItemViewCacheSize(4); // Default is 2 OverScrollManager.install(this.moduleList, this); this.swipeRefreshLayout.setOnRefreshListener(this); + this.actionBarBlur.setBackground(this.actionBarBackground); this.actionBarBlur.setupWith(this.moduleList).setFrameClearDrawable( this.getWindow().getDecorView().getBackground()) .setBlurAlgorithm(new RenderScriptBlur(this)) .setBlurRadius(5F).setBlurAutoUpdate(true) .setHasFixedTransformationMatrix(true); + this.updateBlurState(); this.moduleList.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { @@ -223,6 +230,7 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O private void updateScreenInsets(Configuration configuration) { boolean landscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE; + int bottomInset = (landscape ? 0 : this.getNavigationBarHeight()); int statusBarHeight = getStatusBarHeight(); int actionBarHeight = getActionBarHeight(); int combinedBarsHeight = statusBarHeight + actionBarHeight; @@ -231,7 +239,6 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O swipeRefreshLayoutOrigStartOffset + combinedBarsHeight, swipeRefreshLayoutOrigEndOffset + combinedBarsHeight); this.moduleViewListBuilder.setHeaderPx(actionBarHeight); - int bottomInset = (landscape ? 0 : this.getNavigationBarHeight()); this.moduleViewListBuilder.setFooterPx( bottomInset + this.searchCard.getHeight()); this.moduleViewListBuilder.updateInsets(); @@ -240,6 +247,26 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O this.overScrollInsetBottom = bottomInset; } + private void updateBlurState() { + if (MainApplication.isBlurEnabled()) { + this.actionBarBlur.setBlurEnabled(true); + int transparent = this.getColorCompat(R.color.transparent); + this.actionBarBackground.setColor(transparent); + } else { + this.actionBarBlur.setBlurEnabled(false); + boolean isLightMode = this.isLightTheme(); + int colorOpaque; + try { + colorOpaque = this.getColorCompat( + android.R.attr.windowBackground); + } catch (Resources.NotFoundException e) { + colorOpaque = this.getColorCompat(isLightMode ? + R.color.white : R.color.black); + } + this.actionBarBackground.setColor(colorOpaque); + } + } + @Override public void refreshUI() { super.refreshUI(); @@ -251,6 +278,7 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O this.searchView.setIconified(true); this.cardIconifyUpdate(); this.updateScreenInsets(); + this.updateBlurState(); this.moduleViewListBuilder.setQuery(null); Log.i(TAG, "Item After"); this.moduleViewListBuilder.refreshNotificationsUI(this.moduleViewAdapter); diff --git a/app/src/main/java/com/fox2code/mmm/MainApplication.java b/app/src/main/java/com/fox2code/mmm/MainApplication.java index e03cdbc..3a502df 100644 --- a/app/src/main/java/com/fox2code/mmm/MainApplication.java +++ b/app/src/main/java/com/fox2code/mmm/MainApplication.java @@ -7,6 +7,7 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Color; +import android.os.Build; import android.os.SystemClock; import android.text.SpannableStringBuilder; import android.util.Log; @@ -18,6 +19,7 @@ import androidx.emoji2.text.EmojiCompat; import androidx.emoji2.text.FontRequestEmojiCompatConfig; import com.fox2code.mmm.compat.CompatActivity; +import com.fox2code.mmm.compat.CompatApplication; import com.fox2code.mmm.compat.CompatThemeWrapper; import com.fox2code.mmm.installer.InstallerInitializer; import com.fox2code.mmm.utils.GMSProviderInstaller; @@ -44,7 +46,7 @@ import io.noties.prism4j.annotations.PrismBundle; includeAll = true, grammarLocatorClassName = ".Prism4jGrammarLocator" ) -public class MainApplication extends Application implements CompatActivity.ApplicationCallbacks { +public class MainApplication extends CompatApplication { private static final String timeFormatString = "dd MMM yyyy"; // Example: 13 july 2001 private static Locale timeFormatLocale = Resources.getSystem().getConfiguration().locale; @@ -110,6 +112,11 @@ public class MainApplication extends Application implements CompatActivity.Appli return getSharedPreferences().getBoolean("pref_dns_over_https", true); } + public static boolean isBlurEnabled() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && + getSharedPreferences().getBoolean("pref_enable_blur", false); + } + public static boolean isDeveloper() { return BuildConfig.DEBUG || getSharedPreferences().getBoolean("developer", false); @@ -164,7 +171,6 @@ public class MainApplication extends Application implements CompatActivity.Appli @StyleRes private int managerThemeResId = R.style.Theme_MagiskModuleManager; - private Boolean nightModeOverride = null; private CompatThemeWrapper markwonThemeContext; private Markwon markwon; @@ -217,20 +223,7 @@ public class MainApplication extends Application implements CompatActivity.Appli @SuppressLint("NonConstantResourceId") public void setManagerThemeResId(@StyleRes int resId) { this.managerThemeResId = resId; - switch (this.managerThemeResId) { - case R.style.Theme_MagiskModuleManager: - this.nightModeOverride = null; - break; - case R.style.Theme_MagiskModuleManager_Light: - this.nightModeOverride = Boolean.FALSE; - break; - case R.style.Theme_MagiskModuleManager_Dark: - this.nightModeOverride = Boolean.TRUE; - break; - default: - } if (this.markwonThemeContext != null) { - this.markwonThemeContext.setNightModeOverride(this.nightModeOverride); this.markwonThemeContext.setTheme(resId); } this.markwon = null; @@ -317,15 +310,15 @@ public class MainApplication extends Application implements CompatActivity.Appli @Override public void onCreateCompatActivity(CompatActivity compatActivity) { - compatActivity.setNightModeOverride(this.nightModeOverride); - compatActivity.setForceEnglish(isForceEnglish()); + this.setForceEnglish(isForceEnglish()); + super.onCreateCompatActivity(compatActivity); compatActivity.setTheme(this.managerThemeResId); } @Override public void onRefreshUI(CompatActivity compatActivity) { - compatActivity.setNightModeOverride(this.nightModeOverride); - compatActivity.setForceEnglish(isForceEnglish()); + this.setForceEnglish(isForceEnglish()); + super.onRefreshUI(compatActivity); compatActivity.setThemeRecreate(this.managerThemeResId); } diff --git a/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyActivity.java b/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyActivity.java index c965735..c7d905d 100644 --- a/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyActivity.java +++ b/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyActivity.java @@ -105,6 +105,7 @@ public class AndroidacyActivity extends CompatActivity { webSettings.setUserAgentString(Http.getAndroidacyUA()); webSettings.setDomStorageEnabled(true); webSettings.setJavaScriptEnabled(true); + webSettings.setAllowFileAccess(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { // Make website follow app theme webSettings.setForceDark(MainApplication.getINSTANCE().isLightTheme() ? WebSettings.FORCE_DARK_OFF : WebSettings.FORCE_DARK_ON); diff --git a/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java b/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java index 2a91d7b..aace709 100644 --- a/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java +++ b/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java @@ -6,6 +6,8 @@ import android.util.Log; import android.webkit.JavascriptInterface; import android.widget.Toast; +import androidx.annotation.Keep; + import com.fox2code.mmm.BuildConfig; import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.installer.InstallerInitializer; @@ -20,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; +@Keep public class AndroidacyWebAPI { private static final String TAG = "AndroidacyWebAPI"; private final AndroidacyActivity activity; @@ -106,7 +109,9 @@ public class AndroidacyWebAPI { return; } if (checksum != null) checksum = checksum.trim(); - if (!Hashes.checkSumValid(checksum)) { + if (checksum == null || checksum.isEmpty()) { + Log.w(TAG, "Androidacy WebView didn't provided a checksum!"); + } else if (!Hashes.checkSumValid(checksum)) { this.forceQuitRaw("Androidacy didn't provided a valid checksum"); return; } diff --git a/app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java b/app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java index 87d4675..9c3e547 100644 --- a/app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java +++ b/app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java @@ -11,11 +11,15 @@ import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.util.Log; +import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import androidx.annotation.AttrRes; import androidx.annotation.CallSuper; +import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; import androidx.annotation.Dimension; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; @@ -24,12 +28,15 @@ import androidx.annotation.Px; import androidx.annotation.StringRes; import androidx.annotation.StyleRes; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.ContextCompat; +import androidx.core.graphics.ColorUtils; import androidx.core.view.WindowInsetsCompat; import androidx.fragment.app.Fragment; import com.fox2code.mmm.Constants; import com.fox2code.mmm.R; +import java.lang.ref.WeakReference; import java.util.Locale; import java.util.Objects; @@ -51,6 +58,7 @@ public class CompatActivity extends AppCompatActivity { } }; + final WeakReference selfReference; private final CompatConfigHelper compatConfigHelper = new CompatConfigHelper(this); private CompatActivity.OnActivityResultCallback onActivityResultCallback; private CompatActivity.OnBackPressedCallback onBackPressedCallback; @@ -65,6 +73,10 @@ public class CompatActivity extends AppCompatActivity { private boolean forceEnglish; private Boolean nightModeOverride; + public CompatActivity() { + this.selfReference = new WeakReference<>(this); + } + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { if (!this.onCreateCalled) { @@ -326,7 +338,7 @@ public class CompatActivity extends AppCompatActivity { @Override public void onConfigurationChanged(@NonNull Configuration newConfig) { - this.compatConfigHelper.checkResourcesOverrides(this.getTheme(), + this.compatConfigHelper.checkResourcesOverrides(newConfig, this.forceEnglish, this.nightModeOverride); super.onConfigurationChanged(newConfig); } @@ -409,11 +421,51 @@ public class CompatActivity extends AppCompatActivity { this.checkResourcesOverrides(this.forceEnglish, nightModeOverride); } + void propagateResourcesOverride(boolean forceEnglish, Boolean nightModeOverride) { + if (this.forceEnglish == forceEnglish && + this.nightModeOverride == nightModeOverride) return; + this.forceEnglish = forceEnglish; + this.nightModeOverride = nightModeOverride; + this.checkResourcesOverrides(forceEnglish, nightModeOverride); + } + private void checkResourcesOverrides(boolean forceEnglish,Boolean nightModeOverride) { if (this.isRefreshUi || !this.onCreateCalled) return; // Wait before reload this.compatConfigHelper.checkResourcesOverrides(forceEnglish, nightModeOverride); } + public boolean isLightTheme() { + Resources.Theme theme = this.getTheme(); + TypedValue typedValue = new TypedValue(); + theme.resolveAttribute(R.attr.isLightTheme, typedValue, true); + if (typedValue.type == TypedValue.TYPE_INT_BOOLEAN) { + return typedValue.data != 0; + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + theme.resolveAttribute(android.R.attr.isLightTheme, typedValue, true); + if (typedValue.type == TypedValue.TYPE_INT_BOOLEAN) { + return typedValue.data != 0; + } + } + theme.resolveAttribute(android.R.attr.background, typedValue, true); + if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && + typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { + return ColorUtils.calculateLuminance(typedValue.data) > 0.7D; + } + throw new IllegalStateException("Theme is not a valid theme!"); + } + + @ColorInt + public final int getColorCompat(@ColorRes @AttrRes int color) { + TypedValue typedValue = new TypedValue(); + this.getTheme().resolveAttribute(color, typedValue, true); + if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && + typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { + return typedValue.data; + } + return ContextCompat.getColor(this, color); + } + public Locale getUserLocale() { return this.compatConfigHelper.getUserLocale(); } @@ -435,6 +487,10 @@ public class CompatActivity extends AppCompatActivity { return (CompatActivity) context; } + public WeakReference asWeakReference() { + return this.selfReference; + } + @FunctionalInterface public interface OnActivityResultCallback { void onActivityResult(int resultCode, @Nullable Intent data); diff --git a/app/src/main/java/com/fox2code/mmm/compat/CompatApplication.java b/app/src/main/java/com/fox2code/mmm/compat/CompatApplication.java new file mode 100644 index 0000000..1e937f7 --- /dev/null +++ b/app/src/main/java/com/fox2code/mmm/compat/CompatApplication.java @@ -0,0 +1,144 @@ +package com.fox2code.mmm.compat; + +import android.app.Application; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.os.Build; +import android.util.Log; +import android.util.TypedValue; + +import androidx.annotation.AttrRes; +import androidx.annotation.CallSuper; +import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; +import androidx.core.graphics.ColorUtils; + +import com.fox2code.mmm.R; + +import java.lang.ref.WeakReference; + +/** + * I will probably outsource this to a separate library later + */ +public class CompatApplication extends Application implements CompatActivity.ApplicationCallbacks { + private static final String TAG = "CompatApplication"; + private final CompatConfigHelper compatConfigHelper = new CompatConfigHelper(this); + private WeakReference lastCompatActivity; + // CompatConfigHelper + private boolean forceEnglish; + private Boolean nightModeOverride; + private boolean propagateOverrides; + + public CompatApplication() {} + + @Override + public void onConfigurationChanged(@NonNull Configuration newConfig) { + this.compatConfigHelper.checkResourcesOverrides(newConfig, + this.forceEnglish, this.nightModeOverride); + super.onConfigurationChanged(newConfig); + } + + public void setForceEnglish(boolean forceEnglish) { + if (this.forceEnglish != forceEnglish) { + this.forceEnglish = forceEnglish; + this.checkResourcesOverrides(forceEnglish, this.nightModeOverride); + } + // Propagate even if local value didn't changed + if (this.propagateOverrides && this.lastCompatActivity != null) { + CompatActivity compatActivity = this.lastCompatActivity.get(); + if (compatActivity != null) + compatActivity.setForceEnglish(forceEnglish); + } + } + + public void setNightModeOverride(Boolean nightModeOverride) { + if (this.nightModeOverride != nightModeOverride) { + this.nightModeOverride = nightModeOverride; + this.checkResourcesOverrides(this.forceEnglish, nightModeOverride); + } + // Propagate even if local value didn't changed + if (this.propagateOverrides && this.lastCompatActivity != null) { + CompatActivity compatActivity = this.lastCompatActivity.get(); + if (compatActivity != null) + compatActivity.setNightModeOverride(nightModeOverride); + } + } + + public boolean isPropagateOverrides() { + return propagateOverrides; + } + + public void setPropagateOverrides(boolean propagateOverrides) { + this.propagateOverrides = propagateOverrides; + WeakReference lastCompatActivity = this.lastCompatActivity; + if (lastCompatActivity != null) { + Log.d(TAG, "setPropagateOverrides(" + // This should be avoided + propagateOverrides + ") called after first activity created!"); + CompatActivity compatActivity = lastCompatActivity.get(); + if (compatActivity != null && propagateOverrides) { + this.propagateOverrides(compatActivity); + } + } + } + + private void checkResourcesOverrides(boolean forceEnglish, Boolean nightModeOverride) { + this.compatConfigHelper.checkResourcesOverrides(forceEnglish, nightModeOverride); + } + + public boolean isLightTheme() { + Resources.Theme theme = this.getTheme(); + TypedValue typedValue = new TypedValue(); + theme.resolveAttribute(R.attr.isLightTheme, typedValue, true); + if (typedValue.type == TypedValue.TYPE_INT_BOOLEAN) { + return typedValue.data == 1; + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + theme.resolveAttribute(android.R.attr.isLightTheme, typedValue, true); + if (typedValue.type == TypedValue.TYPE_INT_BOOLEAN) { + return typedValue.data == 1; + } + } + theme.resolveAttribute(android.R.attr.background, typedValue, true); + if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && + typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { + return ColorUtils.calculateLuminance(typedValue.data) > 0.7D; + } + throw new IllegalStateException("Theme is not a valid theme!"); + } + + @ColorInt + public final int getColorCompat(@ColorRes @AttrRes int color) { + TypedValue typedValue = new TypedValue(); + this.getTheme().resolveAttribute(color, typedValue, true); + if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && + typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { + return typedValue.data; + } + return ContextCompat.getColor(this, color); + } + + @Override + @CallSuper + public void onCreateCompatActivity(CompatActivity compatActivity) { + this.lastCompatActivity = compatActivity.selfReference; + if (this.propagateOverrides) { + this.propagateOverrides(compatActivity); + } + } + + @Override + @CallSuper + public void onRefreshUI(CompatActivity compatActivity) { + this.lastCompatActivity = compatActivity.selfReference; + if (this.propagateOverrides) { + this.propagateOverrides(compatActivity); + } + } + + private void propagateOverrides(CompatActivity compatActivity) { + compatActivity.propagateResourcesOverride( + this.forceEnglish, this.nightModeOverride); + } +} diff --git a/app/src/main/java/com/fox2code/mmm/compat/CompatThemeWrapper.java b/app/src/main/java/com/fox2code/mmm/compat/CompatThemeWrapper.java index 56b688f..c623c63 100644 --- a/app/src/main/java/com/fox2code/mmm/compat/CompatThemeWrapper.java +++ b/app/src/main/java/com/fox2code/mmm/compat/CompatThemeWrapper.java @@ -2,9 +2,20 @@ package com.fox2code.mmm.compat; import android.content.Context; import android.content.res.Resources; +import android.graphics.Color; +import android.os.Build; +import android.util.TypedValue; +import androidx.annotation.AttrRes; +import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; import androidx.annotation.StyleRes; import androidx.appcompat.view.ContextThemeWrapper; +import androidx.core.content.ContextCompat; +import androidx.core.content.res.ComplexColorCompat; +import androidx.core.graphics.ColorUtils; + +import com.fox2code.mmm.R; /** * I will probably outsource this to a separate library later @@ -52,4 +63,36 @@ public class CompatThemeWrapper extends ContextThemeWrapper { if (!this.canReload) return; // Do not reload during theme reload this.compatConfigHelper.checkResourcesOverrides(forceEnglish, nightModeOverride); } + + public boolean isLightTheme() { + Resources.Theme theme = this.getTheme(); + TypedValue typedValue = new TypedValue(); + theme.resolveAttribute(R.attr.isLightTheme, typedValue, true); + if (typedValue.type == TypedValue.TYPE_INT_BOOLEAN) { + return typedValue.data == 1; + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + theme.resolveAttribute(android.R.attr.isLightTheme, typedValue, true); + if (typedValue.type == TypedValue.TYPE_INT_BOOLEAN) { + return typedValue.data == 1; + } + } + theme.resolveAttribute(android.R.attr.background, typedValue, true); + if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && + typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { + return ColorUtils.calculateLuminance(typedValue.data) > 0.7D; + } + throw new IllegalStateException("Theme is not a valid theme!"); + } + + @ColorInt + public final int getColorCompat(@ColorRes @AttrRes int color) { + TypedValue typedValue = new TypedValue(); + this.getTheme().resolveAttribute(color, typedValue, true); + if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && + typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { + return typedValue.data; + } + return ContextCompat.getColor(this, color); + } } diff --git a/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java b/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java index f9b5fdd..448c55f 100644 --- a/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java +++ b/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java @@ -112,6 +112,9 @@ public class InstallerActivity extends CompatActivity { .setBackground(new ColorDrawable(background)); this.progressIndicator.setVisibility(View.GONE); this.progressIndicator.setIndeterminate(true); + this.getWindow().setFlags( // Note: Doesn't require WAKELOCK permission + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); if (urlMode) { this.progressIndicator.setVisibility(View.VISIBLE); this.installerTerminal.addLine("- Downloading " + name); @@ -516,6 +519,7 @@ public class InstallerActivity extends CompatActivity { else toDelete = null; } else toDelete = null; this.runOnUiThread(() -> { + this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, 0); this.setOnBackPressedCallback(null); this.setDisplayHomeAsUpEnabled(true); this.progressIndicator.setVisibility(View.GONE); diff --git a/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java b/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java index 8b079c4..739db08 100644 --- a/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java +++ b/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java @@ -1,17 +1,15 @@ package com.fox2code.mmm.settings; +import android.os.Build; import android.os.Bundle; -import android.view.View; import android.widget.Toast; -import androidx.annotation.NonNull; import androidx.annotation.StringRes; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; -import androidx.recyclerview.widget.RecyclerView; import com.fox2code.mmm.AppUpdateManager; import com.fox2code.mmm.BuildConfig; @@ -27,8 +25,6 @@ import com.fox2code.mmm.repo.RepoManager; import com.fox2code.mmm.utils.Http; import com.fox2code.mmm.utils.IntentHelper; import com.mikepenz.aboutlibraries.LibsBuilder; -import com.mikepenz.aboutlibraries.LibsConfiguration; -import com.mikepenz.aboutlibraries.ui.LibsSupportFragment; import com.topjohnwu.superuser.internal.UiThreadHandler; public class SettingsActivity extends CompatActivity { @@ -79,6 +75,11 @@ public class SettingsActivity extends CompatActivity { }, 1); return true; }); + Preference enableBlur = findPreference("pref_enable_blur"); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + enableBlur.setSummary(R.string.require_android_6); + enableBlur.setEnabled(false); + } Preference forceEnglish = findPreference("pref_force_english"); forceEnglish.setOnPreferenceChangeListener((preference, newValue) -> { CompatThemeWrapper compatThemeWrapper = diff --git a/app/src/main/res/drawable/ic_baseline_blur_on_24.xml b/app/src/main/res/drawable/ic_baseline_blur_on_24.xml new file mode 100644 index 0000000..7691dbc --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_blur_on_24.xml @@ -0,0 +1,8 @@ + + + diff --git a/app/src/main/res/layout/installer.xml b/app/src/main/res/layout/installer.xml index 30473c7..236d9b2 100644 --- a/app/src/main/res/layout/installer.xml +++ b/app/src/main/res/layout/installer.xml @@ -2,8 +2,11 @@ + android:layout_height="match_parent" + app:fitsSystemWindowsInsets="left|right" + tools:context=".installer.InstallerActivity"> + android:layout_height="match_parent" + app:fitsSystemWindowsInsets="left|right" + tools:context=".installer.InstallerActivity"> - + app:fitsSystemWindowsInsets="top|left|right"> - - - \ No newline at end of file diff --git a/app/src/main/res/layout/webview.xml b/app/src/main/res/layout/webview.xml index 5174fc5..a5b88e7 100644 --- a/app/src/main/res/layout/webview.xml +++ b/app/src/main/res/layout/webview.xml @@ -1,7 +1,10 @@ - + android:layout_height="match_parent" + app:fitsSystemWindowsInsets="left|right"> + system dark diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ba10cbe..490833b 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,8 +7,8 @@ #FF018786 #EF6C00 #FFA726 - #80000000 - #80FFFFFF + #70000000 + #70FFFFFF #00000000 #FF000000 #FFFFFFFF diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4943369..590a0b3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -22,6 +22,7 @@ Support Donate Submit a module + Require Android 6.0+ Last update: @@ -50,6 +51,7 @@ Delete files Failed to delete the module files Theme + Theme mode Module id: Install module from storage The selected module is in an invalid format @@ -88,6 +90,7 @@ Wrap text to a new line instead of putting all text on the same line when installing a module + Enable blur Repo enabled Repo disabled \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index f163125..0e8aa5b 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -13,7 +13,9 @@ @color/white @color/status_bar_color + @color/transparent true + true true @color/status_bar_color + @color/transparent false + false true Dernière mis-à-jour: @@ -50,6 +51,7 @@ Supprimer les fichiers Échec de suppression des fichiers du module Thème + Mode du thème Id du module: Installer un module module depuis le stockage Le module sélectionné est dans un format invalide @@ -88,6 +90,7 @@ Mise en forme du texte avec une nouvelle ligne au lieu de mettre tout le texte sur la même ligne lors de l\’installation d\’un module + Activer l\’effet de flou Dépôt activé Dépôt désactivé From f4988a20da65da1f41387fe2c2b7cc7827b7e34a Mon Sep 17 00:00:00 2001 From: Igor Sorocean Date: Fri, 25 Feb 2022 16:15:30 +0200 Subject: [PATCH 3/4] update ro translation --- app/src/main/res/values-ro/arrays.xml | 1 + app/src/main/res/values-ro/strings.xml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/app/src/main/res/values-ro/arrays.xml b/app/src/main/res/values-ro/arrays.xml index b7657e3..a102086 100644 --- a/app/src/main/res/values-ro/arrays.xml +++ b/app/src/main/res/values-ro/arrays.xml @@ -1,5 +1,6 @@ + Sistem Întunecată diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index fcc6dfc..f67a0e0 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -23,6 +23,7 @@ Suport Donează Trimite un modul + Necesită Android 6.0+ Ultima actualizare: Depozit: @@ -49,6 +50,7 @@ Șterge fișierele Ștergerea fișierelor modulului a eșuat Temă + Mod temă ID modul: Instalare modul de pe stocare Modulul selectat este într-un format greșit @@ -82,6 +84,7 @@ Se încadrează textul la o linie nouă în loc să fie pus tot textul pe aceeași linie atunci când se instalează un modul + Activează estomparea Depozit activat Depozit dezactivat From 64427356fb7b6813e9373f56c48459701d3c01e5 Mon Sep 17 00:00:00 2001 From: Fox2Code Date: Sat, 26 Feb 2022 00:24:49 +0100 Subject: [PATCH 4/4] Update Android Gradle Plugin --- app/build.gradle | 5 +++-- app/src/main/AndroidManifest.xml | 1 - build.gradle | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9510080..ee5bd64 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,6 +35,7 @@ android { lint { disable 'MissingTranslation' } + namespace 'com.fox2code.mmm' } aboutLibraries { @@ -48,8 +49,8 @@ configurations { dependencies { // UI implementation 'androidx.appcompat:appcompat:1.4.1' - implementation 'androidx.emoji2:emoji2:1.0.1' - implementation 'androidx.emoji2:emoji2-views-helper:1.0.1' + implementation 'androidx.emoji2:emoji2:1.1.0' + implementation 'androidx.emoji2:emoji2-views-helper:1.1.0' implementation 'androidx.preference:preference:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.3' implementation 'androidx.recyclerview:recyclerview:1.2.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d143063..3ce948e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ diff --git a/build.gradle b/build.gradle index 13292da..e39403f 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { } project.ext.latestAboutLibsRelease = "10.0.0-rc01" dependencies { - classpath 'com.android.tools.build:gradle:7.1.1' + classpath 'com.android.tools.build:gradle:7.1.2' classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:${latestAboutLibsRelease}" // NOTE: Do not place your application dependencies here; they belong