summaryrefslogtreecommitdiff
path: root/java/com/android/contacts
diff options
context:
space:
mode:
authorsail <sail@google.com>2017-07-03 10:28:43 -0700
committerEric Erfanian <erfanian@google.com>2017-07-10 10:45:00 -0700
commitce5ad9c817de101f5685d6f63e0a90a02ebc4b2b (patch)
tree5e7cf3797e996e9a100caf310c2355e7b3b47b01 /java/com/android/contacts
parent115a7c9bffc79aff0e9d9215489f5b3f200c94b4 (diff)
Automated g4 rollback of changelist 160696979.
*** Reason for rollback *** Causes crash on launch (b/63252565) *** Original change description *** Fix concurrency issue in constructor. Before: sColors served as the branch to initialize all member variables. Subsequent calls to the constructor after sColors had been initialized, would result in the use of static members that were not yet initialized. Now: We guard each reference with an explicit null check during construct. Members that require synchronized initialization were put into a small synchronized method. This was chosen instead of AtomicReferences, and instead of double check... *** Bug: 63143138 Test: N/A PiperOrigin-RevId: 160837963 Change-Id: I2586f7586c8f39182d64c3b28a59886c5ba94789
Diffstat (limited to 'java/com/android/contacts')
-rw-r--r--java/com/android/contacts/common/lettertiles/LetterTileDrawable.java83
1 files changed, 26 insertions, 57 deletions
diff --git a/java/com/android/contacts/common/lettertiles/LetterTileDrawable.java b/java/com/android/contacts/common/lettertiles/LetterTileDrawable.java
index 5b7dcbe84..5c401fe38 100644
--- a/java/com/android/contacts/common/lettertiles/LetterTileDrawable.java
+++ b/java/com/android/contacts/common/lettertiles/LetterTileDrawable.java
@@ -87,23 +87,23 @@ public class LetterTileDrawable extends Drawable {
/** Default icon scale for vector drawable. */
private static final float VECTOR_ICON_SCALE = 0.7f;
- private static Paint sPaint;
+ /** Reusable components to avoid new allocations */
+ private static final Paint sPaint = new Paint();
private static final Rect sRect = new Rect();
private static final char[] sFirstChar = new char[1];
-
- private static volatile Integer sSpamColor;
- private static volatile Integer sDefaultColor;
- private static volatile Integer sTileFontColor;
- private static volatile Float sLetterToTileRatio;
-
- private static volatile TypedArray sColors;
-
- private static volatile Drawable sDefaultPersonAvatar;
- private static volatile Drawable sDefaultBusinessAvatar;
- private static volatile Drawable sDefaultVoicemailAvatar;
- private static volatile Drawable sDefaultSpamAvatar;
- private static volatile Drawable sDefaultConferenceAvatar;
+ /** Letter tile */
+ private static TypedArray sColors;
+
+ private static int sSpamColor;
+ private static int sDefaultColor;
+ private static int sTileFontColor;
+ private static float sLetterToTileRatio;
+ private static Drawable sDefaultPersonAvatar;
+ private static Drawable sDefaultBusinessAvatar;
+ private static Drawable sDefaultVoicemailAvatar;
+ private static Drawable sDefaultSpamAvatar;
+ private static Drawable sDefaultConferenceAvatar;
private final Paint mPaint;
@ContactType private int mContactType = TYPE_DEFAULT;
@@ -117,66 +117,35 @@ public class LetterTileDrawable extends Drawable {
private String mDisplayName;
public LetterTileDrawable(final Resources res) {
- // Guard static members with null checks to insulate against concurrent calls to the
- // constructor.
- if (sSpamColor == null) {
+ if (sColors == null) {
+ sColors = res.obtainTypedArray(R.array.letter_tile_colors);
sSpamColor = res.getColor(R.color.spam_contact_background);
- }
- if (sDefaultColor == null) {
sDefaultColor = res.getColor(R.color.letter_tile_default_color);
- }
- if (sTileFontColor == null) {
sTileFontColor = res.getColor(R.color.letter_tile_font_color);
- }
- if (sTileFontColor == null) {
sLetterToTileRatio = res.getFraction(R.dimen.letter_to_tile_ratio, 1, 1);
- }
-
- if (sColors == null) {
- sColors = res.obtainTypedArray(R.array.letter_tile_colors);
- }
- if (sDefaultPersonAvatar == null) {
sDefaultPersonAvatar =
res.getDrawable(R.drawable.product_logo_avatar_anonymous_white_color_120, null);
- }
- if (sDefaultBusinessAvatar == null) {
+ Assert.isNotNull(sDefaultPersonAvatar, "sDefaultPersonAvatar is null");
sDefaultBusinessAvatar = res.getDrawable(R.drawable.quantum_ic_business_vd_theme_24, null);
- }
- if (sDefaultVoicemailAvatar == null) {
+ Assert.isNotNull(sDefaultBusinessAvatar, "sDefaultBusinessAvatar is null");
sDefaultVoicemailAvatar = res.getDrawable(R.drawable.quantum_ic_voicemail_vd_theme_24, null);
- }
- if (sDefaultSpamAvatar == null) {
+ Assert.isNotNull(sDefaultVoicemailAvatar, "sDefaultVoicemailAvatar is null");
sDefaultSpamAvatar = res.getDrawable(R.drawable.quantum_ic_report_vd_theme_24, null);
- }
- if (sDefaultConferenceAvatar == null) {
+ Assert.isNotNull(sDefaultSpamAvatar, "sDefaultSpamAvatar is null");
sDefaultConferenceAvatar = res.getDrawable(R.drawable.quantum_ic_group_vd_theme_24, null);
- }
-
- // Calls in this method are potentially not idempotent, and need to be set after
- // the member is initilaized.
- this.initializeDefaultPaintOptions(res);
+ Assert.isNotNull(sDefaultConferenceAvatar, "sDefaultConferenceAvatar is null");
- // These values should be reset on every call to the constructor.
+ sPaint.setTypeface(
+ Typeface.create(res.getString(R.string.letter_tile_letter_font_family), Typeface.NORMAL));
+ sPaint.setTextAlign(Align.CENTER);
+ sPaint.setAntiAlias(true);
+ }
mPaint = new Paint();
mPaint.setFilterBitmap(true);
mPaint.setDither(true);
-
mColor = sDefaultColor;
}
- private static void initializeDefaultPaintOptions(final Resources res) {
- if (sPaint == null) {
- synchronized (LetterTileDrawable.class) {
- sPaint = new Paint();
- sPaint.setTypeface(
- Typeface.create(
- res.getString(R.string.letter_tile_letter_font_family), Typeface.NORMAL));
- sPaint.setTextAlign(Align.CENTER);
- sPaint.setAntiAlias(true);
- }
- }
- }
-
private Rect getScaledBounds(float scale, float offset) {
// The drawable should be drawn in the middle of the canvas without changing its width to
// height ratio.