package com.joker.fourfun.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.widget.Toast;

import com.joker.fourfun.FourFun;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * Created by joker on 2016/11/27.
 */
public class SystemUtil {
    private static Toast mToast;

    /**
     * 网络是否连接
     * @return
     */
    public static boolean isNetworkConnected() {
        ConnectivityManager connectivityManager = (ConnectivityManager) FourFun.getInstance()
                .getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
        return connectivityManager.getActiveNetworkInfo() != null;
    }

    /**
     * toast 优化显示
     * @param context
     * @param content
     */
    public static void showToast(Context context, String content) {
        if (mToast == null) {
            mToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(content);
        }

        mToast.show();
    }

    /**
     * 取消 toast
     */
    public static void cancelToast() {
        if (mToast != null) {
            mToast.cancel();
        }
    }

    /**
     * 前几天的日期
     * @param before 和今天相差的天数
     * @return
     */
    public static String beforeToday(int before) {
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); //设置时间格式

        if (before <= 0) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(now);
            calendar.add(Calendar.DATE, before);
            now = calendar.getTime();
        }

        return sdf.format(now);
    }
}

@@ -59,16 +59,50 @@
 ontext;%0A
+import android.graphics.Typeface;%0A
 import a
@@ -387,35 +387,135 @@
    p
-rivate static Toast mToast;
+ublic static final String RUNNING_FONT = %22running_font.ttf%22;%0A    private static Toast mToast;%0A%0A    private SystemUtil() %7B%0A    %7D
 %0A%0A  
@@ -534,16 +534,23 @@
  %E7%BD%91%E7%BB%9C%E6%98%AF%E5%90%A6%E8%BF%9E%E6%8E%A5%0A
+     *%0A
      * @
@@ -896,16 +896,23 @@
 st %E4%BC%98%E5%8C%96%E6%98%BE%E7%A4%BA%0A
+     *%0A
      * @
@@ -1392,16 +1392,23 @@
  %E5%89%8D%E5%87%A0%E5%A4%A9%E7%9A%84%E6%97%A5%E6%9C%9F%0A
+     *%0A
      * @
@@ -1878,11 +1878,1369 @@
 );%0A    %7D
+%0A%0A    /**%0A     * %E5%83%8F%E7%B4%A0%E8%BD%AC sp%0A     *%0A     * @param context%0A     * @param textSizePixel%0A     * @return%0A     */%0A    public static int px2sp(Context context, float textSizePixel) %7B%0A        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;%0A        return (int) (textSizePixel / fontScale + 0.5f);%0A    %7D%0A%0A    /**%0A     * sp %E8%BD%AC%E5%83%8F%E7%B4%A0%0A     * @param context%0A     * @param textSizeSp%0A     * @return%0A     */%0A    public static float sp2px(Context context, int textSizeSp) %7B%0A        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;%0A        return (int) (textSizeSp * fontScale + 0.5f);%0A    %7D%0A%0A    /**%0A     * dip %E8%BD%AC%E5%83%8F%E7%B4%A0%0A     * @param context%0A     * @param dpValue%0A     * @return%0A     */%0A    public static int dip2px(Context context, float dpValue) %7B%0A        final float scale = context.getResources().getDisplayMetrics().density;%0A        return (int) (dpValue * scale + 0.5f);%0A    %7D%0A%0A    /**%0A     * %E5%83%8F%E7%B4%A0%E8%BD%AC dip%0A     * @param context%0A     * @param pxValue%0A     * @return%0A     */%0A    public static int px2dip(Context context, float pxValue) %7B%0A        final float scale = context.getResources().getDisplayMetrics().density;%0A        return (int) (pxValue / scale + 0.5f);%0A    %7D%0A%0A    public static Typeface getTypeface(Context context) %7B%0A        return Typeface.createFromAsset(context.getAssets(), %22fonts/%22 + RUNNING_FONT);%0A    %7D
 %0A%7D%0A

add typeface