Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 363c238b authored by Yang Ren's avatar Yang Ren Committed by Android (Google) Code Review
Browse files

Merge "Change Media Route Button animation images"

parents e79ce180 d9125cf9
Loading
Loading
Loading
Loading
+33 −18
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.media.MediaRouter;
import android.media.MediaRouter;
import android.media.MediaRouter.RouteGroup;
import android.media.MediaRouter.RouteGroup;
@@ -339,11 +340,9 @@ public class MediaRouteButton extends View {
    }
    }


    private void refreshRoute() {
    private void refreshRoute() {
        if (mAttachedToWindow) {
        final MediaRouter.RouteInfo route = mRouter.getSelectedRoute();
        final MediaRouter.RouteInfo route = mRouter.getSelectedRoute();
        final boolean isRemote = !route.isDefault() && route.matchesTypes(mRouteTypes);
        final boolean isRemote = !route.isDefault() && route.matchesTypes(mRouteTypes);
        final boolean isConnecting = isRemote && route.isConnecting();
        final boolean isConnecting = isRemote && route.isConnecting();

        boolean needsRefresh = false;
        boolean needsRefresh = false;
        if (mRemoteActive != isRemote) {
        if (mRemoteActive != isRemote) {
            mRemoteActive = isRemote;
            mRemoteActive = isRemote;
@@ -357,10 +356,26 @@ public class MediaRouteButton extends View {
        if (needsRefresh) {
        if (needsRefresh) {
            refreshDrawableState();
            refreshDrawableState();
        }
        }

        if (mAttachedToWindow) {
            setEnabled(mRouter.isRouteAvailable(mRouteTypes,
            setEnabled(mRouter.isRouteAvailable(mRouteTypes,
                    MediaRouter.AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE));
                    MediaRouter.AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE));
        }
        }
        if (mRemoteIndicator != null
                && mRemoteIndicator.getCurrent() instanceof AnimationDrawable) {
            AnimationDrawable curDrawable = (AnimationDrawable) mRemoteIndicator.getCurrent();
            if (mAttachedToWindow) {
                if ((needsRefresh || isConnecting) && !curDrawable.isRunning()) {
                    curDrawable.start();
                }
            } else if (isRemote && !isConnecting) {
                // When the route is already connected before the view is attached, show the last
                // frame of the connected animation immediately.
                if (curDrawable.isRunning()) {
                    curDrawable.stop();
                }
                curDrawable.selectDrawable(curDrawable.getNumberOfFrames() - 1);
            }
        }
    }
    }


    private final class MediaRouterCallback extends MediaRouter.SimpleCallback {
    private final class MediaRouterCallback extends MediaRouter.SimpleCallback {
+11 −1
Original line number Original line Diff line number Diff line
@@ -72,6 +72,7 @@ public class MediaRouteControllerDialog extends AlertDialog {
    private boolean mVolumeSliderTouched;
    private boolean mVolumeSliderTouched;


    private View mControlView;
    private View mControlView;
    private boolean mAttachedToWindow;


    public MediaRouteControllerDialog(Context context, int theme) {
    public MediaRouteControllerDialog(Context context, int theme) {
        super(context, theme);
        super(context, theme);
@@ -211,6 +212,7 @@ public class MediaRouteControllerDialog extends AlertDialog {
    @Override
    @Override
    public void onAttachedToWindow() {
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        super.onAttachedToWindow();
        mAttachedToWindow = true;


        mRouter.addCallback(0, mCallback, MediaRouter.CALLBACK_FLAG_UNFILTERED_EVENTS);
        mRouter.addCallback(0, mCallback, MediaRouter.CALLBACK_FLAG_UNFILTERED_EVENTS);
        update();
        update();
@@ -219,6 +221,7 @@ public class MediaRouteControllerDialog extends AlertDialog {
    @Override
    @Override
    public void onDetachedFromWindow() {
    public void onDetachedFromWindow() {
        mRouter.removeCallback(mCallback);
        mRouter.removeCallback(mCallback);
        mAttachedToWindow = false;


        super.onDetachedFromWindow();
        super.onDetachedFromWindow();
    }
    }
@@ -256,7 +259,14 @@ public class MediaRouteControllerDialog extends AlertDialog {
            mCurrentIconDrawable = icon;
            mCurrentIconDrawable = icon;
            if (icon instanceof AnimationDrawable) {
            if (icon instanceof AnimationDrawable) {
                AnimationDrawable animDrawable = (AnimationDrawable) icon;
                AnimationDrawable animDrawable = (AnimationDrawable) icon;
                if (!animDrawable.isRunning()) {
                if (!mAttachedToWindow && !mRoute.isConnecting()) {
                    // When the route is already connected before the view is attached, show the
                    // last frame of the connected animation immediately.
                    if (animDrawable.isRunning()) {
                        animDrawable.stop();
                    }
                    icon = animDrawable.getFrame(animDrawable.getNumberOfFrames() - 1);
                } else if (!animDrawable.isRunning()) {
                    animDrawable.start();
                    animDrawable.start();
                }
                }
            }
            }
+1.33 KiB
Loading image diff...
+1.34 KiB
Loading image diff...
+1.33 KiB
Loading image diff...
Loading