Example usage for android.view View buildDrawingCache

List of usage examples for android.view View buildDrawingCache

Introduction

In this page you can find the example usage for android.view View buildDrawingCache.

Prototype

@Deprecated
public void buildDrawingCache() 

Source Link

Document

Calling this method is equivalent to calling buildDrawingCache(false).

Usage

From source file:org.androfarsh.widget.DragGridLayout.java

@SuppressWarnings("deprecation")
private static BitmapDrawable createDrawingCache(View view) {
    BitmapDrawable drawable = null;//  www. j a  v  a2  s.c om
    view.buildDrawingCache();
    final Bitmap bitmap = view.getDrawingCache();
    if (bitmap != null) {
        drawable = new BitmapDrawable(Bitmap.createBitmap(bitmap));
        bitmap.recycle();
    }
    view.destroyDrawingCache();
    return drawable;
}

From source file:cc.softwarefactory.lokki.android.fragments.MapViewFragment.java

public Bitmap createDrawableFromView(View view) {

    Log.e(TAG, "createDrawableFromView");
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    view.setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT));
    view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
    view.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
    view.buildDrawingCache();
    Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
            Bitmap.Config.ARGB_8888);/*www.j  a v a2s .  com*/

    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);

    return bitmap;
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * View??bitmap// ww w  .ja v a  2  s.co  m
 * 
 * @param view
 *            View
 * @return Bitmap
 */
public static Bitmap getBitmapFromView2(View view) {

    view.clearFocus();
    view.setPressed(false);

    // false
    boolean willNotCache = view.willNotCacheDrawing();
    view.setWillNotCacheDrawing(false);
    int color = view.getDrawingCacheBackgroundColor();
    view.setDrawingCacheBackgroundColor(0);
    if (color != 0) {
        view.destroyDrawingCache();
    }
    view.buildDrawingCache();
    Bitmap cacheBitmap = view.getDrawingCache();
    if (cacheBitmap == null) {
        if (DEBUG) {
            Log.e(TAG, "failed getViewBitmap(" + view + ")", new RuntimeException());
        }
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
    // Restore the view
    view.destroyDrawingCache();
    view.setWillNotCacheDrawing(willNotCache);
    view.setDrawingCacheBackgroundColor(color);
    return bitmap;
}

From source file:com.bigpigs.fragments.SearchFragment.java

private Bitmap getMarkerBitmapFromView(@DrawableRes int resId) {

    View customMarkerView = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.custom_marker, null);
    ImageView markerImageView = (ImageView) customMarkerView.findViewById(R.id.marker_icon);
    markerImageView.setImageResource(resId);
    customMarkerView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    customMarkerView.layout(0, 0, customMarkerView.getMeasuredWidth(), customMarkerView.getMeasuredHeight());
    customMarkerView.buildDrawingCache();
    Bitmap returnedBitmap = Bitmap.createBitmap(customMarkerView.getMeasuredWidth(),
            customMarkerView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);
    canvas.drawColor(Color.WHITE, PorterDuff.Mode.SRC_IN);
    Drawable drawable = customMarkerView.getBackground();
    if (drawable != null)
        drawable.draw(canvas);//from ww w.j av  a 2s . c o  m
    customMarkerView.draw(canvas);
    return returnedBitmap;
}

From source file:com.android.launcher3.Utilities.java

private static Bitmap takeShot(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);/* w ww  . j  a va2s  . c o m*/
    view.buildDrawingCache();
    Bitmap b1 = view.getDrawingCache();
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;

    int width = activity.getWindowManager().getDefaultDisplay().getWidth();
    int height = activity.getWindowManager().getDefaultDisplay().getHeight();

    Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return b;
}

From source file:com.dycody.android.idealnote.ListFragment.java

/**
 * Retrieves from the single listview note item the element to be zoomed when opening a note
 *///  w  ww.  j a v a 2 s .  co m
