Example usage for android.view View getBackground

List of usage examples for android.view View getBackground

Introduction

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

Prototype

public Drawable getBackground() 

Source Link

Document

Gets the background drawable

Usage

From source file:poche.fm.potunes.utils.TintManager.java

public static void tintViewBackground(View view, TintInfo tint) {
    Drawable background;/*from   w  w  w.j  a va 2 s  .  c om*/
    if (view == null || (background = view.getBackground()) == null)
        return;

    if (tint.mHasTintList || tint.mHasTintMode) {
        background.mutate();
        if (background instanceof ColorDrawable) {
            ((ColorDrawable) background).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList
                    .getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor())));
        } else {
            background.setColorFilter(
                    createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null,
                            tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState()));
        }
    } else {
        background.clearColorFilter();
    }

    if (Build.VERSION.SDK_INT <= 23) {
        // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter
        // has changed, so we need to force an invalidation
        background.invalidateSelf();
    }
}

From source file:Main.java

public static void clearDrawableAnimation(View view) {
    if (Build.VERSION.SDK_INT < 21 || view == null) {
        return;/*www .  ja v  a 2  s  .com*/
    }
    Drawable drawable = null;
    if (view instanceof ListView) {
        drawable = ((ListView) view).getSelector();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
        }
    } else {
        drawable = view.getBackground();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
            drawable.jumpToCurrentState();
        }
    }
}

From source file:android.support.v7.testutils.TestUtilsMatchers.java

/**
 * Returns a matcher that matches <code>View</code>s which have background flat-filled
 * with the specific color./*from  w  w w .j a  v  a2 s  .  co  m*/
 */
public static Matcher isBackground(@ColorInt final int color) {
    return new BoundedMatcher<View, View>(View.class) {
        private String failedComparisonDescription;

        @Override
        public void describeTo(final Description description) {
            description.appendText("with background of color: ");

            description.appendText(failedComparisonDescription);
        }

        @Override
        public boolean matchesSafely(final View view) {
            Drawable drawable = view.getBackground();
            if (drawable == null) {
                return false;
            }

            try {
                TestUtils.assertAllPixelsOfColor("", drawable, view.getWidth(), view.getHeight(), false, color,
                        0, true);
                // If we are here, the color comparison has passed.
                failedComparisonDescription = null;
                return true;
            } catch (Throwable t) {
                // If we are here, the color comparison has failed.
                failedComparisonDescription = t.getMessage();
                return false;
            }
        }
    };
}

From source file:com.bilibili.magicasakura.utils.TintManager.java

public static void tintViewBackground(View view, com.bilibili.magicasakura.utils.TintInfo tint) {
    Drawable background;//from  ww w .j ava 2 s .c om
    if (view == null || (background = view.getBackground()) == null)
        return;

    if (tint.mHasTintList || tint.mHasTintMode) {
        background.mutate();
        if (background instanceof ColorDrawable) {
            ((ColorDrawable) background).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList
                    .getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor())));
        } else {
            background.setColorFilter(
                    createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null,
                            tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState()));
        }
    } else {
        background.clearColorFilter();
    }

    if (Build.VERSION.SDK_INT <= 23) {
        // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter
        // has changed, so we need to force an invalidation
        background.invalidateSelf();
    }
}

From source file:com.android.clear.reminder.AnimatorUtils.java

/**
 * @param target the view to be morphed//from   w  w  w .java 2s .  c o m
 * @param from the bounds of the {@code target} before animating
 * @param to the bounds of the {@code target} after animating
 * @return an animator that morphs the {@code target} between the {@code from} bounds and the
 *      {@code to} bounds. Note that it is the *content* bounds that matter here, so padding
 *      insets contributed by the background are subtracted from the views when computing the
 *      {@code target} bounds.
 */
