当前位置: 首页>>代码示例>>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;未经允许,请勿转载。