Fabian Kozynski | c57c162 | 2019-11-20 13:05:12 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.service.controls; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Fabian Kozynski | 0bde9c1 | 2019-12-09 16:08:30 -0500 | [diff] [blame] | 21 | import android.os.Bundle; |
Fabian Kozynski | c57c162 | 2019-11-20 13:05:12 -0500 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | |
| 24 | /** |
| 25 | * Action sent by a {@link RangeTemplate}. |
| 26 | * @hide |
| 27 | */ |
| 28 | public final class FloatAction extends ControlAction { |
| 29 | |
Fabian Kozynski | 0bde9c1 | 2019-12-09 16:08:30 -0500 | [diff] [blame] | 30 | private static final String KEY_NEW_VALUE = "key_new_value"; |
| 31 | |
Fabian Kozynski | c57c162 | 2019-11-20 13:05:12 -0500 | [diff] [blame] | 32 | 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 Kozynski | 0bde9c1 | 2019-12-09 16:08:30 -0500 | [diff] [blame] | 56 | public FloatAction(Bundle b) { |
| 57 | super(b); |
| 58 | mNewValue = b.getFloat(KEY_NEW_VALUE); |
Fabian Kozynski | c57c162 | 2019-11-20 13:05:12 -0500 | [diff] [blame] | 59 | } |
| 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 Kozynski | 0bde9c1 | 2019-12-09 16:08:30 -0500 | [diff] [blame] | 77 | protected Bundle getDataBundle() { |
| 78 | Bundle b = super.getDataBundle(); |
| 79 | b.putFloat(KEY_NEW_VALUE, mNewValue); |
| 80 | return b; |
Fabian Kozynski | c57c162 | 2019-11-20 13:05:12 -0500 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | public static final @NonNull Creator<FloatAction> CREATOR = new Creator<FloatAction>() { |
| 84 | @Override |
| 85 | public FloatAction createFromParcel(Parcel source) { |
Fabian Kozynski | 0bde9c1 | 2019-12-09 16:08:30 -0500 | [diff] [blame] | 86 | return new FloatAction(source.readBundle()); |
Fabian Kozynski | c57c162 | 2019-11-20 13:05:12 -0500 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public FloatAction[] newArray(int size) { |
| 91 | return new FloatAction[size]; |
| 92 | } |
| 93 | }; |
| 94 | } |