Example usage for android.view View getDrawingCache

List of usage examples for android.view View getDrawingCache

Introduction

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

Prototype

@Deprecated
public Bitmap getDrawingCache() 

Source Link

Document

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

Usage

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);//from ww w .ja va 2  s . 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:info.tellmetime.TellmetimeActivity.java

@Override
public boolean onMenuItemClick(MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    case R.id.action_mode:
        if (!mSettings.contains(BACKGROUND_MODE_TOGGLED))
            showToast(R.string.info_toggle_mode);

        toggleMode();//  ww  w .  java  2 s  . c  o  m

        mHider.hide();
        return true;
    case R.id.action_share_screenshot:
        mHider.hideNow();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    View rootView = getWindow().getDecorView().getRootView();
                    rootView.setDrawingCacheEnabled(true);
                    Bitmap screenshot = Bitmap.createBitmap(rootView.getDrawingCache());
                    rootView.setDrawingCacheEnabled(false);

                    showToast(R.string.info_saving_screenshot);

                    ContentValues values = new ContentValues();
                    values.put(MediaStore.Images.Media.TITLE, getString(R.string.app_name));
                    values.put(MediaStore.Images.Media.DISPLAY_NAME, getString(R.string.app_name) + ".jpg");
                    values.put(MediaStore.Images.Media.MIME_TYPE, "image/*");
                    Uri uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

                    OutputStream outputStream;
                    outputStream = getContentResolver().openOutputStream(uri);
                    screenshot.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
                    outputStream.close();
                    screenshot.recycle();

                    Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("image/jpeg");
                    intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
                    String shareText = getString(R.string.app_description)
                            + " Get it at http://tellmetime.info";
                    intent.putExtra(Intent.EXTRA_TEXT, shareText);
                    intent.putExtra(Intent.EXTRA_STREAM, uri);
                    startActivity(Intent.createChooser(intent, "Share via"));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        return true;
    case R.id.action_share_app:
        try {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
            String shareText = getString(R.string.app_description) + " Get it at http://tellmetime.info";
            intent.putExtra(Intent.EXTRA_TEXT, shareText);
            startActivity(Intent.createChooser(intent, "Share via"));
        } catch (Exception ignored) {
        }

        return true;
    case R.id.action_rate:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("market://details?id=info.tellmetime"));
        startActivity(intent);

        return true;
    default:
        return false;
    }
}

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

/**
 * View??bitmap/*from  w w  w  .  j  a  v a 2 s . c  om*/
 * 
 * @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.android.launcher3.Utilities.java

private static Bitmap takeShot(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);//from  w w  w .  ja  v a2s. c om
    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:tv.piratemedia.lightcontroler.controller.java

private File getScreen() {
    Long tsLong = System.currentTimeMillis() / 1000;
    String ts = tsLong.toString();
    String mPath = Environment.getExternalStorageDirectory().toString() + "/bug_report_" + ts + ".jpg";

    // create bitmap screen capture
    Bitmap bitmap;/*from ww  w.j a v  a  2 s  .  c  om*/
    View v1 = getWindow().getDecorView().getRootView();
    v1.setDrawingCacheEnabled(true);
    bitmap = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);

    OutputStream fout = null;
    File imageFile = new File(mPath);

    try {
        fout = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
        fout.flush();
        fout.close();
        return imageFile;
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:org.telegram.ui.GroupCreateActivity.java

public Emoji.XImageSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf = (LayoutInflater) parentActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
    text.setText(Utilities.formatName(user.first_name, user.last_name));

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);//from ww w.j  a  v  a2s.  c o  m
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    Emoji.XImageSpan span = new Emoji.XImageSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.id, span);
    for (ImageSpan sp : allSpans) {
        ssb.append("<<");
        ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    userSelectEditText.setText(ssb);
    userSelectEditText.setSelection(ssb.length());
    return span;
}

From source file:com.yahala.ui.GroupCreateActivity.java

public XImageSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf = (LayoutInflater) parentActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
    String name = Utilities.formatName(user.first_name, user.last_name);
    if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
        name = PhoneFormat.getInstance().format("+" + user.phone);
    }/*from   w w  w  .j  a va  2  s  .c  o m*/
    text.setText(name + ", ");

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    XImageSpan span = new XImageSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.jid, span);
    for (ImageSpan sp : allSpans) {
        ssb.append("<<");
        ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    userSelectEditText.setText(ssb);
    userSelectEditText.setSelection(ssb.length());
    return span;
}

From source file:org.drrickorang.loopback.LoopbackActivity.java

/** Save a screenshot of the main activity. */
void saveScreenShot(Uri uri) {
    ParcelFileDescriptor parcelFileDescriptor = null;
    FileOutputStream outputStream;
    try {/*from  ww w  .  j a  va 2 s.com*/
        parcelFileDescriptor = getApplicationContext().getContentResolver().openFileDescriptor(uri, "w");

        FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
        outputStream = new FileOutputStream(fileDescriptor);

        log("Done creating output stream");

        LinearLayout LL = (LinearLayout) findViewById(R.id.linearLayoutMain);

        View v = LL.getRootView();
        v.setDrawingCacheEnabled(true);
        Bitmap b = v.getDrawingCache();

        //save
        b.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
        parcelFileDescriptor.close();
        v.setDrawingCacheEnabled(false);
    } catch (Exception e) {
        log("Failed to open png file " + e);
    } finally {
        try {
            if (parcelFileDescriptor != null) {
                parcelFileDescriptor.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
            log("Error closing ParcelFile Descriptor");
        }
    }
}

From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    canvas.save();/*  w  ww.j  a v  a 2s  .  c  om*/

    //set matrix to child's transformation
    setChildTransformation(child, mMatrix);

    //Generate child bitmap
    Bitmap bitmap = child.getDrawingCache();

    //initialize canvas state. Child 0,0 coordinates will match canvas 0,0
    canvas.translate(child.getLeft(), child.getTop());

    //set child transformation on canvas
    canvas.concat(mMatrix);

    final Bitmap rfCache = ((CoverFrame) child).mReflectionCache;

    if (mReflectionBackgroundColor != Color.TRANSPARENT) {
        final int top = bitmap.getHeight() + mReflectionGap - 2;
        final float frame = 1.0f;
        mReflectionPaint.setColor(mReflectionBackgroundColor);
        canvas.drawRect(frame, top + frame, rfCache.getWidth() - frame, top + rfCache.getHeight() - frame,
                mReflectionPaint);
    }

    mPaint.reset();
    mPaint.setAntiAlias(true);
    mPaint.setFilterBitmap(true);

    //Draw child bitmap with applied transforms
    canvas.drawBitmap(bitmap, 0.0f, 0.0f, mPaint);

    //Draw reflection
    canvas.drawBitmap(rfCache, 0.0f, bitmap.getHeight() - 2 + mReflectionGap, mPaint);

    canvas.restore();
    return false;
}

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  av a 2  s  .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);
    }
}