@Override
  public Bitmap transform(Bitmap bitmap) {

    if (null == bitmap) return null;

    PaintFlagsDrawFilter fliter =
        new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    if (w <= 0 || h <= 0) {
      return null;
    }
    int r = (w < h ? w : h) / 2;
    Bitmap circle = Bitmap.createBitmap(2 * r, 2 * r, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(circle);
    canvas.setDrawFilter(fliter);

    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    p.setColor(Color.RED);
    canvas.drawCircle(r, r, r, p);
    p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

    // 生成结果图片
    Bitmap out = Bitmap.createBitmap(2 * r, 2 * r, Bitmap.Config.ARGB_8888);
    Canvas outCan = new Canvas(out);
    outCan.setDrawFilter(fliter);

    outCan.drawBitmap(bitmap, 0, 0, null);
    outCan.drawBitmap(circle, 0, 0, p);
    circle.recycle();
    bitmap.recycle();
    return out;
  }
예제 #2
0
 protected void onDraw(Canvas paramCanvas) {
   paramCanvas.setDrawFilter(SkinManager.getInstance().getDrawFilter());
   paramCanvas.save();
   drawBg(paramCanvas);
   drawLetters(paramCanvas);
   paramCanvas.restore();
 }
예제 #3
0
  public IconUtilities(Context context) {
    final Resources resources = context.getResources();
    DisplayMetrics metrics = mDisplayMetrics = resources.getDisplayMetrics();
    final float density = metrics.density;
    final float blurPx = 5 * density;

    mIconWidth = mIconHeight = (int) resources.getDimension(android.R.dimen.app_icon_size);
    mIconTextureWidth = mIconTextureHeight = mIconWidth + (int) (blurPx * 2);

    mBlurPaint.setMaskFilter(new BlurMaskFilter(blurPx, BlurMaskFilter.Blur.NORMAL));

    TypedValue value = new TypedValue();
    mGlowColorPressedPaint.setColor(
        context.getTheme().resolveAttribute(android.R.attr.colorPressedHighlight, value, true)
            ? value.data
            : 0xffffc300);
    mGlowColorPressedPaint.setMaskFilter(TableMaskFilter.CreateClipTable(0, 30));
    mGlowColorFocusedPaint.setColor(
        context.getTheme().resolveAttribute(android.R.attr.colorFocusedHighlight, value, true)
            ? value.data
            : 0xffff8e00);
    mGlowColorFocusedPaint.setMaskFilter(TableMaskFilter.CreateClipTable(0, 30));

    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0.2f);

    mCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, Paint.FILTER_BITMAP_FLAG));
  }
예제 #4
0
파일: WidgetView.java 프로젝트: fesch/CanZE
 // DIRECT repaint method
 public void repaint2() {
   Canvas c = null;
   try {
     c = getHolder().lockCanvas();
     if (c != null) {
       // enable anti-aliasing
       c.setDrawFilter(new PaintFlagsDrawFilter(1, Paint.ANTI_ALIAS_FLAG));
       // clean background
       Paint paint = new Paint();
       paint.setColor(drawable.getBackground().getAndroidColor());
       c.drawRect(0, 0, c.getWidth(), c.getHeight(), paint);
       // set dimensions
       drawable.setWidth(getWidth());
       drawable.setHeight(getHeight());
       // do the drawing
       drawable.draw(new Graphics(c));
     }
   } catch (Exception e) {
     // ignore
   } finally {
     if (c != null) {
       getHolder().unlockCanvasAndPost(c);
     }
   }
 }
