List of usage examples for android.graphics Color colorToHSV
public static void colorToHSV(@ColorInt int color, @Size(3) float hsv[])
From source file:com.serenegiant.autoparrot.BaseAutoPilotFragment.java
@Override public void onDismiss(final ColorPickerDialog dialog, final int color) { final float[] hsv = new float[3]; Color.colorToHSV(color, hsv); synchronized (mParamSync) { mExtractH = hsv[0] / 360.0f;//from w w w. j a va2s . com mExtractS = hsv[1]; mExtractV = hsv[2]; // ImageProcessor?? applyExtract(mExtractH, mExtractS, mExtractV); } // ??? mPref.edit().putFloat(KEY_EXTRACT_H, mExtractH).putFloat(KEY_EXTRACT_S, mExtractS) .putFloat(KEY_EXTRACT_V, mExtractV).apply(); }
From source file:de.vanita5.twittnuker.util.ThemeUtils.java
public static int getUserLinkTextColor(final Context context) { if (context == null) return new TextPaint().linkColor; final int themeColor = getUserAccentColor(context); final float[] hsv = new float[3]; Color.colorToHSV(themeColor, hsv); if (isDarkTheme(context)) { hsv[2] = MathUtils.clamp(hsv[2], 1, 0.5f); } else {//from www. j a v a 2 s.c o m hsv[2] = MathUtils.clamp(hsv[2], 0.1f, 0.75f); } return Color.HSVToColor(hsv); }
From source file:com.github.colorchief.colorchief.MainActivity.java
public void hsvButtonClick(View view) { ImageView colourBlock22 = (ImageView) findViewById(R.id.colour22); ColorDrawable colourDrawable = (ColorDrawable) colourBlock22.getBackground(); int setColour = colourDrawable.getColor(); int newColour = 0; float hsvColour[] = new float[3]; Color.colorToHSV(setColour, hsvColour); if (view.getId() == R.id.hueDownButton) { //Log.d(TAG, "Hue Down Button Clicked"); hsvColour[0] = hsvColour[0] - H_ADJUST; if (hsvColour[0] < 0f) hsvColour[0] = 360f + hsvColour[0]; }/* w w w . j av a2s . c o m*/ if (view.getId() == R.id.hueUpButton) { //Log.d(TAG, "Hue Up Button Clicked"); hsvColour[0] = hsvColour[0] + H_ADJUST; if (hsvColour[0] > 360f) hsvColour[0] = hsvColour[0] - 360f; } if (view.getId() == R.id.saturationDownButton) { //Log.d(TAG, "Saturation Down Button Clicked"); hsvColour[1] = hsvColour[1] - S_ADJUST; //if (hsvColour[1] < 0f ) hsvColour[1] = 1f + hsvColour[1]; if (hsvColour[1] < 0f) hsvColour[1] = 0f; } if (view.getId() == R.id.saturationUpButton) { //Log.d(TAG, "Saturation Up Button Clicked"); hsvColour[1] = hsvColour[1] + S_ADJUST; //if (hsvColour[1] > 1f ) hsvColour[1] = hsvColour[1] - 1f; if (hsvColour[1] > 1f) hsvColour[1] = 1f; } if (view.getId() == R.id.lightnessDownButton) { //Log.d(TAG, "Lightness Down Button Clicked"); hsvColour[2] = hsvColour[2] - V_ADJUST; //if (hsvColour[2] < 0f ) hsvColour[2] = 1f + hsvColour[2]; if (hsvColour[2] < 0f) hsvColour[2] = 0f; } if (view.getId() == R.id.lightnessUpButton) { //Log.d(TAG, "Lightness Up Button Clicked"); hsvColour[2] = hsvColour[2] + V_ADJUST; //if (hsvColour[2] > 1f ) hsvColour[2] = hsvColour[2] - 1f; if (hsvColour[2] > 1f) hsvColour[2] = 1f; } newColour = Color.HSVToColor(hsvColour); colourBlock22.setBackgroundColor(newColour); }
From source file:com.brejza.matt.habmodem.Dsp_service.java
private int newColour() { if (last_colour == 0) { last_colour = 0xFFFF0000;/*from ww w.j a v a 2s . c o m*/ return last_colour; } else { float lasthsv[] = new float[3]; Color.colorToHSV(last_colour, lasthsv); lasthsv[0] = (lasthsv[0] + (180 + 33)) % 360; last_colour = Color.HSVToColor(lasthsv); return last_colour; } }
From source file:com.skytree.epubtest.BookViewActivity.java
public int getBrighterColor(int color) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] *= 1.2f; // value component int darker = Color.HSVToColor(hsv); return darker; }
From source file:com.google.appinventor.components.runtime.GoogleMap.java
/** * * @param markers/*from w w w. j a v a 2 s .c o m*/ * @return * TODO: Adding customized icons, also too many error msgs (disable for now) */ @SimpleFunction(description = "Adding a list of YailLists for markers. The representation of a maker in the " + "inner YailList is composed of: " + "lat(double) [required], long(double) [required], Color, " + "title(String), snippet(String), draggable(boolean). Return a list of unqiue ids for the added " + " markers. Note that the markers ids are not meant to persist after " + " the app is closed, but for temporary references to the markers within the program only. Return an empty list" + " if any error happen in the input") public YailList AddMarkers(YailList markers) { // For color, check out the code in Form.java$BackgroundColor() e.g. if // (argb != Component.COLOR_DEFAULT) // After the color is chosen, it's passed in as int into the method // We can have two ways for supporting color of map markers: 1) pass it in // as int in the Yailist, // 2) if the user omit the value for color, we will use the blue color\ // what's a easier way for people to know about the color list? // App Inventor currently uses RGB (android.graphics.Color), but android map // marker uses HUE // http://developer.android.com/reference/com/google/android/gms/maps/model/BitmapDescriptorFactory.html#HUE_YELLOW // We can use Android.graphics.Color.colorToHSV(int rgbcolor, float[]hsv) to // get the hue value in the hsv array float[] hsv = new float[3]; ArrayList<Integer> markerIds = new ArrayList<Integer>(); for (Object marker : markers.toArray()) { boolean addOne = true; if (marker instanceof YailList) { Log.i(TAG, "interior YailLiat"); if (((YailList) marker).size() < 2) { addOne = false; // don't add this marker because its invalid inputs, going to the next one } // ((YailList) marker).getObject(0) will return type gnu.math.DFloNum Object latObj = ((YailList) marker).getObject(0); Object lngObj = ((YailList) marker).getObject(1); Log.i(TAG, "Type: " + latObj.getClass()); Log.i(TAG, "Type: " + lngObj.getClass()); Double lat = new Double(0); Double lng = new Double(0); if (!(latObj instanceof DFloNum && lngObj instanceof DFloNum)) {//if one of the lat or lng is not DFloNum addOne = false; } else { lat = ((DFloNum) latObj).doubleValue(); lng = ((DFloNum) lngObj).doubleValue(); } //check for lat, lng range // Latitude measurements range from 0 to (+/)90. // Longitude measurements range from 0 to (+/)180 if ((lat < -90) || (lat > 90) || (lng < -180) || (lng > 180)) { addOne = false; } //default values for optional params int color = mMarkerColor; String title = ""; String snippet = ""; boolean draggable = mMarkerDraggable; if (((YailList) marker).size() >= 3) { Log.i(TAG, "Type: " + ((YailList) marker).getObject(2).getClass()); Log.i(TAG, "Value: " + ((YailList) marker).getObject(2).toString()); // Integer within Yaillist is of type gnu.math.IntNum Object colorObj = ((YailList) marker).getObject(2); if (colorObj instanceof gnu.math.IntNum) color = ((IntNum) ((YailList) marker).getObject(2)).intValue(); else { addOne = false; } } if (((YailList) marker).size() >= 4) { Log.i(TAG, "Type: " + ((YailList) marker).getObject(3).getClass()); Log.i(TAG, "Value: " + ((YailList) marker).getObject(3).toString()); title = ((YailList) marker).getObject(3).toString(); } if (((YailList) marker).size() >= 5) { Log.i(TAG, "Type: " + ((YailList) marker).getObject(4).getClass()); Log.i(TAG, "Value: " + ((YailList) marker).getObject(4).toString()); snippet = ((YailList) marker).getObject(4).toString(); } if (((YailList) marker).size() >= 6) { Log.i(TAG, "Type: " + ((YailList) marker).getObject(5).getClass()); Log.i(TAG, "Value: " + ((YailList) marker).getObject(5).toString()); if (((YailList) marker).getObject(5) instanceof Boolean) { draggable = (Boolean) ((YailList) marker).getObject(5); } else { addOne = false; } } Color.colorToHSV(color, hsv); if (addOne) { int uniqueId = generateMarkerId(); markerIds.add(uniqueId); addMarkerToMap(lat, lng, uniqueId, hsv[0], title, snippet, draggable); } } else { // fire exception and throw error messages form.dispatchErrorOccurredEvent(this, "AddMarkers", ErrorMessages.ERROR_GOOGLE_MAP_INVALID_INPUT, "marker is not represented as list"); continue; // don't add this marker because its invalid inputs, going to the next one } } return YailList.makeList(markerIds); }
From source file:com.google.appinventor.components.runtime.GoogleMap.java
@SimpleFunction(description = "Adding a list of markers that are represented as JsonArray. " + " The inner JsonObject represents a marker" + "and is composed of name-value pairs. Name fields for a marker are: " + "\"lat\" (type double) [required], \"lng\"(type double) [required], " + "\"color\"(type int)[in hue value ranging from 0~360], " + "\"title\"(type String), \"snippet\"(type String), \"draggable\"(type boolean)") public void AddMarkersFromJson(String jsonString) { ArrayList<Integer> markerIds = new ArrayList<Integer>(); JsonParser parser = new JsonParser(); float[] hsv = new float[3]; // parse jsonString into jsonArray try {/*from w w w. j a va2 s .c om*/ JsonElement markerList = parser.parse(jsonString); if (markerList.isJsonArray()) { JsonArray markerArray = markerList.getAsJsonArray(); Log.i(TAG, "It's a JsonArry: " + markerArray.toString()); for (JsonElement marker : markerArray) { boolean addOne = true; // now we have marker if (marker.isJsonObject()) { JsonObject markerJson = marker.getAsJsonObject(); if (markerJson.get("lat") == null || markerJson.get("lng") == null) { addOne = false; } else { // having correct syntax of a marker in Json // check for cases: "lat" : "40.7561" (as String) JsonPrimitive jpLat = (JsonPrimitive) markerJson.get("lat"); JsonPrimitive jpLng = (JsonPrimitive) markerJson.get("lng"); double latitude = 0; double longitude = 0; try { //it's possible that when converting to Double, we will have errors // for example, some json has "lat": "" (empty string for lat, lng values) if (jpLat.isString() && jpLng.isString()) { Log.i(TAG, "jpLat:" + jpLat.toString()); Log.i(TAG, "jpLng:" + jpLng.toString()); latitude = new Double(jpLat.getAsString()); longitude = new Double(jpLng.getAsString()); Log.i(TAG, "convert to double:" + latitude + "," + longitude); } else { latitude = markerJson.get("lat").getAsDouble(); longitude = markerJson.get("lng").getAsDouble(); } } catch (NumberFormatException e) { addOne = false; } // check for Lat, Lng correct range if ((latitude < -90) || (latitude > 90) || (longitude < -180) || (longitude > 180)) { Log.i(TAG, "Lat/Lng wrong range:" + latitude + "," + longitude); addOne = false; } Color.colorToHSV(mMarkerColor, hsv); float defaultColor = hsv[0]; float color = (markerJson.get("color") == null) ? defaultColor : markerJson.get("color").getAsInt(); if ((color < 0) || (color > 360)) { Log.i(TAG, "Wrong color"); addOne = false; } String title = (markerJson.get("title") == null) ? "" : markerJson.get("title").getAsString(); String snippet = (markerJson.get("snippet") == null) ? "" : markerJson.get("snippet").getAsString(); boolean draggable = (markerJson.get("draggable") == null) ? mMarkerDraggable : markerJson.get("draggable").getAsBoolean(); if (addOne) { Log.i(TAG, "Adding marker" + latitude + "," + longitude); int uniqueId = generateMarkerId(); markerIds.add(uniqueId); addMarkerToMap(latitude, longitude, uniqueId, color, title, snippet, draggable); } } } } //end of JsonArray } else { // not a JsonArray form.dispatchErrorOccurredEvent(this, "AddMarkersFromJson", ErrorMessages.ERROR_GOOGLE_MAP_INVALID_INPUT, "markers needs to be represented as JsonArray"); markersList = YailList.makeList(markerIds); } } catch (JsonSyntaxException e) { form.dispatchErrorOccurredEvent(this, "AddMarkersFromJson", ErrorMessages.ERROR_GOOGLE_MAP_JSON_FORMAT_DECODE_FAILED, jsonString); markersList = YailList.makeList(markerIds); // return an empty markerIds list } markersList = YailList.makeList(markerIds); // return YailList.makeList(markerIds); }
From source file:com.rks.musicx.misc.utils.Helper.java
@ColorInt public static int getDarkerColor(@ColorInt int color, @FloatRange(from = 0.0D, to = 1.0D) float transparency) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] *= transparency;/*from w ww .j a v a 2 s . c om*/ return Color.HSVToColor(hsv); }
From source file:com.creativeongreen.imageeffects.MainActivity.java
public static Bitmap getCartoonizedBitmap(Bitmap realBitmap, Bitmap dodgeBlendBitmap, int hueIntervalSize, int saturationIntervalSize, int valueIntervalSize, int saturationPercent, int valuePercent) { // Bitmap bitmap = Bitmap.createBitmap(scaledBitmap); // //fastblur(scaledBitmap, 4); Bitmap base = fastblur(realBitmap, 3).copy(Config.ARGB_8888, true); Bitmap dodge = dodgeBlendBitmap.copy(Config.ARGB_8888, false); try {/*from w w w.jav a 2 s. com*/ int realColor; int color; float top = 0.87f;// VALUE_TOP; // Between 0.0f .. 1.0f I use 0.87f IntBuffer templatePixels = IntBuffer.allocate(dodge.getWidth() * dodge.getHeight()); IntBuffer scaledPixels = IntBuffer.allocate(base.getWidth() * base.getHeight()); IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight()); base.copyPixelsToBuffer(scaledPixels); dodge.copyPixelsToBuffer(templatePixels); templatePixels.rewind(); scaledPixels.rewind(); buffOut.rewind(); while (buffOut.position() < buffOut.limit()) { color = (templatePixels.get()); realColor = scaledPixels.get(); float[] realHSV = new float[3]; Color.colorToHSV(realColor, realHSV); realHSV[0] = getRoundedValue(realHSV[0], hueIntervalSize); realHSV[2] = (getRoundedValue(realHSV[2] * 100, valueIntervalSize) / 100) * (valuePercent / 100); realHSV[2] = realHSV[2] < 1.0 ? realHSV[2] : 1.0f; realHSV[1] = realHSV[1] * (saturationPercent / 100); realHSV[1] = realHSV[1] < 1.0 ? realHSV[1] : 1.0f; float[] HSV = new float[3]; Color.colorToHSV(color, HSV); boolean putBlackPixel = HSV[2] <= top; realColor = Color.HSVToColor(realHSV); if (putBlackPixel) { buffOut.put(color); } else { buffOut.put(realColor); } } // END WHILE dodge.recycle(); buffOut.rewind(); base.copyPixelsFromBuffer(buffOut); } catch (Exception e) { // TODO: handle exception } return base; }