com.squareup.picasso.Target Java Examples

The following examples show how to use com.squareup.picasso.Target. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DaVinciDaemon.java    From DaVinci with Apache License 2.0 6 votes vote down vote up
private void sendImage(final String url, final String path) {
    Picasso.with(mContext)
            .load(url)
            .transform(new ResizeTransformation(300))
            .into(new Target() {
                @Override
                public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                    Log.d(TAG, "Picasso " + url + " loaded");
                    sentBitmap(bitmap, url, path);
                }

                @Override
                public void onBitmapFailed(Drawable errorDrawable) {
                    Log.d(TAG, "Picasso " + url + " failed");
                }

                @Override
                public void onPrepareLoad(Drawable placeHolderDrawable) {

                }
            });
}
 
Example #2
Source File: PicassoActivity.java    From Carbon with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    initToolbar();

    final PicassoView image = findViewById(R.id.image);
    Button button = findViewById(R.id.button);
    button.setOnClickListener(view -> {
        Picasso.get()
                .load("http://lorempixel.com/" + image.getWidth() + "/" + image.getHeight() + "/people/#" + System.currentTimeMillis())
                .placeholder(new ColorDrawable(0x00000000))
                .error(new ColorDrawable(0x00000000))
                .into((Target) image);
    });
}
 
Example #3
Source File: FullScreenImageFragment.java    From DismissibleImageView with Apache License 2.0 6 votes vote down vote up
private void loadLoadingUrl(@NonNull final String url, @NonNull final String loadingUrl, final boolean loadingBlur) {
    final List<Transformation> transformations = new ArrayList<>();

    if (loadingBlur) {
        transformations.add(new BlurTransformation(getContext()));
    }

    Picasso.with(getContext()).load(loadingUrl).transform(transformations).into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            loadUrl(url, bitmap);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    });
}
 
Example #4
Source File: NotificationManager.java    From Cheerleader with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize target used to load artwork asynchronously.
 */
private void initializeArtworkTarget() {
    mThumbnailArtworkTarget = new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            mNotificationView.setImageViewBitmap(
                    R.id.simple_sound_cloud_notification_thumbnail, bitmap);
            mNotificationExpandedView.setImageViewBitmap(
                    R.id.simple_sound_cloud_notification_thumbnail, bitmap);
            mNotificationManager.notify(NOTIFICATION_ID, buildNotification());
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
        }
    };
}
 
Example #5
Source File: PlayerService.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 6 votes vote down vote up
private void loadStreamerInfoAlbumArt() {
	Target loadArtTarget = new Target() {
		@Override
		public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
			if (mediaSession != null && mediaSession.isActive()) {
				mediaSession.setMetadata(getMediaSessionData(bitmap));
			}
			mChannelInfo.setLogoImage(bitmap);
			if (lastNotificationAction != null) {
				buildNotification(lastNotificationAction);
			}
		}

		@Override
		public void onBitmapFailed(Drawable errorDrawable) {

		}

		@Override
		public void onPrepareLoad(Drawable placeHolderDrawable) {

		}
	};
	Picasso.with(this).load(mChannelInfo.getLogoURLString()).into(loadArtTarget);
}
 
Example #6
Source File: PlaceMapFragment.java    From RxGpsService with Apache License 2.0 6 votes vote down vote up
private Target getTargetForPois(final Place place, final int idPlaceToGo) {
    return new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            bitmap = bitmapHelper.getTintedBitmap(bitmap, ContextCompat.getColor(getContext(), R.color.orange));
            bitmap = bitmapHelper.getScaledBitmap(bitmap, (int) getResources().getDimension(R.dimen._30dp));
            markersMap.put(addMarkerPoi(place, BitmapDescriptorFactory.fromBitmap(bitmap), idPlaceToGo), place);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            markersMap.put(addMarkerPoi(place, getIconPoi(), idPlaceToGo), place);
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    };
}
 
Example #7
Source File: ChannelActivity.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 6 votes vote down vote up
private Target getNightThemeTarget() {
	return new Target() {
		@Override
		public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
			streamerImage.setImageBitmap(bitmap);
		}

		@Override
		public void onBitmapFailed(Drawable errorDrawable) {

		}

		@Override
		public void onPrepareLoad(Drawable placeHolderDrawable) {

		}
	};
}
 
