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

Commit 6f8568af authored by kaiyiz's avatar kaiyiz Committed by Linux Build Service Account
Browse files

SystemUI: Add sound item in quick settings panel

Add sound item in quick settings panel.

CRs-Fixed: 715258

Change-Id: I090929a3622101edc5413afe4f7c2d1863139d2c
parent bf1eb124
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
<!-- Copyright (c) 2014, The Linux Foundation. All rights reserved.

     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions are
     met:
         * Redistributions of source code must retain the above copyright
           notice, this list of conditions and the following disclaimer.
         * Redistributions in binary form must reproduce the above
           copyright notice, this list of conditions and the following
           disclaimer in the documentation and/or other materials provided
           with the distribution.
         * Neither the name of The Linux Foundation nor the names of its
           contributors may be used to endorse or promote products derived
           from this software without specific prior written permission.

     THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="64dp"
    android:height="64dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">

    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M12.0,17.273l6.1800003,3.7269993 -1.6350002,-7.0290003 5.455,-4.7269993 -7.191,-0.6170006 -2.809,-6.627 -2.809,6.627 -7.191,0.6170006 5.455,4.7269993 -1.6349998,7.0290003z"/>
</vector>
+37 −0
Original line number Diff line number Diff line
<!-- Copyright (c) 2014, The Linux Foundation. All rights reserved.

     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions are
     met:
         * Redistributions of source code must retain the above copyright
           notice, this list of conditions and the following disclaimer.
         * Redistributions in binary form must reproduce the above
           copyright notice, this list of conditions and the following
           disclaimer in the documentation and/or other materials provided
           with the distribution.
         * Neither the name of The Linux Foundation nor the names of its
           contributors may be used to endorse or promote products derived
           from this software without specific prior written permission.

     THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="32dp"
    android:height="32dp"
    android:viewportWidth="48.0"
    android:viewportHeight="48.0">

    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M4.0,24.0c0.0,11.0 9.0,20.0 20.0,20.0s20.0,-9.0 20.0,-20.0S35.0,4.0 24.0,4.0S4.0,13.0 4.0,24.0zM36.6,33.8L14.2,11.4C16.9,9.3 20.3,8.0 24.0,8.0c8.8,0.0 16.0,7.2 16.0,16.0C40.0,27.7 38.7,31.1 36.6,33.8zM8.0,24.0c0.0,-3.7 1.3,-7.1 3.4,-9.8L33.8,36.6C31.1,38.7 27.7,40.0 24.0,40.0C15.2,40.0 8.0,32.8 8.0,24.0z"/>
</vector>
+2 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.android.systemui.statusbar.policy.NetworkController;
import com.android.systemui.statusbar.policy.RotationLockController;
import com.android.systemui.statusbar.policy.HotspotController;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.volume.VolumeComponent;

