Add files via upload

This commit is contained in:
xC3FFF0E 2021-02-08 19:43:37 +08:00 committed by GitHub
parent 9cf8d11b82
commit a37367cf75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 6208 additions and 0 deletions

25
AJCode.java Normal file
View File

@ -0,0 +1,25 @@
package com.xc3fff0e.xmanager;
import android.graphics.drawable.*;
import android.view.*;
import android.widget.*;
import android.content.res.*;
import android.graphics.*;
import android.view.Gravity;
public class AJCode{
public static void setBackgroundGradient(View view, int color1, int color2){
GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.BL_TR, new int[] {color1,color2});
view.setBackgroundDrawable(gd);
}
public static void setRoundedRipple(View v,int LT,int RT,int RB,int LB,int color1,int size,int color2,int color3){
GradientDrawable shape = new GradientDrawable();
shape.setColor(color1);
shape.setCornerRadii(new float[]{(float)LT,(float)LT,(float)RT,(float)RT,(float)RB,(float)RB,(float)LB,(float)LB});
shape.setStroke(size, color2);
RippleDrawable ripdr = new RippleDrawable(new ColorStateList(new int[][]{new int[]{}}, new int[]{color3}), shape, null);
v.setBackgroundDrawable(ripdr);
}
}

111
BluetoothConnect.java Normal file
View File

@ -0,0 +1,111 @@
package com.xc3fff0e.xmanager;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.util.UUID;
public class BluetoothConnect {
private static final String DEFAULT_UUID = "00001101-0000-1000-8000-00805F9B34FB";
private Activity activity;
private BluetoothAdapter bluetoothAdapter;
public BluetoothConnect(Activity activity) {
this.activity = activity;
this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
public boolean isBluetoothEnabled() {
if(bluetoothAdapter != null) return true;
return false;
}
public boolean isBluetoothActivated() {
if(bluetoothAdapter == null) return false;
return bluetoothAdapter.isEnabled();
}
public void activateBluetooth() {
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
activity.startActivity(intent);
}
public String getRandomUUID() {
return String.valueOf(UUID.randomUUID());
}
public void getPairedDevices(ArrayList<HashMap<String, Object>> results) {
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
if(pairedDevices.size() > 0) {
for(BluetoothDevice device : pairedDevices) {
HashMap<String, Object> result = new HashMap<>();
result.put("name", device.getName());
result.put("address", device.getAddress());
results.add(result);
}
}
}
public void readyConnection(BluetoothConnectionListener listener, String tag) {
if(BluetoothController.getInstance().getState().equals(BluetoothController.STATE_NONE)) {
BluetoothController.getInstance().start(this, listener, tag, UUID.fromString(DEFAULT_UUID), bluetoothAdapter);
}
}
public void readyConnection(BluetoothConnectionListener listener, String uuid, String tag) {
if(BluetoothController.getInstance().getState().equals(BluetoothController.STATE_NONE)) {
BluetoothController.getInstance().start(this, listener, tag, UUID.fromString(uuid), bluetoothAdapter);
}
}
public void startConnection(BluetoothConnectionListener listener, String address, String tag) {
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address);
BluetoothController.getInstance().connect(device, this, listener, tag, UUID.fromString(DEFAULT_UUID), bluetoothAdapter);
}
public void startConnection(BluetoothConnectionListener listener, String uuid, String address, String tag) {
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address);
BluetoothController.getInstance().connect(device, this, listener, tag, UUID.fromString(uuid), bluetoothAdapter);
}
public void stopConnection(BluetoothConnectionListener listener, String tag) {
BluetoothController.getInstance().stop(this, listener, tag);
}
public void sendData(BluetoothConnectionListener listener, String data, String tag) {
String state = BluetoothController.getInstance().getState();
if(!state.equals(BluetoothController.STATE_CONNECTED)) {
listener.onConnectionError(tag, state, "Bluetooth is not connected yet");
return;
}
BluetoothController.getInstance().write(data.getBytes());
}
public Activity getActivity() {
return activity;
}
public interface BluetoothConnectionListener {
void onConnected(String tag, HashMap<String, Object> deviceData);
void onDataReceived(String tag, byte[] data, int bytes);
void onDataSent(String tag, byte[] data);
void onConnectionError(String tag, String connectionState, String message);
void onConnectionStopped(String tag);
}
}

