@@ -55,12 +55,11 @@ public class MarkdownActivity extends CompatActivity {
5555 private static final String [] variants = new String []{
5656 "readme.md" , "README.MD" , ".github/README.md"
5757 };
58- private BlurView chipHolder ;
5958 private TextView actionBarPadding ;
59+ private ColorDrawable actionBarBackground ;
6060 private BlurView actionBarBlur ;
61- private ColorDrawable anyBarBackground ;
62- private ScrollView scrollView ;
63- private LinearLayout md_layout ;
61+ private TextView header ;
62+ private TextView footer ;
6463
6564 private static byte [] getRawMarkdown (String url ) throws IOException {
6665 String newUrl = redirects .get (url );
@@ -138,40 +137,23 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
138137 setContentView (R .layout .markdown_view );
139138 final ViewGroup markdownBackground = findViewById (R .id .markdownBackground );
140139 final TextView textView = findViewById (R .id .markdownView );
141- this .chipHolder = findViewById (R .id .chip_holder );
142- this .anyBarBackground = new ColorDrawable (Color .TRANSPARENT );
143140 this .actionBarPadding = findViewById (R .id .markdown_action_bar_padding );
141+ this .actionBarBackground = new ColorDrawable (Color .TRANSPARENT );
144142 this .actionBarBlur = findViewById (R .id .markdown_action_bar_blur );
145- this .scrollView = findViewById (R .id .scrollView2 );
146- this .md_layout = findViewById (R .id .md_layout );
147- final TextView footer = findViewById (R .id .markdownFooter );
148- UiThreadHandler .handler .postDelayed (() -> // Fix footer height
149- footer .setMinHeight (this .getNavigationBarHeight ()), 1L );
150- this .actionBarBlur .setBackground (this .anyBarBackground );
151- this .setupBlurView (this .chipHolder , markdownBackground , this .anyBarBackground );
152- this .setupBlurView (this .actionBarBlur , markdownBackground , this .anyBarBackground );
153- this .updateScreenInsets ();
154- this .updateUI ();
143+ this .header = findViewById (R .id .markdownHeader );
144+ this .footer = findViewById (R .id .markdownFooter );
145+ this .actionBarBlur .setBackground (this .actionBarBackground );
146+ this .setupBlurView (this .actionBarBlur , markdownBackground );
147+ UiThreadHandler .handler .post (() -> // Fix header/footer height
148+ this .updateScreenInsets (this .getResources ().getConfiguration ()));
155149
156150 // Really bad created (MSG by Der_Googler)
157- if (MainApplication .isChipsDisabled ()) {
158- this .chipHolder .setVisibility (View .GONE );
159- } else {
160- this .chipHolder .setPadding (0 ,0 ,0 ,this .getNavigationBarHeight ());
161- // set "message" to null to disable dialog
162- this .setChip (change_boot ,
163- getString (R .string .module_can_change_boot ),
164- "This module may change the boot image" );
165- this .setChip (needs_ramdisk ,
166- getString (R .string .module_needs_ramdisk ),
167- "This module need boot ramdisk to be installed" );
168- this .setChip (min_magisk , "Min. Magisk \" " + min_magisk + "\" " ,
169- null );
170- this .setChip (min_api , "Min. Android " + min_api ,
171- null );
172- this .setChip (max_api , "Max. Android " + max_api ,
173- null );
174- }
151+ // set "message" to null to disable dialog
152+ if (change_boot ) this .addChip (MarkdownChip .CHANGE_BOOT );
153+ if (needs_ramdisk ) this .addChip (MarkdownChip .NEED_RAMDISK );
154+ if (min_magisk != 0 ) this .addChip (MarkdownChip .MIN_MAGISK , String .valueOf (min_magisk ));
155+ if (min_api != 0 ) this .addChip (MarkdownChip .MIN_SDK , parseAndroidVersion (min_api ));
156+ if (max_api != 0 ) this .addChip (MarkdownChip .MAX_SDK , parseAndroidVersion (max_api ));
175157
176158 new Thread (() -> {
177159 try {
@@ -201,15 +183,37 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
201183 }, "Markdown load thread" ).start ();
202184 }
203185
204- private void setupBlurView (BlurView view , ViewGroup setupWith , ColorDrawable background ) {
205- view .setBackground (background );
186+ private void setupBlurView (BlurView view , ViewGroup setupWith ) {
206187 view .setupWith (setupWith ).setFrameClearDrawable (
207188 this .getWindow ().getDecorView ().getBackground ())
208189 .setBlurAlgorithm (new RenderScriptBlur (this ))
209190 .setBlurRadius (4F ).setBlurAutoUpdate (true )
210191 .setHasFixedTransformationMatrix (true );
192+ this .updateBlurState ();
211193 }
212194
195+ private void updateBlurState () {
196+ boolean isLightMode = this .isLightTheme ();
197+ int colorBackground ;
198+ try {
199+ colorBackground = this .getColorCompat (
200+ android .R .attr .windowBackground );
201+ } catch (Resources .NotFoundException e ) {
202+ colorBackground = this .getColorCompat (isLightMode ?
203+ R .color .white : R .color .black );
204+ }
205+ if (MainApplication .isBlurEnabled ()) {
206+ this .actionBarBlur .setBlurEnabled (true );
207+ this .actionBarBackground .setColor (ColorUtils
208+ .setAlphaComponent (colorBackground , 0x02 ));
209+ this .actionBarBackground .setColor (Color .TRANSPARENT );
210+ } else {
211+ this .actionBarBlur .setBlurEnabled (false );
212+ this .actionBarBlur .setOverlayColor (Color .TRANSPARENT );
213+ this .actionBarBackground .setColor (colorBackground );
214+ }
215+ }
216+
213217 private void updateScreenInsets () {
214218 this .runOnUiThread (() -> this .updateScreenInsets (
215219 this .getResources ().getConfiguration ()));
@@ -223,46 +227,33 @@ private void updateScreenInsets(Configuration configuration) {
223227 int actionBarHeight = getActionBarHeight ();
224228 int combinedBarsHeight = statusBarHeight + actionBarHeight ;
225229 this .actionBarPadding .setMinHeight (combinedBarsHeight );
230+ this .header .setMinHeight (combinedBarsHeight );
231+ this .footer .setMinHeight (bottomInset );
226232 //this.actionBarBlur.invalidate();
227233 }
228234
229- private void updateUI () {
230- boolean isLightMode = this .isLightTheme ();
231- int colorBackground ;
232- try {
233- colorBackground = this .getColorCompat (
234- android .R .attr .windowBackground );
235- } catch (Resources .NotFoundException e ) {
236- colorBackground = this .getColorCompat (isLightMode ?
237- R .color .white : R .color .black );
238- }
239- this .md_layout .setPadding (0 ,this .getActionBarHeight (this ) + this .getStatusBarHeight (),0 ,this .getNavigationBarHeight () + 56 );
240- if (MainApplication .isBlurEnabled ()) {
241- this .actionBarBlur .setLayoutParams (new ViewGroup .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , this .getActionBarHeight (this ) + this .getStatusBarHeight ()));
242- this .chipHolder .setBlurEnabled (true );
243- this .anyBarBackground .setColor (ColorUtils
244- .setAlphaComponent (colorBackground , 0x02 ));
245- this .anyBarBackground .setColor (Color .TRANSPARENT );
246- this .actionBarBlur .setBlurEnabled (true );
247- } else {
248- this .chipHolder .setBlurEnabled (false );
249- this .chipHolder .setOverlayColor (Color .TRANSPARENT );
250- this .anyBarBackground .setColor (colorBackground );
251- this .actionBarBlur .setBlurEnabled (false );
252- this .actionBarBlur .setOverlayColor (Color .TRANSPARENT );
253- }
235+ @ Override
236+ public void refreshUI () {
237+ super .refreshUI ();
238+ this .updateScreenInsets ();
239+ this .updateBlurState ();
254240 }
255241
256- private void setChip ( boolean bool , String title , String message ) {
257- if ( bool ) {
258- this .makeChip (title , message );
259- }
242+
243+ private void addChip ( MarkdownChip markdownChip ) {
244+ this .makeChip (this . getString ( markdownChip . title ),
245+ markdownChip . desc == 0 ? null : this . getString ( markdownChip . desc ));
260246 }
261247
262- private void setChip (int i , String title , String message ) {
263- if (i != 0 ) {
264- this .makeChip (title , message );
248+ private void addChip (MarkdownChip markdownChip , String extra ) {
249+ String title = this .getString (markdownChip .title );
250+ if (title .contains ("%s" )) {
251+ title = title .replace ("%s" , extra );
252+ } else {
253+ title = title + " " + extra ;
265254 }
255+ this .makeChip (title , markdownChip .desc == 0 ?
256+ null : this .getString (markdownChip .desc ));
266257 }
267258
268259 private void makeChip (String title , String message ) {
@@ -288,22 +279,32 @@ private void makeChip(String title, String message) {
288279
289280 private String parseAndroidVersion (int version ) {
290281 switch (version ) {
282+ case Build .VERSION_CODES .JELLY_BEAN :
283+ return "4.1 JellyBean" ;
284+ case Build .VERSION_CODES .JELLY_BEAN_MR1 :
285+ return "4.2 JellyBean" ;
286+ case Build .VERSION_CODES .JELLY_BEAN_MR2 :
287+ return "4.3 JellyBean" ;
288+ case Build .VERSION_CODES .KITKAT :
289+ return "4.4 KitKat" ;
290+ case Build .VERSION_CODES .KITKAT_WATCH :
291+ return "4.4 KitKat Watch" ;
291292 case Build .VERSION_CODES .LOLLIPOP :
292- return "5.0" ;
293+ return "5.0 Lollipop " ;
293294 case Build .VERSION_CODES .LOLLIPOP_MR1 :
294- return "5.1" ;
295+ return "5.1 Lollipop " ;
295296 case Build .VERSION_CODES .M :
296- return "6.0" ;
297+ return "6.0 Marshmallow " ;
297298 case Build .VERSION_CODES .N :
298- return "7.0" ;
299+ return "7.0 Nougat " ;
299300 case Build .VERSION_CODES .N_MR1 :
300- return "7.1" ;
301+ return "7.1 Nougat " ;
301302 case Build .VERSION_CODES .O :
302- return "8.0" ;
303+ return "8.0 Oreo " ;
303304 case Build .VERSION_CODES .O_MR1 :
304- return "8.1" ;
305+ return "8.1 Oreo " ;
305306 case Build .VERSION_CODES .P :
306- return "9.0 (P) " ;
307+ return "9.0 Pie " ;
307308 case Build .VERSION_CODES .Q :
308309 return "10 (Q)" ;
309310 case Build .VERSION_CODES .R :
@@ -313,7 +314,7 @@ private String parseAndroidVersion(int version) {
313314 case Build .VERSION_CODES .S_V2 :
314315 return "12L" ;
315316 default :
316- return "false" ;
317+ return "Sdk: " + version ;
317318 }
318319 }
319320
0 commit comments