1f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford/* 2f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * Copyright (C) 2013 The Android Open Source Project 3f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * 4f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * Licensed under the Apache License, Version 2.0 (the "License"); 5f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * you may not use this file except in compliance with the License. 6f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * You may obtain a copy of the License at 7f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * 8f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * http://www.apache.org/licenses/LICENSE-2.0 9f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * 10f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * Unless required by applicable law or agreed to in writing, software 11f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * distributed under the License is distributed on an "AS IS" BASIS, 12f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * See the License for the specific language governing permissions and 14f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * limitations under the License. 15f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford */ 16f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford 17f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordpackage com.android.gallery3d.filtershow.controller; 18f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford 19f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordimport android.content.Context; 20f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordimport android.view.LayoutInflater; 21f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordimport android.view.View; 22f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordimport android.view.ViewGroup; 23f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordimport android.widget.LinearLayout; 24f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordimport android.widget.SeekBar; 25f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordimport android.widget.SeekBar.OnSeekBarChangeListener; 26f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford 27f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordimport com.android.gallery3d.R; 28f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorListener; 29f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorOpacityView; 30f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorSaturationView; 31f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordimport com.android.gallery3d.filtershow.editors.Editor; 32f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford 33f4b659334750a5aa75f929d18857a2ab93c9d939John Hofordpublic class SliderSaturation implements Control { 34f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford private ColorSaturationView mColorOpacityView; 35f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford private ParameterSaturation mParameter; 36f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford private Editor mEditor; 37f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford 38f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford @Override 39f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford public void setUp(ViewGroup container, Parameter parameter, Editor editor) { 40f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford container.removeAllViews(); 41f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford mEditor = editor; 42f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford Context context = container.getContext(); 43f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford mParameter = (ParameterSaturation) parameter; 44f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford LayoutInflater inflater = 45f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 46f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford LinearLayout lp = (LinearLayout) inflater.inflate( 47f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford R.layout.filtershow_saturation, container, true); 48f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford 49f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford mColorOpacityView = (ColorSaturationView) lp.findViewById(R.id.saturationView); 50f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford updateUI(); 51f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford mColorOpacityView.addColorListener(new ColorListener() { 52f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford @Override 53f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford public void setColor(float[] hsvo) { 54f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford mParameter.setValue((int) (255 * hsvo[3])); 55f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford mEditor.commitLocalRepresentation(); 56f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford } 576125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford @Override 586125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford public void addColorListener(ColorListener l) { 596125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford } 60f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford }); 61f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford } 62f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford 63f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford @Override 64f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford public View getTopView() { 65f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford return mColorOpacityView; 66f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford } 67f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford 68f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford @Override 69f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford public void setPrameter(Parameter parameter) { 70f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford mParameter = (ParameterSaturation) parameter; 71f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford if (mColorOpacityView != null) { 72f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford updateUI(); 73f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford } 74f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford } 75f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford 76f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford @Override 77f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford public void updateUI() { 78f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford mColorOpacityView.setColor(mParameter.getColor()); 79f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford } 80f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford} 81