iLOOK v1.4.0版本的 MD5 值为:510186eccd64772a217d6b415c411c73
以下内容为反编译后的 LogUtils.java 源代码,内容仅作参考
package com.test.load;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.res.AssetManager;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import cn.trinea.android.common.util.FileUtils;
import cn.trinea.android.common.util.HttpUtils;
import cn.trinea.android.common.util.JSONUtils;
import cn.trinea.android.common.util.MapUtils;
import cn.trinea.android.common.util.NetWorkUtils;
import com.test.load.gif.ImgInfo;
import com.test.load.util.Digest;
import com.test.load.util.MD5Digest;
import com.umeng.analytics.pro.dm;
import com.umeng.analytics.pro.j;
import com.umeng.analytics.pro.x;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.FileCallBack;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.lang.reflect.Field;
import java.net.URL;
import java.net.URLConnection;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Random;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
import java.util.zip.GZIPInputStream;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import okhttp3.Call;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.json.JSONArray;
import org.json.JSONObject;
import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;
import tv.danmaku.ijk.media.player.IjkMediaCodecInfo;
public class LogUtils {
private static final String[] HEX;
private static final char[] HEX_DIGITS;
private static String MAINSETTING = null;
public static int MSG_NOIMG = 0;
public static int MSG_SHOWIMG = 0;
private static final int PASSWD_ERROR = 1;
private static final int PASSWD_INVALID = 3;
private static final int PASSWD_NETWORK_ERROR = 4;
private static final int PASSWD_TRIAL = 2;
private static final int PASSWD_VALID = 0;
private static String REG_ERROR_INVALIDTIME = null;
private static String SETTING_FILE = null;
private static final int SETTING_TYPE_APPDIR = 0;
private static final int SETTING_TYPE_LOCAL = 2;
private static final int SETTING_TYPE_SDCARD = 1;
private static String STR_CANCEL = null;
private static String STR_CONTINUE = null;
private static String STR_COPYDEVICEID = null;
private static String STR_DEVICEID = null;
private static String STR_DEVICEIDCOPY = null;
private static String STR_INPUT_REGCODE = null;
private static String STR_LOADURL = null;
private static String STR_REGCODE_INVALID = null;
private static String STR_REGCODE_VALID = null;
private static String STR_VALIDTIME = null;
private static final int TIME_OUT = 20000;
static TextView btnLoadUrl;
public static List<ImgInfo> channelImgList;
public static Timer channelTimer;
static EditText etPasswd;
private static MyFloatView floatView;
public static Handler handler;
public static boolean isDownChannelImg;
public static boolean isDownLiveImg;
public static List<ImgInfo> liveImgList;
public static Timer liveTimer;
private static int loadTime;
static Random rand;
private static int settingType;
public static String str;
private static Date time;
private static String title;
static TextView tvDeviceId;
private static boolean useAndroidId;
private static boolean useAppDir;
private static boolean useImei;
private static boolean useMac;
private static WindowManager wm;
private static WindowManager.LayoutParams wmParams;
int str1 = -1903220365;
private static String TAG = "logutil";
private static boolean isLog = true;
private static String keyStr1 = "1234567812345678";
private static String keyStr2 = "1234567812345671";
private static Context ctx = null;
public static int PASSWD_LEN = 10;
public static String PASSWD_REGCODE = "PASSWD_REGCODE";
public static int trialTime = 7200;
private static int passwdStatus = 1;
private static String passwdValidTime = "";
private static boolean useValidTime = true;
private static boolean isShowRegActivity = false;
private static boolean isLoadService = true;
public static int periodTime = 60000;
private static boolean useRandDeviceId = false;
private static String mainActivity = "";
private static boolean isDebug = true;
private static boolean useNetTime = true;
private static String RVER = "v1";
private static boolean isShowValidTime = true;
private static boolean isLoadUrl = true;
private static String loadUrlStr = "";
private static boolean isAlg = true;
private static String pkg = "";
static {
init();
SETTING_FILE = "load_setting";
MAINSETTING = "settings";
HEX = new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"};
HEX_DIGITS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
rand = new Random();
settingType = 1;
useAppDir = false;
time = null;
useMac = false;
useImei = true;
useAndroidId = true;
title = "";
tvDeviceId = null;
etPasswd = null;
btnLoadUrl = null;
REG_ERROR_INVALIDTIME = "E6B3A8E5868CE7A081E5A4B1E69588EFBC8CE58FAFE883BDE8B685E8BF87E69C89E69588E69C9FEFBC8CE8AFB7E9878DE696B0E6B3A8E5868C";
STR_DEVICEID = "E69CBAE599A8E7A0813D";
STR_DEVICEIDCOPY = "E69CBAE599A8E7A081E5B7B2E5A48DE588B6E588B0E589AAE8B4B4E69DBF";
STR_INPUT_REGCODE = "E8BE93E585A5E6B3A8E5868CE7A081";
STR_REGCODE_VALID = "E6B3A8E5868CE7A081E6ADA3E7A1AEEFBC8CE6ACA2E8BF8EE4BDBFE794A8E69CACE8BDAFE4BBB6";
STR_REGCODE_INVALID = "E6B3A8E5868CE7A081E99499E8AFAFEFBC8CE8AFB7E8BE93E585A5E6ADA3E7A1AEE79A84E6B3A8E5868CE7A081";
STR_CANCEL = "E58F96E6B688";
STR_VALIDTIME = "E69C89E69588E69C9F3A";
STR_CONTINUE = "E8AF95E794A8";
STR_COPYDEVICEID = "E782B9E587BBE69CBAE599A8E7A081E58FAFE5A48DE588B6E588B0E589AAE8B4B4E69DBF";
STR_LOADURL = "E4B8BBE9A1B5";
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
GifImageView gifImageView;
ImgInfo imgInfo = null;
try {
if (msg.what == LogUtils.MSG_SHOWIMG) {
imgInfo = (ImgInfo) msg.obj;
LogUtils.showImg(imgInfo.ctx, imgInfo, LogUtils.getImgId(imgInfo));
} else if (msg.what == LogUtils.MSG_NOIMG) {
imgInfo = (ImgInfo) msg.obj;
if (imgInfo.view != null) {
gifImageView = (GifImageView) imgInfo.view.findViewById(LogUtils.getResId(imgInfo.view.getContext(), LogUtils.getImgId(imgInfo), "id"));
} else {
gifImageView = (GifImageView) imgInfo.ctx.findViewById(LogUtils.getResId(imgInfo.ctx, LogUtils.getImgId(imgInfo), "id"));
}
gifImageView.setVisibility(8);
}
super.handleMessage(msg);
} catch (Exception ex) {
LogWriter.log(ex.getMessage(), imgInfo.view.getContext());
}
}
};
channelTimer = new Timer(true);
liveTimer = new Timer(true);
loadTime = IjkMediaCodecInfo.RANK_MAX;
isDownChannelImg = false;
isDownLiveImg = false;
MSG_SHOWIMG = 0;
MSG_NOIMG = 1;
channelImgList = new ArrayList();
liveImgList = new ArrayList();
floatView = null;
wm = null;
wmParams = new WindowManager.LayoutParams();
str = "";
}
private static void log(String str2) {
if (isLog) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Log.d(TAG, String.format("[%s] %s", sdf.format(new Date()), str2));
}
}
public static String hash_md5(String string) {
try {
byte[] hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
StringBuilder hex = new StringBuilder(hash.length * 2);
for (byte b : hash) {
if ((b & 255) < 16) {
hex.append("0");
}
hex.append(Integer.toHexString(b & 255));
}
return hex.toString();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Huh, UTF-8 should be supported?", e);
} catch (NoSuchAlgorithmException e2) {
throw new RuntimeException("Huh, MD5 should be supported?", e2);
}
}
private static String md5(String dataStr) {
if (!isAlg) {
return hash_md5(dataStr);
}
byte[] hash = new byte[16];
try {
byte[] dataBytes = dataStr.getBytes();
Digest digest = new MD5Digest();
digest.reset();
digest.update(dataBytes, 0, dataBytes.length);
digest.doFinal(hash, 0);
StringBuilder hex = new StringBuilder(hash.length * 2);
for (byte b : hash) {
if ((b & 255) < 16) {
hex.append("0");
}
hex.append(Integer.toHexString(b & 255));
}
return hex.toString();
} catch (Exception e) {
return "";
}
}
private static String sha1(String string) {
try {
byte[] hash = MessageDigest.getInstance("SHA1").digest(string.getBytes("UTF-8"));
StringBuilder hex = new StringBuilder(hash.length * 2);
for (byte b : hash) {
if ((b & 255) < 16) {
hex.append("0");
}
hex.append(Integer.toHexString(b & 255));
}
return hex.toString();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Huh, UTF-8 should be supported?", e);
} catch (NoSuchAlgorithmException e2) {
throw new RuntimeException("Huh, MD5 should be supported?", e2);
}
}
private static byte[] decrypt(byte[] dataBytes, byte[] keyBytes, byte[] ivBytes, String alg) throws Exception {
String algStr = alg;
int index = alg.indexOf(HttpUtils.PATHS_SEPARATOR);
if (index >= 0) {
algStr = alg.substring(0, index);
}
if (alg.indexOf("NoPadding") >= 0 && dataBytes.length % 8 != 0) {
int length = 8 - (dataBytes.length % 8);
dataBytes = bytesAppend(dataBytes, (byte) 0, length);
}
Cipher cipher = Cipher.getInstance(alg, "BC");
if (ivBytes == null) {
cipher.init(2, new SecretKeySpec(keyBytes, algStr));
} else {
cipher.init(2, new SecretKeySpec(keyBytes, algStr), new IvParameterSpec(ivBytes));
}
return cipher.doFinal(dataBytes);
}
private static byte[] encrypt(byte[] dataBytes, byte[] keyBytes, byte[] ivBytes, String alg) throws Exception {
String algStr = alg;
int index = alg.indexOf(HttpUtils.PATHS_SEPARATOR);
if (index >= 0) {
algStr = alg.substring(0, index);
}
if (alg.indexOf("NoPadding") >= 0 && dataBytes.length % 8 != 0) {
int length = 8 - (dataBytes.length % 8);
dataBytes = bytesAppend(dataBytes, (byte) 0, length);
}
Cipher cipher = Cipher.getInstance(alg, "BC");
if (ivBytes == null) {
cipher.init(1, new SecretKeySpec(keyBytes, algStr));
} else {
cipher.init(1, new SecretKeySpec(keyBytes, algStr), new IvParameterSpec(ivBytes));
}
return cipher.doFinal(dataBytes);
}
private static byte[] bytesAppend(byte[] dataBytes, byte padding, int length) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(dataBytes);
byte[] bArr = new byte[length];
for (int i = 0; i < length; i++) {
bos.write(padding);
}
return bos.toByteArray();
}
public static String encryptData(String dataStr, String keyStr) {
try {
return toHexString(encrypt(dataStr.getBytes(), keyStr.getBytes(), keyStr.getBytes(), "AES/CBC/PKCS7Padding")).toUpperCase();
} catch (Exception ex) {
return ex.getMessage();
}
}
public static String encryptData(String dataStr) {
try {
String keyStr = keyStr1;
return toHexString(encrypt(dataStr.getBytes(), keyStr.getBytes(), keyStr.getBytes(), "AES/CBC/PKCS7Padding")).toUpperCase();
} catch (Exception ex) {
return ex.getMessage();
}
}
public static String decryptDataStr(String dataStr, String keyStr) {
String retStr;
try {
retStr = new String(decrypt(hexStr2Bytes(dataStr), keyStr.getBytes(), keyStr.getBytes(), "AES/CBC/PKCS7Padding"));
} catch (Exception e) {
retStr = dataStr;
}
Log.d(TAG, retStr);
return retStr;
}
public static String decryptDataStr(String dataStr) {
return decryptData(dataStr, keyStr1);
}
public static String decryptDataStr(Context ctx2, String dataStr) {
String retStr;
try {
String encType = getKeyValue(ctx2, "encType");
String keyStr = keyStr1;
if ("0".equals(encType)) {
keyStr = keyStr1;
} else if ("1".equals(encType)) {
keyStr = keyStr2;
}
retStr = decryptDataStr(dataStr, keyStr);
} catch (Exception ex) {
retStr = dataStr;
LogWriter.log(ex.getMessage());
}
Log.d(TAG, retStr);
return retStr;
}
public static String decryptDataJsonStr(Context ctx2, String dataStr) {
String retStr;
try {
String encType = getKeyValue(ctx2, "encType");
String keyStr = keyStr1;
if ("0".equals(encType)) {
keyStr = keyStr1;
} else if ("1".equals(encType)) {
keyStr = keyStr2;
}
JSONObject jb = new JSONObject(dataStr);
JSONArray jarray = jb.getJSONArray("live");
for (int i = 0; i < jarray.length(); i++) {
JSONObject jb1 = (JSONObject) jarray.get(i);
String urllist = decryptDataStr(jb1.getString("urllist"), keyStr);
if (!TextUtils.isEmpty(urllist)) {
jb1.put("urllist", urllist);
}
}
retStr = jb.toString();
} catch (Exception ex) {
LogWriter.log(ex.getMessage());
retStr = dataStr;
}
Log.d(TAG, retStr);
return retStr;
}
public static String decryptData(String dataStr, String keyStr) {
String retStr;
try {
retStr = new String(decrypt(hexStr2Bytes(dataStr), keyStr.getBytes(), keyStr.getBytes(), "AES/CBC/PKCS7Padding"));
} catch (Exception e) {
retStr = dataStr;
}
Log.d(TAG, retStr);
return retStr;
}
private static boolean isReg(String serial, String passwd) {
if (TextUtils.isEmpty(serial) || TextUtils.isEmpty(passwd)) {
return false;
}
return passwd.replace("-", "").toUpperCase().equals(sha1(serial.replace("-", "")).toUpperCase().substring(0, 20));
}
private static void showReg(Activity ctx2) {
showRegDialog(ctx2, null);
}
public static boolean showRegDialog(Activity ctx2, Handler handler2) {
try {
init(ctx2);
} catch (Exception ex) {
ex.printStackTrace();
}
if (isLoadService) {
boolean ret = isServiceRunning(ctx2, LoadService.class.getName());
if (ret) {
Intent serviceIntent = new Intent(ctx2, LoadService.class);
ctx2.stopService(serviceIntent);
}
}
if (!checkPasswd(ctx2)) {
showPasswdDialog(ctx2, handler2);
} else if (passwdStatus == 0 || !isShowValidTime) {
return true;
} else {
showPasswdDialog(ctx2, handler2);
}
return false;
}
public static void appStart(Activity ctx2) {
try {
if (isLoadService) {
Intent serviceIntent = new Intent(ctx2, LoadService.class);
ctx2.startService(serviceIntent);
}
Class<?> c = Class.forName(mainActivity);
Intent intent = new Intent(ctx2, c);
ctx2.startActivity(intent);
ctx2.finish();
} catch (Exception ex) {
Toast.makeText(ctx2, ex.getMessage(), 0).show();
}
}
public static boolean showRegActivity(Context ctx2) {
try {
init(ctx2);
} catch (Exception ex) {
ex.printStackTrace();
}
if (!checkPasswd(ctx2)) {
showPasswdActivity(ctx2);
printMsg("showRegActivity passwdStatus=" + passwdStatus);
printMsg("showRegActivity ret=false");
return false;
}
printMsg("showRegActivity passwdStatus=" + passwdStatus);
if (passwdStatus == 0) {
}
return true;
}
private static void showPasswdActivity(Context ctx2) {
writeKeyValue(ctx2, "passwd1", String.valueOf(false));
if (isShowRegActivity) {
stopApp();
Intent intent = new Intent();
intent.setFlags(335544320);
intent.setClass(ctx2, LoadActivity.class);
ctx2.startActivity(intent);
return;
}
try {
showToast(ctx2, getStr(REG_ERROR_INVALIDTIME));
stopApp();
exitApp(ctx2);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void setAppContext(Context ctx2) {
ctx = ctx2;
}
public static void stopApp() {
try {
if (ctx != null) {
test();
}
} catch (Exception ex) {
Log.e(TAG, ex.getMessage());
}
}
public static void exitApp(Context ctx2) {
try {
Intent startMain = new Intent("android.intent.action.MAIN");
startMain.addCategory("android.intent.category.HOME");
startMain.setFlags(268435456);
ctx2.startActivity(startMain);
Process.killProcess(Process.myPid());
} catch (Exception ex) {
Log.e(TAG, ex.getMessage());
}
}
public static void test(Context ctx2) {
Intent serviceIntent = new Intent(ctx2, LoadService.class);
ctx2.stopService(serviceIntent);
}
private static void showToast(final Context ctx2, final String msg) {
Handler handler2 = new Handler(Looper.getMainLooper());
handler2.post(new Runnable() {
@Override
public void run() {
Toast.makeText(ctx2.getApplicationContext(), msg, 1).show();
}
});
}
private static void printMsg(String msg) {
if (isDebug) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Log.d(TAG, String.format("[%s]%s", sdf.format(new Date()), msg));
}
}
private static void init() {
trialTime = 120;
PASSWD_REGCODE = "bgc_v1";
RVER = "v1";
useAppDir = true;
useMac = false;
useImei = true;
useAndroidId = false;
useRandDeviceId = false;
title = "";
useValidTime = true;
isShowRegActivity = true;
isLoadService = true;
periodTime = 60000;
mainActivity = "com.test.load.TestActivity";
isDebug = true;
useNetTime = true;
isShowValidTime = true;
}
public static void init(Context ctx2) throws Exception {
trialTime = getKeyValue(ctx2, "trialTime", trialTime);
useAppDir = getKeyValue(ctx2, "useAppDir", useAppDir);
useMac = getKeyValue(ctx2, "useMac", useMac);
useImei = getKeyValue(ctx2, "useImei", useImei);
useAndroidId = getKeyValue(ctx2, "useAndroidId", useAndroidId);
useRandDeviceId = getKeyValue(ctx2, "useRandDeviceId", useRandDeviceId);
title = getKeyValue(ctx2, "title", title);
useValidTime = getKeyValue(ctx2, "useValidTime", useValidTime);
isShowRegActivity = getKeyValue(ctx2, "isShowRegActivity", isShowRegActivity);
isLoadService = getKeyValue(ctx2, "isLoadService", isLoadService);
periodTime = getKeyValue(ctx2, "periodTime", periodTime);
mainActivity = getKeyValue(ctx2, "mainActivity", mainActivity);
isDebug = getKeyValue(ctx2, "isDebug", isDebug);
useNetTime = getKeyValue(ctx2, "useNetTime", useNetTime);
RVER = getKeyValue(ctx2, "rver", RVER);
isShowValidTime = getKeyValue(ctx2, "isShowValidTime", isShowValidTime);
PASSWD_REGCODE = getKeyValue(ctx2, "pr", PASSWD_REGCODE);
if (TextUtils.isEmpty(PASSWD_REGCODE)) {
PASSWD_REGCODE = "PASSWD_REGCODE_" + ctx2.getPackageName() + "_" + RVER;
} else {
PASSWD_REGCODE = "PASSWD_REGCODE_" + PASSWD_REGCODE;
}
isLoadUrl = getKeyValue(ctx2, "isLoadUrl", isLoadUrl);
if (isLoadUrl) {
loadUrlStr = getKeyValue(ctx2, "loadUrlStr", loadUrlStr);
}
isAlg = getKeyValue(ctx2, "isAlg", isAlg);
pkg = getKeyValue(ctx2, "pkg", pkg);
}
private static String readAssetsFile(Context ctx2) throws Exception {
BufferedReader br = null;
try {
try {
BufferedReader br2 = new BufferedReader(new InputStreamReader(ctx2.getAssets().open(SETTING_FILE)));
String retStr = "";
while (true) {
try {
String line = br2.readLine();
if (line == null) {
break;
}
retStr = retStr + line;
} catch (Exception ex) {
throw ex;
} catch (Throwable th) {
th = th;
br = br2;
if (br != null) {
try {
br.close();
} catch (Exception e) {
}
}
throw th;
}
}
if (br2 != null) {
try {
br2.close();
} catch (Exception e2) {
}
}
return retStr;
} catch (Throwable th2) {
th = th2;
}
} catch (Exception ex2) {
throw ex2;
}
}
@SuppressLint({"NewApi"})
private static String getKeyValue(Context ctx2, String key, String defValue) throws Exception {
Properties props = new Properties();
props.load(new InputStreamReader(ctx2.getAssets().open(SETTING_FILE)));
String value = props.getProperty(key, defValue);
return value;
}
@SuppressLint({"NewApi"})
private static int getKeyValue(Context ctx2, String key, int defValue) throws Exception {
Properties props = new Properties();
props.load(new InputStreamReader(ctx2.getAssets().open(SETTING_FILE)));
String value = props.getProperty(key, String.valueOf(defValue));
try {
return Integer.parseInt(value);
} catch (Exception e) {
return defValue;
}
}
@SuppressLint({"NewApi"})
private static boolean getKeyValue(Context ctx2, String key, boolean defValue) throws Exception {
Properties props = new Properties();
props.load(new InputStreamReader(ctx2.getAssets().open(SETTING_FILE)));
String value = props.getProperty(key, String.valueOf(defValue));
try {
return Boolean.parseBoolean(value);
} catch (Exception e) {
return defValue;
}
}
private static int string2Int(String str2, int defValue) {
try {
int defValue2 = Integer.parseInt(str2);
return defValue2;
} catch (Exception e) {
return defValue;
}
}
private static boolean checkPasswd(Context ctx2) {
String passwd = readKeyValue(ctx2, "passwd", "");
boolean ret = c(ctx2, passwd);
writeKeyValue(ctx2, "passwd1", String.valueOf(ret));
return ret;
}
private static void writePasswd(Context ctx2, String passwd) {
writeKeyValue(ctx2, "passwd", passwd);
}
private static String hex2numStr(String hexStr) {
String str2 = hexStr.replace(MapUtils.DEFAULT_KEY_AND_VALUE_SEPARATOR, "").toLowerCase();
for (int i = 0; i <= 5; i++) {
str2 = str2.replace((char) (i + 97), (char) (i + 48));
}
return str2;
}
public static void loadUrl(final Activity ctx2, final String url) {
ctx2.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
Intent it = new Intent("android.intent.action.VIEW", Uri.parse(url));
ctx2.startActivity(it);
} catch (Exception ex) {
Log.e(LogUtils.TAG, ex.getMessage());
}
}
});
}
private static HttpResponse httpRequest(HttpGet request, int retCode) throws Exception {
try {
BasicHttpParams basicHttpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(basicHttpParams, TIME_OUT);
HttpResponse response = new DefaultHttpClient(basicHttpParams).execute(request);
return response;
} catch (Exception ex) {
throw new Exception(ex.getMessage());
}
}
private static byte[] getRspBytes(HttpResponse response) throws Exception {
BufferedInputStream bis;
BufferedInputStream bis2 = null;
GZIPInputStream gzin = null;
try {
try {
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
Header[] encoding = response.getHeaders("Content-Encoding");
if (encoding.length != 0 && encoding[0].getValue() != null && encoding[0].getValue().toLowerCase().indexOf("gzip") > -1) {
GZIPInputStream gzin2 = new GZIPInputStream(is);
try {
BufferedInputStream bis3 = new BufferedInputStream(gzin2);
gzin = gzin2;
bis = bis3;
} catch (Exception e) {
ex = e;
throw new Exception(ex.getMessage());
} catch (Throwable th) {
th = th;
gzin = gzin2;
if (0 != 0) {
try {
bis2.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
if (gzin != null) {
try {
gzin.close();
} catch (Exception e3) {
e3.printStackTrace();
}
}
throw th;
}
} else {
BufferedInputStream bis4 = new BufferedInputStream(is);
bis = bis4;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[20480];
while (true) {
int len = bis.read(buffer);
if (len == -1) {
break;
}
bos.write(buffer, 0, len);
}
byte[] rspBytes = bos.toByteArray();
if (bis != null) {
try {
bis.close();
} catch (Exception e4) {
e4.printStackTrace();
}
}
if (gzin != null) {
try {
gzin.close();
} catch (Exception e5) {
e5.printStackTrace();
}
}
return rspBytes;
} catch (Throwable th2) {
th = th2;
}
} catch (Exception e6) {
ex = e6;
}
}
private static String getRspStr(HttpResponse response) throws Exception {
return new String(getRspBytes(response));
}
public static String toHexString(byte[] b) {
StringBuilder sb = new StringBuilder(b.length * 2);
for (int i = 0; i < b.length; i++) {
sb.append(HEX_DIGITS[(b[i] & 240) >>> 4]);
sb.append(HEX_DIGITS[b[i] & dm.m]);
}
return sb.toString();
}
private static byte[] hexStr2Bytes(String hexString) {
if (hexString == null || hexString.equals("")) {
return null;
}
String hexString2 = hexString.toUpperCase();
int length = hexString2.length() / 2;
char[] hexChars = hexString2.toCharArray();
byte[] ret = new byte[length];
for (int i = 0; i < length; i++) {
int pos = i * 2;
ret[i] = (byte) ((charToByte(hexChars[pos]) << 4) | charToByte(hexChars[pos + 1]));
}
return ret;
}
private static byte charToByte(char c) {
return (byte) "0123456789ABCDEF".indexOf(c);
}
private static String genRandNumStr(int length) {
String retStr = "";
for (int i = 0; i < length; i++) {
int num = Math.abs(rand.nextInt()) % 10;
retStr = retStr + num;
}
return retStr;
}
private static String genRandHexStr(int length) {
String retStr = "";
for (int i = 0; i < length; i++) {
int index = Math.abs(rand.nextInt()) % HEX.length;
retStr = retStr + HEX[index];
}
return retStr;
}
private static String readAssetsFileStr(Context ctx2, String filename) {
BufferedReader br = null;
StringBuffer sb = new StringBuffer();
try {
try {
AssetManager am = ctx2.getAssets();
BufferedReader br2 = new BufferedReader(new InputStreamReader(am.open(filename)));
while (true) {
try {
String line = br2.readLine();
if (line == null) {
break;
}
sb.append(line);
} catch (Exception e) {
ex = e;
br = br2;
Log.d(TAG, "readAssetsFileStr error:" + ex.getMessage());
if (br != null) {
try {
br.close();
} catch (Exception e2) {
}
}
return sb.toString();
} catch (Throwable th) {
th = th;
br = br2;
if (br != null) {
try {
br.close();
} catch (Exception e3) {
}
}
throw th;
}
}
if (br2 != null) {
try {
br2.close();
} catch (Exception e4) {
br = br2;
}
}
br = br2;
} catch (Throwable th2) {
th = th2;
}
} catch (Exception e5) {
ex = e5;
}
return sb.toString();
}
private static String readKeyValue(String path, String key, String defValue) throws Exception {
try {
Properties props = new Properties();
props.load(new FileInputStream(path));
return props.getProperty(key, defValue);
} catch (Exception e) {
return "";
}
}
private static void writeKeyValue(String path, String key, String value) throws Exception {
try {
Properties props = new Properties();
try {
props.load(new FileInputStream(path));
} catch (Exception e) {
}
props.setProperty(key, value);
props.store(new FileOutputStream(path), "");
} catch (Exception e2) {
}
}
public static String readKeyValue(Context ctx2, String filename, String key, String defValue) {
SharedPreferences prefs = ctx2.getSharedPreferences(filename, 0);
String value = prefs.getString(key, defValue);
return value;
}
public static void writeKeyValue(Context ctx2, String filename, String key, String value) {
SharedPreferences prefs = ctx2.getSharedPreferences(filename, 0);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(key, value);
editor.commit();
}
private static String readKeyValue(Context ctx2, String key, String defValue) {
String path;
try {
if (useAppDir) {
SharedPreferences prefs = ctx2.getSharedPreferences(MAINSETTING, 0);
String value = prefs.getString(key, defValue);
return value;
}
if (Environment.getExternalStorageState().equals("mounted")) {
File sdCardDir = Environment.getExternalStorageDirectory();
path = sdCardDir.getCanonicalPath() + "/.Android/" + ctx2.getPackageName() + HttpUtils.PATHS_SEPARATOR;
} else {
path = "/data/local/.Android/" + ctx2.getPackageName() + HttpUtils.PATHS_SEPARATOR;
}
String value2 = readKeyValue(path + MAINSETTING, key, defValue);
return value2;
} catch (Exception ex) {
log(ex.getMessage());
return defValue;
}
}
private static int readKeyValue(Context ctx2, String key, int defValue) {
String value = readKeyValue(ctx2, key, String.valueOf(defValue));
try {
return Integer.parseInt(value);
} catch (Exception e) {
return defValue;
}
}
public static void writeKeyValue(Context ctx2, String key, String value) {
String path;
try {
if (useAppDir) {
SharedPreferences prefs = ctx2.getSharedPreferences(MAINSETTING, 0);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(key, value);
editor.commit();
return;
}
if (Environment.getExternalStorageState().equals("mounted")) {
File sdCardDir = Environment.getExternalStorageDirectory();
path = sdCardDir.getCanonicalPath() + "/.Android/" + ctx2.getPackageName() + HttpUtils.PATHS_SEPARATOR;
} else {
path = "/data/local/.Android/" + ctx2.getPackageName() + HttpUtils.PATHS_SEPARATOR;
}
File file = new File(path);
file.mkdirs();
writeKeyValue(path + MAINSETTING, key, value);
} catch (Exception ex) {
log(ex.getMessage());
}
}
private static Date queryServerTime(final Context ctx2) throws Exception {
if (useNetTime) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
URL url = new URL("http://www.baidu.com");
TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
URLConnection uc = url.openConnection();
uc.connect();
long ld = uc.getDate();
Date unused = LogUtils.time = new Date(ld);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
LogUtils.writeKeyValue(ctx2, "lastTime", sdf.format(LogUtils.time));
} catch (Exception e) {
Date unused2 = LogUtils.time = null;
}
}
});
thread.start();
thread.join();
if (time == null) {
time = queryLocalTime(ctx2);
}
} else {
time = queryLocalTime(ctx2);
}
return time;
}
private static Date queryLocalTime(Context ctx2) throws Exception {
String lastTimeStr = readKeyValue(ctx2, "lastTime", "1900-01-01 00:00:00");
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
Date lastTime = sdf.parse(lastTimeStr);
Date time2 = new Date();
if (time2.before(lastTime)) {
throw new Exception("系统时间有误");
}
writeKeyValue(ctx2, "lastTime", sdf.format(time2));
return time2;
}
public static boolean c(Context ctx2, String pw) {
String str2 = getRegStr(ctx2);
String activateStr = "";
new Date();
Date time2 = null;
if (TextUtils.isEmpty(pw) && trialTime != 0) {
if (0 == 0) {
try {
time2 = queryServerTime(ctx2);
} catch (Exception ex) {
log(ex.getMessage());
passwdStatus = 4;
passwdValidTime = activateStr;
try {
Toast.makeText(ctx2, "获取系统时间错误,可能未联网,请打开网络:" + ex.getMessage(), 0).show();
} catch (Exception e) {
}
return false;
}
}
Calendar c = Calendar.getInstance();
c.setTime(time2);
c.add(13, trialTime);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
activateStr = sdf.format(c.getTime());
pw = hex2numStr(md5(PASSWD_REGCODE + str2 + activateStr).toLowerCase().substring(0, PASSWD_LEN) + activateStr);
}
if (pw.length() > PASSWD_LEN) {
activateStr = pw.substring(PASSWD_LEN);
try {
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss");
Date validTime = sdf2.parse(activateStr);
if (time2 == null) {
time2 = queryServerTime(ctx2);
}
if (time2.after(validTime)) {
passwdStatus = 3;
passwdValidTime = activateStr;
return false;
}
} catch (Exception ex2) {
log(ex2.getMessage());
passwdStatus = 4;
passwdValidTime = activateStr;
try {
Toast.makeText(ctx2, "获取系统时间错误,可能未联网,请打开网络:" + ex2.getMessage(), 0).show();
} catch (Exception e2) {
}
return false;
}
}
String passwd = hex2numStr(md5(PASSWD_REGCODE + str2 + activateStr).toLowerCase().substring(0, PASSWD_LEN) + activateStr);
if (passwd.toLowerCase().equals(pw.toLowerCase())) {
writePasswd(ctx2, passwd);
if (TextUtils.isEmpty(activateStr)) {
passwdStatus = 0;
} else {
passwdStatus = 2;
}
passwdValidTime = activateStr;
try {
SimpleDateFormat sdf3 = new SimpleDateFormat("yyyyMMddHHmmss");
Date validTime2 = sdf3.parse(passwdValidTime);
SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Toast.makeText(ctx2, "使用有效期为:" + sdf4.format(validTime2), 0).show();
} catch (Exception e3) {
}
return true;
}
passwdStatus = 1;
passwdValidTime = activateStr;
return false;
}
private static boolean checkPasswd(String deviceId, String passwd) {
String str2 = md5(PASSWD_REGCODE + deviceId + "").toLowerCase().substring(0, PASSWD_LEN) + "";
String regCode = hex2numStr(passwd);
return passwd.toLowerCase().equals(regCode.toLowerCase());
}
private static String getRegStr(Context ctx2) {
if (useRandDeviceId) {
String ret = readKeyValue(ctx2, "deviceId", "");
if (TextUtils.isEmpty(ret)) {
String ret2 = genRandNumStr(10);
writeKeyValue(ctx2, "deviceId", ret2);
return ret2;
}
return ret;
}
String mac = "";
String imei = "";
String androidId = "";
if (useMac) {
try {
WifiManager wifi = (WifiManager) ctx2.getSystemService(NetWorkUtils.NETWORK_TYPE_WIFI);
WifiInfo info = wifi.getConnectionInfo();
mac = info.getMacAddress();
} catch (Exception e) {
mac = "mac";
}
}
if (useImei) {
try {
TelephonyManager tm = (TelephonyManager) ctx2.getSystemService("phone");
imei = tm.getDeviceId();
} catch (Exception e2) {
imei = "imei";
}
}
if (useAndroidId) {
try {
androidId = Settings.Secure.getString(ctx2.getContentResolver(), "android_id");
} catch (Exception e3) {
androidId = "androidId";
}
}
String ret3 = mac + imei + androidId;
if (ret3 == "") {
ret3 = "gqzb1.0";
}
return md5(ret3).toLowerCase().substring(0, PASSWD_LEN);
}
public static int getResId(Context ctx2, String resName, String resType) {
return ctx2.getResources().getIdentifier(resName, resType, ctx2.getPackageName());
}
public static String getStr(String dataStr) {
return new String(hexStr2Bytes(dataStr));
}
private static View createView(final Activity ctx2, final String deviceId) {
LayoutInflater inflater = (LayoutInflater) ctx2.getSystemService("layout_inflater");
View view = inflater.inflate(getResId(ctx2, "load_dialogview", "layout"), (ViewGroup) null);
tvDeviceId = (TextView) view.findViewById(getResId(ctx2, "load_tv_deviceid", "id"));
etPasswd = (EditText) view.findViewById(getResId(ctx2, "load_et_passwd", "id"));
btnLoadUrl = (Button) view.findViewById(getResId(ctx2, "load_btn_loadurl", "id"));
TextView tvCopyDeviceId = (TextView) view.findViewById(getResId(ctx2, "load_tv_copydeviceid", "id"));
tvCopyDeviceId.setText(getStr(STR_COPYDEVICEID));
tvDeviceId.setText(getStr(STR_DEVICEID) + deviceId);
tvDeviceId.setOnClickListener(new View.OnClickListener() {
@Override
@SuppressLint({"NewApi"})
public void onClick(View arg0) {
ClipboardManager clip = (ClipboardManager) ctx2.getSystemService("clipboard");
clip.setText(deviceId);
Toast.makeText(ctx2, LogUtils.getStr(LogUtils.STR_DEVICEIDCOPY), 0).show();
}
});
if (isLoadUrl) {
btnLoadUrl.setVisibility(0);
} else {
btnLoadUrl.setVisibility(8);
}
btnLoadUrl.setText(getStr(STR_LOADURL));
btnLoadUrl.setOnClickListener(new View.OnClickListener() {
@Override
@SuppressLint({"NewApi"})
public void onClick(View arg0) {
LogUtils.loadUrl(ctx2, LogUtils.loadUrlStr);
}
});
return view;
}
private static void showPasswdDialog(final Activity ctx2, final Handler handler2) {
Date validTime;
String deviceId = getRegStr(ctx2);
View view = createView(ctx2, deviceId);
AlertDialog.Builder builder = new AlertDialog.Builder(ctx2).setCancelable(false).setTitle(title).setView(view).setPositiveButton(getStr(STR_INPUT_REGCODE), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String passwd = LogUtils.etPasswd.getText().toString().trim();
if (passwd != null && !passwd.equals("")) {
if (LogUtils.c(ctx2, passwd)) {
LogUtils.writeKeyValue(ctx2, "passwd", passwd);
LogUtils.writeKeyValue(ctx2, "passwd1", String.valueOf(true));
Toast.makeText(ctx2, LogUtils.getStr(LogUtils.STR_REGCODE_VALID), 0).show();
dialog.dismiss();
if (handler2 == null) {
try {
if (LogUtils.isLoadService) {
Intent serviceIntent = new Intent(ctx2, LoadService.class);
ctx2.startService(serviceIntent);
}
} catch (Exception ex) {
Toast.makeText(ctx2, ex.getMessage(), 0).show();
}
} else {
Message msg = new Message();
msg.what = 1;
handler2.sendMessage(msg);
}
try {
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, true);
return;
} catch (Exception e) {
return;
}
}
Toast.makeText(ctx2, LogUtils.getStr(LogUtils.STR_REGCODE_INVALID), 0).show();
try {
Field field2 = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field2.setAccessible(true);
field2.set(dialog, false);
return;
} catch (Exception e2) {
return;
}
}
Toast.makeText(ctx2, LogUtils.getStr(LogUtils.STR_INPUT_REGCODE), 0).show();
try {
Field field3 = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field3.setAccessible(true);
field3.set(dialog, false);
} catch (Exception e3) {
}
}
}).setNegativeButton(getStr(STR_CANCEL), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
LogUtils.exitApp(ctx2);
}
}).setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
switch (keyCode) {
case 4:
LogUtils.exitApp(ctx2);
return true;
default:
return false;
}
}
});
if (!TextUtils.isEmpty(passwdValidTime)) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
new Date();
try {
validTime = sdf.parse(passwdValidTime);
} catch (Exception e) {
validTime = new Date();
}
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String msg = String.format("%s%s", getStr(STR_VALIDTIME), sdf2.format(validTime));
etPasswd.setHint(msg);
}
if (passwdStatus == 2) {
builder.setNeutralButton(getStr(STR_CONTINUE), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int arg1) {
dialog.dismiss();
if (handler2 == null) {
try {
if (LogUtils.isLoadService) {
Intent serviceIntent = new Intent(ctx2, LoadService.class);
ctx2.startService(serviceIntent);
}
} catch (Exception ex) {
Toast.makeText(ctx2, ex.getMessage(), 0).show();
}
} else {
Message msg2 = new Message();
msg2.what = 1;
handler2.sendMessage(msg2);
}
try {
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, true);
} catch (Exception e2) {
}
}
});
}
builder.show();
}
private static boolean isServiceRunning(Context mContext, String className) {
boolean isRunning = false;
ActivityManager activityManager = (ActivityManager) mContext.getSystemService("activity");
List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(30);
if (serviceList.size() <= 0) {
return false;
}
int i = 0;
while (true) {
if (i >= serviceList.size()) {
break;
} else if (!serviceList.get(i).service.getClassName().equals(className)) {
i++;
} else {
isRunning = true;
break;
}
}
return isRunning;
}
public static void printCallStack() {
Exception e = new Exception("================callstack===============");
Writer writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
e.printStackTrace(printWriter);
String s = writer.toString();
Log.d(TAG, s);
}
public static void printString(String s) {
int length = 0;
if (s != null) {
length = s.length();
}
Log.d(TAG, "string[" + length + "]=" + s);
}
public static int string2Int(String dataStr) {
if (TextUtils.isEmpty(dataStr)) {
return 0;
}
try {
return Integer.parseInt(dataStr);
} catch (Exception ex) {
Log.d(TAG, ex.getMessage());
return 0;
}
}
public static String getKeyValueStr(Context ctx2, String key) {
try {
ApplicationInfo appInfo = ctx2.getPackageManager().getApplicationInfo(ctx2.getPackageName(), j.h);
return appInfo.metaData.getString(key);
} catch (Exception ex) {
Log.d(TAG, ex.getMessage());
return "";
}
}
public static String getKeyValue(Context ctx2, String key) {
try {
ApplicationInfo appInfo = ctx2.getPackageManager().getApplicationInfo(ctx2.getPackageName(), j.h);
return String.valueOf(appInfo.metaData.getInt(key));
} catch (Exception ex) {
Log.d(TAG, ex.getMessage());
return "";
}
}
public static Boolean getKeyValueBoolean(Context ctx2, String key) {
try {
ApplicationInfo appInfo = ctx2.getPackageManager().getApplicationInfo(ctx2.getPackageName(), j.h);
return Boolean.valueOf(appInfo.metaData.getBoolean(key));
} catch (Exception ex) {
Log.d(TAG, ex.getMessage());
return false;
}
}
public static void showChannelImgByTime(Activity ctx2, View view) {
showImageByTime(ctx2, channelTimer, 0, "iv_channel_ad", view);
}
public static void showLiveImgByTime(Activity ctx2) {
showFloatView(ctx2);
showImageByTime(ctx2, channelTimer, 1, "iv_live_ad", floatView);
}
public static void showImageByTime(final Activity ctx2, Timer timer, final int type, String id, final View view) {
if (timer != null) {
timer.cancel();
}
new Timer(true).schedule(new TimerTask() {
int index = 0;
int lastIndex = -1;
ImgInfo imgInfo = null;
long showImgTime = 0;
long noImgTime = 0;
final int STATUS_NOIMG = 0;
final int STATUS_SHOWIMG = 1;
int status = 1;
@Override
public void run() {
List<ImgInfo> list = null;
try {
if (type == 0) {
list = LogUtils.channelImgList;
} else if (type == 1) {
list = LogUtils.liveImgList;
}
if (list != null && list.size() != 0) {
if (this.index != this.lastIndex) {
this.imgInfo = list.get(this.index);
this.lastIndex = this.index;
}
if (this.imgInfo != null) {
if (this.imgInfo.type != 0 || LogUtils.isDownChannelImg) {
if (this.imgInfo.type != 1 || LogUtils.isDownLiveImg) {
if (this.status == 1) {
if (this.showImgTime == 0) {
Boolean isTest = LogUtils.getKeyValueBoolean(ctx2, "isTest");
if (this.imgInfo.isNeedShow.equals("1") || isTest.booleanValue()) {
LogWriter.log("showImg " + this.imgInfo.url);
this.imgInfo.ctx = ctx2;
this.imgInfo.view = view;
Message msg = new Message();
msg.obj = this.imgInfo;
msg.what = LogUtils.MSG_SHOWIMG;
LogUtils.handler.sendMessage(msg);
} else {
this.showImgTime = 0L;
this.noImgTime = 0L;
this.status = 0;
}
}
this.showImgTime += LogUtils.loadTime / IjkMediaCodecInfo.RANK_MAX;
if (this.showImgTime >= this.imgInfo.getShowTime()) {
this.showImgTime = 0L;
this.noImgTime = 0L;
this.status = 0;
}
} else if (this.status == 0) {
if (this.showImgTime == 0) {
LogWriter.log("noImg " + this.imgInfo.url);
this.imgInfo.ctx = ctx2;
this.imgInfo.view = view;
Message msg2 = new Message();
msg2.obj = this.imgInfo;
msg2.what = LogUtils.MSG_NOIMG;
LogUtils.handler.sendMessage(msg2);
}
this.noImgTime += LogUtils.loadTime / IjkMediaCodecInfo.RANK_MAX;
if (this.noImgTime >= this.imgInfo.getInterval()) {
this.index = (this.index + 1) % list.size();
this.showImgTime = 0L;
this.noImgTime = 0L;
this.status = 1;
}
}
}
}
}
}
} catch (Exception ex) {
LogWriter.log(ex.getMessage());
}
}
}, 0L, loadTime);
}
public static void showGif(Activity ctx2, String id, String fileName) {
GifImageView gifImageView = (GifImageView) ctx2.findViewById(getResId(ctx2, id, "id"));
try {
if (TextUtils.isEmpty(fileName)) {
File sdCardDir = Environment.getExternalStorageDirectory();
fileName = sdCardDir.getCanonicalPath() + "/tmp/1.gif";
}
GifDrawable gifDrawable = new GifDrawable(fileName);
gifImageView.setImageDrawable(gifDrawable);
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, e.getMessage());
}
}
public static List<ImgInfo> parseImgList(String rspStr, String key, int type) throws Exception {
JSONArray jArray = JSONUtils.getJSONArray(rspStr, key, (JSONArray) null);
if (jArray == null) {
throw new Exception("无图片");
}
List<ImgInfo> list = new ArrayList<>();
for (int i = 0; i < jArray.length(); i++) {
ImgInfo img = new ImgInfo();
img.id = i;
img.isNeedShow = JSONUtils.getString((JSONObject) jArray.get(i), "isNeedShow", "0");
img.showTime = JSONUtils.getString((JSONObject) jArray.get(i), "showTime", "0");
img.interval = JSONUtils.getString((JSONObject) jArray.get(i), x.ap, "0");
img.url = JSONUtils.getString((JSONObject) jArray.get(i), "url", "0");
img.type = type;
list.add(img);
}
return list;
}
public static void downImageList(Activity ctx2) {
try {
getImgList(ctx2);
} catch (Exception ex) {
Log.d(TAG, ex.getMessage());
}
}
public static String getImgId(ImgInfo imgInfo) {
return imgInfo.type == 0 ? "iv_channel_ad" : "iv_live_ad";
}
public static String getImgFileName(Activity ctx2, ImgInfo imgInfo) {
String fileName = hash_md5(imgInfo.url).toUpperCase();
return getCacheDir(ctx2) + fileName;
}
public static boolean isImgExisted(Activity ctx2, ImgInfo imgInfo) {
String fileName = getImgFileName(ctx2, imgInfo);
return FileUtils.isFileExist(fileName);
}
public static void saveImg(Activity ctx2, ImgInfo imgInfo, RspInfo rspInfo) {
ByteArrayInputStream bis = new ByteArrayInputStream(rspInfo.rspBytes);
String fileName = getImgFileName(ctx2, imgInfo);
FileUtils.writeFile(fileName, bis);
LogWriter.log("saveImg");
}
public static void showImg(Activity ctx2, ImgInfo imgInfo, String id) {
GifImageView gifImageView;
try {
if (imgInfo.view != null) {
gifImageView = (GifImageView) imgInfo.view.findViewById(getResId(imgInfo.view.getContext(), id, "id"));
} else {
gifImageView = (GifImageView) ctx2.findViewById(getResId(ctx2, id, "id"));
}
gifImageView.setVisibility(0);
if (isImgExisted(ctx2, imgInfo)) {
String fileName = hash_md5(imgInfo.url).toUpperCase();
GifDrawable gifDrawable = new GifDrawable(getCacheDir(ctx2) + fileName);
gifImageView.setImageDrawable(gifDrawable);
LogWriter.log("showImg");
return;
}
throw new Exception("no img");
} catch (Exception ex) {
LogWriter.log(ex.getMessage());
}
}
public static void downImgeList(Activity ctx2, List<ImgInfo> imgList) throws Exception {
for (int i = 0; i < imgList.size(); i++) {
downImage(ctx2, imgList.get(i));
}
}
public static void downImage(Activity ctx2, ImgInfo imgInfo) throws Exception {
try {
String url = imgInfo.url;
String fileDir = getCacheDir(ctx2);
String fileName = hash_md5(imgInfo.url).toUpperCase();
OkHttpUtils.get().url(url).build().execute(new FileCallBack(fileDir, fileName) {
@Override
public void inProgress(float v, long l) {
}
@Override
public void onResponse(File file) {
}
@Override
public void onError(Call call, Exception e) {
}
});
} catch (Exception ex) {
LogWriter.log(ex.getMessage());
throw ex;
}
}
public static String getCacheDir(Context ctx2) {
if (Environment.getExternalStorageState().equals("mounted")) {
File sdCardDir = Environment.getExternalStorageDirectory();
String path = sdCardDir.getAbsolutePath() + "/.Android/" + ctx2.getPackageName() + HttpUtils.PATHS_SEPARATOR;
return path;
}
String path2 = "/data/local/.Android/" + ctx2.getPackageName() + HttpUtils.PATHS_SEPARATOR;
return path2;
}
public static void getImgList(final Activity ctx2) {
try {
isDownChannelImg = false;
isDownLiveImg = false;
String url = getKeyValueStr(ctx2, "imglist");
OkHttpUtils.get().url(url).build().execute(new HttpCallback() {
@Override
public void onResponse(RspInfo rspInfo) {
try {
String rspStr = rspInfo.rspStr;
LogUtils.channelImgList = LogUtils.parseImgList(rspStr, "show_channel_Img", 0);
LogUtils.liveImgList = LogUtils.parseImgList(rspStr, "show_live_Img", 1);
LogWriter.log("getImgList success");
LogUtils.downImgeList(ctx2, LogUtils.channelImgList);
LogUtils.downImgeList(ctx2, LogUtils.liveImgList);
LogUtils.isDownChannelImg = true;
LogUtils.isDownLiveImg = true;
} catch (Exception ex) {
Log.d(LogUtils.TAG, ex.getMessage());
Toast.makeText(ctx2, "获取图片列表错误:" + ex.getMessage(), 0).show();
}
}
@Override
public void onError(Call arg0, Exception ex) {
Log.d(LogUtils.TAG, ex.getMessage());
Toast.makeText(ctx2, "获取图片列表错误:" + ex.getMessage(), 0).show();
}
});
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, e.getMessage());
}
}
public static void showFloatView(Context context) {
try {
LogWriter.log("showFloatView start");
removeFloatView();
floatView = new MyFloatView(context.getApplicationContext(), wmParams);
wm = (WindowManager) context.getSystemService("window");
wmParams.type = 2;
wmParams.format = 1;
wmParams.flags = 56;
wmParams.gravity = 51;
DisplayMetrics dm = context.getResources().getDisplayMetrics();
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
wmParams.width = screenWidth / 2;
wmParams.height = screenHeight / 2;
wmParams.x = screenWidth - wmParams.width;
wmParams.y = (screenHeight - wmParams.height) - 50;
wm.addView(floatView, wmParams);
LogWriter.log("showFloatView show");
} catch (Exception ex) {
LogWriter.log("showFloatView()" + ex.getMessage());
}
}
public static void removeFloatView() {
LogWriter.log("removeFloatView()");
try {
if (floatView != null) {
wm.removeView(floatView);
floatView = null;
}
} catch (Exception e) {
}
}
public static void setFloatViewVisible(boolean visible) {
if (floatView != null) {
floatView.setVisibility(visible ? 0 : 4);
}
}
public static String queryJsonObject(JSONObject jobj, String key) throws Exception {
String[] strs = key.split("\\.");
if (strs == null) {
return null;
}
Iterator it = jobj.keys();
while (it.hasNext()) {
String keyStr = it.next();
Object value = jobj.get(keyStr);
if (keyStr.equals(strs[0])) {
String key1 = "";
for (int i = 1; i < strs.length; i++) {
key1 = key1 + strs[i];
if (i < strs.length - 1) {
key1 = key1 + FileUtils.FILE_EXTENSION_SEPARATOR;
}
}
if (key1 != "") {
return queryJsonObject((JSONObject) value, key1);
}
return value.toString();
}
}
return null;
}
public static String getJsonKeyValue(String responseStr, String key) throws Exception {
if (responseStr == null || responseStr.trim().equals("")) {
return "";
}
JSONObject jb = new JSONObject(responseStr);
return queryJsonObject(jb, key);
}
public static String readAssetsFile(Context ctx2, String fileName) throws Exception {
BufferedReader br = null;
try {
try {
BufferedReader br2 = new BufferedReader(new InputStreamReader(ctx2.getAssets().open(fileName)));
String retStr = "";
while (true) {
try {
String line = br2.readLine();
if (line == null) {
break;
}
retStr = retStr + line;
} catch (Exception ex) {
throw ex;
} catch (Throwable th) {
th = th;
br = br2;
if (br != null) {
try {
br.close();
} catch (Exception e) {
}
}
throw th;
}
}
if (br2 != null) {
try {
br2.close();
} catch (Exception e2) {
}
}
return retStr;
} catch (Throwable th2) {
th = th2;
}
} catch (Exception ex2) {
throw ex2;
}
}
public static void copyAssetsFile(Context ctx2, String srcFile, String dstFile) throws Exception {
FileOutputStream fos;
InputStream in = null;
FileOutputStream fos2 = null;
try {
try {
in = ctx2.getAssets().open(srcFile);
fos = new FileOutputStream(dstFile);
} catch (Exception ex) {
throw ex;
}
} catch (Throwable th) {
th = th;
}
try {
byte[] buffer = new byte[10240];
while (true) {
int len = in.read(buffer);
if (len == -1) {
break;
}
fos.write(buffer, 0, len);
}
fos.flush();
if (in != null) {
in.close();
}
if (fos != null) {
fos.close();
}
} catch (Exception ex2) {
fos2 = fos;
throw ex2;
} catch (Throwable th2) {
th = th2;
fos2 = fos;
if (in != null) {
in.close();
}
if (fos2 != null) {
fos2.close();
}
throw th;
}
}
public static BufferedReader readChannelUrl(Context ctx2) {
try {
String filename = ctx2.getFilesDir() + HttpUtils.PATHS_SEPARATOR + "player_menu_contrl_small.xml";
if (!new File(filename).exists()) {
copyAssetsFile(ctx2, "player_menu_contrl_small.xml", filename);
}
return new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
} catch (Exception ex) {
log(ex.getMessage());
return null;
}
}
public static void test() {
try {
str = "";
} catch (Exception ex) {
Log.e(TAG, ex.getMessage());
}
}
}