示例#1
0
  public void refresh() {
    int alpha = Color.alpha(mButtonColor);
    float[] hsv = new float[3];
    Color.colorToHSV(mButtonColor, hsv);
    hsv[2] *= 0.8f; // value component
    // if shadow color was not defined, generate shadow color = 80% brightness
    if (!isShadowColorDefined) {
      mShadowColor = Color.HSVToColor(alpha, hsv);
    }
    // Create pressed background and unpressed background drawables

    if (this.isEnabled()) {
      if (isShadowEnabled) {
        pressedDrawable = createDrawable(mCornerRadius, Color.TRANSPARENT, mButtonColor);
        unpressedDrawable = createDrawable(mCornerRadius, mButtonColor, mShadowColor);
      } else {
        mShadowHeight = 0;
        pressedDrawable = createDrawable(mCornerRadius, mShadowColor, Color.TRANSPARENT);
        unpressedDrawable = createDrawable(mCornerRadius, mButtonColor, Color.TRANSPARENT);
      }
    } else {
      Color.colorToHSV(mButtonColor, hsv);
      hsv[1] *= 0.25f; // saturation component
      int disabledColor = mShadowColor = Color.HSVToColor(alpha, hsv);
      // Disabled button does not have shadow
      pressedDrawable = createDrawable(mCornerRadius, disabledColor, Color.TRANSPARENT);
      unpressedDrawable = createDrawable(mCornerRadius, disabledColor, Color.TRANSPARENT);
    }
    updateBackground(unpressedDrawable);
    // Set padding
    this.setPadding(
        mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom + mShadowHeight);
  }
 private int darkenColor(int color) {
   float[] hsv = new float[3];
   Color.colorToHSV(color, hsv);
   hsv[2] = hsv[2] * 0.75f;
   color = Color.HSVToColor(hsv);
   return color;
 }
  /** Given a particular color, adjusts its value by a multiplier */
  private static int getPressedColor(int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] = hsv[2] * PRESSED_STATE_MULTIPLIER;

    return Color.HSVToColor(hsv);
  }
    /**
     * Draw the old and new swatches.
     *
     * @param canvas
     */
    private void drawSwatches(Canvas canvas) {
      float[] hsv = new float[3];

      mText.setTextSize(16);

      // Draw the original swatch
      canvas.drawRect(mOldSwatchRect, mSwatchOld);
      Color.colorToHSV(mOriginalColor, hsv);
      // if (UberColorPickerDialog.isGray(mColor))	//Don't need this right here, but imp't to note
      //	hsv[1] = 0;
      if (hsv[2] > .5) mText.setColor(Color.BLACK);
      canvas.drawText(
          "Revert",
          mOldSwatchRect.left + SWATCH_WIDTH / 2 - mText.measureText("Revert") / 2,
          mOldSwatchRect.top + 16,
          mText);
      mText.setColor(Color.WHITE);

      // Draw the new swatch
      canvas.drawRect(mNewSwatchRect, mSwatchNew);
      if (mHSV[2] > .5) mText.setColor(Color.BLACK);
      canvas.drawText(
          "Accept",
          mNewSwatchRect.left + SWATCH_WIDTH / 2 - mText.measureText("Accept") / 2,
          mNewSwatchRect.top + 16,
          mText);
      mText.setColor(Color.WHITE);

      mText.setTextSize(TEXT_SIZE);
    }
示例#5
0
 public static int darker(int color) {
   float[] hsv = new float[3];
   Color.colorToHSV(color, hsv);
   hsv[2] = 1.0f - 0.8f * (1.0f - hsv[2]);
   color = Color.HSVToColor(hsv);
   return color;
 }
示例#6
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[] {Color.HSVToColor(0x00, mHSVColor), color},
            null,
            Shader.TileMode.CLAMP);
    mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
    mBarPointerPaint.setColor(mColor);
    if (mPicker != null) {
      mPicker.setNewCenterColor(mColor);
    }
    invalidate();
  }
