@Override public void setPreferredOrientations( int deviceOrientationMask, SetPreferredOrientationsResponse callback) { Activity activity = ActivityImpl.getCurrentActivity(); if (activity == null) { callback.call(false); return; } // Currently the Android implementation only supports masks with zero or one // selected device orientations. int androidOrientation; if (deviceOrientationMask == 0) { androidOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; } else if (deviceOrientationMask == DeviceOrientation.PORTRAIT_UP) { androidOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } else if (deviceOrientationMask == DeviceOrientation.LANDSCAPE_LEFT) { androidOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } else if (deviceOrientationMask == DeviceOrientation.PORTRAIT_DOWN) { androidOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } else if (deviceOrientationMask == DeviceOrientation.LANDSCAPE_RIGHT) { androidOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } else { callback.call(false); return; } activity.setRequestedOrientation(androidOrientation); callback.call(true); }
/** @see android.app.Activity#onCreate(android.os.Bundle) */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PlatformViewAndroid.EdgeDims edgeDims = new PlatformViewAndroid.EdgeDims(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); getWindow().setStatusBarColor(0x40000000); } // TODO(abarth): We should get this value from the Android framework somehow. edgeDims.top = 25.0; // TODO(abarth): Unclear if we want to use fullscreen if we don't have // a transparent system bar. getWindow() .getDecorView() .setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); String[] args = getArgsFromIntent(getIntent()); SkyMain.ensureInitialized(getApplicationContext(), args); mView = new PlatformViewAndroid(this, edgeDims); ActivityImpl.setCurrentActivity(this); setContentView(mView); mTracingController = new TracingController(this); onSkyReady(); }
public FlutterView(Context context, AttributeSet attrs) { super(context, attrs); // TODO(abarth): Remove this static and instead make everything that // depends on it into a view-associated service. ActivityImpl.setCurrentActivity((Activity) context); mMetrics = new ViewportMetrics(); mMetrics.devicePixelRatio = context.getResources().getDisplayMetrics().density; setFocusable(true); setFocusableInTouchMode(true); attach(); assert mNativePlatformView != 0; mSurfaceCallback = new SurfaceHolder.Callback() { @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {} @Override public void surfaceCreated(SurfaceHolder holder) { assert mNativePlatformView != 0; nativeSurfaceCreated(mNativePlatformView, holder.getSurface()); } @Override public void surfaceDestroyed(SurfaceHolder holder) { assert mNativePlatformView != 0; nativeSurfaceDestroyed(mNativePlatformView); } }; getHolder().addCallback(mSurfaceCallback); mKeyboardState = new KeyboardViewState(this); mRawKeyboardState = new RawKeyboardServiceState(); Core core = CoreImpl.getInstance(); mPlatformServiceProvider = new ServiceProviderImpl(core, this, ServiceRegistry.SHARED); ServiceRegistry localRegistry = new ServiceRegistry(); configureLocalServices(localRegistry); mViewServiceProvider = new ServiceProviderImpl(core, this, localRegistry); mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); mOnMessageListeners = new HashMap<String, OnMessageListener>(); mAsyncOnMessageListeners = new HashMap<String, OnMessageListenerAsync>(); mActivityLifecycleListeners = new ArrayList<ActivityLifecycleListener>(); setLocale(getResources().getConfiguration().locale); if ((context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { discoveryReceiver = new DiscoveryReceiver(); context.registerReceiver(discoveryReceiver, new IntentFilter(ACTION_DISCOVER)); } }
@Override public void setEnabledSystemUiOverlays( int overlays, SetEnabledSystemUiOverlaysResponse callback) { Activity activity = ActivityImpl.getCurrentActivity(); if (activity == null) { callback.call(false); return; } int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; if ((overlays & SystemUiOverlay.TOP) != 0) { flags |= View.SYSTEM_UI_FLAG_FULLSCREEN; } if ((overlays & SystemUiOverlay.BOTTOM) != 0) { flags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } activity.getWindow().getDecorView().setSystemUiVisibility(flags); callback.call(true); }
@Override protected void onResume() { super.onResume(); ActivityImpl.onResumeActivity(this); }