package com.cygnusa.hyperm.util;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.cygnusa.hyperm.R;


public class TransparentProgressDialog extends Dialog {

    private RotateLoading rotateLoading;
    private ImageView imageView;

    public TransparentProgressDialog(Context context) {
        super(context, R.style.TransparentProgressDialog);

        WindowManager.LayoutParams wlmp = getWindow().getAttributes();
        wlmp.gravity = Gravity.CENTER_HORIZONTAL;
        getWindow().setAttributes(wlmp);

        setTitle(null);
        setCancelable(false);
        setOnCancelListener(null);
        FrameLayout layout = new FrameLayout(context);
//		layout.setOrientation(LinearLayout.VERTICAL);
//		layout.setGravity(Gravity.CENTER);
       // layout.setBackgroundResource(R.drawable.white_back);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        rotateLoading = new RotateLoading(context);

        imageView = new ImageView(context);
        imageView.setBackgroundColor(Color.TRANSPARENT);
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        imageView.setImageResource(R.mipmap.loader);
        FrameLayout.LayoutParams pm = new FrameLayout.LayoutParams((int) context.getResources()
                .getDimension(R.dimen.buttonHeightSmall), (int) context
                .getResources().getDimension(R.dimen.buttonHeightSmall));
        pm.gravity = Gravity.CENTER;
        layout.addView(imageView, pm);

        FrameLayout.LayoutParams pm1 = new FrameLayout.LayoutParams((int) context.getResources()
                .getDimension(R.dimen.buttonHeightLarge), (int) context
                .getResources().getDimension(R.dimen.buttonHeightLarge));
        pm1.gravity = Gravity.CENTER;
        layout.addView(rotateLoading, pm1);
        addContentView(layout, params);;
    }

    @Override
    public void show() {
        super.show();

        if (rotateLoading.isStart()) {
            rotateLoading.stop();
        } else {
            rotateLoading.start();
        }
    }

}