2016-03-29 19:38:50 +02:00
|
|
|
package com.github.dfa.diaspora_android.util;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-08-07 23:37:02 +02:00
|
|
|
import android.content.Context;
|
2016-09-05 20:42:57 +02:00
|
|
|
import android.os.Bundle;
|
2016-08-27 12:34:08 +02:00
|
|
|
import android.os.Environment;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2017-05-29 19:05:37 +02:00
|
|
|
import com.github.dfa.diaspora_android.App;
|
2016-07-18 14:02:18 +02:00
|
|
|
|
2016-08-27 12:34:08 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.text.SimpleDateFormat;
|
2016-09-05 20:42:57 +02:00
|
|
|
import java.util.Arrays;
|
2016-08-27 12:34:08 +02:00
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2017-05-29 19:05:37 +02:00
|
|
|
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue"})
|
|
|
|
public class Helpers extends io.github.gsantner.opoc.util.Helpers {
|
|
|
|
protected Helpers(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Helpers get() {
|
|
|
|
return new Helpers(App.get());
|
2016-09-18 23:17:18 +02:00
|
|
|
}
|
|
|
|
|
2017-05-29 19:05:37 +02:00
|
|
|
public File createImageFile() throws IOException {
|
2016-08-27 12:34:08 +02:00
|
|
|
// Create an image file name
|
|
|
|
String timeStamp = new SimpleDateFormat("dd-MM-yy_HH-mm", Locale.getDefault()).format(new Date());
|
|
|
|
String imageFileName = "JPEG_" + timeStamp + "_";
|
2016-10-05 02:30:10 +02:00
|
|
|
AppLog.d(Helpers.class, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
|
2016-08-27 12:34:08 +02:00
|
|
|
File storageDir = Environment.getExternalStoragePublicDirectory(
|
|
|
|
Environment.DIRECTORY_PICTURES);
|
2016-09-18 23:17:18 +02:00
|
|
|
return new File(
|
2016-09-07 23:12:17 +02:00
|
|
|
imageFileName + /* prefix */
|
2016-09-18 23:17:18 +02:00
|
|
|
".jpg", /* suffix */
|
2016-09-07 23:12:17 +02:00
|
|
|
storageDir.getAbsolutePath() /* directory */
|
2016-08-27 12:34:08 +02:00
|
|
|
);
|
|
|
|
}
|
2016-08-27 16:40:16 +02:00
|
|
|
|
2017-05-29 19:05:37 +02:00
|
|
|
public void logBundle(Bundle savedInstanceState, String k) {
|
2016-09-18 23:17:18 +02:00
|
|
|
if (savedInstanceState != null) {
|
2016-09-05 20:42:57 +02:00
|
|
|
for (String key : savedInstanceState.keySet()) {
|
2017-05-29 19:05:37 +02:00
|
|
|
AppLog.d("Bundle", key + " is a key in the bundle " + k);
|
2016-09-05 20:42:57 +02:00
|
|
|
Object bun = savedInstanceState.get(key);
|
2016-09-18 23:17:18 +02:00
|
|
|
if (bun != null) {
|
2016-09-05 20:42:57 +02:00
|
|
|
if (bun instanceof Bundle) {
|
2017-05-29 19:05:37 +02:00
|
|
|
logBundle((Bundle) bun, k + "." + key);
|
2016-09-05 20:42:57 +02:00
|
|
|
} else if (bun instanceof byte[]) {
|
2017-05-29 19:05:37 +02:00
|
|
|
AppLog.d("Bundle", "Key: " + k + "." + key + ": " + Arrays.toString((byte[]) bun));
|
2016-09-05 20:42:57 +02:00
|
|
|
} else {
|
2017-05-29 19:05:37 +02:00
|
|
|
AppLog.d("Bundle", "Key: " + k + "." + key + ": " + bun.toString());
|
2016-09-05 20:42:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|