コード例 #1
0
ファイル: PicassoDrawable.java プロジェクト: sheytoon/Syna
 public void draw(Canvas canvas) {
   if (this.animating) {
     float uptimeMillis =
         ((float) (SystemClock.uptimeMillis() - this.startTimeMillis)) / FADE_DURATION;
     if (uptimeMillis >= 1.0f) {
       this.animating = false;
       this.placeholder = null;
       super.draw(canvas);
     } else {
       if (this.placeholder != null) {
         this.placeholder.draw(canvas);
       }
       super.setAlpha((int) (uptimeMillis * ((float) this.alpha)));
       super.draw(canvas);
       super.setAlpha(this.alpha);
       if (VERSION.SDK_INT <= 10) {
         invalidateSelf();
       }
     }
   } else {
     super.draw(canvas);
   }
   if (this.debugging) {
     drawDebugIndicator(canvas);
   }
 }
コード例 #2
0
ファイル: PicassoDrawable.java プロジェクト: arok/picasso
  @Override
  public void draw(Canvas canvas) {
    if (!animating) {
      super.draw(canvas);
    } else {
      float normalized = (SystemClock.uptimeMillis() - startTimeMillis) / FADE_DURATION;
      if (normalized >= 1f) {
        animating = false;
        placeholder = null;
        super.draw(canvas);
      } else {
        if (placeholder != null) {
          placeholder.draw(canvas);
        }

        int partialAlpha = (int) (alpha * normalized);
        super.setAlpha(partialAlpha);
        super.draw(canvas);
        super.setAlpha(alpha);
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
          invalidateSelf();
        }
      }
    }

    if (debugging) {
      drawDebugIndicator(canvas);
    }
  }
コード例 #3
0
  @Override
  public void draw(Canvas canvas) {
    if (!animating) {
      image.draw(canvas);
    } else {
      float normalized = (SystemClock.uptimeMillis() - startTimeMillis) / FADE_DURATION;
      if (normalized >= 1f) {
        animating = false;
        placeholder = null;
        image.draw(canvas);
      } else {
        if (placeholder != null) {
          placeholder.draw(canvas);
        }

        int alpha = (int) (0xFF * normalized);
        image.setAlpha(alpha);
        image.draw(canvas);
        image.setAlpha(0xFF);
        invalidateSelf();
      }
    }

    if (debugging) {
      drawDebugIndicator(canvas);
    }
  }
コード例 #4
0
  private Bitmap mask(Bitmap image, Bitmap mask) {
    // todo: image wiederholen und skalierung richtig
    Bitmap bitmapOut =
        Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapOut);

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    if (tileImage) {
      BitmapDrawable background = new BitmapDrawable(image);
      // in this case, you want to tile the entire view
      background.setBounds(0, 0, mask.getWidth(), mask.getHeight());
      background.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
      background.draw(canvas);
    } else {
      canvas.drawBitmap(image, (int) (mask.getWidth() * 0.5 - image.getWidth() * 0.5), 0, paint);
    }

    Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    xferPaint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));

    canvas.drawBitmap(mask, 0, 0, xferPaint);
    xferPaint.setXfermode(null);
    return bitmapOut;
  }
コード例 #5
0
ファイル: LogoView.java プロジェクト: FairylandRock/Android
  @Override
  protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);

    canvas.drawColor(color_logobg);
    if (image_logo != null) image_logo.draw(canvas);
  }
コード例 #6
0
 @Override
 protected void dispatchDraw(Canvas canvas) {
   super.dispatchDraw(canvas);
   if (bitmapDrawable != null) {
     Log.d("zyr", "dispatchDraw");
     bitmapDrawable.draw(canvas);
   }
 }
コード例 #7
0
ファイル: DragSortRecycler.java プロジェクト: jsveiga/Slide
 @Override
 public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
   if (floatingItem != null) {
     floatingItem.setAlpha((int) (255 * floatingItemAlpha));
     bgColor.setColor(floatingItemBgColor);
     c.drawRect(floatingItemBounds, bgColor);
     floatingItem.draw(c);
   }
 }
コード例 #8
0
 @Override
 protected void onDraw(Canvas canvas) {
   if (isVisible) {
     selectionArea.setBounds(
         selectionAreaPositionX,
         selectionAreaPositionY,
         SELECTION_AREA_WIDTH + selectionAreaPositionX,
         SELECTION_AREA_HEIGHT + selectionAreaPositionY);
     selectionArea.draw(canvas);
   }
 }
