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

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 /*
     2  * Copyright (C) 2013 Square, Inc.
     3  *
     4  * Licensed under the Apache License, Version 2.0 (the "License");
     5  * you may not use this file except in compliance with the License.
     6  * You may obtain a copy of the License at
     7  *
     8  *      http://www.apache.org/licenses/LICENSE-2.0
     9  *
    10  * Unless required by applicable law or agreed to in writing, software
    11  * distributed under the License is distributed on an "AS IS" BASIS,
    12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  * See the License for the specific language governing permissions and
    14  * limitations under the License.
    15  */
    16 package com.squareup.picasso;
    18 import android.view.ViewTreeObserver;
    19 import android.widget.ImageView;
    20 import java.lang.ref.WeakReference;
    22 class DeferredRequestCreator implements ViewTreeObserver.OnPreDrawListener {
    24   final RequestCreator creator;
    25   final WeakReference<ImageView> target;
    26   Callback callback;
    28   DeferredRequestCreator(RequestCreator creator, ImageView target, Callback callback) {
    29     this.creator = creator;
    30     this.target = new WeakReference<ImageView>(target);
    31     this.callback = callback;
    32     target.getViewTreeObserver().addOnPreDrawListener(this);
    33   }
    35   @Override public boolean onPreDraw() {
    36     ImageView target = this.target.get();
    37     if (target == null) {
    38       return true;
    39     }
    40     ViewTreeObserver vto = target.getViewTreeObserver();
    41     if (!vto.isAlive()) {
    42       return true;
    43     }
    45     int width = target.getMeasuredWidth();
    46     int height = target.getMeasuredHeight();
    48     if (width <= 0 || height <= 0) {
    49       return true;
    50     }
    52     vto.removeOnPreDrawListener(this);
    54     this.creator.unfit().resize(width, height).into(target, callback);
    55     return true;
    56   }
    58   void cancel() {
    59     callback = null;
    60     ImageView target = this.target.get();
    61     if (target == null) {
    62       return;
    63     }
    64     ViewTreeObserver vto = target.getViewTreeObserver();
    65     if (!vto.isAlive()) {
    66       return;
    67     }
    68     vto.removeOnPreDrawListener(this);
    69   }
    70 }

mercurial