Example #1
0
  /**
   * 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[] {0xffffffff, color, 0xff000000},
            null,
            Shader.TileMode.CLAMP);
    mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
    mBarPointerPaint.setColor(mColor);
    if (mPicker != null) {
      mPicker.setNewCenterColor(mColor);
      if (mPicker.hasOpacityBar()) mPicker.changeOpacityBarColor(mColor);
    }
    invalidate();
  }
Example #2
0
 /**
  * Set the pointer on the bar. With the saturation value.
  *
  * @param saturation float between 0 > 1
  */
 public void setSaturation(float saturation) {
   mBarPointerPosition = Math.round((mSVToPosFactor * saturation) + mBarPointerHaloRadius);
   calculateColor(mBarPointerPosition);
   mBarPointerPaint.setColor(mColor);
   // Check whether the Saturation/Value bar is added to the ColorPicker
   // wheel
   if (mPicker != null) {
     mPicker.setNewCenterColor(mColor);
     mPicker.changeOpacityBarColor(mColor);
   }
   invalidate();
 }
Example #3
0
  @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 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);
              mPicker.changeOpacityBarColor(mColor);
            }
            invalidate();
          } else if (dimen < mBarPointerHaloRadius) {
            mBarPointerPosition = mBarPointerHaloRadius;
            mColor = Color.WHITE;
            mBarPointerPaint.setColor(mColor);
            if (mPicker != null) {
              mPicker.setNewCenterColor(mColor);
              mPicker.changeOpacityBarColor(mColor);
            }
            invalidate();
          } else if (dimen > (mBarPointerHaloRadius + mBarLength)) {
            mBarPointerPosition = mBarPointerHaloRadius + mBarLength;
            mColor = Color.BLACK;
            mBarPointerPaint.setColor(mColor);
            if (mPicker != null) {
              mPicker.setNewCenterColor(mColor);
              mPicker.changeOpacityBarColor(mColor);
            }
            invalidate();
          }
        }
        break;
      case MotionEvent.ACTION_UP:
        mIsMovingPointer = false;
        break;
    }
    return true;
  }