/*
 * Copyright (C) 2013 Peng fei Pan <sky@xiaopan.me>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package me.xiaopan.sketch.feature;

import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.widget.ImageView;

import me.xiaopan.sketch.SketchImageView;
import me.xiaopan.sketch.feature.zoom.ImageZoomer;

/**
 * ImageView缩放功能
 */
public class ImageZoomFunction extends SketchImageView.Function {
    private ImageView imageView;

    private ImageZoomer imageZoomer;
    private boolean fromSuperLargeImageFunction;

    public ImageZoomFunction(ImageView imageView) {
        this.imageView = imageView;
        init();
    }

    private void init() {
        ImageZoomer oldImageZoomer = imageZoomer;

        imageZoomer = new ImageZoomer(imageView, true);

        if (oldImageZoomer != null) {
            oldImageZoomer.cleanup();
        }
    }

    @Override
    public void onAttachedToWindow() {
        init();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return imageZoomer.onTouch(imageView, event);
    }

    @Override
    public boolean onDetachedFromWindow() {
        recycle();
        return false;
    }

    @Override
    public boolean onDrawableChanged(String callPosition, Drawable oldDrawable, Drawable newDrawable) {
        imageZoomer.update();
        return false;
    }

    public ImageView.ScaleType getScaleType() {
        return imageZoomer.getScaleType();
    }

    @Override
    public void setScaleType(ImageView.ScaleType scaleType) {
        super.setScaleType(scaleType);
        imageZoomer.setScaleType(scaleType);
    }

    public void recycle() {
        imageZoomer.cleanup();
    }

    public ImageZoomer getImageZoomer() {
        return imageZoomer;
    }

    public boolean isFromSuperLargeImageFunction() {
        return fromSuperLargeImageFunction;
    }

    public void setFromSuperLargeImageFunction(boolean fromSuperLargeImageFunction) {
        this.fromSuperLargeImageFunction = fromSuperLargeImageFunction;
    }
}

@@ -874,16 +874,42 @@
 %E6%94%BE%E5%8A%9F%E8%83%BD%0A */%0A
+// TODO: 16/8/23 %E6%94%AF%E6%8C%81%E6%98%BE%E7%A4%BA%E6%BB%91%E5%8A%A8%E8%BF%9B%E5%BA%A6%0A
 public c

Mark to-do