/** * Set the bar color. <br> * <br> * Its discouraged to use this method. * * @param color */ public void setColor(int color) { int x1, y1; if (mOrientation == ORIENTATION_HORIZONTAL) { x1 = (mBarLength + mBarPointerHaloRadius); y1 = mBarThickness; } else { x1 = mBarThickness; y1 = (mBarLength + mBarPointerHaloRadius); } Color.colorToHSV(color, mHSVColor); shader = new LinearGradient( mBarPointerHaloRadius, 0, x1, y1, new int[] {Color.HSVToColor(0x00, mHSVColor), color}, null, Shader.TileMode.CLAMP); mBarPaint.setShader(shader); calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } invalidate(); }
/** * Set the pointer on the bar. With the opacity value. * * @param opacity float between 0 and 255 */ public void setOpacity(int opacity) { mBarPointerPosition = Math.round((mOpacToPosFactor * opacity)) + mBarPointerHaloRadius; calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } invalidate(); }
@Override public boolean onTouchEvent(MotionEvent event) { getParent().requestDisallowInterceptTouchEvent(true); // Convert coordinates to our internal coordinate system float dimen; if (mOrientation == ORIENTATION_HORIZONTAL) { dimen = event.getX(); } else { dimen = event.getY(); } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mIsMovingPointer = true; // Check whether the user pressed on (or near) the pointer if (dimen >= (mBarPointerHaloRadius) && dimen <= (mBarPointerHaloRadius + mBarLength)) { mBarPointerPosition = Math.round(dimen); calculateColor(Math.round(dimen)); mBarPointerPaint.setColor(mColor); invalidate(); } break; case MotionEvent.ACTION_MOVE: if (mIsMovingPointer) { // Move the the pointer on the bar. if (dimen >= mBarPointerHaloRadius && dimen <= (mBarPointerHaloRadius + mBarLength)) { mBarPointerPosition = Math.round(dimen); calculateColor(Math.round(dimen)); mBarPointerPaint.setColor(mColor); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } invalidate(); } else if (dimen < mBarPointerHaloRadius) { mBarPointerPosition = mBarPointerHaloRadius; mColor = Color.TRANSPARENT; mBarPointerPaint.setColor(mColor); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } invalidate(); } else if (dimen > (mBarPointerHaloRadius + mBarLength)) { mBarPointerPosition = mBarPointerHaloRadius + mBarLength; mColor = Color.HSVToColor(mHSVColor); mBarPointerPaint.setColor(mColor); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } invalidate(); } } if (onOpacityChangedListener != null && oldChangedListenerOpacity != getOpacity()) { onOpacityChangedListener.onOpacityChanged(getOpacity()); oldChangedListenerOpacity = getOpacity(); } break; case MotionEvent.ACTION_UP: mIsMovingPointer = false; break; } return true; }