V2.1 stable
This commit is contained in:
Epic Studios 2024-01-10 04:46:21 +02:00
parent df34043cfe
commit 512140534c
450 changed files with 64666 additions and 0 deletions

View file

@ -0,0 +1,81 @@
package com.vectras.vm.utils;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import com.vectras.vm.AppConfig;
import com.vectras.vm.R;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class AppUpdater extends AsyncTask<String, String, String> {
private Context context;
private OnUpdateListener listener;
private ProgressDialog progressDialog;
private boolean isOnCreate;
public AppUpdater(Context context, OnUpdateListener listener) {
this.context = context;
this.listener = listener;
}
public void start(boolean isOnCreate) {
this.isOnCreate = isOnCreate;
execute();
}
public interface OnUpdateListener {
void onUpdateListener(String result);
}
@Override
protected String doInBackground(String... strings) {
try {
StringBuilder sb = new StringBuilder();
URL url = new URL(AppConfig.updateJson);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setRequestMethod("GET");
conn.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response;
while ((response = br.readLine()) != null) {
sb.append(response);
}
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
return "Error on getting data: " + e.getMessage();
}
}
@Override
protected void onPreExecute() {
super.onPreExecute();
if (isOnCreate) {
progressDialog = new ProgressDialog(context, R.style.MainDialogTheme);
progressDialog.setMessage("Please wait for the check");
progressDialog.setTitle("Looking for Update");
progressDialog.setCancelable(false);
progressDialog.show();
}
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if (isOnCreate && progressDialog != null) {
progressDialog.dismiss();
}
if (listener != null) {
listener.onUpdateListener(s);
}
}
}

View file

