|
|
|
@ -7,10 +7,8 @@ package com.todoroo.andlib.utility;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
|
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.InputStream;
|
|
|
|
@ -49,7 +47,6 @@ import android.net.NetworkInfo;
|
|
|
|
|
import android.net.NetworkInfo.State;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.text.InputType;
|
|
|
|
|
import android.util.Base64;
|
|
|
|
|
import android.util.DisplayMetrics;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
@ -142,54 +139,6 @@ public class AndroidUtilities {
|
|
|
|
|
return bitmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String encodeBase64Bitmap(Bitmap bitmap) {
|
|
|
|
|
String result = ""; //$NON-NLS-1$
|
|
|
|
|
int tries = 0;
|
|
|
|
|
while ("".equals(result) && tries < 5) { //$NON-NLS-1$
|
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100 - (10 * tries), baos);
|
|
|
|
|
byte[] bytes = baos.toByteArray();
|
|
|
|
|
try {
|
|
|
|
|
result = Base64.encodeToString(bytes, Base64.DEFAULT);
|
|
|
|
|
} catch (OutOfMemoryError e) {
|
|
|
|
|
// Too big, try after recompressing
|
|
|
|
|
}
|
|
|
|
|
tries++;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Bitmap decodeBase64Bitmap(String encoded) {
|
|
|
|
|
byte[] decodedByte = Base64.decode(encoded, 0);
|
|
|
|
|
return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int BUFFER_SIZE = 4096;
|
|
|
|
|
public static String encodeBase64File(File file) {
|
|
|
|
|
try {
|
|
|
|
|
FileInputStream in = new FileInputStream(file);
|
|
|
|
|
try {
|
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
|
|
byte[] buffer = new byte[BUFFER_SIZE];
|
|
|
|
|
int len = 0;
|
|
|
|
|
while ((len = in.read(buffer)) > 0) {
|
|
|
|
|
baos.write(buffer, 0, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] bytes = baos.toByteArray();
|
|
|
|
|
return Base64.encodeToString(bytes, Base64.DEFAULT);
|
|
|
|
|
} finally {
|
|
|
|
|
in.close();
|
|
|
|
|
}
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
return null;
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Start the given intent, handling security exceptions if they arise
|
|
|
|
|
*
|
|
|
|
|