Roll android_tools support library to 25.1.0
[android_tools.git] / sdk / sources / android-23 / com / android / example / rscamera / VerticalSeekBar.java
blob1473e0ba8ec702c556e49f42b4ac782c27c6644e
1 /*
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;
25 /**
26 * Class to create a vertical slider
28 public class VerticalSeekBar extends SeekBar {
30 public VerticalSeekBar(Context context) {
31 super(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);
46 @Override
47 protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
48 super.onMeasure(heightMeasureSpec, widthMeasureSpec);
49 setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
52 protected void onDraw(Canvas c) {
53 c.rotate(-90);
54 c.translate(-getHeight(), 0);
56 super.onDraw(c);
59 @Override
60 public boolean onTouchEvent(MotionEvent event) {
61 if (!isEnabled()) {
62 return false;
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);
71 break;
73 case MotionEvent.ACTION_CANCEL:
74 break;
76 return true;