/**
   * Asynchronously fulfills the request without a {@link ImageView} or {@link Target}. This is
   * useful when you want to warm up the cache with an image.
   */
  public void fetch() {
    if (deferred) {
      throw new IllegalStateException("Fit cannot be used with fetch.");
    }
    if (data.hasImage()) {
      Request finalData = picasso.transformRequest(data.build());
      String key = createKey(finalData);

      Action action = new FetchAction(picasso, finalData, skipMemoryCache, key);
      picasso.enqueueAndSubmit(action);
    }
  }
  private void performRemoteViewInto(RemoteViewsAction action) {
    if (!skipMemoryCache) {
      Bitmap bitmap = picasso.quickMemoryCacheCheck(action.getKey());
      if (bitmap != null) {
        action.complete(bitmap, MEMORY);
        return;
      }
    }

    if (placeholderResId != 0) {
      action.setImageResource(placeholderResId);
    }

    picasso.enqueueAndSubmit(action);
  }
  /**
   * Asynchronously fulfills the request into the specified {@link RemoteViews} object with the
   * given {@code viewId}. This is used for loading bitmaps into all instances of a widget.
   */
  public void into(RemoteViews remoteViews, int viewId, int[] appWidgetIds) {
    if (remoteViews == null) {
      throw new IllegalArgumentException("RemoteViews must not be null.");
    }
    if (appWidgetIds == null) {
      throw new IllegalArgumentException("appWidgetIds must not be null.");
    }
    if (deferred) {
      throw new IllegalStateException("Fit cannot be used with RemoteViews.");
    }
    if (placeholderDrawable != null || errorDrawable != null) {
      throw new IllegalArgumentException(
          "Cannot use placeholder or error drawables with remote views.");
    }

    Request finalData = picasso.transformRequest(data.build());
    String key = createKey(finalData);

    RemoteViewsAction action =
        new AppWidgetAction(
            picasso,
            finalData,
            remoteViews,
            viewId,
            appWidgetIds,
            skipMemoryCache,
            errorResId,
            key);

    performRemoteViewInto(action);
  }
