Skip to content

Commit

Permalink
fix #161
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrupczak3 committed Aug 23, 2024
1 parent 0f98c4e commit fe38217
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
34 changes: 34 additions & 0 deletions app/src/main/java/com/openathena/AthenaActivity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
// }
Expand Down
29 changes: 2 additions & 27 deletions app/src/main/java/com/openathena/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/openathena/NewElevationMapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fe38217

Please sign in to comment.