private ImageView getZoomListItemView(View view, Note note) {
    if (expandedImageView != null) {
        View targetView = null;
        if (note.getAttachmentsList().size() > 0) {
            targetView = view.findViewById(R.id.attachmentThumbnail);
        }
        if (targetView == null && note.getCategory() != null) {
            targetView = view.findViewById(R.id.category_marker);
        }
        if (targetView == null) {
            targetView = new ImageView(mainActivity);
            targetView.setBackgroundColor(Color.WHITE);
        }
        targetView.setDrawingCacheEnabled(true);
        targetView.buildDrawingCache();
        Bitmap bmp = targetView.getDrawingCache();
        expandedImageView.setBackgroundColor(BitmapUtils.getDominantColor(bmp));
    }
    return expandedImageView;
}

From source file:com.example.android_test.loopviewpager.LoopViewPager.java

Bitmap getViewBitmap(View v) {
    v.clearFocus();//from   ww  w.j a  v  a  2  s  . com
    v.setPressed(false);

    // ??????????
    boolean willNotCache = v.willNotCacheDrawing();
    int color = v.getDrawingCacheBackgroundColor();

    // ???????
    v.setWillNotCacheDrawing(false);

    // ???????
    v.setDrawingCacheBackgroundColor(0);

    // ????
    if (color != 0) {
        v.destroyDrawingCache();
    }

    // ??????
    v.buildDrawingCache();

    // ? Bitmap ?
    Bitmap cacheBitmap = v.getDrawingCache();
    if (cacheBitmap == null) {
        Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
        return null;
    }

    // ? Bitmap ???????? Bitmap ?
    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

    // ??????????
    v.destroyDrawingCache();
    v.setWillNotCacheDrawing(willNotCache);
    v.setDrawingCacheBackgroundColor(color);

    return bitmap;
}

From source file:org.chinenv.onroad.loopview.LoopViewPager.java

Bitmap getViewBitmap(View v) {
    v.clearFocus();//from   w  ww.j a va2 s. c o  m
    v.setPressed(false);

    // ??????????
    boolean willNotCache = v.willNotCacheDrawing();
    int color = v.getDrawingCacheBackgroundColor();

    // ????????
    v.setWillNotCacheDrawing(false);

    // ????????
    v.setDrawingCacheBackgroundColor(0);

    // ?????
    if (color != 0) {
        v.destroyDrawingCache();
    }

    // ??????
    v.buildDrawingCache();

    // ?Bitmap ??
    Bitmap cacheBitmap = v.getDrawingCache();
    if (cacheBitmap == null) {
        Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
        return null;
    }

    // ?Bitmap ???????? Bitmap ?
    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

    // ??????????
    v.destroyDrawingCache();
    v.setWillNotCacheDrawing(willNotCache);
    v.setDrawingCacheBackgroundColor(color);

    return bitmap;
}

From source file:com.baiiu.autoloopviewpager.loopvp.LoopViewPager.java

Bitmap getViewBitmap(View v) {
    v.clearFocus();/*from w w  w .j  a  v  a 2  s  . c o m*/
    v.setPressed(false);

    // ??????????
    boolean willNotCache = v.willNotCacheDrawing();
    int color = v.getDrawingCacheBackgroundColor();

    // ???????
    v.setWillNotCacheDrawing(false);

    // ???????
    v.setDrawingCacheBackgroundColor(0);

    // ????
    if (color != 0) {
        v.destroyDrawingCache();
    }

    // ??????
    v.buildDrawingCache();

    // ? Bitmap ?
    Bitmap cacheBitmap = v.getDrawingCache();
    if (cacheBitmap == null) {
        if (DEBUG)
            Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
        return null;
    }

    // ? Bitmap ???????? Bitmap ?
    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

    // ??????????
    v.destroyDrawingCache();
    v.setWillNotCacheDrawing(willNotCache);
    v.setDrawingCacheBackgroundColor(color);

    return bitmap;
}