Home | History | Annotate | Download | only in volume
      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.SystemUIFactory;
     26 import com.android.systemui.qs.tiles.DndTile;
     27 
     28 import java.io.FileDescriptor;
     29 import java.io.PrintWriter;
     30 
     31 public class VolumeUI extends SystemUI {
     32     private static final String TAG = "VolumeUI";
     33     private static boolean LOGD = Log.isLoggable(TAG, Log.DEBUG);
     34 
     35     private final Handler mHandler = new Handler();
     36 
     37     private boolean mEnabled;
     38     private VolumeDialogComponent mVolumeComponent;
     39 
     40     @Override
     41     public void start() {
     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;
     46         if (!mEnabled) return;
     47 
     48         mVolumeComponent = SystemUIFactory.getInstance()
     49                 .createVolumeDialogComponent(this, mContext);
     50         mVolumeComponent.setEnableDialogs(enableVolumeUi, enableSafetyWarning);
     51         putComponent(VolumeComponent.class, getVolumeComponent());
     52         setDefaultVolumeController();
     53     }
     54 
     55     private VolumeComponent getVolumeComponent() {
     56         return mVolumeComponent;
     57     }
     58 
     59     @Override
     60     protected void onConfigurationChanged(Configuration newConfig) {
     61         super.onConfigurationChanged(newConfig);
     62         if (!mEnabled) return;
     63         getVolumeComponent().onConfigurationChanged(newConfig);
     64     }
     65 
     66     @Override
     67     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
     68         pw.print("mEnabled="); pw.println(mEnabled);
     69         if (!mEnabled) return;
     70         getVolumeComponent().dump(fd, pw, args);
     71     }
     72 
     73     private void setDefaultVolumeController() {
     74         DndTile.setVisible(mContext, true);
     75         if (LOGD) Log.d(TAG, "Registering default volume controller");
     76         getVolumeComponent().register();
     77     }
     78 }
     79