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.graphics.Canvas;
     21 import android.graphics.ColorFilter;
     22 import android.graphics.LinearGradient;
     23 import android.graphics.Paint;
     24 import android.graphics.RectF;
     25 import android.graphics.Shader;
     26 import android.graphics.drawable.Drawable;
     27 import android.view.LayoutInflater;
     28 import android.view.View;
     29 import android.view.ViewGroup;
     30 import android.widget.LinearLayout;
     31 import android.widget.SeekBar;
     32 import android.widget.SeekBar.OnSeekBarChangeListener;
     33 
     34 import com.android.gallery3d.R;
     35 import com.android.gallery3d.app.Log;
     36 import com.android.gallery3d.filtershow.colorpicker.ColorHueView;
     37 import com.android.gallery3d.filtershow.colorpicker.ColorListener;
     38 import com.android.gallery3d.filtershow.colorpicker.ColorOpacityView;
     39 import com.android.gallery3d.filtershow.editors.Editor;
     40 
     41 public class SliderHue implements Control {
     42     public static String LOGTAG = "SliderHue";
     43     private ColorHueView mColorOpacityView;
     44     private ParameterHue mParameter;
     45     Editor mEditor;
     46 
     47     @Override
     48     public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
     49         container.removeAllViews();
     50         mEditor = editor;
     51         Context context = container.getContext();
     52         mParameter = (ParameterHue) parameter;
     53         LayoutInflater inflater =
     54                 (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     55         LinearLayout lp = (LinearLayout) inflater.inflate(
     56                 R.layout.filtershow_hue, container, true);
     57 
     58         mColorOpacityView =   (ColorHueView) lp.findViewById(R.id.hueView);
     59         updateUI();
     60         mColorOpacityView.addColorListener(new ColorListener() {
     61             @Override
     62             public void setColor(float[] hsvo) {
     63                 mParameter.setValue((int)(360* hsvo[3]));
     64                 mEditor.commitLocalRepresentation();
     65             }
     66             @Override
     67             public void addColorListener(ColorListener l) {
     68             }
     69         });
     70     }
     71 
     72     @Override
     73     public View getTopView() {
     74         return mColorOpacityView;
     75     }
     76 
     77     @Override
     78     public void setPrameter(Parameter parameter) {
     79         mParameter = (ParameterHue) parameter;
     80         if (mColorOpacityView != null) {
     81             updateUI();
     82         }
     83     }
     84 
     85     @Override
     86     public void updateUI() {
     87         mColorOpacityView.setColor(mParameter.getColor());
     88     }
     89 }
     90