Java Code Examples for android.graphics.Canvas

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/view/overlay/.

Source file: BufferingOverlay.java

  18 
vote

public void update(UpdateData updateData){
  Canvas canvas=null;
  Projection projectionToUse=null;
synchronized (this) {
    if (bitmap != null) {
      canvas=new Canvas(bitmap);
      projectionToUse=this.projection;
    }
  }
  if (canvas != null) {
    performUpdate(canvas,projectionToUse,updateData);
  }
}
 

Example 2

From project Airports, under directory /src/com/nadmm/airports/utils/.

Source file: UiUtils.java

  18 
vote

public static Drawable getRotatedDrawable(Context context,int resid,float rotation){
  Resources res=context.getResources();
  Bitmap bmp=BitmapFactory.decodeResource(res,resid);
  Bitmap rotated=Bitmap.createBitmap(bmp.getWidth(),bmp.getHeight(),Bitmap.Config.ARGB_8888);
  Canvas canvas=new Canvas(rotated);
  canvas.setDensity(Bitmap.DENSITY_NONE);
  canvas.rotate(rotation,bmp.getWidth() / 2,bmp.getHeight() / 2);
  canvas.drawBitmap(bmp,0,0,sPaint);
  return new BitmapDrawable(res,rotated);
}
 

Example 3

From project android-ocr, under directory /android/src/edu/sfsu/cs/orange/ocr/.

Source file: OcrResult.java

  18 
vote

private Bitmap getAnnotatedBitmap(){
  Canvas canvas=new Canvas(bitmap);
  for (int i=0; i < wordBoundingBoxes.size(); i++) {
    paint.setAlpha(0xFF);
    paint.setColor(0xFF00CCFF);
    paint.setStyle(Style.STROKE);
    paint.setStrokeWidth(2);
    Rect r=wordBoundingBoxes.get(i);
    canvas.drawRect(r,paint);
  }
  return bitmap;
}
 

Example 4

From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/internal/widget/.

Source file: ActionBarContainer.java

  17 
vote

public ActionBarContainer(Context context,AttributeSet attrs){
  super(context,attrs);
  setBackgroundDrawable(null);
  TypedArray a=context.obtainStyledAttributes(attrs,R.styleable.SherlockActionBar);
  mBackground=a.getDrawable(R.styleable.SherlockActionBar_background);
  mStackedBackground=a.getDrawable(R.styleable.SherlockActionBar_backgroundStacked);
  if (mStackedBackground instanceof ColorDrawable && Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
    Bitmap bitmap=Bitmap.createBitmap(1,1,Bitmap.Config.ARGB_8888);
    Canvas c=new Canvas(bitmap);
    mStackedBackground.draw(c);
    int color=bitmap.getPixel(0,0);
    bitmap.recycle();
    mStackedBackground=new IcsColorDrawable(color);
  }
  if (getId() == R.id.abs__split_action_bar) {
    mIsSplit=true;
    mSplitBackground=a.getDrawable(R.styleable.SherlockActionBar_backgroundSplit);
  }
  a.recycle();
  setWillNotDraw(mIsSplit ? mSplitBackground == null : mBackground == null && mStackedBackground == null);
}
 

Example 5

From project Alerte-voirie-android, under directory /src/com/fabernovel/alertevoirie/entities/.

Source file: PictoView.java

  17 
vote

/** 
 * Method to link a photo to this arrow, giving the photo position on arrow layout
 * @param picture
 * @param x
 * @param y
 * @throws FileNotFoundException
 */
public Bitmap setSupport(Bitmap picture,float targetx,float targety,Context c) throws FileNotFoundException {
  Bitmap arrow=((BitmapDrawable)this.getDrawable()).getBitmap();
  float coeffx=targetx / getWidth();
  float coeffy=targety / getHeight();
  int scaledOffsetX=(int)(offsetx * coeffx);
  int scaledOffsetY=(int)(offsety * coeffy);
  Matrix matrix=new Matrix();
  matrix.postRotate(degree,(arrow.getWidth() / 2),(arrow.getHeight() / 2));
  arrow=Bitmap.createBitmap(arrow,0,0,arrow.getWidth(),arrow.getHeight(),matrix,true);
  Bitmap b=picture.copy(picture.getConfig(),true);
  Canvas myCanvas=new Canvas(b);
  myCanvas.drawBitmap(arrow,(b.getWidth() - arrow.getWidth()) / 2 + scaledOffsetX,(b.getHeight() - arrow.getHeight()) / 2 + scaledOffsetY,new Paint());
  b.compress(CompressFormat.JPEG,80,c.openFileOutput("arrowed.jpg",Context.MODE_PRIVATE));
  return b;
}
 

