private static String buildImagePath(Image image, int width) {
   if (image.isHatchetImage()) {
     int squareImageWidth = Math.min(image.getHeight(), image.getWidth());
     if (isWifiAvailable()) {
       if (squareImageWidth > width) {
         return image.getImagePath() + "?width=" + width + "&height=" + width;
       }
     } else if (squareImageWidth > width * 2 / 3) {
       return image.getImagePath() + "?width=" + width * 2 / 3 + "&height=" + width * 2 / 3;
     }
   }
   return image.getImagePath();
 }
Ejemplo n.º 2
0
 private static String buildImagePath(Image image, int width) {
   if (image.isHatchetImage()) {
     int imageSize = Math.min(image.getHeight(), image.getWidth());
     int actualWidth;
     if (NetworkUtils.isWifiAvailable()) {
       actualWidth = Math.min(imageSize, width);
     } else {
       actualWidth = Math.min(imageSize, width * 2 / 3);
     }
     return image.getImagePath() + "?width=" + actualWidth + "&height=" + actualWidth;
   }
   return image.getImagePath();
 }
 /**
  * Load a {@link android.graphics.Bitmap} asynchronously
  *
  * @param context the context needed for fetching resources
  * @param imageView the {@link android.widget.ImageView}, which will be used to show the {@link
  *     android.graphics.Bitmap}
  * @param image the path to load the image from
  * @param width the width in pixels to scale the image down to
  */
 public static void loadImageIntoImageView(
     Context context,
     ImageView imageView,
     Image image,
     int width,
     boolean fit,
     boolean isArtistImage) {
   int placeHolder =
       isArtistImage ? R.drawable.artist_placeholder_grid : R.drawable.album_placeholder_grid;
   if (image != null && !TextUtils.isEmpty(image.getImagePath())) {
     String imagePath = buildImagePath(image, width);
     RequestCreator creator =
         Picasso.with(context)
             .load(TomahawkUtils.preparePathForPicasso(imagePath))
             .placeholder(placeHolder)
             .error(placeHolder);
     if (fit) {
       creator.resize(width, width);
     }
     creator.into(imageView);
   } else {
     RequestCreator creator =
         Picasso.with(context).load(placeHolder).placeholder(placeHolder).error(placeHolder);
     if (fit) {
       creator.resize(width, width);
     }
     creator.into(imageView);
   }
 }
 /**
  * Load a {@link android.graphics.Bitmap} asynchronously
  *
  * @param context the context needed for fetching resources
  * @param image the path to load the image from
  * @param target the Target which the loaded image will be pushed to
  * @param width the width in pixels to scale the image down to
  */
 public static void loadImageIntoBitmap(
     Context context, Image image, Target target, int width, boolean isArtistImage) {
   int placeHolder =
       isArtistImage ? R.drawable.artist_placeholder_grid : R.drawable.album_placeholder_grid;
   if (image != null && !TextUtils.isEmpty(image.getImagePath())) {
     String imagePath = buildImagePath(image, width);
     Picasso.with(context)
         .load(TomahawkUtils.preparePathForPicasso(imagePath))
         .resize(width, width)
         .into(target);
   } else {
     Picasso.with(context).load(placeHolder).resize(width, width).into(target);
   }
 }
 /**
  * Load a {@link android.graphics.Bitmap} asynchronously
  *
  * @param context the context needed for fetching resources
  * @param imageView the {@link android.widget.ImageView}, which will be used to show the {@link
  *     android.graphics.Bitmap}
  * @param image the path to load the image from
  * @param width the width in density independent pixels to scale the image down to
  */
 public static void loadBlurredImageIntoImageView(
     Context context, ImageView imageView, Image image, int width, int placeHolderResId) {
   if (image != null && !TextUtils.isEmpty(image.getImagePath())) {
     String imagePath = buildImagePath(image, width);
     RequestCreator creator =
         Picasso.with(context)
             .load(TomahawkUtils.preparePathForPicasso(imagePath))
             .resize(width, width);
     if (placeHolderResId > 0) {
       creator.placeholder(placeHolderResId);
       creator.error(placeHolderResId);
     }
     creator.transform(new BlurTransformation());
     creator.into(imageView);
   } else {
     RequestCreator creator =
         Picasso.with(context)
             .load(placeHolderResId)
             .placeholder(placeHolderResId)
             .error(placeHolderResId);
     creator.into(imageView);
   }
 }
 /**
  * Load a {@link android.graphics.Bitmap} asynchronously
  *
  * @param context the context needed for fetching resources
  * @param image the path to load the image from
  * @param width the width in pixels to scale the image down to
  */
 public static void loadImageIntoNotification(
     Context context,
     Image image,
     RemoteViews remoteViews,
     int viewId,
     int notificationId,
     Notification notification,
     int width,
     boolean isArtistImage) {
   int placeHolder =
       isArtistImage ? R.drawable.artist_placeholder_grid : R.drawable.album_placeholder_grid;
   if (image != null && !TextUtils.isEmpty(image.getImagePath())) {
     String imagePath = buildImagePath(image, width);
     Picasso.with(context)
         .load(TomahawkUtils.preparePathForPicasso(imagePath))
         .resize(width, width)
         .into(remoteViews, viewId, notificationId, notification);
   } else {
     Picasso.with(context)
         .load(placeHolder)
         .resize(width, width)
         .into(remoteViews, viewId, notificationId, notification);
   }
 }