diff options
author | Fabrice Di Meglio <fdimeglio@google.com> | 2014-07-15 16:02:09 -0700 |
---|---|---|
committer | Fabrice Di Meglio <fdimeglio@google.com> | 2014-07-15 18:52:37 -0700 |
commit | 1b18665dbc49663f290859ce9cdf3237b8a30b7c (patch) | |
tree | 4d17463e4643cf50424cee2af2e42bf4975c6c2c | |
parent | 62a8aa7ac90ad28e8f524011480b8b379d0bb50a (diff) | |
download | packages_apps_Settings-1b18665dbc49663f290859ce9cdf3237b8a30b7c.tar.gz packages_apps_Settings-1b18665dbc49663f290859ce9cdf3237b8a30b7c.tar.bz2 packages_apps_Settings-1b18665dbc49663f290859ce9cdf3237b8a30b7c.zip |
Fix bug #16319697 ACTION_DEVICE_INFO_SETTINGS intent causes Settings app to crash
- fix the way we are passing switchBarMarginStart / switchBarMarginEnd
Change-Id: Ic6e67643be10877a74ae68075460fa5fd4cc5da1
-rw-r--r-- | res/layout/settings_main.xml | 2 | ||||
-rw-r--r-- | res/layout/switch_bar.xml | 3 | ||||
-rw-r--r-- | res/values/attrs.xml | 1 | ||||
-rw-r--r-- | res/values/themes.xml | 31 | ||||
-rw-r--r-- | src/com/android/settings/widget/SwitchBar.java | 27 |
5 files changed, 42 insertions, 22 deletions
diff --git a/res/layout/settings_main.xml b/res/layout/settings_main.xml index cfd4e6473..56737a126 100644 --- a/res/layout/settings_main.xml +++ b/res/layout/settings_main.xml @@ -33,7 +33,7 @@ android:layout_height="?android:attr/actionBarSize" android:layout_width="match_parent" android:background="@drawable/switchbar_background" - android:theme="@android:style/Theme.Material" + android:theme="?attr/switchBarTheme" /> <FrameLayout diff --git a/res/layout/switch_bar.xml b/res/layout/switch_bar.xml index be24ff1d9..6b37e4cf4 100644 --- a/res/layout/switch_bar.xml +++ b/res/layout/switch_bar.xml @@ -23,7 +23,6 @@ android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" - android:layout_marginStart="?attr/switchBarMarginStart" android:layout_gravity="center_vertical" android:textAppearance="@style/TextAppearance.Switch" android:textAlignment="viewStart" /> @@ -32,7 +31,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:layout_marginEnd="?attr/switchBarMarginEnd" android:background="@null" /> + </merge> diff --git a/res/values/attrs.xml b/res/values/attrs.xml index a4e4d48eb..71e08d8bc 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -97,6 +97,7 @@ <attr name="keywords" format="string" /> </declare-styleable> + <attr name="switchBarTheme" format="reference" /> <attr name="switchBarMarginStart" format="dimension" /> <attr name="switchBarMarginEnd" format="dimension" /> diff --git a/res/values/themes.xml b/res/values/themes.xml index 8142bb57a..0bf3c061d 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -32,8 +32,6 @@ <item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item> <item name="ic_wps">@drawable/ic_wps_dark</item> <item name="setup_divider_color">@color/setup_divider_color_dark</item> - <item name="switchBarMarginStart">0dip</item> - <item name="switchBarMarginEnd">0dip</item> <item name="wifi_signal">@drawable/wifi_signal_dark</item> <item name="dashboardBackgroundColor">@color/dashboard_background_color</item> </style> @@ -49,8 +47,6 @@ <item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item> <item name="ic_wps">@drawable/ic_wps_light</item> <item name="setup_divider_color">@color/setup_divider_color_light</item> - <item name="switchBarMarginStart">0dip</item> - <item name="switchBarMarginEnd">0dip</item> <item name="wifi_signal">@drawable/wifi_signal_light</item> <item name="dashboardBackgroundColor">@color/dashboard_background_color</item> </style> @@ -94,8 +90,8 @@ <item name="@*android:actionBarSize">@dimen/actionbar_size</item> - <item name="switchBarMarginStart">@dimen/switchbar_margin_start</item> - <item name="switchBarMarginEnd">@dimen/switchbar_margin_end</item> + <item name="switchBarTheme">@style/Theme.SwitchBar.Settings</item> + <item name="dashboardBackgroundColor">@color/dashboard_background_color</item> <!-- Redefine the ActionBar style for contentInsetStart --> @@ -110,20 +106,29 @@ </style> + <style name="Theme.SubSettings" parent="Theme.Settings"> + <!-- Redefine the ActionBar style for contentInsetStart --> + <item name="android:actionBarStyle">@style/Theme.ActionBar.SubSettings</item> + + <item name="switchBarTheme">@style/Theme.SwitchBar.SubSettings</item> + </style> + <style name="Theme.ActionBar" parent="@android:style/Widget.Material.Light.ActionBar.Solid"> <item name="android:contentInsetStart">@dimen/actionbar_contentInsetStart</item> </style> - <style name="Theme.SubSettings" parent="Theme.Settings"> - <!-- Redefine the ActionBar style for contentInsetStart --> - <item name="android:actionBarStyle">@style/Theme.SubSettingsActionBar</item> + <style name="Theme.ActionBar.SubSettings" parent="Theme.ActionBar"> + <item name="android:contentInsetStart">@dimen/actionbar_subsettings_contentInsetStart</item> + </style> - <item name="switchBarMarginStart">@dimen/switchbar_subsettings_margin_start</item> - <item name="switchBarMarginEnd">@dimen/switchbar_subsettings_margin_end</item> + <style name="Theme.SwitchBar.Settings" parent="@android:style/Theme.Material"> + <item name="switchBarMarginStart">@dimen/switchbar_margin_start</item> + <item name="switchBarMarginEnd">@dimen/switchbar_margin_end</item> </style> - <style name="Theme.SubSettingsActionBar" parent="Theme.ActionBar"> - <item name="android:contentInsetStart">@dimen/actionbar_subsettings_contentInsetStart</item> + <style name="Theme.SwitchBar.SubSettings" parent="@android:style/Theme.Material"> + <item name="switchBarMarginStart">@dimen/switchbar_subsettings_margin_start</item> + <item name="switchBarMarginEnd">@dimen/switchbar_subsettings_margin_end</item> </style> <style name="Theme.DialogWhenLarge" parent="@android:style/Theme.Material.Light.DialogWhenLarge"> diff --git a/src/com/android/settings/widget/SwitchBar.java b/src/com/android/settings/widget/SwitchBar.java index c8afa1c76..d974a9d62 100644 --- a/src/com/android/settings/widget/SwitchBar.java +++ b/src/com/android/settings/widget/SwitchBar.java @@ -17,11 +17,14 @@ package com.android.settings.widget; import android.content.Context; +import android.content.res.TypedArray; import android.os.Parcel; import android.os.Parcelable; import android.util.AttributeSet; +import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.LinearLayout; @@ -34,12 +37,6 @@ import java.util.ArrayList; public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedChangeListener, View.OnClickListener { - private ToggleSwitch mSwitch; - private TextView mTextView; - - private ArrayList<OnSwitchChangeListener> mSwitchChangeListeners = - new ArrayList<OnSwitchChangeListener>(); - public static interface OnSwitchChangeListener { /** * Called when the checked state of the Switch has changed. @@ -50,6 +47,15 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC void onSwitchChanged(Switch switchView, boolean isChecked); } + private ToggleSwitch mSwitch; + private TextView mTextView; + + private ArrayList<OnSwitchChangeListener> mSwitchChangeListeners = + new ArrayList<OnSwitchChangeListener>(); + + private static int[] MARGIN_ATTRIBUTES = { + R.attr.switchBarMarginStart, R.attr.switchBarMarginEnd}; + public SwitchBar(Context context) { this(context, null); } @@ -67,13 +73,22 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC LayoutInflater.from(context).inflate(R.layout.switch_bar, this); + final TypedArray a = context.obtainStyledAttributes(attrs, MARGIN_ATTRIBUTES); + int switchBarMarginStart = (int) a.getDimension(0, 0); + int switchBarMarginEnd = (int) a.getDimension(1, 0); + a.recycle(); + mTextView = (TextView) findViewById(R.id.switch_text); mTextView.setText(R.string.switch_off_text); + ViewGroup.MarginLayoutParams lp = (MarginLayoutParams) mTextView.getLayoutParams(); + lp.setMarginStart(switchBarMarginStart); mSwitch = (ToggleSwitch) findViewById(R.id.switch_widget); // Prevent onSaveInstanceState() to be called as we are managing the state of the Switch // on our own mSwitch.setSaveEnabled(false); + lp = (MarginLayoutParams) mSwitch.getLayoutParams(); + lp.setMarginEnd(switchBarMarginEnd); addOnSwitchChangeListener(new OnSwitchChangeListener() { @Override |