99import android .util .Base64 ;
1010import android .util .Log ;
1111import android .view .View ;
12+ import android .view .ViewGroup ;
13+ import android .view .Window ;
1214import android .webkit .DownloadListener ;
1315import android .webkit .JavascriptInterface ;
1416import android .webkit .ValueCallback ;
1719import android .webkit .WebSettings ;
1820import android .webkit .WebView ;
1921import android .webkit .WebViewClient ;
22+ import android .widget .LinearLayout ;
2023import android .widget .Toast ;
2124
2225import com .samsung .microbit .BuildConfig ;
3134
3235import static android .content .ContentValues .TAG ;
3336
37+ import androidx .core .graphics .Insets ;
38+ import androidx .core .view .ViewCompat ;
3439import androidx .core .view .WindowCompat ;
40+ import androidx .core .view .WindowInsetsCompat ;
41+ import androidx .core .view .WindowInsetsControllerCompat ;
3542
3643/**
3744 * Displays MakeCode
@@ -54,19 +61,35 @@ public class MakeCodeWebView extends Activity implements View.OnClickListener {
5461 private boolean mRelaunchOnFinishNavigation = false ;
5562 private String mRelaunchURL = makecodeUrl ;
5663
57-
5864 public static void setMakecodeUrl (String url ) {
5965 makecodeUrl = url ;
6066 }
6167
68+ protected void showSystemBars ( boolean show ) {
69+ WindowInsetsControllerCompat wIC =
70+ WindowCompat .getInsetsController (getWindow (), getWindow ().getDecorView ());
71+ if (wIC == null ) {
72+ return ;
73+ }
74+
75+ int type = WindowInsetsCompat .Type .statusBars ();
76+ if (show ) {
77+ wIC .show (type );
78+ } else {
79+ wIC .hide (type );
80+ }
81+ }
82+
6283 @ Override
6384 protected void onStart () {
6485 super .onStart ();
86+ showSystemBars ( false );
6587 }
6688
6789 @ Override
6890 protected void onStop () {
6991 super .onStop ();
92+ showSystemBars ( true );
7093 }
7194
7295 @ Override
@@ -77,8 +100,19 @@ protected void onCreate(Bundle savedInstanceState) {
77100
78101 activityHandle = this ;
79102
80- setContentView (R .layout .activity_help_web_view );
81- webView = (WebView ) findViewById (R .id .generalView );
103+ setContentView (R .layout .activity_makecode );
104+
105+ ViewCompat .setOnApplyWindowInsetsListener ( findViewById (R .id .MakeCode ), (v , windowInsets ) -> {
106+ Insets insets = windowInsets .getInsets (WindowInsetsCompat .Type .systemBars ());
107+ ViewGroup .MarginLayoutParams mlp = (ViewGroup .MarginLayoutParams ) v .getLayoutParams ();
108+ mlp .leftMargin = insets .left ;
109+ mlp .bottomMargin = insets .bottom ;
110+ mlp .rightMargin = insets .right ;
111+ v .setLayoutParams (mlp );
112+ return WindowInsetsCompat .CONSUMED ;
113+ });
114+
115+ webView = (WebView ) findViewById (R .id .MakeCodeWebView );
82116
83117 webView .setLayerType (View .LAYER_TYPE_HARDWARE , null );
84118
0 commit comments