Example 6

From project Android, under directory /app/src/main/java/com/github/mobile/util/.

Source file: ImageUtils.java

  17 
vote

/** 
 * Round the corners of a  {@link Bitmap}
 * @param source
 * @param radius
 * @return rounded corner bitmap
 */
public static Bitmap roundCorners(final Bitmap source,final float radius){
  int width=source.getWidth();
  int height=source.getHeight();
  Paint paint=new Paint();
  paint.setAntiAlias(true);
  paint.setColor(WHITE);
  Bitmap clipped=Bitmap.createBitmap(width,height,ARGB_8888);
  Canvas canvas=new Canvas(clipped);
  canvas.drawRoundRect(new RectF(0,0,width,height),radius,radius,paint);
  paint.setXfermode(new PorterDuffXfermode(DST_IN));
  Bitmap rounded=Bitmap.createBitmap(width,height,ARGB_8888);
  canvas=new Canvas(rounded);
  canvas.drawBitmap(source,0,0,null);
  canvas.drawBitmap(clipped,0,0,paint);
  source.recycle();
  clipped.recycle();
  return rounded;
}
 

Example 7

From project android-bankdroid, under directory /src/com/liato/bankdroid/.

Source file: LockableActivity.java

  17 
vote

@Override public boolean onCreateThumbnail(Bitmap outBitmap,Canvas canvas){
  View decorview=getWindow().getDecorView();
  if (decorview == null) {
    return true;
  }
  final int vw=decorview.getWidth();
  final int vh=decorview.getHeight();
  final int dw=outBitmap.getWidth();
  final int dh=outBitmap.getHeight();
  Bitmap bluredBitmap=Bitmap.createBitmap(outBitmap.getWidth(),outBitmap.getHeight(),outBitmap.getConfig());
  Canvas c=new Canvas(bluredBitmap);
  c.save();
  c.scale(((float)dw) / vw,((float)dh) / vh);
  decorview.draw(c);
  c.restore();
  canvas.drawBitmap(pixelate(bluredBitmap,5),0,0,null);
  Bitmap lockbitmap=BitmapFactory.decodeResource(getResources(),R.drawable.lock);
  Paint p=new Paint();
  p.setAntiAlias(true);
  p.setDither(true);
  p.setFilterBitmap(true);
  canvas.drawBitmap(lockbitmap,null,new RectF(dw * 0.25f,dh * 0.25f,dw * 0.75f,dh * 0.75f),p);
  return true;
}
 

Example 8

From project android-joedayz, under directory /Proyectos/GreenDroid/src/greendroid/image/.

Source file: MaskImageProcessor.java

  17 
vote

public Bitmap processImage(Bitmap bitmap){
  if (bitmap == null) {
    return null;
  }
  final int width=bitmap.getWidth();
  final int height=bitmap.getHeight();
  mRect.set(0,0,width,height);
  Bitmap result=Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
  Canvas canvas=new Canvas(result);
switch (mShape) {
case CUSTOM:
    canvas.drawBitmap(mMaskBitmap,0,0,mFillPaint);
  break;
case RECTANGLE:
default :
if (mRadiiArray != null) {
  mPath.reset();
  mPath.addRoundRect(mRect,mRadiiArray,Path.Direction.CW);
  canvas.drawPath(mPath,mFillPaint);
}
 else {
  float rad=mRadius;
  float r=Math.min(width,height) * 0.5f;
  if (rad > r) {
    rad=r;
  }
  canvas.drawRoundRect(mRect,rad,rad,mFillPaint);
}
break;
}
canvas.drawBitmap(bitmap,0,0,mMaskPaint);
return result;
}
 

Example 9

From project Android-MapForgeFragment, under directory /library-common/src/com/jakewharton/android/mapsforge_fragment/.

Source file: Overlay.java

  17 
vote

/** 
 * Default constructor which must be called by all subclasses.
 */
protected Overlay(){
  super();
  this.overlayCanvas=new Canvas();
  this.matrix=new Matrix();
  this.point=new Point();
  this.positionBeforeDraw=new Point();
  this.positionAfterDraw=new Point();
}
 

Example 10

