package io.agora.contract.utils;

import android.content.Context;
import android.net.TrafficStats;

import java.util.Formatter;
import java.util.Locale;

public class Utils {

    private StringBuilder mFormatBuilder;
    private Formatter mFormatter;

    private long lastTotalRxBytes = 0;
    private long lastTimeStamp = 0;

    public Utils() {
        // 转换成字符串的时间
        mFormatBuilder = new StringBuilder();
        mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());

    }

    /**
     * 把毫秒转换成：1:20:30这里形式
     *
     * @param timeMs
     * @return
     */
    public String stringForTime(int timeMs) {
        int totalSeconds = timeMs / 1000;
        int seconds = totalSeconds % 60;

        int minutes = (totalSeconds / 60) % 60;

        int hours = totalSeconds / 3600;

        mFormatBuilder.setLength(0);
        if (hours > 0) {
            return mFormatter.format("%d:%02d:%02d", hours, minutes, seconds)
                    .toString();
        } else {
            return mFormatter.format("%02d:%02d", minutes, seconds).toString();
        }
    }


    /**
     * 判断是否是网络的资源
     * @param uri
     * @return
     */
    public boolean isNetUri(String uri) {
        boolean reault = false;
        if (uri != null) {
            if (uri.toLowerCase().startsWith("http") || uri.toLowerCase().startsWith("rtsp") || uri.toLowerCase().startsWith("mms")) {
                reault = true;
            }
        }
        return reault;
    }


    /**
     * 得到网络速度
     * 每隔两秒调用一次
     * @param context
     * @return
     */
    public String getNetSpeed(Context context) {
        String netSpeed = "0 kb/s";
        long nowTotalRxBytes = TrafficStats.getUidRxBytes(context.getApplicationInfo().uid)==TrafficStats.UNSUPPORTED ? 0 :(TrafficStats.getTotalRxBytes()/1024);//转为KB;
        long nowTimeStamp = System.currentTimeMillis();
        long speed = ((nowTotalRxBytes - lastTotalRxBytes) * 1000 / (nowTimeStamp - lastTimeStamp));//毫秒转换

        lastTimeStamp = nowTimeStamp;
        lastTotalRxBytes = nowTotalRxBytes;
        netSpeed  = String.valueOf(speed) + " kb/s";
        return  netSpeed;
    }


}

@@ -59,16 +59,97 @@
 ontext;%0A
+import android.content.pm.PackageInfo;%0Aimport android.content.pm.PackageManager;%0A
 import a
@@ -2224,11 +2224,658 @@
 %0A    %7D%0A%0A
+    // %E7%89%88%E6%9C%AC%E5%90%8D%0A    public static String getVersionName(Context context) %7B%0A        return getPackageInfo(context).versionName;%0A    %7D%0A%0A    // %E7%89%88%E6%9C%AC%E5%8F%B7%0A    public static int getVersionCode(Context context) %7B%0A        return getPackageInfo(context).versionCode;%0A    %7D%0A%0A    private static PackageInfo getPackageInfo(Context context) %7B%0A        PackageInfo pi = null;%0A        try %7B%0A            PackageManager pm = context.getPackageManager();%0A            pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_CONFIGURATIONS);%0A            return pi;%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A        return pi;%0A    %7D%0A%0A
 %0A%7D%0A

完成了评论界面的开发，完成了应用的更新，完成了混淆和签名apk