List of usage examples for android.graphics Color argb
@ColorInt public static int argb(float alpha, float red, float green, float blue)
From source file:net.rossharper.coloredtablayout.TabLayout.java
static int lerpColor(int startColor, int endColor, float fraction) { return Color.argb((int) lerp(Color.alpha(startColor), Color.alpha(endColor), fraction), (int) lerp(Color.red(startColor), Color.red(endColor), fraction), (int) lerp(Color.green(startColor), Color.green(endColor), fraction), (int) lerp(Color.blue(startColor), Color.blue(endColor), fraction)); }
From source file:com.yk.notification.util.BitmapUtil.java
/** * ?//from w w w . j a v a2s . co m * * @param bitmap * * @param centerX * ?X? * @param centerY * ?Y? * @return ?? */ public static Bitmap sunshine(Bitmap bitmap, int centerX, int centerY) { final int width = bitmap.getWidth(); final int height = bitmap.getHeight(); Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565); int pixR = 0; int pixG = 0; int pixB = 0; int pixColor = 0; int newR = 0; int newG = 0; int newB = 0; int radius = Math.min(centerX, centerY); final float strength = 150F; // 100~150 int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); int pos = 0; for (int i = 1, length = height - 1; i < length; i++) { for (int k = 1, len = width - 1; k < len; k++) { pos = i * width + k; pixColor = pixels[pos]; pixR = Color.red(pixColor); pixG = Color.green(pixColor); pixB = Color.blue(pixColor); newR = pixR; newG = pixG; newB = pixB; // ???? int distance = (int) (Math.pow((centerY - i), 2) + Math.pow(centerX - k, 2)); if (distance < radius * radius) { // ?? int result = (int) (strength * (1.0 - Math.sqrt(distance) / radius)); newR = pixR + result; newG = pixG + result; newB = pixB + result; } newR = Math.min(255, Math.max(0, newR)); newG = Math.min(255, Math.max(0, newG)); newB = Math.min(255, Math.max(0, newB)); pixels[pos] = Color.argb(255, newR, newG, newB); } } newBitmap.setPixels(pixels, 0, width, 0, 0, width, height); return newBitmap; }
From source file:com.alexcruz.papuhwalls.MainActivity.java
public static int tint(int color, double factor) { int a = Color.alpha(color); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); return Color.argb(a, Math.max((int) (r * factor), 0), Math.max((int) (g * factor), 0), Math.max((int) (b * factor), 0)); }
From source file:com.yk.notification.util.BitmapUtil.java
/** * ?/*from w ww. j a va 2s.co m*/ * * @param bitmap * * @return ?? */ public static Bitmap film(Bitmap bitmap) { // RGBA final int MAX_VALUE = 255; int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565); int pixR = 0; int pixG = 0; int pixB = 0; int pixColor = 0; int newR = 0; int newG = 0; int newB = 0; int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); int pos = 0; for (int i = 1, length = height - 1; i < length; i++) { for (int k = 1, len = width - 1; k < len; k++) { pos = i * width + k; pixColor = pixels[pos]; pixR = Color.red(pixColor); pixG = Color.green(pixColor); pixB = Color.blue(pixColor); newR = MAX_VALUE - pixR; newG = MAX_VALUE - pixG; newB = MAX_VALUE - pixB; newR = Math.min(MAX_VALUE, Math.max(0, newR)); newG = Math.min(MAX_VALUE, Math.max(0, newG)); newB = Math.min(MAX_VALUE, Math.max(0, newB)); pixels[pos] = Color.argb(MAX_VALUE, newR, newG, newB); } } newBitmap.setPixels(pixels, 0, width, 0, 0, width, height); return newBitmap; }
From source file:com.yk.notification.util.BitmapUtil.java
/** * ??/* w ww .j a va2 s .c o m*/ * * @param bitmap * * @return ??? */ public static Bitmap sharpen(Bitmap bitmap) { // int[] laplacian = new int[] { -1, -1, -1, -1, 9, -1, -1, -1, -1 }; int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565); int pixR = 0; int pixG = 0; int pixB = 0; int pixColor = 0; int newR = 0; int newG = 0; int newB = 0; int idx = 0; float alpha = 0.3F; int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); for (int i = 1, length = height - 1; i < length; i++) { for (int k = 1, len = width - 1; k < len; k++) { idx = 0; for (int m = -1; m <= 1; m++) { for (int n = -1; n <= 1; n++) { pixColor = pixels[(i + n) * width + k + m]; pixR = Color.red(pixColor); pixG = Color.green(pixColor); pixB = Color.blue(pixColor); newR = newR + (int) (pixR * laplacian[idx] * alpha); newG = newG + (int) (pixG * laplacian[idx] * alpha); newB = newB + (int) (pixB * laplacian[idx] * alpha); idx++; } } newR = Math.min(255, Math.max(0, newR)); newG = Math.min(255, Math.max(0, newG)); newB = Math.min(255, Math.max(0, newB)); pixels[i * width + k] = Color.argb(255, newR, newG, newB); newR = 0; newG = 0; newB = 0; } } newBitmap.setPixels(pixels, 0, width, 0, 0, width, height); return newBitmap; }
From source file:com.creativeongreen.imageeffects.MainActivity.java
public static Bitmap colorDodgeBlend(Bitmap source, Bitmap layer) { Bitmap base = source.copy(Config.ARGB_8888, true); Bitmap blend = layer.copy(Config.ARGB_8888, false); IntBuffer buffBase = IntBuffer.allocate(base.getWidth() * base.getHeight()); base.copyPixelsToBuffer(buffBase);/* w w w . j ava 2 s . c o m*/ buffBase.rewind(); IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight()); blend.copyPixelsToBuffer(buffBlend); buffBlend.rewind(); IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight()); buffOut.rewind(); while (buffOut.position() < buffOut.limit()) { int filterInt = buffBlend.get(); int srcInt = buffBase.get(); int redValueFilter = Color.red(filterInt); int greenValueFilter = Color.green(filterInt); int blueValueFilter = Color.blue(filterInt); int redValueSrc = Color.red(srcInt); int greenValueSrc = Color.green(srcInt); int blueValueSrc = Color.blue(srcInt); int redValueFinal = colordodge(redValueFilter, redValueSrc); int greenValueFinal = colordodge(greenValueFilter, greenValueSrc); int blueValueFinal = colordodge(blueValueFilter, blueValueSrc); int pixel = Color.argb(255, redValueFinal, greenValueFinal, blueValueFinal); /* * float[] hsv = new float[3]; Color.colorToHSV(pixel, hsv); hsv[1] = 0.0f; float top = * VALUE_TOP; // Setting this as 0.95f gave the best result so far if (hsv[2] <= top) { * hsv[2] = 0.0f; } else { hsv[2] = 1.0f; } pixel = Color.HSVToColor(hsv); */ buffOut.put(pixel); } buffOut.rewind(); base.copyPixelsFromBuffer(buffOut); blend.recycle(); return base; }
From source file:com.ichi2.anki.AbstractFlashcardViewer.java
@SuppressLint({ "NewApi", "SetJavaScriptEnabled" }) // because of setDisplayZoomControls. private WebView createWebView() { WebView webView = new MyWebView(this); webView.setWillNotCacheDrawing(true); webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); if (CompatHelper.isHoneycomb()) { // Disable the on-screen zoom buttons for API > 11 webView.getSettings().setDisplayZoomControls(false); }//from www .j a v a 2s.c o m webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setSupportZoom(true); // Start at the most zoomed-out level webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setJavaScriptEnabled(true); webView.setWebChromeClient(new AnkiDroidWebChromeClient()); // Problems with focus and input tags is the reason we keep the old type answer mechanism for old Androids. webView.setFocusableInTouchMode(mUseInputTag); webView.setScrollbarFadingEnabled(true); Timber.d("Focusable = %s, Focusable in touch mode = %s", webView.isFocusable(), webView.isFocusableInTouchMode()); webView.setWebViewClient(new WebViewClient() { // Filter any links using the custom "playsound" protocol defined in Sound.java. // We play sounds through these links when a user taps the sound icon. @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.startsWith("playsound:")) { // Send a message that will be handled on the UI thread. Message msg = Message.obtain(); String soundPath = url.replaceFirst("playsound:", ""); msg.obj = soundPath; mHandler.sendMessage(msg); return true; } if (url.startsWith("file") || url.startsWith("data:")) { return false; // Let the webview load files, i.e. local images. } if (url.startsWith("typeblurtext:")) { // Store the text the javascript has send us mTypeInput = URLDecoder.decode(url.replaceFirst("typeblurtext:", "")); // and show the SHOW ANSWER? button again. mFlipCardLayout.setVisibility(View.VISIBLE); return true; } if (url.startsWith("typeentertext:")) { // Store the text the javascript has send us mTypeInput = URLDecoder.decode(url.replaceFirst("typeentertext:", "")); // and show the answer. mFlipCardLayout.performClick(); return true; } if (url.equals("signal:typefocus")) { // Hide the SHOW ANSWER? button when the input has focus. The soft keyboard takes up enough space // by itself. mFlipCardLayout.setVisibility(View.GONE); return true; } Timber.d("Opening external link \"%s\" with an Intent", url); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); try { startActivityWithoutAnimation(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); // Don't crash if the intent is not handled } return true; } // Run any post-load events in javascript that rely on the window being completely loaded. @Override public void onPageFinished(WebView view, String url) { Timber.d("onPageFinished triggered"); view.loadUrl("javascript:onPageFinished();"); } }); // Set transparent color to prevent flashing white when night mode enabled webView.setBackgroundColor(Color.argb(1, 0, 0, 0)); return webView; }
From source file:com.yk.notification.util.BitmapUtil.java
/** * ?//ww w . jav a 2s.c om * * @param bitmap * * @return ?? */ public static Bitmap emboss(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565); int pixR = 0; int pixG = 0; int pixB = 0; int pixColor = 0; int newR = 0; int newG = 0; int newB = 0; int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); int pos = 0; for (int i = 1, length = height - 1; i < length; i++) { for (int k = 1, len = width - 1; k < len; k++) { pos = i * width + k; pixColor = pixels[pos]; pixR = Color.red(pixColor); pixG = Color.green(pixColor); pixB = Color.blue(pixColor); pixColor = pixels[pos + 1]; newR = Color.red(pixColor) - pixR + 127; newG = Color.green(pixColor) - pixG + 127; newB = Color.blue(pixColor) - pixB + 127; newR = Math.min(255, Math.max(0, newR)); newG = Math.min(255, Math.max(0, newG)); newB = Math.min(255, Math.max(0, newB)); pixels[pos] = Color.argb(255, newR, newG, newB); } } newBitmap.setPixels(pixels, 0, width, 0, 0, width, height); return newBitmap; }
From source file:org.appcelerator.titanium.util.TiUIHelper.java
public static int adjustColorAlpha(final int color, final float factor) { int alpha = Math.round(Color.alpha(color) * factor); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); return Color.argb(alpha, red, green, blue); }
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * Reuse of bitmaps in tiled backgrounds is a known cause of problems: * http://stackoverflow.com/questions/4077487/background-image-not-repeating-in-android-layout * So we avoid reusing them.//w w w.j a v a 2 s . c om * * This seems to have become further messed up in 4.1 so now, we just created them manually. No references, * but the old cleanup method (see below for cleanupTiledBackground()) no longer works. Since it effectively * un-cached the background, we just create it here. * * The main problem with this approach is that the style is defined in code rather than XML. * * @param a Activity context * @param bright Flag indicating if background should be 'bright' * * @return Background Drawable */ public static Drawable makeTiledBackground(boolean bright) { // Storage for the layers Drawable[] drawables = new Drawable[2]; // Get the BG image, put in tiled drawable Bitmap b = BitmapFactory.decodeResource(BookCatalogueApp.context.getResources(), R.drawable.books_bg); BitmapDrawable bmD = new BitmapDrawable(BookCatalogueApp.context.getResources(), b); bmD.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT); // Add to layers drawables[0] = bmD; // Set up the gradient colours based on 'bright' setting int[] colours = new int[3]; if (bright) { colours[0] = Color.argb(224, 0, 0, 0); colours[1] = Color.argb(208, 0, 0, 0); colours[2] = Color.argb(48, 0, 0, 0); } else { colours[0] = Color.argb(255, 0, 0, 0); colours[1] = Color.argb(208, 0, 0, 0); colours[2] = Color.argb(160, 0, 0, 0); } // Create a gradient and add to layers GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colours); drawables[1] = gd; // Make the layers and we are done. LayerDrawable ll = new LayerDrawable(drawables); ll.setDither(true); return ll; }