Unverified Commit c5e3a420 authored by gsantner's avatar gsantner 🦀
Browse files

Update opoc

parent 8c3c7da2
......@@ -12,6 +12,7 @@ package net.gsantner.opoc.util;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
......@@ -47,6 +48,7 @@ import android.support.annotation.Nullable;
import android.support.annotation.RawRes;
import android.support.annotation.StringRes;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.app.ActivityManagerCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.util.Pair;
......@@ -945,6 +947,16 @@ public class ContextUtils {
}
}
public boolean isDeviceGoodHardware() {
try {
ActivityManager activityManager = (ActivityManager) _context.getSystemService(Context.ACTIVITY_SERVICE);
return !ActivityManagerCompat.isLowRamDevice(activityManager) &&
Runtime.getRuntime().availableProcessors() >= 4 &&
activityManager.getMemoryClass() >= 128;
} catch (Exception ignored) {
return true;
}
}
}
......@@ -16,6 +16,7 @@ import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
......@@ -42,13 +43,22 @@ public class FileUtils {
public static String readTextFileFast(final File file) {
try {
return new String(readCloseBinaryStream(new FileInputStream(file)));
return new String(readCloseStreamWithSize(new FileInputStream(file), (int) file.length()));
} catch (FileNotFoundException e) {
System.err.println("readTextFileFast: File " + file + " not found.");
}
return "";
}
public static byte[] readCloseStreamWithSize(final InputStream stream, int size) {
byte[] data = new byte[size];
try (DataInputStream dis = new DataInputStream(stream)) {
dis.readFully(data);
} catch (IOException ignored) {
}
return data;
}
public static String readTextFile(final File file) {
try {
return readCloseTextStream(new FileInputStream(file));
......
......@@ -65,6 +65,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Locale;
......@@ -230,6 +231,30 @@ public class ShareUtil {
}
}
/**
* Share the given files as stream with given mime-type
*
* @param files The files to share
* @param mimeType The files mime type. Usally * / * is the best option
*/
public boolean shareStreamMultiple(Collection<File> files, String mimeType) {
ArrayList<Uri> uris = new ArrayList<>();
for (File file : files) {
File uri = new File(file.toString());
uris.add(FileProvider.getUriForFile(_context, getFileProviderAuthority(), file));
}
try {
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType(mimeType);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
showChooser(intent, null);
return true;
} catch (Exception e) { // FileUriExposed(API24) / IllegalArgument
return false;
}
}
/**
* Start calendar application to add new event, with given details prefilled
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment