List of usage examples for android.graphics Color HSVToColor
@ColorInt public static int HSVToColor(@Size(3) float hsv[])
From source file:com.danimahardhika.android.helpers.core.ColorHelper.java
@ColorInt public static int getDarkerColor(@ColorInt int color, @FloatRange(from = 0.0f, to = 1.0f) float transparency) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] *= transparency;/*from ww w. ja va 2 s . c o m*/ return Color.HSVToColor(hsv); }
From source file:Main.java
/** * Converts a hue number to a standard ARGB {@code int}, using {@link #DEFAULT_BLOCK_SATURATION} * and {@link #DEFAULT_BLOCK_VALUE}. The resulting color will always be opaque. * * @param hue The hue to convert.//from ww w.j av a 2 s.com * @param tempHsvArray An optional previously allocated array for HSV calculations. * @return The color as an ARGB {@code int}. */ public static int getBlockColorForHue(int hue, @Nullable float[] tempHsvArray) { hue = ((hue % 360) + 360) % 360; // Clamp to 0-359 if (tempHsvArray == null) { tempHsvArray = new float[3]; } tempHsvArray[0] = hue; tempHsvArray[1] = DEFAULT_BLOCK_SATURATION; tempHsvArray[2] = DEFAULT_BLOCK_VALUE; return Color.HSVToColor(tempHsvArray); }
From source file:com.dirkgassen.wator.ui.fragment.WatorDisplay.java
/** * Calculates a color ramp from {@code youngColor} to {@code oldColor} and returns that array. * * @param max maximum age; defines the number of individual colors calculated * @param youngColor young (starting) color * @param oldColor old (ending) color/*from w w w . java 2s . com*/ * @return array with the color ramp */ private int[] calculateIndividualAgeColors(int max, int youngColor, int oldColor) { final int[] colors = new int[max]; final float[] youngColorHsv = new float[3]; final float[] oldColorHsv = new float[3]; final float[] targetColor = new float[3]; Color.colorToHSV(youngColor, youngColorHsv); Color.colorToHSV(oldColor, oldColorHsv); for (int age = 0; age < max; age++) { for (int no = 0; no < 3; no++) { float proportion = (float) age / (float) max; targetColor[no] = (youngColorHsv[no] + ((oldColorHsv[no] - youngColorHsv[no]) * proportion)); colors[age] = Color.HSVToColor(targetColor); } } return colors; }
From source file:com.caseybrooks.scripturememory.activities.DetailActivity.java
@Override public void setToolBar(String name, int color) { ActionBar ab = getSupportActionBar(); ColorDrawable colorDrawable = new ColorDrawable(color); ab.setBackgroundDrawable(colorDrawable); ab.setTitle(name);//from w w w . j a v a2 s .com ab.setDisplayHomeAsUpEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] *= 0.8f; // value component getWindow().setStatusBarColor(Color.HSVToColor(hsv)); } }
From source file:org.dmfs.tasks.ViewTaskActivity.java
private int darkenColor(int color) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] = hsv[2] * 0.75f;//from w w w. j a va2 s .c om color = Color.HSVToColor(hsv); return color; }
From source file:eltos.simpledialogfragments.FlatFragmentActivity.java
/** * Let the hosting fragment or activity implement this interface * to receive results from the dialog/*from ww w . j ava 2 s. c o m*/ * * @param dialogTag the tag passed to {@link SimpleDialog#show} * @param which result type, one of {@link #BUTTON_POSITIVE}, {@link #BUTTON_NEGATIVE}, * {@link #BUTTON_NEUTRAL} or {@link #CANCELED} * @param extras the extras passed to {@link SimpleDialog#extra(Bundle)} * @return true if the result was handled, false otherwise */ @Override public boolean onResult(@NonNull String dialogTag, int which, @NonNull Bundle extras) { // handle results as usual if (COLOR_FRAGMENT.equals(dialogTag) && which == BUTTON_POSITIVE) { @ColorInt int color = extras.getInt(SimpleColorDialog.COLOR); // Sets action bar colors if (getSupportActionBar() != null) { getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xFF000000 | color)); boolean dark = Color.red(color) * 0.299 + Color.green(color) * 0.587 + Color.blue(color) * 0.114 < 180; SpannableString s = new SpannableString(getSupportActionBar().getTitle()); s.setSpan(new ForegroundColorSpan(dark ? Color.WHITE : Color.BLACK), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); getSupportActionBar().setTitle(s); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] *= 0.75; getWindow().setStatusBarColor(Color.HSVToColor(hsv)); } return true; } return false; }
From source file:de.WyLight.WyLight.WiflyControlActivity.java
private void onColorChanged() { for (OnColorChangeListener listener : mColorChangedListenerList) { listener.onColorChanged(mHSV, mARGB); }/*w ww. j a v a2s . com*/ try { mCtrl.fwSetColor(Color.HSVToColor(mHSV), WiflyControl.ALL_LEDS); } catch (ConnectionTimeout e) { onConnectionLost(); } catch (ScriptBufferFull e) { onScriptBufferFull(); } catch (FatalError e) { onFatalError(e); } }
From source file:me.willowcheng.makerthings.model.OpenHABItem.java
public int getStateAsColor() { return Color.HSVToColor(getStateAsHSV()); }
From source file:com.glabs.homegenie.widgets.ColorLightDialogFragment.java
@Override public void refreshView() { super.refreshView(); ////from ww w .j a va2s .c o m _view.post(new Runnable() { @Override public void run() { _groupText.setText(_module.getDisplayAddress()); ModuleParameter levelParam = _module.getParameter("Status.Level"); if (levelParam != null) _levelText.setText(_module.getDisplayLevel(levelParam.Value)); else _levelText.setText(""); ModuleParameter colorParam = _module.getParameter("Status.ColorHsb"); if (colorParam != null && colorParam.Value != null) { try { String[] sHsb = colorParam.Value.split(","); float[] hsb = new float[3]; hsb[0] = Float.parseFloat(sHsb[0]) * 360f; hsb[1] = Float.parseFloat(sHsb[1]); hsb[2] = Float.parseFloat(sHsb[2]); int color = Color.HSVToColor(hsb); _colorPicker.setColor(color); _colorPreview.setBackgroundColor(color); } catch (Exception e) { // TODO parsing errors } } // _levelBar.setProgress((int)Math.round(_module.getDoubleValue(levelParam.Value) * 100)); } }); }
From source file:com.abhinavjhanwar.android.egg.neko.Cat.java
public Cat(Context context, long seed, List<Cat> mCats) { D = new CatParts(context); mSeed = seed;//from w w w. java 2 s. com long check = seed; for (int i = 0; i < mCats.size(); i++) { while (context.getString(R.string.default_cat_name, String.valueOf(check).substring(0, 3)) .equals(mCats.get(i).getName())) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { check = Math.abs(ThreadLocalRandom.current().nextInt()); } else { check = Math.abs(new Random().nextInt()); } } } setName(context.getString(R.string.default_cat_name, String.valueOf(check).substring(0, 3))); final Random nsr = notSoRandom(seed); // body color mBodyColor = chooseP(nsr, P_BODY_COLORS); if (mBodyColor == 0) mBodyColor = Color.HSVToColor(new float[] { nsr.nextFloat() * 360f, frandrange(nsr), frandrange(nsr) }); tint(mBodyColor, D.body, D.head, D.leg1, D.leg2, D.leg3, D.leg4, D.tail, D.leftEar, D.rightEar, D.foot1, D.foot2, D.foot3, D.foot4, D.tailCap); tint(0x20000000, D.leg2Shadow, D.tailShadow); if (isDark(mBodyColor)) { tint(0xFFFFFFFF, D.leftEye, D.rightEye, D.mouth, D.nose); } tint(isDark(mBodyColor) ? 0xFFEF9A9A : 0x20D50000, D.leftEarInside, D.rightEarInside); tint(chooseP(nsr, P_BELLY_COLORS), D.belly); tint(chooseP(nsr, P_BELLY_COLORS), D.back); final int faceColor = chooseP(nsr, P_BELLY_COLORS); tint(faceColor, D.faceSpot); if (!isDark(faceColor)) { tint(0xFF000000, D.mouth, D.nose); } if (nsr.nextFloat() < 0.25f) { tint(0xFFFFFFFF, D.foot1, D.foot2, D.foot3, D.foot4); } else { if (nsr.nextFloat() < 0.25f) { tint(0xFFFFFFFF, D.foot1, D.foot2); } else if (nsr.nextFloat() < 0.25f) { tint(0xFFFFFFFF, D.foot3, D.foot4); } else if (nsr.nextFloat() < 0.1f) { tint(0xFFFFFFFF, (Drawable) choose(nsr, D.foot1, D.foot2, D.foot3, D.foot4)); } } tint(nsr.nextFloat() < 0.333f ? 0xFFFFFFFF : mBodyColor, D.tailCap); final int capColor = chooseP(nsr, isDark(mBodyColor) ? P_LIGHT_SPOT_COLORS : P_DARK_SPOT_COLORS); tint(capColor, D.cap); //tint(chooseP(nsr, isDark(bodyColor) ? P_LIGHT_SPOT_COLORS : P_DARK_SPOT_COLORS), D.nose); final int collarColor = chooseP(nsr, P_COLLAR_COLORS); tint(collarColor, D.collar); tint((nsr.nextFloat() < 0.1f) ? collarColor : 0, D.bowtie); }