提交 205e2d9a 编写于 作者: A Adam Barth

Merge pull request #553 from abarth/immersive

Add support for immersive mode on Android
......@@ -8,7 +8,7 @@ import 'dart:async';
import 'package:sky/mojo/shell.dart' as shell;
import 'package:sky_services/activity/activity.mojom.dart';
export 'package:sky_services/activity/activity.mojom.dart' show Intent, ComponentName, StringExtra;
export 'package:sky_services/activity/activity.mojom.dart' show Intent, ComponentName, StringExtra, SystemUIVisibility_STANDARD, SystemUIVisibility_FULLSCREEN, SystemUIVisibility_IMMERSIVE;
/// Dart wrapper around Activity mojo service available in Sky on Android.
///
......@@ -55,6 +55,15 @@ void updateTaskDescription(String label, Color color) {
_activity.ptr.setTaskDescription(description);
}
int _cachedSystemUiVisibility = SystemUIVisibility_STANDARD;
void setSystemUiVisibility(int visibility) {
if (_cachedSystemUiVisibility == visibility)
return;
_cachedSystemUiVisibility = visibility;
_activity.ptr.setSystemUiVisibility(visibility);
}
Future<String> getFilesDir() async => (await _activity.ptr.getFilesDir()).path;
Future<String> getCacheDir() async => (await _activity.ptr.getCacheDir()).path;
......@@ -28,6 +28,12 @@ struct TaskDescription {
uint32 primaryColor;
};
enum SystemUIVisibility {
STANDARD,
FULLSCREEN,
IMMERSIVE,
};
// TODO(abarth): This interface seems very specific to Android. Do we want to
// have a higher-level abstraction here? Do we want a collection
// of services that only work on specific platforms? We need to
......@@ -36,6 +42,7 @@ interface Activity {
StartActivity(Intent intent);
FinishCurrentActivity();
SetTaskDescription(TaskDescription description);
SetSystemUIVisibility(SystemUIVisibility visibility);
// These are stored off the Activity on Android, but probably belong in a
// separate FileSystem service.
......
......@@ -6,14 +6,16 @@ package org.domokit.activity;
import android.content.ActivityNotFoundException;
import android.net.Uri;
import android.util.Log;
import android.os.Build;
import android.util.Log;
import android.view.View;
import org.chromium.mojo.system.MojoException;
import org.chromium.mojom.activity.Activity;
import org.chromium.mojom.activity.ComponentName;
import org.chromium.mojom.activity.Intent;
import org.chromium.mojom.activity.StringExtra;
import org.chromium.mojom.activity.SystemUiVisibility;
import org.chromium.mojom.activity.TaskDescription;
/**
......@@ -96,6 +98,28 @@ public class ActivityImpl implements Activity {
);
}
@Override
public void setSystemUiVisibility(int visibility) {
if (sCurrentActivity == null) {
return;
}
int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
if (visibility >= SystemUiVisibility.FULLSCREEN) {
flags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if (visibility >= SystemUiVisibility.IMMERSIVE) {
flags |= View.SYSTEM_UI_FLAG_IMMERSIVE |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
sCurrentActivity.getWindow().getDecorView().setSystemUiVisibility(flags);
}
@Override
public void getFilesDir(GetFilesDirResponse callback) {
String path = null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册