新增 连接电脑支持运行和保存项目
This commit is contained in:
@@ -69,6 +69,19 @@ public class GlobalAppContext {
|
||||
});
|
||||
}
|
||||
|
||||
public static void toast(final int resId, final Object... args) {
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
Toast.makeText(get(), getString(resId, args), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
sHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(get(), getString(resId, args), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void post(Runnable r) {
|
||||
sHandler.post(r);
|
||||
}
|
||||
|
||||
49
common/src/main/java/com/stardust/io/Zip.java
Normal file
49
common/src/main/java/com/stardust/io/Zip.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.stardust.io;
|
||||
|
||||
import com.stardust.pio.PFile;
|
||||
import com.stardust.pio.PFiles;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import static com.stardust.pio.PFiles.closeSilently;
|
||||
|
||||
public class Zip {
|
||||
|
||||
public static void unzip(InputStream stream, File dir) throws IOException {
|
||||
FileOutputStream fos = null;
|
||||
ZipInputStream zis = null;
|
||||
try {
|
||||
zis = new ZipInputStream(stream);
|
||||
ZipEntry entry;
|
||||
while ((entry = zis.getNextEntry()) != null) {
|
||||
File file = new File(dir, entry.getName());
|
||||
if (entry.isDirectory()) {
|
||||
file.mkdirs();
|
||||
} else {
|
||||
PFiles.ensureDir(file.getPath());
|
||||
fos = new FileOutputStream(file);
|
||||
PFiles.write(zis, fos, false);
|
||||
fos.close();
|
||||
fos = null;
|
||||
zis.closeEntry();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
closeSilently(fos);
|
||||
closeSilently(stream);
|
||||
closeSilently(zis);
|
||||
}
|
||||
}
|
||||
|
||||
public static void unzip(File zipFile, File dir) throws IOException {
|
||||
unzip(new FileInputStream(zipFile), dir);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import android.util.Log;
|
||||
|
||||
import com.stardust.util.Func1;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -174,20 +175,28 @@ public class PFiles {
|
||||
}
|
||||
}
|
||||
|
||||
public static void write(InputStream is, OutputStream os) {
|
||||
public static void write(InputStream is, OutputStream os, boolean close) {
|
||||
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
|
||||
try {
|
||||
while (is.available() > 0) {
|
||||
int n = is.read(buffer);
|
||||
os.write(buffer, 0, n);
|
||||
if (n > 0) {
|
||||
os.write(buffer, 0, n);
|
||||
}
|
||||
}
|
||||
if (close) {
|
||||
is.close();
|
||||
os.close();
|
||||
}
|
||||
is.close();
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void write(InputStream is, OutputStream os) {
|
||||
write(is, os, true);
|
||||
}
|
||||
|
||||
|
||||
public static void write(String path, String text) {
|
||||
write(new File(path), text);
|
||||
@@ -296,7 +305,7 @@ public class PFiles {
|
||||
if (list == null)
|
||||
throw new IOException("not a directory: " + assetsDir);
|
||||
for (String file : list) {
|
||||
if(TextUtils.isEmpty(file)){
|
||||
if (TextUtils.isEmpty(file)) {
|
||||
continue;
|
||||
}
|
||||
String fullAssetsPath = join(assetsDir, file);
|
||||
@@ -500,4 +509,15 @@ public class PFiles {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeSilently(Closeable closeable) {
|
||||
if (closeable == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (IOException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,17 @@ import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class MD5 {
|
||||
|
||||
public static byte[] md5Bytes(String message) throws NoSuchAlgorithmException {
|
||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||
md5.update(message.getBytes());
|
||||
return md5.digest();
|
||||
public static byte[] md5Bytes(String message) {
|
||||
try {
|
||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||
md5.update(message.getBytes());
|
||||
return md5.digest();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String md5(String message) throws NoSuchAlgorithmException {
|
||||
public static String md5(String message) {
|
||||
byte[] bytes = md5Bytes(message);
|
||||
StringBuilder hexString = new StringBuilder(32);
|
||||
for (byte b : bytes) {
|
||||
@@ -22,5 +26,7 @@ public class MD5 {
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user