示例#7
0
  public static Bitmap applySaturationFilter(Bitmap source, int level) {
    // get image size
    int width = source.getWidth();
    int height = source.getHeight();
    int[] pixels = new int[width * height];
    float[] HSV = new float[3];
    // get pixel array from source
    source.getPixels(pixels, 0, width, 0, 0, width, height);

    int index = 0;
    // iteration through pixels
    for (int y = 0; y < height; ++y) {
      for (int x = 0; x < width; ++x) {
        // get current index in 2D-matrix
        index = y * width + x;
        // convert to HSV
        Color.colorToHSV(pixels[index], HSV);
        // increase Saturation level
        HSV[1] *= level;
        HSV[1] = (float) Math.max(0.0, Math.min(HSV[1], 1.0));
        // take color back
        pixels[index] |= Color.HSVToColor(HSV);
      }
    }
    // output bitmap
    Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
    return bmOut;
  }
示例#8
0
  /**
   * Set the color to be highlighted by the pointer. </br> </br> 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]);
      }
    }

    invalidate();
  }
示例#9
0
 @ColorInt
 public static int shiftColor(@ColorInt int color, @FloatRange(from = 0.0f, to = 2.0f) float by) {
   if (by == 1f) return color;
   float[] hsv = new float[3];
   Color.colorToHSV(color, hsv);
   hsv[2] *= by; // value component
   return Color.HSVToColor(hsv);
 }
示例#10
0
  private int adjustColorBrightness(int argb, float factor) {
    float[] hsv = new float[3];
    Color.colorToHSV(argb, hsv);

    hsv[2] = Math.min(hsv[2] * factor, 1f);

    return Color.HSVToColor(Color.alpha(argb), hsv);
  }
示例#11
0
    public void setColor(final int color) {
      final float[] hsv = new float[3];
      Color.colorToHSV(color, hsv);

      this.hue = hsv[0];
      this.sat = hsv[1];
      this.val = hsv[2];
    }
示例#12
0
  @ColorInt
  private static int lightenColor(@ColorInt int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] /= 0.7f;
    color = Color.HSVToColor(hsv);

    return color;
  }
 public HSBColorPickerView(Context context, AttributeSet attrs, int defStyle, int startingColor) {
   super(context, attrs, defStyle);
   mPreviousColor = new float[3];
   mNewColor = new float[3];
   Color.colorToHSV(startingColor, mPreviousColor);
   System.arraycopy(mPreviousColor, 0, mNewColor, 0, mPreviousColor.length);
   mBackground =
       BitmapFactory.decodeResource(getResources(), R.drawable.color_picker_wheel_background);
   mWheel = BitmapFactory.decodeResource(getResources(), R.drawable.color_wheel);
 }
示例#14
0
 @SuppressLint("NewApi")
 private void changeStatusBarColor(int color) {
   float[] hsv = new float[3];
   //				int color =
   // Color.parseColor(mCursor.getString(mCursor.getColumnIndex(CategoriesTable.COL_CATEGORY_COLOR)));
   Color.colorToHSV(color, hsv);
   hsv[2] *= 0.8f; // value component
   color = Color.HSVToColor(hsv);
   Window mWindow = getWindow();
   if (Build.VERSION.SDK_INT >= 21) mWindow.setStatusBarColor(color);
 }
示例#15
0
 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();
 }
示例#16
0
 private int getNavbarTheme() {
   boolean isDarkBg = true;
   TypedArray attributes =
       getActivity()
           .obtainStyledAttributes(
               new int[] {R.attr.setup_wizard_navbar_theme, 16842800, 16842801});
   int theme = attributes.getResourceId(0, 0);
   if (theme == 0) {
     float[] foregroundHsv = new float[3];
     float[] backgroundHsv = new float[3];
     Color.colorToHSV(attributes.getColor(1, 0), foregroundHsv);
     Color.colorToHSV(attributes.getColor(2, 0), backgroundHsv);
     if (foregroundHsv[2] <= backgroundHsv[2]) {
       isDarkBg = false;
     }
     theme = isDarkBg ? R.style.SetupWizardNavbarThemeDark : R.style.SetupWizardNavbarThemeLight;
   }
   attributes.recycle();
   return theme;
 }
 public static MaterialColor getModifiedColor(int color, Shade shade) {
   int modified = color;
   if (shade != Shade.Shade500) {
     float[] hsv = new float[3];
     Color.colorToHSV(color, hsv);
     hsv[0] = getModifiedHue(hsv[0], shade);
     hsv[1] = getModifiedSaturation(hsv[1], shade);
     hsv[2] = getModifiedValue(hsv[2], shade);
     modified = Color.HSVToColor(Color.alpha(color), hsv);
   }
   return new SgnColor(modified);
 }
示例#18
0
  public void setInitialColor(int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);

    this.alpha = Utils.getAlphaPercent(color);
    this.lightness = hsv[2];
    this.initialColors[this.colorSelection] = color;
    this.initialColor = color;
    setColorPreviewColor(color);
    setColorToSliders(color);
    if (this.colorEdit != null) setColorText(color, true);
    if (renderer.getColorCircleList() != null) currentColorCircle = findNearestByColor(color);
  }
 private static int getNavbarTheme(Context context) {
   // Normally we can automatically guess the theme by comparing the foreground color against
   // the background color. But we also allow specifying explicitly using suwNavBarTheme.
   TypedArray attributes =
       context.obtainStyledAttributes(
           new int[] {
             R.attr.suwNavBarTheme, android.R.attr.colorForeground, android.R.attr.colorBackground
           });
   int theme = attributes.getResourceId(0, 0);
   if (theme == 0) {
     // Compare the value of the foreground against the background color to see if current
     // theme is light-on-dark or dark-on-light.
     float[] foregroundHsv = new float[3];
     float[] backgroundHsv = new float[3];
     Color.colorToHSV(attributes.getColor(1, 0), foregroundHsv);
     Color.colorToHSV(attributes.getColor(2, 0), backgroundHsv);
     boolean isDarkBg = foregroundHsv[2] > backgroundHsv[2];
     theme = isDarkBg ? R.style.SuwNavBarThemeDark : R.style.SuwNavBarThemeLight;
   }
   attributes.recycle();
   return theme;
 }
 private int getRandomColor() {
   float[] hsv = new float[3];
   int color =
       Color.argb(
           colorMaxValue,
           random.nextInt(colorMaxValue),
           random.nextInt(colorMaxValue),
           random.nextInt(colorMaxValue));
   Color.colorToHSV(color, hsv);
   hsv[2] *= colorAlpha;
   color = Color.HSVToColor(hsv);
   return color;
 }
示例#21
0
    ColorPickerView(Context c, OnColorChangedListener l, int color, int defaultColor) {
      super(c);
      mListener = l;
      mDefaultColor = defaultColor;

      // Get the current hue from the current color and update the main color field
      float[] hsv = new float[3];
      Color.colorToHSV(color, hsv);
      mCurrentHue = hsv[0];
      updateMainColors();

      mCurrentColor = color;

      // Initialize the colors of the hue slider bar
      int index = 0;
      for (float i = 0; i < 256; i += 256 / 42) // Red (#f00) to pink (#f0f)
      {
        mHueBarColors[index] = Color.rgb(255, 0, (int) i);
        index++;
      }
      for (float i = 0; i < 256; i += 256 / 42) // Pink (#f0f) to blue (#00f)
      {
        mHueBarColors[index] = Color.rgb(255 - (int) i, 0, 255);
        index++;
      }
      for (float i = 0; i < 256; i += 256 / 42) // Blue (#00f) to light blue (#0ff)
      {
        mHueBarColors[index] = Color.rgb(0, (int) i, 255);
        index++;
      }
      for (float i = 0; i < 256; i += 256 / 42) // Light blue (#0ff) to green (#0f0)
      {
        mHueBarColors[index] = Color.rgb(0, 255, 255 - (int) i);
        index++;
      }
      for (float i = 0; i < 256; i += 256 / 42) // Green (#0f0) to yellow (#ff0)
      {
        mHueBarColors[index] = Color.rgb((int) i, 255, 0);
        index++;
      }
      for (float i = 0; i < 256; i += 256 / 42) // Yellow (#ff0) to red (#f00)
      {
        mHueBarColors[index] = Color.rgb(255, 255 - (int) i, 0);
        index++;
      }

      // Initializes the Paint that will draw the View
      mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mPaint.setTextAlign(Paint.Align.CENTER);
      mPaint.setTextSize(12);
    }
示例#22
0
  // Thanks to GermainZ for the suggestion
  // http://forum.xda-developers.com/showpost.php?p=46102053&postcount=153
  public static int getIconColorForColor(
      int color, int defaultNormal, int defaultInverted, float hsvMaxValue) {
    /* Take away things people complain about :P */
    if (color == mPlayMusicOrangeColor) return defaultNormal;

    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    float value = hsv[2];
    if (value > hsvMaxValue) {
      return defaultInverted;
    } else {
      return defaultNormal;
    }
  }
