Skip to content

Commit

Permalink
Merge pull request #75 from ngageoint/android14
Browse files Browse the repository at this point in the history
Android 14 updates
  • Loading branch information
jclark118 authored Nov 28, 2023
2 parents cb74a7e + 0a4be42 commit a2f45a9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.8.0'

repositories {
google()
Expand Down
7 changes: 4 additions & 3 deletions mapcache/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def googleMapsApiReleaseKey = hasProperty('RELEASE_MAPS_MAPCACHE_API_KEY') ? REL
def googleMapsApiKeyDebug = hasProperty('DEBUG_MAPS_API_KEY') ? DEBUG_MAPS_API_KEY : ''

android {
compileSdkVersion 33
compileSdkVersion 34

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
Expand All @@ -22,7 +22,7 @@ android {
resValue "string", "applicationId", applicationId
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
minSdkVersion 28
targetSdkVersion 33
targetSdkVersion 34
versionCode 60
versionName '2.1.11'
multiDexEnabled true
Expand Down Expand Up @@ -83,7 +83,8 @@ task androidAppVersion {

dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
api 'androidx.appcompat:appcompat:1.3.0'
api 'androidx.appcompat:appcompat:1.6.1'
api 'androidx.activity:activity:1.8.0'
api 'com.google.android.material:material:1.6.0'
api 'androidx.preference:preference:1.2.1'
api 'androidx.lifecycle:lifecycle-extensions:2.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ protected void onCreate(Bundle savedInstanceState) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// NavUtils.navigateUpFromSameTask(this);
onBackPressed();
super.getOnBackPressedDispatcher().onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.PickVisualMediaRequest;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
Expand Down Expand Up @@ -71,10 +72,15 @@ public class FeatureViewActivity extends AppCompatActivity {


/**
* Permission check
* Permission check for multiple
*/
public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 204;

/**
* Permission check for gallery usage
*/
public static final int REQUEST_ID_GALLERY_PERMISSIONS = 205;

/**
* We'll generate a list of FCObjects to hold our data for the recycler
*/
Expand Down Expand Up @@ -156,16 +162,19 @@ public class FeatureViewActivity extends AppCompatActivity {
private DeleteImageListener deleteImageListener;

/**
* result listener for selecting images from the gallery
* Result listener for selecting images from the gallery.
* Registers a photo picker activity launcher in single-select mode.
*/
private ActivityResultLauncher<String> getImageFromGallery = registerForActivityResult(new ActivityResultContracts.GetContent(),
new ActivityResultCallback<Uri>() {
@Override
public void onActivityResult(Uri uri) {
ActivityResultLauncher<PickVisualMediaRequest> getImageFromGallery =
registerForActivityResult(new ActivityResultContracts.PickVisualMedia(), uri -> {
// Callback is invoked after the user selects a media item or closes the
// photo picker.
if (uri != null) {
Log.d("PhotoPicker", "Selected URI: " + uri);
Bitmap image = getImageResult(uri);
if(image != null) {
addImageToGallery(image);
}
addImageToGallery(image);
} else {
Log.d("PhotoPicker", "No media selected");
}
});

Expand Down Expand Up @@ -252,8 +261,8 @@ protected void onCreate(Bundle savedInstanceState) {
*/
private void createImageGallery(){
if(imageGalleryPager != null && featureViewObjects != null){
for(Map.Entry map : featureViewObjects.getBitmaps().entrySet() ){
sliderItems.add(new SliderItem((long)map.getKey(),(Bitmap)map.getValue()));
for(Map.Entry<Long, Bitmap> map : featureViewObjects.getBitmaps().entrySet() ){
sliderItems.add(new SliderItem(map.getKey(),map.getValue()));
}
imageGalleryPager.setAdapter(sliderAdapter);
imageGalleryPager.setClipToPadding(false);
Expand Down Expand Up @@ -313,7 +322,7 @@ private void createButtonListeners(){
}
if(galleryButton != null) {
galleryButton.setOnClickListener(v -> {
if (checkAndRequestPermissions(FeatureViewActivity.this)) {
if (checkAndRequestGalleryPermissions(FeatureViewActivity.this)) {
addFromGallery();
}
});
Expand Down Expand Up @@ -419,8 +428,8 @@ private void updateImages(){
if(featureViewObjects != null){
sliderItems.clear();
featureViewObjects.getAddedBitmaps().clear();
for(Map.Entry map : featureViewObjects.getBitmaps().entrySet() ){
sliderItems.add(new SliderItem((long)map.getKey(),(Bitmap)map.getValue()));
for(Map.Entry<Long, Bitmap> map : featureViewObjects.getBitmaps().entrySet() ){
sliderItems.add(new SliderItem(map.getKey(),map.getValue()));
}
}
sliderAdapter.setData(sliderItems);
Expand Down Expand Up @@ -455,7 +464,10 @@ private void takePicture(){
* Open the phone's image gallery to add an image
*/
private void addFromGallery(){
getImageFromGallery.launch("image/*");
ActivityResultContracts.PickVisualMedia.VisualMediaType mediaType = (ActivityResultContracts.PickVisualMedia.VisualMediaType) ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE;
getImageFromGallery.launch(new PickVisualMediaRequest.Builder()
.setMediaType(mediaType)
.build());
}


Expand Down Expand Up @@ -550,6 +562,25 @@ public static boolean checkAndRequestPermissions(final Activity context) {
return true;
}

public static boolean checkAndRequestGalleryPermissions(final Activity context) {
int writeExternalPermission = ContextCompat.checkSelfPermission(context,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
List<String> listPermissionsNeeded = new ArrayList<>();
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q){
if (writeExternalPermission != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded
.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(context, listPermissionsNeeded
.toArray(new String[0]),
REQUEST_ID_GALLERY_PERMISSIONS);
return false;
}
return true;
}



/**
Expand All @@ -566,19 +597,22 @@ public void onRequestPermissionsResult(int requestCode, @NotNull String[] permis
"Camera permissions required", Toast.LENGTH_SHORT)
.show();
flagged = true;
} else {
takePicture();
}
}
if (requestCode == REQUEST_ID_GALLERY_PERMISSIONS) {
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
if (ContextCompat.checkSelfPermission(FeatureViewActivity.this,
if (ContextCompat.checkSelfPermission(FeatureViewActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(),
"Storage permissions required",
Toast.LENGTH_SHORT).show();
flagged = true;

}
flagged = true;
}
}
if(!flagged) {
takePicture();
if(!flagged){
addFromGallery();
}
}
}
Expand Down

0 comments on commit a2f45a9

Please sign in to comment.