package com.sybotan.android.demo.tools;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.text.Layout;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;


import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.net.URLConnection;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 通用工具类
 * Created by wangmaobo on 2018/4/26.
 */
public class CommonUtils {
    /**
     * 判断是否为空
     *
     * @param object
     * @return
     */
    public static boolean IsNull(Object object) {
        if (null == object) {
            return true;
        } else {
            if (object instanceof String) {
                if (TextUtils.isEmpty((String) object)) {
                    return true;
                }
            } else if (object instanceof List) {
                if (((List) object).size() <= 0) {
                    return true;
                }
            } else if (object instanceof Map) {
                if (((Map) object).size() <= 0) {
                    return true;
                }
            } else if (object instanceof Set) {
                if (((Set) object).size() <= 0) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 获取时间段
     *
     * @param startTime
     * @param endTime
     * @return
     */
    public static String getTimeMoment(String startTime, String endTime) {
        long start = dateToMillisecond("yyyyMMddHHmmss", startTime);
        long end = dateToMillisecond("yyyyMMddHHmmss", endTime);
        long moment = end - start;
        String result = secondToTimeDHMS(moment);
        return result;
    }

    /**
     * 将自定义格式的日期转化为毫秒
     *
     * @param format
     * @param data
     * @return
     */
    public static long dateToMillisecond(String format, String data) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try {
            long startTime = sdf.parse(data).getTime();
            return startTime;
        } catch (ParseException e) {
            Log.e("tag", "抛异常了，转化失败");
            e.printStackTrace();
        }
        return -1;
    }

    /**
     * 毫将秒数转换为日时分秒，
     *
     * @param second
     * @return
     */
    public static String secondToTime(long second) {
        second = second / 1000;
        long days = second / 86400;
        second = second % 86400;
        long hours = second / 3600;
        second = second % 3600;
        long minutes = second / 60;
        //second = second % 60;
        if (days > 0) {
            if (hours > 0) {
                return days + "天" + hours + "小时" + minutes + "分";
            } else {
                return days + "天" + minutes + "分";
            }
        } else {
            if (hours > 0) {
                return hours + "小时" + minutes + "分";
            } else {
                return minutes + "分";
            }

        }
    }

    /**
     * 毫将秒数转换为日时分秒，
     *
     * @param second
     * @return
     */
    public static String secondToTimeDHMS(long second) {
        second = second / 1000;
        long days = second / 86400;
        second = second % 86400;
        long hours = second / 3600;
        second = second % 3600;
        long minutes = second / 60;
        second = second % 60;
        StringBuilder stringBuilder = new StringBuilder();
        if (days > 0) {
            stringBuilder.append(days + "天");
        }
        if (hours > 0) {
            stringBuilder.append(hours + "小时");
        }
        if (minutes > 0) {
            stringBuilder.append(minutes + "分");
        }
        if (second > 0) {
            stringBuilder.append(second + "秒");
        }
        return stringBuilder.toString();
    }

    /**
     * list 集合去重-基本类型
     */
    public static ArrayList removeRepeatElement(ArrayList list) {
        HashSet hs = new HashSet(list);
        list.clear();
        list.addAll(hs);
        return list;
    }

    /**
     * @param context
     * @param target  目标view
     * @param pxSpace 留白空间-单位dp
     */
    public static void setTextViewMaxWidth(Context context, TextView target, int pxSpace) {
        int screenWidth = ScreenUtils.getScreenWidth(context);
        target.setMaxWidth(screenWidth - pxSpace);
    }

    /**
     * Description: 获取当前版本信息
     *
     * @param context
     * @return 数组 0： 版本号 1： 版本名称
     */
    public static String[] getVersionMsg(Context context) {
        // 获取packagemanager的实例
        PackageManager packageManager = context.getPackageManager();
        // getPackageName()是你当前类的包名，0代表是获取版本信息
        PackageInfo packInfo = null;
        try {
            packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String versionCode = String.valueOf(packInfo.versionCode);
        String versionName = packInfo.versionName;
        return new String[]{versionCode, versionName};
    }

    /**
     * 适用于父控件为相对布局
     *
     * @param view
     * @param margin
     */
    public static void setLeftMargin(View view, int margin) {
        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) view.getLayoutParams();
        lp.leftMargin = margin;
        view.setLayoutParams(lp);
    }

    public static void setRightMargin(View view, int margin) {
        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) view.getLayoutParams();
        lp.rightMargin = margin;
        view.setLayoutParams(lp);
    }

    public static String MD5(String url) {
        Log.e("tag_MD5", url);
        String cacheKey;
        try {
            final MessageDigest mDigest = MessageDigest.getInstance("MD5");
            mDigest.update(url.getBytes());
            byte[] bytes = mDigest.digest();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < bytes.length; i++) {
                String hex = Integer.toHexString(0xFF & bytes[i]);
                if (hex.length() == 1) {
                    sb.append('0');
                }
                sb.append(hex);
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            cacheKey = String.valueOf(url.hashCode());
        }
        return cacheKey;
    }

    private static long lastClickTime;

    /**
     * 防止用户连续点击
     *
     * @return true:连续点击 false：单次点击
     */
    public static boolean isFastDoubleClick() {
        long time = System.currentTimeMillis();
        long timeD = time - lastClickTime;
        if (0 < timeD && timeD < 500) {
            return true;
        }
        lastClickTime = time;
        return false;
    }

    private static long last1Time;

    /**
     * 防止用户连续点击
     *
     * @return true:连续点击 false：单次点击
     */
    public static boolean is1Time() {
        long time = System.currentTimeMillis();
        long timeD = time - last1Time;
        if (0 < timeD && timeD < 1000) {
            return true;
        }
        last1Time = time;
        return false;
    }

    private static long last10Time;

    /**
     * 防止用户连续点击
     *
     * @return true:连续点击 false：单次点击
     */
    public static boolean is10Time() {
        long time = System.currentTimeMillis();
        long timeD = time - last10Time;
        if (0 < timeD && timeD < 10 * 1000) {
            return true;
        }
        last10Time = time;
        return false;
    }

    /**
     * @param view   要动态设置高度的RecyclerView,最多放四个imageview
     * @param margin 边距
     * @note 根据屏幕宽度和边距动态设置高度
     */
    public static int setImageRecyclerViewHeight(RecyclerView view, int margin) {
        int screenWidth = ScreenUtils.getScreenWidth(view.getContext());
        int maxWidth = screenWidth - margin;
        int singWidth = maxWidth / 4;
        ViewGroup.LayoutParams mParams = view.getLayoutParams();
        mParams.height = singWidth;
        mParams.width = maxWidth;
        view.setLayoutParams(mParams);
        return singWidth;
    }

    /**
     * @param view
     * @param margin
     * @param singleNum
     * @param maxNum
     * @return
     */
    public static int setImageRecyclerViewHeight(RecyclerView view, int margin, int singleNum, int maxNum, boolean isPreview) {
        if (singleNum == 0) {
            return 0;
        }
        int sumLine = maxNum / singleNum;
        int extra = maxNum % singleNum;
        if (extra != 0) {
            sumLine += 1;
        }
        int screenWidth = ScreenUtils.getScreenWidth(view.getContext());
        int maxWidth = screenWidth - margin;
        int singWidth = maxWidth / singleNum;
        ViewGroup.LayoutParams mParams = view.getLayoutParams();
        if (isPreview) {
            sumLine = sumLine <= 0 ? 1 : sumLine;
            mParams.height = singWidth * sumLine + (DensityUtils.dp2px(view.getContext(), 4) * sumLine);//分割线的高度
            Log.e("tag", "sumLine=" + sumLine + ",singleWidth=" + singWidth);
        }
        mParams.width = maxWidth;
        view.setLayoutParams(mParams);
        return singWidth;
    }

    public static String formatDate(String time) {
        if (time.length() >= 14) {
            String year, mouth, day, hour, minute;
            year = time.substring(0, 4);
            mouth = time.substring(4, 6);
            day = time.substring(6, 8);
            hour = time.substring(8, 10);
            minute = time.substring(10, 12);
            return year + "-" + mouth + "-" + day + " " + hour + ":" + minute;
        }
        return null;
    }

    /**
     * 将某种格式的string日期转化为某种格式的string日期
     *
     * @param format_pre   入参日期的格式
     * @param format_after 出参日期的格式
     * @param time         入参日期
     * @return 出参日期
     */
    public static String formatDate(String format_pre, String format_after, String time) {
        if (TextUtils.isEmpty(time)) {
            return "--";
        }
        String result = null;
        SimpleDateFormat sdf_pre = new SimpleDateFormat(format_pre);
        SimpleDateFormat sdf_after = new SimpleDateFormat(format_after);
        try {
            Date date = sdf_pre.parse(time);
            result = sdf_after.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 制定的日期与当前日期对比
     *
     * @param time
     * @return 负值为比当前时间晚，正值为比当前时间早
     */
    public static long compareTime(String time) {
        DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//创建日期转换对象HH:mm:ss为时分秒，年月日为yyyy-MM-dd
        try {
            Date dt1 = df.parse(time);//将字符串转换为date类型
            Date dt2 = df.parse(df.format(new Date()));
            Calendar c1 = Calendar.getInstance();
            Calendar c2 = Calendar.getInstance();
            c1.setTime(dt1);
            c2.setTime(dt2);

            int result = c2.compareTo(c1);
            Log.e("tag", "差值：" + result);
            return result;
        } catch (ParseException e) {
        }
        return -1;
    }

    /**
     * 制定的日期与当前日期对比
     *
     * @param time
     * @return 负值为比当前时间晚，正值为比当前时间早
     */
    public static long compareTimeTwo(String time) {
        DateFormat df = new SimpleDateFormat("yyyyMMdd");//创建日期转换对象HH:mm:ss为时分秒，年月日为yyyy-MM-dd
        try {
            Date dt1 = df.parse(time);//将字符串转换为date类型
            Date dt2 = df.parse(df.format(new Date()));
            Calendar c1 = Calendar.getInstance();
            Calendar c2 = Calendar.getInstance();
            c1.setTime(dt1);
            c2.setTime(dt2);

            int result = c2.compareTo(c1);
            Log.e("tag", "差值：" + result);
            return result;
        } catch (ParseException e) {
        }
        return -1;
    }

    //===================================数据部分===============================================
    public static String getCheckDescription(String recommend_control_code, boolean isOrder) {
        StringBuilder sb = new StringBuilder();
        sb.append((isOrder ? "工单" : "任务节点") + "-");
        switch (recommend_control_code) {
            case "auditMatters":
            case "approvalMatters":
                sb.append("申请事项");
                break;
            case "auditAddingPeople":
            case "approvalAddingPeople":
                sb.append("申请加人");
                break;
            case "auditReplacePeople":
            case "approvalReplacePeople":
                sb.append("申请换人");
                break;
            case "auditDelay":
            case "approvalDelay":
                sb.append("申请延期");
                break;
            case "auditClose":
            case "approvalClose":
                sb.append("申请结束");
                break;
            case "auditStop":
            case "approvalStop":
                sb.append("申请终止");
                break;
            case "auditPause":
            case "approvalPause":
                sb.append("申请暂停");
                break;
        }
        return sb.toString();
    }

    /**
     * 是否应该显示 查看更多
     *
     * @param tv_content 被观察者对象
     * @param checkAll   需要显隐的查看更多view
     */
    public static void showCheckAll(TextView tv_content, TextView checkAll) {
        //checkAll.setVisibility(View.VISIBLE);
        tv_content.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                Layout l = tv_content.getLayout();
                if (l != null) {
                    int lines = l.getLineCount();
                    if (lines > 0) {
                        if (l.getEllipsisCount(lines - 1) > 0) {
                            checkAll.setVisibility(View.VISIBLE);
                            checkAll.setOnClickListener(v1 -> {
                                if (checkAll.getText().equals("点击收起")) {
                                    checkAll.setText("展开更多");
                                    tv_content.setEllipsize(TextUtils.TruncateAt.END);
                                    tv_content.setMaxLines(2);
                                } else {
                                    //显示TextView的全部内容其实就是取消这类隐藏文字的属性
                                    tv_content.setEllipsize(null);
                                    tv_content.setMaxLines(100);
                                    checkAll.setText("点击收起");
                                }
                                //checkAll.setVisibility(View.GONE);
                            });
                        } else {
                            checkAll.setVisibility(View.GONE);
                        }
                    }
                }
            }
        });
    }

