示例#1
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
     case MotionEvent.ACTION_MOVE:
       {
         currentColorCircle = findNearestByPosition(event.getX(), event.getY());
         int selectedColor = getSelectedColor();
         initialColor = selectedColor;
         setColorToSliders(selectedColor);
         invalidate();
         break;
       }
     case MotionEvent.ACTION_UP:
       {
         int selectedColor = getSelectedColor();
         if (listeners != null) {
           for (OnColorSelectedListener listener : listeners) {
             try {
               listener.onColorSelected(selectedColor);
             } catch (Exception e) {
               // Squash individual listener exceptions
             }
           }
         }
         setColorToSliders(selectedColor);
         setColorText(selectedColor, true);
         setColorPreviewColor(selectedColor);
         invalidate();
         break;
       }
   }
   return true;
 }
 public void onClick(DialogInterface dialog, int which) {
   switch (which) {
     case BUTTON_NEGATIVE:
       dialog.dismiss();
       break;
     case BUTTON_NEUTRAL:
       dialog.dismiss();
       listener.colorSelected(-1);
       break;
     case BUTTON_POSITIVE:
       listener.colorSelected(selectedColor);
       break;
   }
 }
 public void setColor(int color, boolean keepValue) {
   float oldValue = colorHsv[2];
   Color.colorToHSV(color, colorHsv);
   if (keepValue) {
     colorHsv[2] = oldValue;
   }
   if (listener != null) {
     listener.colorSelected(Color.HSVToColor(colorHsv));
   }
   createBitmap();
 }
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   int action = event.getActionMasked();
   switch (action) {
     case MotionEvent.ACTION_DOWN:
     case MotionEvent.ACTION_MOVE:
       if (listener != null) {
         int color = getColorForPoint((int) event.getX(), (int) event.getY(), colorHsv);
         listener.colorSelected(color);
       }
       invalidate();
       return true;
   }
   return super.onTouchEvent(event);
 }
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   int action = event.getActionMasked();
   switch (action) {
     case MotionEvent.ACTION_DOWN:
     case MotionEvent.ACTION_MOVE:
       int EventX = (int) event.getX();
       int x = Math.max(0, Math.min(bitmap.getWidth(), EventX));
       float value = x / (float) bitmap.getWidth();
       if (colorHsv[2] != value) {
         colorHsv[2] = value;
         if (listener != null) {
           listener.colorSelected(Color.HSVToColor(colorHsv));
         }
         createBitmap();
         invalidate();
       }
       return true;
   }
   return super.onTouchEvent(event);
 }
示例#6
0
  @SuppressLint("ClickableViewAccessibility")
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    getParent().requestDisallowInterceptTouchEvent(true);

    // Convert coordinates to our internal coordinate system
    float x = event.getX() - mTranslationOffset;
    float y = event.getY() - mTranslationOffset;

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        // Check whether the user pressed on the pointer.
        float[] pointerPosition = calculatePointerPosition(mAngle);
        if (x >= (pointerPosition[0] - mColorPointerHaloRadius)
            && x <= (pointerPosition[0] + mColorPointerHaloRadius)
            && y >= (pointerPosition[1] - mColorPointerHaloRadius)
            && y <= (pointerPosition[1] + mColorPointerHaloRadius)) {
          mSlopX = x - pointerPosition[0];
          mSlopY = y - pointerPosition[1];
          mUserIsMovingPointer = true;
          invalidate();
        }
        // Check whether the user pressed on the center.
        else if (x >= -mColorCenterRadius
            && x <= mColorCenterRadius
            && y >= -mColorCenterRadius
            && y <= mColorCenterRadius
            && mShowCenterOldColor) {
          mCenterHaloPaint.setAlpha(0x50);
          setColor(getOldCenterColor());
          invalidate();
        }
        // Check whether the user pressed anywhere on the wheel.
        else if (Math.sqrt(x * x + y * y) <= mColorWheelRadius + mColorPointerHaloRadius
            && Math.sqrt(x * x + y * y) >= mColorWheelRadius - mColorPointerHaloRadius
            && mTouchAnywhereOnColorWheelEnabled) {
          mUserIsMovingPointer = true;
          invalidate();
        }
        // If user did not press pointer or center, report event not handled
        else {
          getParent().requestDisallowInterceptTouchEvent(false);
          return false;
        }
        break;
      case MotionEvent.ACTION_MOVE:
        if (mUserIsMovingPointer) {
          mAngle = (float) Math.atan2(y - mSlopY, x - mSlopX);
          mPointerColor.setColor(calculateColor(mAngle));

          setNewCenterColor(mCenterNewColor = calculateColor(mAngle));

          if (mSVbar != null) {
            mSVbar.setColor(mColor);
          }

          invalidate();
        }
        // If user did not press pointer or center, report event not handled
        else {
          getParent().requestDisallowInterceptTouchEvent(false);
          return false;
        }
        break;
      case MotionEvent.ACTION_UP:
        mUserIsMovingPointer = false;
        mCenterHaloPaint.setAlpha(0x00);

        if (onColorSelectedListener != null && mCenterNewColor != oldSelectedListenerColor) {
          onColorSelectedListener.onColorSelected(mCenterNewColor);
          oldSelectedListenerColor = mCenterNewColor;
        }

        invalidate();
        break;
      case MotionEvent.ACTION_CANCEL:
        if (onColorSelectedListener != null && mCenterNewColor != oldSelectedListenerColor) {
          onColorSelectedListener.onColorSelected(mCenterNewColor);
          oldSelectedListenerColor = mCenterNewColor;
        }
        break;
    }
    return true;
  }
 @Override
 public void onClick(View v) {
   if (mOnColorSelectedListener != null) {
     mOnColorSelectedListener.onColorSelected(mColor);
   }
 }