From project android-thaiime, under directory /latinime/src/com/android/inputmethod/deprecated/voice/.

Source file: SoundIndicator.java

  17 
vote

public SoundIndicator(Context context,AttributeSet attrs){
  super(context,attrs);
  mFrontDrawable=getDrawable();
  BitmapDrawable edgeDrawable=(BitmapDrawable)context.getResources().getDrawable(R.drawable.vs_popup_mic_edge);
  mEdgeBitmap=edgeDrawable.getBitmap();
  mEdgeBitmapOffset=mEdgeBitmap.getHeight() / 2;
  mDrawingBuffer=Bitmap.createBitmap(mFrontDrawable.getIntrinsicWidth(),mFrontDrawable.getIntrinsicHeight(),Config.ARGB_8888);
  mBufferCanvas=new Canvas(mDrawingBuffer);
  mClearPaint=new Paint();
  mClearPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
  mMultPaint=new Paint();
  mMultPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
  mHandler=new Handler();
}
 

Example 11

From project android-voip-service, under directory /src/main/java/org/linphone/core/.

Source file: AndroidVideoWindowImpl.java

  17 
vote

public synchronized void update(){
  if (mSurface != null) {
    try {
      Canvas canvas=mSurface.lockCanvas(null);
      canvas.drawBitmap(mBitmap,0,0,null);
      mSurface.unlockCanvasAndPost(canvas);
    }
 catch (    IllegalArgumentException e) {
      e.printStackTrace();
    }
catch (    OutOfResourcesException e) {
      e.printStackTrace();
    }
  }
}
 

Example 12

From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/util/.

Source file: ImageUtilities.java

  17 
vote

/** 
 * Create a book cover with the specified bitmap. This method applies several lighting effects to the original bitmap and returns a new decored bitmap.
 * @param bitmap The bitmap to decor with lighting effects
 * @param width The target width of the decored bitmap
 * @param height The target height of the decored bitmap
 * @return A new Bitmap based on the original bitmap
 */
public static Bitmap createBookCover(Bitmap bitmap,int width,int height){
  final int bitmapWidth=bitmap.getWidth();
  final int bitmapHeight=bitmap.getHeight();
  final float scale=Math.min((float)width / (float)bitmapWidth,(float)height / (float)bitmapHeight);
  final int scaledWidth=(int)(bitmapWidth * scale);
  final int scaledHeight=(int)(bitmapHeight * scale);
  final Bitmap decored=createScaledBitmap(bitmap,scaledWidth,scaledHeight,SHADOW_RADIUS,true,SHADOW_PAINT);
  final Canvas canvas=new Canvas(decored);
  canvas.translate(SHADOW_RADIUS / 2.0f,SHADOW_RADIUS / 2.0f);
  canvas.drawRect(EDGE_START,0.0f,EDGE_END,scaledHeight,EDGE_PAINT);
  canvas.drawRect(FOLD_START,0.0f,FOLD_END,scaledHeight,FOLD_PAINT);
  canvas.translate(scaledWidth - (EDGE_END - EDGE_START),0.0f);
  canvas.drawRect(EDGE_START,0.0f,EDGE_END,scaledHeight,END_EDGE_PAINT);
  return decored;
}
 

Example 13

From project AndroidExamples, under directory /DrawingExample2/src/com/robertszkutak/drawingexample2/.

Source file: DrawingExample2Activity.java

  17 
vote

@Override public void run(){
  Canvas c;
  timer=System.currentTimeMillis();
  if (timer > timeBuffer + (1000 / 60)) {
    timeBuffer=timer;
    while (run) {
      c=null;
      try {
        c=surfaceHolder.lockCanvas(null);
synchronized (surfaceHolder) {
          panel.onDraw(c);
        }
      }
  finally {
        if (c != null) {
          surfaceHolder.unlockCanvasAndPost(c);
        }
      }
    }
  }
}
 

Example 14

From project androidquery, under directory /src/com/androidquery/callback/.

Source file: BitmapAjaxCallback.java

  17 
vote

private static Bitmap getRoundedCornerBitmap(Bitmap bitmap,int pixels){
  Bitmap output=Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),Config.ARGB_8888);
  Canvas canvas=new Canvas(output);
  final int color=0xff424242;
  final Paint paint=new Paint();
  final Rect rect=new Rect(0,0,bitmap.getWidth(),bitmap.getHeight());
  final RectF rectF=new RectF(rect);
  final float roundPx=pixels;
  paint.setAntiAlias(true);
  canvas.drawARGB(0,0,0,0);
  paint.setColor(color);
  canvas.drawRoundRect(rectF,roundPx,roundPx,paint);
  paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
  canvas.drawBitmap(bitmap,rect,rect,paint);
  return output;
}
 

