michael@0: /* michael@0: * Copyright (C) 2013 Square, Inc. michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: package com.squareup.picasso; michael@0: michael@0: import android.graphics.Bitmap; michael@0: import android.graphics.drawable.Drawable; michael@0: import java.lang.ref.ReferenceQueue; michael@0: import java.lang.ref.WeakReference; michael@0: michael@0: abstract class Action { michael@0: static class RequestWeakReference extends WeakReference { michael@0: final Action action; michael@0: michael@0: public RequestWeakReference(Action action, T referent, ReferenceQueue q) { michael@0: super(referent, q); michael@0: this.action = action; michael@0: } michael@0: } michael@0: michael@0: final Picasso picasso; michael@0: final Request data; michael@0: final WeakReference target; michael@0: final boolean skipCache; michael@0: final boolean noFade; michael@0: final int errorResId; michael@0: final Drawable errorDrawable; michael@0: final String key; michael@0: michael@0: boolean cancelled; michael@0: michael@0: Action(Picasso picasso, T target, Request data, boolean skipCache, boolean noFade, michael@0: int errorResId, Drawable errorDrawable, String key) { michael@0: this.picasso = picasso; michael@0: this.data = data; michael@0: this.target = new RequestWeakReference(this, target, picasso.referenceQueue); michael@0: this.skipCache = skipCache; michael@0: this.noFade = noFade; michael@0: this.errorResId = errorResId; michael@0: this.errorDrawable = errorDrawable; michael@0: this.key = key; michael@0: } michael@0: michael@0: abstract void complete(Bitmap result, Picasso.LoadedFrom from); michael@0: michael@0: abstract void error(); michael@0: michael@0: void cancel() { michael@0: cancelled = true; michael@0: } michael@0: michael@0: Request getData() { michael@0: return data; michael@0: } michael@0: michael@0: T getTarget() { michael@0: return target.get(); michael@0: } michael@0: michael@0: String getKey() { michael@0: return key; michael@0: } michael@0: michael@0: boolean isCancelled() { michael@0: return cancelled; michael@0: } michael@0: michael@0: Picasso getPicasso() { michael@0: return picasso; michael@0: } michael@0: }