Fixing android layout for older android devices, fix debug builds.

pull/27/head
Fox2Code 3 years ago
parent 64427356fb
commit 495e1cc3e6

@ -35,7 +35,6 @@ android {
lint { lint {
disable 'MissingTranslation' disable 'MissingTranslation'
} }
namespace 'com.fox2code.mmm'
} }
aboutLibraries { aboutLibraries {

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="com.fox2code.mmm"
tools:ignore="QueryAllPackagesPermission"> tools:ignore="QueryAllPackagesPermission">
<!-- Wifi is not the only way to get an internet connection --> <!-- Wifi is not the only way to get an internet connection -->

@ -4,6 +4,7 @@ import androidx.annotation.NonNull;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.cardview.widget.CardView; import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@ -22,6 +23,7 @@ import android.view.inputmethod.EditorInfo;
import android.widget.TextView; import android.widget.TextView;
import com.fox2code.mmm.compat.CompatActivity; import com.fox2code.mmm.compat.CompatActivity;
import com.fox2code.mmm.compat.CompatDisplay;
import com.fox2code.mmm.installer.InstallerInitializer; import com.fox2code.mmm.installer.InstallerInitializer;
import com.fox2code.mmm.manager.LocalModuleInfo; import com.fox2code.mmm.manager.LocalModuleInfo;
import com.fox2code.mmm.manager.ModuleManager; import com.fox2code.mmm.manager.ModuleManager;
@ -32,6 +34,7 @@ import com.fox2code.mmm.utils.IntentHelper;
import com.google.android.material.progressindicator.LinearProgressIndicator; import com.google.android.material.progressindicator.LinearProgressIndicator;
import eightbitlab.com.blurview.BlurView; import eightbitlab.com.blurview.BlurView;
import eightbitlab.com.blurview.BlurViewFacade;
import eightbitlab.com.blurview.RenderScriptBlur; import eightbitlab.com.blurview.RenderScriptBlur;
public class MainActivity extends CompatActivity implements SwipeRefreshLayout.OnRefreshListener, 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); setContentView(R.layout.activity_main);
this.setTitle(R.string.app_name); this.setTitle(R.string.app_name);
this.getWindow().setFlags( this.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION |
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
setActionBarBackground(null); setActionBarBackground(null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes(); 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.actionBarBlur.setupWith(this.moduleList).setFrameClearDrawable(
this.getWindow().getDecorView().getBackground()) this.getWindow().getDecorView().getBackground())
.setBlurAlgorithm(new RenderScriptBlur(this)) .setBlurAlgorithm(new RenderScriptBlur(this))
.setBlurRadius(5F).setBlurAutoUpdate(true) .setBlurRadius(4F).setBlurAutoUpdate(true)
.setHasFixedTransformationMatrix(true); .setHasFixedTransformationMatrix(true);
this.updateBlurState(); this.updateBlurState();
this.moduleList.addOnScrollListener(new RecyclerView.OnScrollListener() { this.moduleList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@ -116,6 +117,7 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O
MainActivity.this.searchView.clearFocus(); MainActivity.this.searchView.clearFocus();
} }
}); });
this.searchView.setMinimumHeight(CompatDisplay.dpToPixel(16));
this.searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH | this.searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH |
EditorInfo.IME_FLAG_NO_FULLSCREEN); EditorInfo.IME_FLAG_NO_FULLSCREEN);
this.searchView.setOnQueryTextListener(this); this.searchView.setOnQueryTextListener(this);
@ -238,32 +240,37 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O
this.swipeRefreshLayout.setProgressViewOffset(false, this.swipeRefreshLayout.setProgressViewOffset(false,
swipeRefreshLayoutOrigStartOffset + combinedBarsHeight, swipeRefreshLayoutOrigStartOffset + combinedBarsHeight,
swipeRefreshLayoutOrigEndOffset + combinedBarsHeight); swipeRefreshLayoutOrigEndOffset + combinedBarsHeight);
this.moduleViewListBuilder.setHeaderPx(actionBarHeight); this.moduleViewListBuilder.setHeaderPx(
actionBarHeight + CompatDisplay.dpToPixel(4));
this.moduleViewListBuilder.setFooterPx( this.moduleViewListBuilder.setFooterPx(
bottomInset + this.searchCard.getHeight()); bottomInset + this.searchCard.getHeight());
this.moduleViewListBuilder.updateInsets(); this.moduleViewListBuilder.updateInsets();
this.actionBarBlur.invalidate(); this.actionBarBlur.invalidate();
this.overScrollInsetTop = combinedBarsHeight; this.overScrollInsetTop = combinedBarsHeight;
this.overScrollInsetBottom = bottomInset; this.overScrollInsetBottom = bottomInset;
Log.d(TAG, "( " + bottomInset + ", " +
this.searchCard.getHeight() + ")");
} }
private void updateBlurState() { 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()) { if (MainApplication.isBlurEnabled()) {
this.actionBarBlur.setBlurEnabled(true); this.actionBarBlur.setBlurEnabled(true);
int transparent = this.getColorCompat(R.color.transparent); this.actionBarBackground.setColor(ColorUtils
this.actionBarBackground.setColor(transparent); .setAlphaComponent(colorBackground, 0x02));
this.actionBarBackground.setColor(Color.TRANSPARENT);
} else { } else {
this.actionBarBlur.setBlurEnabled(false); this.actionBarBlur.setBlurEnabled(false);
boolean isLightMode = this.isLightTheme(); this.actionBarBlur.setOverlayColor(Color.TRANSPARENT);
int colorOpaque; this.actionBarBackground.setColor(colorBackground);
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);
} }
} }

