Example usage for android.view View setDrawingCacheBackgroundColor

List of usage examples for android.view View setDrawingCacheBackgroundColor

Introduction

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

Prototype

@Deprecated
public void setDrawingCacheBackgroundColor(@ColorInt int color) 

Source Link

Document

Setting a solid background color for the drawing cache's bitmaps will improve performance and memory usage.

Usage

From source file:Main.java

public static Bitmap convertViewToBitmap(View comBitmap, int width, int height) {
    Bitmap bitmap = null;/*from  ww w. jav a  2 s .c o  m*/
    if (comBitmap != null) {
        comBitmap.clearFocus();
        comBitmap.setPressed(false);

        boolean willNotCache = comBitmap.willNotCacheDrawing();
        comBitmap.setWillNotCacheDrawing(false);

        // Reset the drawing cache background color to fully transparent
        // for the duration of this operation
        int color = comBitmap.getDrawingCacheBackgroundColor();
        comBitmap.setDrawingCacheBackgroundColor(0);
        float alpha = comBitmap.getAlpha();
        comBitmap.setAlpha(1.0f);

        if (color != 0) {
            comBitmap.destroyDrawingCache();
        }

        int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
        comBitmap.measure(widthSpec, heightSpec);
        comBitmap.layout(0, 0, width, height);

        comBitmap.buildDrawingCache();
        Bitmap cacheBitmap = comBitmap.getDrawingCache();
        if (cacheBitmap == null) {
            Log.e("view.ProcessImageToBlur", "failed getViewBitmap(" + comBitmap + ")", new RuntimeException());
            return null;
        }
        bitmap = Bitmap.createBitmap(cacheBitmap);
        // Restore the view
        comBitmap.setAlpha(alpha);
        comBitmap.destroyDrawingCache();
        comBitmap.setWillNotCacheDrawing(willNotCache);
        comBitmap.setDrawingCacheBackgroundColor(color);
    }
    return bitmap;
}

From source file:com.example.nwilde.myfirstapp.settingsactivity.SettingsFragment.java

@Override
public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
    View view = super.onCreateView(paramLayoutInflater, paramViewGroup, paramBundle);
    // TODO: bring in default value
    String theme = mSharedPreferences.getString(SettingsFragment.KEY_PREFS_THEME, "");
    if (theme.equalsIgnoreCase("dark")) {
        view.setDrawingCacheBackgroundColor(getResources().getColor(android.R.color.transparent));
        view.setBackgroundColor(getResources().getColor(R.color.list_background_dark));
    }// w  w  w .  j a v a2 s  .co m
    return view;
}

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);/* ww  w . java2s.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(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:com.actionbarsherlock.internal.widget.IcsListPopupWindow.java

private int measureHeightOfChildren(int widthMeasureSpec, int startPosition, int endPosition,
        final int maxHeight, int disallowPartialChildPosition) {

    final ListAdapter adapter = mAdapter;
    if (adapter == null) {
        return mDropDownList.getListPaddingTop() + mDropDownList.getListPaddingBottom();
    }//from  w  w  w . j  a v  a  2s  .  co  m

    // Include the padding of the list
    int returnedHeight = mDropDownList.getListPaddingTop() + mDropDownList.getListPaddingBottom();
    final int dividerHeight = ((mDropDownList.getDividerHeight() > 0) && mDropDownList.getDivider() != null)
            ? mDropDownList.getDividerHeight()
            : 0;
    // The previous height value that was less than maxHeight and contained
    // no partial children
    int prevHeightWithoutPartialChild = 0;
    int i;
    View child;

    // mItemCount - 1 since endPosition parameter is inclusive
    endPosition = (endPosition == -1/*NO_POSITION*/) ? adapter.getCount() - 1 : endPosition;

    for (i = startPosition; i <= endPosition; ++i) {
        child = mAdapter.getView(i, null, mDropDownList);
        if (mDropDownList.getCacheColorHint() != 0) {
            child.setDrawingCacheBackgroundColor(mDropDownList.getCacheColorHint());
        }

        measureScrapChild(child, i, widthMeasureSpec);

        if (i > 0) {
            // Count the divider for all but one child
            returnedHeight += dividerHeight;
        }

        returnedHeight += child.getMeasuredHeight();

        if (returnedHeight >= maxHeight) {
            // We went over, figure out which height to return.  If returnedHeight > maxHeight,
            // then the i'th position did not fit completely.
            return (disallowPartialChildPosition >= 0) // Disallowing is enabled (> -1)
                    && (i > disallowPartialChildPosition) // We've past the min pos
                    && (prevHeightWithoutPartialChild > 0) // We have a prev height
                    && (returnedHeight != maxHeight) // i'th child did not fit completely
                            ? prevHeightWithoutPartialChild
                            : maxHeight;
        }

        if ((disallowPartialChildPosition >= 0) && (i >= disallowPartialChildPosition)) {
            prevHeightWithoutPartialChild = returnedHeight;
        }
    }

    // At this point, we went through the range of children, and they each
    // completely fit, so return the returnedHeight
    return returnedHeight;
}

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

