Update Main Switch widget.
- Update switch size - Update title magrin right - Use default text color - Update switch margin right - Support xml title attribute Fix: 177967927 Fix: 177968636 Test: Run robotest and apply the widget in Settings and see the ui Change-Id: I226abbffc1539cc31e64f4a3b3723c95b40e5780
This commit is contained in:
@@ -15,11 +15,17 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval" >
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:top="4dp"
|
||||
android:left="4dp"
|
||||
android:right="4dp"
|
||||
android:bottom="4dp">
|
||||
|
||||
<size android:height="24dp" android:width="24dp" />
|
||||
<solid android:color="@color/thumb_off" />
|
||||
<stroke android:width="4dp" android:color="@android:color/transparent" />
|
||||
<shape android:shape="oval" >
|
||||
<size android:height="20dp" android:width="20dp" />
|
||||
<solid android:color="@color/thumb_off" />
|
||||
</shape>
|
||||
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
||||
|
||||
@@ -15,11 +15,17 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval" >
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:top="4dp"
|
||||
android:left="4dp"
|
||||
android:right="4dp"
|
||||
android:bottom="4dp">
|
||||
|
||||
<size android:height="24dp" android:width="24dp" />
|
||||
<solid android:color="?android:attr/colorAccent" />
|
||||
<stroke android:width="4dp" android:color="@android:color/transparent" />
|
||||
<shape android:shape="oval" >
|
||||
<size android:height="20dp" android:width="20dp" />
|
||||
<solid android:color="?android:attr/colorAccent" />
|
||||
</shape>
|
||||
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<item
|
||||
android:width="13.33dp"
|
||||
android:height="1.67dp"
|
||||
android:left="19dp"
|
||||
android:left="21dp"
|
||||
android:gravity="center"
|
||||
android:drawable="@drawable/track_off_indicator" />
|
||||
</layer-list>
|
||||
|
||||
@@ -17,17 +17,17 @@
|
||||
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="48"
|
||||
android:viewportHeight="24">
|
||||
android:width="52dp"
|
||||
android:height="28dp"
|
||||
android:viewportWidth="52"
|
||||
android:viewportHeight="28">
|
||||
|
||||
<group>
|
||||
<clip-path
|
||||
android:pathData="M12 0H36C42.6274 0 48 5.37258 48 12C48 18.6274 42.6274 24 36 24H12C5.37258 24 0 18.6274 0 12C0 5.37258 5.37258 0 12 0Z" />
|
||||
android:pathData="M14 0H38C45.732 0 52 6.26801 52 14C52 21.732 45.732 28 38 28H14C6.26801 28 0 21.732 0 14C0 6.26801 6.26801 0 14 0Z" />
|
||||
|
||||
<path
|
||||
android:pathData="M0 0V24H48V0"
|
||||
android:pathData="M0 0V28H52V0"
|
||||
android:fillColor="@color/track_off" />
|
||||
</group>
|
||||
|
||||
|
||||
@@ -21,6 +21,6 @@
|
||||
android:width="13.19dp"
|
||||
android:height="10.06dp"
|
||||
android:gravity="center"
|
||||
android:right="19dp"
|
||||
android:right="21dp"
|
||||
android:drawable="@drawable/track_on_indicator" />
|
||||
</layer-list>
|
||||
|
||||
@@ -17,19 +17,20 @@
|
||||
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="48"
|
||||
android:viewportHeight="24"
|
||||
android:width="52dp"
|
||||
android:height="28dp"
|
||||
android:viewportWidth="52"
|
||||
android:viewportHeight="28"
|
||||
android:tint="@*android:color/switch_track_material">
|
||||
|
||||
<group>
|
||||
<clip-path
|
||||
android:pathData="M12 0H36C42.6274 0 48 5.37258 48 12C48 18.6274 42.6274 24 36 24H12C5.37258 24 0 18.6274 0 12C0 5.37258 5.37258 0 12 0Z" />
|
||||
android:pathData="M14 0H38C45.732 0 52 6.26801 52 14C52 21.732 45.732 28 38 28H14C6.26801 28 0 21.732 0 14C0 6.26801 6.26801 0 14 0Z" />
|
||||
|
||||
<path
|
||||
android:pathData="M0 0V24H48V0"
|
||||
android:pathData="M0 0V28H52V0"
|
||||
android:fillColor="@*android:color/white_disabled_material" />
|
||||
|
||||
</group>
|
||||
|
||||
</vector>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
android:minHeight="@dimen/min_switch_bar_height"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:background="?android:attr/colorBackground"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:paddingLeft="@dimen/switchbar_margin_start"
|
||||
android:paddingRight="@dimen/switchbar_margin_end">
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:paddingRight="54dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
<resources>
|
||||
|
||||
<color name="title_text_color">@*android:color/primary_text_dark</color>
|
||||
<color name="thumb_off">#BFFFFFFF</color>
|
||||
<color name="track_off">@*android:color/material_grey_600</color>
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
<resources>
|
||||
|
||||
<color name="title_text_color">@*android:color/primary_text_light</color>
|
||||
<color name="thumb_off">#BFFFFFFF</color>
|
||||
<color name="track_off">@*android:color/material_grey_600</color>
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
<resources>
|
||||
|
||||
<!-- Size of layout margin left -->
|
||||
<dimen name="switchbar_margin_start">26dp</dimen>
|
||||
<dimen name="switchbar_margin_start">22dp</dimen>
|
||||
|
||||
<!-- Size of layout margin right -->
|
||||
<dimen name="switchbar_margin_end">24dp</dimen>
|
||||
<dimen name="switchbar_margin_end">16dp</dimen>
|
||||
|
||||
<!-- Minimum width of switch -->
|
||||
<dimen name="min_switch_width">48dp</dimen>
|
||||
<dimen name="min_switch_width">52dp</dimen>
|
||||
|
||||
<!-- Minimum width of switch bar -->
|
||||
<dimen name="min_switch_bar_height">72dp</dimen>
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
<style name="MainSwitchText">
|
||||
<item name="android:textSize">20sp</item>
|
||||
<item name="android:textColor">@color/title_text_color</item>
|
||||
</style>
|
||||
|
||||
<style name="Settings.MainSwitch" parent="@android:style/Widget.Material.CompoundButton.Switch">
|
||||
|
||||
@@ -136,10 +136,8 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
|
||||
* Show the MainSwitchBar
|
||||
*/
|
||||
public void show() {
|
||||
if (!isShowing()) {
|
||||
setVisibility(View.VISIBLE);
|
||||
mSwitch.setOnCheckedChangeListener(this);
|
||||
}
|
||||
setVisibility(View.VISIBLE);
|
||||
mSwitch.setOnCheckedChangeListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
package com.android.settingslib.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Switch;
|
||||
|
||||
import androidx.core.content.res.TypedArrayUtils;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
@@ -38,30 +40,29 @@ public class MainSwitchPreference extends TwoStatePreference {
|
||||
private final List<OnMainSwitchChangeListener> mSwitchChangeListeners = new ArrayList<>();
|
||||
|
||||
private MainSwitchBar mMainSwitchBar;
|
||||
private Switch mSwitch;
|
||||
private String mTitle;
|
||||
|
||||
private RestrictedLockUtils.EnforcedAdmin mEnforcedAdmin;
|
||||
|
||||
public MainSwitchPreference(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
init(context, null);
|
||||
}
|
||||
|
||||
public MainSwitchPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
public MainSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
public MainSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,8 +77,21 @@ public class MainSwitchPreference extends TwoStatePreference {
|
||||
registerListenerToSwitchBar();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
setLayoutResource(R.layout.main_switch_layout);
|
||||
|
||||
if (attrs != null) {
|
||||
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
androidx.preference.R.styleable.Preference, 0 /*defStyleAttr*/,
|
||||
0 /*defStyleRes*/);
|
||||
final CharSequence title = TypedArrayUtils.getText(a,
|
||||
androidx.preference.R.styleable.Preference_title,
|
||||
androidx.preference.R.styleable.Preference_android_title);
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
setTitle(title.toString());
|
||||
}
|
||||
a.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user