Skip to content

Commit

Permalink
improve photo storage capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
ramack committed Dec 18, 2017
1 parent 53e7868 commit 4cd1b29
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".ActivityDiaryApplication">
android:name=".ActivityDiaryApplication"
android:installLocation="auto">
<activity android:name=".ui.main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,39 @@ public class GraphicsHelper {
/* list if recommended colors for new activites, populated from resources on startup */
public static ArrayList<Integer> activityColorPalette = new ArrayList<Integer>(19);

/* Checks if external storage is available for read and write */
public static boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}

public static File imageStorageDirectory(){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ActivityDiaryApplication.getAppContext());
File root = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
File directory;

if(isExternalStorageWritable()) {
directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
}else {
directory = ActivityDiaryApplication.getAppContext().getFilesDir();
}

File root = new File(directory,
sharedPreferences.getString("pref_storageFolder", "ActivityDiary"));

int permissionCheck = ContextCompat.checkSelfPermission(ActivityDiaryApplication.getAppContext(),
Manifest.permission.WRITE_EXTERNAL_STORAGE);

if(permissionCheck == PackageManager.PERMISSION_GRANTED) {
if(!root.exists()){
if( !root.mkdirs() ) {
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
if (!root.exists()) {
if (!root.mkdirs()) {
Log.e(TAG, "failed to create directory");
throw new RuntimeException("failed to create directory " + root.toString());
}
}
}else{
} else {
/* no permission, return null */
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@

<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="public_images" path="Pictures" />
<files-path name="private_images" path="/" />
</paths>

0 comments on commit 4cd1b29

Please sign in to comment.