示例#23
0
  @Override
  protected Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();

    Bundle state = new Bundle();
    state.putParcelable(STATE_PARENT, superState);
    state.putFloatArray(STATE_COLOR, mHSVColor);

    float[] hsvColor = new float[3];
    Color.colorToHSV(mColor, hsvColor);
    state.putFloat(STATE_SATURATION, hsvColor[1]);

    return state;
  }
示例#24
0
 @SuppressWarnings({"ConstantConditions", "deprecation"})
 public static void applyTheme(Dialog dialog, Context context, SharedPreferences prefs) {
   int colorPrimary =
       prefs.getInt("theme_colorPrimary", context.getResources().getColor(R.color.colorPrimary));
   float[] hsv = new float[3];
   Color.colorToHSV(colorPrimary, hsv);
   hsv[2] *= 0.8f;
   int colorPrimaryDark = Color.HSVToColor(hsv);
   dialog.getWindow().setStatusBarColor(colorPrimaryDark);
   try {
     dialog.getActionBar().setBackgroundDrawable(new ColorDrawable(colorPrimary));
   } catch (NullPointerException ignore) {
   }
 }
示例#25
0
 @Override
 public void colorSelected(int color) {
   ColorDrawable drawable = new ColorDrawable(color);
   colorView.setImageDrawable(drawable);
   float[] hsv = new float[3];
   Color.colorToHSV(color, hsv);
   StringBuffer buf = new StringBuffer();
   buf.append(hsv[0]);
   buf.append(',');
   buf.append(hsv[1] * 100);
   buf.append(',');
   buf.append(hsv[2] * 100);
   sendCommand(buf.toString());
 }
