Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: ui/android/java/src/org/chromium/ui/widget/ButtonCompat.java

Issue 1390883007: ButtonCompat: handle missing StateListAnimator gracefully. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.ui.widget; 5 package org.chromium.ui.widget;
6 6
7 import android.animation.AnimatorInflater; 7 import android.animation.AnimatorInflater;
8 import android.annotation.TargetApi; 8 import android.annotation.TargetApi;
9 import android.content.Context; 9 import android.content.Context;
10 import android.content.res.ColorStateList; 10 import android.content.res.ColorStateList;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 getBackground().mutate(); 75 getBackground().mutate();
76 setButtonColor(buttonColor); 76 setButtonColor(buttonColor);
77 77
78 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 78 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
79 // Use the StateListAnimator from the Widget.Material.Button style t o animate the 79 // Use the StateListAnimator from the Widget.Material.Button style t o animate the
80 // elevation when the button is pressed. 80 // elevation when the button is pressed.
81 TypedArray a = getContext().obtainStyledAttributes(null, 81 TypedArray a = getContext().obtainStyledAttributes(null,
82 new int[]{android.R.attr.stateListAnimator}, 0, 82 new int[]{android.R.attr.stateListAnimator}, 0,
83 android.R.style.Widget_Material_Button); 83 android.R.style.Widget_Material_Button);
84 setStateListAnimator(AnimatorInflater.loadStateListAnimator(getConte xt(), 84 int stateListAnimatorId = a.getResourceId(0, 0);
85 a.getResourceId(0, 0)));
86 a.recycle(); 85 a.recycle();
86 // stateListAnimatorId could be 0 on custom or future builds of Andr oid, or when using a
87 // framework like Xposed. Handle these cases gracefully by simply no t using a
88 // StateListAnimator.
89 if (stateListAnimatorId != 0) {
90 setStateListAnimator(AnimatorInflater.loadStateListAnimator(getC ontext(),
91 stateListAnimatorId));
92 }
87 } 93 }
88 } 94 }
89 95
90 /** 96 /**
91 * Sets the background color of the button. 97 * Sets the background color of the button.
92 */ 98 */
93 public void setButtonColor(int color) { 99 public void setButtonColor(int color) {
94 if (color == mColor) return; 100 if (color == mColor) return;
95 mColor = color; 101 mColor = color;
96 102
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 return DISABLED_COLOR; 150 return DISABLED_COLOR;
145 } 151 }
146 152
147 private static int getColorFromAttributeSet(Context context, AttributeSet at trs) { 153 private static int getColorFromAttributeSet(Context context, AttributeSet at trs) {
148 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ButtonC ompat, 0, 0); 154 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ButtonC ompat, 0, 0);
149 int color = a.getColor(R.styleable.ButtonCompat_buttonColor, Color.WHITE ); 155 int color = a.getColor(R.styleable.ButtonCompat_buttonColor, Color.WHITE );
150 a.recycle(); 156 a.recycle();
151 return color; 157 return color;
152 } 158 }
153 } 159 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698