1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/com/squareup/picasso/DeferredRequestCreator.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 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.view.ViewTreeObserver; 1.22 +import android.widget.ImageView; 1.23 +import java.lang.ref.WeakReference; 1.24 + 1.25 +class DeferredRequestCreator implements ViewTreeObserver.OnPreDrawListener { 1.26 + 1.27 + final RequestCreator creator; 1.28 + final WeakReference<ImageView> target; 1.29 + Callback callback; 1.30 + 1.31 + DeferredRequestCreator(RequestCreator creator, ImageView target, Callback callback) { 1.32 + this.creator = creator; 1.33 + this.target = new WeakReference<ImageView>(target); 1.34 + this.callback = callback; 1.35 + target.getViewTreeObserver().addOnPreDrawListener(this); 1.36 + } 1.37 + 1.38 + @Override public boolean onPreDraw() { 1.39 + ImageView target = this.target.get(); 1.40 + if (target == null) { 1.41 + return true; 1.42 + } 1.43 + ViewTreeObserver vto = target.getViewTreeObserver(); 1.44 + if (!vto.isAlive()) { 1.45 + return true; 1.46 + } 1.47 + 1.48 + int width = target.getMeasuredWidth(); 1.49 + int height = target.getMeasuredHeight(); 1.50 + 1.51 + if (width <= 0 || height <= 0) { 1.52 + return true; 1.53 + } 1.54 + 1.55 + vto.removeOnPreDrawListener(this); 1.56 + 1.57 + this.creator.unfit().resize(width, height).into(target, callback); 1.58 + return true; 1.59 + } 1.60 + 1.61 + void cancel() { 1.62 + callback = null; 1.63 + ImageView target = this.target.get(); 1.64 + if (target == null) { 1.65 + return; 1.66 + } 1.67 + ViewTreeObserver vto = target.getViewTreeObserver(); 1.68 + if (!vto.isAlive()) { 1.69 + return; 1.70 + } 1.71 + vto.removeOnPreDrawListener(this); 1.72 + } 1.73 +}