/**
 * View??bitmap/*from  w w w . j  a  v  a 2s . com*/
 * 
 * @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: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 w w w  .  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(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./*  w  ww.  j  ava2 s .  c  o  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.app.blockydemo.ui.adapter.BrickAdapter.java

@Override
public void onClick(final View view) {
    if (!viewSwitchLock.tryLock()) {
        return;// w ww  .j  a  v  a2s. co  m
    }

    animatedBricks.clear();
    final int itemPosition = calculateItemPositionAndTouchPointY(view);
    final List<CharSequence> items = new ArrayList<CharSequence>();

    if (brickList.get(itemPosition) instanceof ScriptBrick) {
        int scriptIndex = getScriptIndexFromProject(itemPosition);
        ProjectManager.getInstance().setCurrentScript(sprite.getScript(scriptIndex));
    }

    if (!(brickList.get(itemPosition) instanceof DeadEndBrick)
            && !(brickList.get(itemPosition) instanceof ScriptBrick)) {
        items.add(context.getText(R.string.brick_context_dialog_move_brick));
    }
    if (brickList.get(itemPosition) instanceof NestingBrick) {
        items.add(context.getText(R.string.brick_context_dialog_animate_bricks));
    }
    if (!(brickList.get(itemPosition) instanceof ScriptBrick)) {
        items.add(context.getText(R.string.brick_context_dialog_copy_brick));
        items.add(context.getText(R.string.brick_context_dialog_delete_brick));
    } else {
        items.add(context.getText(R.string.brick_context_dialog_edit_script_name));
        items.add(context.getText(R.string.brick_context_dialog_delete_script));
    }
    if (brickList.get(itemPosition) instanceof FormulaBrick) {
        items.add(context.getText(R.string.brick_context_dialog_formula_edit_brick));
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    boolean drawingCacheEnabled = view.isDrawingCacheEnabled();
    view.setDrawingCacheEnabled(true);
    view.setDrawingCacheBackgroundColor(Color.TRANSPARENT);
    view.buildDrawingCache(true);

    if (view.getDrawingCache() != null) {
        Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
        view.setDrawingCacheEnabled(drawingCacheEnabled);

        ImageView imageView = dragAndDropListView.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_move_brick))) {
                view.performLongClick();
            } else if (clickedItemText.equals(context.getText(R.string.brick_context_dialog_copy_brick))) {
                copyBrickListAndProject(itemPosition);
            } else if (clickedItemText.equals(context.getText(R.string.brick_context_dialog_delete_brick))
                    || clickedItemText.equals(context.getText(R.string.brick_context_dialog_delete_script))) {
                showConfirmDeleteDialog(itemPosition);
            } else if (clickedItemText.equals(context.getText(R.string.brick_context_dialog_animate_bricks))) {
                int itemPosition = calculateItemPositionAndTouchPointY(view);
                Brick brick = brickList.get(itemPosition);
                if (brick instanceof NestingBrick) {
                    List<NestingBrick> list = ((NestingBrick) brick).getAllNestingBrickParts(true);
                    for (Brick tempBrick : list) {
                        animatedBricks.add(tempBrick);
                    }
                }
                notifyDataSetChanged();
            } else if (clickedItemText
                    .equals(context.getText(R.string.brick_context_dialog_formula_edit_brick))) {

                if (brickList.get(itemPosition) instanceof FormulaBrick) {
                    FormulaEditorFragment.showFragment(view, brickList.get(itemPosition),
                            ((FormulaBrick) brickList.get(itemPosition)).getFormula());
                }
            } else if (clickedItemText
                    .equals(context.getText(R.string.brick_context_dialog_edit_script_name))) {
                ScriptNameDialog dialog2 = new ScriptNameDialog(
                        ProjectManager.getInstance().getCurrentScript());
                dialog2.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                        ScriptNameDialog.DIALOG_FRAGMENT_TAG);
                initBrickList();
                notifyDataSetChanged();
                notifyDataSetInvalidated();
            }
        }
    });
    AlertDialog alertDialog = builder.create();

    if ((selectMode == ListView.CHOICE_MODE_NONE)) {
        alertDialog.show();
    }
}

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

Bitmap getViewBitmap(View v) {
    v.clearFocus();// ww  w .ja v  a2s  . 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:org.chinenv.onroad.loopview.LoopViewPager.java

Bitmap getViewBitmap(View v) {
    v.clearFocus();/*from   w  ww  .j  a  v  a2 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;
}