예제 #5
0
 @Override
 public void draw(Canvas canvas) {
   // TODO Auto-generated method stub
   canvas.setDrawFilter(pfd);
   canvas.drawCircle(
       getWidth() / 2, getHeight() / 2, Math.max(getWidth(), getHeight()) / 2, mBgPaint);
   super.draw(canvas);
 }
  @Override
  public void onAnimDraw(SurfaceHolder holder) {

    while (!isDragEnd) {
      Canvas canvas = null;
      int size = 0;
      int oldsize = 0;
      while ((size = mStack.size()) > 0 && null != holder) {
        if (oldsize == size) {
          break;
        }
        oldsize = size;

        try {
          canvas = holder.lockCanvas(null);
          canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR);
          canvas.setDrawFilter(pdf);

          for (int i = 0; i < shadowBitmap.length; i++) {
            int[] _point = mStack.get((int) (size * (1 - (i + 1) * 0.1)));

            dst.set(
                _point[0] - headWidth / 2,
                _point[1] - headWidth / 2,
                _point[0] + headWidth / 2,
                _point[1] + headWidth / 2);
            canvas.drawBitmap(mDstB, null, dst, paint);
            paint.setXfermode(xfermode);
            canvas.drawBitmap(shadowBitmap[i], null, dst, paint);
            paint.setXfermode(null);
          }

          ballIconRect.set(
              _lastX - ballIcon.getIntrinsicWidth() / 2,
              _lastY - ballIcon.getIntrinsicHeight() / 2,
              _lastX + ballIcon.getIntrinsicWidth() / 2,
              _lastY + ballIcon.getIntrinsicHeight() / 2);
          ballIcon.setBounds(ballIconRect);
          ballIcon.draw(canvas);

        } catch (Exception e) {
          e.printStackTrace();
        } finally {
          if (null != canvas) {
            holder.unlockCanvasAndPost(canvas);
          } else {
            break;
          }
        }
      }
      mStack.clear();
      try {
        Thread.sleep(15);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
예제 #7
0
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   if (isFirst) {
     isFirst = false;
     init();
   }
   canvas.setDrawFilter(
       new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
 }
예제 #8
0
  /**
   * ��ͼƬ��ΪԲ��ͼƬ
   *
   * @param bitmap
   * @return
   */
  public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {

    output = null;
    if (bitmap != null) {

      int width = bitmap.getWidth();
      int height = bitmap.getHeight();
      float roundPx;
      float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;
      if (width <= height) {
        roundPx = width / 2;
        top = 0;
        bottom = width;
        left = 0;
        right = width;
        height = width;
        dst_left = 0;
        dst_top = 0;
        dst_right = width;
        dst_bottom = width;
      } else {
        roundPx = height / 2;
        float clip = (width - height) / 2;
        left = clip;
        right = width - clip;
        top = 0;
        bottom = height;
        width = height;
        dst_left = 0;
        dst_top = 0;
        dst_right = height;
        dst_bottom = height;
      }
      output = Bitmap.createBitmap(width, height, android.graphics.Bitmap.Config.ARGB_8888);
      Canvas canvas = new Canvas(output);
      canvas.setDrawFilter(
          new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
      final int color = 0xff424242;
      final Paint paint = new Paint();
      final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom);
      final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom);
      final RectF rectF = new RectF(dst);
      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, src, dst, paint);

      bitmap = output;
      return bitmap;
    }
    output = null;
    return null;
  }
예제 #9
0
 protected void onDraw(Canvas paramCanvas) {
   if (this.mNode == null) return;
   paramCanvas.setDrawFilter(this.filter);
   paramCanvas.save();
   if (this.mNode.nodeName.equalsIgnoreCase("playhistory")) drawRecentItem(paramCanvas);
   while (true) {
     paramCanvas.restore();
     return;
     drawNormalItem(paramCanvas);
   }
 }
예제 #10
0
 protected void onDraw(Canvas paramCanvas)
 {
   if (this.mNode == null)
     return;
   paramCanvas.save();
   paramCanvas.setDrawFilter(this.filter);
   drawBg(paramCanvas);
   drawLine(paramCanvas);
   drawTitle(paramCanvas);
   drawArrow(paramCanvas);
   paramCanvas.restore();
 }
    @Override
    public void draw(Canvas canvas) {
      if (mBitmap == null) {
        return;
      }
      int width = canvas.getWidth();
      int height = canvas.getHeight();

      if (LauncherLog.DEBUG) {
        LauncherLog.d(
            TAG,
            "Bitmap width is "
                + mIntrinsicWidth
                + ", height is "
                + mIntrinsicHeight
                + ". Canvas width is "
                + width
                + ", height is "
                + height);
      }

      /// M: scale up the bitmap to make it cover the entire area
      float scalew = width / (float) mIntrinsicWidth;
      float scaleh = height / (float) mIntrinsicHeight;

      if (scalew > 1.0 || scaleh > 1.0) {
        if (LauncherLog.DEBUG) {
          LauncherLog.d(TAG, "Draw by scale size");
        }
        float scale = scalew > scaleh ? scalew : scaleh;
        int scaledWidth = (int) (mIntrinsicWidth * scale);
        int scaledHeight = (int) (mIntrinsicHeight * scale);
        int x = (width - scaledWidth) / 2;
        int y = (height - scaledHeight) / 2;

        Bitmap scaledBitmap = Bitmap.createScaledBitmap(mBitmap, scaledWidth, scaledHeight, true);
        canvas.setDrawFilter(
            new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
        canvas.drawBitmap(scaledBitmap, x, y, null);
        scaledBitmap.recycle();
        scaledBitmap = null;
      } else {
        if (LauncherLog.DEBUG) {
          LauncherLog.d(TAG, "Draw by original size");
        }
        int x = (width - mIntrinsicWidth) / 2;
        int y = (height - mIntrinsicHeight) / 2;
        canvas.drawBitmap(mBitmap, x, y, null);
      }
    }
예제 #12
0
  @Override
  protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    Paint tmpPaint = new Paint();
    tmpPaint.setAlpha(70);

    canvas.setDrawFilter(paintFilter);
    canvas.drawBitmap(bmpBack, 0, 0, paint);
    canvas.drawBitmap(bmpMotion, matrixPaint, tmpPaint);
    canvas.drawBitmap(bmpRotate, null, rectRotate, null);
    //		canvas.drawRect(rectPaint, paint);
    //		canvas.drawRect(rectRotate, paint);
    //		canvas.drawCircle(picMidPoint.x, picMidPoint.y, 5, paint);
    super.onDraw(canvas);
  }