@ -0,0 +1,605 @@
package com.vectras.vm.utils;
import android.annotation.SuppressLint;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.provider.OpenableColumns;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.MimeTypeMap;
import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.widget.Toast;
import com.vectras.vm.MainActivity;
import com.vectras.vm.AppConfig;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
/**
*
* @author dev
*/
public class FileUtils {
private static Uri contentUri = null;
@SuppressLint("NewApi")
public static String getPath(Context context, final Uri uri) {
// check here to KITKAT or new version
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
String selection = null;
String[] selectionArgs = null;
// DocumentProvider
if (isKitKat ) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
String fullPath = getPathFromExtSD(split);
if (fullPath != "") {
return fullPath;
} else {
return null;
}
}
// DownloadsProvider
if (isDownloadsDocument(uri)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final String id;
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, new String[]{MediaStore.MediaColumns.DISPLAY_NAME}, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
String fileName = cursor.getString(0);
String path = Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName;
if (!TextUtils.isEmpty(path)) {
return path;
}
}
}
finally {
if (cursor != null)
cursor.close();
}
id = DocumentsContract.getDocumentId(uri);
if (!TextUtils.isEmpty(id)) {
if (id.startsWith("raw:")) {
return id.replaceFirst("raw:", "");
}
String[] contentUriPrefixesToTry = new String[]{
"content://downloads/public_downloads",
"content://downloads/my_downloads"
};
for (String contentUriPrefix : contentUriPrefixesToTry) {
try {
final Uri contentUri = ContentUris.withAppendedId(Uri.parse(contentUriPrefix), Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);
} catch (NumberFormatException e) {
//In Android 8 and Android P the id is not a number
return uri.getPath().replaceFirst("^/document/raw:", "").replaceFirst("^raw:", "");
}
}
}
}
else {
final String id = DocumentsContract.getDocumentId(uri);
if (id.startsWith("raw:")) {
return id.replaceFirst("raw:", "");
}
try {
contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
}
catch (NumberFormatException e) {
e.printStackTrace();
}
if (contentUri != null) {
return getDataColumn(context, contentUri, null, null);
}
}
}
// MediaProvider
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;
}
selection = "_id=?";
selectionArgs = new String[]{split[1]};
return getDataColumn(context, contentUri, selection,
selectionArgs);
}
if (isGoogleDriveUri(uri)) {
return getDriveFilePath(context, uri);
}
if(isWhatsAppFile(uri)){
return getFilePathForWhatsApp(context, uri);
}
if ("content".equalsIgnoreCase(uri.getScheme())) {
if (isGooglePhotosUri(uri)) {
return uri.getLastPathSegment();
}
if (isGoogleDriveUri(uri)) {
return getDriveFilePath(context, uri);
}
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
{
// return getFilePathFromURI(context,uri);
return copyFileToInternalStorage(context, uri,"userfiles");
// return getRealPathFromURI(context,uri);
}
else
{
return getDataColumn(context, uri, null, null);
}
}
if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
}
else {
if(isWhatsAppFile(uri)){
return getFilePathForWhatsApp(context, uri);
}
if ("content".equalsIgnoreCase(uri.getScheme())) {
String[] projection = {
MediaStore.Images.Media.DATA
};
Cursor cursor = null;
try {
cursor = context.getContentResolver()
.query(uri, projection, selection, selectionArgs, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
if (cursor.moveToFirst()) {
return cursor.getString(column_index);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return null;
}
private static boolean fileExists(String filePath) {
File file = new File(filePath);
return file.exists();
}
private static String getPathFromExtSD(String[] pathData) {
final String type = pathData[0];
final String relativePath = "/" + pathData[1];
String fullPath = "";
// on my Sony devices (4.4.4 & 5.1.1), `type` is a dynamic string
// something like "71F8-2C0A", some kind of unique id per storage
// don't know any API that can get the root path of that storage based on its id.
//
// so no "primary" type, but let the check here for other devices
if ("primary".equalsIgnoreCase(type)) {
fullPath = Environment.getExternalStorageDirectory() + relativePath;
if (fileExists(fullPath)) {
return fullPath;
}
}
// Environment.isExternalStorageRemovable() is `true` for external and internal storage
// so we cannot relay on it.
//
// instead, for each possible path, check if file exists
// we'll start with secondary storage as this could be our (physically) removable sd card
fullPath = System.getenv("SECONDARY_STORAGE") + relativePath;
if (fileExists(fullPath)) {
return fullPath;
}
fullPath = System.getenv("EXTERNAL_STORAGE") + relativePath;
if (fileExists(fullPath)) {
return fullPath;
}
return fullPath;
}
private static String getDriveFilePath(Context context, Uri uri) {
Uri returnUri = uri;
Cursor returnCursor = context.getContentResolver().query(returnUri, null, null, null, null);
/*
* Get the column indexes of the data in the Cursor,
* * move to the first row in the Cursor, get the data,
* * and display it.
* */
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
returnCursor.moveToFirst();
String name = (returnCursor.getString(nameIndex));
String size = (Long.toString(returnCursor.getLong(sizeIndex)));
File file = new File(context.getCacheDir(), name);
try {
InputStream inputStream = context.getContentResolver().openInputStream(uri);
FileOutputStream outputStream = new FileOutputStream(file);
int read = 0;
int maxBufferSize = 1 * 1024 * 1024;
int bytesAvailable = inputStream.available();
//int bufferSize = 1024;
int bufferSize = Math.min(bytesAvailable, maxBufferSize);
final byte[] buffers = new byte[bufferSize];
while ((read = inputStream.read(buffers)) != -1) {
outputStream.write(buffers, 0, read);
}
Log.e("File Size", "Size " + file.length());
inputStream.close();
outputStream.close();
Log.e("File Path", "Path " + file.getPath());
Log.e("File Size", "Size " + file.length());
} catch (Exception e) {
Log.e("Exception", e.getMessage());
}
return file.getPath();
}
/***
* Used for Android Q+
* @param uri
* @param newDirName if you want to create a directory, you can set this variable
* @return
*/
private static String copyFileToInternalStorage(Context context, Uri uri, String newDirName) {
Uri returnUri = uri;
Cursor returnCursor = context.getContentResolver().query(returnUri, new String[]{
OpenableColumns.DISPLAY_NAME,OpenableColumns.SIZE
}, null, null, null);
/*
* Get the column indexes of the data in the Cursor,
* * move to the first row in the Cursor, get the data,
* * and display it.
* */
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
returnCursor.moveToFirst();
String name = (returnCursor.getString(nameIndex));
String size = (Long.toString(returnCursor.getLong(sizeIndex)));
File output;
if(!newDirName.equals("")) {
File dir = new File(context.getFilesDir() + "/" + newDirName);
if (!dir.exists()) {
dir.mkdir();
}
output = new File(context.getFilesDir() + "/" + newDirName + "/" + name);
}
else{
output = new File(context.getFilesDir() + "/" + name);
}
try {
InputStream inputStream = context.getContentResolver().openInputStream(uri);
FileOutputStream outputStream = new FileOutputStream(output);
int read = 0;
int bufferSize = 1024;
final byte[] buffers = new byte[bufferSize];
while ((read = inputStream.read(buffers)) != -1) {
outputStream.write(buffers, 0, read);
}
inputStream.close();
outputStream.close();
}
catch (Exception e) {
Log.e("Exception", e.getMessage());
}
return output.getPath();
}
private static String getFilePathForWhatsApp(Context context, Uri uri){
return copyFileToInternalStorage(context, uri,"whatsapp");
}
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
Cursor cursor = null;
final String column = "_data";
final String[] projection = {column};
try {
cursor = context.getContentResolver().query(uri, projection,
selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
final int index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(index);
}
}
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 boolean isGooglePhotosUri(Uri uri) {
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
}
public static boolean isWhatsAppFile(Uri uri){
return "com.whatsapp.provider.media".equals(uri.getAuthority());
}
private static boolean isGoogleDriveUri(Uri uri) {
return "com.google.android.apps.docs.storage".equals(uri.getAuthority()) || "com.google.android.apps.docs.storage.legacy".equals(uri.getAuthority());
}
public String LoadFile(Activity activity, String fileName, boolean loadFromRawFolder) throws IOException {
// Create a InputStream to read the file into
InputStream iS;
if (loadFromRawFolder) {
// get the resource id from the file name
int rID = activity.getResources().getIdentifier(getClass().getPackage().getName() + ":raw/" + fileName,
null, null);
// get the file as a stream
iS = activity.getResources().openRawResource(rID);
} else {
// get the file as a stream
iS = activity.getResources().getAssets().open(fileName);
}
ByteArrayOutputStream oS = new ByteArrayOutputStream();
byte[] buffer = new byte[iS.available()];
int bytesRead = 0;
while ((bytesRead = iS.read(buffer)) > 0) {
oS.write(buffer);
}
oS.close();
iS.close();
// return the output stream as a String
return oS.toString();
}
public static void saveFileContents(String dBFile, String machinesToExport) {
// TODO Auto-generated method stub
byteArrayToFile(machinesToExport.getBytes(), new File(dBFile));
}
public static void byteArrayToFile(byte[] byteData, File filePath) {
try {
FileOutputStream fos = new FileOutputStream(filePath);
fos.write(byteData);
fos.close();
} catch (FileNotFoundException ex) {
System.out.println("FileNotFoundException : " + ex);
} catch (IOException ioe) {
System.out.println("IOException : " + ioe);
}
}
public static String getDataDir() {
String dataDir = MainActivity.activity.getApplicationInfo().dataDir;
PackageManager m = MainActivity.activity.getPackageManager();
String packageName = MainActivity.activity.getPackageName();
Log.v("VMExecutor", "Found packageName: " + packageName);
if (dataDir == null) {
dataDir = "/data/data/" + packageName;
}
return dataDir;
}
public static boolean fileValid(Context context, String path) {
if (path == null || path.equals(""))
return true;
if (path.startsWith("content://") || path.startsWith("/content/")) {
int fd = get_fd(context, path);
if (fd <= 0)
return false;
} else {
File file = new File(path);
return file.exists();
}
return true;
}
public static HashMap<Integer, ParcelFileDescriptor> fds = new HashMap<Integer, ParcelFileDescriptor>();
public static int get_fd(final Context context, String path) {
int fd = 0;
if (path == null)
return 0;
if (path.startsWith("/content") || path.startsWith("content://")) {
path = path.replaceFirst("/content", "content:");
try {
ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(Uri.parse(path), "rw");
fd = pfd.getFd();
fds.put(fd, pfd);
} catch (final FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "Error: " + e, Toast.LENGTH_SHORT).show();
}
});
}
} else {
try {
File file = new File(path);
if (!file.exists())
file.createNewFile();
ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_WRITE_ONLY);
fd = pfd.getFd();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return fd;
}
public static int close_fd(int fd) {
if (FileUtils.fds.containsKey(fd)) {
ParcelFileDescriptor pfd = FileUtils.fds.get(fd);
try {
pfd.close();
FileUtils.fds.remove(fd);
return 0; // success for Native side
} catch (IOException e) {
e.printStackTrace();
}
}
return -1;
}
public static void writeToFile(String data, File file, Context context) {
try {
FileOutputStream fileOutStream = new FileOutputStream(file);
OutputStreamWriter outputWriter = new OutputStreamWriter(fileOutStream);
outputWriter.write(data);
outputWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static String readFromFile(Context context, File file) {
String contents = null;
try {
int length = (int) file.length();
byte[] bytes = new byte[length];
FileInputStream in = new FileInputStream(file);
try {
in.read(bytes);
} finally {
in.close();
}
contents = new String(bytes);
} catch (Exception e) {
UIUtils.toastLong(context, e.toString());
return "error";
}
return contents;
}
public static boolean moveFile(String oldfilename, String newFolderPath, String newFilename) {
File folder = new File(newFolderPath);
if (!folder.exists())
folder.mkdirs();
File oldfile = new File(oldfilename);
File newFile = new File(newFolderPath, newFilename);
if (!newFile.exists())
try {
newFile.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return oldfile.renameTo(newFile);
}
}

View file

@ -0,0 +1,378 @@
package com.vectras.vm.utils;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Point;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.text.InputType;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.vectras.qemu.Config;
import com.vectras.qemu.MainActivityCommon;
import com.vectras.qemu.MainSettingsManager;
import com.vectras.qemu.utils.FileUtils;
import com.vectras.vm.R;
import com.vectras.vm.AppConfig;
import com.vectras.vm.logger.VectrasStatus;
import java.io.IOException;
import java.util.Scanner;
public class UIUtils {
private static final String TAG = "UIUtils";
public static Spannable formatAndroidLog(String contents) {
Scanner scanner = null;
Spannable formattedString = new SpannableString(contents);
if(contents.length()==0)
return formattedString;
try {
scanner = new Scanner(contents);
int counter = 0;
ForegroundColorSpan colorSpan = null;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
//FIXME: some devices don't have standard format for the log
if (line.startsWith("E/") || line.contains(" E ")) {
colorSpan = new ForegroundColorSpan(Color.rgb(255, 22, 22));
} else if (line.startsWith("W/") || line.contains(" W ")) {
colorSpan = new ForegroundColorSpan(Color.rgb(22, 44, 255));
} else {
colorSpan = null;
}
if (colorSpan!= null) {
formattedString.setSpan(colorSpan, counter, counter + line.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
counter += line.length()+1;
}
}catch (Exception ex) {
Log.e(TAG, "Could not format vectras log: " + ex.getMessage());
} finally {
if(scanner!=null) {
try {
scanner.close();
} catch (Exception ex) {
if(Config.debug)
ex.printStackTrace();
}
}
}
return formattedString;
}
public static void toastLong(final Context activity, final String errStr) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast toast = Toast.makeText(activity, errStr, Toast.LENGTH_LONG);
toast.show();
VectrasStatus.logInfo("<font color='yellow'>[I] "+errStr+"</font>");
}
});
}
public static void showFileNotSupported(Activity context){
UIAlert(context, "Error", "File path is not supported. Make sure you choose a file/directory from your internal storage or external sd card. Root and Download Directories are not supported.");
}
public static boolean onKeyboard(Activity activity, boolean toggle, View view) {
// Prevent crashes from activating mouse when machine is paused
if (MainActivityCommon.vmexecutor.paused == 1)
return !toggle;
InputMethodManager inputMgr = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
//XXX: we need to get the focused view to make this always work
//inputMgr.toggleSoftInput(0, 0);
// View view = activity.getCurrentFocus();
if (toggle || !Config.enableToggleKeyboard){
if(view!=null) {
view.requestFocus();
inputMgr.showSoftInput(view, InputMethodManager.SHOW_FORCED);
}
} else {
if (view != null) {
inputMgr.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
return !toggle;
}
public static void hideKeyboard(Activity activity, View view) {
InputMethodManager inputMgr = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (view != null) {
inputMgr.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
public static void toastShortTop(final Activity activity, final String errStr) {
UIUtils.toast(activity, errStr, Gravity.TOP | Gravity.CENTER, Toast.LENGTH_SHORT);
}
public static void toast(final Context context, final String errStr, final int gravity, final int length) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
if(context instanceof Activity && ((Activity) context).isFinishing()) {
return ;
}
Toast toast = Toast.makeText(context, errStr, length);
toast.setGravity(gravity, 0, 0);
toast.show();
}
});
}
public static void toastShort(final Context context, final String errStr) {
toast(context, errStr, Gravity.CENTER | Gravity.CENTER, Toast.LENGTH_SHORT);
}
public static void setOrientation(Activity activity) {
int orientation = MainSettingsManager.getOrientationSetting(activity);
switch (orientation) {
case 0:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
break;
case 1:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break;
case 2:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
break;
case 3:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
case 4:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
break;
}
}
public static void onChangeLog(Activity activity) {
PackageInfo pInfo = null;
try {
pInfo = activity.getPackageManager().getPackageInfo(activity.getClass().getPackage().getName(),
PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
com.vectras.qemu.utils.FileUtils fileutils = new com.vectras.qemu.utils.FileUtils();
try {
UIUtils.UIAlert(activity,"CHANGELOG", fileutils.LoadFile(activity, "CHANGELOG", false),
0, false, "OK", null, null, null, null, null);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void showHints(Activity activity) {
UIUtils.toastShortTop(activity, "Press Volume Down for Right Click");
}
public static boolean isLandscapeOrientation(Activity activity)
{
Display display = activity.getWindowManager().getDefaultDisplay();
Point screenSize = new Point();
display.getSize(screenSize);
if(screenSize.x < screenSize.y)
return false;
return true;
}
private static void openURL(Activity activity, String url) {
try {
Intent fileIntent = new Intent(Intent.ACTION_VIEW);
fileIntent.setData(Uri.parse(url));
activity.startActivity(fileIntent);
}catch (Exception ex) {
UIUtils.toastShort(activity, "Could not open url");
}
}
public static void UIAlert(Activity activity, String title, String body) {
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
alertDialog.setTitle(title);
TextView textView = new TextView(activity);
textView.setPadding(20,20,20,20);
textView.setText(body);
ScrollView view = new ScrollView(activity);
view.addView(textView);
alertDialog.setView(view);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.show();
}
public static void UIAlert(Activity activity, String title, String body, int textSize, boolean cancelable,
String button1title, DialogInterface.OnClickListener button1Listener,
String button2title, DialogInterface.OnClickListener button2Listener,
String button3title, DialogInterface.OnClickListener button3Listener
) {
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
alertDialog.setTitle(title);
alertDialog.setCanceledOnTouchOutside(cancelable);
TextView textView = new TextView(activity);
textView.setPadding(20,20,20,20);
textView.setText(body);
if(textSize>0)
textView.setTextSize(textSize);
textView.setBackgroundColor(Color.WHITE);
textView.setTextColor(Color.BLACK);
ScrollView view = new ScrollView(activity);
view.addView(textView);
alertDialog.setView(view);
if(button1title!=null)
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, button1title, button1Listener);
if(button2title!=null)
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, button2title, button2Listener);
if(button3title!=null)
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, button3title, button3Listener);
alertDialog.show();
}
public static void UIAlertLog(final Activity activity, String title, Spannable body) {
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
alertDialog.setTitle(title);
TextView textView = new TextView(activity);
textView.setPadding(20,20,20,20);
textView.setText(body);
textView.setBackgroundColor(Color.BLACK);
textView.setTextSize(12);
textView.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
textView.setSingleLine(false);
ScrollView view = new ScrollView(activity);
view.addView(textView);
alertDialog.setView(view);
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "Copy To", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
ClipboardManager clipboardManager = (ClipboardManager)
activity.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("nonsense_data",
body);
clipboardManager.setPrimaryClip(clipData);
UIUtils.toastShort(activity, "Copied to clipboard successfully!");
return;
}
});
alertDialog.show();
}
public static void UIAlertHtml(String title, String body, Activity activity) {
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
alertDialog.setTitle(title);
try {
WebView webview = new WebView(activity);
webview.loadData(body, "text/html", "UTF-8");
alertDialog.setView(webview);
} catch (Exception ex) {
TextView textView = new TextView(activity);
textView.setText(body);
alertDialog.setView(textView);
}
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.show();
}
public static void promptShowLog(final Activity activity) {
final AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
alertDialog.setTitle("Show log");
TextView stateView = new TextView(activity);
stateView.setText("Something happened during last run, do you want to see the log?");
stateView.setPadding(20, 20, 20, 20);
alertDialog.setView(stateView);
// alertDialog.setMessage(body);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
FileUtils.viewVectrasLog(activity);
}
});
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
}