Exemple #4
0
    @Override
    protected void update(final int position, final User user) {

        Picasso.with(BootstrapApplication.getInstance())
                .load(user.getAvatarUrl())
                .placeholder(R.drawable.gravatar_icon)
                .into(imageView(0));

        setText(1, String.format("%1$s %2$s", user.getFirstName(), user.getLastName()));

    }
  /**
   * Asynchronously fulfills the request into the specified {@link Target}. In most cases, you
   * should use this when you are dealing with a custom {@link android.view.View View} or view
   * holder which should implement the {@link Target} interface.
   *
   * <p>Implementing on a {@link android.view.View View}:
   *
   * <blockquote>
   *
   * <pre>
   * public class ProfileView extends FrameLayout implements Target {
   *   {@literal @}Override public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
   *     setBackgroundDrawable(new BitmapDrawable(bitmap));
   *   }
   *
   *   {@literal @}Override public void onBitmapFailed() {
   *     setBackgroundResource(R.drawable.profile_error);
   *   }
   *
   *   {@literal @}Override public void onPrepareLoad(Drawable placeHolderDrawable) {
   *     frame.setBackgroundDrawable(placeHolderDrawable);
   *   }
   * }
   * </pre>
   *
   * </blockquote>
   *
   * Implementing on a view holder object for use inside of an adapter:
   *
   * <blockquote>
   *
   * <pre>
   * public class ViewHolder implements Target {
   *   public FrameLayout frame;
   *   public TextView name;
   *
   *   {@literal @}Override public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
   *     frame.setBackgroundDrawable(new BitmapDrawable(bitmap));
   *   }
   *
   *   {@literal @}Override public void onBitmapFailed() {
   *     frame.setBackgroundResource(R.drawable.profile_error);
   *   }
   *
   *   {@literal @}Override public void onPrepareLoad(Drawable placeHolderDrawable) {
   *     frame.setBackgroundDrawable(placeHolderDrawable);
   *   }
   * }
   * </pre>
   *
   * </blockquote>
   *
   * <p><em>Note:</em> This method keeps a weak reference to the {@link Target} instance and will be
   * garbage collected if you do not keep a strong reference to it. To receive callbacks when an
   * image is loaded use {@link #into(android.widget.ImageView, Callback)}.
   */
  public void into(Target target) {
    if (target == null) {
      throw new IllegalArgumentException("Target must not be null.");
    }
    if (deferred) {
      throw new IllegalStateException("Fit cannot be used with a Target.");
    }

    Drawable drawable =
        placeholderResId != 0
            ? picasso.context.getResources().getDrawable(placeholderResId)
            : placeholderDrawable;

    if (!data.hasImage()) {
      picasso.cancelRequest(target);
      target.onPrepareLoad(drawable);
      return;
    }

    Request finalData = picasso.transformRequest(data.build());
    String requestKey = createKey(finalData);

    if (!skipMemoryCache) {
      Bitmap bitmap = picasso.quickMemoryCacheCheck(requestKey);
      if (bitmap != null) {
        picasso.cancelRequest(target);
        target.onBitmapLoaded(bitmap, MEMORY);
        return;
      }
    }

    target.onPrepareLoad(drawable);

    Action action =
        new TargetAction(
            picasso, target, finalData, skipMemoryCache, errorResId, errorDrawable, requestKey);
    picasso.enqueueAndSubmit(action);
  }
  /**
   * Asynchronously fulfills the request into the specified {@link ImageView} and invokes the target
   * {@link Callback} if it's not {@code null}.
   *
   * <p><em>Note:</em> The {@link Callback} param is a strong reference and will prevent your {@link
   * android.app.Activity} or {@link android.app.Fragment} from being garbage collected. If you use
   * this method, it is <b>strongly</b> recommended you invoke an adjacent {@link
   * Picasso#cancelRequest(android.widget.ImageView)} call to prevent temporary leaking.
   */
  public void into(ImageView target, Callback callback) {
    if (target == null) {
      throw new IllegalArgumentException("Target must not be null.");
    }

    if (!data.hasImage()) {
      picasso.cancelRequest(target);
      PicassoDrawable.setPlaceholder(target, placeholderResId, placeholderDrawable);
      return;
    }

    if (deferred) {
      if (data.hasSize()) {
        throw new IllegalStateException("Fit cannot be used with resize.");
      }
      int measuredWidth = target.getMeasuredWidth();
      int measuredHeight = target.getMeasuredHeight();
      if (measuredWidth == 0 || measuredHeight == 0) {
        PicassoDrawable.setPlaceholder(target, placeholderResId, placeholderDrawable);
        picasso.defer(target, new DeferredRequestCreator(this, target, callback));
        return;
      }
      data.resize(measuredWidth, measuredHeight);
    }

    Request finalData = picasso.transformRequest(data.build());
    String requestKey = createKey(finalData);

    if (!skipMemoryCache) {
      Bitmap bitmap = picasso.quickMemoryCacheCheck(requestKey);
      if (bitmap != null) {
        picasso.cancelRequest(target);
        PicassoDrawable.setBitmap(
            target, picasso.context, bitmap, MEMORY, noFade, picasso.indicatorsEnabled);
        if (callback != null) {
          callback.onSuccess();
        }
        return;
      }
    }

    PicassoDrawable.setPlaceholder(target, placeholderResId, placeholderDrawable);

    Action action =
        new ImageViewAction(
            picasso,
            target,
            finalData,
            skipMemoryCache,
            noFade,
            errorResId,
            errorDrawable,
            requestKey,
            callback);

    picasso.enqueueAndSubmit(action);
  }
  @Test
  public void onGlobalLayoutSubmitsRequestAndCleansUp() throws Exception {
    Picasso picasso = mock(Picasso.class);
    when(picasso.transformRequest(any(Request.class))).thenAnswer(TRANSFORM_REQUEST_ANSWER);

    RequestCreator creator = new RequestCreator(picasso, URI_1, 0);

    ImageView target = mockFitImageViewTarget(true);
    when(target.getWidth()).thenReturn(100);
    when(target.getHeight()).thenReturn(100);

    ViewTreeObserver observer = target.getViewTreeObserver();

    DeferredRequestCreator request = new DeferredRequestCreator(creator, target);
    request.onPreDraw();

    verify(observer).removeOnPreDrawListener(request);
    verify(picasso).enqueueAndSubmit(actionCaptor.capture());

    Action value = actionCaptor.getValue();
    assertThat(value).isInstanceOf(ImageViewAction.class);
    assertThat(value.getRequest().targetWidth).isEqualTo(100);
    assertThat(value.getRequest().targetHeight).isEqualTo(100);
  }
