List of usage examples for android.graphics Color colorToHSV
public static void colorToHSV(@ColorInt int color, @Size(3) float hsv[])
From source file:com.granita.tasks.EditTaskFragment.java
private static int darkenColor(int color) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] = hsv[2] * 0.75f;// w ww . ja v a2 s . com color = Color.HSVToColor(hsv); return color; }
From source file:tv.piratemedia.lightcontroler.controller.java
private void setActionbarColor(int c) { mActionBarToolbar.setBackgroundColor(c); try {/* w ww.ja v a 2s . c om*/ tabs.setBackgroundColor(c); } catch (Exception e) { //do nothing } float[] hsv = new float[3]; Color.colorToHSV(c, hsv); hsv[2] *= 0.8f; // value component c = Color.HSVToColor(hsv); drawer.setStatusBarBackgroundColor(c); //little hack to make the statusbar background redraw when called from another thread drawer.openDrawer(); drawer.closeDrawer(); }
From source file:io.jawg.osmcontributor.ui.utils.BitmapHandler.java
public static Bitmap hue(Bitmap bitmap, float hue) { Bitmap newBitmap = bitmap.copy(bitmap.getConfig(), true); final int width = newBitmap.getWidth(); final int height = newBitmap.getHeight(); float[] hsv = new float[3]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int pixel = newBitmap.getPixel(x, y); Color.colorToHSV(pixel, hsv); hsv[0] = hue;/* ww w.j av a 2 s.c om*/ newBitmap.setPixel(x, y, Color.HSVToColor(Color.alpha(pixel), hsv)); } } return newBitmap; }
From source file:info.tellmetime.TellmetimeActivity.java
/** * Handles changing highlight color via #mSeekBarHighlight. * * @param value indicates exact offset in gradient (SeekBar's max value is equal to #mRainbow width). *//*from w w w. ja v a 2 s . c o m*/ @Override public void onProgressChanged(SeekBar seekBar, int value, boolean fromUser) { switch (seekBar.getId()) { case R.id.highlightValue: mHighlightColor = mRainbow.getPixel(value, 0); if (((RadioButton) findViewById(R.id.radio_backlight_highlight)).isChecked()) { float[] highlightHSV = new float[3]; Color.colorToHSV(mHighlightColor, highlightHSV); mBacklightColor = Color.HSVToColor(33, highlightHSV); } if (fromUser) mHighlightPosition = (float) value / seekBar.getMax(); mClockAlgorithm.tickTock(); break; case R.id.minutesSize: mMinutesSize = value; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { FrameLayout minutesIndicators = (FrameLayout) findViewById(R.id.minutes_indicators); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) minutesIndicators .getLayoutParams(); params.topMargin = (int) -TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize / 3, getResources().getDisplayMetrics()); minutesIndicators.setLayoutParams(params); } ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots); for (int i = 0; i < minutesDots.getChildCount(); i++) { TextView m = (TextView) minutesDots.getChildAt(i); m.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize); } break; } mHider.delayedHide(4000); }
From source file:com.mikhaellopez.saveinsta.activity.MainActivity.java
private int darkerColor(int color) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] *= 0.8f; // value component return Color.HSVToColor(hsv); }
From source file:com.ruesga.rview.widget.TagEditTextView.java
public static int newRandomColor() { int random = (int) (Math.floor(Math.random() * 0xff0f0f0f) + 0xff000000); int color = Color.argb(0xff, Color.red(random), Color.green(random), Color.blue(random)); float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] *= 0.8f; // value component color = Color.HSVToColor(hsv); return color; }
From source file:com.google.appinventor.components.runtime.GoogleMap.java
@SimpleFunction(description = "Set the property of an existing circle. Properties include: " + "\"alpha\"(number, value ranging from 0~255), \"color\" (nimber, hue value ranging 0~360), " + "\"radius\"(number in meters)") public void UpdateCircle(int circleId, String propertyName, Object value) { Log.i(TAG, "inputs: " + circleId + "," + propertyName + ", " + value); float[] hsv = new float[3]; Object circle = getCircleIfExisted(circleId); // if it's null, getCircleIfExisted will show error msg Circle updateCircle = null; // the real circle content that gets updated if (circle != null) { if (circle instanceof DraggableCircle) { updateCircle = ((DraggableCircle) circle).getCircle(); }/* www .j a v a 2s . co m*/ if (circle instanceof Circle) { updateCircle = (Circle) circle; } try { Float val = Float.parseFloat(value.toString()); if (propertyName.equals("alpha")) { int color = updateCircle.getFillColor(); Color.colorToHSV(color, hsv); Integer alphaVal = val.intValue(); //Color.HSVToColor(mAlpha, new float[] {mColorHue, 1, 1});//default to red, medium level hue color int newColor = Color.HSVToColor(alphaVal, hsv); updateCircle.setFillColor(newColor); } if (propertyName.equals("color")) { int alpha = Color.alpha(updateCircle.getFillColor()); int newColor = Color.HSVToColor(alpha, new float[] { val, 1, 1 }); updateCircle.setFillColor(newColor); } if (propertyName.equals("radius")) { // need to cast value to float Float radius = val; updateCircle.setRadius(radius); // if it's a draggableCircle, then we need to remove the previous marker and get new radius marker if (circle instanceof DraggableCircle) { // remove previous radius marker Marker centerMarker = ((DraggableCircle) circle).getCenterMarker(); Marker oldMarker = ((DraggableCircle) circle).getRadiusMarker(); oldMarker.remove(); Marker newMarker = mMap.addMarker(new MarkerOptions() .position(toRadiusLatLng(centerMarker.getPosition(), radius)).draggable(true) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))); ((DraggableCircle) circle).setRadiusMarker(newMarker); // create a new draggabble circle } } } catch (NumberFormatException e) { //can't parse the string form.dispatchErrorOccurredEvent(this, "UpdateCircle", ErrorMessages.ERROR_GOOGLE_MAP_INVALID_INPUT, value.toString()); } } else { // the circle doesn't exist form.dispatchErrorOccurredEvent(this, "UpdateCircle", ErrorMessages.ERROR_GOOGLE_MAP_CIRCLE_NOT_EXIST, circleId); } }
From source file:info.tellmetime.TellmetimeActivity.java
public void onBacklightRadioClick(View view) { boolean isChecked = ((RadioButton) view).isChecked(); switch (view.getId()) { case R.id.radio_backlight_light: if (isChecked) mBacklightColor = mBacklightLight; break;//from ww w . j a v a 2 s . c o m case R.id.radio_backlight_dark: if (isChecked) mBacklightColor = mBacklightDark; break; case R.id.radio_backlight_highlight: if (isChecked) { float[] highlightHSV = new float[3]; Color.colorToHSV(mHighlightColor, highlightHSV); mBacklightColor = Color.HSVToColor(33, highlightHSV); } break; } mClockAlgorithm.tickTock(); mHider.delayedHide(4000); }
From source file:com.heinrichreimersoftware.materialintro.app.IntroActivity.java
private void updateBackground() { @ColorInt// w ww . j av a 2 s . c om int background; @ColorInt int backgroundNext; @ColorInt int backgroundDark; @ColorInt int backgroundDarkNext; if (position == getCount()) { background = Color.TRANSPARENT; backgroundNext = Color.TRANSPARENT; backgroundDark = Color.TRANSPARENT; backgroundDarkNext = Color.TRANSPARENT; } else { background = ContextCompat.getColor(IntroActivity.this, getBackground(position)); backgroundNext = ContextCompat.getColor(IntroActivity.this, getBackground(Math.min(position + 1, getCount() - 1))); background = ColorUtils.setAlphaComponent(background, 0xFF); backgroundNext = ColorUtils.setAlphaComponent(backgroundNext, 0xFF); try { backgroundDark = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(position)); } catch (Resources.NotFoundException e) { backgroundDark = ContextCompat.getColor(IntroActivity.this, R.color.mi_status_bar_background); } try { backgroundDarkNext = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(Math.min(position + 1, getCount() - 1))); } catch (Resources.NotFoundException e) { backgroundDarkNext = ContextCompat.getColor(IntroActivity.this, R.color.mi_status_bar_background); } } if (position + positionOffset >= adapter.getCount() - 1) { backgroundNext = ColorUtils.setAlphaComponent(background, 0x00); backgroundDarkNext = ColorUtils.setAlphaComponent(backgroundDark, 0x00); } background = (Integer) evaluator.evaluate(positionOffset, background, backgroundNext); backgroundDark = (Integer) evaluator.evaluate(positionOffset, backgroundDark, backgroundDarkNext); miFrame.setBackgroundColor(background); float[] backgroundDarkHsv = new float[3]; Color.colorToHSV(backgroundDark, backgroundDarkHsv); //Slightly darken the background color a bit for more contrast backgroundDarkHsv[2] *= 0.95; int backgroundDarker = Color.HSVToColor(backgroundDarkHsv); miPagerIndicator.setPageIndicatorColor(backgroundDarker); ViewCompat.setBackgroundTintList(miButtonNext, ColorStateList.valueOf(backgroundDarker)); ViewCompat.setBackgroundTintList(miButtonBack, ColorStateList.valueOf(backgroundDarker)); @ColorInt int backgroundButtonCta = buttonCtaTintMode == BUTTON_CTA_TINT_MODE_TEXT ? ContextCompat.getColor(this, android.R.color.white) : backgroundDarker; ViewCompat.setBackgroundTintList(miButtonCta.getChildAt(0), ColorStateList.valueOf(backgroundButtonCta)); ViewCompat.setBackgroundTintList(miButtonCta.getChildAt(1), ColorStateList.valueOf(backgroundButtonCta)); int iconColor; if (ColorUtils.calculateLuminance(backgroundDark) > 0.4) { //Light background iconColor = ContextCompat.getColor(this, R.color.mi_icon_color_light); } else { //Dark background iconColor = ContextCompat.getColor(this, R.color.mi_icon_color_dark); } miPagerIndicator.setCurrentPageIndicatorColor(iconColor); DrawableCompat.setTint(miButtonNext.getDrawable(), iconColor); DrawableCompat.setTint(miButtonBack.getDrawable(), iconColor); @ColorInt int textColorButtonCta = buttonCtaTintMode == BUTTON_CTA_TINT_MODE_TEXT ? backgroundDarker : iconColor; ((Button) miButtonCta.getChildAt(0)).setTextColor(textColorButtonCta); ((Button) miButtonCta.getChildAt(1)).setTextColor(textColorButtonCta); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().setStatusBarColor(backgroundDark); if (position == adapter.getCount()) { getWindow().setNavigationBarColor(Color.TRANSPARENT); } else if (position + positionOffset >= adapter.getCount() - 1) { TypedValue typedValue = new TypedValue(); TypedArray a = obtainStyledAttributes(typedValue.data, new int[] { android.R.attr.navigationBarColor }); int defaultNavigationBarColor = a.getColor(0, Color.BLACK); a.recycle(); int navigationBarColor = (Integer) evaluator.evaluate(positionOffset, defaultNavigationBarColor, Color.TRANSPARENT); getWindow().setNavigationBarColor(navigationBarColor); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int systemUiVisibility = getWindow().getDecorView().getSystemUiVisibility(); int flagLightStatusBar = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; if (ColorUtils.calculateLuminance(backgroundDark) > 0.4) { //Light background systemUiVisibility |= flagLightStatusBar; } else { //Dark background systemUiVisibility &= ~flagLightStatusBar; } getWindow().getDecorView().setSystemUiVisibility(systemUiVisibility); } } }
From source file:com.serenegiant.autoparrot.BaseAutoPilotFragment.java
@Override public void onColorChanged(final ColorPickerDialog dialog, final int color) { final float[] hsv = new float[3]; Color.colorToHSV(color, hsv); synchronized (mParamSync) { // ImageProcessor?? applyExtract(hsv[0] / 360.0f, hsv[1], hsv[2]); }/*from w ww . j av a2 s . c o m*/ }