1235d2179374bec14040f20af91dc753e38ea3639John Hoford/*
2235d2179374bec14040f20af91dc753e38ea3639John Hoford * Copyright (C) 2013 The Android Open Source Project
3235d2179374bec14040f20af91dc753e38ea3639John Hoford *
4235d2179374bec14040f20af91dc753e38ea3639John Hoford * Licensed under the Apache License, Version 2.0 (the "License");
5235d2179374bec14040f20af91dc753e38ea3639John Hoford * you may not use this file except in compliance with the License.
6235d2179374bec14040f20af91dc753e38ea3639John Hoford * You may obtain a copy of the License at
7235d2179374bec14040f20af91dc753e38ea3639John Hoford *
8235d2179374bec14040f20af91dc753e38ea3639John Hoford *      http://www.apache.org/licenses/LICENSE-2.0
9235d2179374bec14040f20af91dc753e38ea3639John Hoford *
10235d2179374bec14040f20af91dc753e38ea3639John Hoford * Unless required by applicable law or agreed to in writing, software
11235d2179374bec14040f20af91dc753e38ea3639John Hoford * distributed under the License is distributed on an "AS IS" BASIS,
12235d2179374bec14040f20af91dc753e38ea3639John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13235d2179374bec14040f20af91dc753e38ea3639John Hoford * See the License for the specific language governing permissions and
14235d2179374bec14040f20af91dc753e38ea3639John Hoford * limitations under the License.
15235d2179374bec14040f20af91dc753e38ea3639John Hoford */
16235d2179374bec14040f20af91dc753e38ea3639John Hoford
17235d2179374bec14040f20af91dc753e38ea3639John Hofordpackage com.android.gallery3d.filtershow.controller;
18235d2179374bec14040f20af91dc753e38ea3639John Hoford
19235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.content.Context;
20235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.util.Log;
21235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.view.LayoutInflater;
22235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.view.View;
23235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.view.ViewGroup;
24235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.widget.SeekBar;
25235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.widget.SeekBar.OnSeekBarChangeListener;
26235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.widget.TextView;
27235d2179374bec14040f20af91dc753e38ea3639John Hoford
28235d2179374bec14040f20af91dc753e38ea3639John Hofordimport com.android.gallery3d.R;
29235d2179374bec14040f20af91dc753e38ea3639John Hofordimport com.android.gallery3d.filtershow.editors.Editor;
30235d2179374bec14040f20af91dc753e38ea3639John Hoford
31235d2179374bec14040f20af91dc753e38ea3639John Hofordpublic class TitledSlider implements Control {
32235d2179374bec14040f20af91dc753e38ea3639John Hoford    private final String LOGTAG = "ParametricEditor";
33235d2179374bec14040f20af91dc753e38ea3639John Hoford    private SeekBar mSeekBar;
34235d2179374bec14040f20af91dc753e38ea3639John Hoford    private TextView mControlName;
35235d2179374bec14040f20af91dc753e38ea3639John Hoford    private TextView mControlValue;
36235d2179374bec14040f20af91dc753e38ea3639John Hoford    protected ParameterInteger mParameter;
37235d2179374bec14040f20af91dc753e38ea3639John Hoford    Editor mEditor;
38235d2179374bec14040f20af91dc753e38ea3639John Hoford    View mTopView;
39235d2179374bec14040f20af91dc753e38ea3639John Hoford    protected int mLayoutID = R.layout.filtershow_control_title_slider;
40235d2179374bec14040f20af91dc753e38ea3639John Hoford
41235d2179374bec14040f20af91dc753e38ea3639John Hoford    @Override
42235d2179374bec14040f20af91dc753e38ea3639John Hoford    public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
43166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        container.removeAllViews();
44235d2179374bec14040f20af91dc753e38ea3639John Hoford        mEditor = editor;
45235d2179374bec14040f20af91dc753e38ea3639John Hoford        Context context = container.getContext();
46235d2179374bec14040f20af91dc753e38ea3639John Hoford        mParameter = (ParameterInteger) parameter;
47235d2179374bec14040f20af91dc753e38ea3639John Hoford        LayoutInflater inflater =
48235d2179374bec14040f20af91dc753e38ea3639John Hoford                (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
49235d2179374bec14040f20af91dc753e38ea3639John Hoford        mTopView = inflater.inflate(mLayoutID, container, true);
50235d2179374bec14040f20af91dc753e38ea3639John Hoford        mTopView.setVisibility(View.VISIBLE);
51235d2179374bec14040f20af91dc753e38ea3639John Hoford        mSeekBar = (SeekBar) mTopView.findViewById(R.id.controlValueSeekBar);
52235d2179374bec14040f20af91dc753e38ea3639John Hoford        mControlName = (TextView) mTopView.findViewById(R.id.controlName);
53235d2179374bec14040f20af91dc753e38ea3639John Hoford        mControlValue = (TextView) mTopView.findViewById(R.id.controlValue);
54235d2179374bec14040f20af91dc753e38ea3639John Hoford        updateUI();
55235d2179374bec14040f20af91dc753e38ea3639John Hoford        mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
56235d2179374bec14040f20af91dc753e38ea3639John Hoford
57235d2179374bec14040f20af91dc753e38ea3639John Hoford            @Override
58235d2179374bec14040f20af91dc753e38ea3639John Hoford            public void onStopTrackingTouch(SeekBar seekBar) {
59235d2179374bec14040f20af91dc753e38ea3639John Hoford            }
60235d2179374bec14040f20af91dc753e38ea3639John Hoford
61235d2179374bec14040f20af91dc753e38ea3639John Hoford            @Override
62235d2179374bec14040f20af91dc753e38ea3639John Hoford            public void onStartTrackingTouch(SeekBar seekBar) {
63235d2179374bec14040f20af91dc753e38ea3639John Hoford            }
64235d2179374bec14040f20af91dc753e38ea3639John Hoford
65235d2179374bec14040f20af91dc753e38ea3639John Hoford            @Override
66235d2179374bec14040f20af91dc753e38ea3639John Hoford            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
67235d2179374bec14040f20af91dc753e38ea3639John Hoford                if (mParameter != null) {
68235d2179374bec14040f20af91dc753e38ea3639John Hoford                    mParameter.setValue(progress + mParameter.getMinimum());
69235d2179374bec14040f20af91dc753e38ea3639John Hoford                    if (mControlName != null) {
70235d2179374bec14040f20af91dc753e38ea3639John Hoford                        mControlName.setText(mParameter.getParameterName());
71235d2179374bec14040f20af91dc753e38ea3639John Hoford                    }
72235d2179374bec14040f20af91dc753e38ea3639John Hoford                    if (mControlValue != null) {
73235d2179374bec14040f20af91dc753e38ea3639John Hoford                        mControlValue.setText(Integer.toString(mParameter.getValue()));
74235d2179374bec14040f20af91dc753e38ea3639John Hoford                    }
75235d2179374bec14040f20af91dc753e38ea3639John Hoford                    mEditor.commitLocalRepresentation();
76235d2179374bec14040f20af91dc753e38ea3639John Hoford                }
77235d2179374bec14040f20af91dc753e38ea3639John Hoford            }
78235d2179374bec14040f20af91dc753e38ea3639John Hoford        });
79235d2179374bec14040f20af91dc753e38ea3639John Hoford    }
80235d2179374bec14040f20af91dc753e38ea3639John Hoford
81235d2179374bec14040f20af91dc753e38ea3639John Hoford    @Override
82235d2179374bec14040f20af91dc753e38ea3639John Hoford    public void setPrameter(Parameter parameter) {
83235d2179374bec14040f20af91dc753e38ea3639John Hoford        mParameter = (ParameterInteger) parameter;
84235d2179374bec14040f20af91dc753e38ea3639John Hoford        if (mSeekBar != null)
85235d2179374bec14040f20af91dc753e38ea3639John Hoford            updateUI();
86235d2179374bec14040f20af91dc753e38ea3639John Hoford    }
87235d2179374bec14040f20af91dc753e38ea3639John Hoford
88235d2179374bec14040f20af91dc753e38ea3639John Hoford    @Override
89235d2179374bec14040f20af91dc753e38ea3639John Hoford    public void updateUI() {
9033de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford        if (mControlName != null && mParameter.getParameterName() != null) {
9133de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford            mControlName.setText(mParameter.getParameterName().toUpperCase());
92235d2179374bec14040f20af91dc753e38ea3639John Hoford        }
93235d2179374bec14040f20af91dc753e38ea3639John Hoford        if (mControlValue != null) {
94235d2179374bec14040f20af91dc753e38ea3639John Hoford            mControlValue.setText(
95235d2179374bec14040f20af91dc753e38ea3639John Hoford                    Integer.toString(mParameter.getValue()));
96235d2179374bec14040f20af91dc753e38ea3639John Hoford        }
97235d2179374bec14040f20af91dc753e38ea3639John Hoford        mSeekBar.setMax(mParameter.getMaximum() - mParameter.getMinimum());
98235d2179374bec14040f20af91dc753e38ea3639John Hoford        mSeekBar.setProgress(mParameter.getValue() - mParameter.getMinimum());
99235d2179374bec14040f20af91dc753e38ea3639John Hoford        mEditor.commitLocalRepresentation();
100235d2179374bec14040f20af91dc753e38ea3639John Hoford    }
101235d2179374bec14040f20af91dc753e38ea3639John Hoford
102235d2179374bec14040f20af91dc753e38ea3639John Hoford    @Override
103235d2179374bec14040f20af91dc753e38ea3639John Hoford    public View getTopView() {
104235d2179374bec14040f20af91dc753e38ea3639John Hoford        return mTopView;
105235d2179374bec14040f20af91dc753e38ea3639John Hoford    }
106235d2179374bec14040f20af91dc753e38ea3639John Hoford}
107