BasicEditor.java revision 87835aa01412f9ba20eb57ac0cbbad3a19b48623
1/* 2 * Copyright (C) 2012 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 17package com.android.gallery3d.filtershow.editors; 18 19import android.content.Context; 20import android.view.View; 21import android.widget.FrameLayout; 22import android.widget.SeekBar; 23import android.widget.SeekBar.OnSeekBarChangeListener; 24 25import com.android.gallery3d.R; 26import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation; 27 28/** 29 * The basic editor that all the one parameter filters 30 */ 31public class BasicEditor extends Editor implements OnSeekBarChangeListener { 32 public static int ID = R.id.basicEditor; 33 private SeekBar mSeekBar; 34 private final String LOGTAG = "Editor"; 35 private int mLayoutID = R.layout.filtershow_default_editor; 36 private int mViewID = R.id.basicEditor; 37 38 public BasicEditor() { 39 super(ID); 40 } 41 42 protected BasicEditor(int id) { 43 super(id); 44 } 45 46 protected BasicEditor(int id, int layoutID, int viewID) { 47 super(id); 48 mLayoutID = layoutID; 49 mViewID = viewID; 50 } 51 52 @Override 53 public void createEditor(Context context, FrameLayout frameLayout) { 54 super.createEditor(context, frameLayout); 55 unpack(mViewID, mLayoutID); 56 mSeekBar = (SeekBar) mView.findViewById(R.id.filterSeekBar); 57 mSeekBar.setOnSeekBarChangeListener(this); 58 } 59 60 @Override 61 public void reflectCurrentFilter() { 62 super.reflectCurrentFilter(); 63 if (getLocalRepresentation() != null && getLocalRepresentation() instanceof FilterBasicRepresentation) { 64 FilterBasicRepresentation interval = (FilterBasicRepresentation) getLocalRepresentation(); 65 boolean f = interval.showParameterValue(); 66 mSeekBar.setVisibility((f) ? View.VISIBLE : View.GONE); 67 int value = interval.getValue(); 68 int min = interval.getMinimum(); 69 int max = interval.getMaximum(); 70 mSeekBar.setMax(max - min); 71 mSeekBar.setProgress(value - min); 72 } 73 } 74 75 @Override 76 public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) { 77 if (getLocalRepresentation() != null && getLocalRepresentation() instanceof FilterBasicRepresentation) { 78 FilterBasicRepresentation interval = (FilterBasicRepresentation) getLocalRepresentation(); 79 int value = progress + interval.getMinimum(); 80 interval.setValue(value); 81 mImageShow.onNewValue(value); 82 mView.invalidate(); 83 if (interval.showParameterValue()) { 84 mPanelController.onNewValue(value); 85 } 86 commitLocalRepresentation(); 87 } 88 } 89 90 @Override 91 public void onStartTrackingTouch(SeekBar arg0) { 92 } 93 94 @Override 95 public void onStopTrackingTouch(SeekBar arg0) { 96 } 97} 98