Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 495e1cc

Browse files
committed
Fixing android layout for older android devices, fix debug builds.
1 parent 6442735 commit 495e1cc

File tree

8 files changed

+83
-32
lines changed

8 files changed

+83
-32
lines changed

app/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ android {
3535
lint {
3636
disable 'MissingTranslation'
3737
}
38-
namespace 'com.fox2code.mmm'
3938
}
4039

4140
aboutLibraries {

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.fox2code.mmm"
45
tools:ignore="QueryAllPackagesPermission">
56

67
<!-- Wifi is not the only way to get an internet connection -->

app/src/main/java/com/fox2code/mmm/MainActivity.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import androidx.appcompat.widget.SearchView;
55
import androidx.cardview.widget.CardView;
66
import androidx.core.content.ContextCompat;
7+
import androidx.core.graphics.ColorUtils;
78
import androidx.recyclerview.widget.LinearLayoutManager;
89
import androidx.recyclerview.widget.RecyclerView;
910
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -22,6 +23,7 @@
2223
import android.widget.TextView;
2324

2425
import com.fox2code.mmm.compat.CompatActivity;
26+
import com.fox2code.mmm.compat.CompatDisplay;
2527
import com.fox2code.mmm.installer.InstallerInitializer;
2628
import com.fox2code.mmm.manager.LocalModuleInfo;
2729
import com.fox2code.mmm.manager.ModuleManager;
@@ -32,6 +34,7 @@
3234
import com.google.android.material.progressindicator.LinearProgressIndicator;
3335

3436
import eightbitlab.com.blurview.BlurView;
37+
import eightbitlab.com.blurview.BlurViewFacade;
3538
import eightbitlab.com.blurview.RenderScriptBlur;
3639

3740
public class MainActivity extends CompatActivity implements SwipeRefreshLayout.OnRefreshListener,
@@ -72,10 +75,8 @@ protected void onCreate(Bundle savedInstanceState) {
7275
setContentView(R.layout.activity_main);
7376
this.setTitle(R.string.app_name);
7477
this.getWindow().setFlags(
75-
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION |
76-
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
77-
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION |
78-
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
78+
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
79+
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
7980
setActionBarBackground(null);
8081
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
8182
WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes();
@@ -106,7 +107,7 @@ protected void onCreate(Bundle savedInstanceState) {
106107
this.actionBarBlur.setupWith(this.moduleList).setFrameClearDrawable(
107108
this.getWindow().getDecorView().getBackground())
108109
.setBlurAlgorithm(new RenderScriptBlur(this))
109-
.setBlurRadius(5F).setBlurAutoUpdate(true)
110+
.setBlurRadius(4F).setBlurAutoUpdate(true)
110111
.setHasFixedTransformationMatrix(true);
111112
this.updateBlurState();
112113
this.moduleList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@@ -116,6 +117,7 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
116117
MainActivity.this.searchView.clearFocus();
117118
}
118119
});
120+
this.searchView.setMinimumHeight(CompatDisplay.dpToPixel(16));
119121
this.searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH |
120122
EditorInfo.IME_FLAG_NO_FULLSCREEN);
121123
this.searchView.setOnQueryTextListener(this);
@@ -238,32 +240,37 @@ private void updateScreenInsets(Configuration configuration) {
238240
this.swipeRefreshLayout.setProgressViewOffset(false,
239241
swipeRefreshLayoutOrigStartOffset + combinedBarsHeight,
240242
swipeRefreshLayoutOrigEndOffset + combinedBarsHeight);
241-
this.moduleViewListBuilder.setHeaderPx(actionBarHeight);
243+
this.moduleViewListBuilder.setHeaderPx(
244+
actionBarHeight + CompatDisplay.dpToPixel(4));
242245
this.moduleViewListBuilder.setFooterPx(
243246
bottomInset + this.searchCard.getHeight());
244247
this.moduleViewListBuilder.updateInsets();
245248
this.actionBarBlur.invalidate();
246249
this.overScrollInsetTop = combinedBarsHeight;
247250
this.overScrollInsetBottom = bottomInset;
251+
Log.d(TAG, "( " + bottomInset + ", " +
252+
this.searchCard.getHeight() + ")");
248253
}
249254

