Home | History | Annotate | Download | only in applications
      1 /*
      2  * Copyright (C) 2013 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.settings.applications;
     18 
     19 import android.content.Context;
     20 import android.support.v7.preference.Preference;
     21 import android.support.v7.preference.PreferenceViewHolder;
     22 
     23 import com.android.settings.R;
     24 
     25 public class LinearColorPreference extends Preference {
     26     float mRedRatio;
     27     float mYellowRatio;
     28     float mGreenRatio;
     29     int mRedColor = 0xffaa5030;
     30     int mYellowColor = 0xffaaaa30;
     31     int mGreenColor = 0xff30aa50;
     32     int mColoredRegions = LinearColorBar.REGION_ALL;
     33     LinearColorBar.OnRegionTappedListener mOnRegionTappedListener;
     34 
     35     public LinearColorPreference(Context context) {
     36         super(context);
     37         setLayoutResource(R.layout.preference_linearcolor);
     38     }
     39 
     40     public void setRatios(float red, float yellow, float green) {
     41         mRedRatio = red;
     42         mYellowRatio = yellow;
     43         mGreenRatio = green;
     44         notifyChanged();
     45     }
     46 
     47     public void setColors(int red, int yellow, int green) {
     48         mRedColor = red;
     49         mYellowColor = yellow;
     50         mGreenColor = green;
     51         notifyChanged();
     52     }
     53 
     54     public void setOnRegionTappedListener(LinearColorBar.OnRegionTappedListener listener) {
     55         mOnRegionTappedListener = listener;
     56         notifyChanged();
     57     }
     58 
     59     public void setColoredRegions(int regions) {
     60         mColoredRegions = regions;
     61         notifyChanged();
     62     }
     63 
     64     @Override
     65     public void onBindViewHolder(PreferenceViewHolder view) {
     66         super.onBindViewHolder(view);
     67 
     68         LinearColorBar colors = (LinearColorBar)view.findViewById(
     69                 R.id.linear_color_bar);
     70         colors.setShowIndicator(false);
     71         colors.setColors(mRedColor, mYellowColor, mGreenColor);
     72         colors.setRatios(mRedRatio, mYellowRatio, mGreenRatio);
     73         colors.setColoredRegions(mColoredRegions);
     74         colors.setOnRegionTappedListener(mOnRegionTappedListener);
     75     }
     76 }
     77