354
BluetoothController.java Normal file
View File

@ -0,0 +1,354 @@
package com.xc3fff0e.xmanager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.UUID;
public class BluetoothController {
public static final String STATE_NONE = "none";
public static final String STATE_LISTEN = "listen";
public static final String STATE_CONNECTING = "connecting";
public static final String STATE_CONNECTED = "connected";
private AcceptThread acceptThread;
private ConnectThread connectThread;
private ConnectedThread connectedThread;
private String state = STATE_NONE;
private static BluetoothController instance;
public static synchronized BluetoothController getInstance() {
if(instance == null) {
instance = new BluetoothController();
}
return instance;
}
public synchronized void start(BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag, UUID uuid, BluetoothAdapter bluetoothAdapter) {
if (connectThread != null) {
connectThread.cancel();
connectThread = null;
}
if (connectedThread != null) {
connectedThread.cancel();
connectedThread = null;
}
if (acceptThread != null) {
acceptThread.cancel();
acceptThread = null;
}
acceptThread = new AcceptThread(bluetoothConnect, listener, tag, uuid, bluetoothAdapter);
acceptThread.start();}
public synchronized void connect(BluetoothDevice device, BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag, UUID uuid, BluetoothAdapter bluetoothAdapter) {
if (state.equals(STATE_CONNECTING)) {
if (connectThread != null) {
connectThread.cancel();
connectThread = null;
}
}
if (connectedThread != null) {
connectedThread.cancel();
connectedThread = null;
}
connectThread = new ConnectThread(device, bluetoothConnect, listener, tag, uuid, bluetoothAdapter);
connectThread.start();
}
public synchronized void connected(BluetoothSocket socket, final BluetoothDevice device, BluetoothConnect bluetoothConnect, final BluetoothConnect.BluetoothConnectionListener listener, final String tag) {
if (connectThread != null) {
connectThread.cancel();
connectThread = null;
}
if (connectedThread != null) {
connectedThread.cancel();
connectedThread = null;
}
if (acceptThread != null) {
acceptThread.cancel();
acceptThread = null;
}
connectedThread = new ConnectedThread(socket, bluetoothConnect, listener, tag);
connectedThread.start();
bluetoothConnect.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
HashMap<String, Object> deviceMap = new HashMap<>();
deviceMap.put("name", device.getName());
deviceMap.put("address", device.getAddress());
listener.onConnected(tag, deviceMap);
}
});
}
public synchronized void stop(BluetoothConnect bluetoothConnect, final BluetoothConnect.BluetoothConnectionListener listener, final String tag) {
if (connectThread != null) {
connectThread.cancel();
connectThread = null;
}
if (connectedThread != null) {
connectedThread.cancel();
connectedThread = null;
}
if (acceptThread != null) {
acceptThread.cancel();
acceptThread = null;
}
state = STATE_NONE;
bluetoothConnect.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
listener.onConnectionStopped(tag);
}
});
}
public void write(byte[] out) {
ConnectedThread r;
synchronized (this) {
if (!state.equals(STATE_CONNECTED)) return;
r = connectedThread;
}
r.write(out);
}
public void connectionFailed(BluetoothConnect bluetoothConnect, final BluetoothConnect.BluetoothConnectionListener listener, final String tag, final String message) {
state = STATE_NONE;
bluetoothConnect.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
listener.onConnectionError(tag, state, message);
}
});
}
public void connectionLost(BluetoothConnect bluetoothConnect, final BluetoothConnect.BluetoothConnectionListener listener, final String tag) {
state = STATE_NONE;
bluetoothConnect.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
listener.onConnectionError(tag, state, "Bluetooth connection is disconnected");
}
});
}
public String getState() {
return state;
}
private class AcceptThread extends Thread {
private BluetoothServerSocket serverSocket;
private BluetoothConnect bluetoothConnect;
private BluetoothConnect.BluetoothConnectionListener listener;
private String tag;
public AcceptThread(BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag, UUID uuid, BluetoothAdapter bluetoothAdapter) {
this.bluetoothConnect = bluetoothConnect;
this.listener = listener;
this.tag = tag;
try {
serverSocket = bluetoothAdapter.listenUsingRfcommWithServiceRecord(tag, uuid);
} catch (Exception e) {
e.printStackTrace();
}
state = STATE_LISTEN;
}
@Override
public void run() {
BluetoothSocket bluetoothSocket;
while (!state.equals(STATE_CONNECTED)) {
try {
bluetoothSocket = serverSocket.accept();
} catch (Exception e) {
e.printStackTrace();
break;
}
if (bluetoothSocket != null) {
synchronized (BluetoothController.this) {
switch (state) {
case STATE_LISTEN:
case STATE_CONNECTING:
connected(bluetoothSocket, bluetoothSocket.getRemoteDevice(), bluetoothConnect, listener, tag);
break;
case STATE_NONE:
case STATE_CONNECTED:
try {
bluetoothSocket.close();
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
}
}
}
public void cancel() {
try {
serverSocket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private class ConnectThread extends Thread {
private BluetoothDevice device;
private BluetoothSocket socket;
private BluetoothConnect bluetoothConnect;
private BluetoothConnect.BluetoothConnectionListener listener;
private String tag;
private BluetoothAdapter bluetoothAdapter;
public ConnectThread(BluetoothDevice device, BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag, UUID uuid, BluetoothAdapter bluetoothAdapter) {
this.device = device;
this.bluetoothConnect = bluetoothConnect;
this.listener = listener;
this.tag = tag;
this.bluetoothAdapter = bluetoothAdapter;
try {
socket = device.createRfcommSocketToServiceRecord(uuid);
} catch (Exception e) {
e.printStackTrace();
}
state = STATE_CONNECTING;
}
@Override
public void run() {
bluetoothAdapter.cancelDiscovery();
try {
socket.connect();
} catch (Exception e) {
try {
socket.close();
} catch (Exception e2) {
e2.printStackTrace();
}
connectionFailed(bluetoothConnect, listener, tag, e.getMessage());
return;
}
synchronized (BluetoothController.this) {
connectThread = null;
}
connected(socket, device, bluetoothConnect, listener, tag);
}
public void cancel() {
try {
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private class ConnectedThread extends Thread {
private BluetoothSocket socket;
private InputStream inputStream;
private OutputStream outputStream;
private BluetoothConnect bluetoothConnect;
private BluetoothConnect.BluetoothConnectionListener listener;
private String tag;
public ConnectedThread(BluetoothSocket socket, BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag) {
this.bluetoothConnect = bluetoothConnect;
this.listener = listener;
this.tag = tag;
this.socket = socket;
try {
inputStream = socket.getInputStream();
outputStream = socket.getOutputStream();
} catch (Exception e) {
e.printStackTrace();
}
state = STATE_CONNECTED;
}
public void run() {
while (state.equals(STATE_CONNECTED)) {
try {
final byte[] buffer = new byte[1024];
final int bytes = inputStream.read(buffer);
bluetoothConnect.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
listener.onDataReceived(tag, buffer, bytes);
}
});
} catch (Exception e) {
e.printStackTrace();
connectionLost(bluetoothConnect, listener, tag);
break;
}
}
}
public void write(final byte[] buffer) {
try {
outputStream.write(buffer);
bluetoothConnect.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
listener.onDataSent(tag, buffer);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void cancel() {
try {
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

604
FileUtil.java Normal file
View File

@ -0,0 +1,604 @@
package com.xc3fff0e.xmanager;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.text.TextUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class FileUtil {
private static void createNewFile(String path) {
int lastSep = path.lastIndexOf(File.separator);
if (lastSep > 0) {
String dirPath = path.substring(0, lastSep);
makeDir(dirPath);
}
File file = new File(path);
try {
if (!file.exists())
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String readFile(String path) {
createNewFile(path);
StringBuilder sb = new StringBuilder();
FileReader fr = null;
try {
fr = new FileReader(new File(path));
char[] buff = new char[1024];
int length = 0;
while ((length = fr.read(buff)) > 0) {
sb.append(new String(buff, 0, length));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fr != null) {
try {
fr.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return sb.toString();
}
public static void writeFile(String path, String str) {
createNewFile(path);
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(new File(path), false);
fileWriter.write(str);
fileWriter.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fileWriter != null)
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void copyFile(String sourcePath, String destPath) {
if (!isExistFile(sourcePath)) return;
createNewFile(destPath);
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(sourcePath);
fos = new FileOutputStream(destPath, false);
byte[] buff = new byte[1024];
int length = 0;
while ((length = fis.read(buff)) > 0) {
fos.write(buff, 0, length);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void moveFile(String sourcePath, String destPath) {
copyFile(sourcePath, destPath);
deleteFile(sourcePath);
}
public static void deleteFile(String path) {
File file = new File(path);
if (!file.exists()) return;
if (file.isFile()) {
file.delete();
return;
}
File[] fileArr = file.listFiles();
if (fileArr != null) {
for (File subFile : fileArr) {
if (subFile.isDirectory()) {
deleteFile(subFile.getAbsolutePath());
}
if (subFile.isFile()) {
subFile.delete();
}
}
}
file.delete();
}
public static boolean isExistFile(String path) {
File file = new File(path);
return file.exists();
}
public static void makeDir(String path) {
if (!isExistFile(path)) {
File file = new File(path);
file.mkdirs();
}
}
public static void listDir(String path, ArrayList<String> list) {
File dir = new File(path);
if (!dir.exists() || dir.isFile()) return;
File[] listFiles = dir.listFiles();
if (listFiles == null || listFiles.length <= 0) return;
if (list == null) return;
list.clear();
for (File file : listFiles) {
list.add(file.getAbsolutePath());
}
}
public static boolean isDirectory(String path) {
if (!isExistFile(path)) return false;
return new File(path).isDirectory();
}
public static boolean isFile(String path) {
if (!isExistFile(path)) return false;
return new File(path).isFile();
}
public static long getFileLength(String path) {
if (!isExistFile(path)) return 0;
return new File(path).length();
}
public static String getExternalStorageDir() {
return Environment.getExternalStorageDirectory().getAbsolutePath();
}
public static String getPackageDataDir(Context context) {
return context.getExternalFilesDir(null).getAbsolutePath();
}
public static String getPublicDir(String type) {
return Environment.getExternalStoragePublicDirectory(type).getAbsolutePath();
}
public static String convertUriToFilePath(final Context context, final Uri uri) {
String path = null;
if (DocumentsContract.isDocumentUri(context, uri)) {
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
path = Environment.getExternalStorageDirectory() + "/" + split[1];
}
} else if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
if (!TextUtils.isEmpty(id)) {
if (id.startsWith("raw:")) {
return id.replaceFirst("raw:", "");
}
}
final Uri contentUri = ContentUris
.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
path = getDataColumn(context, contentUri, null, null);
} else if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = MediaStore.Audio.Media._ID + "=?";
final String[] selectionArgs = new String[]{
split[1]
};
path = getDataColumn(context, contentUri, selection, selectionArgs);
}
} else if (ContentResolver.SCHEME_CONTENT.equalsIgnoreCase(uri.getScheme())) {
path = getDataColumn(context, uri, null, null);
} else if (ContentResolver.SCHEME_FILE.equalsIgnoreCase(uri.getScheme())) {
path = uri.getPath();
}
if (path != null) {
try {
return URLDecoder.decode(path, "UTF-8");
}catch(Exception e){
return null;
}
}
return null;
}
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
Cursor cursor = null;
final String column = MediaStore.Images.Media.DATA;
final String[] projection = {
column
};
try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
final int column_index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(column_index);
}
} catch (Exception e) {
} finally {
if (cursor != null) {
cursor.close();
}
}
return null;
}
private static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
private static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
private static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
private static void saveBitmap(Bitmap bitmap, String destPath) {
FileOutputStream out = null;
FileUtil.createNewFile(destPath);
try {
out = new FileOutputStream(new File(destPath));
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static Bitmap getScaledBitmap(String path, int max) {
Bitmap src = BitmapFactory.decodeFile(path);
int width = src.getWidth();
int height = src.getHeight();
float rate = 0.0f;
if (width > height) {
rate = max / (float) width;
height = (int) (height * rate);
width = max;
} else {
rate = max / (float) height;
width = (int) (width * rate);
height = max;
}
return Bitmap.createScaledBitmap(src, width, height, true);
}
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
final int width = options.outWidth;
final int height = options.outHeight;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
public static Bitmap decodeSampleBitmapFromPath(String path, int reqWidth, int reqHeight) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, options);
}
public static void resizeBitmapFileRetainRatio(String fromPath, String destPath, int max) {
if (!isExistFile(fromPath)) return;
Bitmap bitmap = getScaledBitmap(fromPath, max);
saveBitmap(bitmap, destPath);
}
public static void resizeBitmapFileToSquare(String fromPath, String destPath, int max) {
if (!isExistFile(fromPath)) return;
Bitmap src = BitmapFactory.decodeFile(fromPath);
Bitmap bitmap = Bitmap.createScaledBitmap(src, max, max, true);
saveBitmap(bitmap, destPath);
}
public static void resizeBitmapFileToCircle(String fromPath, String destPath) {
if (!isExistFile(fromPath)) return;
Bitmap src = BitmapFactory.decodeFile(fromPath);
Bitmap bitmap = Bitmap.createBitmap(src.getWidth(),
src.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, src.getWidth(), src.getHeight());
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawCircle(src.getWidth() / 2, src.getHeight() / 2,
src.getWidth() / 2, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(src, rect, rect, paint);
saveBitmap(bitmap, destPath);
}
public static void resizeBitmapFileWithRoundedBorder(String fromPath, String destPath, int pixels) {
if (!isExistFile(fromPath)) return;
Bitmap src = BitmapFactory.decodeFile(fromPath);
Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src
.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, src.getWidth(), src.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(src, rect, rect, paint);
saveBitmap(bitmap, destPath);
}
public static void cropBitmapFileFromCenter(String fromPath, String destPath, int w, int h) {
if (!isExistFile(fromPath)) return;
Bitmap src = BitmapFactory.decodeFile(fromPath);
int width = src.getWidth();
int height = src.getHeight();
if (width < w && height < h)
return;
int x = 0;
int y = 0;
if (width > w)
x = (width - w) / 2;
if (height > h)
y = (height - h) / 2;
int cw = w;
int ch = h;
if (w > width)
cw = width;
if (h > height)
ch = height;
Bitmap bitmap = Bitmap.createBitmap(src, x, y, cw, ch);
saveBitmap(bitmap, destPath);
}
public static void rotateBitmapFile(String fromPath, String destPath, float angle) {
if (!isExistFile(fromPath)) return;
Bitmap src = BitmapFactory.decodeFile(fromPath);
Matrix matrix = new Matrix();
matrix.postRotate(angle);
Bitmap bitmap = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
saveBitmap(bitmap, destPath);
}
public static void scaleBitmapFile(String fromPath, String destPath, float x, float y) {
if (!isExistFile(fromPath)) return;
Bitmap src = BitmapFactory.decodeFile(fromPath);
Matrix matrix = new Matrix();
matrix.postScale(x, y);
int w = src.getWidth();
int h = src.getHeight();
Bitmap bitmap = Bitmap.createBitmap(src, 0, 0, w, h, matrix, true);
saveBitmap(bitmap, destPath);
}
public static void skewBitmapFile(String fromPath, String destPath, float x, float y) {
if (!isExistFile(fromPath)) return;
Bitmap src = BitmapFactory.decodeFile(fromPath);
Matrix matrix = new Matrix();
matrix.postSkew(x, y);
int w = src.getWidth();
int h = src.getHeight();
Bitmap bitmap = Bitmap.createBitmap(src, 0, 0, w, h, matrix, true);
saveBitmap(bitmap, destPath);
}
public static void setBitmapFileColorFilter(String fromPath, String destPath, int color) {
if (!isExistFile(fromPath)) return;
Bitmap src = BitmapFactory.decodeFile(fromPath);
Bitmap bitmap = Bitmap.createBitmap(src, 0, 0,
src.getWidth() - 1, src.getHeight() - 1);
Paint p = new Paint();
ColorFilter filter = new LightingColorFilter(color, 1);
p.setColorFilter(filter);
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(bitmap, 0, 0, p);
saveBitmap(bitmap, destPath);
}
public static void setBitmapFileBrightness(String fromPath, String destPath, float brightness) {
if (!isExistFile(fromPath)) return;
Bitmap src = BitmapFactory.decodeFile(fromPath);
ColorMatrix cm = new ColorMatrix(new float[]
{
1, 0, 0, 0, brightness,
0, 1, 0, 0, brightness,
0, 0, 1, 0, brightness,
0, 0, 0, 1, 0
});
Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(src, 0, 0, paint);
saveBitmap(bitmap, destPath);
}
public static void setBitmapFileContrast(String fromPath, String destPath, float contrast) {
if (!isExistFile(fromPath)) return;
Bitmap src = BitmapFactory.decodeFile(fromPath);
ColorMatrix cm = new ColorMatrix(new float[]
{
contrast, 0, 0, 0, 0,
0, contrast, 0, 0, 0,
0, 0, contrast, 0, 0,
0, 0, 0, 1, 0
});
Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(src, 0, 0, paint);
saveBitmap(bitmap, destPath);
}
public static int getJpegRotate(String filePath) {
int rotate = 0;
try {
ExifInterface exif = new ExifInterface(filePath);
int iOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
switch (iOrientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
default:
rotate = 0;
break;
}
}
catch (IOException e) {
return 0;
}
return rotate;
}
public static File createNewPictureFile(Context context) {
SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd_HHmmss");
String fileName = date.format(new Date()) + ".jpg";
File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_DCIM).getAbsolutePath() + File.separator + fileName);
return file;
}
}

4660
MainActivity.java Normal file

File diff suppressed because it is too large Load Diff

52
RequestNetwork.java Normal file
View File

@ -0,0 +1,52 @@
package com.xc3fff0e.xmanager;
import android.app.Activity;
import java.util.HashMap;
public class RequestNetwork {
private HashMap<String, Object> params = new HashMap<>();
private HashMap<String, Object> headers = new HashMap<>();
private Activity activity;
private int requestType = 0;
public RequestNetwork(Activity activity) {
this.activity = activity;
}
public void setHeaders(HashMap<String, Object> headers) {
this.headers = headers;
}
public void setParams(HashMap<String, Object> params, int requestType) {
this.params = params;
this.requestType = requestType;
}
public HashMap<String, Object> getParams() {
return params;
}
public HashMap<String, Object> getHeaders() {
return headers;
}
public Activity getActivity() {
return activity;
}
public int getRequestType() {
return requestType;
}
public void startRequestNetwork(String method, String url, String tag, RequestListener requestListener) {
RequestNetworkController.getInstance().execute(this, method, url, tag, requestListener);
}
public interface RequestListener {
public void onResponse(String tag, String response);
public void onErrorResponse(String tag, String message);
}
}

View File

@ -0,0 +1,180 @@
package com.xc3fff0e.xmanager;
import com.google.gson.Gson;
import java.io.IOException;
import java.security.cert.CertificateException;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class RequestNetworkController {
public static final String GET = "GET";
public static final String POST = "POST";
public static final String PUT = "PUT";
public static final String DELETE = "DELETE";
public static final int REQUEST_PARAM = 0;
public static final int REQUEST_BODY = 1;
private static final int SOCKET_TIMEOUT = 15000;
private static final int READ_TIMEOUT = 25000;
protected OkHttpClient client;
private static RequestNetworkController mInstance;
public static synchronized RequestNetworkController getInstance() {
if(mInstance == null) {
mInstance = new RequestNetworkController();
}
return mInstance;
}
private OkHttpClient getClient() {
if (client == null) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
try {
final TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType)
throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType)
throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
}
};
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]);
builder.connectTimeout(SOCKET_TIMEOUT, TimeUnit.MILLISECONDS);
builder.readTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
builder.writeTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
} catch (Exception e) {
}
client = builder.build();
}
return client;
}
public void execute(final RequestNetwork requestNetwork, String method, String url, final String tag, final RequestNetwork.RequestListener requestListener) {
Request.Builder reqBuilder = new Request.Builder();
Headers.Builder headerBuilder = new Headers.Builder();
if(requestNetwork.getHeaders().size() > 0) {
HashMap<String, Object> headers = requestNetwork.getHeaders();
for(HashMap.Entry<String, Object> header : headers.entrySet()) {
headerBuilder.add(header.getKey(), String.valueOf(header.getValue()));
}
}
try {
if (requestNetwork.getRequestType() == REQUEST_PARAM) {
if (method.equals(GET)) {
HttpUrl.Builder httpBuilder;
try {
httpBuilder = HttpUrl.parse(url).newBuilder();
} catch (NullPointerException ne) {
throw new NullPointerException("unexpected url: " + url);
}
if (requestNetwork.getParams().size() > 0) {
HashMap<String, Object> params = requestNetwork.getParams();
for (HashMap.Entry<String, Object> param : params.entrySet()) {
httpBuilder.addQueryParameter(param.getKey(), String.valueOf(param.getValue()));
}
}
reqBuilder.url(httpBuilder.build()).headers(headerBuilder.build()).get();
} else {
FormBody.Builder formBuilder = new FormBody.Builder();
if (requestNetwork.getParams().size() > 0) {
HashMap<String, Object> params = requestNetwork.getParams();
for (HashMap.Entry<String, Object> param : params.entrySet()) {
formBuilder.add(param.getKey(), String.valueOf(param.getValue()));
}
}
RequestBody reqBody = formBuilder.build();
reqBuilder.url(url).headers(headerBuilder.build()).method(method, reqBody);
}
} else {
RequestBody reqBody = RequestBody.create(okhttp3.MediaType.parse("application/json"), new Gson().toJson(requestNetwork.getParams()));
if (method.equals(GET)) {
reqBuilder.url(url).headers(headerBuilder.build()).get();
} else {
reqBuilder.url(url).headers(headerBuilder.build()).method(method, reqBody);
}
}
Request req = reqBuilder.build();
getClient().newCall(req).enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
requestNetwork.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
requestListener.onErrorResponse(tag, e.getMessage());
}
});
}
@Override
public void onResponse(Call call, final Response response) throws IOException {
final String responseBody = response.body().string().trim();
requestNetwork.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
requestListener.onResponse(tag, responseBody);
}
});
}
});
} catch (Exception e) {
requestListener.onErrorResponse(tag, e.getMessage());
}
}
}

