Пример #1
0
  public static Drawable getGroupContactPhoto(Context context, @Nullable byte[] avatar) {
    if (avatar == null) return getDefaultGroupPhoto(context);

    return RoundedDrawable.fromBitmap(BitmapFactory.decodeByteArray(avatar, 0, avatar.length))
        .setScaleType(ImageView.ScaleType.CENTER_CROP)
        .setOval(true);
  }
Пример #2
0
  public static Drawable getDefaultGroupPhoto(Context context) {
    synchronized (defaultGroupPhotoLock) {
      if (defaultGroupContactPhoto == null) {
        Drawable background = TextDrawable.builder().buildRound(" ", UNKNOWN_COLOR);
        RoundedDrawable foreground =
            (RoundedDrawable)
                RoundedDrawable.fromDrawable(
                    context.getResources().getDrawable(R.drawable.ic_group_white_24dp));
        foreground.setScaleType(ImageView.ScaleType.CENTER);

        defaultGroupContactPhoto =
            new ExpandingLayerDrawable(new Drawable[] {background, foreground});
      }

      return defaultGroupContactPhoto;
    }
  }
Пример #3
0
  public static Drawable getLoadingPhoto(Context context) {
    synchronized (loadingPhotoLock) {
      if (loadingPhoto == null)
        loadingPhoto =
            RoundedDrawable.fromDrawable(
                context.getResources().getDrawable(android.R.color.transparent));

      return loadingPhoto;
    }
  }
Пример #4
0
  public static Drawable getContactPhoto(Context context, Uri uri, String name) {
    final InputStream inputStream = getContactPhotoStream(context, uri);
    final int targetSize =
        context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);

    if (inputStream != null) {
      try {
        return RoundedDrawable.fromBitmap(
                BitmapUtil.createScaledBitmap(
                    inputStream, getContactPhotoStream(context, uri), targetSize, targetSize))
            .setScaleType(ImageView.ScaleType.CENTER_CROP)
            .setOval(true);
      } catch (BitmapDecodingException bde) {
        Log.w(TAG, bde);
      }
    }

    return getDefaultContactPhoto(context, name);
  }