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 mColoredRegions = LinearColorBar.REGION_ALL;
     29     LinearColorBar.OnRegionTappedListener mOnRegionTappedListener;
     30 
     31     public LinearColorPreference(Context context) {
     32         super(context);
     33         setLayoutResource(R.layout.preference_linearcolor);
     34     }
     35 
     36     public void setRatios(float red, float yellow, float green) {
     37         mRedRatio = red;
     38         mYellowRatio = yellow;
     39         mGreenRatio = green;
     40         notifyChanged();
     41     }
     42 
     43     public void setOnRegionTappedListener(LinearColorBar.OnRegionTappedListener listener) {
     44         mOnRegionTappedListener = listener;
     45         notifyChanged();
     46     }
     47 
     48     public void setColoredRegions(int regions) {
     49         mColoredRegions = regions;
     50         notifyChanged();
     51     }
     52 
     53     @Override
     54     protected void onBindView(View view) {
     55         super.onBindView(view);
     56 
     57         LinearColorBar colors = (LinearColorBar)view.findViewById(
     58                 R.id.linear_color_bar);
     59         colors.setShowIndicator(false);
     60         colors.setColors(0xffaa5030, 0xffaaaa30, 0xff30aa50);
     61         colors.setRatios(mRedRatio, mYellowRatio, mGreenRatio);
     62         colors.setColoredRegions(mColoredRegions);
     63         colors.setOnRegionTappedListener(mOnRegionTappedListener);
     64     }
     65 }
     66