Skip to content

Commit

Permalink
Removing Android Support library
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekriskovich committed Jul 17, 2024
1 parent 1d24ee5 commit acf6e08
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 63 deletions.
4 changes: 1 addition & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@

<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
</config-file>

<preference name="ANDROID_SUPPORT_V7_VERSION" default="27.+"/>
<framework src="com.android.support:appcompat-v7:$ANDROID_SUPPORT_V7_VERSION" />

<source-file src="src/android/com/synconset/ImagePicker/ImagePicker.java" target-dir="src/com/synconset" />
<source-file src="src/android/com/synconset/ImagePicker/FakeR.java" target-dir="src/com/synconset" />
<source-file src="src/android/com/synconset/ImagePicker/ResultIPC.java" target-dir="src/com/synconset" />
Expand Down
127 changes: 73 additions & 54 deletions src/android/Library/src/MultiImageChooserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDIN G NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDIN G NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE
*
* Code modified by Andrew Stephan for Sync OnSet
Expand All @@ -30,6 +30,7 @@

package com.synconset;

import java.io.InputStream;
import java.net.URI;
import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down Expand Up @@ -62,8 +63,8 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.ActionBar;
import android.util.Base64;
import android.util.SparseBooleanArray;
import android.view.Display;
Expand Down Expand Up @@ -218,9 +219,9 @@ public void onClick(DialogInterface dialog, int which) {
ImageView imageView = (ImageView) view;

if (android.os.Build.VERSION.SDK_INT >= 16) {
imageView.setImageAlpha(128);
imageView.setImageAlpha(128);
} else {
imageView.setAlpha(128);
imageView.setAlpha(128);
}

view.setBackgroundColor(selectedColor);
Expand Down Expand Up @@ -424,12 +425,12 @@ public boolean isChecked(int position) {


/*********************
* Nested Classes
********************/
* Nested Classes
********************/
private class SquareImageView extends ImageView {
public SquareImageView(Context context) {
super(context);
}
super(context);
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Expand Down Expand Up @@ -481,18 +482,18 @@ public View getView(int position, View convertView, ViewGroup parent) {

if (isChecked(position)) {
if (android.os.Build.VERSION.SDK_INT >= 16) {
imageView.setImageAlpha(128);
imageView.setImageAlpha(128);
} else {
imageView.setAlpha(128);
imageView.setAlpha(128);
}

imageView.setBackgroundColor(selectedColor);

} else {
if (android.os.Build.VERSION.SDK_INT >= 16) {
imageView.setImageAlpha(255);
imageView.setImageAlpha(255);
} else {
imageView.setAlpha(255);
imageView.setAlpha(255);
}
imageView.setBackgroundColor(Color.TRANSPARENT);
}
Expand Down Expand Up @@ -522,7 +523,17 @@ protected ArrayList<String> doInBackground(Set<Entry<String, Integer>>... fileSe
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getAbsolutePath(), options);

InputStream is = null;
try {
is = getContentResolver().openInputStream(Uri.fromFile(file));
BitmapFactory.decodeStream(is, null, options);
} finally {
if (is != null) {
is.close();
}
}

int width = options.outWidth;
int height = options.outHeight;
float scale = calculateScale(width, height);
Expand Down Expand Up @@ -624,40 +635,48 @@ private Bitmap tryToGetBitmap(File file,
BitmapFactory.Options options,
int rotate,
boolean shouldScale) throws IOException, OutOfMemoryError {
Bitmap bmp;
if (options == null) {
bmp = BitmapFactory.decodeFile(file.getAbsolutePath());
} else {
bmp = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
}
InputStream is = null;
try {
is = getContentResolver().openInputStream(Uri.fromFile(file));
Bitmap bmp;
if (options == null) {
bmp = BitmapFactory.decodeStream(is);
} else {
bmp = BitmapFactory.decodeStream(is, null, options);
}

if (bmp == null) {
throw new IOException("The image file could not be opened.");
}
if (bmp == null) {
throw new IOException("The image file could not be opened.");
}

if (options != null && shouldScale) {
float scale = calculateScale(options.outWidth, options.outHeight);
bmp = this.getResizedBitmap(bmp, scale);
}
if (options != null && shouldScale) {
float scale = calculateScale(options.outWidth, options.outHeight);
bmp = this.getResizedBitmap(bmp, scale);
}

if (rotate != 0) {
Matrix matrix = new Matrix();
matrix.setRotate(rotate);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}
if (rotate != 0) {
Matrix matrix = new Matrix();
matrix.setRotate(rotate);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}

return bmp;
return bmp;
} finally {
if (is != null) {
is.close();
}
}
}

/*
* The following functions are originally from
* https://github.com/raananw/PhoneGap-Image-Resizer
*
* They have been modified by Andrew Stephan for Sync OnSet
*
* The software is open source, MIT Licensed.
* Copyright (C) 2012, webXells GmbH All Rights Reserved.
*/
* The following functions are originally from
* https://github.com/raananw/PhoneGap-Image-Resizer
*
* They have been modified by Andrew Stephan for Sync OnSet
*
* The software is open source, MIT Licensed.
* Copyright (C) 2012, webXells GmbH All Rights Reserved.
*/
private File storeImage(Bitmap bmp, String fileName) throws IOException {
int index = fileName.lastIndexOf('.');
String name = fileName.substring(0, index);
Expand Down Expand Up @@ -687,7 +706,7 @@ private Bitmap getResizedBitmap(Bitmap bm, float factor) {
return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
}

private String getBase64OfImage(Bitmap bm) {
private String getBase64OfImage(Bitmap bm) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, quality, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
Expand Down
16 changes: 10 additions & 6 deletions src/android/com/synconset/ImagePicker/ImagePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class ImagePicker extends CordovaPlugin {

Expand Down Expand Up @@ -77,13 +77,13 @@ public boolean execute(String action, final JSONArray args, final CallbackContex
// some day, when everybody uses a cordova version supporting 'hasPermission', enable this:
/*
if (cordova != null) {
if (cordova.hasPermission(Manifest.permission.READ_EXTERNAL_STORAGE)) {
if (cordova.hasPermission(Manifest.permission.READ_MEDIA_IMAGES)) {
cordova.startActivityForResult(this, imagePickerIntent, 0);
} else {
cordova.requestPermission(
this,
PERMISSION_REQUEST_CODE,
Manifest.permission.READ_EXTERNAL_STORAGE
Manifest.permission.READ_MEDIA_IMAGES
);
}
}
Expand All @@ -102,18 +102,22 @@ public boolean execute(String action, final JSONArray args, final CallbackContex
return false;
}

private String getMediaPermissionName() {
return Build.VERSION.SDK_INT >= 33 ? Manifest.permission.READ_MEDIA_IMAGES : Manifest.permission.READ_EXTERNAL_STORAGE;
}

@SuppressLint("InlinedApi")
private boolean hasReadPermission() {
return Build.VERSION.SDK_INT < 23 ||
PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(this.cordova.getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE);
PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(this.cordova.getActivity(), this.getMediaPermissionName());
}

@SuppressLint("InlinedApi")
private void requestReadPermission() {
if (!hasReadPermission()) {
ActivityCompat.requestPermissions(
this.cordova.getActivity(),
new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},
new String[] {this.getMediaPermissionName()},
PERMISSION_REQUEST_CODE);
}
// This method executes async and we seem to have no known way to receive the result
Expand Down

0 comments on commit acf6e08

Please sign in to comment.