summaryrefslogtreecommitdiff
path: root/core/java/android/widget/CompoundButton.java
diff options
context:
space:
mode:
authorSteven Kideckel <kideckel@google.com>2021-02-03 13:43:26 +0000
committerSteven Kideckel <kideckel@google.com>2021-02-03 23:00:24 +0000
commitc42edd69f93606470e13a5b508087c5ce8476359 (patch)
tree6ce649e42f477876acbce03f01abaef2018bc1df /core/java/android/widget/CompoundButton.java
parent09462b68e2fd803ba7e33aeb153a4f269d6d1bd6 (diff)
Enable use of of CompoundButtons in RemoteViews
This change adds @RemoteView and @RemotableViewMethod to the relevant views we'd like to enable. New APIs have been added to set Icons in CompooundButton and Switch. onCheckedChange support will be added in a follow-up CL. CompoundButton.setChecked and RadioGroup.check aren't directly remotable since RemoteViews will need to control those calls directly to ensure that any onCheckedChange listeners aren't triggered by RemoteViews actions. Bug: 179245670 Test: manual, atest Change-Id: I85e2aee62cf39ed008d9c9c1fece813293841fbd
Diffstat (limited to 'core/java/android/widget/CompoundButton.java')
-rw-r--r--core/java/android/widget/CompoundButton.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java
index 135ff9fcd989..63f8ee7528f2 100644
--- a/core/java/android/widget/CompoundButton.java
+++ b/core/java/android/widget/CompoundButton.java
@@ -27,11 +27,13 @@ import android.graphics.BlendMode;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.Icon;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
+import android.view.RemotableViewMethod;
import android.view.SoundEffectConstants;
import android.view.ViewDebug;
import android.view.ViewHierarchyEncoder;
@@ -275,6 +277,7 @@ public abstract class CompoundButton extends Button implements Checkable {
* @param resId the resource identifier of the drawable
* @attr ref android.R.styleable#CompoundButton_button
*/
+ @RemotableViewMethod(asyncImpl = "setButtonDrawableAsync")
public void setButtonDrawable(@DrawableRes int resId) {
final Drawable d;
if (resId != 0) {
@@ -285,6 +288,12 @@ public abstract class CompoundButton extends Button implements Checkable {
setButtonDrawable(d);
}
+ /** @hide **/
+ public Runnable setButtonDrawableAsync(@DrawableRes int resId) {
+ Drawable drawable = resId == 0 ? null : getContext().getDrawable(resId);
+ return () -> setButtonDrawable(drawable);
+ }
+
/**
* Sets a drawable as the compound button image.
*
@@ -336,6 +345,23 @@ public abstract class CompoundButton extends Button implements Checkable {
}
/**
+ * Sets the button of this CompoundButton to the specified Icon.
+ *
+ * @param icon an Icon holding the desired button, or {@code null} to clear
+ * the button
+ */
+ @RemotableViewMethod(asyncImpl = "setButtonIconAsync")
+ public void setButtonIcon(@Nullable Icon icon) {
+ setButtonDrawable(icon == null ? null : icon.loadDrawable(getContext()));
+ }
+
+ /** @hide **/
+ public Runnable setButtonIconAsync(@Nullable Icon icon) {
+ Drawable button = icon == null ? null : icon.loadDrawable(getContext());
+ return () -> setButtonDrawable(button);
+ }
+
+ /**
* Applies a tint to the button drawable. Does not modify the current tint
* mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
* <p>
@@ -350,6 +376,7 @@ public abstract class CompoundButton extends Button implements Checkable {
* @see #setButtonTintList(ColorStateList)
* @see Drawable#setTintList(ColorStateList)
*/
+ @RemotableViewMethod
public void setButtonTintList(@Nullable ColorStateList tint) {
mButtonTintList = tint;
mHasButtonTint = true;
@@ -394,6 +421,7 @@ public abstract class CompoundButton extends Button implements Checkable {
* @see #getButtonTintMode()
* @see Drawable#setTintBlendMode(BlendMode)
*/
+ @RemotableViewMethod
public void setButtonTintBlendMode(@Nullable BlendMode tintMode) {
mButtonBlendMode = tintMode;
mHasButtonBlendMode = true;