Java Code Examples for android.graphics.drawable.Drawable#equals()
The following examples show how to use
android.graphics.drawable.Drawable#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PXDrawableUtil.java From pixate-freestyle-android with Apache License 2.0 | 6 votes |
/** * Check if two Drawables are equal. A regular check for a Drawable equals * just checks for the instance reference, while this check is doing a * deeper equals when dealing with {@link DrawableContainer} instances. In * these cases, the method will run equals on each of the child drawables in * the container (order is importance as well). * * @param d1 * @param d2 * @return <code>true</code> if the drawables are equal, <code>false</code> * otherwise. */ public static boolean isEquals(Drawable d1, Drawable d2) { if (d1 == d2) { return true; } if (d1 == null || d2 == null) { return false; } if (d1 instanceof DrawableContainer && d2 instanceof DrawableContainer) { // Try to match the content of those containers DrawableContainerState containerState1 = (DrawableContainerState) ((DrawableContainer) d1) .getConstantState(); DrawableContainerState containerState2 = (DrawableContainerState) ((DrawableContainer) d2) .getConstantState(); return Arrays.equals(containerState1.getChildren(), containerState2.getChildren()); } return d1.equals(d2); }
Example 2
Source File: DrawableUtils.java From litho with Apache License 2.0 | 5 votes |
/** null safe utility method to check equality of 2 comparable drawables */ public static boolean isEquivalentTo(@Nullable Drawable x, @Nullable Drawable y) { if (x == null) { return y == null; } else if (y == null) { return false; } if (x instanceof ComparableDrawable && y instanceof ComparableDrawable) { return ((ComparableDrawable) x).isEquivalentTo((ComparableDrawable) y); } return x.equals(y); }
Example 3
Source File: PreferenceManager.java From MaterialPreference with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * * <p>The result of this method is only valid for the default {@link Preference} objects, * and custom subclasses which do not override * {@link Preference#onBindViewHolder(PreferenceViewHolder)}. This method also assumes * that if a preference object is being replaced by a new instance, the old instance was * not modified after being removed from its containing {@link PreferenceGroup}.</p> */ @Override public boolean arePreferenceContentsTheSame(Preference p1, Preference p2) { if (p1.getClass() != p2.getClass()) { return false; } if (p1 == p2 && p1.wasDetached()) { // Defensively handle the case where a preference was removed, updated and re-added. // Hopefully this is rare. return false; } if (!TextUtils.equals(p1.getTitle(), p2.getTitle())) { return false; } if (!TextUtils.equals(p1.getSummary(), p2.getSummary())) { return false; } final Drawable p1Icon = p1.getIcon(); final Drawable p2Icon = p2.getIcon(); if (p1Icon != p2Icon && (p1Icon == null || !p1Icon.equals(p2Icon))) { return false; } if (p1.isEnabled() != p2.isEnabled()) { return false; } if (p1.isSelectable() != p2.isSelectable()) { return false; } if (p1 instanceof TwoStatePreference) { if (((TwoStatePreference) p1).isChecked() != ((TwoStatePreference) p2).isChecked()) { return false; } } return !(p1 instanceof DropDownPreference) || p1 == p2; }
Example 4
Source File: CollapsingDrawableHelper.java From AppCompat-Extension-Library with Apache License 2.0 | 5 votes |
/** * Set the drawable to display * * @param drawable */ void setDrawable(Drawable drawable) { if (drawable == null || !drawable.equals(mDrawable)) { mDrawable = drawable; recalculate(); } }