예제 #13
0
  @Override
  protected synchronized void onDraw(Canvas canvas) {

    // LogManager.d("noImage" + this + "begin onDraw");
    super.onDraw(canvas);
    canvas.save();
    PaintFlagsDrawFilter filter = new PaintFlagsDrawFilter(0, Paint.FILTER_BITMAP_FLAG);
    canvas.setDrawFilter(filter);
    canvas.drawColor(Color.TRANSPARENT);
    if (bitmap != null && !bitmap.isRecycled()) {
      canvas.drawBitmap(bitmap, 0, 0, paint);
    } else {
      // LogManager.d("noImage" + this + bitmap + "isRecycled");
    }
    canvas.restore();
    // LogManager.d("noImage" + this + "end onDraw");
  }
예제 #14
0
  @Override
  protected void onDraw(Canvas canvas) {

    int alpha = (int) Math.ceil((255 * mAlpha));
    //		Paint iPaint = new Paint();
    //		iPaint.setFilterBitmap(true);//去掉该句会使下面两项设置失效
    //		iPaint.setAntiAlias(true);//设置是否使用抗锯齿功能
    //		iPaint.setDither(true);//设定是否使用图像抖动处理
    canvas.setDrawFilter(
        new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
    //		canvas.drawBitmap(icon, null, iconRect, iPaint);
    canvas.drawBitmap(icon, null, iconRect, null);

    setupTargetBitmap(alpha);
    drawSourceText(canvas, alpha);
    drawTargetText(canvas, alpha);
    canvas.drawBitmap(mBitmap, 0, 0, null);
    if (drawFlag) drawCirc(canvas);
  }
예제 #15
0
 /**
  * 具体的画法
  *
  * @param paint
  * @param canvas
  */
 private void draw(Paint paint, Canvas canvas) {
   // 外形不为空画外形
   if (null != info.getsShapId()) {
     if (imageItem == null) {
       imageItem = new ImageDrawItem(info.getsShapId(), mRect);
     }
     imageItem.draw(paint, canvas);
   }
   // 画静态文本
   drawTextValue(paint, canvas);
   // 画点击输入背景提示框
   if (drawBack) {
     if (bgBitmap == null) {
       bgBitmap = ImageFileTool.getBitmap(R.drawable.rect_red_bg, mContext);
       bgRect = new Rect(0, 0, bgBitmap.getWidth(), bgBitmap.getHeight());
     }
     if (bgBitmap != null) {
       canvas.setDrawFilter(
           new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
       if (mBitmapPaint == null) {
         mBitmapPaint = new Paint();
         mBitmapPaint.setDither(true);
         mBitmapPaint.setAntiAlias(true);
       }
       canvas.drawBitmap(bgBitmap, bgRect, mRect, mBitmapPaint);
     }
   }
   // 不可触控加上锁图标
   if (!isTouchFlag && SystemInfo.isbLockIcon()) {
     if (mLockBitmap == null) {
       mLockBitmap = ImageFileTool.getBitmap(R.drawable.lock, mContext);
     }
     if (mLockBitmap != null) {
       if (mBitmapPaint == null) {
         mBitmapPaint = new Paint();
         mBitmapPaint.setDither(true);
         mBitmapPaint.setAntiAlias(true);
       }
       canvas.drawBitmap(mLockBitmap, info.getnStartX(), info.getnStartY(), mBitmapPaint);
     }
   }
 }
예제 #16
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mShader != null) {
      canvas.setDrawFilter(mFast);

      int saveCount = canvas.save();

      mPaint.setShader(mShader);
      canvas.drawRect(mRealRect, mPaint);

      canvas.translate(mPaddingLeft - mLineBigSize / 2, 0);
      mPaint.setShader(mShader1);
      canvas.drawPaint(mPaint);

      mPaint.setShader(null);

      float rw = ((float) mRealRect.width() - (mCorrectionX)) / 2;
      canvas.drawBitmap(mIndicator, (rw + (rw * mValue)), 0, mPaint);
      canvas.restoreToCount(saveCount);
    }
  }