public static Animator getBoundsAnimator(View target, View from, View to) {
    // Fetch the content insets for the views. Content bounds are what matter, not total bounds.
    final Rect targetInsets = new Rect();
    target.getBackground().getPadding(targetInsets);
    final Rect fromInsets = new Rect();
    from.getBackground().getPadding(fromInsets);
    final Rect toInsets = new Rect();
    to.getBackground().getPadding(toInsets);

    // Before animating, the content bounds of target must match the content bounds of from.
    final int startLeft = from.getLeft() - fromInsets.left + targetInsets.left;
    final int startTop = from.getTop() - fromInsets.top + targetInsets.top;
    final int startRight = from.getRight() - fromInsets.right + targetInsets.right;
    final int startBottom = from.getBottom() - fromInsets.bottom + targetInsets.bottom;

    // After animating, the content bounds of target must match the content bounds of to.
    final int endLeft = to.getLeft() - toInsets.left + targetInsets.left;
    final int endTop = to.getTop() - toInsets.top + targetInsets.top;
    final int endRight = to.getRight() - toInsets.right + targetInsets.right;
    final int endBottom = to.getBottom() - toInsets.bottom + targetInsets.bottom;

    return getBoundsAnimator(target, startLeft, startTop, startRight, startBottom, endLeft, endTop, endRight,
            endBottom);
}

From source file:android.support.v7.internal.widget.TintManager.java

public static void tintViewBackground(View view, TintInfo tint) {
    final Drawable background = view.getBackground();
    if (tint.mTintList != null) {
        tintDrawableUsingColorFilter(background,
                tint.mTintList.getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor()),
                tint.mTintMode != null ? tint.mTintMode : DEFAULT_MODE);
    } else {/*from   www  .j av  a  2  s  .  c om*/
        background.clearColorFilter();
    }
}

From source file:Main.java

private static void downEffect(View v) {

    /*ColorMatrix cm = new ColorMatrix(
          new float[] {/*from w  ww . ja va  2  s  . c om*/
                  -1, 0, 0, 0, 255,
                  0, -1, 0, 0, 255,
                  0, 0, -1, 0, 255,
                  0, 0, 0, 1, 0 }
      );
                
      v.getBackground().mutate().setColorFilter(new ColorMatrixColorFilter(cm));*/

    Drawable drwb;
    if (v instanceof ImageView) {
        drwb = ((ImageView) v).getDrawable();
    } else {
        drwb = v.getBackground();
    }

    if (drwb == null)
        return;
    drwb.mutate().setColorFilter(0xffaaaaaa, PorterDuff.Mode.MULTIPLY);

    v.invalidate();
}

From source file:com.hippo.android.animator.AnimatorsBase.java

static Animator recolorBackground(View view, int color) {
    Drawable drawable = view.getBackground();
    if (drawable instanceof ColorDrawable) {
        return recolorBackground(view, ((ColorDrawable) drawable).getColor(), color);
    } else {/* w w  w .jav a2 s.  c o m*/
        return null;
    }
}

From source file:com.android.messaging.ui.animation.ViewGroupItemVerticalExplodeAnimation.java

/**
 * Take a snapshot of the given review, return a Bitmap object that's owned by the caller.
 *///  ww w  . j a v  a  2s.  co  m
static Bitmap snapshotView(final View view) {
    // Save the content of the view into a bitmap.
    final Bitmap viewBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    // Strip the view of its background when taking a snapshot so that things like touch
    // feedback don't get accidentally snapshotted.
    final Drawable viewBackground = view.getBackground();
    ImageUtils.setBackgroundDrawableOnView(view, null);
    view.draw(new Canvas(viewBitmap));
    ImageUtils.setBackgroundDrawableOnView(view, viewBackground);
    return viewBitmap;
}

From source file:com.hippo.android.animator.AnimatorsBase.java

static Animator recolorBackground(View view, int startColor, int endColor) {
    if (startColor != endColor) {
        Drawable drawable = view.getBackground();
        if (drawable instanceof ColorDrawable) {
            ObjectAnimator animator = ObjectAnimator.ofInt((ColorDrawable) drawable,
                    COLOR_DRAWABLE_COLOR_PROPERTY, startColor, endColor);
            animator.setEvaluator(new ArgbEvaluator());
            return animator;
        }//from  w w w  . j ava 2s .c  om
    }
    return null;
}