Example 15

From project Android_1, under directory /Livewallpaper/switch_animation/src/com/novoda/wallpaper/.

Source file: AnimSwitchWallPaper.java

  17 
vote

void drawFrame(){
  final SurfaceHolder holder=getSurfaceHolder();
  Canvas c=null;
  try {
    c=holder.lockCanvas();
    if (c != null) {
      c.save();
      drawCar(c);
      c.restore();
    }
  }
  finally {
    if (c != null)     holder.unlockCanvasAndPost(c);
  }
  mHandler.removeCallbacks(mDrawWallpaper);
  if (mVisible) {
    mHandler.postDelayed(mDrawWallpaper,1000 / 300);
  }
}
 

Example 16

From project 2Degrees-Toolbox, under directory /ActionBarSherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenuView.java

  15 
vote

@Override protected void onDraw(Canvas canvas){
  if (!IS_FROYO && mFirst) {
    mFirst=false;
    requestLayout();
    return;
  }
  super.onDraw(canvas);
}
 

Example 17

From project 4308Cirrus, under directory /Extras/actionbarsherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenuView.java

  15 
vote

@Override protected void onDraw(Canvas canvas){
  if (!IS_FROYO && mFirst) {
    mFirst=false;
    requestLayout();
    return;
  }
  super.onDraw(canvas);
}
 

Example 18

From project abalone-android, under directory /src/com/bytopia/abalone/.

Source file: BoardRenderer.java

  15 
vote

/** 
 * Renders the specified RenderBall on the Canvas.
 * @param canvas canvas to render the ball onto
 * @param ball ball to render
 */
private void renderBall(Canvas canvas,RenderBall ball){
  dst.set((int)(ball.x - ballSize / 2),(int)(ball.y - ballSize / 2),(int)(ball.x + ballSize / 2),(int)(ball.y + ballSize / 2));
switch (ball.state) {
case Layout.B:
    blackBallPicture.setBounds(dst);
  blackBallPicture.draw(canvas);
break;
case Layout.W:
whiteBallPicture.setBounds(dst);
whiteBallPicture.draw(canvas);
break;
case Layout.E:
emptyBallPicture.setBounds(dst);
emptyBallPicture.draw(canvas);
break;
}
}
 

Example 19

From project AChartEngine, under directory /achartengine/src/org/achartengine/chart/.

Source file: AbstractChart.java

  15 
vote

/** 
 * Draws the chart background.
 * @param renderer the chart renderer
 * @param canvas the canvas to paint to
 * @param x the top left x value of the view to draw to
 * @param y the top left y value of the view to draw to
 * @param width the width of the view to draw to
 * @param height the height of the view to draw to
 * @param paint the paint used for drawing
 * @param newColor if a new color is to be used
 * @param color the color to be used
 */
protected void drawBackground(DefaultRenderer renderer,Canvas canvas,int x,int y,int width,int height,Paint paint,boolean newColor,int color){
  if (renderer.isApplyBackgroundColor() || newColor) {
    if (newColor) {
      paint.setColor(color);
    }
 else {
      paint.setColor(renderer.getBackgroundColor());
    }
    paint.setStyle(Style.FILL);
    canvas.drawRect(x,y,x + width,y + height,paint);
  }
}
 

Example 20

From project adg-android, under directory /src/com/analysedesgeeks/android/view/.

Source file: EllipsizingTextView.java

  15 
vote

@Override protected void onDraw(final Canvas canvas){
  if (isStale) {
    super.setEllipsize(null);
    resetText();
  }
  super.onDraw(canvas);
}
 

Example 21

From project Amantech, under directory /Android/action_bar_sherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenuView.java

  15 
vote

@Override protected void onDraw(Canvas canvas){
  if (!IS_FROYO && mFirst) {
    mFirst=false;
    requestLayout();
    return;
  }
  super.onDraw(canvas);
}
 

Example 22

From project andlytics, under directory /actionbarsherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenuView.java

  15 
vote

@Override protected void onDraw(Canvas canvas){
  if (!IS_FROYO && mFirst) {
    mFirst=false;
    requestLayout();
    return;
  }
  super.onDraw(canvas);
}
 

