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