Skip to content

Commit 7ebcbcd

Browse files
committed
edge-to-edge MakeCode
1 parent 4c7367b commit 7ebcbcd

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

app/src/main/java/com/samsung/microbit/ui/activity/MakeCodeWebView.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import android.util.Base64;
1010
import android.util.Log;
1111
import android.view.View;
12+
import android.view.ViewGroup;
13+
import android.view.Window;
1214
import android.webkit.DownloadListener;
1315
import android.webkit.JavascriptInterface;
1416
import android.webkit.ValueCallback;
@@ -17,6 +19,7 @@
1719
import android.webkit.WebSettings;
1820
import android.webkit.WebView;
1921
import android.webkit.WebViewClient;
22+
import android.widget.LinearLayout;
2023
import android.widget.Toast;
2124

2225
import com.samsung.microbit.BuildConfig;
@@ -31,7 +34,11 @@
3134

3235
import static android.content.ContentValues.TAG;
3336

37+
import androidx.core.graphics.Insets;
38+
import androidx.core.view.ViewCompat;
3439
import 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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:id="@+id/MakeCode"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:padding="0dp"
7+
tools:context="com.samsung.microbit.ui.activity.MakeCodeWebView">
8+
9+
<WebView
10+
android:id="@+id/MakeCodeWebView"
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent"
13+
android:layout_marginBottom="0dp"
14+
android:hardwareAccelerated="true"
15+
android:windowSoftInputMode="adjustResize" />
16+
17+
</LinearLayout>

0 commit comments

Comments
 (0)