2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com
.android
.example
.rscamera
;
19 import android
.content
.Context
;
20 import android
.graphics
.Canvas
;
21 import android
.util
.AttributeSet
;
22 import android
.view
.MotionEvent
;
23 import android
.widget
.SeekBar
;
26 * Class to create a vertical slider
28 public class VerticalSeekBar
extends SeekBar
{
30 public VerticalSeekBar(Context context
) {
34 public VerticalSeekBar(Context context
, AttributeSet attrs
, int defStyle
) {
35 super(context
, attrs
, defStyle
);
38 public VerticalSeekBar(Context context
, AttributeSet attrs
) {
39 super(context
, attrs
);
42 protected void onSizeChanged(int w
, int h
, int oldw
, int oldh
) {
43 super.onSizeChanged(h
, w
, oldh
, oldw
);
47 protected synchronized void onMeasure(int widthMeasureSpec
, int heightMeasureSpec
) {
48 super.onMeasure(heightMeasureSpec
, widthMeasureSpec
);
49 setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
52 protected void onDraw(Canvas c
) {
54 c
.translate(-getHeight(), 0);
60 public boolean onTouchEvent(MotionEvent event
) {
65 switch (event
.getAction()) {
66 case MotionEvent
.ACTION_DOWN
:
67 case MotionEvent
.ACTION_MOVE
:
68 case MotionEvent
.ACTION_UP
:
69 setProgress(getMax() - (int) (getMax() * event
.getY() / getHeight()));
70 onSizeChanged(getWidth(), getHeight(), 0, 0);
73 case MotionEvent
.ACTION_CANCEL
: