blob: 73d9ea7022e476c8bf8670e9ecbbd05c51264836 [file] [log] [blame]
John Spurlock3346a802014-05-20 16:25:37 -04001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
John Spurlockcdb57ae2015-02-11 19:04:11 -050017package com.android.systemui.volume;
18
John Spurlockcdb57ae2015-02-11 19:04:11 -050019import android.content.res.Configuration;
John Spurlockcdb57ae2015-02-11 19:04:11 -050020import android.os.Handler;
John Spurlockcdb57ae2015-02-11 19:04:11 -050021import android.util.Log;
22
23import com.android.systemui.R;
24import com.android.systemui.SystemUI;
John Spurlock3c4076a2015-02-24 12:12:25 -050025import com.android.systemui.qs.tiles.DndTile;
John Spurlockcdb57ae2015-02-11 19:04:11 -050026import com.android.systemui.statusbar.policy.ZenModeController;
27import com.android.systemui.statusbar.policy.ZenModeControllerImpl;
28
29import java.io.FileDescriptor;
30import java.io.PrintWriter;
31
John Spurlock3346a802014-05-20 16:25:37 -040032public class VolumeUI extends SystemUI {
33 private static final String TAG = "VolumeUI";
John Spurlockcdb57ae2015-02-11 19:04:11 -050034 private static boolean LOGD = Log.isLoggable(TAG, Log.DEBUG);
John Spurlock3346a802014-05-20 16:25:37 -040035
John Spurlock86005342014-05-23 11:58:00 -040036 private final Handler mHandler = new Handler();
John Spurlock1dad2722014-07-11 11:07:53 -040037
John Spurlockf2565a82014-10-23 20:16:22 -040038 private boolean mEnabled;
John Spurlock90be3792015-04-16 12:09:15 -040039 private VolumeDialogComponent mVolumeComponent;
John Spurlock3346a802014-05-20 16:25:37 -040040
41 @Override
42 public void start() {
John Spurlockf2565a82014-10-23 20:16:22 -040043 mEnabled = mContext.getResources().getBoolean(R.bool.enable_volume_ui);
44 if (!mEnabled) return;
John Spurlockf88d8082015-03-25 18:09:51 -040045 final ZenModeController zenController = new ZenModeControllerImpl(mContext, mHandler);
John Spurlock90be3792015-04-16 12:09:15 -040046 mVolumeComponent = new VolumeDialogComponent(this, mContext, null, zenController);
John Spurlockf88d8082015-03-25 18:09:51 -040047 putComponent(VolumeComponent.class, getVolumeComponent());
Julia Reynoldsbb983d202017-01-06 09:54:20 -050048 setDefaultVolumeController();
John Spurlock3346a802014-05-20 16:25:37 -040049 }
50
John Spurlockf88d8082015-03-25 18:09:51 -040051 private VolumeComponent getVolumeComponent() {
John Spurlock90be3792015-04-16 12:09:15 -040052 return mVolumeComponent;
John Spurlockf88d8082015-03-25 18:09:51 -040053 }
54
John Spurlockad494bc2014-07-19 15:56:19 -040055 @Override
John Spurlock7e6809a2014-08-06 16:03:14 -040056 protected void onConfigurationChanged(Configuration newConfig) {
57 super.onConfigurationChanged(newConfig);
John Spurlockf88d8082015-03-25 18:09:51 -040058 if (!mEnabled) return;
59 getVolumeComponent().onConfigurationChanged(newConfig);
John Spurlock7e6809a2014-08-06 16:03:14 -040060 }
61
62 @Override
John Spurlockad494bc2014-07-19 15:56:19 -040063 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
John Spurlockf2565a82014-10-23 20:16:22 -040064 pw.print("mEnabled="); pw.println(mEnabled);
John Spurlockf88d8082015-03-25 18:09:51 -040065 if (!mEnabled) return;
John Spurlockf88d8082015-03-25 18:09:51 -040066 getVolumeComponent().dump(fd, pw, args);
John Spurlockad494bc2014-07-19 15:56:19 -040067 }
68
Julia Reynoldsbb983d202017-01-06 09:54:20 -050069 private void setDefaultVolumeController() {
70 DndTile.setVisible(mContext, true);
71 if (LOGD) Log.d(TAG, "Registering default volume controller");
72 getVolumeComponent().register();
John Spurlockcdb57ae2015-02-11 19:04:11 -050073 }
John Spurlock3346a802014-05-20 16:25:37 -040074}