예제 #17
0
  public HandDraw(View v) {
    view = v;
    try {
      bitmapSrc =
          Bitmap.createBitmap(
              GlobalVariables.screenWidth, GlobalVariables.canvasHeigh, Bitmap.Config.ARGB_4444);
      bitmapSrc.eraseColor(0x0);
      canvasSrc = new Canvas(bitmapSrc);
      bitmapDst =
          Bitmap.createBitmap(
              GlobalVariables.screenWidth, GlobalVariables.canvasHeigh, Bitmap.Config.ARGB_4444);

      bitmapDst.eraseColor(0x0);
      canvasDst = new Canvas(bitmapDst);
      DrawingFactory factory = new DrawingFactory();
      pathDrawing = (PathLine) factory.createDrawing(DrawingId.DRAWING_PATHLINE, null);
      Paint paint = new Paint();
      paint = Brush.getPen();
      pathDrawing.setPen(paint);
      canvasSrc.setDrawFilter(new PaintFlagsDrawFilter(0x0, 0x3));
    } catch (OutOfMemoryError e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
    // 笔迹颜色
    path = new Path();

    int colll = Brush.getPen().getColor();
    thinPen.setColor(colll);
    thinPen.setStrokeWidth(1.5f);
    thinPen.setAntiAlias(true);
    thinPen.setDither(true);
    thinPen.setStyle(Paint.Style.STROKE);
    thinPen.setStrokeJoin(Paint.Join.ROUND);
    thinPen.setStrokeCap(Paint.Cap.ROUND);
  }
예제 #18
0
    @Override
    protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);

      if (_valid) {

        DrawFilter drawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG);
        canvas.setDrawFilter(drawFilter);

        float density = getContext().getResources().getDisplayMetrics().density;
        int height = getHeight();
        int width = getWidth();
        int number_bars = _values.length;
        int space = 1;

        // Log.i("Draw","Density " +  density );
        // Log.i("Draw","Width " +  height );
        // Log.i("Draw","Height " +  width );

        float thickness = ((width - number_bars + 1) / number_bars);
        float border = (width - (number_bars * space) - (thickness * (number_bars + 1))) / 2;

        float startX;
        float startY;
        float stopX;
        float stopY;

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.rgb(0x00, 0x66, 0xff));
        paint.setStrokeWidth(thickness);

        int i;
        Integer highestvalue = 0;
        float textposition = 0;
        for (i = 1; i < number_bars + 1; i++) {
          int value = _values[i - 1];

          float barheight = (value / 100) * density;

          startX = border + (i * (thickness + space));
          stopX = border + (i * (thickness + space));

          if (highestvalue < value) {
            highestvalue = value;
            textposition = stopX;
          }

          startY = height;
          stopY = height - barheight;
          if (barheight > 30) {
            paint.setColor(Color.rgb(0xff, 0x66, 0x00));
            canvas.drawLine(startX, startY, stopX, stopY, paint);
            paint.setColor(Color.rgb(0x00, 0x66, 0xff));
            stopY = height - (30 * density);
            canvas.drawLine(startX, startY, stopX, stopY, paint);
          } else {
            canvas.drawLine(startX, startY, stopX, stopY, paint);
          }
          // Log.i("Draw","stopY " +  stopY + " Height " + height + " value " +
          // ((Integer.parseInt(_ecmvalues[i-1]) / 100) * density));
        }

        paint.setStrokeWidth(1);
        paint.setColor(Color.rgb(0x18, 0x18, 0x18));
        float j;
        for (j = (10 * density); j < height; j += (10 * density)) {
          canvas.drawLine(0, j, getWidth(), j, paint);
        }

        paint.setColor(Color.rgb(0xff, 0xff, 0xff));
        paint.setTextSize((10 * density));
        paint.setTextAlign(Paint.Align.CENTER);
        canvas.drawText(highestvalue.toString(), textposition, 50 * density, paint);

        // _logo = Bitmap.createScaledBitmap(_logo, 40, 30, true);
        if (_logo != null) canvas.drawBitmap(_logo, 2, 2, paint);
      }
    }
