Example #1
0
  @Override
  protected void onRestoreInstanceState(Parcelable state) {
    Bundle savedState = (Bundle) state;

    Parcelable superState = savedState.getParcelable(STATE_PARENT);
    super.onRestoreInstanceState(superState);

    setColor(Color.HSVToColor(savedState.getFloatArray(STATE_COLOR)));
    if (savedState.containsKey(STATE_SATURATION)) {
      setSaturation(savedState.getFloat(STATE_SATURATION));
    } else {
      setValue(savedState.getFloat(STATE_VALUE));
    }
    mOrientation = savedState.getBoolean(STATE_ORIENTATION, ORIENTATION_DEFAULT);
  }
Example #2
0
  /**
   * Set the color to be highlighted by the pointer. If the instances {@code SVBar} and the {@code
   * OpacityBar} aren't null the color will also be set to them
   *
   * @param color The RGB value of the color to highlight. If this is not a color displayed on the
   *     color wheel a very simple algorithm is used to map it to the color wheel. The resulting
   *     color often won't look close to the original color. This is especially true for shades of
   *     grey. You have been warned!
   */
  public void setColor(int color) {
    mAngle = colorToAngle(color);
    mPointerColor.setColor(calculateColor(mAngle));

    // check of the instance isn't null
    if (mOpacityBar != null) {
      // set the value of the opacity
      mOpacityBar.setColor(mColor);
      mOpacityBar.setOpacity(Color.alpha(color));
    }

    // check if the instance isn't null
    if (mSVbar != null) {
      // the array mHSV will be filled with the HSV values of the color.
      Color.colorToHSV(color, mHSV);
      mSVbar.setColor(mColor);

      // because of the design of the Saturation/Value bar,
      // we can only use Saturation or Value every time.
      // Here will be checked which we shall use.
      if (mHSV[1] < mHSV[2]) {
        mSVbar.setSaturation(mHSV[1]);
      } else if (mHSV[1] > mHSV[2]) {
        mSVbar.setValue(mHSV[2]);
      }
    }

    if (mSaturationBar != null) {
      Color.colorToHSV(color, mHSV);
      mSaturationBar.setColor(mColor);
      mSaturationBar.setSaturation(mHSV[1]);
    }

    if (mValueBar != null && mSaturationBar == null) {
      Color.colorToHSV(color, mHSV);
      mValueBar.setColor(mColor);
      mValueBar.setValue(mHSV[2]);
    } else if (mValueBar != null) {
      Color.colorToHSV(color, mHSV);
      mValueBar.setValue(mHSV[2]);
    }
    setNewCenterColor(color);
  }