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

pull/88/head
Fox2Code 2 years ago
parent 64427356fb
commit 495e1cc3e6

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

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.fox2code.mmm"
tools:ignore="QueryAllPackagesPermission">
<!-- 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.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);
}
}

@ -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,

@ -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");

@ -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">
<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:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shape="ring"
android:background="@null"
app:cardCornerRadius="75dp"
app:cardCornerRadius="@dimen/card_corner_radius"
app:cardPreventCornerOverlap="true"
app:strokeColor="@android:color/transparent"
app:cardElevation="0dp"
app:strokeWidth="0dp">
@ -75,7 +80,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null" />
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

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

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

Loading…
Cancel
Save