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

Commit 286bcc6b authored by John Spurlock's avatar John Spurlock Committed by Android Git Automerger
Browse files

am d10e8b57: VolumeZen: Pulse silent mode icon on disabled slider touch.

* commit 'd10e8b57a3b28f4ab511c6cf0514b3a8e457efbf':
  VolumeZen: Pulse silent mode icon on disabled slider touch.
parents 1d430699 5f640e4a
Loading
Loading
Loading
Loading
+28 −24
Original line number Diff line number Diff line
@@ -29,16 +29,20 @@
            android:layout_height="wrap_content"
            android:padding="16dip"
            android:contentDescription="@null" />
    <FrameLayout
            android:id="@+id/seekbar_container"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        <SeekBar
                style="?android:attr/seekBarStyle"
                android:id="@+id/seekbar"
        android:layout_width="0dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
        android:layout_weight="1"
                android:paddingTop="16dip"
                android:paddingBottom="16dip"
                android:paddingStart="11dip"
                android:paddingEnd="11dip"
                android:layout_marginEnd="16dip" />

    </FrameLayout>
</LinearLayout>
+41 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.volume;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
@@ -49,7 +51,8 @@ import android.view.ViewStub;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.FrameLayout;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
@@ -83,6 +86,7 @@ public class VolumePanel extends Handler {
    private static final int FREE_DELAY = 10000;
    private static final int TIMEOUT_DELAY = 3000;
    private static final int TIMEOUT_DELAY_EXPANDED = 10000;
    private static final float ICON_PULSE_SCALE = 1.3f;

    private static final int MSG_VOLUME_CHANGED = 0;
    private static final int MSG_FREE_RESOURCES = 1;
@@ -107,6 +111,7 @@ public class VolumePanel extends Handler {
    protected final Context mContext;
    private final AudioManager mAudioManager;
    private final ZenModeController mZenController;
    private final Interpolator mFastOutSlowInInterpolator;
    private boolean mRingIsSilent;
    private boolean mVoiceCapable;
    private boolean mZenModeCapable;
@@ -222,6 +227,7 @@ public class VolumePanel extends Handler {
        ViewGroup group;
        ImageView icon;
        SeekBar seekbarView;
        View seekbarContainer;
        int iconRes;
        int iconMuteRes;
    }
@@ -275,6 +281,8 @@ public class VolumePanel extends Handler {
        mParent = parent;
        mZenController = zenController;
        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(mContext,
                android.R.interpolator.fast_out_slow_in);

        // For now, only show master volume if master volume is supported
        final Resources res = context.getResources();
@@ -473,6 +481,8 @@ public class VolumePanel extends Handler {
                    }
                });
            }
            sc.seekbarContainer =
                    sc.group.findViewById(com.android.systemui.R.id.seekbar_container);
            sc.seekbarView = (SeekBar) sc.group.findViewById(com.android.systemui.R.id.seekbar);
            final int plusOne = (streamType == AudioSystem.STREAM_BLUETOOTH_SCO ||
                    streamType == AudioSystem.STREAM_VOICE_CALL) ? 1 : 0;
@@ -533,7 +543,8 @@ public class VolumePanel extends Handler {
        updateSliderEnabled(sc, muted, false);
    }

    private void updateSliderEnabled(StreamControl sc, boolean muted, boolean fixedVolume) {
    private void updateSliderEnabled(final StreamControl sc, boolean muted, boolean fixedVolume) {
        final boolean wasEnabled = sc.seekbarView.isEnabled();
        if (sc.streamType == AudioService.STREAM_REMOTE_MUSIC) {
            // never disable touch interactions for remote playback, the muting is not tied to
            // the state of the phone.
@@ -548,6 +559,34 @@ public class VolumePanel extends Handler {
        } else {
            sc.seekbarView.setEnabled(true);
        }
        // pulse the ringer icon when the disabled slider is touched in silent mode
        if (sc.icon.isClickable() && wasEnabled != sc.seekbarView.isEnabled()) {
            if (sc.seekbarView.isEnabled()) {
                sc.seekbarContainer.setOnTouchListener(null);
            } else {
                sc.seekbarContainer.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        resetTimeout();
                        pulseIcon(sc.icon);
                        return false;
                    }
                });
            }
        }
    }

    private void pulseIcon(final ImageView icon) {
        if (icon.getScaleX() != 1) return;  // already running
        icon.animate().cancel();
        icon.animate().scaleX(ICON_PULSE_SCALE).scaleY(ICON_PULSE_SCALE)
                .setInterpolator(mFastOutSlowInInterpolator)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        icon.animate().scaleX(1).scaleY(1).setListener(null);
                    }
                });
    }

    private static boolean isNotificationOrRing(int streamType) {