|
|
|
|
@@ -18,19 +18,23 @@ package com.android.internal.app;
|
|
|
|
|
|
|
|
|
|
import com.android.internal.R;
|
|
|
|
|
|
|
|
|
|
import android.app.Dialog;
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
|
import android.app.MediaRouteActionProvider;
|
|
|
|
|
import android.app.MediaRouteButton;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.content.res.Resources;
|
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
|
import android.graphics.drawable.AnimationDrawable;
|
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
|
import android.graphics.drawable.StateListDrawable;
|
|
|
|
|
import android.media.MediaRouter;
|
|
|
|
|
import android.media.MediaRouter.RouteGroup;
|
|
|
|
|
import android.media.MediaRouter.RouteInfo;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.util.TypedValue;
|
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.Window;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.SeekBar;
|
|
|
|
|
@@ -46,7 +50,7 @@ import android.widget.SeekBar;
|
|
|
|
|
*
|
|
|
|
|
* TODO: Move this back into the API, as in the support library media router.
|
|
|
|
|
*/
|
|
|
|
|
public class MediaRouteControllerDialog extends Dialog {
|
|
|
|
|
public class MediaRouteControllerDialog extends AlertDialog {
|
|
|
|
|
// Time to wait before updating the volume when the user lets go of the seek bar
|
|
|
|
|
// to allow the route provider time to propagate the change and publish a new
|
|
|
|
|
// route descriptor.
|
|
|
|
|
@@ -57,8 +61,9 @@ public class MediaRouteControllerDialog extends Dialog {
|
|
|
|
|
private final MediaRouter.RouteInfo mRoute;
|
|
|
|
|
|
|
|
|
|
private boolean mCreated;
|
|
|
|
|
private Drawable mMediaRouteConnectingDrawable;
|
|
|
|
|
private Drawable mMediaRouteOnDrawable;
|
|
|
|
|
private Drawable mMediaRouteButtonDrawable;
|
|
|
|
|
private int[] mMediaRouteConnectingState = { R.attr.state_checked, R.attr.state_enabled };
|
|
|
|
|
private int[] mMediaRouteOnState = { R.attr.state_activated, R.attr.state_enabled };
|
|
|
|
|
private Drawable mCurrentIconDrawable;
|
|
|
|
|
|
|
|
|
|
private boolean mVolumeControlEnabled = true;
|
|
|
|
|
@@ -68,8 +73,6 @@ public class MediaRouteControllerDialog extends Dialog {
|
|
|
|
|
|
|
|
|
|
private View mControlView;
|
|
|
|
|
|
|
|
|
|
private Button mDisconnectButton;
|
|
|
|
|
|
|
|
|
|
public MediaRouteControllerDialog(Context context, int theme) {
|
|
|
|
|
super(context, theme);
|
|
|
|
|
|
|
|
|
|
@@ -132,14 +135,28 @@ public class MediaRouteControllerDialog extends Dialog {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
setTitle(mRoute.getName());
|
|
|
|
|
Resources res = getContext().getResources();
|
|
|
|
|
setButton(BUTTON_NEGATIVE, res.getString(R.string.media_route_controller_disconnect),
|
|
|
|
|
new OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialogInterface, int id) {
|
|
|
|
|
if (mRoute.isSelected()) {
|
|
|
|
|
mRouter.getDefaultRoute().select();
|
|
|
|
|
}
|
|
|
|
|
dismiss();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
View customView = getLayoutInflater().inflate(R.layout.media_route_controller_dialog, null);
|
|
|
|
|
setView(customView, 0, 0, 0, 0);
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
getWindow().requestFeature(Window.FEATURE_LEFT_ICON);
|
|
|
|
|
|
|
|
|
|
setContentView(R.layout.media_route_controller_dialog);
|
|
|
|
|
|
|
|
|
|
mVolumeLayout = (LinearLayout)findViewById(R.id.media_route_volume_layout);
|
|
|
|
|
mVolumeSlider = (SeekBar)findViewById(R.id.media_route_volume_slider);
|
|
|
|
|
View customPanelView = getWindow().findViewById(R.id.customPanel);
|
|
|
|
|
if (customPanelView != null) {
|
|
|
|
|
customPanelView.setMinimumHeight(0);
|
|
|
|
|
}
|
|
|
|
|
mVolumeLayout = (LinearLayout) customView.findViewById(R.id.media_route_volume_layout);
|
|
|
|
|
mVolumeSlider = (SeekBar) customView.findViewById(R.id.media_route_volume_slider);
|
|
|
|
|
mVolumeSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
|
|
|
|
private final Runnable mStopTrackingTouch = new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
@@ -176,22 +193,12 @@ public class MediaRouteControllerDialog extends Dialog {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mDisconnectButton = (Button)findViewById(R.id.media_route_disconnect_button);
|
|
|
|
|
mDisconnectButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
if (mRoute.isSelected()) {
|
|
|
|
|
mRouter.getDefaultRoute().select();
|
|
|
|
|
}
|
|
|
|
|
dismiss();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mMediaRouteButtonDrawable = obtainMediaRouteButtonDrawable();
|
|
|
|
|
mCreated = true;
|
|
|
|
|
if (update()) {
|
|
|
|
|
mControlView = onCreateMediaControlView(savedInstanceState);
|
|
|
|
|
FrameLayout controlFrame =
|
|
|
|
|
(FrameLayout)findViewById(R.id.media_route_control_frame);
|
|
|
|
|
(FrameLayout) customView.findViewById(R.id.media_route_control_frame);
|
|
|
|
|
if (mControlView != null) {
|
|
|
|
|
controlFrame.addView(mControlView);
|
|
|
|
|
controlFrame.setVisibility(View.VISIBLE);
|
|
|
|
|
@@ -201,7 +208,6 @@ public class MediaRouteControllerDialog extends Dialog {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAttachedToWindow() {
|
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
|
@@ -248,24 +254,41 @@ public class MediaRouteControllerDialog extends Dialog {
|
|
|
|
|
Drawable icon = getIconDrawable();
|
|
|
|
|
if (icon != mCurrentIconDrawable) {
|
|
|
|
|
mCurrentIconDrawable = icon;
|
|
|
|
|
getWindow().setFeatureDrawable(Window.FEATURE_LEFT_ICON, icon);
|
|
|
|
|
if (icon instanceof AnimationDrawable) {
|
|
|
|
|
AnimationDrawable animDrawable = (AnimationDrawable) icon;
|
|
|
|
|
if (!animDrawable.isRunning()) {
|
|
|
|
|
animDrawable.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setIcon(icon);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Drawable obtainMediaRouteButtonDrawable() {
|
|
|
|
|
Context context = getContext();
|
|
|
|
|
TypedValue value = new TypedValue();
|
|
|
|
|
if (!context.getTheme().resolveAttribute(R.attr.mediaRouteButtonStyle, value, true)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
int[] drawableAttrs = new int[] { R.attr.externalRouteEnabledDrawable };
|
|
|
|
|
TypedArray a = context.obtainStyledAttributes(value.data, drawableAttrs);
|
|
|
|
|
Drawable drawable = a.getDrawable(0);
|
|
|
|
|
a.recycle();
|
|
|
|
|
return drawable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Drawable getIconDrawable() {
|
|
|
|
|
if (mRoute.isConnecting()) {
|
|
|
|
|
if (mMediaRouteConnectingDrawable == null) {
|
|
|
|
|
mMediaRouteConnectingDrawable = getContext().getDrawable(
|
|
|
|
|
R.drawable.ic_media_route_connecting_holo_dark);
|
|
|
|
|
}
|
|
|
|
|
return mMediaRouteConnectingDrawable;
|
|
|
|
|
if (!(mMediaRouteButtonDrawable instanceof StateListDrawable)) {
|
|
|
|
|
return mMediaRouteButtonDrawable;
|
|
|
|
|
} else if (mRoute.isConnecting()) {
|
|
|
|
|
StateListDrawable stateListDrawable = (StateListDrawable) mMediaRouteButtonDrawable;
|
|
|
|
|
stateListDrawable.setState(mMediaRouteConnectingState);
|
|
|
|
|
return stateListDrawable.getCurrent();
|
|
|
|
|
} else {
|
|
|
|
|
if (mMediaRouteOnDrawable == null) {
|
|
|
|
|
mMediaRouteOnDrawable = getContext().getDrawable(
|
|
|
|
|
R.drawable.ic_media_route_on_holo_dark);
|
|
|
|
|
}
|
|
|
|
|
return mMediaRouteOnDrawable;
|
|
|
|
|
StateListDrawable stateListDrawable = (StateListDrawable) mMediaRouteButtonDrawable;
|
|
|
|
|
stateListDrawable.setState(mMediaRouteOnState);
|
|
|
|
|
return stateListDrawable.getCurrent();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|