250255
private void updateBlurState() {
256+
boolean isLightMode = this.isLightTheme();
257+
int colorBackground;
258+
try {
259+
colorBackground = this.getColorCompat(
260+
android.R.attr.windowBackground);
261+
} catch (Resources.NotFoundException e) {
262+
colorBackground = this.getColorCompat(isLightMode ?
263+
R.color.white : R.color.black);
264+
}
251265
if (MainApplication.isBlurEnabled()) {
252266
this.actionBarBlur.setBlurEnabled(true);
253-
int transparent = this.getColorCompat(R.color.transparent);
254-
this.actionBarBackground.setColor(transparent);
267+
this.actionBarBackground.setColor(ColorUtils
268+
.setAlphaComponent(colorBackground, 0x02));
269+
this.actionBarBackground.setColor(Color.TRANSPARENT);
255270
} else {
256271
this.actionBarBlur.setBlurEnabled(false);
257-
boolean isLightMode = this.isLightTheme();
258-
int colorOpaque;
259-
try {
260-
colorOpaque = this.getColorCompat(
261-
android.R.attr.windowBackground);
262-
} catch (Resources.NotFoundException e) {
263-
colorOpaque = this.getColorCompat(isLightMode ?
264-
R.color.white : R.color.black);
265-
}
266-
this.actionBarBackground.setColor(colorOpaque);
272+
this.actionBarBlur.setOverlayColor(Color.TRANSPARENT);
273+
this.actionBarBackground.setColor(colorBackground);
267274
}
268275
}
269276

app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
import android.os.Bundle;
1313
import android.util.Log;
1414
import android.util.TypedValue;
15+
import android.view.KeyCharacterMap;
16+
import android.view.KeyEvent;
1517
import android.view.Menu;
1618
import android.view.MenuItem;
1719
import android.view.View;
20+
import android.view.ViewConfiguration;
21+
import android.view.WindowManager;
1822

