77import androidx .recyclerview .widget .RecyclerView ;
88import androidx .swiperefreshlayout .widget .SwipeRefreshLayout ;
99
10+ import android .content .res .Configuration ;
1011import android .content .res .Resources ;
12+ import android .os .Build ;
1113import android .os .Bundle ;
1214import android .util .Log ;
1315import android .util .TypedValue ;
1416import android .view .View ;
1517import android .view .WindowManager ;
1618import android .view .inputmethod .EditorInfo ;
19+ import android .widget .TextView ;
1720
1821import com .fox2code .mmm .compat .CompatActivity ;
1922import com .fox2code .mmm .installer .InstallerInitializer ;
2528import com .fox2code .mmm .utils .IntentHelper ;
2629import com .google .android .material .progressindicator .LinearProgressIndicator ;
2730
31+ import eightbitlab .com .blurview .BlurView ;
32+ import eightbitlab .com .blurview .RenderScriptBlur ;
33+
2834public class MainActivity extends CompatActivity implements SwipeRefreshLayout .OnRefreshListener ,
29- SearchView .OnQueryTextListener , SearchView .OnCloseListener {
35+ SearchView .OnQueryTextListener , SearchView .OnCloseListener ,
36+ OverScrollManager .OverScrollHelper {
3037 private static final String TAG = "MainActivity" ;
3138 private static final int PRECISION = 10000 ;
3239 public final ModuleViewListBuilder moduleViewListBuilder ;
3340 public LinearProgressIndicator progressIndicator ;
3441 private ModuleViewAdapter moduleViewAdapter ;
3542 private SwipeRefreshLayout swipeRefreshLayout ;
43+ private int swipeRefreshLayoutOrigStartOffset ;
44+ private int swipeRefreshLayoutOrigEndOffset ;
3645 private long swipeRefreshBlocker = 0 ;
46+ private int overScrollInsetTop ;
47+ private int overScrollInsetBottom ;
48+ private TextView actionBarPadding ;
49+ private BlurView actionBarBlur ;
3750 private RecyclerView moduleList ;
3851 private CardView searchCard ;
3952 private SearchView searchView ;
@@ -55,10 +68,25 @@ protected void onCreate(Bundle savedInstanceState) {
5568 setContentView (R .layout .activity_main );
5669 this .setTitle (R .string .app_name );
5770 this .getWindow ().setFlags (
58- WindowManager .LayoutParams .FLAG_TRANSLUCENT_NAVIGATION ,
59- WindowManager .LayoutParams .FLAG_TRANSLUCENT_NAVIGATION );
71+ WindowManager .LayoutParams .FLAG_TRANSLUCENT_NAVIGATION |
72+ WindowManager .LayoutParams .FLAG_LAYOUT_NO_LIMITS ,
73+ WindowManager .LayoutParams .FLAG_TRANSLUCENT_NAVIGATION |
74+ WindowManager .LayoutParams .FLAG_LAYOUT_NO_LIMITS );
75+ setActionBarBackground (null );
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 );
@@ -67,7 +95,13 @@ protected void onCreate(Bundle savedInstanceState) {
6795 this .moduleList .setAdapter (this .moduleViewAdapter );
6896 this .moduleList .setLayoutManager (new LinearLayoutManager (this ));
6997 this .moduleList .setItemViewCacheSize (4 ); // Default is 2
98+ OverScrollManager .install (this .moduleList , this );
7099 this .swipeRefreshLayout .setOnRefreshListener (this );
100+ this .actionBarBlur .setupWith (this .moduleList ).setFrameClearDrawable (
101+ this .getWindow ().getDecorView ().getBackground ())
102+ .setBlurAlgorithm (new RenderScriptBlur (this ))
103+ .setBlurRadius (5F ).setBlurAutoUpdate (true )
104+ .setHasFixedTransformationMatrix (true );
71105 this .moduleList .addOnScrollListener (new RecyclerView .OnScrollListener () {
72106 @ Override
73107 public void onScrollStateChanged (@ NonNull RecyclerView recyclerView , int newState ) {
@@ -76,7 +110,7 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
76110 }
77111 });
78112 this .searchView .setImeOptions (EditorInfo .IME_ACTION_SEARCH |
79- EditorInfo .IME_FLAG_NO_FULLSCREEN | EditorInfo . IME_FLAG_FORCE_ASCII );
113+ EditorInfo .IME_FLAG_NO_FULLSCREEN );
80114 this .searchView .setOnQueryTextListener (this );
81115 this .searchView .setOnCloseListener (this );
82116 this .searchView .setOnQueryTextFocusChangeListener ((v , h ) -> {
@@ -121,6 +155,8 @@ public void commonNext() {
121155 runOnUiThread (() -> {
122156 progressIndicator .setIndeterminate (false );
123157 progressIndicator .setMax (PRECISION );
158+ // Fix insets not being accounted for correctly
159+ updateScreenInsets (getResources ().getConfiguration ());
124160 });
125161 Log .i (TAG , "Scanning for modules!" );
126162 final int max = ModuleManager .getINSTANCE ().getUpdatableModuleCount ();
@@ -158,6 +194,7 @@ public void commonNext() {
158194 progressIndicator .setProgressCompat (PRECISION , true );
159195 progressIndicator .setVisibility (View .GONE );
160196 searchView .setEnabled (true );
197+ setActionBarBackground (null );
161198 });
162199 moduleViewListBuilder .appendRemoteModules ();
163200 moduleViewListBuilder .applyTo (moduleList , moduleViewAdapter );
@@ -175,12 +212,32 @@ private void cardIconifyUpdate() {
175212 TypedValue value = new TypedValue ();
176213 theme .resolveAttribute (backgroundAttr , value , true );
177214 this .searchCard .setCardBackgroundColor (value .data );
178- this .searchCard .setAlpha (iconified ? 0.70F : 1F );
215+ this .searchCard .setAlpha (iconified ? 0.80F : 1F );
179216 }
180217
181218 private void updateScreenInsets () {
219+ this .runOnUiThread (() -> this .updateScreenInsets (
220+ this .getResources ().getConfiguration ()));
221+ }
222+
223+ private void updateScreenInsets (Configuration configuration ) {
224+ boolean landscape = configuration .orientation ==
225+ Configuration .ORIENTATION_LANDSCAPE ;
226+ int statusBarHeight = getStatusBarHeight ();
227+ int actionBarHeight = getActionBarHeight ();
228+ int combinedBarsHeight = statusBarHeight + actionBarHeight ;
229+ this .actionBarPadding .setMinHeight (combinedBarsHeight );
230+ this .swipeRefreshLayout .setProgressViewOffset (false ,
231+ swipeRefreshLayoutOrigStartOffset + combinedBarsHeight ,
232+ swipeRefreshLayoutOrigEndOffset + combinedBarsHeight );
233+ this .moduleViewListBuilder .setHeaderPx (actionBarHeight );
234+ int bottomInset = (landscape ? 0 : this .getNavigationBarHeight ());
182235 this .moduleViewListBuilder .setFooterPx (
183- this .getNavigationBarHeight () + this .searchCard .getHeight ());
236+ bottomInset + this .searchCard .getHeight ());
237+ this .moduleViewListBuilder .updateInsets ();
238+ this .actionBarBlur .invalidate ();
239+ this .overScrollInsetTop = combinedBarsHeight ;
240+ this .overScrollInsetBottom = bottomInset ;
184241 }
185242
186243 @ Override
@@ -234,6 +291,12 @@ else if (AppUpdateManager.getAppUpdateManager().checkUpdate(false))
234291 this .initMode = false ;
235292 }
236293
294+ @ Override
295+ public void onConfigurationChanged (@ NonNull Configuration newConfig ) {
296+ this .updateScreenInsets (newConfig );
297+ super .onConfigurationChanged (newConfig );
298+ }
299+
237300 @ Override
238301 public void onRefresh () {
239302 if (this .swipeRefreshBlocker > System .currentTimeMillis () ||
@@ -301,4 +364,14 @@ public boolean onClose() {
301364 }
302365 return false ;
303366 }
367+
368+ @ Override
369+ public int getOverScrollInsetTop () {
370+ return this .overScrollInsetTop ;
371+ }
372+
373+ @ Override
374+ public int getOverScrollInsetBottom () {
375+ return this .overScrollInsetBottom ;
376+ }
304377}
0 commit comments