コード例 #9
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    paint.setTypeface(Typeface.create("", Typeface.BOLD));

    paint.setTextSize((int) (textSize * BaseActivity.screen_width));
    paint.setAntiAlias(true);
    paint.setColor(Color.rgb(100, 100, 100));

    float x = Utils.measureX(paint, AVAILABLE_BALANCE_TITLE, maxwidth);
    canvas.drawText(AVAILABLE_BALANCE_TITLE, x, (float) (availableY * maxHeight), paint);

    x = Utils.measureX(paint, ACCOUNT_BALANCE_TITLE, maxwidth);
    canvas.drawText(ACCOUNT_BALANCE_TITLE, x, (float) ((accountY) * maxHeight), paint);
    x = Utils.measureX(paint, ACCOUNT_BALANCE_TITLE, maxwidth);
    canvas.drawText(ACCOUNT_BALANCE_TITLE, x, (float) ((accountY) * maxHeight), paint);

    paint.setColor(Color.BLACK);
    x = Utils.measureX(paint, getAvailableBalanceValue(), maxwidth);
    canvas.drawText(
        getAvailableBalanceValue(), x, (float) ((availableY + line) * maxHeight), paint);

    x = Utils.measureX(paint, getAccountBalanceValue(), maxwidth);
    canvas.drawText(getAccountBalanceValue(), x, (float) ((accountY + line) * maxHeight), paint);

    x = (float) (maxwidth / 2 - paint.measureText(DEPOSIT_TITLE) - placeholderLineDrawableWidth);
    canvas.drawText(DEPOSIT_TITLE, x, (float) ((depositY) * maxHeight), paint);

    x = (float) (maxwidth / 2 + placeholderLineDrawableWidth);
    canvas.drawText(WITHDRAWALS_TITLE, x, (float) ((depositY) * maxHeight), paint);

    x =
        (float)
            (maxwidth / 2 - paint.measureText(getDepositValue()) - placeholderLineDrawableWidth);
    canvas.drawText(getDepositValue(), x, (float) ((depositY + line) * maxHeight), paint);

    x = (float) (maxwidth / 2 + placeholderLineDrawableWidth);

    canvas.drawText(getWidthdrawalsValue(), x, (float) ((depositY + line) * maxHeight), paint);

    if (placeholderLineDrawable != null) {
      canvas.save();
      // canvas.scale((float)xx, (float)xx);
      canvas.translate((float) (o_x), (float) ((depositY) * maxHeight) - paint.getTextSize());
      placeholderLineDrawable.draw(canvas);
      canvas.restore();
    }
  }
コード例 #10
0
  @Override
  public View getChildView(
      int groupPosition,
      int childPosition,
      boolean isLastChild,
      View convertView,
      ViewGroup parent) {
    View view = getCustomChildView();

    TextView titleView = (TextView) view.findViewById(R.id.HistoryRow_Title);

    HistoryItem item = (HistoryItem) getChild(groupPosition, childPosition);
    titleView.setText(item.getTitle());

    TextView urlView = (TextView) view.findViewById(R.id.HistoryRow_Url);
    urlView.setText(item.getUrl());

    CheckBox bookmarkStar = (CheckBox) view.findViewById(R.id.HistoryRow_BookmarkStar);

    bookmarkStar.setTag(item.getId());

    bookmarkStar.setOnCheckedChangeListener(null);
    bookmarkStar.setChecked(item.isBookmark());
    bookmarkStar.setOnCheckedChangeListener(mBookmarkStarChangeListener);

    ImageView faviconView = (ImageView) view.findViewById(R.id.HistoryRow_Thumbnail);
    Bitmap favicon = item.getFavicon();
    if (favicon != null) {
      BitmapDrawable icon = new BitmapDrawable(favicon);

      Bitmap bm = Bitmap.createBitmap(mFaviconSize, mFaviconSize, Bitmap.Config.ARGB_4444);
      Canvas canvas = new Canvas(bm);

      icon.setBounds(0, 0, mFaviconSize, mFaviconSize);
      icon.draw(canvas);

      faviconView.setImageBitmap(bm);
    } else {
      faviconView.setImageResource(R.drawable.fav_icn_unknown);
    }

    return view;
  }