Example #8
Source File: MD360PlayerActivity.java    From MD360Player4Android with Apache License 2.0 6 votes vote down vote up
@Override
public void onProvideBitmap(final Uri uri, final MD360BitmapTexture.Callback callback) {

    final Target target = new Target() {

        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            // texture
            callback.texture(bitmap);
            targetMap.remove(uri);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            targetMap.remove(uri);
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    };
    targetMap.put(uri, target);
    Picasso.with(getApplicationContext()).load(uri).resize(callback.getMaxTextureSize(),callback.getMaxTextureSize()).onlyScaleDown().centerInside().memoryPolicy(NO_CACHE, NO_STORE).into(target);
}
 
Example #9
Source File: RecyclerViewActivity.java    From MD360Player4Android with Apache License 2.0 6 votes vote down vote up
@Override
public void onProvideBitmap(final MD360BitmapTexture.Callback callback) {
    if (model == null) {
        return;
    }

    Picasso.with(itemView.getContext()).load(model.uri).into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            vrlib.onTextureResize(bitmap.getWidth(), bitmap.getHeight());
            callback.texture(bitmap);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    });
}
 
Example #10
Source File: BeautifulPhotosPresenterImpl.java    From Beautiful-Photos with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Launch intent to share current photo
 */
@Override
public void share(final Context ctx) {
	final PhotoModel photo = photos.get(itemIndex);

	// Picasso already has cached this image, so extract cached bitmap from its cache
	Picasso.with(ctx).load(photo.getLargeUrl()).into(new Target() {
		@Override
		public void onBitmapFailed(Drawable errorDrawable) {
		}

		@Override
		public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
			// Get bitmap uri from filesystem and create intent with it.
			shareBitmap(ctx, bitmap, photo.getTitle());
		}

		@Override
		public void onPrepareLoad(Drawable placeHolderDrawable) {
			 /* nothing to do */
		}
	});

}
 
Example #11
Source File: BackgroundSwitcherView.java    From Dagger2-Sample with MIT License 6 votes vote down vote up
public void updateCurrentBackground(String imageUrl) {

        this.currentAnimationDirection = AnimationDirection.RIGHT;
        ImageView image = (ImageView) this.getNextView();
        image.setImageDrawable(null);
        showNext();

        if(imageUrl == null) return;

        Picasso.get().load(imageUrl)
                .noFade().noPlaceholder()
                .into(new Target() {
                    @Override
                    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                        setImageBitmapWithAnimation(bitmap, currentAnimationDirection);
                    }
                    @Override
                    public void onBitmapFailed(Exception e, Drawable errorDrawable) {
                        System.out.println("@#@#@#@#@" + e.getMessage());
                    }
                    @Override
                    public void onPrepareLoad(Drawable placeHolderDrawable) { }
                });
    }
 
Example #12
Source File: Utils.java    From android with MIT License 6 votes vote down vote up
public static Target toDrawable(Resources resources, DrawableReceiver drawableReceiver) {
    return new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            drawableReceiver.loaded(new BitmapDrawable(resources, bitmap));
        }

        @Override
        public void onBitmapFailed(Exception e, Drawable errorDrawable) {
            Log.e("Bitmap failed", e);
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {}
    };
}
 
Example #13
Source File: MessagesActivity.java    From android with MIT License 6 votes vote down vote up
protected void onUpdateApps(List<Application> applications) {
    Menu menu = navigationView.getMenu();
    menu.removeGroup(R.id.apps);
    targetReferences.clear();
    updateMessagesAndStopLoading(messages.get(appId));
    for (Application app : applications) {
        MenuItem item = menu.add(R.id.apps, app.getId(), APPLICATION_ORDER, app.getName());
        item.setCheckable(true);
        Target t = Utils.toDrawable(getResources(), item::setIcon);
        targetReferences.add(t);
        picassoHandler
                .get()
                .load(Utils.resolveAbsoluteUrl(settings.url() + "/", app.getImage()))
                .error(R.drawable.ic_alarm)
                .placeholder(R.drawable.ic_placeholder)
                .resize(100, 100)
                .into(t);
    }
}
 
