private void setLogoImage(ParseFile logoImage) { if (logoImage != null) { mLogoImageButton.setParseFile(logoImage); mLogoImageButton.loadInBackground(); } else { String title = mTitleText.getText().toString(); String firstChar = title.isEmpty() ? "N" : title.substring(0, 1).toUpperCase(); ColorGenerator generator = ColorGenerator.MATERIAL; int alphabetColor = generator.getColor(firstChar); final TextDrawable drawable = TextDrawable.builder().buildRound(firstChar, alphabetColor); mLogoImageButton.setImageDrawable(drawable); } }
public static Drawable getDefaultContactPhoto(Context context, @Nullable String name) { int targetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size); if (name != null && !name.isEmpty()) { return TextDrawable.builder() .beginConfig() .width(targetSize) .height(targetSize) .endConfig() .buildRound(String.valueOf(name.charAt(0)), COLOR_GENERATOR.getColor(name)); } synchronized (defaultPhotoLock) { if (defaultContactPhoto == null) defaultContactPhoto = TextDrawable.builder() .beginConfig() .width(targetSize) .height(targetSize) .endConfig() .buildRound("#", UNKNOWN_COLOR); return defaultContactPhoto; } }