blob: c0b80417fe1499fc9e7f6c11f78227ffeb7a6000 [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;
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
Dave Mankoff33174bc2019-10-10 14:57:02 -040031import javax.inject.Inject;
32import javax.inject.Singleton;
33
34@Singleton
John Spurlock3346a802014-05-20 16:25:37 -040035public class VolumeUI extends SystemUI {
36 private static final String TAG = "VolumeUI";
John Spurlockcdb57ae2015-02-11 19:04:11 -050037 private static boolean LOGD = Log.isLoggable(TAG, Log.DEBUG);
John Spurlock3346a802014-05-20 16:25:37 -040038
John Spurlock86005342014-05-23 11:58:00 -040039 private final Handler mHandler = new Handler();
John Spurlock1dad2722014-07-11 11:07:53 -040040
John Spurlockf2565a82014-10-23 20:16:22 -040041 private boolean mEnabled;
John Spurlock90be3792015-04-16 12:09:15 -040042 private VolumeDialogComponent mVolumeComponent;
John Spurlock3346a802014-05-20 16:25:37 -040043
Dave Mankoff33174bc2019-10-10 14:57:02 -040044 @Inject
45 public VolumeUI(Context context, VolumeDialogComponent volumeDialogComponent) {
Dave Mankoffa5d8a392019-10-10 12:21:09 -040046 super(context);
Dave Mankoff33174bc2019-10-10 14:57:02 -040047 mVolumeComponent = volumeDialogComponent;
Dave Mankoffa5d8a392019-10-10 12:21:09 -040048 }
49
John Spurlock3346a802014-05-20 16:25:37 -040050 @Override
51 public void start() {
Luke Songe0036662017-12-12 12:27:08 -080052 boolean enableVolumeUi = mContext.getResources().getBoolean(R.bool.enable_volume_ui);
53 boolean enableSafetyWarning =
54 mContext.getResources().getBoolean(R.bool.enable_safety_warning);
55 mEnabled = enableVolumeUi || enableSafetyWarning;
John Spurlockf2565a82014-10-23 20:16:22 -040056 if (!mEnabled) return;
Brad Stenning8d1a51c2018-11-20 17:34:16 -080057
Luke Songe0036662017-12-12 12:27:08 -080058 mVolumeComponent.setEnableDialogs(enableVolumeUi, enableSafetyWarning);
Julia Reynoldsbb983d202017-01-06 09:54:20 -050059 setDefaultVolumeController();
John Spurlock3346a802014-05-20 16:25:37 -040060 }
61
John Spurlockad494bc2014-07-19 15:56:19 -040062 @Override
John Spurlock7e6809a2014-08-06 16:03:14 -040063 protected void onConfigurationChanged(Configuration newConfig) {
64 super.onConfigurationChanged(newConfig);
John Spurlockf88d8082015-03-25 18:09:51 -040065 if (!mEnabled) return;
Dave Mankoffa30b88b2019-11-05 20:21:38 -050066 mVolumeComponent.onConfigurationChanged(newConfig);
John Spurlock7e6809a2014-08-06 16:03:14 -040067 }
68
69 @Override
John Spurlockad494bc2014-07-19 15:56:19 -040070 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
John Spurlockf2565a82014-10-23 20:16:22 -040071 pw.print("mEnabled="); pw.println(mEnabled);
John Spurlockf88d8082015-03-25 18:09:51 -040072 if (!mEnabled) return;
Dave Mankoffa30b88b2019-11-05 20:21:38 -050073 mVolumeComponent.dump(fd, pw, args);
John Spurlockad494bc2014-07-19 15:56:19 -040074 }
75
Julia Reynoldsbb983d202017-01-06 09:54:20 -050076 private void setDefaultVolumeController() {
77 DndTile.setVisible(mContext, true);
78 if (LOGD) Log.d(TAG, "Registering default volume controller");
Dave Mankoffa30b88b2019-11-05 20:21:38 -050079 mVolumeComponent.register();
John Spurlockcdb57ae2015-02-11 19:04:11 -050080 }
John Spurlock3346a802014-05-20 16:25:37 -040081}