示例#26
0
 @SuppressWarnings({"ConstantConditions", "deprecation"})
 public static void applyTheme(Activity activity, SharedPreferences prefs) {
   if (prefs.getBoolean("app_dark_theme", false)) activity.setTheme(R.style.DarkTheme);
   int colorPrimary =
       prefs.getInt("theme_colorPrimary", activity.getResources().getColor(R.color.colorPrimary));
   float[] hsv = new float[3];
   Color.colorToHSV(colorPrimary, hsv);
   hsv[2] *= 0.8f;
   int colorPrimaryDark = Color.HSVToColor(hsv);
   activity.getWindow().setStatusBarColor(colorPrimaryDark);
   activity.getActionBar().setBackgroundDrawable(new ColorDrawable(colorPrimary));
   if (prefs.getBoolean("force_english", false)) {
     Configuration config = activity.getResources().getConfiguration();
     config.locale = Locale.ENGLISH;
     activity.getResources().updateConfiguration(config, null);
   }
 }
示例#27
0
  @Override
  protected Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();

    Bundle state = new Bundle();
    state.putParcelable(STATE_PARENT, superState);
    state.putFloatArray(STATE_COLOR, mHSVColor);
    float[] hsvColor = new float[3];
    Color.colorToHSV(mColor, hsvColor);
    if (hsvColor[1] < hsvColor[2]) {
      state.putFloat(STATE_SATURATION, hsvColor[1]);
    } else {
      state.putFloat(STATE_VALUE, hsvColor[2]);
    }
    state.putBoolean(STATE_ORIENTATION, ORIENTATION_HORIZONTAL);

    return state;
  }
示例#28
0
  @SuppressWarnings("deprecation")
  @SuppressLint("NewApi")
  public void refresh() {
    float[] hsv = new float[3];
    Color.colorToHSV(mButtonColor, hsv); // 将ARGB转化为HSV(H色调,S饱和度,V亮度)
    hsv[2] *= 0.8f; // Value component(亮度改为原来的80%)
    // if shadow color was not defined, generate shadow color = 80%
    // brightness
    if (!isShadowColorDefined) {
      mShadowColor = Color.HSVToColor(hsv); // 将HSV转化为ARGB值
    }

    StateListDrawable stateListDrawable = new StateListDrawable();
    if (isShadowEnabled) {
      // Shadow is enabled
      stateListDrawable.addState(
          new int[] {-android.R.attr.state_pressed},
          createDrawable(mCornerRadius, mButtonColor, mShadowColor));
      stateListDrawable.addState(
          new int[] {android.R.attr.state_pressed},
          createDrawable(mCornerRadius, Color.TRANSPARENT, mButtonColor));
    } else {
      // Shadow is disabled
      mShadowHeight = 0;
      stateListDrawable.addState(
          new int[] {-android.R.attr.state_pressed},
          createDrawable(mCornerRadius, mButtonColor, Color.TRANSPARENT));
      stateListDrawable.addState(
          new int[] {android.R.attr.state_pressed},
          createDrawable(mCornerRadius, mShadowColor, Color.TRANSPARENT));
    }

    // Set button background
    if (Build.VERSION.SDK_INT >= 16) {
      this.setBackground(stateListDrawable);
    } else {
      this.setBackgroundDrawable(stateListDrawable);
    }

    // Set padding
    this.setPadding(
        mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom + mShadowHeight);
  }
