From fe38217df3fc8861d689fabcf91f4f81ecb4b76b Mon Sep 17 00:00:00 2001 From: mkrupczak3 Date: Thu, 22 Aug 2024 20:38:49 -0400 Subject: [PATCH] fix #161 --- .../java/com/openathena/AthenaActivity.java | 34 +++++++++++++++++++ .../java/com/openathena/MainActivity.java | 29 ++-------------- .../openathena/NewElevationMapActivity.java | 6 ++++ 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/openathena/AthenaActivity.java b/app/src/main/java/com/openathena/AthenaActivity.java index 8379314..8d3d3cd 100644 --- a/app/src/main/java/com/openathena/AthenaActivity.java +++ b/app/src/main/java/com/openathena/AthenaActivity.java @@ -1,19 +1,23 @@ package com.openathena; +import android.Manifest; import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.exifinterface.media.ExifInterface; +import android.content.pm.PackageManager; import android.database.Cursor; import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.preference.PreferenceManager; @@ -25,6 +29,7 @@ import android.widget.RadioGroup; import android.widget.SeekBar; import android.widget.TextView; +import android.widget.Toast; import org.apache.commons.lang3.StringUtils; @@ -306,6 +311,35 @@ public double calculateCompassCorrectionOffset(int seekBarValue) { return offset; } + protected void requestExternStorage() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + if (checkSelfPermission(android.Manifest.permission.READ_MEDIA_IMAGES) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[] {Manifest.permission.READ_MEDIA_IMAGES}, requestNo); + } + requestNo++; + } else { + if (checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED) { + // Permission is not granted + Log.d(TAG, "Attempting to Obtain unobtained permission READ_EXTERNAL_STORAGE"); + requestPermissions(new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, requestNo); + requestNo++; + } + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, + @NonNull String[] permissions, + @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + Toast.makeText(AthenaActivity.this, getString(R.string.permissions_toast_success_msg), Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(AthenaActivity.this, getString(R.string.permissions_toast_error_msg), Toast.LENGTH_SHORT).show(); + } + } + // public static int get_selection_x() { // return athenaApp.get_selection_x(); // } diff --git a/app/src/main/java/com/openathena/MainActivity.java b/app/src/main/java/com/openathena/MainActivity.java index caf1a36..43bd272 100644 --- a/app/src/main/java/com/openathena/MainActivity.java +++ b/app/src/main/java/com/openathena/MainActivity.java @@ -602,17 +602,7 @@ public boolean onCreateOptionsMenu(Menu menu) { return true; } - @Override - public void onRequestPermissionsResult(int requestCode, - @NonNull String[] permissions, - @NonNull int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - Toast.makeText(MainActivity.this, getString(R.string.permissions_toast_success_msg), Toast.LENGTH_SHORT).show(); - } else { - Toast.makeText(MainActivity.this, getString(R.string.permissions_toast_error_msg), Toast.LENGTH_SHORT).show(); - } - } + @Override protected void onDestroy() @@ -1140,22 +1130,7 @@ public void selectImage(View view) // // } - private void requestExternStorage() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - if (checkSelfPermission(Manifest.permission.READ_MEDIA_IMAGES) != PackageManager.PERMISSION_GRANTED) { - requestPermissions(new String[] {Manifest.permission.READ_MEDIA_IMAGES}, requestNo); - } - requestNo++; - } else { - if (checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) - != PackageManager.PERMISSION_GRANTED) { - // Permission is not granted - Log.d(TAG, "Attempting to Obtain unobtained permission READ_EXTERNAL_STORAGE"); - requestPermissions(new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, requestNo); - requestNo++; - } - } - } + private static String roundDouble(double d) { DecimalFormatSymbols decimalSymbols = DecimalFormatSymbols.getInstance(); diff --git a/app/src/main/java/com/openathena/NewElevationMapActivity.java b/app/src/main/java/com/openathena/NewElevationMapActivity.java index d54b3ae..14477e7 100644 --- a/app/src/main/java/com/openathena/NewElevationMapActivity.java +++ b/app/src/main/java/com/openathena/NewElevationMapActivity.java @@ -60,6 +60,9 @@ protected void onCreate(Bundle savedInstanceState) setContentView(R.layout.activity_new_dem); demDir = new File(getCacheDir(), "DEMs"); + if (!demDir.exists()) { + demDir.mkdirs(); + } instructionsLabel = (TextView)findViewById(R.id.new_dem_label); getPosGPSButton = (ImageButton) findViewById(R.id.get_pos_gps_button); @@ -298,6 +301,9 @@ public void run() { private void onClickImport() { Log.d(TAG,"NewElevationMapActivity: going to pick a file to import"); + + requestExternStorage(); + // launch and give it .tiff as a restriction? // launcher takes mime-types; here are a few options // image/tiff -- just tiff files