List of usage examples for android.graphics Bitmap getPixels
public void getPixels(@ColorInt int[] pixels, int offset, int stride, int x, int y, int width, int height)
From source file:com.yk.notification.util.BitmapUtil.java
/** * ??// www . j a v a2s.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.yk.notification.util.BitmapUtil.java
/** * ??/*from w w w. j av a 2 s .c o m*/ * * @param delta * ??(0,24) * @return */ public static Bitmap adjustTone(Bitmap src, int delta) { if (delta >= 24 || delta <= 0) { return null; } // int[] gauss = new int[] { 1, 2, 1, 2, 4, 2, 1, 2, 1 }; int width = src.getWidth(); int height = src.getHeight(); Bitmap bitmap = 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; int[] pixels = new int[width * height]; src.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 + m) * width + k + n]; pixR = Color.red(pixColor); pixG = Color.green(pixColor); pixB = Color.blue(pixColor); newR += (pixR * gauss[idx]); newG += (pixG * gauss[idx]); newB += (pixB * gauss[idx]); idx++; } } newR /= delta; newG /= delta; newB /= delta; 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; } } bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; }
From source file:com.yk.notification.util.BitmapUtil.java
/** * ?/*from w w w .java 2s. c om*/ * * @param bitmap * * @return ?? */ public static Bitmap soften(Bitmap bitmap) { // int[] gauss = new int[] { 1, 2, 1, 2, 4, 2, 1, 2, 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 delta = 16; // ? int idx = 0; 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 + m) * width + k + n]; pixR = Color.red(pixColor); pixG = Color.green(pixColor); pixB = Color.blue(pixColor); newR = newR + pixR * gauss[idx]; newG = newG + pixG * gauss[idx]; newB = newB + pixB * gauss[idx]; idx++; } } newR /= delta; newG /= delta; newB /= delta; 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.juce.JuceAppActivity.java
public final int[] renderGlyph (char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) { Path p = new Path(); paint.getTextPath (String.valueOf (glyph), 0, 1, 0.0f, 0.0f, p); RectF boundsF = new RectF(); p.computeBounds (boundsF, true);//w ww .j a v a2 s . com matrix.mapRect (boundsF); boundsF.roundOut (bounds); bounds.left--; bounds.right++; final int w = bounds.width(); final int h = Math.max (1, bounds.height()); Bitmap bm = Bitmap.createBitmap (w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas (bm); matrix.postTranslate (-bounds.left, -bounds.top); c.setMatrix (matrix); c.drawPath (p, paint); final int sizeNeeded = w * h; if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int [sizeNeeded]; bm.getPixels (cachedRenderArray, 0, w, 0, 0, w, h); bm.recycle(); return cachedRenderArray; }
From source file:com.ksharkapps.musicnow.ui.activities.AudioPlayerActivity.java
private int getBackgroundColor(Bitmap imagen) { long reds = 0L; long greens = 0L; long blues = 0L; int[] pixeles = new int[imagen.getWidth() * imagen.getHeight()]; imagen.getPixels(pixeles, 0, imagen.getWidth(), 0, 0, imagen.getWidth(), imagen.getHeight()); for (int cursor = 0; cursor < pixeles.length; cursor++) { reds += Color.red(pixeles[cursor]); greens += Color.green(pixeles[cursor]); blues += Color.blue(pixeles[cursor]); }//from w ww. j a v a 2 s. com long numPixels = imagen.getWidth() * imagen.getHeight(); reds /= numPixels; greens /= numPixels; blues /= numPixels; Punto3D[] pixelesRef = { new Punto3D(255, 0, 0), new Punto3D(0, 255, 0), new Punto3D(0, 0, 255), new Punto3D(255, 255, 0), new Punto3D(0, 255, 255), new Punto3D(255, 0, 255), new Punto3D(0, 0, 0), new Punto3D(255, 255, 255) }; Punto3D pixelActual = new Punto3D(reds, greens, blues); double[] distancias = { pixelActual.distancia(pixelesRef[0]), pixelActual.distancia(pixelesRef[1]), pixelActual.distancia(pixelesRef[2]), pixelActual.distancia(pixelesRef[3]), pixelActual.distancia(pixelesRef[4]), pixelActual.distancia(pixelesRef[5]), pixelActual.distancia(pixelesRef[6]), pixelActual.distancia(pixelesRef[7]) }; String[] colors = { "Red", "Green", "Blue", "Yellow", "Cyan ", "Magenta", " Black ", "White" }; double dist_minima = 255; int indice_minima = 0; for (int index = 0; index < distancias.length; index++) { if (distancias[index] <= dist_minima) { indice_minima = index; dist_minima = distancias[index]; } Log.i("Distancias", "Distancias en pos " + index + ": " + distancias[index]); } return Color.rgb((int) pixelesRef[indice_minima].getX(), (int) pixelesRef[indice_minima].getY(), (int) pixelesRef[indice_minima].getZ()); }
From source file:com.ksharkapps.musicnow.ui.activities.AudioPlayerActivity.java
private void processImage() { Bitmap image = ((BitmapDrawable) mAlbumArt.getDrawable()).getBitmap(); ColorArt colorArt = new ColorArt(image); // get the colors colorArt.getBackgroundColor();//from w ww .j a v a 2 s .c om colorArt.getPrimaryColor(); colorArt.getSecondaryColor(); colorArt.getDetailColor(); Bitmap imagen = ((BitmapDrawable) mAlbumArt.getDrawable()).getBitmap(); long reds = 0L; long greens = 0L; long blues = 0L; int[] pixeles = new int[imagen.getWidth() * imagen.getHeight()]; imagen.getPixels(pixeles, 0, imagen.getWidth(), 0, 0, imagen.getWidth(), imagen.getHeight()); for (int cursor = 0; cursor < pixeles.length; cursor++) { reds += Color.red(pixeles[cursor]); greens += Color.green(pixeles[cursor]); blues += Color.blue(pixeles[cursor]); } long numPixels = imagen.getWidth() * imagen.getHeight(); reds /= numPixels; greens /= numPixels; blues /= numPixels; Punto3D[] pixelesRef = { new Punto3D(255, 0, 0), new Punto3D(0, 255, 0), new Punto3D(0, 0, 255), new Punto3D(255, 255, 0), new Punto3D(0, 255, 255), new Punto3D(255, 0, 255), new Punto3D(0, 0, 0), new Punto3D(255, 255, 255) }; Punto3D pixelActual = new Punto3D(reds, greens, blues); double[] distancias = { pixelActual.distancia(pixelesRef[0]), pixelActual.distancia(pixelesRef[1]), pixelActual.distancia(pixelesRef[2]), pixelActual.distancia(pixelesRef[3]), pixelActual.distancia(pixelesRef[4]), pixelActual.distancia(pixelesRef[5]), pixelActual.distancia(pixelesRef[6]), pixelActual.distancia(pixelesRef[7]) }; String[] colors = { "Red", "Green", "Blue", "Yellow", "Cyan ", "Magenta", " Black ", "White" }; double dist_minima = 255; int indice_minima = 0; for (int index = 0; index < distancias.length; index++) { if (distancias[index] <= dist_minima) { indice_minima = index; dist_minima = distancias[index]; } Log.i("Distancias", "Distancias en pos " + index + ": " + distancias[index]); } GradientDrawable gd2 = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { Color.rgb((int) pixelesRef[indice_minima].getX(), (int) pixelesRef[indice_minima].getY(), (int) pixelesRef[indice_minima].getZ()), colorArt.getBackgroundColor(), colorArt.getDetailColor() }); gd2.setCornerRadius(0f); player_bg.setBackgroundDrawable(gd2); }
From source file:com.miz.functions.MizLib.java
/** * Stack BlurUtil v1.0 from//from ww w .j a va 2 s . co m http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html Java Author: Mario Klingemann <mario at quasimondo.com> http://incubator.quasimondo.com created Feburary 29, 2004 Android port : Yahel Bouaziz <yahel at kayenko.com> http://www.kayenko.com ported april 5th, 2012 This is a compromise between Gaussian BlurUtil and Box blur It creates much better looking blurs than Box BlurUtil, but is 7x faster than my Gaussian BlurUtil implementation. I called it Stack BlurUtil because this describes best how this filter works internally: it creates a kind of moving stack of colors whilst scanning through the image. Thereby it just has to add one new block of color to the right side of the stack and remove the leftmost color. The remaining colors on the topmost layer of the stack are either added on or reduced by one, depending on if they are on the right or on the left side of the stack. If you are using this algorithm in your code please add the following line: Stack BlurUtil Algorithm by Mario Klingemann <mario@quasimondo.com> */ public static Bitmap slowBlur(Bitmap originalBitmap, int radius) { if (radius < 1) { return (null); } int w = originalBitmap.getWidth(); int h = originalBitmap.getHeight(); int[] pix = new int[w * h]; originalBitmap.getPixels(pix, 0, w, 0, 0, w, h); int wm = w - 1; int hm = h - 1; int wh = w * h; int div = radius + radius + 1; int r[] = new int[wh]; int g[] = new int[wh]; int b[] = new int[wh]; int rsum, gsum, bsum, x, y, i, p, yp, yi, yw; int vmin[] = new int[Math.max(w, h)]; int divsum = (div + 1) >> 1; divsum *= divsum; int dv[] = new int[256 * divsum]; for (i = 0; i < 256 * divsum; i++) { dv[i] = (i / divsum); } yw = yi = 0; int[][] stack = new int[div][3]; int stackpointer; int stackstart; int[] sir; int rbs; int r1 = radius + 1; int routsum, goutsum, boutsum; int rinsum, ginsum, binsum; for (y = 0; y < h; y++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; for (i = -radius; i <= radius; i++) { p = pix[yi + Math.min(wm, Math.max(i, 0))]; sir = stack[i + radius]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rbs = r1 - Math.abs(i); rsum += sir[0] * rbs; gsum += sir[1] * rbs; bsum += sir[2] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } } stackpointer = radius; for (x = 0; x < w; x++) { r[yi] = dv[rsum]; g[yi] = dv[gsum]; b[yi] = dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (y == 0) { vmin[x] = Math.min(x + radius + 1, wm); } p = pix[yw + vmin[x]]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[(stackpointer) % div]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi++; } yw += w; } for (x = 0; x < w; x++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; yp = -radius * w; for (i = -radius; i <= radius; i++) { yi = Math.max(0, yp) + x; sir = stack[i + radius]; sir[0] = r[yi]; sir[1] = g[yi]; sir[2] = b[yi]; rbs = r1 - Math.abs(i); rsum += r[yi] * rbs; gsum += g[yi] * rbs; bsum += b[yi] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } if (i < hm) { yp += w; } } yi = x; stackpointer = radius; for (y = 0; y < h; y++) { // Preserve alpha channel: ( 0xff000000 & pix[yi] ) pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (x == 0) { vmin[y] = Math.min(y + r1, hm) * w; } p = x + vmin[y]; sir[0] = r[p]; sir[1] = g[p]; sir[2] = b[p]; rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[stackpointer]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi += w; } } originalBitmap.setPixels(pix, 0, w, 0, 0, w, h); return originalBitmap; }
From source file:Main.java
/** * Apply a blur to a Bitmap//from w w w . j a v a2 s.c o m * * @param context Application context * @param sentBitmap Bitmap to be converted * @param radius Desired Radius, 0 < r < 25 * @return a copy of the image with a blur */ @SuppressLint("InlinedApi") public static Bitmap blur(Context context, Bitmap sentBitmap, int radius) { if (radius < 0) { radius = 0; if (DEBUG) { } } else if (radius > 25) { radius = 25; if (DEBUG) { } } if (Build.VERSION.SDK_INT > 16) { Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); final RenderScript rs = RenderScript.create(context); final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius /* e.g. 3.f */); script.setInput(input); script.forEach(output); output.copyTo(bitmap); return bitmap; } // Stack Blur v1.0 from // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html // // Java Author: Mario Klingemann <mario at quasimondo.com> // http://incubator.quasimondo.com // created Feburary 29, 2004 // Android port : Yahel Bouaziz <yahel at kayenko.com> // http://www.kayenko.com // ported april 5th, 2012 // This is a compromise between Gaussian Blur and Box blur // It creates much better looking blurs than Box Blur, but is // 7x faster than my Gaussian Blur implementation. // // I called it Stack Blur because this describes best how this // filter works internally: it creates a kind of moving stack // of colors whilst scanning through the image. Thereby it // just has to add one new block of color to the right side // of the stack and remove the leftmost color. The remaining // colors on the topmost layer of the stack are either added on // or reduced by one, depending on if they are on the right or // on the left side of the stack. // // If you are using this algorithm in your code please add // the following line: // // Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com> Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); if (radius < 1) { return (null); } int w = bitmap.getWidth(); int h = bitmap.getHeight(); int[] pix = new int[w * h]; Log.e("pix", w + " " + h + " " + pix.length); bitmap.getPixels(pix, 0, w, 0, 0, w, h); int wm = w - 1; int hm = h - 1; int wh = w * h; int div = radius + radius + 1; int r[] = new int[wh]; int g[] = new int[wh]; int b[] = new int[wh]; int rsum, gsum, bsum, x, y, i, p, yp, yi, yw; int vmin[] = new int[Math.max(w, h)]; int divsum = (div + 1) >> 1; divsum *= divsum; int dv[] = new int[256 * divsum]; for (i = 0; i < 256 * divsum; i++) { dv[i] = (i / divsum); } yw = yi = 0; int[][] stack = new int[div][3]; int stackpointer; int stackstart; int[] sir; int rbs; int r1 = radius + 1; int routsum, goutsum, boutsum; int rinsum, ginsum, binsum; for (y = 0; y < h; y++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; for (i = -radius; i <= radius; i++) { p = pix[yi + Math.min(wm, Math.max(i, 0))]; sir = stack[i + radius]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rbs = r1 - Math.abs(i); rsum += sir[0] * rbs; gsum += sir[1] * rbs; bsum += sir[2] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } } stackpointer = radius; for (x = 0; x < w; x++) { r[yi] = dv[rsum]; g[yi] = dv[gsum]; b[yi] = dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (y == 0) { vmin[x] = Math.min(x + radius + 1, wm); } p = pix[yw + vmin[x]]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[(stackpointer) % div]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi++; } yw += w; } for (x = 0; x < w; x++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; yp = -radius * w; for (i = -radius; i <= radius; i++) { yi = Math.max(0, yp) + x; sir = stack[i + radius]; sir[0] = r[yi]; sir[1] = g[yi]; sir[2] = b[yi]; rbs = r1 - Math.abs(i); rsum += r[yi] * rbs; gsum += g[yi] * rbs; bsum += b[yi] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } if (i < hm) { yp += w; } } yi = x; stackpointer = radius; for (y = 0; y < h; y++) { // Preserve alpha channel: ( 0xff000000 & pix[yi] ) pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (x == 0) { vmin[y] = Math.min(y + r1, hm) * w; } p = x + vmin[y]; sir[0] = r[p]; sir[1] = g[p]; sir[2] = b[p]; rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[stackpointer]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi += w; } } Log.e("pix", w + " " + h + " " + pix.length); bitmap.setPixels(pix, 0, w, 0, 0, w, h); return (bitmap); }
From source file:com.iiordanov.bVNC.RemoteCanvas.java
/** * Initializes the data structure which holds the remote pointer data. *//*from ww w . j a v a 2s .c om*/ void initializeSoftCursor() { Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.cursor); int w = bm.getWidth(); int h = bm.getHeight(); int[] tempPixels = new int[w * h]; bm.getPixels(tempPixels, 0, w, 0, 0, w, h); // Set cursor rectangle as well. bitmapData.setCursorRect(pointer.getX(), pointer.getY(), w, h, 0, 0); // Set softCursor to whatever the resource is. bitmapData.setSoftCursor(tempPixels); bm.recycle(); }
From source file:com.hotstar.player.adplayer.player.PlayerFragment.java
/** * Initialize the player fragment by setting up views, media player and * feature managers/*from w ww .j a va 2 s . co m*/ * * @param intent * the intent that contains the video item */ private void initialize(Intent intent) { videoItem = (VideoItem) intent.getExtras().getSerializable("CONTENT_INFO"); AdVideoApplication.logger.i(LOG_TAG + "#initialize", "Initializing the media player with item [" + videoItem.getTitle() + "]."); playerClickableAdFragment = (PlayerClickableAdFragment) getActivity().getSupportFragmentManager() .findFragmentById(R.id.playerClickInfo); playerFrame = (FrameLayout) playerFragmentView.findViewById(R.id.playerFrame); ViewGroup controlBarView = (ViewGroup) playerFragmentView.findViewById(R.id.ControlBarItem); controlBar = new PlayerControlBar(getActivity(), controlBarView); // ViewGroup controlTopBarView = (ViewGroup) playerFragmentView.findViewById(R.id.ControlTopBarItem); // controlTopBar = new PlayerControlTopBar(getActivity(), controlTopBarView); ViewGroup controlAdBarView = (ViewGroup) playerFragmentView.findViewById(R.id.AdControlBarItem); controlAdBar = new PlayerAdControlBar(getActivity(), controlAdBarView); spinner = (ProgressBar) playerFragmentView.findViewById(R.id.pbBufferingSpinner); overlayAdImageView = (ImageView) playerFragmentView.findViewById(R.id.overlayAdImageView); overlayAdGifView = (GifImageView) playerFragmentView.findViewById(R.id.overlayAdGifView); overlayAdGifView.setOnFrameAvailable(new GifImageView.OnFrameAvailable() { @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override public Bitmap onFrameAvailable(Bitmap bitmap) { return bitmap; } }); java.io.InputStream is; is = mActivity.getResources().openRawResource(R.drawable.vpaid_ad_icon); vpaidAdIconGifView = (GifImageView) playerFragmentView.findViewById(R.id.vpaidAdIconGifView); vpaidAdIconGifView.setBytes(BytesManager.getBytes(is)); vpaidAdIconGifView.setOnFrameAvailable(new GifImageView.OnFrameAvailable() { @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override public Bitmap onFrameAvailable(Bitmap src) { if (src == null) return src; int width = src.getWidth(); int height = src.getHeight(); Bitmap b = src.copy(Bitmap.Config.ARGB_8888, true); b.setHasAlpha(true); int[] pixels = new int[width * height]; src.getPixels(pixels, 0, width, 0, 0, width, height); for (int i = 0; i < width * height; i++) { if ((pixels[i] == WHITE_COLOR) || (pixels[i] == BLACK_COLOR)) { pixels[i] = 0; } } b.setPixels(pixels, 0, width, 0, 0, width, height); return b; } }); vpaidAdIconGifView.setVisibility(View.INVISIBLE); vpaidAdIconGifView.setOnClickListener(vPaidADIconClickListener); thumbnailPlayImageView = (ImageView) playerFragmentView.findViewById(R.id.thumbnailPlayImageView); thumbnailPlayImageView.setVisibility(View.INVISIBLE); thumbnailImageView = (ImageView) playerFragmentView.findViewById(R.id.thumbnailImageView); thumbnailImageView.setVisibility(View.INVISIBLE); thumbnailImageView.setOnClickListener(thumbnailViewClickListener); OverlayAdResourceManager.getInstance().preloadImage(videoItem.getThumbnail().getLargeThumbnailUrl()); // audioProfile = (TextView) playerFragmentView.findViewById(R.id.audioTextView); // audioProfile.setText(R.string.qosAudioProfile); // audioProfile.setVisibility(View.INVISIBLE); // // _ccButton = (ImageButton) playerFragmentView.findViewById(R.id.sbPlayerControlCC); // _rewindButton = (ImageButton) playerFragmentView.findViewById(R.id.playerRewind); ((CustomFrameLayout) playerFrame).addOnSizeChangeListener(new OnSizeChangeListener() { @Override public void onSizeChanged() { // Scale player, since container size has changed. handler.post(new Runnable() { @Override public void run() { setPlayerViewSize(savedMovieWidth, savedMovieHeight); } }); } }); createPlayer(); setupViews(); createManagers(); prepareMedia(); }