示例#29
0
  public void refresh() {
    float[] hsv = new float[3];
    Color.colorToHSV(mButtonColor, hsv);
    hsv[2] *= 0.8f; // value component
    // if shadow color was not defined, generate shadow color = 80% brightness
    if (!isShadowColorDefined) {
      mShadowColor = Color.HSVToColor(hsv);
    }

    StateListDrawable stateListDrawable = new StateListDrawable();
    if (isShadowEnabled) {
      // Shadow is enabled
      stateListDrawable.addState(
          new int[] {-android.R.attr.state_pressed},
          createDrawable(mCornerRadius, mButtonColor, mShadowColor));
      stateListDrawable.addState(
          new int[] {android.R.attr.state_pressed},
          createDrawable(mCornerRadius, Color.TRANSPARENT, mButtonColor));
    } else {
      // Shadow is disabled
      mShadowHeight = 0;
      stateListDrawable.addState(
          new int[] {-android.R.attr.state_pressed},
          createDrawable(mCornerRadius, mButtonColor, Color.TRANSPARENT));
      stateListDrawable.addState(
          new int[] {android.R.attr.state_pressed},
          createDrawable(mCornerRadius, mShadowColor, Color.TRANSPARENT));
    }

    // Set button background
    if (Build.VERSION.SDK_INT >= 16) {
      this.setBackground(stateListDrawable);
    } else {
      this.setBackgroundDrawable(stateListDrawable);
    }

    // Set padding
    this.setPadding(
        mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom + mShadowHeight);
  }
    /**
     * Effect a trackball change to a 2D palette.
     *
     * @param x -1: negative x change, 0: no x change, +1: positive x change.
     * @param y -1: negative y change, 0, no y change, +1: positive y change.
     * @param jump the amount by which to change.
     */
    private void changeHSPalette(float x, float y, int jump) {
      int x2 = 0, y2 = 0;
      if (x < 0) x2 = -jump;
      else if (x > 0) x2 = jump;
      if (y < 0) y2 = -jump;
      else if (y > 0) y2 = jump;

      mCoord[0] += x2;
      mCoord[1] += y2;

      if (mCoord[0] < -PALETTE_RADIUS) mCoord[0] = -PALETTE_RADIUS;
      else if (mCoord[0] > PALETTE_RADIUS) mCoord[0] = PALETTE_RADIUS;
      if (mCoord[1] < -PALETTE_RADIUS) mCoord[1] = -PALETTE_RADIUS;
      else if (mCoord[1] > PALETTE_RADIUS) mCoord[1] = PALETTE_RADIUS;

      float radius = (float) java.lang.Math.sqrt(mCoord[0] * mCoord[0] + mCoord[1] * mCoord[1]);
      if (radius > PALETTE_RADIUS) radius = PALETTE_RADIUS;

      float angle = (float) java.lang.Math.atan2(mCoord[1], mCoord[0]);
      // need to turn angle [-PI ... PI] into unit [0....1]
      float unit = angle / (2 * PI);
      if (unit < 0) {
        unit += 1;
      }

      mCoord[0] = round(Math.cos(angle) * radius);
      mCoord[1] = round(Math.sin(angle) * radius);

      int c = interpColor(mSpectrumColorsRev, unit);
      float[] hsv = new float[3];
      Color.colorToHSV(c, hsv);
      mHSV[0] = hsv[0];
      mHSV[1] = radius / PALETTE_RADIUS;
      updateAllFromHSV();
      mSwatchNew.setColor(Color.HSVToColor(mHSV));

      setVerValSlider();

      invalidate();
    }