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

Commit 1d430699 authored by John Spurlock's avatar John Spurlock Committed by Android Git Automerger
Browse files

am ae7b2da7: Merge "VolumeZen: Slider icon as ringer-mode toggle." into lmp-preview-dev

* commit 'ae7b2da79ef91d0d906a39cb091f0db2e7472cb3':
  VolumeZen: Slider icon as ringer-mode toggle.
parents 9efdcd8a 25431045
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2014 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/qs_panel_background"
    android:translationZ="@dimen/volume_panel_z"
    android:layout_margin="@dimen/volume_panel_z">

        <include layout="@layout/volume_panel" />

</FrameLayout>
 No newline at end of file
+6 −4
Original line number Diff line number Diff line
@@ -24,19 +24,21 @@

    <ImageView
        android:id="@+id/stream_icon"
        style="@style/BorderlessButton.Tiny"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="16dip"
        android:background="?android:attr/selectableItemBackground"
        android:padding="16dip"
        android:contentDescription="@null" />

    <SeekBar
        style="?android:attr/seekBarStyle"
        android:id="@+id/seekbar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:padding="16dip"
        android:paddingTop="16dip"
        android:paddingBottom="16dip"
        android:paddingStart="11dip"
        android:paddingEnd="11dip"
        android:layout_marginEnd="16dip" />

</LinearLayout>
+63 −26
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.Window;
@@ -284,7 +286,6 @@ public class VolumePanel extends Handler {
            }
        }
        if (LOGD) Log.d(mTag, String.format("new VolumePanel hasParent=%s", parent != null));
        final int layoutId = com.android.systemui.R.layout.volume_panel;
        if (parent == null) {
            // dialog mode
            mDialog = new Dialog(context) {
@@ -318,15 +319,7 @@ public class VolumePanel extends Handler {
                    | LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                    | LayoutParams.FLAG_HARDWARE_ACCELERATED);
            mDialog.setCanceledOnTouchOutside(true);
            // temporary workaround for no window shadows
            final FrameLayout layout = new FrameLayout(mContext);
            final int z = res.getDimensionPixelSize(com.android.systemui.R.dimen.volume_panel_z);
            layout.setPadding(z, z, z, z);
            final View v = LayoutInflater.from(mContext).inflate(layoutId, layout, false);
            v.setBackgroundResource(com.android.systemui.R.drawable.qs_panel_background);
            v.setElevation(z);
            layout.addView(v);
            mDialog.setContentView(layout);
            mDialog.setContentView(com.android.systemui.R.layout.volume_dialog);
            mDialog.setOnDismissListener(new OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
@@ -336,6 +329,7 @@ public class VolumePanel extends Handler {
            });

            mDialog.create();
            // temporary workaround, until we support window-level shadows
            mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0x00000000));

            mView = window.findViewById(R.id.content);
@@ -350,7 +344,8 @@ public class VolumePanel extends Handler {
        } else {
            // embedded mode
            mDialog = null;
            mView = LayoutInflater.from(mContext).inflate(layoutId, parent, true);
            mView = LayoutInflater.from(mContext).inflate(
                    com.android.systemui.R.layout.volume_panel, parent, true);
        }
        mPanel = (ViewGroup) mView.findViewById(com.android.systemui.R.id.visible_panel);
        mSliderPanel = (ViewGroup) mView.findViewById(com.android.systemui.R.id.slider_panel);
@@ -460,6 +455,24 @@ public class VolumePanel extends Handler {
            sc.iconRes = streamRes.iconRes;
            sc.iconMuteRes = streamRes.iconMuteRes;
            sc.icon.setImageResource(sc.iconRes);
            sc.icon.setClickable(isNotificationOrRing(streamType));
            if (sc.icon.isClickable()) {
                sc.icon.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        resetTimeout();
                        toggle(sc);
                    }
                });
                sc.icon.setOnLongClickListener(new OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        resetTimeout();
                        longToggle(sc);
                        return true;
                    }
                });
            }
            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;
