當前位置: 首頁>>代碼示例>>Java>>正文


Java Canvas.isHardwareAccelerated方法代碼示例

本文整理匯總了Java中android.graphics.Canvas.isHardwareAccelerated方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.isHardwareAccelerated方法的具體用法?Java Canvas.isHardwareAccelerated怎麽用?Java Canvas.isHardwareAccelerated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.Canvas的用法示例。


在下文中一共展示了Canvas.isHardwareAccelerated方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(final Canvas canvas) {
    super.onDraw(canvas);
    if (canvas.isHardwareAccelerated()) {
        onDrawKeyboard(canvas);
        return;
    }

    final boolean bufferNeedsUpdates = mInvalidateAllKeys || !mInvalidatedKeys.isEmpty();
    if (bufferNeedsUpdates || mOffscreenBuffer == null) {
        if (maybeAllocateOffscreenBuffer()) {
            mInvalidateAllKeys = true;
            // TODO: Stop using the offscreen canvas even when in software rendering
            mOffscreenCanvas.setBitmap(mOffscreenBuffer);
        }
        onDrawKeyboard(mOffscreenCanvas);
    }
    canvas.drawBitmap(mOffscreenBuffer, 0.0f, 0.0f, null);
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:20,代碼來源:KeyboardView.java

示例2: clipCanvasWithinBorderBox

import android.graphics.Canvas; //導入方法依賴的package包/類
public static void clipCanvasWithinBorderBox(View targetView, Canvas canvas) {
  Drawable drawable;
  /* According to https://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported
    API 18 or higher supports clipPath to canvas based on hardware acceleration.
   */
  if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 ||
       !canvas.isHardwareAccelerated()) &&
      ((drawable = targetView.getBackground()) instanceof BorderDrawable)) {
    BorderDrawable borderDrawable = (BorderDrawable) drawable;
    if(borderDrawable.isRounded()) {
      Path path = borderDrawable.getContentPath(
          new RectF(0, 0, targetView.getWidth(), targetView.getHeight()));
      canvas.clipPath(path);
    }
  }
}
 
開發者ID:erguotou520,項目名稱:weex-uikit,代碼行數:17,代碼來源:WXViewUtils.java

示例3: isClipPathSupported

import android.graphics.Canvas; //導入方法依賴的package包/類
@SuppressLint("NewApi")
private boolean isClipPathSupported(Canvas canvas) {
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return false;
    } else if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        || Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        return true;
    } else {
        return !canvas.isHardwareAccelerated();
    }
}
 
開發者ID:mityung,項目名稱:XERUNG,代碼行數:12,代碼來源:HighlightView.java

示例4: draw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
    //draw only on system's hardware accelerated canvas
    if (canvas.isHardwareAccelerated()) {
        blurController.drawBlurredContent(canvas);
        drawColorOverlay(canvas);
        super.draw(canvas);
    } else if (!isHardwareAccelerated()) {
        //if view is in a not hardware accelerated window, don't draw blur
        super.draw(canvas);
    }
}
 
開發者ID:KnIfER,項目名稱:wangyi-Lyric-Parser,代碼行數:13,代碼來源:BlurView.java

示例5: drawBackground

