33import androidx .annotation .NonNull ;
44import androidx .appcompat .widget .SearchView ;
55import androidx .cardview .widget .CardView ;
6+ import androidx .core .view .WindowInsetsCompat ;
67import androidx .recyclerview .widget .LinearLayoutManager ;
78import androidx .recyclerview .widget .RecyclerView ;
89import androidx .swiperefreshlayout .widget .SwipeRefreshLayout ;
910
11+ import android .content .res .Configuration ;
1012import android .content .res .Resources ;
13+ import android .graphics .PixelFormat ;
14+ import android .os .Build ;
1115import android .os .Bundle ;
1216import android .util .Log ;
1317import android .util .TypedValue ;
1418import android .view .View ;
19+ import android .view .ViewGroup ;
20+ import android .view .Window ;
1521import android .view .WindowManager ;
1622import android .view .inputmethod .EditorInfo ;
23+ import android .widget .TextView ;
1724
1825import com .fox2code .mmm .compat .CompatActivity ;
1926import com .fox2code .mmm .installer .InstallerInitializer ;
2532import com .fox2code .mmm .utils .IntentHelper ;
2633import com .google .android .material .progressindicator .LinearProgressIndicator ;
2734
35+ import eightbitlab .com .blurview .BlurView ;
36+ import eightbitlab .com .blurview .RenderScriptBlur ;
37+
2838public class MainActivity extends CompatActivity implements SwipeRefreshLayout .OnRefreshListener ,
2939 SearchView .OnQueryTextListener , SearchView .OnCloseListener {
3040 private static final String TAG = "MainActivity" ;
@@ -33,7 +43,11 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O
3343 public LinearProgressIndicator progressIndicator ;
3444 private ModuleViewAdapter moduleViewAdapter ;
3545 private SwipeRefreshLayout swipeRefreshLayout ;
46+ private int swipeRefreshLayoutOrigStartOffset ;
47+ private int swipeRefreshLayoutOrigEndOffset ;
3648 private long swipeRefreshBlocker = 0 ;
49+ private TextView actionBarPadding ;
50+ private BlurView actionBarBlur ;
3751 private RecyclerView moduleList ;
3852 private CardView searchCard ;
3953 private SearchView searchView ;
@@ -55,10 +69,24 @@ protected void onCreate(Bundle savedInstanceState) {
5569 setContentView (R .layout .activity_main );
5670 this .setTitle (R .string .app_name );
5771 this .getWindow ().setFlags (
58- WindowManager .LayoutParams .FLAG_TRANSLUCENT_NAVIGATION ,
59- WindowManager .LayoutParams .FLAG_TRANSLUCENT_NAVIGATION );
72+ WindowManager .LayoutParams .FLAG_TRANSLUCENT_NAVIGATION |
73+ WindowManager .LayoutParams .FLAG_TRANSLUCENT_STATUS ,
74+ WindowManager .LayoutParams .FLAG_TRANSLUCENT_NAVIGATION |
75+ WindowManager .LayoutParams .FLAG_TRANSLUCENT_STATUS );
76+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
77+ WindowManager .LayoutParams layoutParams = this .getWindow ().getAttributes ();
78+ layoutParams .layoutInDisplayCutoutMode = // Support cutout in Android 9
79+ WindowManager .LayoutParams .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES ;
80+ this .getWindow ().setAttributes (layoutParams );
81+ }
82+ this .actionBarPadding = findViewById (R .id .action_bar_padding );
83+ this .actionBarBlur = findViewById (R .id .action_bar_blur );
6084 this .progressIndicator = findViewById (R .id .progress_bar );
6185 this .swipeRefreshLayout = findViewById (R .id .swipe_refresh );
86+ this .swipeRefreshLayoutOrigStartOffset =
87+ this .swipeRefreshLayout .getProgressViewStartOffset ();
88+ this .swipeRefreshLayoutOrigEndOffset =
89+ this .swipeRefreshLayout .getProgressViewEndOffset ();
6290 this .swipeRefreshBlocker = Long .MAX_VALUE ;
6391 this .moduleList = findViewById (R .id .module_list );
6492 this .searchCard = findViewById (R .id .search_card );
@@ -68,6 +96,11 @@ protected void onCreate(Bundle savedInstanceState) {
6896 this .moduleList .setLayoutManager (new LinearLayoutManager (this ));
6997 this .moduleList .setItemViewCacheSize (4 ); // Default is 2
7098 this .swipeRefreshLayout .setOnRefreshListener (this );
99+ this .actionBarBlur .setupWith (this .moduleList ).setFrameClearDrawable (
100+ this .getWindow ().getDecorView ().getBackground ())
101+ .setBlurAlgorithm (new RenderScriptBlur (this ))
102+ .setBlurRadius (5F ).setBlurAutoUpdate (true )
103+ .setHasFixedTransformationMatrix (true );
71104 this .moduleList .addOnScrollListener (new RecyclerView .OnScrollListener () {
72105 @ Override
73106 public void onScrollStateChanged (@ NonNull RecyclerView recyclerView , int newState ) {
@@ -158,6 +191,7 @@ public void commonNext() {
158191 progressIndicator .setProgressCompat (PRECISION , true );
159192 progressIndicator .setVisibility (View .GONE );
160193 searchView .setEnabled (true );
194+ setActionBarBackground (null );
161195 });
162196 moduleViewListBuilder .appendRemoteModules ();
163197 moduleViewListBuilder .applyTo (moduleList , moduleViewAdapter );
@@ -175,12 +209,29 @@ private void cardIconifyUpdate() {
175209 TypedValue value = new TypedValue ();
176210 theme .resolveAttribute (backgroundAttr , value , true );
177211 this .searchCard .setCardBackgroundColor (value .data );
178- this .searchCard .setAlpha (iconified ? 0.70F : 1F );
212+ this .searchCard .setAlpha (iconified ? 0.80F : 1F );
179213 }
180214
181215 private void updateScreenInsets () {
182- this .moduleViewListBuilder .setFooterPx (
183- this .getNavigationBarHeight () + this .searchCard .getHeight ());
216+ this .runOnUiThread (() -> this .updateScreenInsets (
217+ this .getResources ().getConfiguration ()));
218+ }
219+
220+ private void updateScreenInsets (Configuration configuration ) {
221+ boolean landscape = configuration .orientation ==
222+ Configuration .ORIENTATION_LANDSCAPE ;
223+ int statusBarHeight = getStatusBarHeight ();
224+ int actionBarHeight = getActionBarHeight ();
225+ int combinedBarsHeight = statusBarHeight + actionBarHeight ;
226+ this .actionBarPadding .setMinHeight (combinedBarsHeight );
227+ this .swipeRefreshLayout .setProgressViewOffset (false ,
228+ swipeRefreshLayoutOrigStartOffset + combinedBarsHeight ,
229+ swipeRefreshLayoutOrigEndOffset + combinedBarsHeight );
230+ this .moduleViewListBuilder .setHeaderPx (actionBarHeight );
231+ this .moduleViewListBuilder .setFooterPx ((landscape ? 0 :
232+ this .getNavigationBarHeight ()) + this .searchCard .getHeight ());
233+ this .moduleViewListBuilder .updateInsets ();
234+ this .actionBarBlur .invalidate ();
184235 }
185236
186237 @ Override
@@ -234,6 +285,12 @@ else if (AppUpdateManager.getAppUpdateManager().checkUpdate(false))
234285 this .initMode = false ;
235286 }
236287
288+ @ Override
289+ public void onConfigurationChanged (@ NonNull Configuration newConfig ) {
290+ this .updateScreenInsets (newConfig );
291+ super .onConfigurationChanged (newConfig );
292+ }
293+
237294 @ Override
238295 public void onRefresh () {
239296 if (this .swipeRefreshBlocker > System .currentTimeMillis () ||
0 commit comments