Example #14
Source File: Sample.java    From ZadakNotification with MIT License 6 votes vote down vote up
private static Target getViewTarget(final OnImageLoadingCompleted onCompleted) {
    return new Target() {

        @Override
        public void onBitmapFailed(final Exception e, final Drawable errorDrawable) {

        }

        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            onCompleted.imageLoadingCompleted(bitmap);
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    };
}
 
Example #15
Source File: SamplePugNotification.java    From Pugnotification with Apache License 2.0 6 votes vote down vote up
private static Target getViewTarget(final OnImageLoadingCompleted onCompleted) {
    return new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            onCompleted.imageLoadingCompleted(bitmap);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    };
}
 
Example #16
Source File: ArcusProductFragment.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
public void doDeviceImageSection(){
    deviceImage = (GlowableImageView) deviceImageView.findViewById(R.id.fragment_device_info_image);
    alarmIcon = (ImageView) deviceImageView.findViewById(R.id.alarm_icon);
    if (deviceModel == null) {
        return; // Can't do anything anyhow.
    }

    // TODO: Check ViewUtils method, it's got some "padding" in it to accommodate "unknown" devices.
    Target imageTarget = new DeviceImageTarget(deviceImage, getActivity());
    deviceImage.setTag(imageTarget);

    ImageManager.with(getActivity())
            .putLargeDeviceImage(deviceModel)
            .withTransformForUgcImages(new CircularTransformation())
            .resize(ImageUtils.dpToPx(getContext(), DEVICE_IMAGE_SIZE_DP), ImageUtils.dpToPx(getContext(), DEVICE_IMAGE_SIZE_DP))
            .into(deviceImage)
            .execute();
}
 
Example #17
Source File: BitmapPlayerActivity.java    From MD360Player4Android with Apache License 2.0 5 votes vote down vote up
private void loadImage(Uri uri, final MD360BitmapTexture.Callback callback){
    mTarget = new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            Log.d(TAG, "loaded image, size:" + bitmap.getWidth() + "," + bitmap.getHeight());

            // notify if size changed
            getVRLibrary().onTextureResize(bitmap.getWidth(), bitmap.getHeight());

            // texture
            callback.texture(bitmap);
            cancelBusy();
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    };
    Log.d(TAG, "load image with max texture size:" + callback.getMaxTextureSize());
    Picasso.with(getApplicationContext())
            .load(uri)
            .resize(callback.getMaxTextureSize(),callback.getMaxTextureSize())
            .onlyScaleDown()
            .centerInside()
            .memoryPolicy(NO_CACHE, NO_STORE)
            .into(mTarget);
}
 
Example #18
Source File: CubemapPlayerActivity.java    From MD360Player4Android with Apache License 2.0 5 votes vote down vote up
private void loadImage(Uri uri, final MD360CubemapTexture.Callback callback){
    mTarget = new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            Log.d(TAG, "loaded image, size:" + bitmap.getWidth() + "," + bitmap.getHeight());

            // notify if size changed
            getVRLibrary().onTextureResize(bitmap.getWidth(), bitmap.getHeight());

            // texture
            callback.texture(bitmap);
            //cancelBusy();
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    };

    Log.d(TAG, "load image with max texture size:" + callback.getMaxTextureSize());
    Picasso.with(getApplicationContext())
            .load(uri)
            .resize(callback.getMaxTextureSize(),callback.getMaxTextureSize())
            .onlyScaleDown()
            .centerInside()
            .memoryPolicy(NO_CACHE, NO_STORE)
            .into(mTarget);
}
 
Example #19
Source File: DetailActivity.java    From RxAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_detail);

    mActionBarSize = getActionBarSize();


    mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);

    image = (ImageView) findViewById(R.id.image);
    ViewCompat.setTransitionName(image, EXTRA_IMAGE);
    collapsingToolbar.setTitle(getIntent().getStringExtra(EXTRA_TITLE));
    bitmapImageViewTarget = new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            Palette.generateAsync(bitmap, DetailActivity.this);
            image.setImageBitmap(bitmap);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            //place your code here
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
            //place your code here
        }
    };
    Picasso.with(this).load(getIntent().getStringExtra(EXTRA_IMAGE)).into(bitmapImageViewTarget);


}
 
