blob: d4a88b08b58a0e0b036496558d28fe8c98944d0e [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
Dave Mankoffa5d8a392019-10-10 12:21:09 -040019import android.content.Context;
John Spurlockcdb57ae2015-02-11 19:04:11 -050020import android.content.res.Configuration;
John Spurlockcdb57ae2015-02-11 19:04:11 -050021import android.os.Handler;
John Spurlockcdb57ae2015-02-11 19:04:11 -050022import android.util.Log;
23
24import com.android.systemui.R;
25import com.android.systemui.SystemUI;
Brad Stenning8d1a51c2018-11-20 17:34:16 -080026import com.android.systemui.SystemUIFactory;
John Spurlock3c4076a2015-02-24 12:12:25 -050027import com.android.systemui.qs.tiles.DndTile;
John Spurlockcdb57ae2015-02-11 19:04:11 -050028
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
Dave Mankoffa5d8a392019-10-10 12:21:09 -040041 public VolumeUI(Context context) {
42 super(context);
43 }
44
John Spurlock3346a802014-05-20 16:25:37 -040045 @Override
46 public void start() {
Luke Songe0036662017-12-12 12:27:08 -080047 boolean enableVolumeUi = mContext.getResources().getBoolean(R.bool.enable_volume_ui);
48 boolean enableSafetyWarning =
49 mContext.getResources().getBoolean(R.bool.enable_safety_warning);
50 mEnabled = enableVolumeUi || enableSafetyWarning;
John Spurlockf2565a82014-10-23 20:16:22 -040051 if (!mEnabled) return;
Brad Stenning8d1a51c2018-11-20 17:34:16 -080052
53 mVolumeComponent = SystemUIFactory.getInstance()
54 .createVolumeDialogComponent(this, mContext);
Luke Songe0036662017-12-12 12:27:08 -080055 mVolumeComponent.setEnableDialogs(enableVolumeUi, enableSafetyWarning);
John Spurlockf88d8082015-03-25 18:09:51 -040056 putComponent(VolumeComponent.class, getVolumeComponent());
Julia Reynoldsbb983d202017-01-06 09:54:20 -050057 setDefaultVolumeController();
John Spurlock3346a802014-05-20 16:25:37 -040058 }
59
John Spurlockf88d8082015-03-25 18:09:51 -040060 private VolumeComponent getVolumeComponent() {
John Spurlock90be3792015-04-16 12:09:15 -040061 return mVolumeComponent;
John Spurlockf88d8082015-03-25 18:09:51 -040062 }
63
John Spurlockad494bc2014-07-19 15:56:19 -040064 @Override
John Spurlock7e6809a2014-08-06 16:03:14 -040065 protected void onConfigurationChanged(Configuration newConfig) {
66 super.onConfigurationChanged(newConfig);
John Spurlockf88d8082015-03-25 18:09:51 -040067 if (!mEnabled) return;
68 getVolumeComponent().onConfigurationChanged(newConfig);
John Spurlock7e6809a2014-08-06 16:03:14 -040069 }
70
71 @Override
John Spurlockad494bc2014-07-19 15:56:19 -040072 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
John Spurlockf2565a82014-10-23 20:16:22 -040073 pw.print("mEnabled="); pw.println(mEnabled);
John Spurlockf88d8082015-03-25 18:09:51 -040074 if (!mEnabled) return;
John Spurlockf88d8082015-03-25 18:09:51 -040075 getVolumeComponent().dump(fd, pw, args);
John Spurlockad494bc2014-07-19 15:56:19 -040076 }
77
Julia Reynoldsbb983d202017-01-06 09:54:20 -050078 private void setDefaultVolumeController() {
79 DndTile.setVisible(mContext, true);
80 if (LOGD) Log.d(TAG, "Registering default volume controller");
81 getVolumeComponent().register();
John Spurlockcdb57ae2015-02-11 19:04:11 -050082 }
John Spurlock3346a802014-05-20 16:25:37 -040083}