1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-07-02 16:26:48 +02:00
dandelion/app/src/main/java/com/github/dfa/diaspora_android/util/ContextUtils.java

59 lines
2.1 KiB
Java
Raw Normal View History

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