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