Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/media/remote/ChromeMediaRouteDialogFactory.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/remote/ChromeMediaRouteDialogFactory.java b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/ChromeMediaRouteDialogFactory.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a6cde85d9daeb70a843c8c85e7f6fc85cf7ff2c4 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/ChromeMediaRouteDialogFactory.java |
| @@ -0,0 +1,111 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.media.remote; |
| + |
| +import android.annotation.TargetApi; |
| +import android.app.Activity; |
| +import android.app.Dialog; |
| +import android.content.Context; |
| +import android.os.Bundle; |
| +import android.support.v7.app.MediaRouteChooserDialog; |
| +import android.support.v7.app.MediaRouteChooserDialogFragment; |
| +import android.support.v7.app.MediaRouteControllerDialogFragment; |
| +import android.support.v7.app.MediaRouteDialogFactory; |
| +import android.view.View; |
| +import android.widget.FrameLayout; |
| + |
| +import org.chromium.third_party.android.media.ChromeMediaRouteControllerDialog; |
| + |
| +/** |
|
whywhat
2015/02/25 16:31:31
nit: I believe you had two blank lines between imp
aberent
2015/03/11 18:29:57
Done.
|
| + * The Chrome implementation of the dialog factory so custom behavior can |
| + * be injected for the disconnect button. |
| + */ |
| +public class ChromeMediaRouteDialogFactory extends MediaRouteDialogFactory { |
| + |
| + private final ChromeMediaRouteControllerDialog.DisconnectListener mDisconnectListener; |
| + |
| + @TargetApi(16) |
| + private static class SystemVisibilitySaver { |
| + private int mSystemVisibility; |
| + private boolean mRestoreSystemVisibility; |
| + |
| + void saveSystemVisibility(Activity activity) { |
| + // If we are in fullscreen we may have also have hidden the system UI. This |
| + // is overridden when we display the dialog. Save the system UI visibility |
| + // state so we can restore it. |
| + FrameLayout decor = (FrameLayout) activity.getWindow().getDecorView(); |
| + mSystemVisibility = decor.getSystemUiVisibility(); |
| + mRestoreSystemVisibility = ( |
| + (mSystemVisibility & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0); |
| + } |
| + |
| + void restoreSystemVisibility(Activity activity) { |
| + if (mRestoreSystemVisibility) { |
| + FrameLayout decor = (FrameLayout) activity.getWindow().getDecorView(); |
| + // In some cases we come out of fullscreen before closing this dialog. In these |
| + // cases we don't want to restore the system UI visibility state. |
| + int systemVisibility = decor.getSystemUiVisibility(); |
| + if ((systemVisibility & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) { |
| + decor.setSystemUiVisibility(mSystemVisibility); |
| + } |
| + } |
| + } |
| + } |
| + |
| + /** |
| + * @param listener to be executed when clicking the disconnect button. |
| + */ |
| + public ChromeMediaRouteDialogFactory( |
| + ChromeMediaRouteControllerDialog.DisconnectListener listener) { |
| + mDisconnectListener = listener; |
| + } |
| + |
| + @Override |
| + public MediaRouteControllerDialogFragment onCreateControllerDialogFragment() { |
| + return new MediaRouteControllerDialogFragment() { |
| + final SystemVisibilitySaver mVisibilitySaver = new SystemVisibilitySaver(); |
| + |
| + @Override |
| + public Dialog onCreateDialog(Bundle saved) { |
| + if (android.os.Build.VERSION.SDK_INT >= 16) { |
| + mVisibilitySaver.saveSystemVisibility(getActivity()); |
| + } |
| + return new ChromeMediaRouteControllerDialog(getActivity(), mDisconnectListener); |
| + } |
| + |
| + @Override |
| + public void onStop() { |
| + super.onStop(); |
| + if (android.os.Build.VERSION.SDK_INT >= 16) { |
| + mVisibilitySaver.restoreSystemVisibility(getActivity()); |
| + } |
| + } |
| + }; |
| + } |
| + |
| + @Override |
| + public MediaRouteChooserDialogFragment onCreateChooserDialogFragment() { |
| + return new MediaRouteChooserDialogFragment() { |
| + final SystemVisibilitySaver mVisibilitySaver = new SystemVisibilitySaver(); |
| + |
| + @Override |
| + public MediaRouteChooserDialog onCreateChooserDialog( |
| + Context context, Bundle savedInstanceState) { |
| + if (android.os.Build.VERSION.SDK_INT >= 16) { |
| + mVisibilitySaver.saveSystemVisibility(getActivity()); |
| + } |
| + return new MediaRouteChooserDialog(context); |
| + } |
| + |
| + @Override |
| + public void onStop() { |
| + super.onStop(); |
| + if (android.os.Build.VERSION.SDK_INT >= 16) { |
| + mVisibilitySaver.restoreSystemVisibility(getActivity()); |
| + } |
| + } |
| + }; |
| + } |
| +} |