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.editors.Editor; 29 30 public class BasicSlider implements Control { 31 private SeekBar mSeekBar; 32 private ParameterInteger mParameter; 33 Editor mEditor; 34 35 @Override 36 public void setUp(ViewGroup container, Parameter parameter, Editor editor) { 37 container.removeAllViews(); 38 mEditor = editor; 39 Context context = container.getContext(); 40 mParameter = (ParameterInteger) parameter; 41 LayoutInflater inflater = 42 (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 43 LinearLayout lp = (LinearLayout) inflater.inflate( 44 R.layout.filtershow_seekbar, container, true); 45 mSeekBar = (SeekBar) lp.findViewById(R.id.primarySeekBar); 46 mSeekBar.setVisibility(View.VISIBLE); 47 updateUI(); 48 mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { 49 50 @Override 51 public void onStopTrackingTouch(SeekBar seekBar) { 52 } 53 54 @Override 55 public void onStartTrackingTouch(SeekBar seekBar) { 56 } 57 58 @Override 59 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 60 if (mParameter != null) { 61 mParameter.setValue(progress + mParameter.getMinimum()); 62 mEditor.commitLocalRepresentation(); 63 64 } 65 } 66 }); 67 } 68 69 @Override 70 public View getTopView() { 71 return mSeekBar; 72 } 73 74 @Override 75 public void setPrameter(Parameter parameter) { 76 mParameter = (ParameterInteger) parameter; 77 if (mSeekBar != null) { 78 updateUI(); 79 } 80 } 81 82 @Override 83 public void updateUI() { 84 mSeekBar.setMax(mParameter.getMaximum() - mParameter.getMinimum()); 85 mSeekBar.setProgress(mParameter.getValue() - mParameter.getMinimum()); 86 } 87 } 88