1 /* 2 * Copyright (C) 2010 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.statusbar.policy; 18 19 import android.content.ContentResolver; 20 import android.content.Context; 21 import android.os.RemoteException; 22 import android.os.ServiceManager; 23 import android.media.AudioManager; 24 import android.provider.Settings; 25 import android.util.Slog; 26 import android.view.IWindowManager; 27 import android.widget.CompoundButton; 28 29 public class VolumeController implements ToggleSlider.Listener { 30 private static final String TAG = "StatusBar.VolumeController"; 31 private static final int STREAM = AudioManager.STREAM_NOTIFICATION; 32 33 private Context mContext; 34 private ToggleSlider mControl; 35 private AudioManager mAudioManager; 36 37 private boolean mMute; 38 private int mVolume; 39 40 public VolumeController(Context context, ToggleSlider control) { 41 mContext = context; 42 mControl = control; 43 mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); 44 45 mMute = mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL; 46 mVolume = mAudioManager.getStreamVolume(STREAM); 47 control.setMax(mAudioManager.getStreamMaxVolume(STREAM)); 48 control.setValue(mVolume); 49 control.setChecked(mMute); 50 51 control.setOnChangedListener(this); 52 } 53 54 public void onChanged(ToggleSlider view, boolean tracking, boolean mute, int level) { 55 if (!tracking) { 56 if (mute) { 57 boolean vibeInSilent = (1 == Settings.System.getInt(mContext.getContentResolver(), 58 Settings.System.VIBRATE_IN_SILENT, 1)); 59 mAudioManager.setRingerMode( 60 vibeInSilent ? AudioManager.RINGER_MODE_VIBRATE 61 : AudioManager.RINGER_MODE_SILENT); 62 } else { 63 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); 64 mAudioManager.setStreamVolume(STREAM, level, AudioManager.FLAG_PLAY_SOUND); 65 } 66 } 67 } 68 } 69