Home | History | Annotate | Download | only in controller
      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.gallery3d.filtershow.controller;
     18 
     19 import android.content.Context;
     20 import android.view.LayoutInflater;
     21 import android.view.View;
     22 import android.view.ViewGroup;
     23 import android.widget.LinearLayout;
     24 
     25 import com.android.gallery3d.R;
     26 import com.android.gallery3d.filtershow.colorpicker.ColorBrightnessView;
     27 import com.android.gallery3d.filtershow.colorpicker.ColorListener;
     28 import com.android.gallery3d.filtershow.colorpicker.ColorOpacityView;
     29 import com.android.gallery3d.filtershow.editors.Editor;
     30 
     31 public class SliderBrightness implements Control {
     32     private ColorBrightnessView mColorOpacityView;
     33     private ParameterBrightness mParameter;
     34     Editor mEditor;
     35 
     36     @Override
     37     public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
     38         container.removeAllViews();
     39         mEditor = editor;
     40         Context context = container.getContext();
     41         mParameter = (ParameterBrightness) parameter;
     42         LayoutInflater inflater =
     43                 (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     44         LinearLayout lp = (LinearLayout) inflater.inflate(
     45                 R.layout.filtershow_brightness, container, true);
     46 
     47         mColorOpacityView =   (ColorBrightnessView) lp.findViewById(R.id.brightnessView);
     48         updateUI();
     49         mColorOpacityView.addColorListener(new ColorListener() {
     50             @Override
     51             public void setColor(float[] hsvo) {
     52                 mParameter.setValue((int)(255* hsvo[3]));
     53                 mEditor.commitLocalRepresentation();
     54             }
     55             @Override
     56             public void addColorListener(ColorListener l) {
     57             }
     58         });
     59     }
     60 
     61     @Override
     62     public View getTopView() {
     63         return mColorOpacityView;
     64     }
     65 
     66     @Override
     67     public void setPrameter(Parameter parameter) {
     68         mParameter = (ParameterBrightness) parameter;
     69         if (mColorOpacityView != null) {
     70             updateUI();
     71         }
     72     }
     73 
     74     @Override
     75     public void updateUI() {
     76         mColorOpacityView.setColor(mParameter.getColor());
     77     }
     78 }
     79