/* * Light Controller, to Control wifi LED Lighting * Copyright (C) 2014 Eliot Stocker * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package tv.piratemedia.lightcontroler; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.SeekBar; public class verticalSeekBar extends SeekBar { public verticalSeekBar(Context context) { super(context); } public verticalSeekBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } private OnSeekBarChangeListener onChangeListener; @Override public void setOnSeekBarChangeListener(OnSeekBarChangeListener onChangeListener){ this.onChangeListener = onChangeListener; super.setOnSeekBarChangeListener(onChangeListener); } public verticalSeekBar(Context context, AttributeSet attrs) { super(context, attrs); } protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(h, w, oldh, oldw); } @Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(heightMeasureSpec, widthMeasureSpec); setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth()); } protected void onDraw(Canvas c) { c.rotate(-90); c.translate(-getHeight(), 0); super.onDraw(c); } @Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) { return false; } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: onChangeListener.onStartTrackingTouch(this); break; case MotionEvent.ACTION_MOVE: setProgress(getMax() - (int) (getMax() * event.getY() / getHeight())); onSizeChanged(getWidth(), getHeight(), 0, 0); break; case MotionEvent.ACTION_UP: setProgress(getMax() - (int) (getMax() * event.getY() / getHeight())); onSizeChanged(getWidth(), getHeight(), 0, 0); onChangeListener.onStopTrackingTouch(this); break; case MotionEvent.ACTION_CANCEL: break; } return true; } }