OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.preferences; | 5 package org.chromium.chrome.browser.preferences; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.TypedArray; | 8 import android.content.res.TypedArray; |
9 import android.graphics.Rect; | 9 import android.graphics.Rect; |
10 import android.graphics.drawable.Drawable; | 10 import android.graphics.drawable.Drawable; |
11 import android.graphics.drawable.LayerDrawable; | 11 import android.graphics.drawable.LayerDrawable; |
12 import android.preference.SwitchPreference; | 12 import android.preference.SwitchPreference; |
13 import android.text.TextUtils; | 13 import android.text.TextUtils; |
14 import android.util.AttributeSet; | 14 import android.util.AttributeSet; |
15 import android.view.View; | 15 import android.view.View; |
16 import android.widget.TextView; | 16 import android.widget.TextView; |
17 | 17 |
18 import org.chromium.base.ApiCompatibilityUtils; | |
19 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
20 import org.chromium.chrome.browser.widget.ChromeSwitchCompat; | 19 import org.chromium.chrome.browser.widget.ChromeSwitchCompat; |
21 | 20 |
22 /** | 21 /** |
23 * A super-powered SwitchPreference designed especially for Chrome. Special feat
ures: | 22 * A super-powered SwitchPreference designed especially for Chrome. Special feat
ures: |
24 * - Supports managed preferences | 23 * - Supports managed preferences |
25 * - Displays a material-styled switch, even on pre-L devices | 24 * - Displays a material-styled switch, even on pre-L devices |
26 */ | 25 */ |
27 public class ChromeSwitchPreference extends SwitchPreference { | 26 public class ChromeSwitchPreference extends SwitchPreference { |
28 | 27 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 64 |
66 @Override | 65 @Override |
67 protected void onBindView(View view) { | 66 protected void onBindView(View view) { |
68 super.onBindView(view); | 67 super.onBindView(view); |
69 | 68 |
70 if (mDrawDivider) { | 69 if (mDrawDivider) { |
71 int left = view.getPaddingLeft(); | 70 int left = view.getPaddingLeft(); |
72 int right = view.getPaddingRight(); | 71 int right = view.getPaddingRight(); |
73 int top = view.getPaddingTop(); | 72 int top = view.getPaddingTop(); |
74 int bottom = view.getPaddingBottom(); | 73 int bottom = view.getPaddingBottom(); |
75 ApiCompatibilityUtils.setBackgroundForView(view, DividerDrawable.cre
ate(getContext())); | 74 view.setBackground(DividerDrawable.create(getContext())); |
76 view.setPadding(left, top, right, bottom); | 75 view.setPadding(left, top, right, bottom); |
77 } | 76 } |
78 | 77 |
79 ChromeSwitchCompat switchView = (ChromeSwitchCompat) view.findViewById(R
.id.switch_widget); | 78 ChromeSwitchCompat switchView = (ChromeSwitchCompat) view.findViewById(R
.id.switch_widget); |
80 // On BLU Life Play devices SwitchPreference.setWidgetLayoutResource() d
oes nothing. As a | 79 // On BLU Life Play devices SwitchPreference.setWidgetLayoutResource() d
oes nothing. As a |
81 // result, the user will see a non-material Switch and switchView will b
e null, hence the | 80 // result, the user will see a non-material Switch and switchView will b
e null, hence the |
82 // null check below. http://crbug.com/451447 | 81 // null check below. http://crbug.com/451447 |
83 if (switchView != null) { | 82 if (switchView != null) { |
84 switchView.setChecked(isChecked()); | 83 switchView.setChecked(isChecked()); |
85 } | 84 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 121 } |
123 | 122 |
124 @Override | 123 @Override |
125 protected void onBoundsChange(Rect bounds) { | 124 protected void onBoundsChange(Rect bounds) { |
126 int listDividerHeight = getDrawable(0).getIntrinsicHeight(); | 125 int listDividerHeight = getDrawable(0).getIntrinsicHeight(); |
127 setLayerInset(0, 0, bounds.height() - listDividerHeight, 0, 0); | 126 setLayerInset(0, 0, bounds.height() - listDividerHeight, 0, 0); |
128 super.onBoundsChange(bounds); | 127 super.onBoundsChange(bounds); |
129 } | 128 } |
130 } | 129 } |
131 } | 130 } |
OLD | NEW |