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.util.Log; 21 import android.view.LayoutInflater; 22 import android.view.View; 23 import android.view.ViewGroup; 24 import android.widget.SeekBar; 25 import android.widget.SeekBar.OnSeekBarChangeListener; 26 import android.widget.TextView; 27 28 import com.android.gallery3d.R; 29 import com.android.gallery3d.filtershow.editors.Editor; 30 31 public class TitledSlider implements Control { 32 private final String LOGTAG = "ParametricEditor"; 33 private SeekBar mSeekBar; 34 private TextView mControlName; 35 private TextView mControlValue; 36 protected ParameterInteger mParameter; 37 Editor mEditor; 38 View mTopView; 39 protected int mLayoutID = R.layout.filtershow_control_title_slider; 40 41 @Override 42 public void setUp(ViewGroup container, Parameter parameter, Editor editor) { 43 container.removeAllViews(); 44 mEditor = editor; 45 Context context = container.getContext(); 46 mParameter = (ParameterInteger) parameter; 47 LayoutInflater inflater = 48 (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 49 mTopView = inflater.inflate(mLayoutID, container, true); 50 mTopView.setVisibility(View.VISIBLE); 51 mSeekBar = (SeekBar) mTopView.findViewById(R.id.controlValueSeekBar); 52 mControlName = (TextView) mTopView.findViewById(R.id.controlName); 53 mControlValue = (TextView) mTopView.findViewById(R.id.controlValue); 54 updateUI(); 55 mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { 56 57 @Override 58 public void onStopTrackingTouch(SeekBar seekBar) { 59 } 60 61 @Override 62 public void onStartTrackingTouch(SeekBar seekBar) { 63 } 64 65 @Override 66 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 67 if (mParameter != null) { 68 mParameter.setValue(progress + mParameter.getMinimum()); 69 if (mControlName != null) { 70 mControlName.setText(mParameter.getParameterName()); 71 } 72 if (mControlValue != null) { 73 mControlValue.setText(Integer.toString(mParameter.getValue())); 74 } 75 mEditor.commitLocalRepresentation(); 76 } 77 } 78 }); 79 } 80 81 @Override 82 public void setPrameter(Parameter parameter) { 83 mParameter = (ParameterInteger) parameter; 84 if (mSeekBar != null) 85 updateUI(); 86 } 87 88 @Override 89 public void updateUI() { 90 if (mControlName != null && mParameter.getParameterName() != null) { 91 mControlName.setText(mParameter.getParameterName().toUpperCase()); 92 } 93 if (mControlValue != null) { 94 mControlValue.setText( 95 Integer.toString(mParameter.getValue())); 96 } 97 mSeekBar.setMax(mParameter.getMaximum() - mParameter.getMinimum()); 98 mSeekBar.setProgress(mParameter.getValue() - mParameter.getMinimum()); 99 mEditor.commitLocalRepresentation(); 100 } 101 102 @Override 103 public View getTopView() { 104 return mTopView; 105 } 106 } 107