提交 8880b13c 编写于 作者: B Blankj

see 04/26 log

上级 17dd4d80
* `19/04/25` [fix] LogUtils delete due log.
* `19/04/24` [upd] The swipe panel.
* `19/03/17` [fix] The ugly UI.
* `19/03/14` [fix] AdaptScreenUtils didn't work on some HaWei tablet.
......
......@@ -281,8 +281,8 @@ shutdown : 关机
reboot : 重启
reboot2Recovery : 重启到 recovery
reboot2Bootloader: 重启到 bootloader
isTablet : 判断是否是平板
isEmulator : 判断是否是模拟器
isTablet : 判断是否是平板
isEmulator : 判断是否是模拟器
```
* ### 闪光灯相关 -> [FlashlightUtils.java][flashlight.java] -> [Demo][flashlight.demo]
......@@ -543,7 +543,7 @@ isWifiConnected : 判断 wifi 是否连接状态
isWifiAvailable[Async] : 判断 wifi 数据是否可用
getNetworkOperatorName : 获取移动网络运营商名称
getNetworkType : 获取当前网络类型
getIPAddress : 获取 IP 地址
getIPAddress[Async] : 获取 IP 地址
getDomainAddress[Async] : 获取域名 IP 地址
getIpAddressByWifi : 根据 WiFi 获取网络 IP 地址
getGatewayByWifi : 根据 WiFi 获取网关 IP 地址
......
......@@ -281,6 +281,8 @@ shutdown
reboot
reboot2Recovery
reboot2Bootloader
isTablet
isEmulator
```
* ### About Flashlight -> [FlashlightUtils.java][flashlight.java] -> [Demo][flashlight.demo]
......@@ -541,7 +543,7 @@ isWifiConnected
isWifiAvailable[Async] : 判断 wifi 数据是否可用
getNetworkOperatorName
getNetworkType
getIPAddress
getIPAddress[Async] : 获取 IP 地址
getDomainAddress[Async] : 获取域名 IP 地址
getIpAddressByWifi
getGatewayByWifi
......@@ -712,6 +714,8 @@ getRomInfo
```
getScreenWidth
getScreenHeight
getAppScreenWidth
getAppScreenHeight
getScreenDensity
getScreenDensityDpi
setFullScreen
......@@ -727,7 +731,6 @@ screenShot
isScreenLock
setSleepDuration
getSleepDuration
isTablet
```
* ### About SDCard -> [SDCardUtils.java][sdcard.java] -> [Demo][sdcard.demo]
......
......@@ -17,7 +17,7 @@ public final class AdaptScreenUtils {
* Adapt for the horizontal screen, and call it in [android.app.Activity.getResources].
*/
public static Resources adaptWidth(final Resources resources, final int designWidth) {
float newXdpi = (Resources.getSystem().getDisplayMetrics().widthPixels * 72f) / designWidth;
float newXdpi = (resources.getDisplayMetrics().widthPixels * 72f) / designWidth;
applyDisplayMetrics(resources, newXdpi);
return resources;
}
......@@ -26,11 +26,29 @@ public final class AdaptScreenUtils {
* Adapt for the vertical screen, and call it in [android.app.Activity.getResources].
*/
public static Resources adaptHeight(final Resources resources, final int designHeight) {
float newXdpi = (Resources.getSystem().getDisplayMetrics().heightPixels * 72f) / designHeight;
return adaptHeight(resources, designHeight, false);
}
/**
* Adapt for the vertical screen, and call it in [android.app.Activity.getResources].
*/
public static Resources adaptHeight(final Resources resources, final int designHeight, final boolean includeNavBar) {
float screenHeight = resources.getDisplayMetrics().heightPixels * 72f
+ (includeNavBar ? getNavBarHeight(resources) : 0);
float newXdpi = screenHeight / designHeight;
applyDisplayMetrics(resources, newXdpi);
return resources;
}
private static int getNavBarHeight(final Resources resources) {
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId != 0) {
return resources.getDimensionPixelSize(resourceId);
} else {
return 0;
}
}
/**
* @param resources The resources.
* @return the resource
......
......@@ -31,7 +31,7 @@ import java.util.List;
*/
public final class FileIOUtils {
private static int sBufferSize = 8192;
private static int sBufferSize = 524288;
private FileIOUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
......
......@@ -46,6 +46,8 @@ import java.util.Locale;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
......@@ -526,19 +528,19 @@ public final class LogUtils {
File[] files = parentFile.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.matches("^" + CONFIG.getFilePrefix() + "-[0-9]{4}-[0-9]{2}-[0-9]{2}-" + CONFIG.getProcessName() + ".txt$");
return name.matches("^" + CONFIG.getFilePrefix() + "-[0-9]{4}-[0-9]{2}-[0-9]{2}-.*\\.txt$");
}
});
if (files == null || files.length <= 0) return;
final int length = filePath.length();
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
try {
String curDay = filePath.substring(length - 14, length - 4);
String curDay = findDate(filePath);
long dueMillis = sdf.parse(curDay).getTime() - CONFIG.getSaveDays() * 86400000L;
for (final File aFile : files) {
String name = aFile.getName();
int l = name.length();
String logDay = name.substring(l - 14, l - 4);
String logDay = findDate(name);
if (sdf.parse(logDay).getTime() <= dueMillis) {
EXECUTOR.execute(new Runnable() {
@Override
......@@ -556,6 +558,15 @@ public final class LogUtils {
}
}
private static String findDate(String str) {
Pattern pattern = Pattern.compile("[0-9]{4}-[0-9]{2}-[0-9]{2}");
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
return matcher.group();
}
return "";
}
private static void printDeviceInfo(final String filePath) {
String versionName = "";
int versionCode = 0;
......@@ -817,7 +828,7 @@ public final class LogUtils {
BufferedReader mBufferedReader = new BufferedReader(new FileReader(file));
String processName = mBufferedReader.readLine().trim();
mBufferedReader.close();
return processName;
return processName.replace(":", "_");
} catch (Exception e) {
e.printStackTrace();
return "";
......
......@@ -82,6 +82,7 @@ public final class NetworkUtils {
* <p>Must hold {@code <uses-permission android:name="android.permission.INTERNET" />}</p>
*
* @param callback The callback.
* @return the task
*/
@RequiresPermission(INTERNET)
public static Utils.Task<Boolean> isAvailableAsync(@NonNull final Utils.Callback<Boolean> callback) {
......@@ -123,6 +124,7 @@ public final class NetworkUtils {
*
* @param ip The ip address.
* @param callback The callback.
* @return the task
*/
@RequiresPermission(INTERNET)
public static Utils.Task<Boolean> isAvailableByPingAsync(final String ip,
......@@ -186,6 +188,7 @@ public final class NetworkUtils {
*
* @param domain The name of domain.
* @param callback The callback.
* @return the task
*/
@RequiresPermission(INTERNET)
public static Utils.Task isAvailableByDnsAsync(final String domain,
......@@ -373,6 +376,9 @@ public final class NetworkUtils {
* Return whether wifi is available.
* <p>Must hold {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />},
* {@code <uses-permission android:name="android.permission.INTERNET" />}</p>
*
* @param callback The callback.
* @return the task
*/
@RequiresPermission(allOf = {ACCESS_WIFI_STATE, INTERNET})
public static Utils.Task<Boolean> isWifiAvailableAsync(@NonNull final Utils.Callback<Boolean> callback) {
......@@ -487,6 +493,25 @@ public final class NetworkUtils {
return cm.getActiveNetworkInfo();
}
/**
* Return the ip address.
* <p>Must hold {@code <uses-permission android:name="android.permission.INTERNET" />}</p>
*
* @param useIPv4 True to use ipv4, false otherwise.
* @param callback The callback.
* @return the task
*/
public static Utils.Task<String> getIPAddressAsync(final boolean useIPv4,
@NonNull final Utils.Callback<String> callback) {
return Utils.doAsync(new Utils.Task<String>(callback) {
@RequiresPermission(INTERNET)
@Override
public String doInBackground() {
return getIPAddress(useIPv4);
}
});
}
/**
* Return the ip address.
* <p>Must hold {@code <uses-permission android:name="android.permission.INTERNET" />}</p>
......@@ -563,6 +588,7 @@ public final class NetworkUtils {
*
* @param domain The name of domain.
* @param callback The callback.
* @return the task
*/
@RequiresPermission(INTERNET)
public static Utils.Task<String> getDomainAddressAsync(final String domain,
......
......@@ -31,6 +31,16 @@ public final class ResourceUtils {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* Return the drawable identifier by name.
*
* @param name The name of drawable.
* @return the drawable identifier by name
*/
public static int getDrawableIdByName(String name) {
return Utils.getApp().getResources().getIdentifier(name, "drawable", Utils.getApp().getPackageName());
}
/**
* Copy the file from assets.
*
......
......@@ -31,7 +31,9 @@ public final class ShellUtils {
* @param isRooted True to use root, false otherwise.
* @param callback The callback.
*/
public static void execCmdAsync(final String command, final boolean isRooted, final Utils.Callback<CommandResult> callback) {
public static void execCmdAsync(final String command,
final boolean isRooted,
final Utils.Callback<CommandResult> callback) {
execCmdAsync(new String[]{command}, isRooted, true, callback);
}
......@@ -42,7 +44,9 @@ public final class ShellUtils {
* @param isRooted True to use root, false otherwise.
* @param callback The callback.
*/
public static void execCmdAsync(final List<String> commands, final boolean isRooted, final Utils.Callback<CommandResult> callback) {
public static void execCmdAsync(final List<String> commands,
final boolean isRooted,
final Utils.Callback<CommandResult> callback) {
execCmdAsync(commands == null ? null : commands.toArray(new String[]{}), isRooted, true, callback);
}
......@@ -53,7 +57,9 @@ public final class ShellUtils {
* @param isRooted True to use root, false otherwise.
* @param callback The callback.
*/
public static void execCmdAsync(final String[] commands, final boolean isRooted, final Utils.Callback<CommandResult> callback) {
public static void execCmdAsync(final String[] commands,
final boolean isRooted,
final Utils.Callback<CommandResult> callback) {
execCmdAsync(commands, isRooted, true, callback);
}
......@@ -97,6 +103,7 @@ public final class ShellUtils {
* @param isRooted True to use root, false otherwise.
* @param isNeedResultMsg True to return the message of result, false otherwise.
* @param callback The callback.
* @return the task
*/
public static Utils.Task<CommandResult> execCmdAsync(final String[] commands,
final boolean isRooted,
......
......@@ -4,8 +4,8 @@ import android.os.Handler;
import android.os.Looper;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.util.SparseArray;
import java.util.HashMap;
import java.util.Map;
......@@ -30,8 +30,8 @@ import java.util.concurrent.atomic.AtomicLong;
*/
public final class ThreadUtils {
private static final SparseArray<SparseArray<ExecutorService>> TYPE_PRIORITY_POOLS = new SparseArray<>();
private static final Map<Task, ScheduledExecutorService> TASK_SCHEDULED = new HashMap<>();
private static final HashMap<Integer, Map<Integer, ExecutorService>> TYPE_PRIORITY_POOLS = new HashMap<>();
private static final Map<Task, ScheduledExecutorService> TASK_SCHEDULED = new HashMap<>();
private static final byte TYPE_SINGLE = -1;
private static final byte TYPE_CACHED = -2;
......@@ -912,9 +912,9 @@ public final class ThreadUtils {
private synchronized static ExecutorService getPoolByTypeAndPriority(final int type, final int priority) {
ExecutorService pool;
SparseArray<ExecutorService> priorityPools = TYPE_PRIORITY_POOLS.get(type);
Map<Integer, ExecutorService> priorityPools = TYPE_PRIORITY_POOLS.get(type);
if (priorityPools == null) {
priorityPools = new SparseArray<>();
priorityPools = new HashMap<>();
pool = createPoolByTypeAndPriority(type, priority);
priorityPools.put(priority, pool);
TYPE_PRIORITY_POOLS.put(type, priorityPools);
......@@ -998,9 +998,10 @@ public final class ThreadUtils {
private volatile int state = NEW;
private boolean isSchedule;
@Nullable
public abstract T doInBackground() throws Throwable;
public abstract void onSuccess(T result);
public abstract void onSuccess(@Nullable T result);
public abstract void onCancel();
......@@ -1080,6 +1081,7 @@ public final class ThreadUtils {
this.priority = priority;
}
@Override
public Thread newThread(@NonNull Runnable r) {
Thread t = new Thread(r, namePrefix + getAndIncrement()) {
@Override
......
......@@ -10,7 +10,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog;
import java.util.TreeSet;
import java.util.concurrent.Executor;
/**
* <pre>
......@@ -21,28 +21,22 @@ import java.util.TreeSet;
* </pre>
*/
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, shadows = {ShadowLog.class}, sdk = 19)
@Config(manifest = Config.NONE, shadows = {ShadowLog.class})
public class BaseTest {
public BaseTest() {
ShadowLog.stream = System.out;
ThreadUtils.setDeliver(new Executor() {
@Override
public void execute(@NonNull Runnable command) {
command.run();
}
});
Utils.init(RuntimeEnvironment.application);
}
@Test
public void test() throws Exception {
TreeSet<Person> people = new TreeSet<>();
people.add(new Person("1", 1, 0));
people.add(new Person("3", 3, 0));
people.add(new Person("3", 3, 1));
people.add(new Person("2", 2, 0));
for (Person person : people) {
System.out.println(person);
}
System.out.println(people);
// final Scanner scanner = new Scanner(System.in);
//
// final CountDownLatch countDownLatch = new CountDownLatch(1);
......
......@@ -530,7 +530,6 @@ public class EncryptUtilsTest extends BaseTest {
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
System.out.println(EncodeUtils.base64Decode(publicKey.getBytes()).length);
assertTrue(
Arrays.equals(
EncryptUtils.decryptRSA(
......@@ -538,11 +537,11 @@ public class EncryptUtilsTest extends BaseTest {
dataRSA.getBytes(),
base64Decode(publicKey.getBytes()),
true,
"RSA/ECB/NoPadding"
"RSA/ECB/PKCS1Padding"
),
base64Decode(privateKey.getBytes()),
false,
"RSA/ECB/NoPadding"
"RSA/ECB/PKCS1Padding"
),
dataRSA.getBytes()
)
......
......@@ -133,7 +133,7 @@ class ReleaseInstallApkTask(private val mListener: OnReleasedListener) : ThreadU
ResourceUtils.copyFileFromAssets("test_install", Config.TEST_APK_PATH)
}
override fun onSuccess(result: Unit) {
override fun onSuccess(result: Unit?) {
mListener.onReleased()
}
......
......@@ -80,6 +80,8 @@ class NetworkActivity : BaseTitleActivity() {
updateAboutNetwork()
}
private lateinit var ipV4AddressAsyncTask: Utils.Task<String>
private lateinit var ipV6AddressAsyncTask: Utils.Task<String>
private lateinit var wifiAvailableAsyncTask: Utils.Task<Boolean>
private lateinit var availableAsyncTask: Utils.Task<Boolean>
private lateinit var domainAddressAsyncTask: Utils.Task<String>
......@@ -94,19 +96,39 @@ class NetworkActivity : BaseTitleActivity() {
.appendLine("isWifiConnected: " + NetworkUtils.isWifiConnected())
.appendLine("getNetworkOperatorName: " + NetworkUtils.getNetworkOperatorName())
.appendLine("getNetworkTypeName: " + NetworkUtils.getNetworkType())
.appendLine("getIPv4Address: " + NetworkUtils.getIPAddress(true))
.appendLine("getIPv6Address: " + NetworkUtils.getIPAddress(false))
.appendLine("getBroadcastIpAddress: " + NetworkUtils.getBroadcastIpAddress())
.appendLine("getIpAddressByWifi: " + NetworkUtils.getIpAddressByWifi())
.appendLine("getGatewayByWifi: " + NetworkUtils.getGatewayByWifi())
.appendLine("getNetMaskByWifi: " + NetworkUtils.getNetMaskByWifi())
.append("getServerAddressByWifi: " + NetworkUtils.getServerAddressByWifi())
.create()
cur += 3
cur += 5
ipV4AddressAsyncTask = NetworkUtils.getIPAddressAsync(true) { data ->
val num = count.get()
if (num >= cur - 5) {
spanSb = SpanUtils().appendLine(spanSb)
.append("getIPv4Address: $data")
.create()
networkAboutTv.text = spanSb
}
count.addAndGet(1)
}
ipV6AddressAsyncTask = NetworkUtils.getIPAddressAsync(false) { data ->
val num = count.get()
if (num >= cur - 5) {
spanSb = SpanUtils().appendLine(spanSb)
.append("getIPv6Address: $data")
.create()
networkAboutTv.text = spanSb
}
count.addAndGet(1)
}
wifiAvailableAsyncTask = NetworkUtils.isWifiAvailableAsync { data ->
val num = count.get()
if (num >= cur - 3) {
if (num >= cur - 5) {
spanSb = SpanUtils().appendLine(spanSb)
.append("isWifiAvailable: $data")
.create()
......@@ -117,7 +139,7 @@ class NetworkActivity : BaseTitleActivity() {
availableAsyncTask = NetworkUtils.isAvailableAsync { data ->
val num = count.get()
if (num >= cur - 3) {
if (num >= cur - 5) {
spanSb = SpanUtils().appendLine(spanSb)
.append("isAvailable: $data")
.create()
......@@ -128,7 +150,7 @@ class NetworkActivity : BaseTitleActivity() {
domainAddressAsyncTask = NetworkUtils.getDomainAddressAsync("baidu.com") { data ->
val num = count.get()
if (num >= cur - 3) {
if (num >= cur - 5) {
spanSb = SpanUtils().appendLine(spanSb)
.append("getBaiduDomainAddress: $data")
.create()
......@@ -139,6 +161,8 @@ class NetworkActivity : BaseTitleActivity() {
}
override fun onDestroy() {
ipV4AddressAsyncTask.cancel()
ipV6AddressAsyncTask.cancel()
wifiAvailableAsyncTask.cancel()
availableAsyncTask.cancel()
domainAddressAsyncTask.cancel()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册