blob: 229435f647a2e14ab3e1a799c492f6cfd1d473f8 [file] [log] [blame]
Fabian Kozynskic57c1622019-11-20 13:05:12 -05001/*
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;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
Fabian Kozynski0bde9c12019-12-09 16:08:30 -050021import android.os.Bundle;
Fabian Kozynskic57c1622019-11-20 13:05:12 -050022import android.os.Parcel;
23
24/**
25 * Action sent by a {@link RangeTemplate}.
26 * @hide
27 */
28public final class FloatAction extends ControlAction {
29
Fabian Kozynski0bde9c12019-12-09 16:08:30 -050030 private static final String KEY_NEW_VALUE = "key_new_value";
31
Fabian Kozynskic57c1622019-11-20 13:05:12 -050032 private final float mNewValue;
33
34 /**
35 * @param templateId the identifier of the {@link RangeTemplate} that produced this action.
36 * @param newValue new value for the state displayed by the {@link RangeTemplate}.
37 */
38 public FloatAction(@NonNull String templateId, float newValue) {
39 this(templateId, newValue, null);
40 }
41
42 /**
43 * @param templateId the identifier of the {@link RangeTemplate} that originated this action.
44 * @param newValue new value for the state of the {@link RangeTemplate}.
45 * @param challengeValue a value sent by the user along with the action to authenticate. {@code}
46 * null is sent when no authentication is needed or has not been
47 * requested.
48 */
49
50 public FloatAction(@NonNull String templateId, float newValue,
51 @Nullable String challengeValue) {
52 super(templateId, challengeValue);
53 mNewValue = newValue;
54 }
55
Fabian Kozynski0bde9c12019-12-09 16:08:30 -050056 public FloatAction(Bundle b) {
57 super(b);
58 mNewValue = b.getFloat(KEY_NEW_VALUE);
Fabian Kozynskic57c1622019-11-20 13:05:12 -050059 }
60
61 /**
62 * The new value set for the range in the corresponding {@link RangeTemplate}.
63 */
64 public float getNewValue() {
65 return mNewValue;
66 }
67
68 /**
69 * @return {@link ControlAction#TYPE_FLOAT}
70 */
71 @Override
72 public int getActionType() {
73 return TYPE_FLOAT;
74 }
75
76 @Override
Fabian Kozynski0bde9c12019-12-09 16:08:30 -050077 protected Bundle getDataBundle() {
78 Bundle b = super.getDataBundle();
79 b.putFloat(KEY_NEW_VALUE, mNewValue);
80 return b;
Fabian Kozynskic57c1622019-11-20 13:05:12 -050081 }
82
83 public static final @NonNull Creator<FloatAction> CREATOR = new Creator<FloatAction>() {
84 @Override
85 public FloatAction createFromParcel(Parcel source) {
Fabian Kozynski0bde9c12019-12-09 16:08:30 -050086 return new FloatAction(source.readBundle());
Fabian Kozynskic57c1622019-11-20 13:05:12 -050087 }
88
89 @Override
90 public FloatAction[] newArray(int size) {
91 return new FloatAction[size];
92 }
93 };
94}