194 lines
7.1 KiB
Java
194 lines
7.1 KiB
Java
package com.ubt.jimu.blockly;
|
|
|
|
import android.util.Log;
|
|
import android.webkit.WebView;
|
|
import com.ubt.jimu.JimuApplication;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.cache.Constants;
|
|
import com.ubt.jimu.unity.ModelType;
|
|
import com.ubt.jimu.utils.ExternalOverFroyoUtils;
|
|
import com.ubt.jimu.utils.PackageHelper;
|
|
import com.ubtech.utils.FileHelper;
|
|
import com.ubtech.utils.StringUtils;
|
|
import com.ubtech.utils.XLog;
|
|
import com.ubtrobot.log.ALog;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Random;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class Utils {
|
|
public static final String BLOCKLY = "Blockly";
|
|
public static final String BLOCKLY_ADD_PATH = "_new";
|
|
public static final String Blockly_Root = "blockly";
|
|
private static final String TAG = "Utils";
|
|
private static Random sRandom = new Random();
|
|
public static final String BLOCKLY_NEW = "TeachMaterialBlockly";
|
|
public static String baseUrl = ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + "data/blockly/" + BLOCKLY_NEW + File.separator;
|
|
|
|
public interface IUnzipBlockly {
|
|
void unZipFailed();
|
|
|
|
void unZipSuccessed();
|
|
}
|
|
|
|
public static long formatFileCreateTime(String str) {
|
|
if (str == null || !StringUtils.f(str)) {
|
|
return 0L;
|
|
}
|
|
if (str.length() < 18) {
|
|
return Long.parseLong(str);
|
|
}
|
|
try {
|
|
return new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS").parse(String.format("20%s/%s/%s %s:%s:%s.%s", str.substring(0, 2), str.substring(2, 4), str.substring(4, 6), str.substring(6, 8), str.substring(8, 10), str.substring(10, 12), str.substring(12, 15))).getTime();
|
|
} catch (ParseException e) {
|
|
e.printStackTrace();
|
|
return 0L;
|
|
}
|
|
}
|
|
|
|
public static String getBlocklyHelpUrl() {
|
|
String str = "https://jimu.ubtrobot.com/jimu/help_new/help_new.html?language=" + JimuApplication.l().g();
|
|
return "https://video.ubtrobot.com/jimu/help_303/help_new.html?language=" + JimuApplication.l().g();
|
|
}
|
|
|
|
public static String getDefaultName(int[] iArr, int i, String str) {
|
|
String str2;
|
|
if (i == 0) {
|
|
return str + "1";
|
|
}
|
|
boolean z = false;
|
|
for (int i2 = 0; i2 < i - 1; i2++) {
|
|
int i3 = 0;
|
|
while (i3 < (i - i2) - 1) {
|
|
int i4 = i3 + 1;
|
|
if (iArr[i3] > iArr[i4]) {
|
|
int i5 = iArr[i3];
|
|
iArr[i3] = iArr[i4];
|
|
iArr[i4] = i5;
|
|
}
|
|
i3 = i4;
|
|
}
|
|
}
|
|
int i6 = 0;
|
|
while (true) {
|
|
if (i6 >= i) {
|
|
str2 = null;
|
|
break;
|
|
}
|
|
int i7 = iArr[i6];
|
|
i6++;
|
|
if (i7 != i6) {
|
|
str2 = str + i6;
|
|
z = true;
|
|
break;
|
|
}
|
|
}
|
|
if (z) {
|
|
return str2;
|
|
}
|
|
return str + (i + 1);
|
|
}
|
|
|
|
public static String getFormatId(long j) {
|
|
String format = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date(j));
|
|
String substring = format.substring(format.length() - 15, format.length());
|
|
String str = substring + sRandom.nextInt(10) + sRandom.nextInt(10) + sRandom.nextInt(10);
|
|
System.out.println(format);
|
|
System.out.println(substring);
|
|
System.out.println(str);
|
|
return str;
|
|
}
|
|
|
|
public static String getStarCourseDirPath() {
|
|
String str = ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + "data" + File.separator + "blockly" + File.separator + "storyCourse";
|
|
File file = new File(str);
|
|
if (!file.isDirectory()) {
|
|
file.mkdirs();
|
|
}
|
|
return str;
|
|
}
|
|
|
|
public static void setJSResult(final WebView webView, String str, String... strArr) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("javascript:");
|
|
sb.append(str);
|
|
sb.append("(");
|
|
if (strArr != null && strArr.length > 0) {
|
|
for (int i = 0; i < strArr.length; i++) {
|
|
sb.append("'");
|
|
sb.append(strArr[i]);
|
|
sb.append("'");
|
|
if (i < strArr.length - 1) {
|
|
sb.append(",");
|
|
}
|
|
}
|
|
}
|
|
sb.append(")");
|
|
final String sb2 = sb.toString();
|
|
webView.post(new Runnable() { // from class: com.ubt.jimu.blockly.Utils.2
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
webView.loadUrl(sb2);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Deprecated
|
|
public static void unZipBlockly(IUnzipBlockly iUnzipBlockly) {
|
|
unZipBlockly(BLOCKLY_NEW, iUnzipBlockly);
|
|
}
|
|
|
|
private static void unzip(final String str, final String str2, final IUnzipBlockly iUnzipBlockly) {
|
|
new Thread() { // from class: com.ubt.jimu.blockly.Utils.1
|
|
@Override // java.lang.Thread, java.lang.Runnable
|
|
public void run() {
|
|
String str3 = str2 + ".zip";
|
|
String str4 = ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + "data/blockly/";
|
|
try {
|
|
FileHelper.a(new File(str4 + str2 + File.separator));
|
|
FileHelper.a(JimuApplication.l(), str3, str4, true);
|
|
Cache.getInstance().getSettings().put(Constants.BLOCKLY_VERSION, str);
|
|
if (iUnzipBlockly != null) {
|
|
iUnzipBlockly.unZipSuccessed();
|
|
}
|
|
XLog.c(Utils.TAG, "Unzip blockly success!");
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
Log.e("ActivityModelHome", "unAssertsZip Error:" + e.getMessage());
|
|
IUnzipBlockly iUnzipBlockly2 = iUnzipBlockly;
|
|
if (iUnzipBlockly2 != null) {
|
|
iUnzipBlockly2.unZipFailed();
|
|
}
|
|
}
|
|
}
|
|
}.start();
|
|
}
|
|
|
|
public static void unZipBlockly(String str, IUnzipBlockly iUnzipBlockly) {
|
|
String str2 = ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + "data/blockly/" + str + File.separator;
|
|
File file = new File(str2);
|
|
try {
|
|
String string = Cache.getInstance().getSettings().getString(Constants.BLOCKLY_VERSION, BuildConfig.VERSION_NAME);
|
|
String a = PackageHelper.a();
|
|
XLog.c(TAG, "blockly oldversion: %s, currentVersion: %s", string, a);
|
|
if (!string.equals(a)) {
|
|
unzip(a, str, iUnzipBlockly);
|
|
} else if (!file.exists() || file.list() == null || file.list().length < 2) {
|
|
unzip(a, str, iUnzipBlockly);
|
|
} else {
|
|
ALog.a("ActivityModelHome").d(str + "已经解压到" + str2);
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
Log.e("ActivityModelHome", e.getMessage());
|
|
if (iUnzipBlockly != null) {
|
|
iUnzipBlockly.unZipFailed();
|
|
}
|
|
}
|
|
}
|
|
}
|