diff --git a/packages/SystemUI/res/drawable-mdpi/scrubber_control_disabled_holo.png b/packages/SystemUI/res/drawable-mdpi/scrubber_control_disabled_holo.png new file mode 100644 index 0000000000000..b8adc97a4c33d Binary files /dev/null and b/packages/SystemUI/res/drawable-mdpi/scrubber_control_disabled_holo.png differ diff --git a/packages/SystemUI/res/layout-xlarge/status_bar_settings_view.xml b/packages/SystemUI/res/layout-xlarge/status_bar_settings_view.xml index 6dd97c389069e..ed07b9fcf985b 100644 --- a/packages/SystemUI/res/layout-xlarge/status_bar_settings_view.xml +++ b/packages/SystemUI/res/layout-xlarge/status_bar_settings_view.xml @@ -104,6 +104,12 @@ style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/ic_sysbar_brightness" /> + @@ -114,6 +120,12 @@ style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/ic_sysbar_sound_on" /> + diff --git a/packages/SystemUI/res/layout/status_bar_toggle_slider.xml b/packages/SystemUI/res/layout/status_bar_toggle_slider.xml new file mode 100644 index 0000000000000..c5ad047c6e9ac --- /dev/null +++ b/packages/SystemUI/res/layout/status_bar_toggle_slider.xml @@ -0,0 +1,52 @@ + + + + + + + + + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessController.java new file mode 100644 index 0000000000000..c11d04e3468a3 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessController.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.policy; + +import android.content.ContentResolver; +import android.content.Context; +import android.os.IPowerManager; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.provider.Settings; +import android.provider.Settings.SettingNotFoundException; +import android.util.Slog; +import android.view.IWindowManager; +import android.widget.CompoundButton; + +public class BrightnessController implements ToggleSlider.Listener { + private static final String TAG = "StatusBar.BrightnessController"; + + // Backlight range is from 0 - 255. Need to make sure that user + // doesn't set the backlight to 0 and get stuck + private static final int MINIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_DIM + 10; + private static final int MAXIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_ON; + + private Context mContext; + private ToggleSlider mControl; + private IPowerManager mPower; + + public BrightnessController(Context context, ToggleSlider control) { + mContext = context; + mControl = control; + + boolean automaticAvailable = context.getResources().getBoolean( + com.android.internal.R.bool.config_automatic_brightness_available); + mPower = IPowerManager.Stub.asInterface(ServiceManager.getService("power")); + + if (automaticAvailable) { + int automatic; + try { + automatic = Settings.System.getInt(mContext.getContentResolver(), + Settings.System.SCREEN_BRIGHTNESS_MODE); + } catch (SettingNotFoundException snfe) { + automatic = 0; + } + control.setChecked(automatic != 0); + } else { + control.setChecked(false); + //control.hideToggle(); + } + + int value; + try { + value = Settings.System.getInt(mContext.getContentResolver(), + Settings.System.SCREEN_BRIGHTNESS); + } catch (SettingNotFoundException ex) { + value = MAXIMUM_BACKLIGHT; + } + + control.setMax(MAXIMUM_BACKLIGHT - MINIMUM_BACKLIGHT); + control.setValue(value - MINIMUM_BACKLIGHT); + + control.setOnChangedListener(this); + } + + public void onChanged(ToggleSlider view, boolean tracking, boolean automatic, int value) { + setMode(automatic ? Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC + : Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); + if (!automatic) { + setBrightness(value + MINIMUM_BACKLIGHT); + } + } + + private void setMode(int mode) { + Settings.System.putInt(mContext.getContentResolver(), + Settings.System.SCREEN_BRIGHTNESS_MODE, mode); + } + + private void setBrightness(int brightness) { + try { + mPower.setBacklightBrightness(brightness); + } catch (RemoteException ex) { + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ToggleSlider.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ToggleSlider.java new file mode 100644 index 0000000000000..f4994d51e166d --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ToggleSlider.java @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.policy; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; +import android.util.Slog; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.RelativeLayout; +import android.widget.SeekBar; +import android.widget.TextView; +import android.widget.ToggleButton; + +import com.android.systemui.R; + +public class ToggleSlider extends RelativeLayout + implements CompoundButton.OnCheckedChangeListener, SeekBar.OnSeekBarChangeListener { + private static final String TAG = "StatusBar.ToggleSlider"; + + public interface Listener { + public void onChanged(ToggleSlider v, boolean tracking, boolean checked, int value); + } + + public static class Slider extends SeekBar { + public Slider(Context context) { + this(context, null); + } + + public Slider(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public Slider(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + } + + private Listener mListener; + private boolean mTracking; + + private ToggleButton mToggle; + private SeekBar mSlider; + private TextView mLabel; + + public ToggleSlider(Context context) { + this(context, null); + } + + public ToggleSlider(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public ToggleSlider(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + View.inflate(context, R.layout.status_bar_toggle_slider, this); + + mToggle = (ToggleButton)findViewById(R.id.toggle); + mToggle.setOnCheckedChangeListener(this); + mToggle.setTextOn("hi"); + mToggle.setTextOff("hi"); + + mSlider = (SeekBar)findViewById(R.id.slider); + mSlider.setOnSeekBarChangeListener(this); + + /* + mLabel = (TextView)findViewById(R.id.label); + mLabel.setText("yo"); + */ + } + + public void onCheckedChanged(CompoundButton toggle, boolean checked) { + Drawable thumb; + final Resources res = getContext().getResources(); + if (checked) { + thumb = res.getDrawable(R.drawable.scrubber_control_disabled_holo); + } else { + thumb = res.getDrawable(com.android.internal.R.drawable.scrubber_control_holo); + } + mSlider.setThumb(thumb); + + if (mListener != null) { + mListener.onChanged(this, mTracking, checked, mSlider.getProgress()); + } + } + + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if (mListener != null) { + mListener.onChanged(this, mTracking, mToggle.isChecked(), progress); + } + } + + public void onStartTrackingTouch(SeekBar seekBar) { + mTracking = true; + if (mListener != null) { + mListener.onChanged(this, mTracking, mToggle.isChecked(), mSlider.getProgress()); + } + mToggle.setChecked(false); + } + + public void onStopTrackingTouch(SeekBar seekBar) { + mTracking = false; + if (mListener != null) { + mListener.onChanged(this, mTracking, mToggle.isChecked(), mSlider.getProgress()); + } + } + + public void setOnChangedListener(Listener l) { + mListener = l; + } + + public void setChecked(boolean checked) { + mToggle.setChecked(checked); + } + + public boolean isChecked() { + return mToggle.isChecked(); + } + + public void setMax(int max) { + mSlider.setMax(max); + } + + public void setValue(int value) { + mSlider.setProgress(value); + } +} + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/VolumeController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/VolumeController.java new file mode 100644 index 0000000000000..c9da01aa73d28 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/VolumeController.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.policy; + +import android.content.ContentResolver; +import android.content.Context; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.media.AudioManager; +import android.provider.Settings; +import android.util.Slog; +import android.view.IWindowManager; +import android.widget.CompoundButton; + +public class VolumeController implements ToggleSlider.Listener { + private static final String TAG = "StatusBar.VolumeController"; + private static final int STREAM = AudioManager.STREAM_NOTIFICATION; + + private Context mContext; + private ToggleSlider mControl; + private AudioManager mAudioManager; + + private boolean mMute; + private int mVolume; + + public VolumeController(Context context, ToggleSlider control) { + mContext = context; + mControl = control; + mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); + + mMute = mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL; + mVolume = mAudioManager.getStreamVolume(STREAM); + control.setMax(mAudioManager.getStreamMaxVolume(STREAM)); + control.setValue(mVolume); + control.setChecked(mMute); + + control.setOnChangedListener(this); + } + + public void onChanged(ToggleSlider view, boolean tracking, boolean mute, int level) { + if (!tracking) { + if (mute) { + boolean vibeInSilent = (1 == Settings.System.getInt(mContext.getContentResolver(), + Settings.System.VIBRATE_IN_SILENT, 1)); + mAudioManager.setRingerMode( + vibeInSilent ? AudioManager.RINGER_MODE_VIBRATE + : AudioManager.RINGER_MODE_SILENT); + } else { + mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); + mAudioManager.setStreamVolume(STREAM, level, AudioManager.FLAG_PLAY_SOUND); + } + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java index d1f8dd0b39c7a..0491baa681464 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java @@ -31,13 +31,18 @@ import android.widget.TextView; import com.android.systemui.R; import com.android.systemui.statusbar.policy.AirplaneModeController; import com.android.systemui.statusbar.policy.AutoRotateController; +import com.android.systemui.statusbar.policy.BrightnessController; import com.android.systemui.statusbar.policy.DoNotDisturbController; +import com.android.systemui.statusbar.policy.ToggleSlider; +import com.android.systemui.statusbar.policy.VolumeController; public class SettingsView extends LinearLayout implements View.OnClickListener { static final String TAG = "SettingsView"; AirplaneModeController mAirplane; AutoRotateController mRotate; + VolumeController mVolume; + BrightnessController mBrightness; DoNotDisturbController mDoNotDisturb; public SettingsView(Context context, AttributeSet attrs) { @@ -59,6 +64,10 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { findViewById(R.id.network).setOnClickListener(this); mRotate = new AutoRotateController(context, (CompoundButton)findViewById(R.id.rotate_checkbox)); + mVolume = new VolumeController(context, + (ToggleSlider)findViewById(R.id.volume)); + mBrightness = new BrightnessController(context, + (ToggleSlider)findViewById(R.id.brightness)); mDoNotDisturb = new DoNotDisturbController(context, (CompoundButton)findViewById(R.id.do_not_disturb_checkbox)); findViewById(R.id.settings).setOnClickListener(this);