John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 1 | /* |
| 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 Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 17 | package com.android.systemui.volume; |
| 18 | |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 19 | import android.content.res.Configuration; |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 20 | import android.os.Handler; |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 21 | import android.util.Log; |
| 22 | |
| 23 | import com.android.systemui.R; |
| 24 | import com.android.systemui.SystemUI; |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 25 | import com.android.systemui.SystemUIFactory; |
John Spurlock | 3c4076a | 2015-02-24 12:12:25 -0500 | [diff] [blame] | 26 | import com.android.systemui.qs.tiles.DndTile; |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 27 | |
| 28 | import java.io.FileDescriptor; |
| 29 | import java.io.PrintWriter; |
| 30 | |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 31 | public class VolumeUI extends SystemUI { |
| 32 | private static final String TAG = "VolumeUI"; |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 33 | private static boolean LOGD = Log.isLoggable(TAG, Log.DEBUG); |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 34 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 35 | private final Handler mHandler = new Handler(); |
John Spurlock | 1dad272 | 2014-07-11 11:07:53 -0400 | [diff] [blame] | 36 | |
John Spurlock | f2565a8 | 2014-10-23 20:16:22 -0400 | [diff] [blame] | 37 | private boolean mEnabled; |
John Spurlock | 90be379 | 2015-04-16 12:09:15 -0400 | [diff] [blame] | 38 | private VolumeDialogComponent mVolumeComponent; |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 39 | |
| 40 | @Override |
| 41 | public void start() { |
Luke Song | e003666 | 2017-12-12 12:27:08 -0800 | [diff] [blame] | 42 | 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 Spurlock | f2565a8 | 2014-10-23 20:16:22 -0400 | [diff] [blame] | 46 | if (!mEnabled) return; |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 47 | |
| 48 | mVolumeComponent = SystemUIFactory.getInstance() |
| 49 | .createVolumeDialogComponent(this, mContext); |
Luke Song | e003666 | 2017-12-12 12:27:08 -0800 | [diff] [blame] | 50 | mVolumeComponent.setEnableDialogs(enableVolumeUi, enableSafetyWarning); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 51 | putComponent(VolumeComponent.class, getVolumeComponent()); |
Julia Reynolds | bb983d20 | 2017-01-06 09:54:20 -0500 | [diff] [blame] | 52 | setDefaultVolumeController(); |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 53 | } |
| 54 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 55 | private VolumeComponent getVolumeComponent() { |
John Spurlock | 90be379 | 2015-04-16 12:09:15 -0400 | [diff] [blame] | 56 | return mVolumeComponent; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 57 | } |
| 58 | |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 59 | @Override |
John Spurlock | 7e6809a | 2014-08-06 16:03:14 -0400 | [diff] [blame] | 60 | protected void onConfigurationChanged(Configuration newConfig) { |
| 61 | super.onConfigurationChanged(newConfig); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 62 | if (!mEnabled) return; |
| 63 | getVolumeComponent().onConfigurationChanged(newConfig); |
John Spurlock | 7e6809a | 2014-08-06 16:03:14 -0400 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Override |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 67 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
John Spurlock | f2565a8 | 2014-10-23 20:16:22 -0400 | [diff] [blame] | 68 | pw.print("mEnabled="); pw.println(mEnabled); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 69 | if (!mEnabled) return; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 70 | getVolumeComponent().dump(fd, pw, args); |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Julia Reynolds | bb983d20 | 2017-01-06 09:54:20 -0500 | [diff] [blame] | 73 | private void setDefaultVolumeController() { |
| 74 | DndTile.setVisible(mContext, true); |
| 75 | if (LOGD) Log.d(TAG, "Registering default volume controller"); |
| 76 | getVolumeComponent().register(); |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 77 | } |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 78 | } |