Example #20
Source File: EPGUtil.java    From android-tv-epg with MIT License 5 votes vote down vote up
public static void loadImageInto(Context context, String url, int width, int height, Target target) {
    initPicasso(context);

    picasso.load(url)
            .resize(width, height)
            .centerInside()
            .into(target);
}
 
Example #21
Source File: VideoPlayerActivity.java    From iview-android-tv with MIT License 5 votes vote down vote up
private void updateMediaSessionData() {
    if (mCurrentEpisode == null) {
        return;
    }
    final MediaMetadata.Builder builder = new MediaMetadata.Builder();

    updatePlaybackState(ExoPlayer.STATE_IDLE);

    updateMediaSessionIntent();

    builder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, mCurrentEpisode.getSeriesTitle());
    builder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, mCurrentEpisode.getTitle());
    builder.putLong(MediaMetadata.METADATA_KEY_DURATION, mCurrentEpisode.getDuration() * 1000);

    builder.putString(MediaMetadata.METADATA_KEY_TITLE, mCurrentEpisode.getSeriesTitle());
    builder.putString(MediaMetadata.METADATA_KEY_ARTIST, mCurrentEpisode.getTitle());

    Point size = new Point(getResources().getDimensionPixelSize(R.dimen.card_width),
            getResources().getDimensionPixelSize(R.dimen.card_height));

    Picasso.with(this).load(mCurrentEpisode.getThumbnail()).resize(size.x, size.y).into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            builder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
            mediaSession.setMetadata(builder.build());
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
        }
    });
}
 
Example #22
Source File: HtmlImageGetter.java    From cnode-android with MIT License 5 votes vote down vote up
@Override
public Drawable getDrawable(String source) {
    final BitmapDrawablePlaceHolder placeHolder = new BitmapDrawablePlaceHolder();
    final String url = ImageLoader.normalizeUrl(source);

    Picasso picasso = Picasso.with(context);
    picasso.setLoggingEnabled(BuildConfig.DEBUG);
    picasso.load(url).into(new Target() {
        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
            Log.d(TAG, "onPrepareLoad " + url);
        }

        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            Log.d(TAG, "onBitmapLoaded " + url);
            placeHolder.setDrawable(new BitmapDrawable(context.getResources(), bitmap));
            onImageLoaded();
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            Log.d(TAG, "onBitmapFailed " + url);
        }
    });

    return placeHolder;
}
 
Example #23
Source File: ChatActivity.java    From Game-of-Thrones with Apache License 2.0 5 votes vote down vote up
private void getAvatarDrawable(String imageUrl) {
  int px = Utilities.dp(context, 40);
  Target target = new Target() {
    @Override
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
      setAvatar(new BitmapDrawable(getResources(), bitmap));
    }

    @Override
    public void onBitmapFailed(Drawable errorDrawable) {
      setAvatar(errorDrawable);
    }

    @Override
    public void onPrepareLoad(Drawable placeHolderDrawable) {
      setAvatar(placeHolderDrawable);
    }
  };

  imageLoader.builder()
      .with(context)
      .load(imageUrl)
      .circle()
      .resize(px, px)
      .centerCrop()
      .into(target)
      .show();
  toolbar.setTag(target);
}
 
Example #24
Source File: PPTGoogleMapManager.java    From react-native-maps with MIT License 5 votes vote down vote up
/**
 * Loads a marker icon via URL and places it on the map at the required position.
 *
 * @param googleMap
 * @param latLng
 * @param uri
 */
private void markerWithCustomIcon(final GoogleMap googleMap, final LatLng latLng, Uri uri, final String publicId) {
    try {
        Target target = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                MarkerOptions options = new MarkerOptions();

                options.position(latLng)
                        .icon(BitmapDescriptorFactory.fromBitmap(bitmap));

                Marker marker = googleMap.addMarker(options);

                publicMarkerIds.put(marker.getId(), publicId);

                protectedFromGarbageCollectorTargets.remove(this);
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
                System.out.println("Failed to load bitmap");
                protectedFromGarbageCollectorTargets.remove(this);
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
                System.out.println("Preparing to load bitmap");
            }
        };

        protectedFromGarbageCollectorTargets.add(target);

        Picasso.with(reactContext)
                .load(uri)
                .into(target);
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
        markerWithDefaultIcon(googleMap,latLng, publicId);
    }
}
 
