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 Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.media.MediaRouter;
import android.media.MediaRouter.RouteGroup;
@@ -339,11 +340,9 @@ public class MediaRouteButton extends View {
    }

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

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

        if (mAttachedToWindow) {
            setEnabled(mRouter.isRouteAvailable(mRouteTypes,
                    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 {
+11 −1
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ public class MediaRouteControllerDialog extends AlertDialog {
    private boolean mVolumeSliderTouched;

    private View mControlView;
    private boolean mAttachedToWindow;

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

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

        super.onDetachedFromWindow();
    }
@@ -256,7 +259,14 @@ public class MediaRouteControllerDialog extends AlertDialog {
            mCurrentIconDrawable = icon;
            if (icon instanceof AnimationDrawable) {
                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();
                }
            }
+1.33 KiB
Loading image diff...
+1.34 KiB
Loading image diff...
+1.33 KiB
Loading image diff...
Loading