    /**
     * 获取版本号
     *
     * @param context 上下文
     * @return 版本号
     */
    public static int getVersionCode(Context context) {

        //获取包管理器
        PackageManager pm = context.getPackageManager();
        //获取包信息
        try {
            PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
            //返回版本号
            return packageInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        return 0;

    }

    public static String formatString(String resource) {
        if (TextUtils.isEmpty(resource)) {
            return "--";
        }
        return resource;
    }

    public static void formatStringAndView(String resource, TextView view) {
        if (TextUtils.isEmpty(resource)) {
            view.setVisibility(View.GONE);
        } else {
            view.setText(resource);
            view.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 结束时间是否在 当前时间之后
     * @param endTime
     * @return
     */
    public  static  boolean setComparisonOfSize(Date  endTime){
        Date date = new Date(CommonUtils.translateMillionToCertain(System.currentTimeMillis(), "yyyyMMddHHmmss") );
       return endTime.before(date);

    }

    /**
     * 父控件为LinearLayout
     *
     * @param view
     * @param left
     * @param top
     * @param right
     * @param bottom
     */
    public static void setMargins(View view, int left, int top, int right, int bottom) {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
        params.setMargins(DensityUtils.dp2px(view.getContext(), left), top, DensityUtils.dp2px(view.getContext(), right), bottom);
        view.setLayoutParams(params);
    }

    public static void setMarginsRl(View view, int left, int top, int right, int bottom) {
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.getLayoutParams();
        params.setMargins(DensityUtils.dp2px(view.getContext(), left), top, DensityUtils.dp2px(view.getContext(), right), bottom);
        view.setLayoutParams(params);
    }

    public static String getCertainDate(int day) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        calendar.add(Calendar.DATE, day);
        String result = sdf.format(calendar.getTime());
        return result;
    }

    /**
     * 将制定毫秒的long转化为制定格式的日期
     *
     * @param mill
     * @param format
     * @return
     */
    public static String translateMillionToCertain(long mill, String format) {
        Date date = new Date(mill);
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }

    /**
     * 判断是否是当前年
     *
     * @param yyyyMMddHHmmss
     * @return
     */
    public static boolean isThisYear(String yyyyMMddHHmmss) {
        try {
            String nowDate = new SimpleDateFormat("yyyyMMddHHmmss").format(new java.sql.Date(System.currentTimeMillis()));
            return nowDate.substring(0, 4).equals(yyyyMMddHHmmss.substring(0, 4));
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * 判断是否是当前天
     *
     * @param yyyyMMddHHmmss
     * @return
     */
    public static boolean isThisDay(String yyyyMMddHHmmss) {
        try {
            String nowDate = new SimpleDateFormat("yyyyMMddHHmmss").format(new java.sql.Date(System.currentTimeMillis()));
            return nowDate.substring(0, 8).equals(yyyyMMddHHmmss.substring(0, 8));
        } catch (Exception e) {
            return false;
        }
    }

    public static String translateDateToCertain(Date date, String format) {//yyyyMMddHHmmss
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }

    public static void setTextNotNull(TextView tv, String text) {
        if (TextUtils.isEmpty(text)) {
            text = "--";
        }
        tv.setText(text);
    }

    public static <T> T mapToObject(Map<String, Object> map, Class<T> beanClass) throws Exception {
        if (map == null)
            return null;

        T obj = beanClass.newInstance();

        Field[] fields = obj.getClass().getDeclaredFields();
        for (Field field : fields) {
            int mod = field.getModifiers();
            if (Modifier.isStatic(mod) || Modifier.isFinal(mod)) {
                continue;
            }

            field.setAccessible(true);
            field.set(obj, map.get(field.getName()));
        }

        return obj;
    }

    /**
     * 获取百度的网络时间
     *
     * @return
     */
    public static String getNetworkTime() {
        try {
            URL url = new URL("http://www.baidu.com");
            URLConnection conn = url.openConnection();
            conn.connect();
            long dateL = conn.getDate();
            Date date = new Date(dateL);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
            String format = dateFormat.format(date);
            if (dateL == 0 || format.equals("19700101080000")) {
                format = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date(System.currentTimeMillis()));
            }
            return format;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date(System.currentTimeMillis()));
    }

    /**
     * 过滤掉中文
     *
     * @param str 待过滤中文的字符串
     * @return 过滤掉中文后字符串
     */
    public static String filterChinese(String str) {
        // 用于返回结果
        String result = str;
        boolean flag = isContainChinese(str);
        if (flag) {// 包含中文
            // 用于拼接过滤中文后的字符
            StringBuffer sb = new StringBuffer();
            // 用于校验是否为中文
            boolean flag2 = false;
            // 用于临时存储单字符
            char chinese = 0;
            // 5.去除掉文件名中的中文
            // 将字符串转换成char[]
            char[] charArray = str.toCharArray();
            // 过滤到中文及中文字符
            for (int i = 0; i < charArray.length; i++) {
                chinese = charArray[i];
                flag2 = isChinese(chinese);
                if (!flag2) {// 不是中日韩文字及标点符号
                    sb.append(chinese);
                }
            }
            result = sb.toString();
        }
        return result;
    }

    /**
     * 判定输入的是否是汉字
     *
     * @param c 被校验的字符
     * @return true代表是汉字
     */
    public static boolean isChinese(char c) {
        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
        if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
                || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
                || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
                || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
                || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
            return true;
        }
        return false;
    }

    /**
     * 判断字符串中是否包含中文
     *
     * @param str 待校验字符串
     * @return 是否为中文
     * @warn 不能校验是否为中文标点符号
     */
    public static boolean isContainChinese(String str) {
        Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
        Matcher m = p.matcher(str);
        if (m.find()) {
            return true;
        }
        return false;
    }

    /**
     * 判断字符是否是数字
     *
     * @param str 字符串
     * @return 是否是数字
     */
    public static boolean isNumeric(String str) {
        for (int i = str.length(); --i >= 0; ) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    /**
     * 获取版本名称
     *
     * @param context 上下文
     * @return 版本名称
     */
    public static String getVersionName(Context context) {

        //获取包管理器
        PackageManager pm = context.getPackageManager();
        //获取包信息
        try {
            PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
            //返回版本号
            return packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        return "";

    }

    public static String upNum(int i) {
        switch (i) {
            case 1:
                return "一";
            case 2:
                return "二";
            case 3:
                return "三";
            case 4:
                return "四";
            case 5:
                return "五";
            case 6:
                return "六";
            case 7:
                return "七";
            case 8:
                return "八";
            case 9:
                return "九";
            case 10:
                return "十";
            case 11:
                return "十一";
            case 12:
                return "十二";
            case 13:
                return "十三";
            case 14:
                return "十四";
            case 15:
                return "十五";
            case 16:
                return "十六";
            case 17:
                return "十七";
            case 18:
                return "十八";
            case 19:
                return "十九";
            case 20:
                return "二十";
        }
        return "";
    }

    public static int getNum(String s) {
        String regEx = "[^0-9]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(s);
        return Integer.parseInt(m.replaceAll("").trim());
    }

    /**
     * 是否包含英文和数字
     */
    public static boolean isContainLetterAndNum(String str) {
        Pattern pattern = Pattern.compile("^(?=.*[a-zA-Z])(?=.*\\d)[a-zA-Z0-9_\\-!@#\\^\\$\\!\\*]{6,}$");
        Matcher matcher = pattern.matcher(str);
        return matcher.find();
    }

    /**
     * 是否包含英文和数字(8-15位)--万达青训
     *
     * @param str
     * @return
     */
    public static boolean isContainLetterAndNumForWanda(String str) {
        Pattern pattern = Pattern.compile("^(?=.*[a-zA-Z])(?=.*\\d)[a-zA-Z0-9_\\-!@#\\^\\$\\!\\*]{8,15}$");
        Matcher matcher = pattern.matcher(str);
        return matcher.find();
    }

    // 判断一个字符串是否含有数字
    private static boolean hasDigit(String content) {
        boolean flag = false;
        Pattern p = Pattern.compile(".*\\d+.*");
        Matcher m = p.matcher(content);
        if (m.matches()) {
            flag = true;
        }
        return flag;
    }

    /*
     * 判断字符串中是否含有英文，包含返回true
     */
    private static boolean isENChar(String string) {
        boolean flag = false;
        Pattern p = Pattern.compile("[a-zA-z]");
        if (p.matcher(string).find()) {
            flag = true;
        }
        return flag;
    }

    public static boolean CheckPhone(String phone) {//判断手机号格式  
//        Pattern pattern = Pattern.compile("^[1][3-8][0-9]{9}$");
//        Matcher matcher = pattern.matcher(phone);
//        return matcher;
        return phone.length() == 11 && CommonUtils.isNumeric(phone);
    }

    /**
     * 拨打电话
     *
     * @param mContext
     * @param phone
     */
    public static void callPhone(Context mContext, String phone) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + phone);
        intent.setData(data);
        mContext.startActivity(intent);
    }

    public static boolean isEquals(ArrayList<String> a, ArrayList<String> b) {
        if (a.size() != b.size()) {
            return false;
        }
        for (int i = 0; i != (a.size() < b.size() ? a.size() : b.size()); i++)
            if (!a.get(i).equals(b.get(i))) return false;
        return true;
    }

    public static String changeTime(long time) {
        StringBuilder stringBuilder = new StringBuilder();
        int day = (int) Math.floor(time / (1000 * 60 * 60 * 24));
        if (day > 0) {
            stringBuilder.append(day).append("天");;
        }
        int hour = (int) Math.floor(( time / (1000 * 60 * 60)) % 24);
        if (hour > 0) {
            stringBuilder.append(hour).append("小时");;
        }
        int minutes = (int) Math.floor(( time / (1000 * 60)) % 60);
        if (minutes > 0) {
            stringBuilder.append(minutes).append("分钟");
        }
        if (TextUtils.isEmpty(stringBuilder.toString())) {
            stringBuilder.append("1分钟");
        }
        return stringBuilder.toString();
    }

    public static String subZeroAndDot(String s) {
        if (s.indexOf(".") > 0) {
            s = s.replaceAll("0+?$", "");//去掉多余的0
            s = s.replaceAll("[.]$", "");//如最后一位是.则去掉
        }
        return s;
    }

}