import java.util.Collection;
import java.util.Objects;
@@ -291,6 +292,7 @@ public abstract class QSTile<TState extends State> implements Listenable {
        ZenModeController getZenModeController();
        HotspotController getHotspotController();
        CastController getCastController();
        VolumeComponent getVolumeComponent();
        FlashlightController getFlashlightController();
        KeyguardMonitor getKeyguardMonitor();

+211 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer in the documentation and/or other materials provided
 *       with the distribution.
 *     * Neither the name of The Linux Foundation nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.android.systemui.qs.tiles;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.provider.Settings.Global;
import android.util.Log;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.ViewGroup;

import com.android.systemui.R;
import com.android.systemui.qs.QSTile;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.volume.VolumeComponent;
import com.android.systemui.volume.VolumePanel;
import com.android.systemui.volume.ZenModePanel;

/** Quick settings tile: Notifications **/
public class NotificationsTile extends QSTile<NotificationsTile.NotificationsState> {
    private final ZenModeController mZenController;
    private final AudioManager mAudioManager;

    private boolean mListening;

    public NotificationsTile(Host host) {
        super(host);
        mZenController = host.getZenModeController();
        mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    }

    @Override
    public DetailAdapter getDetailAdapter() {
        return mDetailAdapter;
    }

    @Override
    protected NotificationsState newTileState() {
        return new NotificationsState();
    }

    @Override
    public void setListening(boolean listening) {
        if (mListening == listening) return;
        mListening = listening;
        if (listening) {
            mZenController.addCallback(mCallback);
            final IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
            mContext.registerReceiver(mReceiver, filter);
        } else {
            mZenController.removeCallback(mCallback);
            mContext.unregisterReceiver(mReceiver);
        }
    }

    @Override
    protected void handleClick() {
        showDetail(true);
    }

    @Override
    protected void handleUpdateState(NotificationsState state, Object arg) {
        state.visible = true;
        state.zen = mZenController.getZen();
        state.ringerMode = mAudioManager.getRingerMode();
        state.iconId = getNotificationIconId(state.zen, state.ringerMode);
        state.label = mContext.getString(R.string.quick_settings_notifications_label);
    }

    private int getNotificationIconId(int zenMode, int ringerMode) {
        int retValue = R.drawable.ic_qs_ringer_audible;
        if (zenMode == Global.ZEN_MODE_NO_INTERRUPTIONS) {
            retValue = R.drawable.ic_qs_zen_on;
        } else if (zenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS){
            retValue = R.drawable.ic_qs_zen_important;
        } else if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
            retValue = R.drawable.ic_qs_ringer_vibrate;
        } else if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
            retValue = R.drawable.ic_qs_ringer_silent;
        }
        return retValue;
    }

    private final ZenModeController.Callback mCallback = new ZenModeController.Callback() {
        @Override
        public void onZenChanged(int zen) {
            if (DEBUG) Log.d(TAG, "onZenChanged " + zen);
            refreshState();
        }
    };

    public static final class NotificationsState extends QSTile.State {
        public int zen;
        public int ringerMode;

        @Override
        public boolean copyTo(State other) {
            final NotificationsState o = (NotificationsState) other;
            final boolean changed = o.zen != zen || o.ringerMode != ringerMode;
            o.zen = zen;
            o.ringerMode = ringerMode;
            return super.copyTo(other) || changed;
        }

        @Override
        protected StringBuilder toStringBuilder() {
            final StringBuilder rt = super.toStringBuilder();
            rt.insert(rt.length() - 1, ",zen=" + zen + ",ringerMode=" + ringerMode);
            return rt;
        }
    }

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(intent.getAction())) {
                refreshState();
            }
        }
    };

    private final DetailAdapter mDetailAdapter = new DetailAdapter() {

        @Override
        public int getTitle() {
            return R.string.quick_settings_notifications_label;
        }

        @Override
        public Boolean getToggleState() {
            return null;
        }

        public void setToggleState(boolean state) {
            // noop
        }

        public Intent getSettingsIntent() {
            return ZenModePanel.ZEN_SETTINGS;
        }

        @Override
        public View createDetailView(Context context, View convertView, ViewGroup parent) {
            if (convertView != null) return convertView;
            final VolumeComponent volumeComponent = mHost.getVolumeComponent();
            final VolumePanel vp = new VolumePanel(mContext, parent, mZenController);
            final View v = vp.getContentView();
            v.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
                @Override
                public void onViewDetachedFromWindow(View v) {
                    volumeComponent.setVolumePanel(null);
                }

                @Override
                public void onViewAttachedToWindow(View v) {
                    vp.updateStates();
                    vp.onConfigurationChanged(null);
                    volumeComponent.setVolumePanel(vp);
                }
            });
            vp.setZenModePanelCallback(new ZenModePanel.Callback() {
                @Override
                public void onMoreSettings() {
                    mHost.startSettingsActivity(ZenModePanel.ZEN_SETTINGS);
                }

                @Override
                public void onInteraction() {
                    // noop
                }

                @Override
                public void onExpanded(boolean expanded) {
                }
            });
            vp.postVolumeChanged(AudioManager.STREAM_RING, AudioManager.FLAG_SHOW_UI);
            return v;
        }
    };
}
+4 −4
Original line number Diff line number Diff line
@@ -938,15 +938,15 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
            if (isMSim()) {
                qsh = new QSTileHost(mContext, this,
                    mBluetoothController, mLocationController, mRotationLockController,
                    mMSimNetworkController, mZenModeController, mHotspotController,
                    mCastController, mFlashlightController,
                    mMSimNetworkController, mZenModeController, mVolumeComponent,
                    mHotspotController, mCastController, mFlashlightController,
                    mUserSwitcherController, mKeyguardMonitor,
                    mSecurityController);
            } else {
                qsh = new QSTileHost(mContext, this,
                    mBluetoothController, mLocationController, mRotationLockController,
                    mNetworkController, mZenModeController, mHotspotController,
                    mCastController, mFlashlightController,
                    mNetworkController, mZenModeController, mVolumeComponent,
                    mHotspotController, mCastController, mFlashlightController,
                    mUserSwitcherController, mKeyguardMonitor,
                    mSecurityController);
            }
Loading