Home | History | Annotate | Download | only in hvac
      1 /*
      2  * Copyright 2018 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 com.android.systemui.statusbar.car.hvac;
     18 
     19 import android.content.Context;
     20 import android.content.res.TypedArray;
     21 import android.util.AttributeSet;
     22 import android.widget.TextView;
     23 
     24 import com.android.systemui.Dependency;
     25 import com.android.systemui.R;
     26 
     27 /**
     28  * Simple text display of HVAC properties, It is designed to show temperature and is configured in
     29  * the XML.
     30  * XML properties:
     31  * hvacPropertyId - Example: CarHvacManager.ID_ZONED_TEMP_SETPOINT (16385)
     32  * hvacAreaId - Example: VehicleSeat.SEAT_ROW_1_LEFT (1)
     33  * hvacTempFormat - Example: "%.1f\u00B0" (1 decimal and the degree symbol)
     34  *
     35  * Note: It registers itself with {@link HvacController}
     36  */
     37 public class TemperatureTextView extends TextView implements TemperatureView {
     38 
     39     private final int mAreaId;
     40     private final int mPropertyId;
     41     private final String mTempFormat;
     42 
     43     public TemperatureTextView(Context context, AttributeSet attrs) {
     44         super(context, attrs);
     45         TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TemperatureView);
     46         mAreaId = typedArray.getInt(R.styleable.TemperatureView_hvacAreaId,-1);
     47         mPropertyId = typedArray.getInt(R.styleable.TemperatureView_hvacPropertyId, -1);
     48         String format = typedArray.getString(R.styleable.TemperatureView_hvacTempFormat);
     49         mTempFormat = (format == null) ? "%.1f\u00B0" : format;
     50 
     51         // register with controller
     52         HvacController hvacController = Dependency.get(HvacController.class);
     53         hvacController.addHvacTextView(this);
     54     }
     55 
     56     /**
     57      * Formats the float for display
     58      * @param temp - The current temp or NaN
     59      */
     60     @Override
     61     public void setTemp(float temp) {
     62         if (Float.isNaN(temp)) {
     63             setText("--");
     64             return;
     65         }
     66         setText(String.format(mTempFormat, temp));
     67     }
     68 
     69     /**
     70      * @return propertiyId  Example: CarHvacManager.ID_ZONED_TEMP_SETPOINT (16385)
     71      */
     72     @Override
     73     public int getPropertyId() {
     74         return mPropertyId;
     75     }
     76 
     77     /**
     78      * @return hvac AreaId - Example: VehicleSeat.SEAT_ROW_1_LEFT (1)
     79      */
     80     @Override
     81     public int getAreaId() {
     82         return mAreaId;
     83     }
     84 }
     85 
     86