|
1 | 1 | /*
|
2 |
| -* Copyright (C) 2015 Vincent Mi |
| 2 | +* Copyright (C) 2017 Vincent Mi |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
27 | 27 | import android.graphics.drawable.Drawable;
|
28 | 28 | import android.graphics.drawable.LayerDrawable;
|
29 | 29 | import android.net.Uri;
|
30 |
| -import android.os.Build; |
31 | 30 | import android.support.annotation.ColorInt;
|
32 | 31 | import android.support.annotation.DimenRes;
|
33 | 32 | import android.support.annotation.DrawableRes;
|
@@ -164,10 +163,6 @@ public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
|
164 | 163 | updateBackgroundDrawableAttrs(true);
|
165 | 164 |
|
166 | 165 | if (mMutateBackground) {
|
167 |
| - // when setBackground() is called by View constructor, mMutateBackground is not loaded from the attribute, |
168 |
| - // so it's false by default, what doesn't allow to create the RoundedDrawable. At this point, after load |
169 |
| - // mMutateBackground and updated BackgroundDrawable to RoundedDrawable, the View's background drawable needs to |
170 |
| - // be changed to this new drawable. |
171 | 166 | //noinspection deprecation
|
172 | 167 | super.setBackgroundDrawable(mBackgroundDrawable);
|
173 | 168 | }
|
@@ -534,10 +529,22 @@ public void setBorderColor(ColorStateList colors) {
|
534 | 529 | }
|
535 | 530 | }
|
536 | 531 |
|
| 532 | + /** |
| 533 | + * Return true if this view should be oval and always set corner radii to half the height or |
| 534 | + * width. |
| 535 | + * |
| 536 | + * @return if this {@link RoundedImageView} is set to oval. |
| 537 | + */ |
537 | 538 | public boolean isOval() {
|
538 | 539 | return mIsOval;
|
539 | 540 | }
|
540 | 541 |
|
| 542 | + /** |
| 543 | + * Set if the drawable should ignore the corner radii set and always round the source to |
| 544 | + * exactly half the height or width. |
| 545 | + * |
| 546 | + * @param oval if this {@link RoundedImageView} should be oval. |
| 547 | + */ |
541 | 548 | public void setOval(boolean oval) {
|
542 | 549 | mIsOval = oval;
|
543 | 550 | updateDrawableAttrs();
|
@@ -571,10 +578,22 @@ public void setTileModeY(Shader.TileMode tileModeY) {
|
571 | 578 | invalidate();
|
572 | 579 | }
|
573 | 580 |
|
| 581 | + /** |
| 582 | + * If {@code true}, we will also round the background drawable according to the settings on this |
| 583 | + * ImageView. |
| 584 | + * |
| 585 | + * @return whether the background is mutated. |
| 586 | + */ |
574 | 587 | public boolean mutatesBackground() {
|
575 | 588 | return mMutateBackground;
|
576 | 589 | }
|
577 | 590 |
|
| 591 | + /** |
| 592 | + * Set whether the {@link RoundedImageView} should round the background drawable according to |
| 593 | + * the settings in addition to the source drawable. |
| 594 | + * |
| 595 | + * @param mutate true if this view should mutate the background drawable. |
| 596 | + */ |
578 | 597 | public void mutateBackground(boolean mutate) {
|
579 | 598 | if (mMutateBackground == mutate) { return; }
|
580 | 599 |
|
|
0 commit comments