package com.baoshi.swms.util;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baoshi.swms.R;

/**
 * 提示相关工具类
 *
 * @author Zhendong Zhou
 * @date   2021/12/3 18:06
 */
public class Hint {
    public static final int COMMON    = 0;
    public static final int ERROR     = 1;

    public static void toastShort(Context context, CharSequence text, int mode)
    {
        int background;
        int textColor = Color.WHITE;
        switch (mode){
            case COMMON:
                background = R.drawable.shape_corner;
                break;
            default:
                background = R.drawable.shape_corner_error;
        }
        Toast toast = new Toast(context);
        toast.setDuration(Toast.LENGTH_SHORT);
        LinearLayout layout = new LinearLayout(context);
        layout.setBackgroundResource(background);
        layout.setPadding(30,30,30,30);
        TextView tv = new TextView(context);
        tv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));
        tv.setText(text);
        tv.setTextSize(15);
        tv.setTextColor(textColor);
        layout.addView(tv);
        toast.setView(layout);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    public static ProgressDialog showProgressDialog(String message, Activity mActivity) {
        ProgressDialog mProgressDialog;
        mProgressDialog = new ProgressDialog(mActivity);
        mProgressDialog.setCanceledOnTouchOutside(false);
        mProgressDialog.setCancelable(false);
        mProgressDialog.setMessage(message);
        if (!mProgressDialog.isShowing()) {
            mProgressDialog.show();
        }
        return mProgressDialog;
    }
}