コード例 #11
0
 public final void draw(Canvas paramCanvas) {
   if ((getBitmap() != null) && (!getBitmap().isRecycled())) {
     super.draw(paramCanvas);
   }
 }
コード例 #12
0
ファイル: WrapperDrawable.java プロジェクト: sazoo/TweetLanes
 @Override
 public void draw(Canvas canvas) {
   mDrawable.draw(canvas);
 }
コード例 #13
0
  public Bitmap generateWidgetPreview(
      ComponentName provider,
      int previewImage,
      int iconId,
      int cellHSpan,
      int cellVSpan,
      int maxPreviewWidth,
      int maxPreviewHeight,
      Bitmap preview,
      int[] preScaledWidthOut) {
    // Load the preview image if possible
    String packageName = provider.getPackageName();
    if (maxPreviewWidth < 0) maxPreviewWidth = Integer.MAX_VALUE;
    if (maxPreviewHeight < 0) maxPreviewHeight = Integer.MAX_VALUE;

    Drawable drawable = null;
    if (previewImage != 0) {
      drawable = mPackageManager.getDrawable(packageName, previewImage, null);
      if (drawable == null) {
        Log.w(
            TAG,
            "Can't load widget preview drawable 0x"
                + Integer.toHexString(previewImage)
                + " for provider: "
                + provider);
      }
    }

    int previewWidth;
    int previewHeight;
    Bitmap defaultPreview = null;
    boolean widgetPreviewExists = (drawable != null);
    if (widgetPreviewExists) {
      previewWidth = drawable.getIntrinsicWidth();
      previewHeight = drawable.getIntrinsicHeight();
    } else {
      // Generate a preview image if we couldn't load one
      if (cellHSpan < 1) cellHSpan = 1;
      if (cellVSpan < 1) cellVSpan = 1;

      BitmapDrawable previewDrawable =
          (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.widget_tile);
      final int previewDrawableWidth = previewDrawable.getIntrinsicWidth();
      final int previewDrawableHeight = previewDrawable.getIntrinsicHeight();
      previewWidth = previewDrawableWidth * cellHSpan;
      previewHeight = previewDrawableHeight * cellVSpan;

      defaultPreview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888);
      final Canvas c = mCachedAppWidgetPreviewCanvas.get();
      c.setBitmap(defaultPreview);
      previewDrawable.setBounds(0, 0, previewWidth, previewHeight);
      previewDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
      previewDrawable.draw(c);
      c.setBitmap(null);

      // Draw the icon in the top left corner
      int minOffset = (int) (mAppIconSize * sWidgetPreviewIconPaddingPercentage);
      int smallestSide = Math.min(previewWidth, previewHeight);
      float iconScale = Math.min((float) smallestSide / (mAppIconSize + 2 * minOffset), 1f);

      try {
        Drawable icon = null;
        int hoffset = (int) ((previewDrawableWidth - mAppIconSize * iconScale) / 2);
        int yoffset = (int) ((previewDrawableHeight - mAppIconSize * iconScale) / 2);
        if (iconId > 0) icon = mIconCache.getFullResIcon(packageName, iconId);
        if (icon != null) {
          renderDrawableToBitmap(
              icon,
              defaultPreview,
              hoffset,
              yoffset,
              (int) (mAppIconSize * iconScale),
              (int) (mAppIconSize * iconScale));
        }
      } catch (Resources.NotFoundException e) {
      }
    }

    // Scale to fit width only - let the widget preview be clipped in the
    // vertical dimension
    float scale = 1f;
    if (preScaledWidthOut != null) {
      preScaledWidthOut[0] = previewWidth;
    }
    if (previewWidth > maxPreviewWidth) {
      scale = maxPreviewWidth / (float) previewWidth;
    }
    if (scale != 1f) {
      previewWidth = (int) (scale * previewWidth);
      previewHeight = (int) (scale * previewHeight);
    }

    // If a bitmap is passed in, we use it; otherwise, we create a bitmap of the right size
    if (preview == null) {
      preview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888);
    }

    // Draw the scaled preview into the final bitmap
    int x = (preview.getWidth() - previewWidth) / 2;
    if (widgetPreviewExists) {
      renderDrawableToBitmap(drawable, preview, x, 0, previewWidth, previewHeight);
    } else {
      final Canvas c = mCachedAppWidgetPreviewCanvas.get();
      final Rect src = mCachedAppWidgetPreviewSrcRect.get();
      final Rect dest = mCachedAppWidgetPreviewDestRect.get();
      c.setBitmap(preview);
      src.set(0, 0, defaultPreview.getWidth(), defaultPreview.getHeight());
      dest.set(x, 0, x + previewWidth, previewHeight);

      Paint p = mCachedAppWidgetPreviewPaint.get();
      if (p == null) {
        p = new Paint();
        p.setFilterBitmap(true);
        mCachedAppWidgetPreviewPaint.set(p);
      }
      c.drawBitmap(defaultPreview, src, dest, p);
      c.setBitmap(null);
    }
    return preview;
  }