예제 #19
0
  private void onSaveClicked() {
    if (!mNeedCrop) {
      Bitmap nocropBitmap = createNoCropBitmap();
      mImageView.clear();
      if (nocropBitmap != mBitmap) {
        mBitmap.recycle();
        mBitmap = null;
      }
      if (null != nocropBitmap) {
        // Return the cropped image directly or save it to the specified
        // URI.
        Bundle myExtras = getIntent().getExtras();
        if (myExtras != null
            && (myExtras.getParcelable("data") != null || myExtras.getBoolean("return-data"))) {
          Bundle extras = new Bundle();
          extras.putParcelable("data", nocropBitmap);
          setResult(
              RESULT_OK,
              (new Intent()).setAction(ICustomAction.ACTION_INLINE_DATA).putExtras(extras));
          finish();
        } else {
          final Bitmap b = nocropBitmap;
          final int msdId = mSetWallpaper ? R.string.wallpaper : R.string.savingImage;
          Util.startBackgroundJob(
              this,
              null,
              getResources().getString(msdId),
              new Runnable() {
                @Override
                public void run() {
                  saveOutput(b);
                }
              },
              mHandler);
        }
      } else {
        setResult(RESULT_CANCELED);
        finish();
      }
      return;
    }
    // TODO this code needs to change to use the decode/crop/encode single
    // step api so that we don't require that the whole (possibly large)
    // bitmap doesn't have to be read into memory
    if (mCrop == null) {
      return;
    }

    if (mSaving) {
      return;
    }
    mSaving = true;

    Bitmap croppedImage = null;
    Bitmap.Config bmpConfig = mHasApha ? Bitmap.Config.ARGB_8888 : Bitmap.Config.ARGB_8888;

    // If the output is required to a specific size, create an new image
    // with the cropped image in the center and the extra space filled.
    if (mOutputX != 0 && mOutputY != 0 && !mScale) {
      // Don't scale the image but instead fill it so it's the
      // required dimension
      try {
        croppedImage = Bitmap.createBitmap(mOutputX, mOutputY, bmpConfig);
      } catch (OutOfMemoryError e) {
        // 创建失败
        e.printStackTrace();
        OutOfMemoryHandler.handle();
        Toast.makeText(this, getString(R.string.err_out_of_memory), Toast.LENGTH_SHORT);
        // Release bitmap memory as soon as possible
        mImageView.clear();
        mBitmap.recycle();
        mBitmap = null;

        setResult(RESULT_CANCELED);
        finish();
        return;
      }

      Canvas canvas = new Canvas(croppedImage);
      Rect srcRect = mCrop.getCropRect();
      Rect dstRect = new Rect(0, 0, mOutputX, mOutputY);

      int dx = (srcRect.width() - dstRect.width()) / 2;
      int dy = (srcRect.height() - dstRect.height()) / 2;

      // If the srcRect is too big, use the center part of it.
      srcRect.inset(Math.max(0, dx), Math.max(0, dy));

      // If the dstRect is too big, use the center part of it.
      dstRect.inset(Math.max(0, -dx), Math.max(0, -dy));

      // Draw the cropped bitmap in the center
      canvas.drawBitmap(mBitmap, srcRect, dstRect, null);

      // Release bitmap memory as soon as possible
      mImageView.clear();
      mBitmap.recycle();
    } else {
      Rect r = mCrop.getCropRect();

      // int width = r.width();
      // int height = r.height();

      // If we are circle cropping, we want alpha channel, which is the
      // third param here.
      try {
        croppedImage = Bitmap.createBitmap(mOutputX, mOutputY, bmpConfig);
      } catch (OutOfMemoryError e) {
        e.printStackTrace();
        OutOfMemoryHandler.handle();
        // 创建失败
        // Toast.makeText(this, getString(R.string.err_out_of_memory),
        // Toast.LENGTH_SHORT).show();
        // Release bitmap memory as soon as possible
        mImageView.clear();
        mBitmap.recycle();

        setResult(RESULT_CANCELED);
        finish();
        return;
      }

      Canvas canvas = new Canvas(croppedImage);
      canvas.setDrawFilter(
          new PaintFlagsDrawFilter(
              0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG)); // 在有缩放的情况下需要提高绘图质量
      Rect dstRect = new Rect(0, 0, mOutputX, mOutputY);
      canvas.drawBitmap(mBitmap, r, dstRect, null);

      // Release bitmap memory as soon as possible
      mImageView.clear();
      mBitmap.recycle();

      // if (mCircleCrop) {
      // // OK, so what's all this about?
      // // Bitmaps are inherently rectangular but we want to return
      // // something that's basically a circle. So we fill in the
      // // area around the circle with alpha. Note the all important
      // // PortDuff.Mode.CLEAR.
      // Canvas c = new Canvas(croppedImage);
      // Path p = new Path();
      // p.addCircle(width / 2F, height / 2F, width / 2F,
      // Path.Direction.CW);
      // c.clipPath(p, Region.Op.DIFFERENCE);
      // c.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
      // }

      // If the required dimension is specified, scale the image.
      // if (mOutputX != 0 && mOutputY != 0 && mScale) {
      // croppedImage = Util.transform(new Matrix(), croppedImage,
      // mOutputX, mOutputY, mScaleUp, Util.RECYCLE_INPUT);
      // }
    }

    mImageView.setImageBitmapResetBase(croppedImage, true);
    mImageView.center(true, true);
    mImageView.mHighlightViews.clear();

    // Return the cropped image directly or save it to the specified URI.
    Bundle myExtras = getIntent().getExtras();
    if (myExtras != null
        && (myExtras.getParcelable("data") != null || myExtras.getBoolean("return-data"))) {
      Bundle extras = new Bundle();
      extras.putParcelable("data", croppedImage);
      setResult(
          RESULT_OK, (new Intent()).setAction(ICustomAction.ACTION_INLINE_DATA).putExtras(extras));
      finish();
    } else {
      final Bitmap b = croppedImage;
      final int msdId = mSetWallpaper ? R.string.wallpaper : R.string.savingImage;
      Util.startBackgroundJob(
          this,
          null,
          getResources().getString(msdId),
          new Runnable() {
            @Override
            public void run() {
              saveOutput(b);
            }
          },
          mHandler);
    }
  }
