List of usage examples for android.graphics Paint setAlpha
public void setAlpha(int a)
From source file:com.samebits.beacon.locator.ui.view.RadarScanView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int center = getWidth() / 2; int radius = center - 8; // Draw the rings final Paint gridPaint = mGridPaint; canvas.drawCircle(center, center, radius, gridPaint); canvas.drawCircle(center, center, radius * 3 / 4, gridPaint); canvas.drawCircle(center, center, radius >> 1, gridPaint); canvas.drawCircle(center, center, radius >> 2, gridPaint); int blipRadius = (int) (mDistanceRatio * radius); final long now = SystemClock.uptimeMillis(); if (mSweepTime > 0) { // Draw the sweep. Radius is determined by how long ago it started long sweepDifference = now - mSweepTime; if (sweepDifference < 512L) { int sweepRadius = (int) (((radius + 6) * sweepDifference) >> 9); canvas.drawCircle(center, center, sweepRadius, mSweepPaint0); canvas.drawCircle(center, center, sweepRadius - 2, mSweepPaint1); canvas.drawCircle(center, center, sweepRadius - 4, mSweepPaint2); // Note when the sweep has passed the blip boolean before = sweepRadius < blipRadius; if (!before && mSweepBefore) { mSweepBefore = false;/* w w w . j ava 2 s .c om*/ mBlipTime = now; } } else { mSweepTime = now + 1000; mSweepBefore = true; } postInvalidate(); } // Draw horizontal and vertical lines canvas.drawLine(center, center - (radius >> 2) + 6, center, center - radius - 6, gridPaint); canvas.drawLine(center, center + (radius >> 2) - 6, center, center + radius + 6, gridPaint); canvas.drawLine(center - (radius >> 2) + 6, center, center - radius - 6, center, gridPaint); canvas.drawLine(center + (radius >> 2) - 6, center, center + radius + 6, center, gridPaint); // Draw X in the center of the screen canvas.drawLine(center - 4, center - 4, center + 4, center + 4, gridPaint); canvas.drawLine(center - 4, center + 4, center + 4, center - 4, gridPaint); if (mHaveDetected) { // Draw the blip. Alpha is based on how long ago the sweep crossed the blip long blipDifference = now - mBlipTime; gridPaint.setAlpha(255 - (int) ((128 * blipDifference) >> 10)); double bearingToTarget = mLast_bearing; double drawingAngle = Math.toRadians(bearingToTarget) - (Math.PI / 2); float cos = (float) Math.cos(drawingAngle); float sin = (float) Math.sin(drawingAngle); addText(canvas, getRatioDistanceText(0.25f), center, center + (radius >> 2)); addText(canvas, getRatioDistanceText(0.5f), center, center + (radius >> 1)); addText(canvas, getRatioDistanceText(0.75f), center, center + radius * 3 / 4); addText(canvas, getRatioDistanceText(1.0f), center, center + radius); for (Map.Entry<String, DetectedBeacon> entry : mBeacons.entrySet()) { //String key = entry.getKey(); DetectedBeacon dBeacon = entry.getValue(); System.out.println("value: " + dBeacon); // drawing the beacon if (((System.currentTimeMillis() - dBeacon.getTimeLastSeen()) / 1000 < 5)) { canvas.drawBitmap(mBlip, center + (cos * distanceToPix(dBeacon.getDistance())) - 8, center + (sin * distanceToPix(dBeacon.getDistance())) - 8, gridPaint); } } gridPaint.setAlpha(255); } }
From source file:com.eveningoutpost.dexdrip.Home.java
private void setupCharts() { bgGraphBuilder = new BgGraphBuilder(this); updateStuff = false;/*from w w w .j av a 2 s. c o m*/ chart = (LineChartView) findViewById(R.id.chart); if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) { ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) chart.getLayoutParams(); params.topMargin = 130; chart.setLayoutParams(params); } chart.setBackgroundColor(getCol(X.color_home_chart_background)); chart.setZoomType(ZoomType.HORIZONTAL); //Transmitter Battery Level final Sensor sensor = Sensor.currentSensor(); if (sensor != null && sensor.latest_battery_level != 0 && sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_LOW && !prefs.getBoolean("disable_battery_warning", false)) { Drawable background = new Drawable() { @Override public void draw(Canvas canvas) { DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics(); int px = (int) (30 * (metrics.densityDpi / 160f)); Paint paint = new Paint(); paint.setTextSize(px); paint.setAntiAlias(true); paint.setColor(Color.parseColor("#FFFFAA")); paint.setStyle(Paint.Style.STROKE); paint.setAlpha(100); canvas.drawText(getString(R.string.transmitter_battery), 10, chart.getHeight() / 3 - (int) (1.2 * px), paint); if (sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_EMPTY) { paint.setTextSize((int) (px * 1.5)); canvas.drawText(getString(R.string.very_low), 10, chart.getHeight() / 3, paint); } else { canvas.drawText(getString(R.string.low), 10, chart.getHeight() / 3, paint); } } @Override public void setAlpha(int alpha) { } @Override public void setColorFilter(ColorFilter cf) { } @Override public int getOpacity() { return 0; // TODO Which pixel format should this be? } }; chart.setBackground(background); } previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview); chart.setLineChartData(bgGraphBuilder.lineData()); chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener(mActivity)); previewChart.setBackgroundColor(getCol(X.color_home_chart_background)); previewChart.setZoomType(ZoomType.HORIZONTAL); previewChart.setLineChartData(bgGraphBuilder.previewLineData(chart.getLineChartData())); updateStuff = true; previewChart.setViewportCalculationEnabled(true); chart.setViewportCalculationEnabled(true); previewChart.setViewportChangeListener(new ViewportListener()); chart.setViewportChangeListener(new ChartViewPortListener()); setViewport(); if (small_height) { previewChart.setVisibility(View.GONE); // quick test Viewport moveViewPort = new Viewport(chart.getMaximumViewport()); float tempwidth = (float) moveViewPort.width() / 4; holdViewport.left = moveViewPort.right - tempwidth; holdViewport.right = moveViewPort.right + (moveViewPort.width() / 24); holdViewport.top = moveViewPort.top; holdViewport.bottom = moveViewPort.bottom; chart.setCurrentViewport(holdViewport); previewChart.setCurrentViewport(holdViewport); } else { previewChart.setVisibility(View.VISIBLE); } if (insulinset || glucoseset || carbsset || timeset) { if (chart != null) { chart.setAlpha((float) 0.10); // TODO also set buttons alpha } } }
From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
private void doDraw(Canvas canvas) { Paint p = mPaint; Rect r = mRect;/* w w w . j a v a 2s. c om*/ if (mFutureBgColor != 0) { drawBgColors(r, canvas, p); } drawGridBackground(r, canvas, p); drawHours(r, canvas, p); // Draw each day int cell = mFirstJulianDay; p.setAntiAlias(false); int alpha = p.getAlpha(); p.setAlpha(mEventsAlpha); for (int day = 0; day < mNumDays; day++, cell++) { // events on every call. drawEvents(cell, day, HOUR_GAP, canvas, p); // If this is today if (cell == mTodayJulianDay) { int lineY = mCurrentTime.hour * (mCellHeight + HOUR_GAP) + ((mCurrentTime.minute * mCellHeight) / 60) + 1; // And the current time shows up somewhere on the screen if (lineY >= mViewStartY && lineY < mViewStartY + mViewHeight - 2) { drawCurrentTimeLine(r, day, lineY, canvas, p); } } } p.setAntiAlias(true); p.setAlpha(alpha); // drawSelectedRect(r, canvas, p); }
From source file:com.marlonjones.voidlauncher.CellLayout.java
@Override protected void onDraw(Canvas canvas) { if (!mIsDragTarget) { return;//from w w w . ja v a2s. c o m } // When we're large, we are either drawn in a "hover" state (ie when dragging an item to // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f) // When we're small, we are either drawn normally or in the "accepts drops" state (during // a drag). However, we also drag the mini hover background *over* one of those two // backgrounds if (mBackgroundAlpha > 0.0f) { mBackground.draw(canvas); } final Paint paint = mDragOutlinePaint; for (int i = 0; i < mDragOutlines.length; i++) { final float alpha = mDragOutlineAlphas[i]; if (alpha > 0) { final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag(); paint.setAlpha((int) (alpha + .5f)); canvas.drawBitmap(b, null, mDragOutlines[i], paint); } } if (DEBUG_VISUALIZE_OCCUPIED) { int[] pt = new int[2]; ColorDrawable cd = new ColorDrawable(Color.RED); cd.setBounds(0, 0, mCellWidth, mCellHeight); for (int i = 0; i < mCountX; i++) { for (int j = 0; j < mCountY; j++) { if (mOccupied.cells[i][j]) { cellToPoint(i, j, pt); canvas.save(); canvas.translate(pt[0], pt[1]); cd.draw(canvas); canvas.restore(); } } } } for (int i = 0; i < mFolderBackgrounds.size(); i++) { FolderIcon.PreviewBackground bg = mFolderBackgrounds.get(i); cellToPoint(bg.delegateCellX, bg.delegateCellY, mTempLocation); canvas.save(); canvas.translate(mTempLocation[0], mTempLocation[1]); bg.drawBackground(canvas, mFolderBgPaint); if (!bg.isClipping) { bg.drawBackgroundStroke(canvas, mFolderBgPaint); } canvas.restore(); } if (mFolderLeaveBehind.delegateCellX >= 0 && mFolderLeaveBehind.delegateCellY >= 0) { cellToPoint(mFolderLeaveBehind.delegateCellX, mFolderLeaveBehind.delegateCellY, mTempLocation); canvas.save(); canvas.translate(mTempLocation[0], mTempLocation[1]); mFolderLeaveBehind.drawLeaveBehind(canvas, mFolderBgPaint); canvas.restore(); } }
From source file:com.codemx.launcher3.CellLayout.java
@Override protected void onDraw(Canvas canvas) { if (!mIsDragTarget) { return;//from ww w . j a v a 2 s . co m } // When we're large, we are either drawn in a "hover" state (ie when dragging an item to // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f) // When we're small, we are either drawn normally or in the "accepts drops" state (during // a drag). However, we also drag the mini hover background *over* one of those two // backgrounds if (mBackgroundAlpha > 0.0f) { mBackground.draw(canvas); } final Paint paint = mDragOutlinePaint; for (int i = 0; i < mDragOutlines.length; i++) { final float alpha = mDragOutlineAlphas[i]; if (alpha > 0) { final Rect r = mDragOutlines[i]; mTempRect.set(r); Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale()); final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag(); paint.setAlpha((int) (alpha + .5f)); canvas.drawBitmap(b, null, mTempRect, paint); } } if (DEBUG_VISUALIZE_OCCUPIED) { int[] pt = new int[2]; ColorDrawable cd = new ColorDrawable(Color.RED); cd.setBounds(0, 0, mCellWidth, mCellHeight); for (int i = 0; i < mCountX; i++) { for (int j = 0; j < mCountY; j++) { if (mOccupied[i][j]) { cellToPoint(i, j, pt); canvas.save(); canvas.translate(pt[0], pt[1]); cd.draw(canvas); canvas.restore(); } } } } int previewOffset = FolderIcon.FolderRingAnimator.sPreviewSize; // The folder outer / inner ring image(s) DeviceProfile grid = mLauncher.getDeviceProfile(); for (int i = 0; i < mFolderOuterRings.size(); i++) { FolderIcon.FolderRingAnimator fra = mFolderOuterRings.get(i); Drawable d; int width, height; cellToPoint(fra.mCellX, fra.mCellY, mTempLocation); View child = getChildAt(fra.mCellX, fra.mCellY); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; // Draw outer ring, if it exists if (FolderIcon.HAS_OUTER_RING) { d = FolderIcon.FolderRingAnimator.sSharedOuterRingDrawable; width = (int) (fra.getOuterRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - height / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } // Draw inner ring d = FolderIcon.FolderRingAnimator.sSharedInnerRingDrawable; width = (int) (fra.getInnerRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) { Drawable d = FolderIcon.sSharedFolderLeaveBehind; int width = d.getIntrinsicWidth(); int height = d.getIntrinsicHeight(); cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation); View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } }
From source file:com.lite.android.launcher3.CellLayout.java
@Override protected void onDraw(Canvas canvas) { if (!mIsDragTarget) { return;//from w ww .j av a2 s . c o m } // When we're large, we are either drawn in a "hover" state (ie when dragging an item to // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f) // When we're small, we are either drawn normally or in the "accepts drops" state (during // a drag). However, we also drag the mini hover background *over* one of those two // backgrounds if (mBackgroundAlpha > 0.0f) { mBackground.draw(canvas); } final Paint paint = mDragOutlinePaint; for (int i = 0; i < mDragOutlines.length; i++) { final float alpha = mDragOutlineAlphas[i]; if (alpha > 0) { final Rect r = mDragOutlines[i]; mTempRect.set(r); Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale()); final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag(); paint.setAlpha((int) (alpha + .5f)); canvas.drawBitmap(b, null, mTempRect, paint); } } if (DEBUG_VISUALIZE_OCCUPIED) { int[] pt = new int[2]; ColorDrawable cd = new ColorDrawable(Color.RED); cd.setBounds(0, 0, mCellWidth, mCellHeight); for (int i = 0; i < mCountX; i++) { for (int j = 0; j < mCountY; j++) { if (mOccupied[i][j]) { cellToPoint(i, j, pt); canvas.save(); canvas.translate(pt[0], pt[1]); cd.draw(canvas); canvas.restore(); } } } } int previewOffset = FolderRingAnimator.sPreviewSize; // The folder outer / inner ring image(s) DeviceProfile grid = mLauncher.getDeviceProfile(); for (int i = 0; i < mFolderOuterRings.size(); i++) { FolderRingAnimator fra = mFolderOuterRings.get(i); Drawable d; int width, height; cellToPoint(fra.mCellX, fra.mCellY, mTempLocation); View child = getChildAt(fra.mCellX, fra.mCellY); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; // Draw outer ring, if it exists if (FolderIcon.HAS_OUTER_RING) { d = FolderRingAnimator.sSharedOuterRingDrawable; width = (int) (fra.getOuterRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - height / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } // Draw inner ring d = FolderRingAnimator.sSharedInnerRingDrawable; if (d != null) { width = (int) (fra.getInnerRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } } if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) { Drawable d = FolderIcon.sSharedFolderLeaveBehind; int width = d.getIntrinsicWidth(); int height = d.getIntrinsicHeight(); cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation); View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } }
From source file:com.android.leanlauncher.CellLayout.java
@Override protected void onDraw(Canvas canvas) { // When we're large, we are either drawn in a "hover" state (ie when dragging an item to // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f) // When we're small, we are either drawn normally or in the "accepts drops" state (during // a drag). However, we also drag the mini hover background *over* one of those two // backgrounds if (mDrawBackground && mBackgroundAlpha > 0.0f) { Drawable bg;// w ww .j a va 2 s . co m if (mUseActiveGlowBackground) { // In the mini case, we draw the active_glow bg *over* the active background bg = mActiveGlowBackground; } else { bg = mNormalBackground; } bg.setAlpha((int) (mBackgroundAlpha * mBackgroundAlphaMultiplier * 255)); bg.setBounds(mBackgroundRect); bg.draw(canvas); } final Paint paint = mDragOutlinePaint; for (int i = 0; i < mDragOutlines.length; i++) { final float alpha = mDragOutlineAlphas[i]; if (alpha > 0) { final Rect r = mDragOutlines[i]; mTempRect.set(r); Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale()); final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag(); paint.setAlpha((int) (alpha + .5f)); canvas.drawBitmap(b, null, mTempRect, paint); } } }
From source file:com.android.launcher3.CellLayout.java
@Override protected void onDraw(Canvas canvas) { if (!mIsDragTarget) { return;/* w ww . ja va2 s. c o m*/ } // When we're large, we are either drawn in a "hover" state (ie when dragging an item to // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f) // When we're small, we are either drawn normally or in the "accepts drops" state (during // a drag). However, we also drag the mini hover background *over* one of those two // backgrounds if (mBackgroundAlpha > 0.0f) { mBackground.draw(canvas); } final Paint paint = mDragOutlinePaint; for (int i = 0; i < mDragOutlines.length; i++) { final float alpha = mDragOutlineAlphas[i]; if (alpha > 0) { final Rect r = mDragOutlines[i]; mTempRect.set(r); Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale()); final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag(); paint.setAlpha((int) (alpha + .5f)); canvas.drawBitmap(b, null, mTempRect, paint); } } if (DEBUG_VISUALIZE_OCCUPIED) { int[] pt = new int[2]; ColorDrawable cd = new ColorDrawable(Color.RED); cd.setBounds(0, 0, mCellWidth, mCellHeight); for (int i = 0; i < mCountX; i++) { for (int j = 0; j < mCountY; j++) { if (mOccupied[i][j]) { cellToPoint(i, j, pt); canvas.save(); canvas.translate(pt[0], pt[1]); cd.draw(canvas); canvas.restore(); } } } } int previewOffset = FolderRingAnimator.sPreviewSize; // The folder outer / inner ring image(s) DeviceProfile grid = mLauncher.getDeviceProfile(); for (int i = 0; i < mFolderOuterRings.size(); i++) { FolderRingAnimator fra = mFolderOuterRings.get(i); Drawable d; int width, height; cellToPoint(fra.mCellX, fra.mCellY, mTempLocation); View child = getChildAt(fra.mCellX, fra.mCellY); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; // Draw outer ring, if it exists if (FolderIcon.HAS_OUTER_RING) { d = FolderRingAnimator.sSharedOuterRingDrawable; width = (int) (fra.getOuterRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - height / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } // Draw inner ring d = FolderRingAnimator.sSharedInnerRingDrawable; width = (int) (fra.getInnerRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) { Drawable d = FolderIcon.sSharedFolderLeaveBehind; int width = d.getIntrinsicWidth(); int height = d.getIntrinsicHeight(); cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation); View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } }
From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
private void drawEvents(int date, int dayIndex, int top, Canvas canvas, Paint p) { Paint eventTextPaint = mEventTextPaint; int left = computeDayLeftPosition(dayIndex) + 1; int cellWidth = computeDayLeftPosition(dayIndex + 1) - left + 1; int cellHeight = mCellHeight; // Use the selected hour as the selection region Rect selectionArea = mSelectionRect; selectionArea.top = top + mSelectionHour * (cellHeight + HOUR_GAP); selectionArea.bottom = selectionArea.top + cellHeight; selectionArea.left = left;/*from w w w .j a v a2s. co m*/ selectionArea.right = selectionArea.left + cellWidth; final ArrayList<Event> events = mEvents; int numEvents = events.size(); EventGeometry geometry = mEventGeometry; final int viewEndY = mViewStartY + mViewHeight - DAY_HEADER_HEIGHT; int alpha = eventTextPaint.getAlpha(); eventTextPaint.setAlpha(mEventsAlpha); for (int i = 0; i < numEvents; i++) { Event event = events.get(i); if (!geometry.computeEventRect(date, left, top, cellWidth, event)) { continue; } // Don't draw it if it is not visible if (event.bottom < mViewStartY || event.top > viewEndY) { continue; } if (date == mSelectionDay && mComputeSelectedEvents && geometry.eventIntersectsSelection(event, selectionArea)) { mSelectedEvents.add(event); } Rect r = drawEventRect(event, canvas, p, eventTextPaint, mViewStartY, viewEndY); setupTextRect(r); // Don't draw text if it is not visible if (r.top > viewEndY || r.bottom < mViewStartY) { continue; } StaticLayout layout = getEventLayout(mLayouts, i, event, eventTextPaint, r); drawEventText(layout, r, canvas, mViewStartY + 4, mViewStartY + mViewHeight - DAY_HEADER_HEIGHT, false); } eventTextPaint.setAlpha(alpha); }
From source file:t3.giftbook.util.FlipViewPager.java
/** * ??//from w ww . ja v a 2 s. c o m */ private void drawFlippingPage(Canvas canvas) { if (mOffset == 0) { //?????????????Flip?????(draw??) return; } int scrollX = this.getScrollX(); if (currentPageBmp == null || currentPageBmp.isRecycled() || nextPageBmp.isRecycled()) { currentPageBmp = prepareBmp(canvas); currentPageCnv = new Canvas(currentPageBmp); nextPageBmp = prepareBmp(canvas); nextPageCnv = new Canvas(nextPageBmp); } if (currentPageBmp != null) { final int currentPage = mPosition; final int nextPage = currentPage + 1; if (currentPageCnv != null) { if (lastDrawedPage != currentPage) { try { //mPosition????????bounds???? //1???mOffset??????return. //???????????mPosition??????? final long time = System.currentTimeMillis(); drawChildTo(currentPageCnv, currentPage, time); drawChildTo(nextPageCnv, nextPage, time); //??currentPageBmp, nextPageBmp???????????? lastDrawedPage = currentPage; } catch (IllegalArgumentException e) { Log.w(TAG, e); } } } /* * canvas????????????? * ??????????? * ????????????? */ //? final Rect screenLeftSide = new Rect(scrollX, 0, scrollX + this.getWidth() / 2, this.getHeight()); //?? final Rect screenRightSide = new Rect(scrollX + this.getWidth() / 2, 0, scrollX + this.getWidth() / 1, this.getHeight()); //bmp? final Rect pageLeftSide = new Rect((int) (this.getWidth() * 0.0f), 0, (int) (this.getWidth() * 0.5f), this.getHeight()); //bmp?? final Rect pageRightSide = new Rect((int) (this.getWidth() * 0.5f), 0, (int) (this.getWidth() * 1.0f), this.getHeight()); /* * ???Flip?? */ //? Paint white = new Paint() { { this.setColor(Color.WHITE); } }; canvas.drawRect(screenLeftSide, white); canvas.drawRect(screenRightSide, white); //??????? canvas.drawBitmap(currentPageBmp, pageLeftSide, screenLeftSide, new Paint()); //???????? canvas.drawBitmap(nextPageBmp, pageRightSide, screenRightSide, new Paint()); // Paint shadow = new Paint() { { this.setColor(Color.BLACK); } }; final int meshCols = 30; final float meshColsf = (float) meshCols; final int meshRows = 30; final float meshRowsf = (float) meshRows; //?????????? if (mOffset <= 0.5) { final float offsetRate = (0.5f - mOffset) * 2; final float invOffsetRate = 1f - offsetRate; //??? shadow.setAlpha((int) (90 * offsetRate)); canvas.drawRect(screenRightSide, shadow); //??????????? final float[] rVerts = new float[(meshCols + 1) * (meshRows + 1) * 2]; for (int meshY = 0; meshY <= meshRows; meshY++) { final float meshYf = (float) meshY; for (int meshX = 0; meshX <= meshCols; meshX++) { final float meshXf = (float) meshX; final int meshPosition = (meshX + meshY * (meshCols + 1)) * 2; final int xPosition = meshPosition; final int yPosition = xPosition + 1; if (meshX <= meshCols / 2) { rVerts[xPosition] = screenRightSide.left; //?????????? rVerts[yPosition] = screenRightSide.top + screenRightSide.height() / meshRowsf * meshYf; } else { rVerts[xPosition] = screenRightSide.left + offsetRate * screenRightSide.width() / meshColsf * (meshXf - meshColsf / 2f) * 2f; rVerts[yPosition] = screenRightSide.top + screenRightSide.height() / 2f - screenRightSide.height() / meshRowsf * (meshRowsf / 2f - meshYf) * (1f + invOffsetRate / meshColsf * (meshXf - meshColsf / 2f)); } } } canvas.drawBitmapMesh(currentPageBmp, meshCols, meshRows, rVerts, 0, null, 0, null); //???? final Paint pageRootPaint = new Paint() { { int shadow1 = Color.argb((int) (30 * invOffsetRate), 0, 0, 0); int shadow2 = Color.argb(0, 0, 0, 0); this.setShader(new LinearGradient((float) screenRightSide.left, (float) screenRightSide.top + screenRightSide.height() / 2, (float) screenRightSide.left + screenRightSide.width() * offsetRate, (float) screenRightSide.top + screenRightSide.height() / 2, shadow1, shadow2, Shader.TileMode.CLAMP)); } }; canvas.drawRect(screenRightSide.left, screenRightSide.top, screenRightSide.right, screenRightSide.bottom, pageRootPaint); } else { final float offsetRate = (mOffset - 0.5f) * 2; final float invOffsetRate = 1f - offsetRate; //?? shadow.setAlpha((int) (90 * offsetRate)); canvas.drawRect(screenLeftSide, shadow); //???????? final float[] rVerts = new float[(meshCols + 1) * (meshRows + 1) * 2]; for (int meshY = 0; meshY <= meshRows; meshY++) { final float meshYf = (float) meshY; for (int meshX = 0; meshX <= meshCols; meshX++) { final float meshXf = (float) meshX; final float meshXfInv = meshColsf / 2f - meshXf; final int meshPosition = (meshX + meshY * (meshCols + 1)) * 2; final int xPosition = meshPosition; final int yPosition = xPosition + 1; if (meshX >= meshCols / 2) { rVerts[xPosition] = screenLeftSide.right; //??????????? rVerts[yPosition] = screenLeftSide.top + screenLeftSide.height() / meshRowsf * meshYf; } else { rVerts[xPosition] = screenLeftSide.right - offsetRate * screenLeftSide.width() + offsetRate * screenLeftSide.width() / meshColsf * (meshXf) * 2f; rVerts[yPosition] = screenLeftSide.top + screenLeftSide.height() / 2f - screenLeftSide.height() / meshRowsf * (meshRowsf / 2f - meshYf) * (1f + invOffsetRate / meshColsf * (meshColsf / 2f - meshXf)); } } } canvas.drawBitmapMesh(nextPageBmp, meshCols, meshRows, rVerts, 0, null, 0, null); //??? final Paint pageRootPaint = new Paint() { { int shadow2 = Color.argb((int) (30 * invOffsetRate), 0, 0, 0); int shadow1 = Color.argb(0, 0, 0, 0); this.setShader(new LinearGradient( (float) screenLeftSide.right - screenRightSide.width() * offsetRate, (float) screenLeftSide.top + screenRightSide.height() / 2, (float) screenLeftSide.right, (float) screenLeftSide.top + screenRightSide.height() / 2, shadow1, shadow2, Shader.TileMode.CLAMP)); } }; canvas.drawRect(screenLeftSide.left, screenLeftSide.top, screenLeftSide.right, screenLeftSide.bottom, pageRootPaint); } // int y = 0; // canvas.drawRect(0,0,canvas.getWidth(), 300, new Paint() {{this.setColor(Color.WHITE); this.setAlpha(100);}}); // Paint debugPrint = new Paint() {{this.setColor(Color.RED); this.setTextSize(30);}}; // canvas.drawText("b.width = " + bkbmp.getWidth() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("b.height = " + bkbmp.getHeight() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("c.width = " + canvas.getWidth() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("c.height = " + canvas.getHeight() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("scrollX = " + getScrollX() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("mPosition = " + mPosition , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("lastPosition = " + lastDrawedPage , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("mOffset = " + mOffset , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("offsetRate = " + offsetRate , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("invOffsetRate = " + invOffsetRate , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("mOffsetPixels = " + mOffsetPixels , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("index = " + getCurrentItem() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); } }