コード例 #14
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.translate(ProgramTableLayoutConstants.PADDING_SIDE, 0);

    TextPaint toUseForTimeAndTitle = ProgramTableLayoutConstants.NOT_EXPIRED_TITLE_PAINT;
    TextPaint toUseForGenreAndEpisode = ProgramTableLayoutConstants.NOT_EXPIRED_GENRE_EPISODE_PAINT;
    TextPaint toUseForPictureCopyright =
        ProgramTableLayoutConstants.NOT_EXPIRED_PICTURE_COPYRIGHT_PAINT;

    if (isExpired()) {
      toUseForTimeAndTitle = ProgramTableLayoutConstants.EXPIRED_TITLE_PAINT;
      toUseForGenreAndEpisode = ProgramTableLayoutConstants.EXPIRED_GENRE_EPISODE_PAINT;
      toUseForPictureCopyright = ProgramTableLayoutConstants.EXPIRED_PICTURE_COPYRIGHT_PAINT;
    }

    // draw start time
    canvas.drawText(
        mStartTimeString,
        0,
        ProgramTableLayoutConstants.BIG_MAX_FONT_HEIGHT
            - ProgramTableLayoutConstants.BIG_FONT_DESCEND,
        toUseForTimeAndTitle);

    canvas.translate(mStartTimeBounds.width() + ProgramTableLayoutConstants.TIME_TITLE_GAP, 0);

    String[] lines = mTitle.split("\n");

    // draw title
    for (int i = 0; i < lines.length; i++) {
      canvas.drawText(
          lines[i],
          0,
          (i + 1) * ProgramTableLayoutConstants.BIG_MAX_FONT_HEIGHT
              - ProgramTableLayoutConstants.BIG_FONT_DESCEND,
          toUseForTimeAndTitle);
    }

    canvas.translate(0, lines.length * ProgramTableLayoutConstants.BIG_MAX_FONT_HEIGHT);

    // draw picture copyright and picture
    if (mPictureCopyright != null && mPicture != null) {
      mPicture.draw(canvas);

      canvas.translate(0, mPicture.getBounds().height());

      lines = mPictureCopyright.split("\n");

      for (int i = 0; i < lines.length; i++) {
        canvas.drawText(
            lines[i],
            0,
            (i + 1) * ProgramTableLayoutConstants.SUPER_SMALL_MAX_FONT_HEIGHT
                - ProgramTableLayoutConstants.SUPER_SMALL_FONT_DESCEND,
            toUseForPictureCopyright);
      }

      canvas.translate(0, lines.length * ProgramTableLayoutConstants.SUPER_SMALL_MAX_FONT_HEIGHT);
    }

    // draw additonal infos
    if (mCategoriesString != null) {
      // lines = mInfoString.split("\n");

      final int oldColor = toUseForPictureCopyright.getColor();

      final String separator = ",";
      final float separatorWidth = toUseForPictureCopyright.measureText(separator);

      for (int i = 0; i < mCategoriesString.length; i++) {
        canvas.save();

        for (Iterator<ColorEntry> it = mCategoriesString[i].getEntries(); it.hasNext(); ) {
          ColorEntry entry = it.next();

          Integer color = entry.getColor();

          if (color != null && !isExpired()) {
            toUseForPictureCopyright.setColor(color.intValue());
          } else {
            toUseForPictureCopyright.setColor(oldColor);
          }

          canvas.drawText(
              entry.getText(),
              0,
              (i + 1) * ProgramTableLayoutConstants.SUPER_SMALL_MAX_FONT_HEIGHT
                  - ProgramTableLayoutConstants.SUPER_SMALL_FONT_DESCEND,
              toUseForPictureCopyright);

          canvas.translate(entry.measure(toUseForPictureCopyright), 0);

          if (entry.needsSeparator()) {
            toUseForPictureCopyright.setColor(oldColor);

            canvas.drawText(
                separator,
                0,
                (i + 1) * ProgramTableLayoutConstants.SUPER_SMALL_MAX_FONT_HEIGHT
                    - ProgramTableLayoutConstants.SUPER_SMALL_FONT_DESCEND,
                toUseForPictureCopyright);
            canvas.translate(separatorWidth, 0);
          }
        }

        canvas.restore();
        /*
        String first = lines[i].substring(0, lines[i].length()/2);
        String second = lines[i].substring(lines[i].length()/2);

        canvas.save();

        toUseForPictureCopyright.setColor(Color.BLUE);

        canvas.drawText(first, 0, (i+1) * ProgramTableLayoutConstants.SUPER_SMALL_MAX_FONT_HEIGHT - ProgramTableLayoutConstants.SUPER_SMALL_FONT_DESCEND, toUseForPictureCopyright);

        canvas.translate(toUseForPictureCopyright.measureText(first), 0);

        toUseForPictureCopyright.setColor(Color.RED);

        canvas.drawText(second, 0, (i+1) * ProgramTableLayoutConstants.SUPER_SMALL_MAX_FONT_HEIGHT - ProgramTableLayoutConstants.SUPER_SMALL_FONT_DESCEND, toUseForPictureCopyright);

        canvas.restore();*/
      }

      toUseForPictureCopyright.setColor(oldColor);

      canvas.translate(
          0, mCategoriesString.length * ProgramTableLayoutConstants.SUPER_SMALL_MAX_FONT_HEIGHT);
    }

    // draw genre
    if (mGenre != null) {
      lines = mGenre.split("\n");

      for (int i = 0; i < lines.length; i++) {
        canvas.drawText(
            lines[i],
            0,
            (i + 1) * ProgramTableLayoutConstants.SMALL_MAX_FONT_HEIGHT
                - ProgramTableLayoutConstants.SMALL_FONT_DESCEND,
            toUseForGenreAndEpisode);
      }

      canvas.translate(0, lines.length * ProgramTableLayoutConstants.SMALL_MAX_FONT_HEIGHT);
    }

    // draw episode title
    if (mEpisode != null) {
      lines = mEpisode.split("\n");

      for (int i = 0; i < lines.length; i++) {
        canvas.drawText(
            lines[i],
            0,
            (i + 1) * ProgramTableLayoutConstants.SMALL_MAX_FONT_HEIGHT
                - ProgramTableLayoutConstants.SMALL_FONT_DESCEND,
            toUseForGenreAndEpisode);
      }
    }
  }