Example #25
Source File: ChannelActivity.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 5 votes vote down vote up
private void initStreamerImageAndColors() {
	Target mTarget = getNightThemeTarget();
	String theme = new Settings(this).getTheme();
	if (!theme.equals(getString(R.string.night_theme_name)) && !theme.equals(getString(R.string.true_night_theme_name))) {
		mTarget = getLightThemeTarget();
	}

	mLoadingTarget = mTarget;
	Picasso.with(getBaseContext())
			.load(info.getMediumPreview())
			.into(mTarget);
}
 
Example #26
Source File: PicassoLoaderProcessor.java    From ImageLoaderProcessor with Apache License 2.0 5 votes vote down vote up
@Override
public ILoaderProxy saveImage(String url, final File destFile, final ICallback callback) {
    getPicasso().load(url).into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            FileUtil.saveBitmap(bitmap, destFile.getAbsolutePath());
            AppLike.gInstance.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(destFile)));
            ToastUtils.showWarnMsg("图片保存成功!");
            if (callback != null) {
                callback.onSuccess("图片保存成功");
            }
            if (bitmap != null) {
                bitmap.recycle();
            }
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            ToastUtils.showWarnMsg("图片保存失败!");
            if (callback != null) {
                callback.onFailed("图片加载失败");
            }
        }


        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    });
    return obtain();
}
 
Example #27
Source File: WoodminSyncAdapter.java    From Woodmin with Apache License 2.0 4 votes vote down vote up
private void getImages(Product product) {
    for(Images image : product.getImages()) {
        final String folder = "Woodmin/" + product.getId();
        final String filename =  image.getTitle() + ".jpg";
        Target folderTarget = new Target() {
            @Override
            public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
                Runnable runnableImages = new Runnable() {
                    public void run() {
                        try {
                            File directory = Environment.getExternalStoragePublicDirectory((Environment.DIRECTORY_PICTURES));
                            File woodmin = new File(directory + "/" + folder);
                            woodmin.mkdirs();
                            File file = new File(woodmin + "/" + filename);
                            file.createNewFile();

                            FileOutputStream out = new FileOutputStream(file);
                            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
                            out.flush();
                            out.close();
                            Log.v(LOG_TAG, "Product folder: " + folder +  " image: " + filename);
                        } catch (Exception e) {
                            e.printStackTrace();
                            Log.e("IOException", e.getLocalizedMessage());
                        }
                        protectedFromGarbageCollectorTargets.remove(this);
                    }
                };
                threadPoolExecutor.submit(runnableImages);
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
                Log.e(LOG_TAG, "onBitmapFailed");
                protectedFromGarbageCollectorTargets.remove(this);
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
            }

        };
        protectedFromGarbageCollectorTargets.add(folderTarget);

        Picasso.with(getContext())
                .load(image.getSrc())
                .into(folderTarget);
    }
}
 