71
SketchwareUtil.java Normal file
View File

@ -0,0 +1,71 @@
package com.xc3fff0e.xmanager;
import android.content.Context;
import android.util.SparseBooleanArray;
import android.util.TypedValue;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
public class SketchwareUtil {
public static void showMessage(Context _context, String _s) {
Toast.makeText(_context, _s, Toast.LENGTH_SHORT).show();
}
public static int getLocationX(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[0];
}
public static int getLocationY(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[1];
}
public static int getRandom(int _min, int _max) {
Random random = new Random();
return random.nextInt(_max - _min + 1) + _min;
}
public static ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
ArrayList<Double> _result = new ArrayList<Double>();
SparseBooleanArray _arr = _list.getCheckedItemPositions();
for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
if (_arr.valueAt(_iIdx))
_result.add((double) _arr.keyAt(_iIdx));
}
return _result;
}
public static float getDip(Context _context, int _input) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, _context.getResources().getDisplayMetrics());
}
public static int getDisplayWidthPixels(Context _context) {
return _context.getResources().getDisplayMetrics().widthPixels;
}
public static int getDisplayHeightPixels(Context _context) {
return _context.getResources().getDisplayMetrics().heightPixels;
}
public static void getAllKeysFromMap(Map<String, Object> map, ArrayList<String> output) {
if (output == null) return;
output.clear();
if (map == null || map.size() <= 0) return;
Iterator itr = map.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry<String, String> entry = (Map.Entry) itr.next();
output.add(entry.getKey());
}
}
}

