Merge "Controls API - Remove unnecessary templates"

This commit is contained in:
TreeHugger Robot
2020-02-18 18:15:20 +00:00
committed by Android (Google) Code Review
5 changed files with 0 additions and 364 deletions

View File

@@ -43541,7 +43541,6 @@ package android.service.controls.templates {
method public abstract int getTemplateType();
field @NonNull public static final android.service.controls.templates.ControlTemplate ERROR_TEMPLATE;
field @NonNull public static final android.service.controls.templates.ControlTemplate NO_TEMPLATE;
field public static final int TYPE_DISCRETE_TOGGLE = 4; // 0x4
field public static final int TYPE_ERROR = -1; // 0xffffffff
field public static final int TYPE_NONE = 0; // 0x0
field public static final int TYPE_RANGE = 2; // 0x2
@@ -43552,30 +43551,6 @@ package android.service.controls.templates {
field public static final int TYPE_TOGGLE_RANGE = 6; // 0x6
}
public final class CoordinatedRangeTemplate extends android.service.controls.templates.ControlTemplate {
ctor public CoordinatedRangeTemplate(@NonNull String, float, @NonNull android.service.controls.templates.RangeTemplate, @NonNull android.service.controls.templates.RangeTemplate);
ctor public CoordinatedRangeTemplate(@NonNull String, float, float, float, float, float, float, float, float, @Nullable CharSequence);
method public float getCurrentValueHigh();
method public float getCurrentValueLow();
method @NonNull public CharSequence getFormatString();
method public float getMaxValueHigh();
method public float getMaxValueLow();
method public float getMinGap();
method public float getMinValueHigh();
method public float getMinValueLow();
method @NonNull public android.service.controls.templates.RangeTemplate getRangeHigh();
method @NonNull public android.service.controls.templates.RangeTemplate getRangeLow();
method public float getStepValue();
method public int getTemplateType();
}
public final class DiscreteToggleTemplate extends android.service.controls.templates.ControlTemplate {
ctor public DiscreteToggleTemplate(@NonNull String, @NonNull android.service.controls.templates.ControlButton, @NonNull android.service.controls.templates.ControlButton);
method @NonNull public android.service.controls.templates.ControlButton getNegativeButton();
method @NonNull public android.service.controls.templates.ControlButton getPositiveButton();
method public int getTemplateType();
}
public final class RangeTemplate extends android.service.controls.templates.ControlTemplate {
ctor public RangeTemplate(@NonNull String, float, float, float, float, @Nullable CharSequence);
method public float getCurrentValue();

View File

@@ -74,8 +74,6 @@ public abstract class ControlTemplate {
TYPE_TOGGLE,
TYPE_RANGE,
TYPE_THUMBNAIL,
TYPE_DISCRETE_TOGGLE,
TYPE_COORD_RANGE,
TYPE_TOGGLE_RANGE,
TYPE_TEMPERATURE,
TYPE_STATELESS
@@ -104,16 +102,6 @@ public abstract class ControlTemplate {
*/
public static final @TemplateType int TYPE_THUMBNAIL = 3;
/**
* Type identifier of {@link DiscreteToggleTemplate}.
*/
public static final @TemplateType int TYPE_DISCRETE_TOGGLE = 4;
/**
* @hide
*/
public static final @TemplateType int TYPE_COORD_RANGE = 5;
public static final @TemplateType int TYPE_TOGGLE_RANGE = 6;
public static final @TemplateType int TYPE_TEMPERATURE = 7;
@@ -190,10 +178,6 @@ public abstract class ControlTemplate {
return new RangeTemplate(bundle);
case TYPE_THUMBNAIL:
return new ThumbnailTemplate(bundle);
case TYPE_DISCRETE_TOGGLE:
return new DiscreteToggleTemplate(bundle);
case TYPE_COORD_RANGE:
return new CoordinatedRangeTemplate(bundle);
case TYPE_TOGGLE_RANGE:
return new ToggleRangeTemplate(bundle);
case TYPE_TEMPERATURE:

View File

@@ -1,168 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.service.controls.templates;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Bundle;
import android.util.Log;
public final class CoordinatedRangeTemplate extends ControlTemplate {
private static final String TAG = "CoordinatedRangeTemplate";
private static final @TemplateType int TYPE = TYPE_COORD_RANGE;
private static final String KEY_RANGE_LOW = "key_range_low";
private static final String KEY_RANGE_HIGH = "key_range_high";
private static final String KEY_MIN_GAP = "key_min_gap";
private final @NonNull RangeTemplate mRangeLow;
private final @NonNull RangeTemplate mRangeHigh;
private final float mMinGap;
public CoordinatedRangeTemplate(
@NonNull String templateId,
float minGap,
@NonNull RangeTemplate rangeLow,
@NonNull RangeTemplate rangeHigh) {
super(templateId);
mRangeLow = rangeLow;
mRangeHigh = rangeHigh;
if (minGap < 0) {
Log.e(TAG, "minGap must be non-negative. Setting to 0");
mMinGap = 0;
} else {
mMinGap = minGap;
}
validateRanges();
}
public CoordinatedRangeTemplate(
@NonNull String templateId,
float minGap,
float minValueLow,
float maxValueLow,
float currentValueLow,
float minValueHigh,
float maxValueHigh,
float currentValueHigh,
float stepValue,
@Nullable CharSequence formatString) {
this(templateId,
minGap,
new RangeTemplate("",
minValueLow, maxValueLow, currentValueLow, stepValue, formatString),
new RangeTemplate("",
minValueHigh, maxValueHigh, currentValueHigh, stepValue, formatString));
}
/**
* @param b
* @hide
*/
CoordinatedRangeTemplate(Bundle b) {
super(b);
mRangeLow = new RangeTemplate(b.getBundle(KEY_RANGE_LOW));
mRangeHigh = new RangeTemplate(b.getBundle(KEY_RANGE_HIGH));
mMinGap = b.getFloat(KEY_MIN_GAP);
validateRanges();
}
@NonNull
public RangeTemplate getRangeLow() {
return mRangeLow;
}
@NonNull
public RangeTemplate getRangeHigh() {
return mRangeHigh;
}
public float getMinValueLow() {
return mRangeLow.getMinValue();
}
public float getMaxValueLow() {
return mRangeLow.getMaxValue();
}
public float getCurrentValueLow() {
return mRangeLow.getCurrentValue();
}
public float getMinValueHigh() {
return mRangeHigh.getMinValue();
}
public float getMaxValueHigh() {
return mRangeHigh.getMaxValue();
}
public float getCurrentValueHigh() {
return mRangeHigh.getCurrentValue();
}
public float getStepValue() {
return mRangeLow.getStepValue();
}
public float getMinGap() {
return mMinGap;
}
@NonNull
public CharSequence getFormatString() {
return mRangeLow.getFormatString();
}
@Override
public int getTemplateType() {
return TYPE;
}
/**
* @return
* @hide
*/
@Override
@NonNull
Bundle getDataBundle() {
Bundle b = super.getDataBundle();
b.putBundle(KEY_RANGE_LOW, mRangeLow.getDataBundle());
b.putBundle(KEY_RANGE_HIGH, mRangeHigh.getDataBundle());
return b;
}
private void validateRanges() {
if (Float.compare(mRangeLow.getStepValue(), mRangeHigh.getStepValue()) != 0) {
throw new IllegalArgumentException(
String.format("lowStepValue=%f != highStepValue=%f",
mRangeLow.getStepValue(), mRangeHigh.getStepValue()));
}
if (!mRangeLow.getFormatString().equals(mRangeHigh.getFormatString())) {
throw new IllegalArgumentException(
String.format("lowFormatString=%s != highFormatString=%s",
mRangeLow.getFormatString(), mRangeHigh.getFormatString()));
}
if (mMinGap > mRangeHigh.getCurrentValue() - mRangeLow.getCurrentValue()) {
throw new IllegalArgumentException(
String.format("Minimum gap (%f) > Current gap (%f)", mMinGap,
mRangeHigh.getCurrentValue() - mRangeLow.getCurrentValue()));
}
}
}

View File

@@ -1,107 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.service.controls.templates;
import android.annotation.NonNull;
import android.os.Bundle;
import android.service.controls.Control;
import android.service.controls.actions.BooleanAction;
import com.android.internal.util.Preconditions;
/**
* A template for a {@link Control} with two discrete inputs.
*
* The two inputs represent a <i>Negative</i> input and a <i>Positive</i> input.
* <p>
* When one of the buttons is actioned, a {@link BooleanAction} will be sent.
* {@link BooleanAction#getNewState} will be {@code false} if the button was
* {@link DiscreteToggleTemplate#getNegativeButton} and {@code true} if the button was
* {@link DiscreteToggleTemplate#getPositiveButton}.
*/
public final class DiscreteToggleTemplate extends ControlTemplate {
private static final @TemplateType int TYPE = TYPE_DISCRETE_TOGGLE;
private static final String KEY_NEGATIVE_BUTTON = "key_negative_button";
private static final String KEY_POSITIVE_BUTTON = "key_positive_button";
private final @NonNull ControlButton mPositiveButton;
private final @NonNull ControlButton mNegativeButton;
/**
* @param templateId the identifier for this template object
* @param negativeButton a {@link ControlButton} for the <i>Negative</i> input
* @param positiveButton a {@link ControlButton} for the <i>Positive</i> input
*/
public DiscreteToggleTemplate(@NonNull String templateId,
@NonNull ControlButton negativeButton,
@NonNull ControlButton positiveButton) {
super(templateId);
Preconditions.checkNotNull(negativeButton);
Preconditions.checkNotNull(positiveButton);
mNegativeButton = negativeButton;
mPositiveButton = positiveButton;
}
/**
* @param b
* @hide
*/
DiscreteToggleTemplate(Bundle b) {
super(b);
mNegativeButton = b.getParcelable(KEY_NEGATIVE_BUTTON);
mPositiveButton = b.getParcelable(KEY_POSITIVE_BUTTON);
}
/**
* The {@link ControlButton} associated with the <i>Negative</i> action.
*/
@NonNull
public ControlButton getNegativeButton() {
return mNegativeButton;
}
/**
* The {@link ControlButton} associated with the <i>Positive</i> action.
*/
@NonNull
public ControlButton getPositiveButton() {
return mPositiveButton;
}
/**
* @return {@link ControlTemplate#TYPE_DISCRETE_TOGGLE}
*/
@Override
public int getTemplateType() {
return TYPE;
}
/**
* @return
* @hide
*/
@Override
@NonNull
Bundle getDataBundle() {
Bundle b = super.getDataBundle();
b.putParcelable(KEY_NEGATIVE_BUTTON, mNegativeButton);
b.putParcelable(KEY_POSITIVE_BUTTON, mPositiveButton);
return b;
}
}

View File

@@ -112,54 +112,6 @@ public class ControlTemplateTest {
assertTrue(fromParcel instanceof ThumbnailTemplate);
}
@Test
public void testUnparcelingCorrectClass_discreteToggle() {
ControlTemplate toParcel =
new DiscreteToggleTemplate(TEST_ID, mControlButton, mControlButton);
ControlTemplate fromParcel = parcelAndUnparcel(toParcel);
assertEquals(ControlTemplate.TYPE_DISCRETE_TOGGLE, fromParcel.getTemplateType());
assertTrue(fromParcel instanceof DiscreteToggleTemplate);
}
@Test
public void testUnparcelingCorrectClass_coordRange() {
ControlTemplate toParcel =
new CoordinatedRangeTemplate(TEST_ID, 0.1f, 0, 1, 0.5f, 1, 2, 1.5f, 0.1f, "%f");
ControlTemplate fromParcel = parcelAndUnparcel(toParcel);
assertEquals(ControlTemplate.TYPE_COORD_RANGE, fromParcel.getTemplateType());
assertTrue(fromParcel instanceof CoordinatedRangeTemplate);
}
@Test
public void testCoordRangeParameters_negativeMinGap() {
CoordinatedRangeTemplate template =
new CoordinatedRangeTemplate(TEST_ID, -0.1f, 0, 1, 0.5f, 1, 2, 1.5f, 0.1f, "%f");
assertEquals(0, template.getMinGap(), 0);
}
@Test(expected = IllegalArgumentException.class)
public void testCoordRangeParameters_differentStep() {
RangeTemplate rangeLow = new RangeTemplate(TEST_ID, 0, 1, 0.5f, 0.1f, "%f");
RangeTemplate rangeHigh = new RangeTemplate(TEST_ID, 0, 1, 0.75f, 0.2f, "%f");
new CoordinatedRangeTemplate(TEST_ID, 0.1f, rangeLow, rangeHigh);
}
@Test(expected = IllegalArgumentException.class)
public void testCoordRangeParameters_differentFormat() {
RangeTemplate rangeLow = new RangeTemplate(TEST_ID, 0, 1, 0.5f, 0.1f, "%f");
RangeTemplate rangeHigh = new RangeTemplate(TEST_ID, 0, 1, 0.75f, 0.1f, "%.1f");
new CoordinatedRangeTemplate(TEST_ID, 0.1f, rangeLow, rangeHigh);
}
@Test(expected = IllegalArgumentException.class)
public void testCoordRangeParameters_LargeMinGap() {
RangeTemplate rangeLow = new RangeTemplate(TEST_ID, 0, 1, 0.5f, 0.1f, "%f");
RangeTemplate rangeHigh = new RangeTemplate(TEST_ID, 0, 1, 0.75f, 0.1f, "%f");
new CoordinatedRangeTemplate(TEST_ID, 0.5f, rangeLow, rangeHigh);
}
@Test
public void testUnparcelingCorrectClass_toggleRange() {
ControlTemplate toParcel = new ToggleRangeTemplate(TEST_ID, mControlButton,