2020.08.14

This commit is contained in:
2020-08-14 18:13:52 +08:00
commit 840ab0e52b
39 changed files with 734 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package com.tt
import android.app.Application
import com.tt.ttutils.java.ToastUtil
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
ToastUtil.init(this)
}
}

View File

@@ -0,0 +1,16 @@
package com.tt.activity
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.tt.ttutils.R
import com.tt.ttutils.java.CmdUtil
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//截图
CmdUtil.execute(" screencap -p /sdcard/" + "screen" + System.currentTimeMillis() + ".png");
}
}

View File

@@ -0,0 +1,5 @@
package com.tt.ttutils.java;
public class ApkUtils {
}

View File

@@ -0,0 +1,4 @@
package com.tt.ttutils.java;
public class BitmapUtils {
}

View File

@@ -0,0 +1,103 @@
package com.tt.ttutils.java;
import android.text.TextUtils;
import android.util.Log;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class CmdUtil {
private static final String TAG = "CmdUtil";
private static final String COMMAND_SH = "sh";
private static final String COMMAND_EXIT = "exit\n";
private static final String COMMAND_LINE_END = "\n";
/**
* 运行命令
*
* @param command 命令
* @return 结果
*/
public static Result execute(String command) {
Log.i(TAG, "execute() command = " + command);
Result result = new Result();
if (TextUtils.isEmpty(command)) {
Log.w(TAG, "WARNING: command should not be null or empty");
return result;
}
Process process = null;
DataOutputStream dos = null;
try {
process = Runtime.getRuntime().exec(COMMAND_SH);
dos = new DataOutputStream(process.getOutputStream());
dos.write(command.trim().getBytes());
dos.writeBytes(COMMAND_LINE_END);
dos.flush();
dos.writeBytes(COMMAND_EXIT);
dos.flush();
result.code = process.waitFor();
result.success = readBuffer(new BufferedReader(new InputStreamReader(process.getInputStream())));
result.error = readBuffer(new BufferedReader(new InputStreamReader(process.getErrorStream())));
Log.i(TAG, "result = " + result);
} catch (IOException ioe) {
ioe.printStackTrace();
Log.e(TAG, ioe.getMessage());
} catch (InterruptedException ie) {
ie.printStackTrace();
Log.e(TAG, ie.getMessage());
} finally {
try {
if (null != dos) {
dos.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
Log.e(TAG, ioe.getMessage());
}
if (null != process) {
process.destroy();
}
}
return result;
}
private static String readBuffer(BufferedReader bufferedReader) throws IOException {
StringBuilder sb = new StringBuilder();
String s;
while ((s = bufferedReader.readLine()) != null) {
sb.append(s);
}
return sb.toString();
}
/**
* Command执行结果
*/
public static final class Result {
public static final int SUCCESS = 0;
public static final int ERROR = -1;
public int code = ERROR;
String error;
String success;
@Override
public String toString() {
return "Result{" +
"code=" + code +
", error='" + error + '\'' +
", success='" + success + '\'' +
'}';
}
}
}

View File

@@ -0,0 +1,5 @@
package com.tt.ttutils.java;
public class OtherUtils {
}

View File

@@ -0,0 +1,17 @@
package com.tt.ttutils.java;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class PictrueUtils {
/**{@link }
* 静默截图
*https://blog.csdn.net/mochiwxtianya/article/details/78889773
*https://www.cnblogs.com/angel88/p/7933437.html
* @params
*/
//1.系统签名adb命令截图
}

View File

@@ -0,0 +1,5 @@
package com.tt.ttutils.java;
public class SystemSignUtils {
}

View File

@@ -0,0 +1,101 @@
package com.tt.ttutils.java;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import com.tt.ttutils.BuildConfig;
/**
* Created by tongtong on 2017/3/2.
*/
public class ToastUtil {
private static Handler mainHandler = new Handler(Looper.getMainLooper());
private static Toast toast;
private static Context mContext;
@SuppressLint("ShowToast")
public static void init(Context context) {
mContext = context;
toast = Toast.makeText(mContext, "", Toast.LENGTH_SHORT);
debugToast = Toast.makeText(mContext, "", Toast.LENGTH_SHORT);
}
private static long time1 = 0L;
private static long time2 = 0L;
public static void show(final String msg) {
mainHandler.post(new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
time2 = System.currentTimeMillis();
if ((time2 - time1) > 3499) {
showToast(mContext, msg, Toast.LENGTH_LONG);
Log.e("fht", "LENGTH_LONG");
time1 = time2;
}
} else {
if (toast != null) {
toast.setText(msg);
toast.show();
}
}
}
});
}
private static Toast mToast = null;
//android 8.0以后限制
//https://www.jianshu.com/p/d9813ad03d59
//https://www.jianshu.com/p/050ce052b873
public static void showToast(Context context, String text, int duration) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.P) {
Toast.makeText(context, text, duration).show();
} else {
if (mToast == null) {
mToast = Toast.makeText(context, text, duration);
} else {
mToast.setText(text);
mToast.setDuration(duration);
}
mToast.show();
}
}
// public static void showInCenter(String msg) {
// mainHandler.post(() -> {
// if (toast != null) {
// toast.setGravity(Gravity.CENTER, 0, 0);
// toast.setText(msg);
// toast.show();
// }
// });
// }
static Handler debugHandler = new Handler(Looper.getMainLooper());
static Toast debugToast;
public static void debugShow(final String msg) {
mainHandler.post(new Runnable() {
@Override
public void run() {
if (BuildConfig.DEBUG) {
if (toast != null) {
toast.setText(msg);
toast.show();
}
}
}
});
}
}

View File

@@ -0,0 +1,6 @@
package com.tt.ttutils.kt
class ApkUtils {
}