package android.app;
import android.annotation.NonNull;
import android.graphics.drawable.Icon;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import java.io.PrintWriter;
public final class RemoteAction implements Parcelable {
private static final String TAG = "RemoteAction";
private final Icon mIcon;
private final CharSequence mTitle;
private final CharSequence mContentDescription;
private final PendingIntent mActionIntent;
private boolean mEnabled;
private boolean mShouldShowIcon;
RemoteAction(Parcel in) {
mIcon = Icon.CREATOR.createFromParcel(in);
mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mActionIntent = PendingIntent.CREATOR.createFromParcel(in);
mEnabled = in.readBoolean();
mShouldShowIcon = in.readBoolean();
}
public RemoteAction(@NonNull Icon icon, @NonNull CharSequence title,
@NonNull CharSequence contentDescription, @NonNull PendingIntent intent) {
if (icon == null || title == null || contentDescription == null || intent == null) {
throw new IllegalArgumentException("Expected icon, title, content description and " +
"action callback");
}
mIcon = icon;
mTitle = title;
mContentDescription = contentDescription;
mActionIntent = intent;
mEnabled = true;
mShouldShowIcon = true;
}
public void setEnabled(boolean enabled) {
mEnabled = enabled;
}
public boolean isEnabled() {
return mEnabled;
}
public void setShouldShowIcon(boolean shouldShowIcon) {
mShouldShowIcon = shouldShowIcon;
}
public boolean shouldShowIcon() {
return mShouldShowIcon;
}
public @NonNull Icon getIcon() {
return mIcon;
}
public @NonNull CharSequence getTitle() {
return mTitle;
}
public @NonNull CharSequence getContentDescription() {
return mContentDescription;
}
public @NonNull PendingIntent getActionIntent() {
return mActionIntent;
}
@Override
public RemoteAction clone() {
RemoteAction action = new RemoteAction(mIcon, mTitle, mContentDescription, mActionIntent);
action.setEnabled(mEnabled);
action.setShouldShowIcon(mShouldShowIcon);
return action;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
mIcon.writeToParcel(out, 0);
TextUtils.writeToParcel(mTitle, out, flags);
TextUtils.writeToParcel(mContentDescription, out, flags);
mActionIntent.writeToParcel(out, flags);
out.writeBoolean(mEnabled);
out.writeBoolean(mShouldShowIcon);
}
public void dump(String prefix, PrintWriter pw) {
pw.print(prefix);
pw.print("title=" + mTitle);
pw.print(" enabled=" + mEnabled);
pw.print(" contentDescription=" + mContentDescription);
pw.print(" icon=" + mIcon);
pw.print(" action=" + mActionIntent.getIntent());
pw.print(" shouldShowIcon=" + mShouldShowIcon);
pw.println();
}
public static final Parcelable.Creator<RemoteAction> CREATOR =
new Parcelable.Creator<RemoteAction>() {
public RemoteAction createFromParcel(Parcel in) {
return new RemoteAction(in);
}
public RemoteAction[] newArray(int size) {
return new RemoteAction[size];
}
};
}