public static Bitmap getTransparentBitmap(View parent) { // create a bitmap if (parent.getWidth() == 0 || parent.getHeight() == 0) { return null; } int width = parent.getWidth(); int height = parent.getHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape()); shapeDrawable.setAlpha(180); shapeDrawable.getPaint().setColor(0x66000000); shapeDrawable.setBounds(0, 0, width, height); shapeDrawable.draw(canvas); return bitmap; }
public void setPosition(int position, float positionOffset, int positionOffsetPixels) { mTouchZonesAccurate = false; int width = getWidth(); int center = width / 2; // Move the view at position. This will be the label for the left // of the two fragments that may be on the screen if (position >= 0 && position < getChildCount()) { TextView view = (TextView) getChildAt(position); int viewWidth = view.getWidth(); int leftMin = 0; if (position + 1 < getChildCount()) { int nextViewWidth = getChildAt(position + 1).getWidth(); leftMin = Math.min(0, center - (nextViewWidth / 2) - mPaddingPush - viewWidth); } int leftMax = center - (viewWidth / 2); int newLeft = map(positionOffset, 1, 0, leftMin, leftMax); view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom()); view.setTextColor( Color.rgb( map(positionOffset, 1, 0, mInactiveTextColor.red, mActiveTextColor.red), map(positionOffset, 1, 0, mInactiveTextColor.green, mActiveTextColor.green), map(positionOffset, 1, 0, mInactiveTextColor.blue, mActiveTextColor.blue))); } // Move the view at position + 1. This will be the label for the // right of the two fragments that may be visible on screen if ((position + 1) < getChildCount()) { TextView view = (TextView) getChildAt(position + 1); int viewWidth = view.getWidth(); int prevViewWidth = getChildAt(position).getWidth(); int leftMin = center - (viewWidth / 2); int leftMax = Math.max(width - viewWidth, center + (prevViewWidth / 2) + mPaddingPush); int newLeft = map(positionOffset, 1, 0, leftMin, leftMax); view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom()); view.setTextColor( Color.rgb( map(positionOffset, 1, 0, mActiveTextColor.red, mInactiveTextColor.red), map(positionOffset, 1, 0, mActiveTextColor.green, mInactiveTextColor.green), map(positionOffset, 1, 0, mActiveTextColor.blue, mInactiveTextColor.blue))); } // Move the view at position - 1. This will be the label for the // fragment that is off the screen to the left, if it exists if (position > 0) { TextView view = (TextView) getChildAt(position - 1); int plusOneLeft = getChildAt(position).getLeft(); int newLeft = view.getLeft(); int viewWidth = view.getWidth(); if (plusOneLeft < newLeft + viewWidth + mPaddingPush || newLeft < 0) { newLeft = Math.min(0, plusOneLeft - viewWidth - mPaddingPush); view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom()); int alpha = map(positionOffset, 1, 0, 0, 255); view.setTextColor(mInactiveTextColor.getColor(alpha)); } } // Move the view at position + 2. This will be the label for the // fragment that is off the screen to the right, if it exists if ((position + 2) < getChildCount()) { TextView view = (TextView) getChildAt(position + 2); int minusOneRight = getChildAt(position + 1).getRight(); int newLeft = view.getLeft(); int viewWidth = view.getWidth(); if (minusOneRight > (newLeft - mPaddingPush) || newLeft + viewWidth > width) { newLeft = Math.max(minusOneRight + mPaddingPush, width - viewWidth); view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom()); int alpha = map(positionOffset, 0, 1, 0, 255); view.setTextColor(mInactiveTextColor.getColor(alpha)); } } // Draw the tab under the active or oncoming TextView based on the // positionOffset View view = getChildAt(positionOffset < 0.5f ? position : position + 1); int viewLeft = view.getLeft(); int viewRight = view.getRight(); float percent = (Math.abs(positionOffset - 0.5f) / 0.5f); int tabHeight = (int) (mTabHeight * percent); int alpha = (int) (255 * percent); mTabDrawable.setBounds( viewLeft - mTabPadding, getHeight() - tabHeight, viewRight + mTabPadding, getHeight()); mTabDrawable.setAlpha(alpha); }
public void setAlpha(float alpha) { this.alpha = alpha; shape.setAlpha((int) ((alpha * 255f) + .5f)); }
public void draw(Canvas canvas) { // This current version draws will draw the icon, and will draw // a colored rectangle around the person's icon if selected super.onDraw(canvas); // Log.v("UserView", "UserView's onDraw()"); int b = Values.iconBorderPadding; int namebox = Values.iconTextH; // the namebox height if (isSelected) { RectShape rect2 = new RectShape(); ShapeDrawable s = new ShapeDrawable(rect2); s.getPaint().setColor(Color.YELLOW); s.setBounds( x - b - Values.selectedBorder, y - b - Values.selectedBorder, x + image.getWidth() + 2 * Values.selectedBorder + b, y + image.getHeight() + 2 * Values.selectedBorder + b + namebox); s.draw(canvas); } /*if(nameBoxImage!=null){ canvas.drawBitmap(nameBoxImage, x, y + Values.userIconH - Values.iconTextH, null); canvas.drawText(person.getUsername(), 0, Math.min(11,(person.getUsername()).length()), x + Values.iconTextPadding, y + Values.userIconH - Values.iconTextPadding, paint); }*/ // Crystal if (person != null) { // Crystal // Log.v(LOG_TAG, "FINAL!"); RectShape rect1 = new RectShape(); ShapeDrawable bord = new ShapeDrawable(rect1); // Log.v(LOG_TAG,"person color"+person.user_color); // bord.getPaint().setStyle(Style.STROKE); // bord.getPaint().setStrokeWidth(b); bord.getPaint().setColor(getResources().getColor(person.user_color)); bord.setAlpha(204); bord.setBounds(x - b, y - b, x + image.getWidth() + b, y + image.getHeight() + b); Log.v(LOG_TAG, "SIZE" + (image.getWidth() + 2 * b) + "" + (image.getHeight() + 2 * b)); // border.setPadding(b,b,b,b); bord.draw(canvas); // Crystal image Bitmap overlay = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(overlay); paint.setAntiAlias(true); paint.setTextSize(Values.nameTextSize); c.drawBitmap(image, 0, 0, null); RectShape nTag = new RectShape(); ShapeDrawable nameTag = new ShapeDrawable(nTag); nameTag.getPaint().setColor(getResources().getColor(person.user_color)); nameTag.setAlpha(204); nameTag.setBounds(0, image.getHeight() - namebox, image.getWidth(), image.getHeight()); nameTag.draw(c); c.drawText( person.getUsername(), 0, Math.min(11, (person.getUsername()).length()), 0 /*Values.iconTextPadding*/, image.getHeight() - namebox + Values.nameTextSize /*5/2*Values.iconBorderPadding+10*/, paint); canvas.drawBitmap(overlay, x, y, null); if (person == space.getOwner()) { Bitmap adminTag = Bitmap.createBitmap(image.getWidth() + 2 * b, 20, Bitmap.Config.ARGB_8888); Canvas ac = new Canvas(adminTag); Paint ad = new Paint(); ad.setColor(Color.rgb(0, 0, 0)); ad.setAlpha(204); ac.drawRect(0, 0, image.getWidth() + 2 * b, 20, ad); ad.setAlpha(255); ad.setColor(Color.WHITE); ad.setStyle(Paint.Style.FILL); ad.setAntiAlias(true); ad.setTextSize(Values.adminTextSize); ac.drawText("admin", Values.textAdjust, (Values.adminBox - Values.textAdjust), ad); canvas.drawBitmap(adminTag, x - b, y - b, null); } } else { canvas.drawBitmap(image, x, y, null); } }