Example #28
Source File: FeedFragment.java    From Abelana-Android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_feed, container, false);
    //required to display menu with the camera button
    setHasOptionsMenu(true);
    final ListView listView = (ListView) rootView.findViewById(R.id.listview_timeline);

    /* Instantiate the class which has interfaces for the REST APIs. API calls happen off the
     * UI thread in order to not halt the app. The callback function handles the API response.
     * The response contains the information for the feed, including photos, names of people
     * who took the photos, number of likes, and whether the current user liked the photo. This
     * information is stored in the Data class and is accessed by the FeedAdapter to display it.
     */
    AbelanaClient client = new AbelanaClient();
    client.mTimeline.timeline(Data.aTok, "0", new Callback<AbelanaClient.Timeline>() {
        @Override
        public void success(AbelanaClient.Timeline timelineResponse, Response response) {
            Data.mFeedIds = new ArrayList<String>();
            Data.mLikes = new ArrayList<Integer>();
            Data.mNames = new ArrayList<String>();
            Data.mILike = new ArrayList<Boolean>();
            Data.mFeedUrls = new ArrayList<String>();
            String qualifier = rootView.getResources().getString(R.string.size_qualifier);
            if (timelineResponse.entries != null) {
                for (AbelanaClient.TimelineEntry e : timelineResponse.entries) {
                    Data.mFeedIds.add(e.photoid);
                    Data.mFeedUrls.add(AbelanaThings.getImage(e.photoid + qualifier));
                    Data.mLikes.add(e.likes);
                    Data.mNames.add(e.name);
                    Data.mILike.add(e.ilike);
                }
            }
            //Warm the image cache by pre-loading the next 5 photos
            int count = 0;
            for (String url: Data.mFeedUrls) {
                Picasso.with(getActivity()).load(url).into(new Target() {
                    @Override
                    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                        // cache is now warmed up
                    }

                    @Override
                    public void onBitmapFailed(Drawable errorDrawable) {
                    }

                    @Override
                    public void onPrepareLoad(Drawable placeHolderDrawable) {
                    }
                });

                count++;
                if (count == 5) break;
            }
            //set the adapter for the feed listview
            listView.setAdapter(new FeedAdapter(getActivity()));
        }

        @Override
        public void failure(RetrofitError error) {
            error.printStackTrace();
        }
    });


    return rootView;
}
 
Example #29
Source File: PicassoHelper.java    From Qiitanium with MIT License 4 votes vote down vote up
public void cancelRequest(final Target target) {
  picasso.cancelRequest(target);
}
 
Example #30
Source File: MetadataInjector.java    From Xposed-SoundCloudDownloader with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
    XposedBridge.log("[SoundCloud Downloader] Entering album art downloader...");
    context.unregisterReceiver(this);

    XposedBridge.log("[SoundCloud Downloader] Unregistered receiver, starting Picasso...");
    Picasso.with(XposedMod.currentActivity).setLoggingEnabled(true); // enable logging to see why picasso fails to load
    Picasso.with(XposedMod.currentActivity).load(downloadPayload.getImageUrl()).into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            try {
                File downloadedFile = new File(downloadPayload.getSaveDirectory(), downloadPayload.getFileName());
                if (!downloadedFile.exists()) {
                    XposedBridge.log("[SoundCloud Downloader] downloaded file does not exist, exiting...");
                    return;
                }

                TagOptionSingleton.getInstance().setAndroid(true);
                AudioFile audioFile = AudioFileIO.read(downloadedFile);
                Tag tag = audioFile.getTagOrCreateAndSetDefault();
                tag.setField(FieldKey.ARTIST,downloadPayload.getArtistName());
                tag.setField(FieldKey.GENRE, downloadPayload.getGenre());
                tag.setField(FieldKey.TITLE, downloadPayload.getTitle());
                tag.setField(FieldKey.ALBUM, downloadPayload.getTitle());

                ByteArrayOutputStream imgStream = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.JPEG, 90, imgStream);
                File artworkFile = File.createTempFile(downloadPayload.getTitle(), ".jpg");
                FileOutputStream artworkFileStream = new FileOutputStream(artworkFile);
                artworkFileStream.write(imgStream.toByteArray());
                artworkFileStream.close();
                artworkFile.deleteOnExit();
                imgStream.close();

                Artwork artwork = ArtworkFactory.createArtworkFromFile(artworkFile);
                artwork.setPictureType(3);
                tag.deleteArtworkField();
                tag.addField(artwork);
                tag.setField(artwork);

                audioFile.setTag(tag);
                AudioFileIO.write(audioFile);

                XposedBridge.log("[SoundCloud Downloader] Finished writing metadata...");

                XposedMod.currentActivity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(audioFile.getFile())));

                XposedBridge.log("[SoundCloud Downloader] Broadcasting update to media scanner...");

            } catch (Exception e) {
                XposedBridge.log("[SoundCloud Downloader] Metadata error: " + e.getMessage());
            }
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            XposedBridge.log("[SoundCloud Downloader] Album art fetch failed!");
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
            XposedBridge.log("[SoundCloud Downloader] Preparing to load picasso...");
        }
    });
}