mobile/android/thirdparty/com/squareup/picasso/ImageViewAction.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/thirdparty/com/squareup/picasso/ImageViewAction.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     1.4 +/*
     1.5 + * Copyright (C) 2013 Square, Inc.
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +package com.squareup.picasso;
    1.20 +
    1.21 +import android.content.Context;
    1.22 +import android.graphics.Bitmap;
    1.23 +import android.graphics.drawable.Drawable;
    1.24 +import android.widget.ImageView;
    1.25 +
    1.26 +class ImageViewAction extends Action<ImageView> {
    1.27 +
    1.28 +  Callback callback;
    1.29 +
    1.30 +  ImageViewAction(Picasso picasso, ImageView imageView, Request data, boolean skipCache,
    1.31 +      boolean noFade, int errorResId, Drawable errorDrawable, String key, Callback callback) {
    1.32 +    super(picasso, imageView, data, skipCache, noFade, errorResId, errorDrawable, key);
    1.33 +    this.callback = callback;
    1.34 +  }
    1.35 +
    1.36 +  @Override public void complete(Bitmap result, Picasso.LoadedFrom from) {
    1.37 +    if (result == null) {
    1.38 +      throw new AssertionError(
    1.39 +          String.format("Attempted to complete action with no result!\n%s", this));
    1.40 +    }
    1.41 +
    1.42 +    ImageView target = this.target.get();
    1.43 +    if (target == null) {
    1.44 +      return;
    1.45 +    }
    1.46 +
    1.47 +    Context context = picasso.context;
    1.48 +    boolean debugging = picasso.debugging;
    1.49 +    PicassoDrawable.setBitmap(target, context, result, from, noFade, debugging);
    1.50 +
    1.51 +    if (callback != null) {
    1.52 +      callback.onSuccess();
    1.53 +    }
    1.54 +  }
    1.55 +
    1.56 +  @Override public void error() {
    1.57 +    ImageView target = this.target.get();
    1.58 +    if (target == null) {
    1.59 +      return;
    1.60 +    }
    1.61 +    if (errorResId != 0) {
    1.62 +      target.setImageResource(errorResId);
    1.63 +    } else if (errorDrawable != null) {
    1.64 +      target.setImageDrawable(errorDrawable);
    1.65 +    }
    1.66 +
    1.67 +    if (callback != null) {
    1.68 +      callback.onError();
    1.69 +    }
    1.70 +  }
    1.71 +
    1.72 +  @Override void cancel() {
    1.73 +    super.cancel();
    1.74 +    if (callback != null) {
    1.75 +      callback = null;
    1.76 +    }
    1.77 +  }
    1.78 +}

mercurial