예제 #20
0
    public void drawRB(Canvas canvas) {
      double dx = scrollX, dy = contentHeight - scrollY;
      double len = Math.sqrt(dx * dx + dy * dy);
      if (len > contentWidth) {
        scrollX = (float) (contentWidth * dx / len);
        scrollY = (float) (contentHeight - contentWidth * dy / len);
      }

      double px = contentWidth - scrollX;
      double py = contentHeight - scrollY;
      double arc = 2 * Math.atan(py / px) * 180 / Math.PI;

      // 三角
      ps.reset();
      ps.setColor(Color.WHITE);
      ps.setAntiAlias(true);
      canvas.save();
      m.reset();
      m.postTranslate(scrollX, scrollY - contentHeight);
      m.postRotate((float) (arc), scrollX, scrollY);
      canvas.setMatrix(m);
      canvas.drawRect(0, 0, contentWidth, contentHeight, ps);
      canvas.restore();

      // 下一页
      arc = arc * Math.PI / 360;
      angelPath.reset();
      double r = Math.sqrt(px * px + py * py);
      double p1 = contentWidth - r / (2 * Math.cos(arc));
      double p2 = r / (2 * Math.sin(arc));
      if (arc == 0) {
        angelPath.moveTo(contentWidth, 0);
        angelPath.lineTo((float) p1, 0);
        angelPath.lineTo((float) p1, contentHeight);
        angelPath.lineTo(contentWidth, contentHeight);
        angelPath.close();
      } else if (p2 > contentHeight || p2 < 0) {
        double p3 = contentWidth - (p2 - contentHeight) * Math.tan(arc);
        angelPath.moveTo(contentWidth, 0);
        angelPath.lineTo((float) p3, 0);
        angelPath.lineTo((float) p1, contentHeight);
        angelPath.lineTo(contentWidth, contentHeight);
        angelPath.close();
      } else {
        angelPath.moveTo(contentWidth, contentHeight);
        angelPath.lineTo(contentWidth, contentHeight - (float) p2);
        angelPath.lineTo((float) p1, contentHeight);
        angelPath.close();
      }
      canvas.save();
      // canvas.
      canvas.clipPath(angelPath);
      canvas.setDrawFilter(
          new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
      nextPage.draw(canvas);
      canvas.restore();

      ps.reset();
      Shader lg2 =
          new LinearGradient(
              scrollX,
              scrollY,
              contentWidth,
              contentHeight,
              new int[] {0x00000000, 0x33000000, 0x00000000},
              new float[] {0.35f, 0.5f, 0.65f},
              Shader.TileMode.CLAMP);
      ps.setShader(lg2);
      canvas.drawRect(0, 0, contentWidth, contentHeight, ps);
    }
  @Override
  protected void onDraw(Canvas canvas) {

    if (mBounds == null) {
      return;
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
      return;
    }

    canvas.setDrawFilter(
        new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {

      // Need to redraw the cache
      if (width == mCachedWidth && height == mCachedHeight) {
        // Have a correct-sized bitmap cache already allocated. Just erase it.
        mCacheBitmap.eraseColor(0);
      } else {
        // Allocate a new bitmap with the correct dimensions.
        mCacheBitmap.recycle();
        //noinspection AndroidLintDrawAllocation
        mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        mCachedWidth = width;
        mCachedHeight = height;
      }

      Canvas cacheCanvas = new Canvas(mCacheBitmap);
      cacheCanvas.setDrawFilter(
          new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
      if (mMaskDrawable != null) {
        int sc = cacheCanvas.save();
        mMaskDrawable.draw(cacheCanvas);
        mMaskedPaint.setColorFilter(
            (mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
        cacheCanvas.saveLayer(
            mBoundsF,
            mMaskedPaint,
            Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
        super.onDraw(cacheCanvas);
        cacheCanvas.restoreToCount(sc);
      } else if (mDesaturateOnPress && isPressed()) {
        int sc = cacheCanvas.save();
        cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
        mMaskedPaint.setColorFilter(mDesaturateColorFilter);
        cacheCanvas.saveLayer(
            mBoundsF,
            mMaskedPaint,
            Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
        super.onDraw(cacheCanvas);
        cacheCanvas.restoreToCount(sc);
      } else {
        super.onDraw(cacheCanvas);
      }

      if (mBorderDrawable != null) {
        mBorderDrawable.draw(cacheCanvas);
      }
    }

    // Draw from cache
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
  }
  @Override
  public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    super.draw(canvas, mapView, shadow);

    // buildings have no shadows; therefore return without drawing if shadow
    // == true
    if (shadow == true) {
      return;
    }

    try {

      // create a new painter
      Paint paint = new Paint();
      GeoPoint geoPoint = new GeoPoint((int) (1 * 1E6), (int) (1 * 1E6));
      Point screenCoordinates = new Point();
      Path path = new Path();

      //		//draw background
      //		// create a new painter
      //		paint.setColor(R.color.mapBackground);
      //		paint.setStyle(Paint.Style.FILL);
      //
      //		geoPoint = new GeoPoint((int) (1 * 1E6), (int) (1 * 1E6));
      //		screenCoordinates = new Point();
      //		mapView.getProjection().toPixels(geoPoint, screenCoordinates);
      //		path.moveTo(screenCoordinates.x, screenCoordinates.y);
      //
      //		geoPoint = new GeoPoint((int) (70 * 1E6), (int) (1 * 1E6));
      //		screenCoordinates = new Point();
      //		mapView.getProjection().toPixels(geoPoint, screenCoordinates);
      //		path.lineTo(screenCoordinates.x, screenCoordinates.y);
      //
      //		geoPoint = new GeoPoint((int) (70* 1E6), (int) (70 * 1E6));
      //		screenCoordinates = new Point();
      //		mapView.getProjection().toPixels(geoPoint, screenCoordinates);
      //		path.lineTo(screenCoordinates.x, screenCoordinates.y);
      //
      //		geoPoint = new GeoPoint((int) (1 * 1E6), (int) (70 * 1E6));
      //		screenCoordinates = new Point();
      //		mapView.getProjection().toPixels(geoPoint, screenCoordinates);
      //		path.lineTo(screenCoordinates.x, screenCoordinates.y);
      //
      //		// draw the path on bitmapCanvas
      //		canvas.drawPath(path, paint);
      //

      // draw line with antialiasing
      DrawFilter drawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG);
      canvas.setDrawFilter(drawFilter);

      // create a new painter
      paint.setColor(R.color.building);
      paint.setStyle(Paint.Style.FILL);

      // get the layer information of TUD_INF_E0
      WFSServer wfsServer = LocationModelAPI.getSelectedBuilding();

      // check whether WFS data is available
      if (wfsServer == null) {
        // no information available --> nothing has to be drawn
        return;
      }
      ArrayList<WFSLayer> toDrawLayer = wfsServer.getWfsPolygonLayers();
      ArrayList<BuildingPart> toDraw = new ArrayList<BuildingPart>();

      ArrayList<LocatableItem> items = toDrawLayer.get(floor).getItems();
      for (int j = 0; j < items.size(); j++) {
        toDraw.add((BuildingPart) items.get(j));
      }

      // convert polygon points to map points
      Iterator<BuildingPart> toDrawIt = toDraw.iterator();
      while (toDrawIt.hasNext()) {
        // current item
        BuildingPart part = toDrawIt.next();
        // current polygon
        Polygon polygon = (Polygon) part.getGeometry();
        // corner points of this polygon
        de.javagis.jgis.geometry.Point[] points = polygon.asPoints();

        // create new path for every ground
        path = new Path();
        for (int i = 0; i < points.length; i++) {
          // get on of the ground vertices
          double lat = points[i].getY();
          double lon = points[i].getX();
          geoPoint = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6));

          // transform current position to screen coordinates
          screenCoordinates = new Point();
          mapView.getProjection().toPixels(geoPoint, screenCoordinates);

          if (i == 0) {
            // path has to be started --> moveTo
            path.moveTo(screenCoordinates.x, screenCoordinates.y);
          } else {
            // path has to be resumed --> lineTo
            path.lineTo(screenCoordinates.x, screenCoordinates.y);
          }
        }

        // draw the path on bitmapCanvas
        canvas.drawPath(path, paint);
      }
    } catch (Exception e) {
      Log.e("BuildingOverlay", "needs more time to get buildings");
    }
  }
예제 #23
0
  @Override
  public void onDrawScreen(Canvas canvas, int screen, int offset) {
    final DrawFilter filter = canvas.getDrawFilter();
    requestQuality(canvas, GridScreenEffector.DRAW_QUALITY_HIGH);

    final GridScreenContainer container = mContainer;
    final int row = container.getCellRow();
    final int col = container.getCellCol();
    int index = row * col * screen;
    final int end = Math.min(container.getCellCount(), index + row * col);
    final int count = end - index;
    if (count <= 0) {
      return;
    }
    float t = offset * mRatio;
    final float dAngle = -360.f / count;
    final double dRad = Math.toRadians(dAngle);
    final float sin = (float) Math.sin(dRad);
    final float cos = (float) Math.cos(dRad);
    float iconDstX = mRadius, iconDstY = 0, iconDstAngle = -90;
    if (count == 1) {
      iconDstX = 0; // 只有一个的时候把它画在圆心处
      iconDstAngle = -360;
    }
    canvas.translate(mCenterX, mCenterY);
    final boolean isScrollAtEnd = mScroller.isScrollAtEnd();
    if (isScrollAtEnd) {
      t *= 1.5f; // 这样在两端的时候更容易组成圈
    }
    // 以下注释的代码是对cell做包围盒裁剪的,
    // 如果cell的内部结构比较简单,其实优化作用不明显
    float sinWheelAngle = 0, cosWheelAngle = 1;
    if (t > 1) {
      sinWheelAngle = (float) Math.sin((Math.PI * 0.5) * (t - 1));
      cosWheelAngle = (float) Math.cos((Math.PI * 0.5) * (t - 1));
      canvas.rotate(90 * (t - 1));
      t = 1;
    } else if (t < -1) {
      sinWheelAngle = (float) Math.sin((Math.PI * 0.5) * (t + 1));
      cosWheelAngle = (float) Math.cos((Math.PI * 0.5) * (t + 1));
      canvas.rotate(90 * (t + 1));
      t = 1;
    } else if (t < 0) {
      t = -t;
    }
    float t1 = t, t2 = t;
    if (isScrollAtEnd) {
      // 修改插值方式,使在两端恢复时动作更平滑
      t1 = ACC_INTERPOLATOR.getInterpolation(t);
      t2 = DEC_INTERPOLATOR.getInterpolation(t);
    }
    final int cellWidth = container.getCellWidth();
    final int cellHeight = container.getCellHeight();
    final int paddingLeft = container.getPaddingLeft();
    final int paddingTop = container.getPaddingTop();
    final int cellCenterX = cellWidth / 2;
    final int cellCenterY = cellHeight / 2;
    final int cellRadius = (int) (Math.hypot(cellWidth, cellHeight) * 0.5) + 2;
    // 计算物理屏幕在当前坐标系的左右边界值
    final float screenLeft = -mCenterX - offset;
    final float screenRight = mCenterX - offset;
    for (int i = 0, cellY = paddingTop + cellCenterY; i < row && index < end; ++i) {
      for (int j = 0, cellX = paddingLeft + cellCenterX; j < col && index < end; ++j, ++index) {
        final float x = interpolate(cellX - mCenterX, iconDstX, t1);
        final float y = interpolate(cellY - mCenterY, iconDstY, t1);
        final float x2 = x * cosWheelAngle - y * sinWheelAngle;
        if (x2 - cellRadius < screenRight && x2 + cellRadius >= screenLeft) {
          final float a = interpolate(0, iconDstAngle, t2);
          canvas.save();
          canvas.translate(x, y);
          canvas.rotate(a);
          canvas.translate(-cellCenterX, -cellCenterY);
          container.drawGridCell(canvas, index);
          canvas.restore();
        }
        final float xBak = iconDstX;
        iconDstX = cos * xBak - sin * iconDstY;
        iconDstY = sin * xBak + cos * iconDstY;
        iconDstAngle += dAngle;
        cellX += cellWidth;
      }
      cellY += cellHeight;
    }
    canvas.setDrawFilter(filter); // restore filter
  }
예제 #24
0
  @SuppressLint("DrawAllocation")
  @Override
  protected void onDraw(Canvas canvas) {
    if (isCompleted) {
      canvas.drawBitmap(mapBitmap, imgMatrix, paint);
      canvas.setDrawFilter(pfdf);
      if (isInvalidate) {
        if (isRotate) {}
        if (isScale) {
          float curScale = MapCommonUtil.getMapScale(this);
          if (scaleStep > 0) {
            if (curScale * (1 + scaleStep) > scale) {
              isScale = false;
              isInvalidate = false;
              imgMatrix.postScale(scale / curScale, scale / curScale, scaleDx, scaleDy);
              if (onInvalidataListener != null) {
                onInvalidataListener.onInvalidataEnd(-1);
              }
            }
          } else {
            if (curScale * (1 + scaleStep) < scale) {
              isScale = false;
              isInvalidate = false;
              imgMatrix.postScale(scale / curScale, scale / curScale, scaleDx, scaleDy);
              if (onInvalidataListener != null) {
                onInvalidataListener.onInvalidataEnd(-1);
              }
            }
          }
          if (isScale) {
            imgMatrix.postScale(1 + scaleStep, 1 + scaleStep, scaleDx, scaleDy);
          }
        }

        if (isTranslate) {
          sumX += translateStepX;
          sumY += translateStepY;
          if (Math.abs(sumX) > Math.abs(translateX) && Math.abs(sumY) > Math.abs(translateY)) {
            isTranslate = false;
            isInvalidate = false;
            if (onInvalidataListener != null) {
              onInvalidataListener.onInvalidataEnd(translateFrom);
            }
          }
          if (isTranslate) {
            imgMatrix.postTranslate(translateStepX, translateStepY);
          }
        }
        if (onInvalidataListener != null) {
          onInvalidataListener.onInvalidata();
        }
        invalidate();
      }
      if (isNaviRefresh && !isInvalidate) {
        PathEffect pe1 = new CornerPathEffect(10);
        PathEffect pe2 =
            new PathDashPathEffect(
                makePathDash(), 60 * scale, phase, PathDashPathEffect.Style.ROTATE);
        PathEffect pe = new ComposePathEffect(pe2, pe1);
        paint1.setPathEffect(pe);
        paint1.setStrokeWidth(10f * scale);
        paint2.setPathEffect(pe1);
        paint2.setStrokeWidth(15f * scale);
        if (routeAlpha <= 255 && isNaviMode) {
          paint1.setAlpha(routeAlpha);
          paint2.setAlpha(routeAlpha);
          routeAlpha += 5;
        } else if (!isNaviMode) {
          if (routeAlpha > 0) {
            paint1.setAlpha(routeAlpha);
            paint2.setAlpha(routeAlpha);
            routeAlpha -= 5;
          } else {
            isNaviRefresh = false;
          }
        }
        canvas.drawPath(p1, paint2);
        canvas.drawPath(p1, paint1);
        canvas.save();
        phase = phase - 0.5f * scale;
        invalidate();
      }
    }

    super.onDraw(canvas);
  }
예제 #25
0
 static {
   sCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, Paint.FILTER_BITMAP_FLAG));
 }