22
33import android .content .Intent ;
44import android .content .pm .PackageManager ;
5+ import android .content .res .Configuration ;
6+ import android .content .res .Resources ;
57import android .graphics .Color ;
8+ import android .graphics .drawable .ColorDrawable ;
9+ import android .os .Build ;
610import android .os .Bundle ;
711import android .util .Log ;
812import android .view .View ;
13+ import android .view .ViewConfiguration ;
914import android .view .ViewGroup ;
15+ import android .view .ViewTreeObserver ;
1016import android .view .WindowManager ;
1117import android .widget .HorizontalScrollView ;
18+ import android .widget .LinearLayout ;
19+ import android .widget .ScrollView ;
1220import android .widget .TextView ;
1321import android .widget .Toast ;
1422
2129import com .fox2code .mmm .R ;
2230import com .fox2code .mmm .XHooks ;
2331import com .fox2code .mmm .compat .CompatActivity ;
32+ import com .fox2code .mmm .compat .CompatDisplay ;
2433import com .fox2code .mmm .utils .Http ;
2534import com .fox2code .mmm .utils .IntentHelper ;
2635import com .google .android .material .chip .Chip ;
3443import java .util .HashMap ;
3544
3645import eightbitlab .com .blurview .BlurView ;
46+ import eightbitlab .com .blurview .RenderScriptBlur ;
3747
3848
3949public class MarkdownActivity extends CompatActivity {
@@ -42,6 +52,12 @@ public class MarkdownActivity extends CompatActivity {
4252 private static final String [] variants = new String []{
4353 "readme.md" , "README.MD" , ".github/README.md"
4454 };
55+ private BlurView chipHolder ;
56+ private TextView actionBarPadding ;
57+ private BlurView actionBarBlur ;
58+ private ColorDrawable anyBarBackground ;
59+ private ScrollView scrollView ;
60+ private LinearLayout md_layout ;
4561
4662 private static byte [] getRawMarkdown (String url ) throws IOException {
4763 String newUrl = redirects .get (url );
@@ -119,27 +135,38 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
119135 setContentView (R .layout .markdown_view );
120136 final ViewGroup markdownBackground = findViewById (R .id .markdownBackground );
121137 final TextView textView = findViewById (R .id .markdownView );
122- final HorizontalScrollView chip_holder = findViewById (R .id .chip_holder );
138+ this .chipHolder = findViewById (R .id .chip_holder );
139+ this .anyBarBackground = new ColorDrawable (Color .TRANSPARENT );
140+ this .actionBarPadding = findViewById (R .id .markdown_action_bar_padding );
141+ this .actionBarBlur = findViewById (R .id .markdown_action_bar_blur );
142+ this .scrollView = findViewById (R .id .scrollView2 );
143+ this .md_layout = findViewById (R .id .md_layout );
123144 final TextView footer = findViewById (R .id .markdownFooter );
124145 UiThreadHandler .handler .postDelayed (() -> // Fix footer height
125146 footer .setMinHeight (this .getNavigationBarHeight ()), 1L );
147+ this .actionBarBlur .setBackground (this .anyBarBackground );
148+ this .setupBlurView (this .chipHolder , markdownBackground , this .anyBarBackground );
149+ this .setupBlurView (this .actionBarBlur , markdownBackground , this .anyBarBackground );
150+ this .updateScreenInsets ();
151+ this .updateUI ();
126152
127- // Really bad created
153+ // Really bad created (MSG by Der_Googler)
128154 if (MainApplication .isChipsDisabled ()) {
129- chip_holder .setVisibility (View .GONE );
155+ this . chipHolder .setVisibility (View .GONE );
130156 } else {
157+ this .chipHolder .setPadding (0 ,0 ,0 ,this .getNavigationBarHeight ());
131158 // set "message" to null to disable dialog
132- this .setChips (change_boot ,
159+ this .setChip (change_boot ,
133160 getString (R .string .module_can_change_boot ),
134161 "This module may change the boot image" );
135- this .setChips (needs_ramdisk ,
162+ this .setChip (needs_ramdisk ,
136163 getString (R .string .module_needs_ramdisk ),
137164 "This module need boot ramdisk to be installed" );
138- this .setChips (min_magisk , "Min. Magisk \" " + min_magisk + "\" " ,
165+ this .setChip (min_magisk , "Min. Magisk \" " + min_magisk + "\" " ,
139166 null );
140- this .setChips (min_api , "Min. Android " + min_api ,
167+ this .setChip (min_api , "Min. Android " + min_api ,
141168 null );
142- this .setChips (max_api , "Max. Android " + max_api ,
169+ this .setChip (max_api , "Max. Android " + max_api ,
143170 null );
144171 }
145172
@@ -171,53 +198,121 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
171198 }, "Markdown load thread" ).start ();
172199 }
173200
174- private void setChips (boolean bool , String title , String message ) {
175- final ChipGroup chip_group_holder = findViewById (R .id .chip_group_holder );
201+ private void setupBlurView (BlurView view , ViewGroup setupWith , ColorDrawable background ) {
202+ view .setBackground (background );
203+ view .setupWith (setupWith ).setFrameClearDrawable (
204+ this .getWindow ().getDecorView ().getBackground ())
205+ .setBlurAlgorithm (new RenderScriptBlur (this ))
206+ .setBlurRadius (4F ).setBlurAutoUpdate (true )
207+ .setHasFixedTransformationMatrix (true );
208+ }
209+
210+ private void updateScreenInsets () {
211+ this .runOnUiThread (() -> this .updateScreenInsets (
212+ this .getResources ().getConfiguration ()));
213+ }
214+
215+ private void updateScreenInsets (Configuration configuration ) {
216+ boolean landscape = configuration .orientation ==
217+ Configuration .ORIENTATION_LANDSCAPE ;
218+ int bottomInset = (landscape ? 0 : this .getNavigationBarHeight ());
219+ int statusBarHeight = getStatusBarHeight ();
220+ int actionBarHeight = getActionBarHeight ();
221+ int combinedBarsHeight = statusBarHeight + actionBarHeight ;
222+ this .actionBarPadding .setMinHeight (combinedBarsHeight );
223+ //this.actionBarBlur.invalidate();
224+ }
225+
226+ private void updateUI () {
227+ boolean isLightMode = this .isLightTheme ();
228+ int colorBackground ;
229+ try {
230+ colorBackground = this .getColorCompat (
231+ android .R .attr .windowBackground );
232+ } catch (Resources .NotFoundException e ) {
233+ colorBackground = this .getColorCompat (isLightMode ?
234+ R .color .white : R .color .black );
235+ }
236+ this .md_layout .setPadding (0 ,this .getActionBarHeight (this ) + this .getStatusBarHeight (),0 ,this .getNavigationBarHeight () + 56 );
237+ if (MainApplication .isBlurEnabled ()) {
238+ this .actionBarBlur .setLayoutParams (new ViewGroup .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , this .getActionBarHeight (this ) + this .getStatusBarHeight ()));
239+ this .chipHolder .setBlurEnabled (true );
240+ this .anyBarBackground .setColor (ColorUtils
241+ .setAlphaComponent (colorBackground , 0x02 ));
242+ this .anyBarBackground .setColor (Color .TRANSPARENT );
243+ this .actionBarBlur .setBlurEnabled (true );
244+ } else {
245+ this .chipHolder .setBlurEnabled (false );
246+ this .chipHolder .setOverlayColor (Color .TRANSPARENT );
247+ this .anyBarBackground .setColor (colorBackground );
248+ this .actionBarBlur .setBlurEnabled (false );
249+ this .actionBarBlur .setOverlayColor (Color .TRANSPARENT );
250+ }
251+ }
252+
253+ private void setChip (boolean bool , String title , String message ) {
176254 if (bool ) {
177- Chip chip = new Chip (this );
178- chip .setText (title );
179- chip .setVisibility (View .VISIBLE );
180- if (message != null ) {
181- chip .setOnClickListener (_view -> {
182- MaterialAlertDialogBuilder builder =
183- new MaterialAlertDialogBuilder (this );
184-
185- builder
186- .setTitle (title )
187- .setMessage (message )
188- .setCancelable (true )
189- .setPositiveButton (R .string .ok , (x , y ) -> {
190- x .dismiss ();
191- }).show ();
255+ this .makeChip (title , message );
256+ }
257+ }
192258
193- });
194- }
195- chip_group_holder . addView ( chip );
259+ private void setChip ( int i , String title , String message ) {
260+ if ( i != 0 ) {
261+ this . makeChip ( title , message );
196262 }
197263 }
198264
199- private void setChips ( int i , String title , String message ) {
265+ private void makeChip ( String title , String message ) {
200266 final ChipGroup chip_group_holder = findViewById (R .id .chip_group_holder );
201- if (i != 0 ) {
202- Chip chip = new Chip (this );
203- chip .setText (title );
204- chip .setVisibility (View .VISIBLE );
205- if (message != null ) {
206- chip .setOnClickListener (_view -> {
207- MaterialAlertDialogBuilder builder =
208- new MaterialAlertDialogBuilder (this );
209-
210- builder
211- .setTitle (title )
212- .setMessage (message )
213- .setCancelable (true )
214- .setPositiveButton (R .string .ok , (x , y ) -> {
215- x .dismiss ();
216- }).show ();
267+ Chip chip = new Chip (this );
268+ chip .setText (title );
269+ chip .setVisibility (View .VISIBLE );
270+ if (message != null ) {
271+ chip .setOnClickListener (_view -> {
272+ MaterialAlertDialogBuilder builder =
273+ new MaterialAlertDialogBuilder (this );
217274
218- });
219- }
220- chip_group_holder .addView (chip );
275+ builder
276+ .setTitle (title )
277+ .setMessage (message )
278+ .setCancelable (true )
279+ .setPositiveButton (R .string .ok , (x , y ) -> {
280+ x .dismiss ();
281+ }).show ();
282+
283+ });
284+ }
285+ chip_group_holder .addView (chip );
286+ }
287+
288+ private String parseAndroidVersion (int version ) {
289+ switch (version ) {
290+ case Build .VERSION_CODES .LOLLIPOP :
291+ return "5.0" ;
292+ case Build .VERSION_CODES .LOLLIPOP_MR1 :
293+ return "5.1" ;
294+ case Build .VERSION_CODES .M :
295+ return "6.0" ;
296+ case Build .VERSION_CODES .N :
297+ return "7.0" ;
298+ case Build .VERSION_CODES .N_MR1 :
299+ return "7.1" ;
300+ case Build .VERSION_CODES .O :
301+ return "8.0" ;
302+ case Build .VERSION_CODES .O_MR1 :
303+ return "8.1" ;
304+ case Build .VERSION_CODES .P :
305+ return "9.0 (P)" ;
306+ case Build .VERSION_CODES .Q :
307+ return "10 (Q)" ;
308+ case Build .VERSION_CODES .R :
309+ return "11 (R)" ;
310+ case Build .VERSION_CODES .S :
311+ return "12 (S)" ;
312+ case Build .VERSION_CODES .S_V2 :
313+ return "12L" ;
314+ default :
315+ return "false" ;
221316 }
222317 }
223318
0 commit comments