Merge "Brightness and volume controls in the quick settings panel."
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
@@ -104,6 +104,12 @@
|
||||
style="@style/StatusBarPanelSettingsIcon"
|
||||
android:src="@drawable/ic_sysbar_brightness"
|
||||
/>
|
||||
<com.android.systemui.statusbar.policy.ToggleSlider
|
||||
android:id="@+id/brightness"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<View style="@style/StatusBarPanelSettingsPanelSeparator" />
|
||||
|
||||
@@ -114,6 +120,12 @@
|
||||
style="@style/StatusBarPanelSettingsIcon"
|
||||
android:src="@drawable/ic_sysbar_sound_on"
|
||||
/>
|
||||
<com.android.systemui.statusbar.policy.ToggleSlider
|
||||
android:id="@+id/volume"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<View style="@style/StatusBarPanelSettingsPanelSeparator" />
|
||||
|
||||
|
||||
52
packages/SystemUI/res/layout/status_bar_toggle_slider.xml
Normal file
52
packages/SystemUI/res/layout/status_bar_toggle_slider.xml
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
* 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.
|
||||
-->
|
||||
|
||||
<!-- android:background="@drawable/status_bar_closed_default_background" -->
|
||||
<merge
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
|
||||
>
|
||||
<ToggleButton
|
||||
android:id="@+id/toggle"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
/>
|
||||
<view
|
||||
class="com.android.systemui.statusbar.policy.ToggleSlider$Slider"
|
||||
android:id="@+id/slider"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@id/toggle"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingLeft="20dp"
|
||||
/>
|
||||
<!--
|
||||
<TextView
|
||||
android:id="@+id/label"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_alignLeft="@id/toggle"
|
||||
android:layout_alignRight="@id/toggle"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_below="@id/toggle"
|
||||
android:gravity="center"
|
||||
/>
|
||||
-->
|
||||
</merge>
|
||||
@@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user