List of usage examples for android.view View isDrawingCacheEnabled
@Deprecated @ViewDebug.ExportedProperty(category = "drawing") public boolean isDrawingCacheEnabled()
Indicates whether the drawing cache is enabled for this view.
From source file:Main.java
public static Bitmap getScaledScreenshot(final Activity activity, int scaleWidth, int scaleHeight, boolean relativeScaleIfTrue) { final View someView = activity.findViewById(android.R.id.content); final View rootView = someView.getRootView(); final boolean originalCacheState = rootView.isDrawingCacheEnabled(); rootView.setDrawingCacheEnabled(true); rootView.buildDrawingCache(true);//from w w w .ja v a 2s . c o m // We could get a null or zero px bitmap if the rootView hasn't been measured // appropriately, or we grab it before layout. // This is ok, and we should handle it gracefully. final Bitmap original = rootView.getDrawingCache(); Bitmap scaled = null; if (null != original && original.getWidth() > 0 && original.getHeight() > 0) { if (relativeScaleIfTrue) { scaleWidth = original.getWidth() / scaleWidth; scaleHeight = original.getHeight() / scaleHeight; } if (scaleWidth > 0 && scaleHeight > 0) { try { scaled = Bitmap.createScaledBitmap(original, scaleWidth, scaleHeight, false); } catch (OutOfMemoryError error) { Log.i(LOGTAG, "Not enough memory to produce scaled image, returning a null screenshot"); } } } if (!originalCacheState) { rootView.setDrawingCacheEnabled(false); } return scaled; }
From source file:org.catrobat.catroid.ui.fragment.AddBrickFragment.java
private void clickedOnUserBrick(final UserBrick clickedBrick, View view) { final Context context = getActivity(); final List<CharSequence> items = new ArrayList<CharSequence>(); items.add(context.getText(R.string.brick_context_dialog_add_to_script)); items.add(context.getText(R.string.brick_context_dialog_edit_brick)); AlertDialog.Builder builder = new AlertDialog.Builder(context); boolean drawingCacheEnabled = view.isDrawingCacheEnabled(); view.setDrawingCacheEnabled(true);/* w ww. j av a 2s. c om*/ view.setDrawingCacheBackgroundColor(Color.TRANSPARENT); view.buildDrawingCache(true); if (view.getDrawingCache() != null) { Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(drawingCacheEnabled); ImageView imageView = getGlowingBorder(bitmap); builder.setCustomTitle(imageView); } builder.setItems(items.toArray(new CharSequence[items.size()]), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { CharSequence clickedItemText = items.get(item); if (clickedItemText.equals(context.getText(R.string.brick_context_dialog_add_to_script))) { addBrickToScript(clickedBrick); } else if (clickedItemText.equals(context.getText(R.string.brick_context_dialog_edit_brick))) { launchBrickScriptActivityOnBrick(context, clickedBrick); } } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); }
From source file:hku.fyp14017.blencode.ui.fragment.AddBrickFragment.java
private void clickedOnUserBrick(final UserBrick clickedBrick, View view) { final Context context = getActivity(); final List<CharSequence> items = new ArrayList<CharSequence>(); items.add(context.getText(hku.fyp14017.blencode.R.string.brick_context_dialog_add_to_script)); items.add(context.getText(hku.fyp14017.blencode.R.string.brick_context_dialog_edit_brick)); AlertDialog.Builder builder = new AlertDialog.Builder(context); boolean drawingCacheEnabled = view.isDrawingCacheEnabled(); view.setDrawingCacheEnabled(true);//ww w .j a va 2s . co m view.setDrawingCacheBackgroundColor(Color.TRANSPARENT); view.buildDrawingCache(true); if (view.getDrawingCache() != null) { Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(drawingCacheEnabled); ImageView imageView = getGlowingBorder(bitmap); builder.setCustomTitle(imageView); } builder.setItems(items.toArray(new CharSequence[items.size()]), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { CharSequence clickedItemText = items.get(item); if (clickedItemText.equals( context.getText(hku.fyp14017.blencode.R.string.brick_context_dialog_add_to_script))) { addBrickToScript(clickedBrick); } else if (clickedItemText .equals(context.getText(hku.fyp14017.blencode.R.string.brick_context_dialog_edit_brick))) { launchBrickScriptActivityOnBrick(context, clickedBrick); } } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); }
From source file:org.appcelerator.titanium.util.TiUIHelper.java
/** * Draw the view into a bitmap./*from ww w .ja va 2 s .co m*/ */ public static Bitmap getViewBitmap(final View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); if (willNotCache || color != 0) { v.setWillNotCacheDrawing(false); v.setDrawingCacheBackgroundColor(0); v.destroyDrawingCache(); } boolean isDrawinCacheEnabled = v.isDrawingCacheEnabled(); Bitmap bitmap = null; try { v.setDrawingCacheEnabled(true); v.buildDrawingCache(true); bitmap = Bitmap.createBitmap(v.getDrawingCache(true)); } catch (Exception e) { bitmap = null; } v.setDrawingCacheEnabled(isDrawinCacheEnabled); // Restore the view if (willNotCache || color != 0) { v.destroyDrawingCache(); v.setDrawingCacheBackgroundColor(color); v.setWillNotCacheDrawing(willNotCache); } return bitmap; }
From source file:com.digreamon.android.widget.SlidingPaneLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { if (Build.VERSION.SDK_INT >= 11) { // HC return super.drawChild(canvas, child, drawingTime); }/*from w ww . j a va2s.c om*/ final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.dimWhenOffset && mSlideOffset > 0) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } final Bitmap cache = child.getDrawingCache(); canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); return false; } else { if (child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(false); } return super.drawChild(canvas, child, drawingTime); } }
From source file:com.android.dialer.widget.OverlappingPaneLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (mCanSlide && !lp.slideable && mSlideableView != null) { // Clip against the slider; no sense drawing what will immediately be covered. canvas.getClipBounds(mTmpRect);/* www.j a v a 2 s .c o m*/ mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop()); canvas.clipRect(mTmpRect); } if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(false); } result = super.drawChild(canvas, child, drawingTime); } canvas.restoreToCount(save); return result; }
From source file:cn.emagsoftware.ui.BugFixedSlidingPaneLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (mCanSlide && !lp.slideable && mSlideableView != null) { // Clip against the slider; no sense drawing what will immediately be covered. canvas.getClipBounds(mTmpRect);/*from ww w . j a v a2 s. co m*/ mTmpRect.right = Math.min(mTmpRect.right, mSlideableView.getLeft()); canvas.clipRect(mTmpRect); } if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && mSlideOffset > 0) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } final Bitmap cache = child.getDrawingCache(); if (cache != null) { canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); result = false; } else { Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache"); result = super.drawChild(canvas, child, drawingTime); } } else { if (child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(false); } result = super.drawChild(canvas, child, drawingTime); } } canvas.restoreToCount(save); return result; }
From source file:com.aigo.kt03airdemo.ui.view.ResideLayout.java
@Override protected boolean drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(Canvas.ALL_SAVE_FLAG); if (mCanSlide && !lp.slideable && mSlideableView != null) { // Clip against the slider; no sense drawing what will immediately be covered. canvas.scale(1.2f - 0.2f * mSlideOffset, 1.2f - 0.2f * mSlideOffset, child.getRight(), getHeight() / 2); } else {/* w w w .j a v a2s .com*/ assert mSlideableView != null; canvas.scale(1 - mSlideOffset / 3, 1 - mSlideOffset / 3, mSlideableView.getLeft(), getHeight() / 2); ViewCompat.setRotationY(child, -10 * mSlideOffset); } if (!lp.slideable && mSlideOffset == 0) { result = true; } else { if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && mSlideOffset > 0) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } final Bitmap cache = child.getDrawingCache(); if (cache != null) { canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); result = false; } else { Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache"); result = super.drawChild(canvas, child, drawingTime); } } else { if (child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(false); } result = super.drawChild(canvas, child, drawingTime); } } } canvas.restoreToCount(save); return result; }
From source file:com.shouhuan.view.ResideLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(Canvas.ALL_SAVE_FLAG); if (mCanSlide && !lp.slideable && mSlideableView != null) { // Clip against the slider; no sense drawing what will immediately // be covered. canvas.scale(1.2f - 0.2f * mSlideOffset, 1.2f - 0.2f * mSlideOffset, child.getRight(), getHeight() / 2); } else {/*from w w w . j a v a2 s .c om*/ assert mSlideableView != null; canvas.scale(1 - mSlideOffset / 3, 1 - mSlideOffset / 3, mSlideableView.getLeft(), getHeight() / 2); // ViewCompat.setRotationY(child, -10 * mSlideOffset); } if (!lp.slideable && mSlideOffset == 0) { result = true; } else { if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && mSlideOffset > 0) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } final Bitmap cache = child.getDrawingCache(); if (cache != null) { canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); result = false; } else { Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache"); result = super.drawChild(canvas, child, drawingTime); } } else { if (child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(false); } result = super.drawChild(canvas, child, drawingTime); } } } canvas.restoreToCount(save); return result; }
From source file:com.bright.cloudutils.view.ResideLayout.java
@Override protected boolean drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(Canvas.ALL_SAVE_FLAG); if (mCanSlide && !lp.slideable && mSlideableView != null) { // Clip against the slider; no sense drawing what will immediately // be covered. canvas.scale(1.2f - 0.2f * mSlideOffset, 1.2f - 0.2f * mSlideOffset, child.getRight(), getHeight() / 2); } else {/*from ww w . j a v a2 s. c o m*/ assert mSlideableView != null; canvas.scale(1 - mSlideOffset / 3, 1 - mSlideOffset / 3, mSlideableView.getLeft(), getHeight() / 2); ViewCompat.setRotationY(child, -10 * mSlideOffset); } if (!lp.slideable && mSlideOffset == 0) { result = true; } else { if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && mSlideOffset > 0) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } final Bitmap cache = child.getDrawingCache(); if (cache != null) { canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); result = false; } else { Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache"); result = super.drawChild(canvas, child, drawingTime); } } else { if (child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(false); } result = super.drawChild(canvas, child, drawingTime); } } } canvas.restoreToCount(save); return result; }