コード例 #15
0
ファイル: p.java プロジェクト: JaapSuter/Niets
 public void draw(Canvas paramCanvas) {
   boolean bool = DialogToastListActivity.f;
   super.draw(paramCanvas);
   Paint localPaint = new Paint();
   localPaint.setAntiAlias(true);
   RectF localRectF = new RectF(getBounds());
   if (this.d != null) {
     int i = (int) (13.333333F * j4.a(App.Mb.getApplicationContext()).d);
     int j = (int) (2.0F * i);
     Path localPath = new Path();
     localPath.moveTo(localRectF.left, localRectF.bottom - j);
     localPath.lineTo(localRectF.right, localRectF.bottom - j);
     localPath.lineTo(localRectF.right, localRectF.bottom - this.a);
     localPath.arcTo(
         new RectF(
             localRectF.right - 2.0F * this.a,
             localRectF.bottom - 2.0F * this.a,
             localRectF.right,
             localRectF.bottom),
         0.0F,
         90.0F);
     localPath.lineTo(localRectF.left + this.a, localRectF.bottom);
     localPath.arcTo(
         new RectF(
             localRectF.left,
             localRectF.bottom - 2.0F * this.a,
             localRectF.left + 2.0F * this.a,
             localRectF.bottom),
         90.0F,
         90.0F);
     localPath.lineTo(localRectF.left, localRectF.bottom - j);
     localPaint.setStyle(Paint.Style.FILL);
     if (this.b == 16842919) {
       localPaint.setColor(-1712291840);
       if (!bool) ;
     } else {
       localPaint.setColor(1073741824);
     }
     paramCanvas.drawPath(localPath, localPaint);
     TextPaint localTextPaint = new TextPaint();
     localTextPaint.setAntiAlias(true);
     localTextPaint.setColor(-1);
     localTextPaint.setTextSize(i);
     localTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
     localTextPaint.setTextAlign(Paint.Align.CENTER);
     paramCanvas.drawText(
         TextUtils.ellipsize(
                 this.d, localTextPaint, localRectF.width() - this.a, TextUtils.TruncateAt.END)
             .toString(),
         localRectF.left + localRectF.width() / 2.0F,
         localRectF.bottom - (j - i) / 2,
         localTextPaint);
   }
   localPaint.setStyle(Paint.Style.STROKE);
   localPaint.setStrokeJoin(Paint.Join.ROUND);
   localPaint.setStrokeCap(Paint.Cap.ROUND);
   localRectF.top = (1.0F + localRectF.top);
   localRectF.bottom = (1.0F + localRectF.bottom);
   localPaint.setStrokeWidth(1.5F);
   localPaint.setColor(-1711276033);
   paramCanvas.drawRoundRect(localRectF, this.a, this.a, localPaint);
   localRectF.top -= 1.0F;
   localRectF.bottom -= 1.0F;
   if (this.b == 16842919) {
     localPaint.setColor(-1015808);
     if (!bool) ;
   } else {
     localPaint.setColor(1711276032);
   }
   paramCanvas.drawRoundRect(localRectF, this.a, this.a, localPaint);
   localPaint.setStrokeWidth(1.0F);
   localPaint.setAntiAlias(false);
   if (this.b == 16842919) {
     localPaint.setColor(871399424);
     if (!bool) ;
   } else {
     localPaint.setColor(855638016);
   }
   paramCanvas.drawRoundRect(localRectF, this.a, this.a, localPaint);
 }
