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 17 package com.android.systemui.volume; 18 19 import android.content.res.Configuration; 20 import android.os.Handler; 21 import android.util.Log; 22 23 import com.android.systemui.R; 24 import com.android.systemui.SystemUI; 25 import com.android.systemui.qs.tiles.DndTile; 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 32 public class VolumeUI extends SystemUI { 33 private static final String TAG = "VolumeUI"; 34 private static boolean LOGD = Log.isLoggable(TAG, Log.DEBUG); 35 36 private final Handler mHandler = new Handler(); 37 38 private boolean mEnabled; 39 private VolumeDialogComponent mVolumeComponent; 40 41 @Override start()42 public void start() { 43 boolean enableVolumeUi = mContext.getResources().getBoolean(R.bool.enable_volume_ui); 44 boolean enableSafetyWarning = 45 mContext.getResources().getBoolean(R.bool.enable_safety_warning); 46 mEnabled = enableVolumeUi || enableSafetyWarning; 47 if (!mEnabled) return; 48 mVolumeComponent = new VolumeDialogComponent(this, mContext, null); 49 mVolumeComponent.setEnableDialogs(enableVolumeUi, enableSafetyWarning); 50 putComponent(VolumeComponent.class, getVolumeComponent()); 51 setDefaultVolumeController(); 52 } 53 getVolumeComponent()54 private VolumeComponent getVolumeComponent() { 55 return mVolumeComponent; 56 } 57 58 @Override onConfigurationChanged(Configuration newConfig)59 protected void onConfigurationChanged(Configuration newConfig) { 60 super.onConfigurationChanged(newConfig); 61 if (!mEnabled) return; 62 getVolumeComponent().onConfigurationChanged(newConfig); 63 } 64 65 @Override dump(FileDescriptor fd, PrintWriter pw, String[] args)66 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 67 pw.print("mEnabled="); pw.println(mEnabled); 68 if (!mEnabled) return; 69 getVolumeComponent().dump(fd, pw, args); 70 } 71 setDefaultVolumeController()72 private void setDefaultVolumeController() { 73 DndTile.setVisible(mContext, true); 74 if (LOGD) Log.d(TAG, "Registering default volume controller"); 75 getVolumeComponent().register(); 76 } 77 } 78