List of usage examples for android.graphics Canvas getHeight
public int getHeight()
From source file:com.android.incallui.CallCardFragment.java
/** * Converts a drawable into a bitmap.//from ww w .j a v a2s.c o m * * @param drawable the drawable to be converted. */ public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap; if (drawable instanceof BitmapDrawable) { bitmap = ((BitmapDrawable) drawable).getBitmap(); } else { if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { // Needed for drawables that are just a colour. bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); } Log.i(TAG, "Created bitmap with width " + bitmap.getWidth() + ", height " + bitmap.getHeight()); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); } return bitmap; }
From source file:net.naonedbus.appwidget.HoraireWidgetProvider.java
/** * Prparer le widget avec les lments fixes (nom, ligne, sens...) *//*from w w w.jav a 2 s . c om*/ protected void prepareWidgetViewInit(final Context context, final RemoteViews views, final Favori favori) { views.setTextViewText(R.id.itemSymbole, favori.getLettre()); // Uniquement pour 2.2 et sup if (Build.VERSION.SDK_INT > 7) { views.setTextColor(R.id.itemSymbole, favori.getCouleurTexte()); views.setTextColor(R.id.itemTitle, favori.getCouleurTexte()); views.setTextColor(R.id.itemDescription, favori.getCouleurTexte()); final GradientDrawable gradientDrawable = ColorUtils.getGradiant(favori.getCouleurBackground()); final Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); gradientDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); gradientDrawable.draw(canvas); views.setImageViewBitmap(R.id.widgetHeaderBackground, bitmap); } if (favori.getNomFavori() == null) { views.setTextViewText(R.id.itemTitle, favori.getNomArret()); views.setTextViewText(R.id.itemDescription, FormatUtils.formatSens(favori.getNomSens())); } else { views.setTextViewText(R.id.itemTitle, favori.getNomArret()); views.setTextViewText(R.id.itemDescription, FormatUtils.formatSens(favori.getNomArret(), favori.getNomSens())); } views.setViewVisibility(R.id.widgetLoading, View.GONE); }
From source file:org.chromium.chrome.browser.widget.MaterialProgressBar.java
private void drawRect(Canvas canvas, Paint paint, float start, float end) { if (ViewCompat.getLayoutDirection(this) == View.LAYOUT_DIRECTION_RTL) { int width = canvas.getWidth(); float rtlStart = width - end; float rtlEnd = width - start; canvas.drawRect(rtlStart, 0, rtlEnd, canvas.getHeight(), paint); } else {/* ww w. j a v a 2s .c om*/ canvas.drawRect(start, 0, end, canvas.getHeight(), paint); } }
From source file:org.totschnig.myexpenses.util.Utils.java
public static Bitmap getTintedBitmapForTheme(Context context, int drawableResId, int themeResId) { Context wrappedContext = new ContextThemeWrapper(context, themeResId); Drawable d = AppCompatDrawableManager.get().getDrawable(wrappedContext, drawableResId); Bitmap b = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); d.setBounds(0, 0, c.getWidth(), c.getHeight()); d.draw(c);//from www . j a va 2 s.c o m return b; }
From source file:com.cocosw.accessory.views.layout.CollapsingTitleLayout.java
@Override public void draw(Canvas canvas) { final int saveCount = canvas.save(); final int toolbarHeight = mToolbar.getHeight(); canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, mScrollOffset)); // Now call super and let it draw the background, etc super.draw(canvas); if (mTitleToDraw != null) { float x = mTextLeft; float y = mTextTop; if (!mUseTexture) { // If we're not drawing a texture, we need to properly offset the text x -= mDrawnTextBounds.left;/*from w w w.jav a2s .co m*/ y -= mDrawnTextBounds.top; } if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mTextLeft, mTextTop, mTextRight, mTextTop + mDrawnTextBounds.height(), DEBUG_DRAW_PAINT); } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (mUseTexture && mExpandedTitleTexture != null) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTitleToDraw, x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:org.gateshipone.odyssey.playbackservice.managers.OdysseyNotificationManager.java
public void updateNotification(TrackModel track, PlaybackService.PLAYSTATE state, MediaSessionCompat.Token mediaSessionToken) { if (track != null) { mNotificationBuilder = new NotificationCompat.Builder(mContext); // Open application intent Intent contentIntent = new Intent(mContext, OdysseyMainActivity.class); contentIntent.putExtra(OdysseyMainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW, OdysseyMainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW_NOWPLAYINGVIEW); contentIntent.addFlags(//from w w w . j av a 2 s .c o m Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_HISTORY); PendingIntent contentPendingIntent = PendingIntent.getActivity(mContext, NOTIFICATION_INTENT_OPENGUI, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); mNotificationBuilder.setContentIntent(contentPendingIntent); // Set pendingintents // Previous song action Intent prevIntent = new Intent(PlaybackService.ACTION_PREVIOUS); PendingIntent prevPendingIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_PREVIOUS, prevIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action prevAction = new NotificationCompat.Action.Builder( R.drawable.ic_skip_previous_48dp, "Previous", prevPendingIntent).build(); // Pause/Play action PendingIntent playPauseIntent; int playPauseIcon; if (state == PlaybackService.PLAYSTATE.PLAYING) { Intent pauseIntent = new Intent(PlaybackService.ACTION_PAUSE); playPauseIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_PLAYPAUSE, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT); playPauseIcon = R.drawable.ic_pause_48dp; } else { Intent playIntent = new Intent(PlaybackService.ACTION_PLAY); playPauseIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_PLAYPAUSE, playIntent, PendingIntent.FLAG_UPDATE_CURRENT); playPauseIcon = R.drawable.ic_play_arrow_48dp; } NotificationCompat.Action playPauseAction = new NotificationCompat.Action.Builder(playPauseIcon, "PlayPause", playPauseIntent).build(); // Next song action Intent nextIntent = new Intent(PlaybackService.ACTION_NEXT); PendingIntent nextPendingIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_NEXT, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action nextAction = new NotificationCompat.Action.Builder( R.drawable.ic_skip_next_48dp, "Next", nextPendingIntent).build(); // Quit action Intent quitIntent = new Intent(PlaybackService.ACTION_QUIT); PendingIntent quitPendingIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_QUIT, quitIntent, PendingIntent.FLAG_UPDATE_CURRENT); mNotificationBuilder.setDeleteIntent(quitPendingIntent); mNotificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); mNotificationBuilder.setSmallIcon(R.drawable.odyssey_notification); mNotificationBuilder.addAction(prevAction); mNotificationBuilder.addAction(playPauseAction); mNotificationBuilder.addAction(nextAction); NotificationCompat.MediaStyle notificationStyle = new NotificationCompat.MediaStyle(); notificationStyle.setShowActionsInCompactView(1, 2); notificationStyle.setMediaSession(mediaSessionToken); mNotificationBuilder.setStyle(notificationStyle); mNotificationBuilder.setContentTitle(track.getTrackName()); mNotificationBuilder.setContentText(track.getTrackArtistName()); // Remove unnecessary time info mNotificationBuilder.setWhen(0); // Cover but only if changed if (mLastTrack == null || !track.getTrackAlbumKey().equals(mLastTrack.getTrackAlbumKey())) { mLastTrack = track; mLastBitmap = null; } // Only set image if an saved one is available if (mLastBitmap != null) { mNotificationBuilder.setLargeIcon(mLastBitmap); } else { /** * Create a dummy placeholder image for versions greater android 7 because it * does not automatically show the application icon anymore in mediastyle notifications. */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Drawable icon = mContext.getDrawable(R.drawable.notification_placeholder_256dp); Bitmap iconBitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(iconBitmap); DrawFilter filter = new PaintFlagsDrawFilter(Paint.ANTI_ALIAS_FLAG, 1); canvas.setDrawFilter(filter); icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); icon.setFilterBitmap(true); icon.draw(canvas); mNotificationBuilder.setLargeIcon(iconBitmap); } else { /** * For older android versions set the null icon which will result in a dummy icon * generated from the application icon. */ mNotificationBuilder.setLargeIcon(null); } } // Build the notification mNotification = mNotificationBuilder.build(); // Check if run from service and check if playing or pause. // Pause notification should be dismissible. if (mContext instanceof Service) { if (state == PlaybackService.PLAYSTATE.PLAYING) { ((Service) mContext).startForeground(NOTIFICATION_ID, mNotification); } else { ((Service) mContext).stopForeground(false); } } // Send the notification away mNotificationManager.notify(NOTIFICATION_ID, mNotification); } }
From source file:com.journeyapps.barcodescanner.WXViewfinderView.java
@SuppressLint("DrawAllocation") @Override/*from w ww .j a v a2 s . c om*/ public void onDraw(Canvas canvas) { refreshSizes(); if (framingRect == null || previewFramingRect == null) { return; } Rect frame = framingRect; Rect previewFrame = previewFramingRect; int width = canvas.getWidth(); int height = canvas.getHeight(); maskPaint.setColor(maskColor); canvas.drawRect(0, 0, width, frame.top, maskPaint); canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, maskPaint); canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, maskPaint); canvas.drawRect(0, frame.bottom + 1, width, height, maskPaint); //drawable the border canvas.drawRect(frame.left + 1, frame.top + 1, frame.right, frame.bottom, borderPaint); int halfWidth = (int) (cornerWidth / 2); //draw four corner Path corner1 = new Path(); corner1.moveTo(frame.left, frame.top + cornerLength); corner1.lineTo(frame.left, frame.top); corner1.lineTo(frame.left + cornerLength, frame.top); Matrix translate1 = new Matrix(); translate1.setTranslate(halfWidth, halfWidth); corner1.transform(translate1); canvas.drawPath(corner1, cornerPaint); Path corner2 = new Path(); corner2.moveTo(frame.right + 1 - cornerLength, frame.top); corner2.lineTo(frame.right + 1, frame.top); corner2.lineTo(frame.right + 1, frame.top + cornerLength); Matrix translate2 = new Matrix(); translate2.setTranslate(-halfWidth, halfWidth); corner2.transform(translate2); canvas.drawPath(corner2, cornerPaint); Path corner3 = new Path(); corner3.moveTo(frame.left, frame.bottom + 1 - cornerLength); corner3.lineTo(frame.left, frame.bottom + 1); corner3.lineTo(frame.left + cornerLength, frame.bottom + 1); Matrix translate3 = new Matrix(); translate3.setTranslate(halfWidth, -halfWidth); corner3.transform(translate3); canvas.drawPath(corner3, cornerPaint); Path corner4 = new Path(); corner4.moveTo(frame.right + 1 - cornerLength, frame.bottom + 1); corner4.lineTo(frame.right + 1, frame.bottom + 1); corner4.lineTo(frame.right + 1, frame.bottom + 1 - cornerLength); Matrix translate4 = new Matrix(); translate4.setTranslate(-halfWidth, -halfWidth); corner4.transform(translate4); canvas.drawPath(corner4, cornerPaint); offset += speed; if (offset >= frame.bottom - frame.top) { offset = 0; } Rect rect = new Rect(); rect.left = frame.left + 1 + laserPadding; rect.top = frame.top + 1 + offset; rect.right = frame.right - laserPadding; rect.bottom = frame.top + 1 + offset + 3; Bitmap laserBitmap = ((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.scan_laser, null)).getBitmap(); canvas.drawBitmap(laserBitmap, null, rect, linePaint); textPaint.setTextAlign(Paint.Align.CENTER); canvas.drawText(statusText, (frame.right + frame.left) / 2, frame.bottom + statusTextPadding + statusTextSize, textPaint); postInvalidateDelayed(animationDelay, frame.left, frame.top, frame.right, frame.bottom); }
From source file:com.forrestguice.suntimeswidget.LightMapView.java
@SuppressWarnings("BooleanMethodIsAlwaysInverted") private boolean drawRect(SuntimesRiseSetData data, Canvas c, Paint p) { Calendar riseTime = data.sunriseCalendarToday(); Calendar setTime = data.sunsetCalendarToday(); if (riseTime == null && setTime == null) { return false; }/*from w w w . j av a2 s . c o m*/ int w = c.getWidth(); int h = c.getHeight(); int left = 0; if (riseTime != null) { double riseMinute = riseTime.get(Calendar.HOUR_OF_DAY) * 60 + riseTime.get(Calendar.MINUTE); double riseR = riseMinute / MINUTES_IN_DAY; left = (int) Math.round(riseR * w); } int right = w; if (setTime != null) { double setMinute = setTime.get(Calendar.HOUR_OF_DAY) * 60 + setTime.get(Calendar.MINUTE); double setR = setMinute / MINUTES_IN_DAY; right = (int) Math.round(setR * w); } boolean setTimeBeforeRiseTime = (riseTime != null && setTime != null && setTime.getTime().before(riseTime.getTime())); if (setTimeBeforeRiseTime) { c.drawRect(0, 0, right, h, p); c.drawRect(left, 0, w, h, p); } else { c.drawRect(left, 0, right, h, p); } return true; }
From source file:com.justwayward.reader.view.RVPIndicator.java
public RVPIndicator(Context context, AttributeSet attrs) { super(context, attrs); // /*from w w w .j a v a 2s.co m*/ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RVPIndicator); mTabVisibleCount = a.getInt(R.styleable.RVPIndicator_item_count, D_TAB_COUNT); mTextColorNormal = a.getColor(R.styleable.RVPIndicator_text_color_normal, D_TEXT_COLOR_NORMAL); mTextColorHighlight = a.getColor(R.styleable.RVPIndicator_text_color_hightlight, D_TEXT_COLOR_HIGHLIGHT); mTextSize = a.getDimensionPixelSize(R.styleable.RVPIndicator_text_size, 16); mIndicatorColor = a.getColor(R.styleable.RVPIndicator_indicator_color, D_INDICATOR_COLOR); mIndicatorStyle = a.getInt(R.styleable.RVPIndicator_indicator_style, STYLE_LINE); Drawable drawable = a.getDrawable(R.styleable.RVPIndicator_indicator_src); if (drawable != null) { if (drawable instanceof BitmapDrawable) { mBitmap = ((BitmapDrawable) drawable).getBitmap(); } else if (drawable instanceof NinePatchDrawable) { // .9? Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); mBitmap = bitmap; } } else { mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.heart_love); } a.recycle(); /** * */ mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(mIndicatorColor); mPaint.setStyle(Style.FILL); }
From source file:com.ameron32.apps.tapnotes._trial.ui.CollapsingTitleLayout.java
@Override public void draw(Canvas canvas) { final int saveCount = canvas.save(); final int toolbarHeight = mToolbar.getHeight(); canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, mScrollOffset)); // Now call super and let it draw the background, etc super.draw(canvas); if (mTitleToDraw != null) { float x = mTextLeft; float y = mTextTop; final float ascent = mTextPaint.ascent() * mScale; final float descent = mTextPaint.descent() * mScale; final float h = descent - ascent; if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mTextLeft, y - h + descent, mTextRight, y + descent, DEBUG_DRAW_PAINT); }/*ww w . j av a 2s.c o m*/ if (mUseTexture) { y = y - h + descent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (mUseTexture && mExpandedTitleTexture != null) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTitleToDraw, x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }