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