blob: f8cf79322b40bfbfe08590c5288631d456bcb0cd [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;
Brad Stenning8d1a51c2018-11-20 17:34:16 -080025import com.android.systemui.SystemUIFactory;
John Spurlock3c4076a2015-02-24 12:12:25 -050026import com.android.systemui.qs.tiles.DndTile;
John Spurlockcdb57ae2015-02-11 19:04:11 -050027
28import java.io.FileDescriptor;
29import java.io.PrintWriter;
30
John Spurlock3346a802014-05-20 16:25:37 -040031public class VolumeUI extends SystemUI {
32 private static final String TAG = "VolumeUI";
John Spurlockcdb57ae2015-02-11 19:04:11 -050033 private static boolean LOGD = Log.isLoggable(TAG, Log.DEBUG);
John Spurlock3346a802014-05-20 16:25:37 -040034
John Spurlock86005342014-05-23 11:58:00 -040035 private final Handler mHandler = new Handler();
John Spurlock1dad2722014-07-11 11:07:53 -040036
John Spurlockf2565a82014-10-23 20:16:22 -040037 private boolean mEnabled;
John Spurlock90be3792015-04-16 12:09:15 -040038 private VolumeDialogComponent mVolumeComponent;
John Spurlock3346a802014-05-20 16:25:37 -040039
40 @Override
41 public void start() {
Luke Songe0036662017-12-12 12:27:08 -080042 boolean enableVolumeUi = mContext.getResources().getBoolean(R.bool.enable_volume_ui);
43 boolean enableSafetyWarning =
44 mContext.getResources().getBoolean(R.bool.enable_safety_warning);
45 mEnabled = enableVolumeUi || enableSafetyWarning;
John Spurlockf2565a82014-10-23 20:16:22 -040046 if (!mEnabled) return;
Brad Stenning8d1a51c2018-11-20 17:34:16 -080047
48 mVolumeComponent = SystemUIFactory.getInstance()
49 .createVolumeDialogComponent(this, mContext);
Luke Songe0036662017-12-12 12:27:08 -080050 mVolumeComponent.setEnableDialogs(enableVolumeUi, enableSafetyWarning);
John Spurlockf88d8082015-03-25 18:09:51 -040051 putComponent(VolumeComponent.class, getVolumeComponent());
Julia Reynoldsbb983d202017-01-06 09:54:20 -050052 setDefaultVolumeController();
John Spurlock3346a802014-05-20 16:25:37 -040053 }
54
John Spurlockf88d8082015-03-25 18:09:51 -040055 private VolumeComponent getVolumeComponent() {
John Spurlock90be3792015-04-16 12:09:15 -040056 return mVolumeComponent;
John Spurlockf88d8082015-03-25 18:09:51 -040057 }
58
John Spurlockad494bc2014-07-19 15:56:19 -040059 @Override
John Spurlock7e6809a2014-08-06 16:03:14 -040060 protected void onConfigurationChanged(Configuration newConfig) {
61 super.onConfigurationChanged(newConfig);
John Spurlockf88d8082015-03-25 18:09:51 -040062 if (!mEnabled) return;
63 getVolumeComponent().onConfigurationChanged(newConfig);
John Spurlock7e6809a2014-08-06 16:03:14 -040064 }
65
66 @Override
John Spurlockad494bc2014-07-19 15:56:19 -040067 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
John Spurlockf2565a82014-10-23 20:16:22 -040068 pw.print("mEnabled="); pw.println(mEnabled);
John Spurlockf88d8082015-03-25 18:09:51 -040069 if (!mEnabled) return;
John Spurlockf88d8082015-03-25 18:09:51 -040070 getVolumeComponent().dump(fd, pw, args);
John Spurlockad494bc2014-07-19 15:56:19 -040071 }
72
Julia Reynoldsbb983d202017-01-06 09:54:20 -050073 private void setDefaultVolumeController() {
74 DndTile.setVisible(mContext, true);
75 if (LOGD) Log.d(TAG, "Registering default volume controller");
76 getVolumeComponent().register();
John Spurlockcdb57ae2015-02-11 19:04:11 -050077 }
John Spurlock3346a802014-05-20 16:25:37 -040078}