1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-21 11:52:07 +01:00

Update opoc

This commit is contained in:
Gregor Santner 2019-09-07 21:54:08 +02:00
parent 8c3c7da2ab
commit c5e3a42005
No known key found for this signature in database
GPG key ID: 7E83A7834AECB009
3 changed files with 48 additions and 1 deletions

View file

@ -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;
}
}
}

View file

@ -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));

View 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
*/