diff --git a/app/build.gradle b/app/build.gradle index ee5bd64..1661b02 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,7 +35,6 @@ android { lint { disable 'MissingTranslation' } - namespace 'com.fox2code.mmm' } aboutLibraries { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3ce948e..d143063 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ diff --git a/app/src/main/java/com/fox2code/mmm/MainActivity.java b/app/src/main/java/com/fox2code/mmm/MainActivity.java index 2b9558b..2bd3ce3 100644 --- a/app/src/main/java/com/fox2code/mmm/MainActivity.java +++ b/app/src/main/java/com/fox2code/mmm/MainActivity.java @@ -4,6 +4,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.widget.SearchView; import androidx.cardview.widget.CardView; import androidx.core.content.ContextCompat; +import androidx.core.graphics.ColorUtils; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; @@ -22,6 +23,7 @@ import android.view.inputmethod.EditorInfo; import android.widget.TextView; import com.fox2code.mmm.compat.CompatActivity; +import com.fox2code.mmm.compat.CompatDisplay; import com.fox2code.mmm.installer.InstallerInitializer; import com.fox2code.mmm.manager.LocalModuleInfo; import com.fox2code.mmm.manager.ModuleManager; @@ -32,6 +34,7 @@ import com.fox2code.mmm.utils.IntentHelper; import com.google.android.material.progressindicator.LinearProgressIndicator; import eightbitlab.com.blurview.BlurView; +import eightbitlab.com.blurview.BlurViewFacade; import eightbitlab.com.blurview.RenderScriptBlur; public class MainActivity extends CompatActivity implements SwipeRefreshLayout.OnRefreshListener, @@ -72,10 +75,8 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O setContentView(R.layout.activity_main); this.setTitle(R.string.app_name); this.getWindow().setFlags( - WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION | - WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, - WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION | - WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, + WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); setActionBarBackground(null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes(); @@ -106,7 +107,7 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O this.actionBarBlur.setupWith(this.moduleList).setFrameClearDrawable( this.getWindow().getDecorView().getBackground()) .setBlurAlgorithm(new RenderScriptBlur(this)) - .setBlurRadius(5F).setBlurAutoUpdate(true) + .setBlurRadius(4F).setBlurAutoUpdate(true) .setHasFixedTransformationMatrix(true); this.updateBlurState(); this.moduleList.addOnScrollListener(new RecyclerView.OnScrollListener() { @@ -116,6 +117,7 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O MainActivity.this.searchView.clearFocus(); } }); + this.searchView.setMinimumHeight(CompatDisplay.dpToPixel(16)); this.searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH | EditorInfo.IME_FLAG_NO_FULLSCREEN); this.searchView.setOnQueryTextListener(this); @@ -238,32 +240,37 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O this.swipeRefreshLayout.setProgressViewOffset(false, swipeRefreshLayoutOrigStartOffset + combinedBarsHeight, swipeRefreshLayoutOrigEndOffset + combinedBarsHeight); - this.moduleViewListBuilder.setHeaderPx(actionBarHeight); + this.moduleViewListBuilder.setHeaderPx( + actionBarHeight + CompatDisplay.dpToPixel(4)); this.moduleViewListBuilder.setFooterPx( bottomInset + this.searchCard.getHeight()); this.moduleViewListBuilder.updateInsets(); this.actionBarBlur.invalidate(); this.overScrollInsetTop = combinedBarsHeight; this.overScrollInsetBottom = bottomInset; + Log.d(TAG, "( " + bottomInset + ", " + + this.searchCard.getHeight() + ")"); } private void updateBlurState() { + boolean isLightMode = this.isLightTheme(); + int colorBackground; + try { + colorBackground = this.getColorCompat( + android.R.attr.windowBackground); + } catch (Resources.NotFoundException e) { + colorBackground = this.getColorCompat(isLightMode ? + R.color.white : R.color.black); + } if (MainApplication.isBlurEnabled()) { this.actionBarBlur.setBlurEnabled(true); - int transparent = this.getColorCompat(R.color.transparent); - this.actionBarBackground.setColor(transparent); + this.actionBarBackground.setColor(ColorUtils + .setAlphaComponent(colorBackground, 0x02)); + this.actionBarBackground.setColor(Color.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); + this.actionBarBlur.setOverlayColor(Color.TRANSPARENT); + this.actionBarBackground.setColor(colorBackground); } } 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 9c3e547..a7031b8 100644 --- a/app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java +++ b/app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java @@ -12,9 +12,13 @@ import android.os.Build; import android.os.Bundle; import android.util.Log; import android.util.TypedValue; +import android.view.KeyCharacterMap; +import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.ViewConfiguration; +import android.view.WindowManager; import androidx.annotation.AttrRes; import androidx.annotation.CallSuper; @@ -65,8 +69,10 @@ public class CompatActivity extends AppCompatActivity { private MenuItem.OnMenuItemClickListener menuClickListener; private CharSequence menuContentDescription; @StyleRes private int setThemeDynamic = 0; + private boolean onCreateCalledOnce = false; private boolean onCreateCalled = false; private boolean isRefreshUi = false; + private boolean hasHardwareNavBar; private int drawableResId; private MenuItem menuItem; // CompatConfigHelper @@ -82,6 +88,9 @@ public class CompatActivity extends AppCompatActivity { if (!this.onCreateCalled) { this.getLayoutInflater().setFactory2(new LayoutInflaterFactory(this.getDelegate()) .addOnViewCreatedListener(WindowInsetsHelper.Companion.getLISTENER())); + this.hasHardwareNavBar = ViewConfiguration.get(this).hasPermanentMenuKey() || + KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); + this.onCreateCalledOnce = true; } Application application = this.getApplication(); if (application instanceof ApplicationCallbacks) { @@ -114,7 +123,7 @@ public class CompatActivity extends AppCompatActivity { @CallSuper public void refreshUI() { // Avoid recursive calls - if (this.isRefreshUi) return; + if (this.isRefreshUi || !this.onCreateCalled) return; Application application = this.getApplication(); if (application instanceof ApplicationCallbacks) { this.isRefreshUi = true; @@ -196,6 +205,22 @@ public class CompatActivity extends AppCompatActivity { } } + public View getActionBarView() { + androidx.appcompat.app.ActionBar compatActionBar; + try { + compatActionBar = this.getSupportActionBar(); + } catch (Exception e) { + Log.e(TAG, "Failed to call getSupportActionBar", e); + compatActionBar = null; // Allow fallback to builtin actionBar. + } + if (compatActionBar != null) { + return compatActionBar.getCustomView(); + } else { + android.app.ActionBar actionBar = this.getActionBar(); + return actionBar != null ? actionBar.getCustomView() : null; + } + } + @Dimension @Px public int getActionBarHeight() { androidx.appcompat.app.ActionBar compatActionBar; @@ -242,21 +267,31 @@ public class CompatActivity extends AppCompatActivity { return height; } - public int getNavigationBarHeight() { // How to improve this? + public int getNavigationBarHeight() { int height = WindowInsetsCompat.CONSUMED.getInsets( WindowInsetsCompat.Type.navigationBars()).bottom; if (height == 0) { // Fallback to system resources int id = Resources.getSystem().getIdentifier( "config_showNavigationBar", "bool", "android"); - if (id > 0 && Resources.getSystem().getBoolean(id)) { + Log.d(TAG, "Nav 1: " + id); + if ((id > 0 && Resources.getSystem().getBoolean(id)) + || !this.hasHardwareNavBar()) { id = Resources.getSystem().getIdentifier( "navigation_bar_height", "dimen", "android"); + Log.d(TAG, "Nav 2: " + id); if (id > 0) return Resources.getSystem().getDimensionPixelSize(id); } } return height; } + public boolean hasHardwareNavBar() { + // If onCreate has not been called yet, cached value is not valid + return this.onCreateCalledOnce ? this.hasHardwareNavBar : + ViewConfiguration.get(this).hasPermanentMenuKey() || + KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); + } + public void setActionBarExtraMenuButton(@DrawableRes int drawableResId, MenuItem.OnMenuItemClickListener menuClickListener) { this.setActionBarExtraMenuButton(drawableResId, diff --git a/app/src/main/java/com/fox2code/mmm/markdown/MarkdownActivity.java b/app/src/main/java/com/fox2code/mmm/markdown/MarkdownActivity.java index cdd3c80..933b7ca 100644 --- a/app/src/main/java/com/fox2code/mmm/markdown/MarkdownActivity.java +++ b/app/src/main/java/com/fox2code/mmm/markdown/MarkdownActivity.java @@ -18,6 +18,7 @@ import com.fox2code.mmm.R; import com.fox2code.mmm.compat.CompatActivity; import com.fox2code.mmm.utils.Http; import com.fox2code.mmm.utils.IntentHelper; +import com.topjohnwu.superuser.internal.UiThreadHandler; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -64,8 +65,11 @@ public class MarkdownActivity extends CompatActivity { } Log.i(TAG, "Url for markdown " + url); setContentView(R.layout.markdown_view); - ViewGroup markdownBackground = findViewById(R.id.markdownBackground); - TextView textView = findViewById(R.id.markdownView); + final ViewGroup markdownBackground = findViewById(R.id.markdownBackground); + final TextView textView = findViewById(R.id.markdownView); + final TextView footer = findViewById(R.id.markdownFooter); + UiThreadHandler.handler.postDelayed(() -> // Fix footer height + footer.setMinHeight(this.getNavigationBarHeight()), 1L); new Thread(() -> { try { Log.d(TAG, "Downloading"); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2002bd0..4fdbda6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -57,16 +57,21 @@ android:gravity="right" app:layout_constraintRight_toRightOf="parent" app:layout_constraintBottom_toBottomOf="parent" - app:fitsSystemWindowsInsets="bottom" + app:layout_fitsSystemWindowsInsets="bottom" tools:ignore="RtlHardcoded"> - + @@ -75,7 +80,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@null" /> - + \ No newline at end of file diff --git a/app/src/main/res/layout/markdown_view.xml b/app/src/main/res/layout/markdown_view.xml index 5e31dc4..a7616e7 100644 --- a/app/src/main/res/layout/markdown_view.xml +++ b/app/src/main/res/layout/markdown_view.xml @@ -7,7 +7,7 @@ android:background="@color/black" android:id="@+id/markdownBackground" app:fitsSystemWindowsInsets="top|left|right"> - - + \ No newline at end of file diff --git a/app/src/main/res/layout/module_entry.xml b/app/src/main/res/layout/module_entry.xml index f66c17c..43e2ad6 100644 --- a/app/src/main/res/layout/module_entry.xml +++ b/app/src/main/res/layout/module_entry.xml @@ -10,7 +10,7 @@ android:layout_marginBottom="2dp" android:gravity="center_vertical" android:background="@null"> - - +