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