package com.tjzhxx.union.system;/**
 * Created by Administrator on 2016/4/29.
 */

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.text.Html;
import android.text.TextUtils;
import android.view.Display;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.tjzhxx.union.R;


/**
 * 描述:
 * @author yanghuaxiong
 * @create 2018/5/8 下午2:36
 *
 */
public class HodingViewDialog extends Dialog {
    private ImageView ivProcess;
    private TextView tvHodingText;
    private Context mContext;
    public HodingViewDialog(Context context, String message) {
        super(context, R.style.dialogHodingView);
        setContentView(R.layout.layout_viewhandler);
        this.mContext=context;
        ivProcess=(ImageView)findViewById(R.id.iv_progressbar);
        tvHodingText=(TextView) findViewById(R.id.tv_hodingtext);
        setCancelable(false);
        if(message==null|| TextUtils.isEmpty(message)) {
           message=context.getResources().getString(R.string.app_name);
        }
        tvHodingText.setText(Html.fromHtml(message));
        AnimationDrawable animationDrawable=(AnimationDrawable)ivProcess.getBackground();
        animationDrawable.start();
    }
    public void setMessage(String message){
        if(mContext!=null&&tvHodingText!=null) {
            if (message == null || TextUtils.isEmpty(message)) {
                message = mContext.getResources().getString(R.string.app_name);
            }
            tvHodingText.setText(Html.fromHtml(message));
        }
    }
    @SuppressWarnings("deprecation")
    @Override
    public void show() {
        Window dialogWindow = this.getWindow();
        //dialogWindow.setWindowAnimations(yn.huanyi.app.components.R.style.dialogWindowAnim);
        WindowManager windowManager = dialogWindow.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER_HORIZONTAL
                | Gravity.CENTER_VERTICAL);
        lp.width = display.getWidth();
        lp.height=display.getWidth();
        dialogWindow.setAttributes(lp);
        super.show();
    }
}