151
SplashActivity.java Normal file
View File

@ -0,0 +1,151 @@
package com.xc3fff0e.xmanager;
import androidx.appcompat.app.AppCompatActivity;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.graphics.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.util.*;
import java.text.*;
import android.widget.LinearLayout;
import android.widget.ImageView;
import java.util.Timer;
import java.util.TimerTask;
import android.content.Intent;
import android.net.Uri;
public class SplashActivity extends AppCompatActivity {
private Timer _timer = new Timer();
private LinearLayout main_body;
private ImageView icon_logo;
private TimerTask Timer;
private Intent Switch_Activity = new Intent();
@Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.splash);
com.google.firebase.FirebaseApp.initializeApp(this);
initialize(_savedInstanceState);
initializeLogic();
}
private void initialize(Bundle _savedInstanceState) {
main_body = (LinearLayout) findViewById(R.id.main_body);
icon_logo = (ImageView) findViewById(R.id.icon_logo);
}
private void initializeLogic() {
Timer = new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Switch_Activity.setClass(getApplicationContext(), MainActivity.class);
startActivity(Switch_Activity);
finish();
}
});
}
};
_timer.schedule(Timer, (int)(1000));
}
@Override
protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
super.onActivityResult(_requestCode, _resultCode, _data);
switch (_requestCode) {
default:
break;
}
}
@Override
public void onBackPressed() {
SketchwareUtil.showMessage(getApplicationContext(), "Please wait...");
}
@Override
public void onResume() {
super.onResume();
_Hide_Navigation();
}
private void _Hide_Navigation () {
try {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
if (Build.VERSION.SDK_INT >= 21) { Window w = this.getWindow(); w.setNavigationBarColor(Color.parseColor("#212121"));
}
}
catch(Exception e) {
}
}
@Deprecated
public void showMessage(String _s) {
Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
}
@Deprecated
public int getLocationX(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[0];
}
@Deprecated
public int getLocationY(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[1];
}
@Deprecated
public int getRandom(int _min, int _max) {
Random random = new Random();
return random.nextInt(_max - _min + 1) + _min;
}
@Deprecated
public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
ArrayList<Double> _result = new ArrayList<Double>();
SparseBooleanArray _arr = _list.getCheckedItemPositions();
for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
if (_arr.valueAt(_iIdx))
_result.add((double)_arr.keyAt(_iIdx));
}
return _result;
}
@Deprecated
public float getDip(int _input){
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
}
@Deprecated
public int getDisplayWidthPixels(){
return getResources().getDisplayMetrics().widthPixels;
}
@Deprecated
public int getDisplayHeightPixels(){
return getResources().getDisplayMetrics().heightPixels;
}
}