@ -12,9 +12,13 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewConfiguration;
import android.view.WindowManager;
import androidx.annotation.AttrRes; import androidx.annotation.AttrRes;
import androidx.annotation.CallSuper; import androidx.annotation.CallSuper;
@ -65,8 +69,10 @@ public class CompatActivity extends AppCompatActivity {
private MenuItem.OnMenuItemClickListener menuClickListener; private MenuItem.OnMenuItemClickListener menuClickListener;
private CharSequence menuContentDescription; private CharSequence menuContentDescription;
@StyleRes private int setThemeDynamic = 0; @StyleRes private int setThemeDynamic = 0;
private boolean onCreateCalledOnce = false;
private boolean onCreateCalled = false; private boolean onCreateCalled = false;
private boolean isRefreshUi = false; private boolean isRefreshUi = false;
private boolean hasHardwareNavBar;
private int drawableResId; private int drawableResId;
private MenuItem menuItem; private MenuItem menuItem;
// CompatConfigHelper // CompatConfigHelper
@ -82,6 +88,9 @@ public class CompatActivity extends AppCompatActivity {
if (!this.onCreateCalled) { if (!this.onCreateCalled) {
this.getLayoutInflater().setFactory2(new LayoutInflaterFactory(this.getDelegate()) this.getLayoutInflater().setFactory2(new LayoutInflaterFactory(this.getDelegate())
.addOnViewCreatedListener(WindowInsetsHelper.Companion.getLISTENER())); .addOnViewCreatedListener(WindowInsetsHelper.Companion.getLISTENER()));
this.hasHardwareNavBar = ViewConfiguration.get(this).hasPermanentMenuKey() ||
KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
this.onCreateCalledOnce = true;
} }
Application application = this.getApplication(); Application application = this.getApplication();
if (application instanceof ApplicationCallbacks) { if (application instanceof ApplicationCallbacks) {
@ -114,7 +123,7 @@ public class CompatActivity extends AppCompatActivity {
@CallSuper @CallSuper
public void refreshUI() { public void refreshUI() {
// Avoid recursive calls // Avoid recursive calls
if (this.isRefreshUi) return; if (this.isRefreshUi || !this.onCreateCalled) return;
Application application = this.getApplication(); Application application = this.getApplication();
if (application instanceof ApplicationCallbacks) { if (application instanceof ApplicationCallbacks) {
this.isRefreshUi = true; 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 @Dimension @Px
public int getActionBarHeight() { public int getActionBarHeight() {
androidx.appcompat.app.ActionBar compatActionBar; androidx.appcompat.app.ActionBar compatActionBar;
@ -242,21 +267,31 @@ public class CompatActivity extends AppCompatActivity {
return height; return height;
} }
public int getNavigationBarHeight() { // How to improve this? public int getNavigationBarHeight() {
int height = WindowInsetsCompat.CONSUMED.getInsets( int height = WindowInsetsCompat.CONSUMED.getInsets(
WindowInsetsCompat.Type.navigationBars()).bottom; WindowInsetsCompat.Type.navigationBars()).bottom;
if (height == 0) { // Fallback to system resources if (height == 0) { // Fallback to system resources
int id = Resources.getSystem().getIdentifier( int id = Resources.getSystem().getIdentifier(
"config_showNavigationBar", "bool", "android"); "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( id = Resources.getSystem().getIdentifier(
"navigation_bar_height", "dimen", "android"); "navigation_bar_height", "dimen", "android");
Log.d(TAG, "Nav 2: " + id);
if (id > 0) return Resources.getSystem().getDimensionPixelSize(id); if (id > 0) return Resources.getSystem().getDimensionPixelSize(id);
} }
} }
return height; 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, public void setActionBarExtraMenuButton(@DrawableRes int drawableResId,
MenuItem.OnMenuItemClickListener menuClickListener) { MenuItem.OnMenuItemClickListener menuClickListener) {
this.setActionBarExtraMenuButton(drawableResId, this.setActionBarExtraMenuButton(drawableResId,

@ -18,6 +18,7 @@ import com.fox2code.mmm.R;
import com.fox2code.mmm.compat.CompatActivity; import com.fox2code.mmm.compat.CompatActivity;
import com.fox2code.mmm.utils.Http; import com.fox2code.mmm.utils.Http;
import com.fox2code.mmm.utils.IntentHelper; import com.fox2code.mmm.utils.IntentHelper;
import com.topjohnwu.superuser.internal.UiThreadHandler;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -64,8 +65,11 @@ public class MarkdownActivity extends CompatActivity {
} }
Log.i(TAG, "Url for markdown " + url); Log.i(TAG, "Url for markdown " + url);
setContentView(R.layout.markdown_view); setContentView(R.layout.markdown_view);
ViewGroup markdownBackground = findViewById(R.id.markdownBackground); final ViewGroup markdownBackground = findViewById(R.id.markdownBackground);
TextView textView = findViewById(R.id.markdownView); 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(() -> { new Thread(() -> {
try { try {
Log.d(TAG, "Downloading"); Log.d(TAG, "Downloading");

@ -57,16 +57,21 @@
android:gravity="right" android:gravity="right"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:fitsSystemWindowsInsets="bottom" app:layout_fitsSystemWindowsInsets="bottom"
tools:ignore="RtlHardcoded"> tools:ignore="RtlHardcoded">
<androidx.cardview.widget.CardView <!--
setting high app:cardCornerRadius is not supported on some versions
so we must use code to get a round appearance.
-->
<com.google.android.material.card.MaterialCardView
android:id="@+id/search_card" android:id="@+id/search_card"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:shape="ring" android:shape="ring"
android:background="@null" android:background="@null"
app:cardCornerRadius="75dp" app:cardCornerRadius="@dimen/card_corner_radius"
app:cardPreventCornerOverlap="true"
app:strokeColor="@android:color/transparent" app:strokeColor="@android:color/transparent"
app:cardElevation="0dp" app:cardElevation="0dp"
app:strokeWidth="0dp"> app:strokeWidth="0dp">
@ -75,7 +80,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@null" /> android:background="@null" />
</androidx.cardview.widget.CardView> </com.google.android.material.card.MaterialCardView>
</LinearLayout> </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -7,7 +7,7 @@
android:background="@color/black" android:background="@color/black"
android:id="@+id/markdownBackground" android:id="@+id/markdownBackground"
app:fitsSystemWindowsInsets="top|left|right"> app:fitsSystemWindowsInsets="top|left|right">
<androidx.cardview.widget.CardView <com.google.android.material.card.MaterialCardView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center_vertical" android:gravity="center_vertical"
@ -33,5 +33,5 @@
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</androidx.cardview.widget.CardView> </com.google.android.material.card.MaterialCardView>
</LinearLayout> </LinearLayout>

@ -10,7 +10,7 @@
android:layout_marginBottom="2dp" android:layout_marginBottom="2dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:background="@null"> android:background="@null">
<androidx.cardview.widget.CardView <com.google.android.material.card.MaterialCardView
android:id="@+id/card_view" android:id="@+id/card_view"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -190,5 +190,5 @@
tools:ignore="RtlHardcoded" /> tools:ignore="RtlHardcoded" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView> </com.google.android.material.card.MaterialCardView>
</LinearLayout> </LinearLayout>

Loading…
Cancel
Save