package com.wangjie.wavecompat;

import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.widget.PopupWindow;

/**
 * Author: wangjie
 * Email: tiantian.china.2@gmail.com
 * Date: 5/27/15.
 */
public abstract class WaveContainer extends PopupWindow implements WaveDrawable.OnWaveDrawableListener {

    private static final String TAG = WaveContainer.class.getSimpleName();
    private WaveDrawableBase waveDrawable;

    public WaveContainer(View view, WaveDrawableBase waveDrawable, int width, int height) {
        super(view, width, height, false);
        this.waveDrawable = waveDrawable;
        initWaveDrawable(view);
    }

    private void initWaveDrawable(View view) {
//        WaveDrawable waveDrawable = new WaveDrawable(view);
//        waveDrawable.setFrameBitmap(frameBitmap);
        waveDrawable.setOnWaveDrawableListener(this);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
            view.setBackgroundDrawable(waveDrawable);
        } else {
            view.setBackground(waveDrawable);
        }
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
            view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }

    }


    @Override
    public void onWaveDrawableAnimatorStart() {

    }

    @Override
    public void onWaveDrawableAnimatorEnd() {
        if (!this.isShowing()) {
            return;
        }
        onWaveDrawableAnimatorEndExtraAction();
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            @Override
            public void run() {
                try {
                    WaveContainer.this.dismiss();
                } catch (Exception ex) {
                    Log.w(TAG, ex);
                }
            }
        }, 500);
    }

    protected abstract void onWaveDrawableAnimatorEndExtraAction();
}

@@ -45,16 +45,20 @@
 oid.
-os.Build
+app.Activity
 ;%0Aim
@@ -74,18 +74,23 @@
 oid.
-os.Handler
+content.Context
 ;%0Aim
@@ -105,22 +105,21 @@
 roid.os.
-Looper
+Build
 ;%0Aimport
@@ -1471,32 +1471,329 @@
 turn;%0A        %7D%0A
+        View view = getContentView();%0A        Context context = view.getContext();%0A        if (context instanceof Activity) %7B%0A            Activity activity = ((Activity) context);%0A            if (activity.isFinishing()) %7B%0A                dismiss();%0A                return;%0A            %7D%0A        %7D%0A
         onWaveDr
@@ -1836,43 +1836,12 @@
     
-new Handler(Looper.getMainLooper())
+view
 .pos

fix not attached to window(activity leak) error