Fix bug #16319697 ACTION_DEVICE_INFO_SETTINGS intent causes Settings app to crash
- fix the way we are passing switchBarMarginStart / switchBarMarginEnd Change-Id: Ic6e67643be10877a74ae68075460fa5fd4cc5da1
This commit is contained in:
@@ -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
|
||||
|
@@ -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>
|
||||
|
||||
|
@@ -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" />
|
||||
|
||||
|
@@ -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>
|
||||
|
||||
<item name="switchBarMarginStart">@dimen/switchbar_subsettings_margin_start</item>
|
||||
<item name="switchBarMarginEnd">@dimen/switchbar_subsettings_margin_end</item>
|
||||
<style name="Theme.ActionBar.SubSettings" parent="Theme.ActionBar">
|
||||
<item name="android:contentInsetStart">@dimen/actionbar_subsettings_contentInsetStart</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.SubSettingsActionBar" parent="Theme.ActionBar">
|
||||
<item name="android:contentInsetStart">@dimen/actionbar_subsettings_contentInsetStart</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.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">
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user