1923
import androidx.annotation.AttrRes;
2024
import androidx.annotation.CallSuper;
@@ -65,8 +69,10 @@ public boolean onBackPressed(CompatActivity compatActivity) {
6569
private MenuItem.OnMenuItemClickListener menuClickListener;
6670
private CharSequence menuContentDescription;
6771
@StyleRes private int setThemeDynamic = 0;
72+
private boolean onCreateCalledOnce = false;
6873
private boolean onCreateCalled = false;
6974
private boolean isRefreshUi = false;
75+
private boolean hasHardwareNavBar;
7076
private int drawableResId;
7177
private MenuItem menuItem;
7278
// CompatConfigHelper
@@ -82,6 +88,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
8288
if (!this.onCreateCalled) {
8389
this.getLayoutInflater().setFactory2(new LayoutInflaterFactory(this.getDelegate())
8490
.addOnViewCreatedListener(WindowInsetsHelper.Companion.getLISTENER()));
91+
this.hasHardwareNavBar = ViewConfiguration.get(this).hasPermanentMenuKey() ||
92+
KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
93+
this.onCreateCalledOnce = true;
8594
}
8695
Application application = this.getApplication();
8796
if (application instanceof ApplicationCallbacks) {
@@ -114,7 +123,7 @@ public void finish() {
114123
@CallSuper
115124
public void refreshUI() {
116125
// Avoid recursive calls
117-
if (this.isRefreshUi) return;
126+
if (this.isRefreshUi || !this.onCreateCalled) return;
118127
Application application = this.getApplication();
119128
if (application instanceof ApplicationCallbacks) {
120129
this.isRefreshUi = true;
@@ -196,6 +205,22 @@ public void showActionBar() {
196205
}
197206
}
198207

208+
public View getActionBarView() {
209+
androidx.appcompat.app.ActionBar compatActionBar;
210+
try {
211+
compatActionBar = this.getSupportActionBar();
212+
} catch (Exception e) {
213+
Log.e(TAG, "Failed to call getSupportActionBar", e);
214+
compatActionBar = null; // Allow fallback to builtin actionBar.
215+
}
216+
if (compatActionBar != null) {
217+
return compatActionBar.getCustomView();
218+
} else {
219+
android.app.ActionBar actionBar = this.getActionBar();
220+
return actionBar != null ? actionBar.getCustomView() : null;
221+
}
222+
}
223+
199224
@Dimension @Px
200225
public int getActionBarHeight() {
201226
androidx.appcompat.app.ActionBar compatActionBar;
@@ -242,21 +267,31 @@ public int getStatusBarHeight() { // How to improve this?
242267
return height;
243268
}
244269

245-
public int getNavigationBarHeight() { // How to improve this?
270+
public int getNavigationBarHeight() {
246271
int height = WindowInsetsCompat.CONSUMED.getInsets(
247272
WindowInsetsCompat.Type.navigationBars()).bottom;
248273
if (height == 0) { // Fallback to system resources
249274
int id = Resources.getSystem().getIdentifier(
250275
"config_showNavigationBar", "bool", "android");
251-
if (id > 0 && Resources.getSystem().getBoolean(id)) {
276+
Log.d(TAG, "Nav 1: " + id);
277+
if ((id > 0 && Resources.getSystem().getBoolean(id))
278+
|| !this.hasHardwareNavBar()) {
252279
id = Resources.getSystem().getIdentifier(
253280
"navigation_bar_height", "dimen", "android");
281+
Log.d(TAG, "Nav 2: " + id);
254282
if (id > 0) return Resources.getSystem().getDimensionPixelSize(id);
255283
}
256284
}
257285
return height;
258286
}
259287

288+
public boolean hasHardwareNavBar() {
289+
// If onCreate has not been called yet, cached value is not valid
290+
return this.onCreateCalledOnce ? this.hasHardwareNavBar :
291+
ViewConfiguration.get(this).hasPermanentMenuKey() ||
292+
KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
293+
}
294+
260295
public void setActionBarExtraMenuButton(@DrawableRes int drawableResId,
261296
MenuItem.OnMenuItemClickListener menuClickListener) {
262297
this.setActionBarExtraMenuButton(drawableResId,

app/src/main/java/com/fox2code/mmm/markdown/MarkdownActivity.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.fox2code.mmm.compat.CompatActivity;
1919
import com.fox2code.mmm.utils.Http;
2020
import com.fox2code.mmm.utils.IntentHelper;
21+
import com.topjohnwu.superuser.internal.UiThreadHandler;
2122

2223
import java.io.IOException;
2324
import java.nio.charset.StandardCharsets;
@@ -64,8 +65,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
6465
}
6566
Log.i(TAG, "Url for markdown " + url);
6667
setContentView(R.layout.markdown_view);
67-
ViewGroup markdownBackground = findViewById(R.id.markdownBackground);
68-
TextView textView = findViewById(R.id.markdownView);
68+
final ViewGroup markdownBackground = findViewById(R.id.markdownBackground);
69+
final TextView textView = findViewById(R.id.markdownView);
70+
final TextView footer = findViewById(R.id.markdownFooter);
71+
UiThreadHandler.handler.postDelayed(() -> // Fix footer height
72+
footer.setMinHeight(this.getNavigationBarHeight()), 1L);
6973
new Thread(() -> {
7074
try {
7175
Log.d(TAG, "Downloading");

app/src/main/res/layout/activity_main.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,21 @@
5757
android:gravity="right"
5858
app:layout_constraintRight_toRightOf="parent"
5959
app:layout_constraintBottom_toBottomOf="parent"
60-
app:fitsSystemWindowsInsets="bottom"
60+
app:layout_fitsSystemWindowsInsets="bottom"
6161
tools:ignore="RtlHardcoded">
62-
<androidx.cardview.widget.CardView
62+
<!--
63+
setting high app:cardCornerRadius is not supported on some versions
64+
so we must use code to get a round appearance.
65+
-->
66+
<com.google.android.material.card.MaterialCardView
6367
android:id="@+id/search_card"
6468
android:layout_gravity="center"
6569
android:layout_width="wrap_content"
6670
android:layout_height="wrap_content"
6771
android:shape="ring"
6872
android:background="@null"
69-
app:cardCornerRadius="75dp"
73+
app:cardCornerRadius="@dimen/card_corner_radius"
74+
app:cardPreventCornerOverlap="true"
7075
app:strokeColor="@android:color/transparent"
7176
app:cardElevation="0dp"
7277
app:strokeWidth="0dp">
@@ -75,7 +80,7 @@
7580
android:layout_width="match_parent"
7681
android:layout_height="wrap_content"
7782
android:background="@null" />
78-
</androidx.cardview.widget.CardView>
83+
</com.google.android.material.card.MaterialCardView>
7984
</LinearLayout>
8085

8186
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/markdown_view.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
android:background="@color/black"
88
android:id="@+id/markdownBackground"
99
app:fitsSystemWindowsInsets="top|left|right">
10-
<androidx.cardview.widget.CardView
10+
<com.google.android.material.card.MaterialCardView
1111
android:layout_width="match_parent"
1212
android:layout_height="match_parent"
1313
android:gravity="center_vertical"
@@ -33,5 +33,5 @@
3333
android:layout_height="wrap_content" />
3434
</LinearLayout>
3535
</ScrollView>
36-
</androidx.cardview.widget.CardView>
36+
</com.google.android.material.card.MaterialCardView>
3737
</LinearLayout>

app/src/main/res/layout/module_entry.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
android:layout_marginBottom="2dp"
1111
android:gravity="center_vertical"
1212
android:background="@null">
13-
<androidx.cardview.widget.CardView
13+
<com.google.android.material.card.MaterialCardView
1414
android:id="@+id/card_view"
1515
android:layout_gravity="center"
1616
android:layout_width="match_parent"
@@ -190,5 +190,5 @@
190190
tools:ignore="RtlHardcoded" />
191191
</androidx.constraintlayout.widget.ConstraintLayout>
192192
</androidx.constraintlayout.widget.ConstraintLayout>
193-
</androidx.cardview.widget.CardView>
193+
</com.google.android.material.card.MaterialCardView>
194194
</LinearLayout>

0 commit comments

Comments
 (0)