1fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford/*
2fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford * Copyright (C) 2015 The Android Open Source Project
3fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford *
4fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford * Licensed under the Apache License, Version 2.0 (the "License");
5fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford * you may not use this file except in compliance with the License.
6fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford * You may obtain a copy of the License at
7fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford *
8fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford *      http://www.apache.org/licenses/LICENSE-2.0
9fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford *
10fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford * Unless required by applicable law or agreed to in writing, software
11fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford * distributed under the License is distributed on an "AS IS" BASIS,
12fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford * See the License for the specific language governing permissions and
14fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford * limitations under the License.
15fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford */
16fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
17fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hofordpackage com.android.example.rscamera;
18fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
19fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hofordimport android.content.Context;
20fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hofordimport android.graphics.Canvas;
21fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hofordimport android.util.AttributeSet;
22fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hofordimport android.view.MotionEvent;
23fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hofordimport android.widget.SeekBar;
24fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
25fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford/**
26fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford * Class to create a vertical slider
27fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford */
28fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hofordpublic class VerticalSeekBar extends SeekBar {
29fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
30fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    public VerticalSeekBar(Context context) {
31fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        super(context);
32fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    }
33fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
34fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
35fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        super(context, attrs, defStyle);
36fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    }
37fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
38fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    public VerticalSeekBar(Context context, AttributeSet attrs) {
39fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        super(context, attrs);
40fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    }
41fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
42fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
43fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        super.onSizeChanged(h, w, oldh, oldw);
44fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    }
45fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
46fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    @Override
47fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
48fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        super.onMeasure(heightMeasureSpec, widthMeasureSpec);
49fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
50fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    }
51fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
52fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    protected void onDraw(Canvas c) {
53fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        c.rotate(-90);
54fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        c.translate(-getHeight(), 0);
55fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
56fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        super.onDraw(c);
57fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    }
58fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
59fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    @Override
60fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    public boolean onTouchEvent(MotionEvent event) {
61fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        if (!isEnabled()) {
62fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford            return false;
63fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        }
64fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
65fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        switch (event.getAction()) {
66fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford            case MotionEvent.ACTION_DOWN:
67fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford            case MotionEvent.ACTION_MOVE:
68fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford            case MotionEvent.ACTION_UP:
69fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford                setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
70fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford                onSizeChanged(getWidth(), getHeight(), 0, 0);
71fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford                break;
72fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford
73fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford            case MotionEvent.ACTION_CANCEL:
74fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford                break;
75fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        }
76fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford        return true;
77fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford    }
78fbb9dd1843197a0d2f7fcda29abbe9d170682a5dJohn Hoford}