com.squareup.picasso.Request Java Examples

The following examples show how to use com.squareup.picasso.Request. 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 Project: DoraemonKit   Author: didi   File: PicassoHook.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 注入到com.squareup.picasso.Request 构造方法中
 */
public static void proxy(Object request) {
    try {
        if (request instanceof Request) {
            Request requestObj = (Request) request;
            List<Transformation> transformations = requestObj.transformations;
            if (transformations == null) {
                transformations = new ArrayList<>();
                transformations.add(new DokitPicassoTransformation(requestObj.uri, requestObj.resourceId));
            } else {
                transformations.clear();
                transformations.add(new DokitPicassoTransformation(requestObj.uri, requestObj.resourceId));
            }
            ReflectUtils.reflect(request).field("transformations", transformations);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example #2
Source Project: android   Author: gotify   File: PicassoDataRequestHandler.java    License: MIT License 6 votes vote down vote up
@Override
public Result load(Request request, int networkPolicy) {
    String uri = request.uri.toString();
    String imageDataBytes = uri.substring(uri.indexOf(",") + 1);
    byte[] bytes = Base64.decode(imageDataBytes.getBytes(), Base64.DEFAULT);
    Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

    if (bitmap == null) {
        String show = uri.length() > 50 ? uri.substring(0, 49) + "..." : uri;
        RuntimeException malformed = new RuntimeException("Malformed data uri: " + show);
        Log.e("Could not load image", malformed);
        throw malformed;
    }

    return new Result(bitmap, Picasso.LoadedFrom.NETWORK);
}
 
Example #3
Source Project: cathode   Author: SimonVT   File: ImageRequestTransformer.java    License: Apache License 2.0 6 votes vote down vote up
@Override public Request transformRequest(Request request) {
  Uri uri = request.uri;

  if (uri == null) {
    return request;
  }

  final String scheme = uri.getScheme();

  if (!SCHEMES.contains(scheme)) {
    return request;
  }

  final ImageType imageType = ImageType.fromValue(uri.getHost());
  final String size = ImageSizeSelector.getInstance(context)
      .getSize(imageType, request.targetWidth, request.targetHeight);

  Uri newUri = uri.buildUpon().appendQueryParameter(QUERY_SIZE, size).build();

  return request.buildUpon().setUri(newUri).build();
}
 
Example #4
Source Project: cathode   Author: SimonVT   File: ImageRequestHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override public RequestHandler.Result load(Request request, int networkPolicy)
    throws IOException {
  final String baseUrl = getBaseUrl();
  if (TextUtils.isEmpty(baseUrl)) {
    return null;
  }

  String path = transform(request, request.uri);

  if (TextUtils.isEmpty(path)) {
    return null;
  }

  Downloader.Response response = downloader.load(Uri.parse(path), networkPolicy);
  if (response == null) {
    return null;
  }

  InputStream is = response.getInputStream();
  if (is == null) {
    return null;
  }

  return new RequestHandler.Result(is, Picasso.LoadedFrom.NETWORK);
}
 
Example #5
Source Project: notSABS   Author: GoldenKappa   File: PackageDisablerFragment.java    License: MIT License 5 votes vote down vote up
@Override
public Result load(Request request, int networkPolicy) throws IOException {
    String packageName = request.uri.getSchemeSpecificPart();
    Drawable drawable;
    try {
        drawable = mPackageManager.getApplicationIcon(packageName);
    } catch (PackageManager.NameNotFoundException ignored) {
        return null;
    }
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    return new Result(bitmap, Picasso.LoadedFrom.DISK);
}
 
Example #6
Source Project: notSABS   Author: GoldenKappa   File: AppWhitelistAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public Result load(Request request, int networkPolicy) throws IOException {
    String packageName = request.uri.getSchemeSpecificPart();
    Drawable drawable;
    try {
        drawable = mPackageManager.getApplicationIcon(packageName);
    } catch (PackageManager.NameNotFoundException ignored) {
        return null;
    }
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    return new Result(bitmap, Picasso.LoadedFrom.DISK);
}
 
Example #7
Source Project: citra_android   Author: SachinVin   File: GameBannerRequestHandler.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public Result load(Request request, int networkPolicy)
{
  String url = request.uri.getHost() + request.uri.getPath();
  int[] vector = NativeLibrary.GetBanner(url);
  int width = 48;
  int height = 48;
  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
  bitmap.copyPixelsFromBuffer(IntBuffer.wrap(vector));
  return new Result(bitmap, Picasso.LoadedFrom.DISK);
}
 
Example #8
Source Project: SABS   Author: nvmkpk   File: PackageDisablerFragment.java    License: MIT License 5 votes vote down vote up
@Override
public Result load(Request request, int networkPolicy) throws IOException {
    String packageName = request.uri.getSchemeSpecificPart();
    Drawable drawable;
    try {
        drawable = mPackageManager.getApplicationIcon(packageName);
    } catch (PackageManager.NameNotFoundException ignored) {
        return null;
    }
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    return new Result(bitmap, Picasso.LoadedFrom.DISK);
}
 
Example #9
Source Project: SABS   Author: nvmkpk   File: AppWhitelistAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public Result load(Request request, int networkPolicy) throws IOException {
    String packageName = request.uri.getSchemeSpecificPart();
    Drawable drawable;
    try {
        drawable = mPackageManager.getApplicationIcon(packageName);
    } catch (PackageManager.NameNotFoundException ignored) {
        return null;
    }
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    return new Result(bitmap, Picasso.LoadedFrom.DISK);
}
 
Example #10
Source Project: PictureSelector   Author: LuckSiege   File: VideoRequestHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Result load(Request request, int networkPolicy) throws IOException {
    Uri uri = request.uri;
    String path = uri.getPath();
    if (!TextUtils.isEmpty(path)) {
        Bitmap bm = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MINI_KIND);
        return new Result(bm, Picasso.LoadedFrom.DISK);
    }
    return null;
}
 
Example #11
Source Project: android-instant-apps-demo   Author: willowtreeapps   File: FirebaseRequestHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Result load(Request request, int networkPolicy) throws IOException {
    Log.i(TAG, "load " + request.uri.toString());
    StorageReference gsReference = firebaseStorage.getReferenceFromUrl(request.uri.toString());
    StreamDownloadTask mStreamTask = gsReference.getStream();

    InputStream inputStream;
    try {
        inputStream = Tasks.await(mStreamTask).getStream();
        return new Result(BitmapFactory.decodeStream(inputStream), Picasso.LoadedFrom.NETWORK);
    } catch (ExecutionException | InterruptedException e) {
        throw new IOException(e);
    }
}
 
Example #12
Source Project: AndroidProcesses   Author: jaredrummler   File: AppIconRequestHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override public Result load(Request request, int networkPolicy) throws IOException {
  try {
    return new Result(getFullResIcon(request.uri.toString().split(":")[1]), DISK);
  } catch (PackageManager.NameNotFoundException e) {
    return null;
  }
}
 
Example #13
Source Project: bubble   Author: nkanaev   File: LocalCoverHandler.java    License: MIT License 5 votes vote down vote up
@Override
public Result load(Request data, int networkPolicy) throws IOException {
    String path = getCoverPath(data.uri);
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.RGB_565;
    return new Result(BitmapFactory.decodeFile(path, options), Picasso.LoadedFrom.DISK);
}
 
Example #14
Source Project: u2020-mvp   Author: LiveTyping   File: MockRequestHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override public Result load(Request request, int networkPolicy) throws IOException {
    String imagePath = request.uri.getPath().substring(1); // Grab only the path sans leading slash.

    // Check the disk cache for the image. A non-null return value indicates a hit.
    boolean cacheHit = emulatedDiskCache.get(imagePath) != null;

    // If there's a hit, grab the image stream and return it.
    if (cacheHit) {
        return new Result(loadBitmap(imagePath), Picasso.LoadedFrom.DISK);
    }

    // If we are not allowed to hit the network and the cache missed return a big fat nothing.
    if (NetworkPolicy.isOfflineOnly(networkPolicy)) {
        return null;
    }

    // If we got this far there was a cache miss and hitting the network is required. See if we need
    // to fake an network error.
    if (behavior.calculateIsFailure()) {
        SystemClock.sleep(behavior.calculateDelay(MILLISECONDS));
        throw new IOException("Fake network error!");
    }

    // We aren't throwing a network error so fake a round trip delay.
    SystemClock.sleep(behavior.calculateDelay(MILLISECONDS));

    // Since we cache missed put it in the LRU.
    AssetFileDescriptor fileDescriptor = assetManager.openFd(imagePath);
    long size = fileDescriptor.getLength();
    fileDescriptor.close();
    emulatedDiskCache.put(imagePath, size);

    // Grab the image stream and return it.
    return new Result(loadBitmap(imagePath), Picasso.LoadedFrom.NETWORK);
}
 
Example #15
Source Project: u2020   Author: JakeWharton   File: MockRequestHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override public Result load(Request request, int networkPolicy) throws IOException {
  String imagePath = request.uri.getPath().substring(1); // Grab only the path sans leading slash.

  // Check the disk cache for the image. A non-null return value indicates a hit.
  boolean cacheHit = emulatedDiskCache.get(imagePath) != null;

  // If there's a hit, grab the image stream and return it.
  if (cacheHit) {
    return new Result(loadBitmap(imagePath), Picasso.LoadedFrom.DISK);
  }

  // If we are not allowed to hit the network and the cache missed return a big fat nothing.
  if (NetworkPolicy.isOfflineOnly(networkPolicy)) {
    return null;
  }

  // If we got this far there was a cache miss and hitting the network is required. See if we need
  // to fake an network error.
  if (behavior.calculateIsFailure()) {
    SystemClock.sleep(behavior.calculateDelay(MILLISECONDS));
    throw new IOException("Fake network error!");
  }

  // We aren't throwing a network error so fake a round trip delay.
  SystemClock.sleep(behavior.calculateDelay(MILLISECONDS));

  // Since we cache missed put it in the LRU.
  AssetFileDescriptor fileDescriptor = assetManager.openFd(imagePath);
  long size = fileDescriptor.getLength();
  fileDescriptor.close();

  emulatedDiskCache.put(imagePath, size);

  // Grab the image stream and return it.
  return new Result(loadBitmap(imagePath), Picasso.LoadedFrom.NETWORK);
}
 
Example #16
Source Project: cathode   Author: SimonVT   File: BaseUrlRequestHandler.java    License: Apache License 2.0 5 votes vote down vote up
protected String transform(Request request, Uri uri) throws IOException {
  final String image = uri.getPath();
  String size = request.uri.getQueryParameter(QUERY_SIZE);

  String url = getBaseUrl() + size + image;
  Timber.d("Url: %s", url);
  return url;
}
 
Example #17
Source Project: dropbox-sdk-java   Author: dropbox   File: FileThumbnailRequestHandler.java    License: MIT License 5 votes vote down vote up
@Override
public Result load(Request request, int networkPolicy) throws IOException {

    try {
        DbxDownloader<FileMetadata> downloader =
                mDbxClient.files().getThumbnailBuilder(request.uri.getPath())
                        .withFormat(ThumbnailFormat.JPEG)
                        .withSize(ThumbnailSize.W1024H768)
                        .start();

        return new Result(Okio.source(downloader.getInputStream()), Picasso.LoadedFrom.NETWORK);
    } catch (DbxException e) {
        throw new IOException(e);
    }
}
 
Example #18
Source Project: android   Author: gotify   File: PicassoDataRequestHandler.java    License: MIT License 4 votes vote down vote up
@Override
public boolean canHandleRequest(Request data) {
    String scheme = data.uri.getScheme();
    return DATA_SCHEME.equalsIgnoreCase(scheme);
}
 
Example #19
Source Project: notSABS   Author: GoldenKappa   File: PackageDisablerFragment.java    License: MIT License 4 votes vote down vote up
@Override
public boolean canHandleRequest(Request data) {
    // only handle Uris matching our scheme
    return (SCHEME_APP_ICON.equals(data.uri.getScheme()));
}
 
Example #20
Source Project: notSABS   Author: GoldenKappa   File: AppWhitelistAdapter.java    License: MIT License 4 votes vote down vote up
@Override
public boolean canHandleRequest(Request data) {
    // only handle Uris matching our scheme
    return (SCHEME_APP_ICON.equals(data.uri.getScheme()));
}
 
Example #21
Source Project: citra_android   Author: SachinVin   File: GameBannerRequestHandler.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canHandleRequest(Request data)
{
  return "iso".equals(data.uri.getScheme());
}
 
Example #22
Source Project: SABS   Author: nvmkpk   File: PackageDisablerFragment.java    License: MIT License 4 votes vote down vote up
@Override
public boolean canHandleRequest(Request data) {
    // only handle Uris matching our scheme
    return (SCHEME_APP_ICON.equals(data.uri.getScheme()));
}
 
Example #23
Source Project: SABS   Author: nvmkpk   File: AppWhitelistAdapter.java    License: MIT License 4 votes vote down vote up
@Override
public boolean canHandleRequest(Request data) {
    // only handle Uris matching our scheme
    return (SCHEME_APP_ICON.equals(data.uri.getScheme()));
}
 
Example #24
Source Project: PictureSelector   Author: LuckSiege   File: VideoRequestHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean canHandleRequest(Request data) {
    String scheme = data.uri.getScheme();
    return (SCHEME_VIDEO.equals(scheme));
}
 
Example #25
Source Project: android-instant-apps-demo   Author: willowtreeapps   File: FirebaseRequestHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean canHandleRequest(Request data) {
    String scheme = data.uri.getScheme();
    return SCHEME_FIREBASE_STORAGE.equals(scheme);
}
 
Example #26
Source Project: AndroidProcesses   Author: jaredrummler   File: AppIconRequestHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override public boolean canHandleRequest(Request data) {
  return data.uri != null && TextUtils.equals(data.uri.getScheme(), SCHEME_PNAME);
}
 
Example #27
Source Project: bubble   Author: nkanaev   File: LocalCoverHandler.java    License: MIT License 4 votes vote down vote up
@Override
public boolean canHandleRequest(Request data) {
    return HANDLER_URI.equals(data.uri.getScheme());
}
 
Example #28
Source Project: bubble   Author: nkanaev   File: LocalComicHandler.java    License: MIT License 4 votes vote down vote up
@Override
public boolean canHandleRequest(Request request) {
    return HANDLER_URI.equals(request.uri.getScheme());
}
 
Example #29
Source Project: bubble   Author: nkanaev   File: LocalComicHandler.java    License: MIT License 4 votes vote down vote up
@Override
public Result load(Request request, int networkPolicy) throws IOException {
    int pageNum = Integer.parseInt(request.uri.getFragment());
    InputStream stream = mParser.getPage(pageNum);
    return new Result(stream, Picasso.LoadedFrom.DISK);
}
 
Example #30
Source Project: u2020-mvp   Author: LiveTyping   File: MockRequestHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override public boolean canHandleRequest(Request data) {
    return "mock".equals(data.uri.getScheme());
}