コード例 #16
0
  private void drawDrawable(Canvas canvas, Drawable drawable, int alpha) {
    if (drawable instanceof BitmapDrawable) {
      BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;

      Paint paint = bitmapDrawable.getPaint();
      boolean hasFilter = paint != null && paint.getColorFilter() != null;
      if (hasFilter && !isPressed) {
        bitmapDrawable.setColorFilter(null);
      } else if (!hasFilter && isPressed) {
        bitmapDrawable.setColorFilter(
            new PorterDuffColorFilter(0xffdddddd, PorterDuff.Mode.MULTIPLY));
      }
      if (colorFilter != null) {
        bitmapDrawable.setColorFilter(colorFilter);
      }
      if (bitmapShader != null) {
        drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
        if (isVisible) {
          roundRect.set(drawRegion);
          shaderMatrix.reset();
          shaderMatrix.setRectToRect(bitmapRect, roundRect, Matrix.ScaleToFit.FILL);
          bitmapShader.setLocalMatrix(shaderMatrix);
          roundPaint.setAlpha(alpha);
          canvas.drawRoundRect(roundRect, roundRadius, roundRadius, roundPaint);
        }
      } else {
        int bitmapW;
        int bitmapH;
        if (orientation == 90 || orientation == 270) {
          bitmapW = bitmapDrawable.getIntrinsicHeight();
          bitmapH = bitmapDrawable.getIntrinsicWidth();
        } else {
          bitmapW = bitmapDrawable.getIntrinsicWidth();
          bitmapH = bitmapDrawable.getIntrinsicHeight();
        }
        float scaleW = bitmapW / (float) imageW;
        float scaleH = bitmapH / (float) imageH;

        if (isAspectFit) {
          float scale = Math.max(scaleW, scaleH);
          canvas.save();
          bitmapW /= scale;
          bitmapH /= scale;
          drawRegion.set(
              imageX + (imageW - bitmapW) / 2,
              imageY + (imageH - bitmapH) / 2,
              imageX + (imageW + bitmapW) / 2,
              imageY + (imageH + bitmapH) / 2);
          bitmapDrawable.setBounds(drawRegion);
          try {
            bitmapDrawable.setAlpha(alpha);
            bitmapDrawable.draw(canvas);
          } catch (Exception e) {
            if (bitmapDrawable == currentImage && currentKey != null) {
              ImageLoader.getInstance().removeImage(currentKey);
              currentKey = null;
            } else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
              ImageLoader.getInstance().removeImage(currentThumbKey);
              currentThumbKey = null;
            }
            setImage(
                currentImageLocation,
                currentHttpUrl,
                currentFilter,
                currentThumb,
                currentThumbLocation,
                currentThumbFilter,
                currentSize,
                currentExt,
                currentCacheOnly);
            FileLog.e("tmessages", e);
          }
          canvas.restore();
        } else {
          if (Math.abs(scaleW - scaleH) > 0.00001f) {
            canvas.save();
            canvas.clipRect(imageX, imageY, imageX + imageW, imageY + imageH);

            if (orientation != 0) {
              if (centerRotation) {
                canvas.rotate(orientation, imageW / 2, imageH / 2);
              } else {
                canvas.rotate(orientation, 0, 0);
              }
            }

            if (bitmapW / scaleH > imageW) {
              bitmapW /= scaleH;
              drawRegion.set(
                  imageX - (bitmapW - imageW) / 2,
                  imageY,
                  imageX + (bitmapW + imageW) / 2,
                  imageY + imageH);
            } else {
              bitmapH /= scaleW;
              drawRegion.set(
                  imageX,
                  imageY - (bitmapH - imageH) / 2,
                  imageX + imageW,
                  imageY + (bitmapH + imageH) / 2);
            }
            if (orientation == 90 || orientation == 270) {
              int width = (drawRegion.right - drawRegion.left) / 2;
              int height = (drawRegion.bottom - drawRegion.top) / 2;
              int centerX = (drawRegion.right + drawRegion.left) / 2;
              int centerY = (drawRegion.top + drawRegion.bottom) / 2;
              bitmapDrawable.setBounds(
                  centerX - height, centerY - width, centerX + height, centerY + width);
            } else {
              bitmapDrawable.setBounds(drawRegion);
            }
            if (isVisible) {
              try {
                bitmapDrawable.setAlpha(alpha);
                bitmapDrawable.draw(canvas);
              } catch (Exception e) {
                if (bitmapDrawable == currentImage && currentKey != null) {
                  ImageLoader.getInstance().removeImage(currentKey);
                  currentKey = null;
                } else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
                  ImageLoader.getInstance().removeImage(currentThumbKey);
                  currentThumbKey = null;
                }
                setImage(
                    currentImageLocation,
                    currentHttpUrl,
                    currentFilter,
                    currentThumb,
                    currentThumbLocation,
                    currentThumbFilter,
                    currentSize,
                    currentExt,
                    currentCacheOnly);
                FileLog.e("tmessages", e);
              }
            }

            canvas.restore();
          } else {
            canvas.save();
            if (orientation != 0) {
              if (centerRotation) {
                canvas.rotate(orientation, imageW / 2, imageH / 2);
              } else {
                canvas.rotate(orientation, 0, 0);
              }
            }
            drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
            if (orientation == 90 || orientation == 270) {
              int width = (drawRegion.right - drawRegion.left) / 2;
              int height = (drawRegion.bottom - drawRegion.top) / 2;
              int centerX = (drawRegion.right + drawRegion.left) / 2;
              int centerY = (drawRegion.top + drawRegion.bottom) / 2;
              bitmapDrawable.setBounds(
                  centerX - height, centerY - width, centerX + height, centerY + width);
            } else {
              bitmapDrawable.setBounds(drawRegion);
            }
            if (isVisible) {
              try {
                bitmapDrawable.setAlpha(alpha);
                bitmapDrawable.draw(canvas);
              } catch (Exception e) {
                if (bitmapDrawable == currentImage && currentKey != null) {
                  ImageLoader.getInstance().removeImage(currentKey);
                  currentKey = null;
                } else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
                  ImageLoader.getInstance().removeImage(currentThumbKey);
                  currentThumbKey = null;
                }
                setImage(
                    currentImageLocation,
                    currentHttpUrl,
                    currentFilter,
                    currentThumb,
                    currentThumbLocation,
                    currentThumbFilter,
                    currentSize,
                    currentExt,
                    currentCacheOnly);
                FileLog.e("tmessages", e);
              }
            }
            canvas.restore();
          }
        }
      }
    } else {
      drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
      drawable.setBounds(drawRegion);
      if (isVisible) {
        try {
          drawable.setAlpha(alpha);
          drawable.draw(canvas);
        } catch (Exception e) {
          FileLog.e("tmessages", e);
        }
      }
    }
  }
コード例 #17
0
ファイル: HelloDragDropActivity.java プロジェクト: nwtek/aad
    @Override
    public void onDrawShadow(Canvas canvas) {

      mBitmapDrawable.draw(canvas);
    }