import android.graphics.Canvas; //導入方法依賴的package包/類
public void drawBackground(Context context, Canvas canvas) {
    mPaint.setStyle(Paint.Style.FILL);

    int alpha = (int) Math.min(MAX_BG_OPACITY, BG_OPACITY * mColorMultiplier);

    //set the theme attributes to the folder preview circle (stroke and inner bg)
    int accent = ThemeUtils.getColorAccent(context);
    int defaultColor = PreferencesState.isDarkThemeEnabled(context)? Color.argb(alpha, BG_INTENSITY_DARK, BG_INTENSITY_DARK, BG_INTENSITY_DARK) : Color.argb(alpha, BG_INTENSITY, BG_INTENSITY, BG_INTENSITY);
    int color = PreferencesState.areColoredFoldersEnabled(context)? ColorUtils.setAlphaComponent(accent, alpha) : defaultColor;

    mPaint.setColor(color);

    drawCircle(canvas, 0 /* deltaRadius */);

    // Draw shadow.
    if (mShadowShader == null) {
        return;
    }
    float radius = getScaledRadius();
    float shadowRadius = radius + mStrokeWidth;
    mPaint.setColor(Color.BLACK);
    int offsetX = getOffsetX();
    int offsetY = getOffsetY();
    final int saveCount;
    if (canvas.isHardwareAccelerated()) {
        saveCount = canvas.saveLayer(offsetX - mStrokeWidth, offsetY,
                offsetX + radius + shadowRadius, offsetY + shadowRadius + shadowRadius,
                null, Canvas.CLIP_TO_LAYER_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);

    } else {
        saveCount = canvas.save(Canvas.CLIP_SAVE_FLAG);
        clipCanvasSoftware(canvas, Region.Op.DIFFERENCE);
    }

    mShaderMatrix.setScale(shadowRadius, shadowRadius);
    mShaderMatrix.postTranslate(radius + offsetX, shadowRadius + offsetY);
    mShadowShader.setLocalMatrix(mShaderMatrix);
    mPaint.setShader(mShadowShader);
    canvas.drawPaint(mPaint);
    mPaint.setShader(null);

    if (canvas.isHardwareAccelerated()) {
        mPaint.setXfermode(mShadowPorterDuffXfermode);
        canvas.drawCircle(radius + offsetX, radius + offsetY, radius, mPaint);
        mPaint.setXfermode(null);
    }

    canvas.restoreToCount(saveCount);
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:50,代碼來源:FolderIcon.java

示例6: dispatchDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);

    if (mReferenceDrawable != null) {
        computePreviewDrawingParams(mReferenceDrawable);
    }

    if (!mBackground.drawingDelegated()) {
        mBackground.drawBackground(mContext, canvas);
    }

    if (mFolder == null) return;
    if (mFolder.getItemCount() == 0 && !mAnimating) return;

    final int saveCount;

    if (canvas.isHardwareAccelerated()) {
        saveCount = canvas.saveLayer(0, 0, getWidth(), getHeight(), null,
                Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG);
    } else {
        saveCount = canvas.save(Canvas.CLIP_SAVE_FLAG);
        if (mPreviewLayoutRule.clipToBackground()) {
            mBackground.clipCanvasSoftware(canvas, Region.Op.INTERSECT);
        }
    }

    // The items are drawn in coordinates relative to the preview offset
    canvas.translate(mBackground.basePreviewOffsetX, mBackground.basePreviewOffsetY);

    // The first item should be drawn last (ie. on top of later items)
    for (int i = mDrawingParams.size() - 1; i >= 0; i--) {
        PreviewItemDrawingParams p = mDrawingParams.get(i);
        if (!p.hidden) {
            drawPreviewItem(canvas, p);
        }
    }
    canvas.translate(-mBackground.basePreviewOffsetX, -mBackground.basePreviewOffsetY);

    if (mPreviewLayoutRule.clipToBackground() && canvas.isHardwareAccelerated()) {
        mBackground.clipCanvasHardware(canvas);
    }
    canvas.restoreToCount(saveCount);

    if (mPreviewLayoutRule.clipToBackground() && !mBackground.drawingDelegated()) {
        mBackground.drawBackgroundStroke(mContext, canvas);
    }

    if ((mBadgeInfo != null && mBadgeInfo.hasBadge()) || mBadgeScale > 0) {
        int offsetX = mBackground.getOffsetX();
        int offsetY = mBackground.getOffsetY();
        int previewSize = (int) (mBackground.previewSize * mBackground.mScale);
        mTempBounds.set(offsetX, offsetY, offsetX + previewSize, offsetY + previewSize);

        // If we are animating to the accepting state, animate the badge out.
        float badgeScale = Math.max(0, mBadgeScale - mBackground.getScaleProgress());
        mTempSpaceForBadgeOffset.set(getWidth() - mTempBounds.right, mTempBounds.top);
        IconPalette badgePalette = IconPalette.getFolderBadgePalette(getResources());
        mBadgeRenderer.draw(canvas, badgePalette, mBadgeInfo, mTempBounds,
                badgeScale, mTempSpaceForBadgeOffset);
    }
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:63,代碼來源:FolderIcon.java

示例7: draw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
    final Rect bounds = getBounds();
    int drawableWidth = bounds.width();
    int drawableHeight = bounds.height();
    Bitmap bitmap = null;
    if (sBitmapCache != null) {
        bitmap = sBitmapCache.get();
    }
    if (bitmap != null) {
        final int bitmapWidth = bitmap.getWidth();
        final int bitmapHeight = bitmap.getHeight();
        // Invalidate the cache if this drawable is bigger and we can still create a bigger
        // cache.
        if (drawableWidth > bitmapWidth
                && bitmapWidth < VIEWBOX_WIDTH * MAX_CACHED_BITMAP_SCALE) {
            bitmap = null;
        } else if (drawableHeight > bitmapHeight
                && bitmapHeight < VIEWBOX_HEIGHT * MAX_CACHED_BITMAP_SCALE) {
            bitmap = null;
        }
    }

    if (bitmap == null) {
        // Reset the paint so it can be used to draw the paths in renderOnCanvas
        mTempPaint.reset();

        bitmap = createBitmapCache(drawableWidth, drawableHeight);
        sBitmapCache = new SoftReference<>(bitmap);

        // Reset the paint to so it can be used to draw the bitmap
        mTempPaint.reset();
    }

    canvas.save();
    canvas.clipRect(bounds);

    scaleCanvasToBounds(canvas, bitmap, bounds);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
            && canvas.isHardwareAccelerated()) {
        mTempPaint.setColorFilter(mColorFilter);
        canvas.drawBitmap(bitmap, 0, 0, mTempPaint);
    } else {
        // Software renderer doesn't work properly with ColorMatrix filter on ALPHA_8 bitmaps.
        canvas.drawColor(Color.BLACK);
        mTempPaint.setColor(Color.WHITE);
        canvas.drawBitmap(bitmap, 0, 0, mTempPaint);
        canvas.drawColor(mColor);
    }

    canvas.restore();
}
 
開發者ID:Trumeet,項目名稱:SetupWizardLibCompat,代碼行數:53,代碼來源:GlifPatternDrawable.java

示例8: clipCanvasDueToAndroidVersion

import android.graphics.Canvas; //導入方法依賴的package包/類
/**
 * According to https://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported
 API 18 or higher supports clipPath to canvas based on hardware acceleration.
 * @param canvas
 * @return
 */
private static boolean clipCanvasDueToAndroidVersion(Canvas canvas) {
  return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 ||
         !canvas.isHardwareAccelerated();
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:11,代碼來源:WXViewUtils.java


注:本文中的android.graphics.Canvas.isHardwareAccelerated方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。