Example 23

From project android-cropimage, under directory /src/com/android/camera/.

Source file: CropImage.java

  15 
vote

@Override protected void onDraw(Canvas canvas){
  super.onDraw(canvas);
  for (int i=0; i < mHighlightViews.size(); i++) {
    mHighlightViews.get(i).draw(canvas);
  }
}
 

Example 24

From project android-pulltorefresh, under directory /library/src/com/handmark/pulltorefresh/library/.

Source file: PullToRefreshListView.java

  15 
vote

@Override public void draw(Canvas canvas){
  try {
    super.draw(canvas);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 25

From project Android-Terminal-Emulator, under directory /libraries/emulatorview/src/jackpal/androidterm/emulatorview/.

Source file: EmulatorView.java

  15 
vote

/** 
 * Draw the view to the provided  {@link Canvas}.
 * @param canvas The {@link Canvas} to draw the view to.
 */
@Override protected void onDraw(Canvas canvas){
  updateSize(false);
  if (mEmulator == null) {
    return;
  }
  int w=getWidth();
  int h=getHeight();
  boolean reverseVideo=mEmulator.getReverseVideo();
  mTextRenderer.setReverseVideo(reverseVideo);
  Paint backgroundPaint=reverseVideo ? mForegroundPaint : mBackgroundPaint;
  canvas.drawRect(0,0,w,h,backgroundPaint);
  float x=-mLeftColumn * mCharacterWidth;
  float y=mCharacterHeight + mTopOfScreenMargin;
  int endLine=mTopRow + mRows;
  int cx=mEmulator.getCursorCol();
  int cy=mEmulator.getCursorRow();
  for (int i=mTopRow; i < endLine; i++) {
    int cursorX=-1;
    if (i == cy && mCursorVisible) {
      cursorX=cx;
    }
    int selx1=-1;
    int selx2=-1;
    if (i >= mSelY1 && i <= mSelY2) {
      if (i == mSelY1) {
        selx1=mSelX1;
      }
      if (i == mSelY2) {
        selx2=mSelX2;
      }
 else {
        selx2=mColumns;
      }
    }
    mTranscriptScreen.drawText(i,canvas,x,y,mTextRenderer,cursorX,selx1,selx2,mImeBuffer);
    y+=mCharacterHeight;
  }
}
 

Example 26

From project android-tether, under directory /android-misc-widgets/src/org/miscwidgets/widget/.

Source file: Panel.java

  15 
vote

@Override protected void dispatchDraw(Canvas canvas){
  if (mState == State.ABOUT_TO_ANIMATE && !mIsShrinking) {
    int delta=mOrientation == VERTICAL ? mContentHeight : mContentWidth;
    if (mPosition == LEFT || mPosition == TOP) {
      delta=-delta;
    }
    if (mOrientation == VERTICAL) {
      canvas.translate(0,delta);
    }
 else {
      canvas.translate(delta,0);
    }
  }
  if (mState == State.TRACKING || mState == State.FLYING) {
    canvas.translate(mTrackX,mTrackY);
  }
  super.dispatchDraw(canvas);
}
 

Example 27

From project android-viewflow, under directory /viewflow/src/org/taptwo/android/widget/.

Source file: CircleFlowIndicator.java

  15 
vote

@Override protected void onDraw(Canvas canvas){
  super.onDraw(canvas);
  int count=3;
  if (viewFlow != null) {
    count=viewFlow.getViewsCount();
  }
  float circleSeparation=2 * radius + radius;
  float centeringOffset=0;
  int leftPadding=getPaddingLeft();
  for (int iLoop=0; iLoop < count; iLoop++) {
    canvas.drawCircle(leftPadding + radius + (iLoop * circleSeparation)+ centeringOffset,getPaddingTop() + radius,radius,mPaintInactive);
  }
  float cx=0;
  if (flowWidth != 0) {
    cx=(currentScroll * (2 * radius + radius)) / flowWidth;
  }
  canvas.drawCircle(leftPadding + radius + cx+ centeringOffset,getPaddingTop() + radius,radius,mPaintActive);
}
 

Example 28

From project android-wheel, under directory /wheel/src/kankan/wheel/widget/.

Source file: WheelView.java

  15 
vote

@Override protected void onDraw(Canvas canvas){
  super.onDraw(canvas);
  if (viewAdapter != null && viewAdapter.getItemsCount() > 0) {
    updateView();
    drawItems(canvas);
    drawCenterRect(canvas);
  }
  drawShadows(canvas);
}
 

Example 29

From project android-wheel-datetime-picker, under directory /src/kankan/wheel/widget/.

Source file: WheelView.java

  15 
vote

@Override protected void onDraw(Canvas canvas){
  super.onDraw(canvas);
  if (viewAdapter != null && viewAdapter.getItemsCount() > 0) {
    updateView();
    drawItems(canvas);
    drawCenterRect(canvas);
  }
  drawShadows(canvas);
}
 

Example 30

From project android-wheel_1, under directory /wheel/src/kankan/wheel/widget/.

Source file: WheelView.java

  15 
vote

@Override protected void onDraw(Canvas canvas){
  super.onDraw(canvas);
  if (viewAdapter != null && viewAdapter.getItemsCount() > 0) {
    updateView();
    drawItems(canvas);
    drawCenterRect(canvas);
  }
  drawShadows(canvas);
}
 

Example 31

From project android-xbmcremote, under directory /src/org/xbmc/android/remote/presentation/widget/.

Source file: AbstractItemView.java

  15 
vote

protected void drawPoster(Canvas canvas,int posterWidth,int posterHeight,int canvasWidth){
  if ((isSelected() || isPressed()) && mSelection != null) {
    mSelection.setBounds(posterWidth,0,canvasWidth,posterHeight);
    mSelection.draw(canvas);
  }
 else {
    PAINT.setColor(mDefaultColor);
    canvas.drawRect(posterWidth,0,canvasWidth,posterHeight,PAINT);
  }
  Bitmap cover=mCover;
  if (mCover == null || mCover.isRecycled()) {
    cover=mDefaultCover;
  }
  if (cover != null && !cover.isRecycled()) {
    int dx=(cover.getWidth() - posterWidth) / 2;
    int dy=(cover.getHeight() - posterHeight) / 2;
    Rect src=null;
    if (dx > 0 || dy > 0) {
      src=new Rect(dx,dy,dx + posterWidth,dy + posterHeight);
    }
    Rect dst=getPosterRect();
    PAINT.setColor(mDefaultColor);
    canvas.drawRect(0,0,posterWidth,posterHeight,PAINT);
    canvas.drawBitmap(cover,src,dst,PAINT);
  }
}
 

Example 32

From project androidtracks, under directory /src/org/sfcta/cycletracks/.

Source file: ShowMap.java

  15 
vote

@Override public boolean draw(Canvas canvas,MapView mapView,boolean shadow,long when){
  super.draw(canvas,mapView,shadow);
  if (track.size() < 2)   return true;
  float[] points=new float[4 * track.size()];
  int segments=0;
  int startx=-1;
  int starty=-1;
  for (int i=0; i < track.size(); i++) {
    CyclePoint z=(CyclePoint)track.getItem(i).getPoint();
    if (z.accuracy > 8) {
      startx=-1;
      continue;
    }
    Point screenPoint=new Point();
    mapView.getProjection().toPixels(z,screenPoint);
    if (startx == -1) {
      startx=screenPoint.x;
      starty=screenPoint.y;
      continue;
    }
    int numpts=segments * 4;
    points[numpts]=startx;
    points[numpts + 1]=starty;
    points[numpts + 2]=startx=screenPoint.x;
    points[numpts + 3]=starty=screenPoint.y;
    segments++;
  }
  Paint paint=new Paint();
  paint.setARGB(255,0,0,255);
  paint.setStrokeWidth(5);
  paint.setStyle(Style.FILL_AND_STROKE);
  canvas.drawLines(points,0,segments * 4,paint);
  return false;
}
 

Example 33

From project androidZenWriter, under directory /library/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenuView.java

  15 
vote

@Override protected void onDraw(Canvas canvas){
  if (!IS_FROYO && mFirst) {
    mFirst=false;
    requestLayout();
    return;
  }
  super.onDraw(canvas);
}
 

Example 34

From project android_7, under directory /src/org/immopoly/android/widget/.

Source file: ClusterMarker.java

  15 
vote

@Override public void draw(Canvas canvas){
  if (!shadowMode) {
    int numFlats=flats.size();
    baseDrawable.draw(canvas);
    String text=numFlats < 10 ? Integer.toString(numFlats) : "+";
    canvas.drawText(text,textX,textY,textPaint);
  }
}