use of android.graphics.PorterDuffXfermode in project android_frameworks_base by ParanoidAndroid.
the class BaseStatusBar method prepareHaloNotification.
public void prepareHaloNotification(NotificationData.Entry entry, StatusBarNotification notification, boolean update) {
Notification notif = notification.getNotification();
// Get the remote view
try {
if (!update) {
ViewGroup mainView = (ViewGroup) notif.contentView.apply(mContext, null, mOnClickHandler);
if (mainView instanceof FrameLayout) {
entry.haloContent = mainView.getChildAt(1);
mainView.removeViewAt(1);
} else {
entry.haloContent = mainView;
}
} else {
notif.contentView.reapply(mContext, entry.haloContent, mOnClickHandler);
}
} catch (Exception e) {
// Non uniform content?
android.util.Log.d("PARANOID", " Non uniform content?");
}
// Construct the round icon
final float haloSize = Settings.System.getFloat(mContext.getContentResolver(), Settings.System.HALO_SIZE, 1.0f);
int iconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.halo_bubble_size) * haloSize);
int smallIconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.status_bar_icon_size) * haloSize);
int largeIconWidth = notif.largeIcon != null ? (int) (notif.largeIcon.getWidth() * haloSize) : 0;
int largeIconHeight = notif.largeIcon != null ? (int) (notif.largeIcon.getHeight() * haloSize) : 0;
Bitmap roundIcon = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(roundIcon);
canvas.drawARGB(0, 0, 0, 0);
// halo-bubble, we'll use that one and cut it round
if (notif.largeIcon != null && largeIconWidth >= iconSize / 2) {
Paint smoothingPaint = new Paint();
smoothingPaint.setAntiAlias(true);
smoothingPaint.setFilterBitmap(true);
smoothingPaint.setDither(true);
canvas.drawCircle(iconSize / 2, iconSize / 2, iconSize / 2.3f, smoothingPaint);
smoothingPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
final int newWidth = iconSize;
final int newHeight = iconSize * largeIconWidth / largeIconHeight;
Bitmap scaledBitmap = Bitmap.createScaledBitmap(notif.largeIcon, newWidth, newHeight, true);
canvas.drawBitmap(scaledBitmap, null, new Rect(0, 0, iconSize, iconSize), smoothingPaint);
} else {
try {
Drawable icon = StatusBarIconView.getIcon(mContext, new StatusBarIcon(notification.getPackageName(), notification.getUser(), notif.icon, notif.iconLevel, notif.number, notif.tickerText));
if (icon == null)
icon = mContext.getPackageManager().getApplicationIcon(notification.getPackageName());
int margin = (iconSize - smallIconSize) / 2;
icon.setBounds(margin, margin, iconSize - margin, iconSize - margin);
icon.draw(canvas);
} catch (Exception e) {
// NameNotFoundException
}
}
entry.roundIcon = roundIcon;
}
use of android.graphics.PorterDuffXfermode in project Rajawali by Rajawali.
the class TerrainGenerator method createSquareTerrainFromBitmap.
/**
* Generate a Square Terrain using Bitmap as depth map (green component of ARGB)
*
* @param Parameters
* object that specify: ARGB Bitmap (R is temparature G is depth, A and B not used) Color Bitmpa
* (Optional) Number of divisions Scale of x,y,z coordinate TextureMult Specify the grid/texture relation
* Basecolor start color in relation with depth Middlecolor middle color Upcolor max depth color
* @param createVBOs
* @return
*/
public static SquareTerrain createSquareTerrainFromBitmap(SquareTerrain.Parameters prs, boolean createVBOs) {
int divisions = prs.divisions;
if (!((prs.divisions != 0) && ((prs.divisions & (prs.divisions - 1)) == 0))) {
throw new RuntimeException("Divisions must be x^2");
}
double[][] terrain = new double[divisions + 1][divisions + 1];
double[][] temperature = new double[divisions + 1][divisions + 1];
Vector3[][] normals = new Vector3[divisions + 1][divisions + 1];
boolean useColorBitmap = prs.colorMapBitmap != null;
int[] colorpixels = null;
Bitmap bnew = Bitmap.createBitmap(divisions + 1, divisions + 1, Bitmap.Config.ARGB_8888);
Canvas cnv = new Canvas(bnew);
cnv.drawBitmap(prs.heightMapBitmap, new Rect(0, 0, prs.heightMapBitmap.getWidth(), prs.heightMapBitmap.getHeight()), new Rect(0, 0, divisions + 1, divisions + 1), null);
int[] pixels = new int[(divisions + 1) * (divisions + 1)];
bnew.getPixels(pixels, 0, divisions + 1, 0, 0, divisions + 1, divisions + 1);
if (useColorBitmap) {
colorpixels = new int[(divisions + 1) * (divisions + 1)];
Paint clearPaint = new Paint();
clearPaint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR));
cnv.drawRect(0, 0, prs.colorMapBitmap.getWidth(), prs.colorMapBitmap.getHeight(), clearPaint);
cnv.drawBitmap(prs.colorMapBitmap, new Rect(0, 0, prs.colorMapBitmap.getWidth(), prs.colorMapBitmap.getHeight()), new Rect(0, 0, divisions + 1, divisions + 1), null);
bnew.getPixels(colorpixels, 0, divisions + 1, 0, 0, divisions + 1, divisions + 1);
}
bnew.recycle();
int color;
int cols = divisions + 1;
double min, max;
terrain[0][0] = Color.green(0) / 255f * prs.scale.y;
min = max = terrain[0][0];
double alt;
double temp;
float oneover255 = 1f / 255f;
for (int i = 0; i <= divisions; ++i) {
for (int j = 0; j <= divisions; ++j) {
color = pixels[i + j * cols];
alt = Color.green(color) * oneover255 * prs.scale.y;
temp = Color.red(color) * oneover255 * (prs.maxTemp - prs.minTemp) + prs.minTemp;
if (i > 0 && j > 0) {
temp = ((temperature[i - 1][j] + temperature[i][j - 1]) * 0.5f + temp) * 0.5f;
alt = ((terrain[i - 1][j] + terrain[i][j - 1]) * 0.5f + alt) * 0.5f;
} else if (j > 0) {
temp = (temperature[i][j - 1] + temp) * 0.5f;
alt = (terrain[i][j - 1] + alt) * 0.5f;
} else if (i > 0) {
temp = (temperature[i - 1][j] + temp) * 0.5f;
alt = (terrain[i - 1][j] + alt) * 0.5f;
}
temperature[i][j] = temp;
terrain[i][j] = alt;
if (alt < min)
min = alt;
else if (alt > max)
max = alt;
normals[i][j] = new Vector3(0f, 1f, 0f);
}
}
Vector3 scale = prs.scale;
Vector3 v0 = new Vector3();
Vector3 v1 = new Vector3();
Vector3 v2 = new Vector3();
Vector3 na = new Vector3();
Vector3 nb = new Vector3();
Vector3 nc = new Vector3();
Vector3 nd = new Vector3();
for (int x = 1; x < divisions; x++) {
for (int z = 1; z < divisions; z++) {
// O z-1
// /|\
// / | \
// x-1 O--O--O x+1
// \ | /
// \|/
// O z+1
v0.x = (x - 1) * scale.x;
v0.z = z * scale.z;
v0.y = terrain[x - 1][z];
v1.x = x * scale.x;
v1.z = (z - 1) * scale.z;
v1.y = terrain[x][z - 1];
v2.x = x * scale.x;
v2.z = z * scale.z;
v2.y = terrain[x][z];
na = v1.subtract(v0).cross(v2.subtract(v0));
v0.x = x * scale.x;
v0.z = z * scale.z;
v0.y = terrain[x][z];
v1.x = x * scale.x;
v1.z = (z - 1) * scale.z;
v1.y = terrain[x][z - 1];
v2.x = (x + 1) * scale.x;
v2.z = z * scale.z;
v2.y = terrain[x + 1][z];
nb = v1.subtract(v0).cross(v2.subtract(v0));
v0.x = x * scale.x;
v0.z = z * scale.z;
v0.y = terrain[x][z];
v1.x = (x + 1) * scale.x;
v1.z = z * scale.z;
v1.y = terrain[x + 1][z];
v2.x = x * scale.x;
v2.z = (z + 1) * scale.z;
v2.y = terrain[x][z + 1];
nc = v1.subtract(v0).cross(v2.subtract(v0));
v0.x = x * scale.x;
v0.z = z * scale.z;
v0.y = terrain[x][z];
v1.x = x * scale.x;
v1.z = (z + 1) * scale.z;
v1.y = terrain[x][z + 1];
v2.x = (x - 1) * scale.x;
v2.z = z * scale.z;
v2.y = terrain[x - 1][z];
nd = v1.subtract(v0).cross(v2.subtract(v0));
// pre-set to 1
normals[x][z].y = 0f;
normals[x][z].add(na);
normals[x][z].add(nb);
normals[x][z].add(nc);
normals[x][z].add(nd);
}
}
SquareTerrain sq = new SquareTerrain(divisions, terrain, normals, temperature, scale.x, scale.z);
float[] vertices = new float[(divisions + 1) * (divisions + 1) * 3];
float[] nors = new float[(divisions + 1) * (divisions + 1) * 3];
float[] colors = new float[(divisions + 1) * (divisions + 1) * 4];
float[] textureCoords = new float[(divisions + 1) * (divisions + 1) * 2];
int[] indices = new int[(divisions) * (divisions) * 6];
int ii = 0;
int nn = 0;
int tt = 0;
int xx = 0;
int cc = 0;
double maxtt = 1f / (divisions + 1);
double xmid = (divisions * scale.x) / 2f;
double zmid = (divisions * scale.z) / 2f;
double percalt = 0;
float r, g, b, a;
a = 1f;
float a_basecolor = (float) ((float) Color.alpha(prs.basecolor) * oneover255);
float a_middlecolor = (float) Color.alpha(prs.middlecolor) * oneover255;
float a_upcolor = (float) Color.alpha(prs.upcolor) * oneover255;
float g_basecolor = (float) Color.green(prs.basecolor) * oneover255;
float g_middlecolor = (float) Color.green(prs.middlecolor) * oneover255;
float g_upcolor = (float) Color.green(prs.upcolor) * oneover255;
float b_basecolor = (float) Color.blue(prs.basecolor) * oneover255;
float b_middlecolor = (float) Color.blue(prs.middlecolor) * oneover255;
float b_upcolor = (float) Color.blue(prs.upcolor) * oneover255;
float r_basecolor = (float) Color.red(prs.basecolor) * oneover255;
float r_middlecolor = (float) Color.red(prs.middlecolor) * oneover255;
float r_upcolor = (float) Color.red(prs.upcolor) * oneover255;
int bmpcolor;
float a_bmp;
float r_bmp;
float g_bmp;
float b_bmp;
for (int i = 0; i <= divisions; ++i) {
for (int j = 0; j <= divisions; ++j) {
vertices[ii++] = (float) (i * scale.x - xmid);
vertices[ii++] = (float) terrain[i][j];
vertices[ii++] = (float) (j * scale.z - zmid);
percalt = sq.getPercAltitude(i, j);
if (percalt < 0.5) {
temp = (percalt - 0.0) * 2;
r = (float) (r_basecolor + (r_middlecolor - r_basecolor) * temp);
g = (float) (g_basecolor + (g_middlecolor - g_basecolor) * temp);
b = (float) (b_basecolor + (b_middlecolor - b_basecolor) * temp);
a = (float) (a_basecolor + (a_middlecolor - a_basecolor) * temp);
} else {
temp = (percalt - 0.5) * 2;
r = (float) (r_middlecolor + (r_upcolor - r_middlecolor) * temp);
g = (float) (g_middlecolor + (g_upcolor - g_middlecolor) * temp);
b = (float) (b_middlecolor + (b_upcolor - b_middlecolor) * temp);
a = (float) (a_middlecolor + (a_upcolor - a_middlecolor) * temp);
}
if (useColorBitmap) {
bmpcolor = colorpixels[i + j * cols];
a_bmp = (float) Color.alpha(bmpcolor) * oneover255;
r_bmp = (float) Color.red(bmpcolor) * oneover255;
g_bmp = (float) Color.green(bmpcolor) * oneover255;
b_bmp = (float) Color.blue(bmpcolor) * oneover255;
r = r * (1f - a_bmp) + a_bmp * r_bmp;
g = g * (1f - a_bmp) + a_bmp * g_bmp;
b = b * (1f - a_bmp) + a_bmp * b_bmp;
}
r = r < 0f ? 0f : r;
r = r > 1f ? 1f : r;
g = g < 0f ? 0f : g;
g = g > 1f ? 1f : g;
b = b < 0f ? 0f : b;
b = b > 1f ? 1f : b;
a = a < 0f ? 0f : a;
a = a > 1f ? 1f : a;
colors[cc++] = r;
colors[cc++] = g;
colors[cc++] = b;
colors[cc++] = a;
normals[i][j].normalize();
nors[nn++] = (float) normals[i][j].x;
nors[nn++] = (float) normals[i][j].y;
nors[nn++] = (float) normals[i][j].z;
textureCoords[tt++] = (float) (i * maxtt * prs.textureMult);
textureCoords[tt++] = (float) (j * maxtt * prs.textureMult);
}
}
for (int i = 0; i < divisions; i += 2) {
for (int j = 0; j < divisions; j += 2) {
// O--O--O--O--O
// |A/|\D| /|\ |
// |/B|C\|/ | \|
// O--O--O--O--O
// |\F|G/|\ | /|
// |E\|/H| \|/ |
// O--O--O--O--O
// A
indices[xx++] = (i) + (j) * cols;
indices[xx++] = (i + 1) + (j) * cols;
indices[xx++] = (i) + (j + 1) * cols;
// B
indices[xx++] = (i + 1) + (j) * cols;
indices[xx++] = (i + 1) + (j + 1) * cols;
indices[xx++] = (i) + (j + 1) * cols;
// C
indices[xx++] = (i + 1) + (j) * cols;
indices[xx++] = (i + 2) + (j + 1) * cols;
indices[xx++] = (i + 1) + (j + 1) * cols;
// D
indices[xx++] = (i + 1) + (j) * cols;
indices[xx++] = (i + 2) + (j) * cols;
indices[xx++] = (i + 2) + (j + 1) * cols;
// E
indices[xx++] = (i) + (j + 1) * cols;
indices[xx++] = (i + 1) + (j + 2) * cols;
indices[xx++] = (i) + (j + 2) * cols;
// F
indices[xx++] = (i) + (j + 1) * cols;
indices[xx++] = (i + 1) + (j + 1) * cols;
indices[xx++] = (i + 1) + (j + 2) * cols;
// G
indices[xx++] = (i + 1) + (j + 1) * cols;
indices[xx++] = (i + 2) + (j + 1) * cols;
indices[xx++] = (i + 1) + (j + 2) * cols;
// H
indices[xx++] = (i + 2) + (j + 1) * cols;
indices[xx++] = (i + 2) + (j + 2) * cols;
indices[xx++] = (i + 1) + (j + 2) * cols;
}
}
sq.setData(vertices, nors, textureCoords, colors, indices, createVBOs);
nors = null;
colors = null;
indices = null;
textureCoords = null;
vertices = null;
return sq;
}
use of android.graphics.PorterDuffXfermode in project Fairphone by Kwamecorp.
the class Cling method init.
void init(Launcher l, int[] positionData) {
if (!mIsInitialized) {
mLauncher = l;
mPositionData = positionData;
Resources r = getContext().getResources();
mPunchThroughGraphic = r.getDrawable(R.drawable.cling);
mPunchThroughGraphicCenterRadius = r.getDimensionPixelSize(R.dimen.clingPunchThroughGraphicCenterRadius);
mAppIconSize = r.getDimensionPixelSize(R.dimen.app_icon_size);
mRevealRadius = r.getDimensionPixelSize(R.dimen.reveal_radius) * 1f;
mButtonBarHeight = r.getDimensionPixelSize(R.dimen.button_bar_height);
mErasePaint = new Paint();
mErasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
mErasePaint.setColor(0xFFFFFF);
mErasePaint.setAlpha(0);
mIsInitialized = true;
}
}
use of android.graphics.PorterDuffXfermode in project remusic by aa112901.
the class RoundImageView method getCroppedRoundBitmap.
public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius, int borde) {
//处理传入的bitmap得到外围有黑色边的圆形bitmap
Bitmap scaledSrcBmp;
int diameter = radius * 2;
// 为了防止宽高不相等,造成圆形图片变形,因此截取长方形中处于中间位置最大的正方形图�?
int bmpWidth = bmp.getWidth();
int bmpHeight = bmp.getHeight();
int squareWidth = 0, squareHeight = 0;
int x = 0, y = 0;
Bitmap squareBitmap;
if (bmpHeight > bmpWidth) {
// 高大于宽
squareWidth = squareHeight = bmpWidth;
x = 0;
y = (bmpHeight - bmpWidth) / 2;
// 截取正方形图�?
squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
} else if (bmpHeight < bmpWidth) {
// 宽大于高
squareWidth = squareHeight = bmpHeight;
x = (bmpWidth - bmpHeight) / 2;
y = 0;
squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
} else {
squareBitmap = bmp;
}
if (squareBitmap.getWidth() != diameter || squareBitmap.getHeight() != diameter) {
scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter, diameter, true);
} else {
scaledSrcBmp = squareBitmap;
}
int width = scaledSrcBmp.getWidth();
int height = scaledSrcBmp.getHeight();
//建立返回的bitmap画布 设置长宽和属性
Bitmap output = Bitmap.createBitmap(width + 30, height + 30, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
Paint bordePaint = new Paint();
//根据图片长宽建立rect
Rect rect = new Rect(0, 0, width, height);
//圆形的画笔
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawARGB(0, 0, 0, 0);
//边界的画笔
bordePaint.setStyle(Paint.Style.STROKE);
bordePaint.setAntiAlias(true);
bordePaint.setColor(Color.BLACK);
bordePaint.setStrokeWidth(borde);
//画外围圆形
canvas.drawCircle(15 + (width / 2), 15 + (height / 2), Math.min(rect.height() / 2, rect.width() / 2), paint);
//设置图片合成用的画笔
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
//画上传入的bitmap
canvas.drawBitmap(scaledSrcBmp, 15 + (width / 2) - rect.width() / 2, 15 + (height / 2) - rect.height() / 2, paint);
//画上外边框
canvas.drawCircle((15 + width / 2), 15 + (height / 2), (width / 2) + 6, bordePaint);
//给圆形图片一个外围的图片
srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.play_disc);
Bitmap bitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), srcBitmap.getConfig());
Paint p = new Paint();
canvas = new Canvas(bitmap);
canvas.drawARGB(0, 0, 0, 0);
p.setAntiAlias(true);
p.setFilterBitmap(true);
p.setDither(true);
//首先绘制第一张图片,很简单,就是和方法中getDstImage一样
canvas.drawBitmap(srcBitmap, 0, 0, p);
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
canvas.drawBitmap(output, (bitmap.getWidth() - output.getWidth()) / 2, (bitmap.getHeight() - output.getHeight()) / 2, null);
return bitmap;
}
use of android.graphics.PorterDuffXfermode in project LikeButton by jd-alexander.
the class CircleView method init.
private void init() {
circlePaint.setStyle(Paint.Style.FILL);
maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
Aggregations