From 45769044b79f46b0d9f58b646534357a9a6a8adf Mon Sep 17 00:00:00 2001 From: Joshua Brown Date: Thu, 12 Apr 2018 16:36:19 -0700 Subject: [PATCH] Extract interface for the TemperatureView Extract an interface for the TemperatureView so that other implementations can be substituted. Bug: 78246329 Test: manual Change-Id: Icb0f9481c274913500a3b1754df1cdfbc48d03bf --- .../car/hvac/TemperatureTextView.java | 85 +++++++++++++++++++ .../statusbar/car/hvac/TemperatureView.java | 56 ++---------- 2 files changed, 92 insertions(+), 49 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/car/hvac/TemperatureTextView.java diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/car/hvac/TemperatureTextView.java b/packages/SystemUI/src/com/android/systemui/statusbar/car/hvac/TemperatureTextView.java new file mode 100644 index 0000000000000..8143c13b8b55a --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/car/hvac/TemperatureTextView.java @@ -0,0 +1,85 @@ +/* + * Copyright 2018 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 com.android.systemui.statusbar.car.hvac; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.widget.TextView; + +import com.android.systemui.Dependency; +import com.android.systemui.R; + +/** + * Simple text display of HVAC properties, It is designed to show temperature and is configured in + * the XML. + * XML properties: + * hvacPropertyId - Example: CarHvacManager.ID_ZONED_TEMP_SETPOINT (16385) + * hvacAreaId - Example: VehicleSeat.SEAT_ROW_1_LEFT (1) + * hvacTempFormat - Example: "%.1f\u00B0" (1 decimal and the degree symbol) + * + * Note: It registers itself with {@link HvacController} + */ +public class TemperatureTextView extends TextView implements TemperatureView { + + private final int mAreaId; + private final int mPropertyId; + private final String mTempFormat; + + public TemperatureTextView(Context context, AttributeSet attrs) { + super(context, attrs); + TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TemperatureView); + mAreaId = typedArray.getInt(R.styleable.TemperatureView_hvacAreaId,-1); + mPropertyId = typedArray.getInt(R.styleable.TemperatureView_hvacPropertyId, -1); + String format = typedArray.getString(R.styleable.TemperatureView_hvacTempFormat); + mTempFormat = (format == null) ? "%.1f\u00B0" : format; + + // register with controller + HvacController hvacController = Dependency.get(HvacController.class); + hvacController.addHvacTextView(this); + } + + /** + * Formats the float for display + * @param temp - The current temp or NaN + */ + @Override + public void setTemp(float temp) { + if (Float.isNaN(temp)) { + setText("--"); + return; + } + setText(String.format(mTempFormat, temp)); + } + + /** + * @return propertiyId Example: CarHvacManager.ID_ZONED_TEMP_SETPOINT (16385) + */ + @Override + public int getPropertyId() { + return mPropertyId; + } + + /** + * @return hvac AreaId - Example: VehicleSeat.SEAT_ROW_1_LEFT (1) + */ + @Override + public int getAreaId() { + return mAreaId; + } +} + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/car/hvac/TemperatureView.java b/packages/SystemUI/src/com/android/systemui/statusbar/car/hvac/TemperatureView.java index 4049ec3aa385b..7651356f98a39 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/car/hvac/TemperatureView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/car/hvac/TemperatureView.java @@ -16,67 +16,25 @@ package com.android.systemui.statusbar.car.hvac; -import android.content.Context; -import android.content.res.TypedArray; -import android.util.AttributeSet; -import android.widget.TextView; - -import com.android.systemui.Dependency; -import com.android.systemui.R; - /** - * Simple text display of HVAC properties, It is designed to show temperature and is configured in - * the XML. - * XML properties: - * hvacPropertyId - Example: CarHvacManager.ID_ZONED_TEMP_SETPOINT (16385) - * hvacAreaId - Example: VehicleSeat.SEAT_ROW_1_LEFT (1) - * hvacTempFormat - Example: "%.1f\u00B0" (1 decimal and the degree symbol) - * - * Note: It registers itself with {@link HvacController} + * Interface for Views that display temperature HVAC properties */ -public class TemperatureView extends TextView { - - private final int mAreaId; - private final int mPropertyId; - private final String mTempFormat; - - public TemperatureView(Context context, AttributeSet attrs) { - super(context, attrs); - TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TemperatureView); - mAreaId = typedArray.getInt(R.styleable.TemperatureView_hvacAreaId,-1); - mPropertyId = typedArray.getInt(R.styleable.TemperatureView_hvacPropertyId, -1); - String format = typedArray.getString(R.styleable.TemperatureView_hvacTempFormat); - mTempFormat = (format == null) ? "%.1f\u00B0" : format; - - // register with controller - HvacController hvacController = Dependency.get(HvacController.class); - hvacController.addHvacTextView(this); - } - +public interface TemperatureView { /** * Formats the float for display + * * @param temp - The current temp or NaN */ - public void setTemp(float temp) { - if (Float.isNaN(temp)) { - setText("--"); - return; - } - setText(String.format(mTempFormat, temp)); - } + void setTemp(float temp); + /** * @return propertiyId Example: CarHvacManager.ID_ZONED_TEMP_SETPOINT (16385) */ - public int getPropertyId() { - return mPropertyId; - } + int getPropertyId(); /** * @return hvac AreaId - Example: VehicleSeat.SEAT_ROW_1_LEFT (1) */ - public int getAreaId() { - return mAreaId; - } + int getAreaId(); } -