Exemple #8
0
    public final void handleMessage(Message message)
    {
        message.what;
        JVM INSTR lookupswitch 3: default 40
    //                   3: 117
    //                   8: 67
    //                   13: 163;
           goto _L1 _L2 _L3 _L4
_L1:
        throw new AssertionError((new StringBuilder("Unknown handler message received: ")).append(message.what).toString());
_L3:
        message = (List)message.obj;
        int i = 0;
        for (int k = message.size(); i < k; i++)
        {
            BitmapHunter bitmaphunter = (BitmapHunter)message.get(i);
            bitmaphunter.picasso.complete(bitmaphunter);
        }

        break; /* Loop/switch isn't completed */
_L2:
        message = (Action)message.obj;
        if (message.getPicasso().loggingEnabled)
        {
            Utils.log("Main", "canceled", ((Action) (message)).request.logId(), "target got garbage collected");
        }
        Picasso.access$000(((Action) (message)).picasso, message.getTarget());
_L6:
        return;
_L4:
        message = (List)message.obj;
        int j = 0;
        int l = message.size();
        while (j < l) 
        {
            Action action = (Action)message.get(j);
            action.picasso.resumeAction(action);
            j++;
        }
        if (true) goto _L6; else goto _L5
  /**
   * Synchronously fulfill this request. Must not be called from the main thread.
   *
   * <p><em>Note</em>: The result of this operation is not cached in memory because the underlying
   * {@link Cache} implementation is not guaranteed to be thread-safe.
   */
  public Bitmap get() throws IOException {
    checkNotMain();
    if (deferred) {
      throw new IllegalStateException("Fit cannot be used with get.");
    }
    if (!data.hasImage()) {
      return null;
    }

    Request finalData = picasso.transformRequest(data.build());
    String key = createKey(finalData, new StringBuilder());

    Action action = new GetAction(picasso, finalData, skipMemoryCache, key);
    return forRequest(
            picasso.context,
            picasso,
            picasso.dispatcher,
            picasso.cache,
            picasso.stats,
            action,
            picasso.dispatcher.downloader)
        .hunt();
  }
  @Override
  public void onBindViewHolder(final CustomViewHolder customViewHolder, final int i) {

    Data element = lists.get(i);

    /*
     * Glide.with(mContext).load("http://i66.tinypic.com/2liivbo.png").
     * centerCrop().placeholder(R.drawable.bg)
     * .crossFade().into(customViewHolder.imageView);
     */
    String image = element.getLocation();

    if ("Vijayawada".equals(image)) {
      Picasso.with(mContext)
          .load("http://media-cdn.tripadvisor.com/media/photo-s/03/a8/a7/f2/view-from-nh-5.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Tirupati".equals(image)) {
      Picasso.with(mContext)
          .load("http://wikitravel.org/upload/shared/9/93/Tirupathi.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }
    if ("Gannavaram".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("http://www.thehindu.com/multimedia/dynamic/01577/08VZ_VIJ_P2_FLIGHT_1577738f.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .into(customViewHolder.imageView);
    }

    if ("Mumbai".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("http://wikitravel.org/upload/en/e/ed/Gateway_of_India.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Guntur".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("http://wikitravel.org/shared/File:Guntur_Banner.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Visakhapatnam".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("http://www.urbannewsdigest.in/wp-content/uploads/2013/09/DSC_0017.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Nellore".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("https://upload.wikimedia.org/wikipedia/commons/5/53/Nellore_Montage.png")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Kurnool".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("https://upload.wikimedia.org/wikipedia/commons/c/c8/KurnoolSkyLine.jpeg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Rajahmundry".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load(
              "https://upload.wikimedia.org/wikipedia/commons/9/91/Rail_Cum_Road_Bridge_on_Godavari_at_Rajahmundry.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Kadapa".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load(
              "https://upload.wikimedia.org/wikipedia/commons/f/f4/Ameen_Peer_Dargah_in_the_City_of_Kadapa.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Kakinada".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("https://upload.wikimedia.org/wikipedia/commons/d/de/Godavari_fertilizers.JPG")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Anantapur".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("https://upload.wikimedia.org/wikipedia/commons/c/ca/Ananthapur_ISKCON.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Vizianagaram".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load(
              "http://www.onefivenine.com/images/districtimages/Andhra%20Pradesh/Vizianagaram/3.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Eluru".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load(
              "http://www.yatrastotemples.com/wp-content/gallery/sri-venkateswara-swamy-temple-chinna-tirupati-in-dwaraka-tirumala/Sri-Venkateswara-Swamy-Temple-Chinna-Tirupati-in-Dwaraka-Tirumala-4.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Ongole".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load(
              "http://www.veethi.com/watermark.php?path=images/city-images/fullsize/Ongole-10918.jpeg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Nandyal".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("http://www.aptdc.gov.in/LargeImage/Karnool/MahaNandi1.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Machilipatnam".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("http://www.thehindu.com/multimedia/dynamic/01441/26VJTAN01-MANGI_27_1441058e.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Hyderabad".equals(image)) {

      Picasso.with(mContext)
          .load("http://www.csicon2014.com/uploads/hyderabad.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }
    if ("New York".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("https://upload.wikimedia.org/wikipedia/commons/d/d3/Statue_of_Liberty%2C_NY.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Los Angeles".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("https://upload.wikimedia.org/wikipedia/commons/5/57/LA_Skyline_Mountains2.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Chicago".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("https://upload.wikimedia.org/wikipedia/commons/0/0b/ChicagovanafSearsTower.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Houston".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("https://upload.wikimedia.org/wikipedia/commons/4/44/Panoramic_Houston_skyline.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("San Diego".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("https://upload.wikimedia.org/wikipedia/commons/7/7c/SanDiegoSkylineBay.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("Dallas".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("https://upload.wikimedia.org/wikipedia/commons/f/f7/Xvisionx_Dallas_Stemmons.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("San Jose".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("https://upload.wikimedia.org/wikipedia/en/1/1c/Downtown_San_Jose.PNG")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    }

    if ("San Francisco".equals(image)) {
      // Download image using picasso library
      Picasso.with(mContext)
          .load("https://upload.wikimedia.org/wikipedia/commons/0/07/FinancialNorth.jpg")
          .error(R.drawable.sl)
          .placeholder(R.drawable.sl)
          .fit()
          .into(customViewHolder.imageView);
    } else {
      customViewHolder.relativeLayout.setBackgroundResource(R.drawable.sl);
    }

    // Setting text view title
    customViewHolder.textView1.setText(element.getDescription());
    customViewHolder.textView2.setText(element.getTemperature() + "℃");
    customViewHolder.textView3.setText(element.getLocation());
    customViewHolder.texthigh.setText(element.getMax() + "℃");
    customViewHolder.textlow.setText(element.getMin() + "℃");

    // setting Background Resource
    // customViewHolder.imageView.setBackgroundResource(R.drawable.bg);

    customViewHolder.swipeLayout.addSwipeListener(
        new SwipeLayout.SwipeListener() {
          @Override
          public void onClose(SwipeLayout layout) {
            // when the SurfaceView totally cover the BottomView.
          }

          @Override
          public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
            // you are swiping.
          }

          @Override
          public void onStartOpen(SwipeLayout layout) {}

          @Override
          public void onOpen(SwipeLayout layout) {
            // when the BottomView totally show.
          }

          @Override
          public void onStartClose(SwipeLayout layout) {}

          @Override
          public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
            // when user's hand released.
          }
        });

    customViewHolder.buttonDelete.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            lists.remove(i);
            notifyItemRemoved(i);
            notifyItemRangeChanged(i, lists.size());
            Toast.makeText(
                    view.getContext(),
                    "Deleted " + customViewHolder.textView3.getText().toString() + "!",
                    Toast.LENGTH_SHORT)
                .show();
          }
        });
  }