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; |
John Spurlock | 3c4076a | 2015-02-24 12:12:25 -0500 | [diff] [blame] | 25 | import com.android.systemui.qs.tiles.DndTile; |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 26 | import com.android.systemui.statusbar.policy.ZenModeController; |
| 27 | import com.android.systemui.statusbar.policy.ZenModeControllerImpl; |
| 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 | |
| 41 | @Override |
| 42 | public void start() { |
John Spurlock | f2565a8 | 2014-10-23 20:16:22 -0400 | [diff] [blame] | 43 | mEnabled = mContext.getResources().getBoolean(R.bool.enable_volume_ui); |
| 44 | if (!mEnabled) return; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 45 | mVolumeComponent = new VolumeDialogComponent(this, mContext, null); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 46 | putComponent(VolumeComponent.class, getVolumeComponent()); |
Julia Reynolds | bb983d20 | 2017-01-06 09:54:20 -0500 | [diff] [blame] | 47 | setDefaultVolumeController(); |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 48 | } |
| 49 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 50 | private VolumeComponent getVolumeComponent() { |
John Spurlock | 90be379 | 2015-04-16 12:09:15 -0400 | [diff] [blame] | 51 | return mVolumeComponent; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 52 | } |
| 53 | |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 54 | @Override |
John Spurlock | 7e6809a | 2014-08-06 16:03:14 -0400 | [diff] [blame] | 55 | protected void onConfigurationChanged(Configuration newConfig) { |
| 56 | super.onConfigurationChanged(newConfig); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 57 | if (!mEnabled) return; |
| 58 | getVolumeComponent().onConfigurationChanged(newConfig); |
John Spurlock | 7e6809a | 2014-08-06 16:03:14 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 62 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
John Spurlock | f2565a8 | 2014-10-23 20:16:22 -0400 | [diff] [blame] | 63 | pw.print("mEnabled="); pw.println(mEnabled); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 64 | if (!mEnabled) return; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 65 | getVolumeComponent().dump(fd, pw, args); |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 66 | } |
| 67 | |
Julia Reynolds | bb983d20 | 2017-01-06 09:54:20 -0500 | [diff] [blame] | 68 | private void setDefaultVolumeController() { |
| 69 | DndTile.setVisible(mContext, true); |
| 70 | if (LOGD) Log.d(TAG, "Registering default volume controller"); |
| 71 | getVolumeComponent().register(); |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 72 | } |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 73 | } |