@@ -470,6 +483,26 @@ public class VolumePanel extends Handler {
        }
    }

    private void toggle(StreamControl sc) {
        if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
            postVolumeChanged(sc.streamType, AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE);
        } else {
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            postVolumeChanged(sc.streamType, AudioManager.FLAG_PLAY_SOUND);
        }
    }

    private void longToggle(StreamControl sc) {
        if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            postVolumeChanged(sc.streamType, AudioManager.FLAG_PLAY_SOUND);
        } else {
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            postVolumeChanged(sc.streamType, AudioManager.FLAG_SHOW_UI); // disable the slider
        }
    }

    private void reorderSliders(int activeStreamType) {
        mSliderPanel.removeAllViews();

@@ -493,23 +526,35 @@ public class VolumePanel extends Handler {
        // Force reloading the image resource
        sc.icon.setImageDrawable(null);
        sc.icon.setImageResource(muted ? sc.iconMuteRes : sc.iconRes);
        if (((sc.streamType == AudioManager.STREAM_RING) ||
                (sc.streamType == AudioManager.STREAM_NOTIFICATION)) &&
        if (isNotificationOrRing(sc.streamType) &&
                mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
            sc.icon.setImageResource(com.android.systemui.R.drawable.ic_ringer_vibrate);
        }
        updateSliderEnabled(sc, muted, false);
    }

    private void updateSliderEnabled(StreamControl sc, boolean muted, boolean fixedVolume) {
        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.
            sc.seekbarView.setEnabled(true);
        } else if ((sc.streamType != mAudioManager.getMasterStreamType() && muted) ||
        } else if (fixedVolume ||
                        (sc.streamType != mAudioManager.getMasterStreamType() && muted) ||
                        (sConfirmSafeVolumeDialog != null)) {
            sc.seekbarView.setEnabled(false);
        } else if (isNotificationOrRing(sc.streamType)
                && mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
            sc.seekbarView.setEnabled(false);
        } else {
            sc.seekbarView.setEnabled(true);
        }
    }

    private static boolean isNotificationOrRing(int streamType) {
        return streamType == AudioManager.STREAM_RING
                || streamType == AudioManager.STREAM_NOTIFICATION;
    }

    public void setZenModePanelCallback(ZenModePanel.Callback callback) {
        mZenPanelCallback = callback;
    }
@@ -562,8 +607,7 @@ public class VolumePanel extends Handler {

    private void updateZenMode(boolean zen) {
        if (mZenModeCapable) {
            final boolean show = mActiveStreamType == AudioManager.STREAM_NOTIFICATION
                    || mActiveStreamType == AudioManager.STREAM_RING;
            final boolean show = isNotificationOrRing(mActiveStreamType);
            mExpandButton.setVisibility(show ? View.VISIBLE : View.GONE);
            mExpandDivider.setVisibility(show ? View.VISIBLE : View.GONE);
            mExpandButton.setImageResource(zen ? com.android.systemui.R.drawable.ic_vol_zen_on
@@ -790,15 +834,8 @@ public class VolumePanel extends Handler {
            }

            sc.seekbarView.setProgress(index);
            if (((flags & AudioManager.FLAG_FIXED_VOLUME) != 0) ||
                    (streamType != mAudioManager.getMasterStreamType() &&
                     streamType != AudioService.STREAM_REMOTE_MUSIC &&
                     isMuted(streamType)) ||
                     sConfirmSafeVolumeDialog != null) {
                sc.seekbarView.setEnabled(false);
            } else {
                sc.seekbarView.setEnabled(true);
            }
            updateSliderEnabled(sc, isMuted(streamType),
                    (flags & AudioManager.FLAG_FIXED_VOLUME) != 0);
        }

        if (!isShowing()) {
@@ -1173,7 +1210,7 @@ public class VolumePanel extends Handler {

    private final ZenModeController.Callback mZenCallback = new ZenModeController.Callback() {
        public void onZenChanged(boolean zen) {
            updateZenMode(zen);
            postZenModeChanged(zen);
        }
    };
}
+2 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ public class ZenModePanel extends LinearLayout {
    private static final int[] MINUTES = new int[] { 15, 30, 45, 60, 120, 180, 240, 480 };
    public static final Intent ZEN_SETTINGS = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS);

    private final Context mContext;
    private final LayoutInflater mInflater;
    private final HashSet<RadioButton> mRadioButtons = new HashSet<RadioButton>();
    private final H mHandler = new H();
@@ -56,6 +57,7 @@ public class ZenModePanel extends LinearLayout {

    public ZenModePanel(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        mInflater = LayoutInflater.from(new ContextThemeWrapper(context, R.style.QSWhiteTheme));
    }