blob: 157e231b1da69e4313cff0e0404dcb2391e03d75 [file] [log] [blame]
Aurimas Liutikasdc3f8852024-07-11 10:07:48 -07001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.service.controls.templates;
18
19import android.annotation.NonNull;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23import com.android.internal.util.Preconditions;
24
25/**
26 * Button element for {@link ControlTemplate}.
27 */
28public final class ControlButton implements Parcelable {
29
30 private final boolean mChecked;
31 private final @NonNull CharSequence mActionDescription;
32
33 /**
34 * @param checked true if the button should be rendered as active.
35 * @param actionDescription action description for the button.
36 */
37 public ControlButton(boolean checked,
38 @NonNull CharSequence actionDescription) {
39 Preconditions.checkNotNull(actionDescription);
40 mChecked = checked;
41 mActionDescription = actionDescription;
42 }
43
44 /**
45 * Whether the button should be rendered in a checked state.
46 */
47 public boolean isChecked() {
48 return mChecked;
49 }
50
51 /**
52 * The content description for this button.
53 */
54 @NonNull
55 public CharSequence getActionDescription() {
56 return mActionDescription;
57 }
58
59
60 @Override
61 public int describeContents() {
62 return 0;
63 }
64
65 @Override
66 @NonNull
67 public void writeToParcel(@NonNull Parcel dest, int flags) {
68 dest.writeByte(mChecked ? (byte) 1 : (byte) 0);
69 dest.writeCharSequence(mActionDescription);
70 }
71
72 ControlButton(Parcel in) {
73 mChecked = in.readByte() != 0;
74 mActionDescription = in.readCharSequence();
75 }
76
77 public static final @NonNull Creator<ControlButton> CREATOR = new Creator<ControlButton>() {
78 @Override
79 public ControlButton createFromParcel(Parcel source) {
80 return new ControlButton(source);
81 }
82
83 @Override
84 public ControlButton[] newArray(int size) {
85 return new ControlButton[size];
86 }
87 };
88}