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: michael@0: final class TargetAction extends Action { michael@0: michael@0: TargetAction(Picasso picasso, Target target, Request data, boolean skipCache, String key) { michael@0: super(picasso, target, data, skipCache, false, 0, null, key); michael@0: } michael@0: michael@0: @Override void complete(Bitmap result, Picasso.LoadedFrom from) { michael@0: if (result == null) { michael@0: throw new AssertionError( michael@0: String.format("Attempted to complete action with no result!\n%s", this)); michael@0: } michael@0: Target target = getTarget(); michael@0: if (target != null) { michael@0: target.onBitmapLoaded(result, from); michael@0: if (result.isRecycled()) { michael@0: throw new IllegalStateException("Target callback must not recycle bitmap!"); michael@0: } michael@0: } michael@0: } michael@0: michael@0: @Override void error() { michael@0: Target target = getTarget(); michael@0: if (target != null) { michael@0: target.onBitmapFailed(errorDrawable); michael@0: } michael@0: } michael@0: }