mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 08:25:34 +00:00
ui/app,cmd/gio: support edge-to-edge layout on Android
Implement recomendations from https://developer.android.com/preview/features/gesturalnav#java While here, give up on providing translucent top and bottom bars on Android 4.4 and below. It's simpler to use the app drawn system backgrounds from 5.0 and newer. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+50
-6
@@ -233,6 +233,49 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo) (err error) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Compile resources.
|
||||
resDir := filepath.Join(tmpDir, "res")
|
||||
valDir := filepath.Join(resDir, "values")
|
||||
v21Dir := filepath.Join(resDir, "values-v21")
|
||||
for _, dir := range []string{valDir, v21Dir} {
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
themes := `<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="Theme.GioApp" parent="android:style/Theme.NoTitleBar">
|
||||
</style>
|
||||
</resources>`
|
||||
err = ioutil.WriteFile(filepath.Join(valDir, "themes.xml"), []byte(themes), 0660)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
themesV21 := `<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="Theme.GioApp" parent="android:style/Theme.NoTitleBar">
|
||||
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
|
||||
<item name="android:navigationBarColor">#40000000</item>
|
||||
<item name="android:statusBarColor">#40000000</item>
|
||||
</style>
|
||||
</resources>`
|
||||
err = ioutil.WriteFile(filepath.Join(v21Dir, "themes.xml"), []byte(themesV21), 0660)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resZip := filepath.Join(tmpDir, "resources.zip")
|
||||
aapt2 := filepath.Join(tools.buildtools, "aapt2")
|
||||
_, err = runCmd(exec.Command(
|
||||
aapt2,
|
||||
"compile",
|
||||
"-o", resZip,
|
||||
"--dir", resDir))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Link APK.
|
||||
appName := strings.Title(filepath.Base(bi.pkg))
|
||||
manifestSrc := fmt.Sprintf(`<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
@@ -245,7 +288,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo) (err error) {
|
||||
<application android:label="Gio">
|
||||
<activity android:name="org.gioui.GioActivity"
|
||||
android:label="%s"
|
||||
android:theme="@android:style/Theme.NoTitleBar"
|
||||
android:theme="@style/Theme.GioApp"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
@@ -256,18 +299,19 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo) (err error) {
|
||||
</application>
|
||||
</manifest>`, *appID, appName)
|
||||
manifest := filepath.Join(tmpDir, "AndroidManifest.xml")
|
||||
if err := ioutil.WriteFile(manifest, []byte(manifestSrc), 0600); err != nil {
|
||||
if err := ioutil.WriteFile(manifest, []byte(manifestSrc), 0660); err != nil {
|
||||
return err
|
||||
}
|
||||
tmpapk := filepath.Join(tmpDir, "link.apk")
|
||||
_, err = runCmd(exec.Command(
|
||||
filepath.Join(tools.buildtools, "aapt2"),
|
||||
link := exec.Command(
|
||||
aapt2,
|
||||
"link",
|
||||
"--manifest", manifest,
|
||||
"-I", tools.androidjar,
|
||||
"-o", tmpapk,
|
||||
))
|
||||
if err != nil {
|
||||
resZip,
|
||||
)
|
||||
if _, err := runCmd(link); err != nil {
|
||||
return err
|
||||
}
|
||||
// The Go standard library archive/zip doesn't support appending to zip
|
||||
|
||||
+3
-3
@@ -115,7 +115,7 @@ func signIOS(tmpDir, app, ipa string) error {
|
||||
return err
|
||||
}
|
||||
entFile := filepath.Join(tmpDir, "entitlements.plist")
|
||||
if err := ioutil.WriteFile(entFile, []byte(entitlements), 0600); err != nil {
|
||||
if err := ioutil.WriteFile(entFile, []byte(entitlements), 0660); err != nil {
|
||||
return err
|
||||
}
|
||||
signIdentity := cert.Subject.CommonName
|
||||
@@ -144,7 +144,7 @@ int main(int argc, char * argv[]) {
|
||||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([GioAppDelegate class]));
|
||||
}
|
||||
}`
|
||||
if err := ioutil.WriteFile(mainm, []byte(mainmSrc), 0600); err != nil {
|
||||
if err := ioutil.WriteFile(mainm, []byte(mainmSrc), 0660); err != nil {
|
||||
return err
|
||||
}
|
||||
exe := filepath.Join(app, "app")
|
||||
@@ -200,7 +200,7 @@ int main(int argc, char * argv[]) {
|
||||
</dict>
|
||||
</plist>`, *appID, appName)
|
||||
infoPlist := filepath.Join(app, "Info.plist")
|
||||
if err := ioutil.WriteFile(infoPlist, []byte(infoPlistSrc), 0600); err != nil {
|
||||
if err := ioutil.WriteFile(infoPlist, []byte(infoPlistSrc), 0660); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := runCmd(exec.Command("plutil", "-convert", "binary1", infoPlist)); err != nil {
|
||||
|
||||
@@ -17,11 +17,11 @@ public class GioActivity extends Activity {
|
||||
super.onCreate(state);
|
||||
|
||||
Window w = getWindow();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
}
|
||||
|
||||
this.view = new GioView(this);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
this.view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
}
|
||||
this.view.setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
|
||||
setContentView(view);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user