summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrob43 <robert4three@gmail.com>2012-06-30 07:51:49 -0500
committerJesus David <jesuelfather@hotmail.com>2012-06-30 07:56:49 -0500
commit159b77efac5de2150476c3cf400a85f201cae689 (patch)
treeae9f851b57924a9379eaf1fcefa13b9d5d69dae0
parent9ba2de56e07106926118d4b719a8357733cbdbec (diff)
downloadframeworks_base-159b77efac5de2150476c3cf400a85f201cae689.zip
frameworks_base-159b77efac5de2150476c3cf400a85f201cae689.tar.gz
frameworks_base-159b77efac5de2150476c3cf400a85f201cae689.tar.bz2
Tablet powerwidget improvements (1/2)
Removes a lot of unecessary code, and does not limit toggles by 6 but dinamically adds the views to layout patchset 2: remove tab Change-Id: Id125605791d2de353e7466c4dfe135c32fb80df6
-rw-r--r--packages/SystemUI/res/layout-sw600dp/status_bar_settings_button.xml15
-rw-r--r--packages/SystemUI/res/layout-sw600dp/status_bar_settings_view.xml151
-rw-r--r--packages/SystemUI/res/values/styles.xml23
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java135
4 files changed, 108 insertions, 216 deletions
diff --git a/packages/SystemUI/res/layout-sw600dp/status_bar_settings_button.xml b/packages/SystemUI/res/layout-sw600dp/status_bar_settings_button.xml
new file mode 100644
index 0000000..ebf0102
--- /dev/null
+++ b/packages/SystemUI/res/layout-sw600dp/status_bar_settings_button.xml
@@ -0,0 +1,15 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/StatusBarPanelSettingsRow">
+
+ <ImageView
+ style="@style/StatusBarPanelSettingsIcon"/>
+
+ <TextView
+ style="@style/StatusBarPanelSettingsContents"/>
+
+ <Switch android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_marginRight="5dp"/>
+
+</LinearLayout>
diff --git a/packages/SystemUI/res/layout-sw600dp/status_bar_settings_view.xml b/packages/SystemUI/res/layout-sw600dp/status_bar_settings_view.xml
index b315432..45152a0 100644
--- a/packages/SystemUI/res/layout-sw600dp/status_bar_settings_view.xml
+++ b/packages/SystemUI/res/layout-sw600dp/status_bar_settings_view.xml
@@ -18,165 +18,18 @@
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
android:layout_height="match_parent"
android:layout_width="match_parent">
<com.android.systemui.statusbar.tablet.SettingsView
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
- <!-- Toggle 1 -->
- <LinearLayout
- android:id="@+id/toggle_1"
- style="@style/StatusBarPanelSettingsRow"
- >
- <ImageView
- android:id="@+id/toggle_1_icon"
- style="@style/StatusBarPanelSettingsIcon"
- android:src="@drawable/ic_sysbar_airplane_on"
- />
- <TextView
- android:id="@+id/toggle_1_label"
- style="@style/StatusBarPanelSettingsContents"
- android:text="@string/status_bar_settings_airplane"
- />
- <Switch
- android:id="@+id/toggle_1_checkbox"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_marginRight="5dp"
- />
- </LinearLayout>
- <View style="@style/StatusBarPanelSettingsPanelSeparator" />
-
- <!-- Toggle 2 -->
- <LinearLayout
- android:id="@+id/toggle_2"
- style="@style/StatusBarPanelSettingsRow"
- >
- <ImageView
- android:id="@+id/toggle_2_icon"
- style="@style/StatusBarPanelSettingsIcon"
- android:src="@drawable/ic_sysbar_wifi_on"
- />
- <TextView
- android:id="@+id/toggle_2_label"
- style="@style/StatusBarPanelSettingsContents"
- android:text="@string/status_bar_settings_wifi_button"
- />
- <Switch
- android:id="@+id/toggle_2_checkbox"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_marginRight="5dp"
- />
- </LinearLayout>
- <View style="@style/StatusBarPanelSettingsPanelSeparator" />
-
- <!-- Toggle 3 -->
- <LinearLayout
- android:id="@+id/toggle_3"
- style="@style/StatusBarPanelSettingsRow"
- >
- <ImageView
- android:id="@+id/toggle_3_icon"
- style="@style/StatusBarPanelSettingsIcon"
- android:src="@drawable/stat_sys_data_bluetooth"
- />
- <TextView
- android:id="@+id/toggle_3_label"
- style="@style/StatusBarPanelSettingsContents"
- android:text="@string/status_bar_settings_bluetooth_button"
- />
- <Switch
- android:id="@+id/toggle_3_checkbox"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_marginRight="5dp"
- />
- </LinearLayout>
- <View style="@style/StatusBarPanelSettingsPanelSeparator" />
+ <!-- Power widget buttons will be added here -->
- <!-- Toggle 4 -->
- <LinearLayout
- android:id="@+id/toggle_4"
- style="@style/StatusBarPanelSettingsRow"
- >
- <ImageView
- android:id="@+id/toggle_4_icon"
- style="@style/StatusBarPanelSettingsIcon"
- android:src="@drawable/ic_sysbar_rotate_on"
- />
- <TextView
- android:id="@+id/toggle_4_label"
- style="@style/StatusBarPanelSettingsContents"
- android:text="@string/status_bar_settings_auto_rotation"
- />
- <Switch
- android:id="@+id/toggle_4_checkbox"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_marginRight="5dp"
- />
- </LinearLayout>
- <View style="@style/StatusBarPanelSettingsPanelSeparator" />
-
- <!-- Toggle 5 -->
- <LinearLayout
- android:id="@+id/toggle_5"
- style="@style/StatusBarPanelSettingsRow"
- >
- <ImageView
- android:id="@+id/toggle_5_icon"
- style="@style/StatusBarPanelSettingsIcon"
- android:src="@drawable/stat_gps_on"
- />
- <TextView
- android:id="@+id/toggle_5_label"
- style="@style/StatusBarPanelSettingsContents"
- android:text="@string/status_bar_settings_location"
- />
- <Switch
- android:id="@+id/toggle_5_checkbox"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_marginRight="5dp"
- />
- </LinearLayout>
- <View style="@style/StatusBarPanelSettingsPanelSeparator" />
-
- <!-- Toggle 6 -->
- <LinearLayout
- android:id="@+id/toggle_6"
- style="@style/StatusBarPanelSettingsRow"
- >
- <ImageView
- android:id="@+id/toggle_6_icon"
- style="@style/StatusBarPanelSettingsIcon"
- android:src="@drawable/stat_flashlight_on"
- />
- <TextView
- android:id="@+id/toggle_6_label"
- style="@style/StatusBarPanelSettingsContents"
- android:text="@string/status_bar_settings_flashlight"
- />
- <Switch
- android:id="@+id/toggle_6_checkbox"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_marginRight="5dp"
- />
- </LinearLayout>
<View style="@style/StatusBarPanelSettingsPanelSeparator" />
<!-- Brightness -->
diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml
index 51bd0cf..2b0fdba 100644
--- a/packages/SystemUI/res/values/styles.xml
+++ b/packages/SystemUI/res/values/styles.xml
@@ -95,5 +95,28 @@
<!-- Note: must be dp to fit in status bar -->
<item name="android:textSize">14dp</item>
</style>
+
+ <style name="StatusBarPanelSettingsIcon">
+ <item name="android:layout_height">match_parent</item>
+ <item name="android:layout_width">64dp</item>
+ <item name="android:scaleType">center</item>
+ </style>
+
+ <style name="StatusBarPanelSettingsRow">
+ <item name="android:paddingRight">16dp</item>
+ <item name="android:layout_height">64dp</item>
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:orientation">horizontal</item>
+ <item name="android:background">?android:attr/listChoiceBackgroundIndicator</item>
+ </style>
+
+ <style name="StatusBarPanelSettingsContents">
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:layout_width">0dp</item>
+ <item name="android:layout_weight">1</item>
+ <item name="android:layout_gravity">left|center_vertical</item>
+ <item name="android:textColor">?android:attr/textColorPrimary</item>
+ <item name="android:textSize">18sp</item>
+ </style>
</resources>
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 d0f9449..0432ffa 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java
@@ -31,6 +31,8 @@ import android.widget.LinearLayout;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
+import android.widget.Switch;
+import android.view.LayoutInflater;
import com.android.systemui.R;
import com.android.systemui.statusbar.policy.AirplaneModeController;
@@ -51,7 +53,6 @@ public class SettingsView extends LinearLayout implements View.OnClickListener {
static final String TAG = "SettingsView";
private static final String NO_TOGGLES = "no_toggles";
- private static final int[] TOGGLE_ID_ARRAY = new int[6];
private static final int AIRPLANE_ID = 0;
private static final int ROTATE_ID = 1;
private static final int BLUETOOTH_ID = 2;
@@ -62,15 +63,6 @@ public class SettingsView extends LinearLayout implements View.OnClickListener {
private static final int NETWORK_MODE_ID = 7;
private static final int SOUND_ID = 8;
- private static final int[] mToggleIds = new int[]{
- R.id.toggle_1, R.id.toggle_2, R.id.toggle_3, R.id.toggle_4, R.id.toggle_5, R.id.toggle_6};
- private static final int[] mToggleIcons = new int[]{
- R.id.toggle_1_icon, R.id.toggle_2_icon, R.id.toggle_3_icon, R.id.toggle_4_icon, R.id.toggle_5_icon, R.id.toggle_6_icon};
- private static final int[] mToggleLabels = new int[]{
- R.id.toggle_1_label, R.id.toggle_2_label, R.id.toggle_3_label, R.id.toggle_4_label, R.id.toggle_5_label, R.id.toggle_6_label};
- private static final int[] mToggleCheckBoxes = new int[]{
- R.id.toggle_1_checkbox, R.id.toggle_2_checkbox, R.id.toggle_3_checkbox, R.id.toggle_4_checkbox, R.id.toggle_5_checkbox, R.id.toggle_6_checkbox};
-
private static final String[] KEY_TOGGLES = new String[]{"pref_airplane_toggle", "pref_rotate_toggle", "pref_bluetooth_toggle", "pref_gps_toggle", "pref_wifi_toggle", "pref_flashlight_toggle", "pref_mobile_data_toggle", "pref_network_mode_toggle", "pref_sound_toggle"};
private static final String BUTTON_DELIMITER = "\\|";
@@ -118,6 +110,13 @@ public class SettingsView extends LinearLayout implements View.OnClickListener {
}
}
+ private class ButtonTag {
+ public int toggleId;
+ public ButtonTag(int id) {
+ toggleId = id;
+ }
+ }
+
public SettingsView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@@ -141,33 +140,46 @@ public class SettingsView extends LinearLayout implements View.OnClickListener {
mToggleContainer = BUTTONS_DEFAULT;
if(!mToggleContainer.equals(NO_TOGGLES)){
updateToggles();
-
- int mLastVisible = mToggles.length;
- for(int i=0; i<mToggleIds.length; i++){
- if(i<mLastVisible)
- findViewById(mToggleIds[i]).setOnClickListener(this);
- else
- findViewById(mToggleIds[i]).setVisibility(View.GONE);
- }
- } else {
- for(int i=0; i<mToggleIds.length; i++){
- findViewById(mToggleIds[i]).setVisibility(View.GONE);
- }
}
findViewById(R.id.settings).setOnClickListener(this);
}
- private void updateToggles(){
+ private void clearToggles() {
+ for (int i = getChildCount() - 1; i >= 0; i--) {
+ View v = getChildAt(i);
+ if (v.getTag() instanceof ButtonTag)
+ removeView(v);
+ }
+ }
+
+ private void updateToggles(){
+ clearToggleControllers();
+ clearToggles();
mToggles = mToggleContainer.split("\\|");
- for(int i=0; i<mToggles.length; i++){
+ for(int i=mToggles.length - 1; i>=0; i--){
String mToggleName = mToggles[i].replace("\\", "");
int[] resources = getResourcesById(mToggleName);
- setToggleResources(mToggleIds[i], mToggleIcons[i], mToggleLabels[i], resources[0], resources[1]);
- TOGGLE_ID_ARRAY[i] = resources[2];
- setToggleController(mToggleName, mToggleCheckBoxes[i]);
+ addToggle(resources, mToggleName);
}
}
+ private void addToggle(final int[] res, String name) {
+ LinearLayout toggle = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.status_bar_settings_button, this, false);
+ addView(toggle,0);
+
+ ImageView icon = (ImageView)toggle.getChildAt(0);
+ icon.setImageResource(res[0]);
+ TextView label = (TextView)toggle.getChildAt(1);
+ label.setText(res[1]);
+ Switch checkbox = (Switch)toggle.getChildAt(2);
+
+ toggle.setTag(new ButtonTag(res[2]));
+ toggle.setOnClickListener(this);
+
+ setToggleController(name, (CompoundButton)checkbox);
+ }
+
+
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
@@ -180,25 +192,38 @@ public class SettingsView extends LinearLayout implements View.OnClickListener {
mDoNotDisturb.release();
}
- private void setToggleController(String id, int mCheckbox){
+
+ private void clearToggleControllers() {
+ mAirplane = null;
+ mRotate = null;
+ mBluetooth = null;
+ mFlashLight = null;
+ mGps = null;
+ mMobileData = null;
+ mNetworkMode = null;
+ mSound = null;
+ mWifi = null;
+ }
+
+ private void setToggleController(String id, CompoundButton checkbox) {
if(id.equals(KEY_TOGGLES[0]))
- mAirplane = new AirplaneModeController(mContext, (CompoundButton)findViewById(mCheckbox));
+ mAirplane = new AirplaneModeController(mContext, checkbox);
else if(id.equals(KEY_TOGGLES[1]))
- mRotate = new AutoRotateController(mContext, (CompoundButton)findViewById(mCheckbox));
+ mRotate = new AutoRotateController(mContext, checkbox);
else if(id.equals(KEY_TOGGLES[2]))
- mBluetooth = new BluetoothController(mContext, (CompoundButton)findViewById(mCheckbox));
+ mBluetooth = new BluetoothController(mContext, checkbox);
else if(id.equals(KEY_TOGGLES[3]))
- mGps = new LocationController(mContext, (CompoundButton)findViewById(mCheckbox));
+ mGps = new LocationController(mContext, checkbox);
else if(id.equals(KEY_TOGGLES[4]))
- mWifi = new WifiController(mContext, (CompoundButton)findViewById(mCheckbox));
+ mWifi = new WifiController(mContext, checkbox);
else if(id.equals(KEY_TOGGLES[5]))
- mFlashLight = new FlashlightController(mContext, (CompoundButton)findViewById(mCheckbox));
+ mFlashLight = new FlashlightController(mContext, checkbox);
else if(id.equals(KEY_TOGGLES[6]))
- mMobileData = new MobileDataController(mContext, (CompoundButton)findViewById(mCheckbox));
+ mMobileData = new MobileDataController(mContext, checkbox);
else if(id.equals(KEY_TOGGLES[7]))
- mNetworkMode = new NetworkModeController(mContext, (CompoundButton)findViewById(mCheckbox));
+ mNetworkMode = new NetworkModeController(mContext, checkbox);
else if(id.equals(KEY_TOGGLES[8]))
- mSound = new SoundController(mContext, (CompoundButton)findViewById(mCheckbox));
+ mSound = new SoundController(mContext, checkbox);
}
private int[] getResourcesById(String id){
@@ -224,41 +249,17 @@ public class SettingsView extends LinearLayout implements View.OnClickListener {
return new int[]{0, 0};
}
- private void setToggleResources(int resourceId, int resourceIcon, int resourceLabel, int newResourceIcon, int newResourceLabel){
- LinearLayout mToggle = (LinearLayout) findViewById(resourceId);
- ImageView mToggleImageView = (ImageView) mToggle.findViewById(resourceIcon);
- mToggleImageView.setImageResource(newResourceIcon);
- TextView mToggleTextView = (TextView) mToggle.findViewById(resourceLabel);
- mToggleTextView.setText(newResourceLabel);
- }
-
private StatusBarManager getStatusBarManager() {
return (StatusBarManager)getContext().getSystemService(Context.STATUS_BAR_SERVICE);
}
public void onClick(View v) {
- switch (v.getId()) {
- case R.id.toggle_1:
- onClickToggle(TOGGLE_ID_ARRAY[0]);
- break;
- case R.id.toggle_2:
- onClickToggle(TOGGLE_ID_ARRAY[1]);
- break;
- case R.id.toggle_3:
- onClickToggle(TOGGLE_ID_ARRAY[2]);
- break;
- case R.id.toggle_4:
- onClickToggle(TOGGLE_ID_ARRAY[3]);
- break;
- case R.id.toggle_5:
- onClickToggle(TOGGLE_ID_ARRAY[4]);
- break;
- case R.id.toggle_6:
- onClickToggle(TOGGLE_ID_ARRAY[5]);
- break;
- case R.id.settings:
- onClickSettings();
- break;
+ if (v.getId() == R.id.settings) {
+ onClickSettings();
+ } else {
+ Object tag = v.getTag();
+ if (tag instanceof ButtonTag)
+ onClickToggle(((ButtonTag) tag).toggleId);
}
}