Skip to content

Commit

Permalink
- Additional options added for iOS
Browse files Browse the repository at this point in the history
- Fix share issue with SDK version 24 or above on Android
  • Loading branch information
Davaadorj committed May 24, 2018
1 parent 729ca8e commit 19029eb
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 69 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,23 @@ $ npm install --save @ionic-native/photo-viewer
PhotoViewer.show('http://my_site.com/my_image.jpg', 'Optional Title');
```

Optionally you can pass third parameter which can be used to hide the share button [ONLY FOR ANDROID]
Optionally you can pass third parameter option as object.

Options:
* share: Option is used to hide and show the share option.
* closeBtn: Option for close button visibility when share false [ONLY FOR iOS]
* copyToReference: If you need to copy image to reference before show then set it true [ONLY FOR iOS]

##### Usage

```
PhotoViewer.show('http://my_site.com/my_image.jpg', 'Optional Title', {share:false});
var options = {
share: true, // default is false
closeButton: false, // default is true
copyToReference: true // default is false
};
PhotoViewer.show('http://my_site.com/my_image.jpg', 'Optional Title', options);
```

### Versions
Expand Down Expand Up @@ -71,3 +82,7 @@ PhotoViewer.show('http://my_site.com/my_image.jpg', 'Optional Title', {share:fal

(1.1.9/10)
- Fix how image is shown on Android

(1.1.17)
- Additional options added for iOS
- Fix share issue with SDK version 24 or above on Android
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com-sarriaroman-photoviewer",
"version": "1.1.16",
"version": "1.1.17",
"description": "This plugin is intended to show a picture from an URL into a Photo Viewer with zoom features.",
"cordova": {
"id": "com-sarriaroman-photoviewer",
Expand All @@ -22,4 +22,4 @@
],
"author": "Román A. Sarria",
"license": "MIT"
}
}
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8' ?>
<plugin id="com-sarriaroman-photoviewer" version="1.1.16" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="com-sarriaroman-photoviewer" version="1.1.17" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>PhotoViewer</name>
<description>This plugin is intended to show a picture from an URL into a Photo Viewer with zoom features.</description>
<js-module name="PhotoViewer" src="www/PhotoViewer.js">
Expand Down
32 changes: 21 additions & 11 deletions src/android/PhotoActivity.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.sarriaroman.PhotoViewer;

import uk.co.senab.photoview.PhotoViewAttacher;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.util.Base64;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;

import android.content.Intent;
import android.net.Uri;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
Expand All @@ -24,11 +23,13 @@

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;

import uk.co.senab.photoview.PhotoViewAttacher;

public class PhotoActivity extends Activity {
private PhotoViewAttacher mAttacher;
Expand All @@ -43,7 +44,7 @@ public class PhotoActivity extends Activity {

private String mImage;
private String mTitle;
private JSONObject mOptions;
private boolean mShare;
private File mTempImage;
private int shareBtnVisibility;

Expand All @@ -61,13 +62,13 @@ protected void onCreate(Bundle savedInstanceState) {
try {
this.mImage = mArgs.getString(0);
this.mTitle = mArgs.getString(1);
this.mOptions = mArgs.getJSONObject(2);
this.mShare = mArgs.getBoolean(2);
//Set the share button visibility
shareBtnVisibility = mOptions.getBoolean("share") ? View.VISIBLE : View.INVISIBLE;
shareBtnVisibility = this.mShare ? View.VISIBLE : View.INVISIBLE;


} catch (JSONException exception) {
shareBtnVisibility = View.VISIBLE;
shareBtnVisibility = View.INVISIBLE;
}
shareBtn.setVisibility(shareBtnVisibility);
//Change the activity title
Expand All @@ -88,8 +89,17 @@ public void onClick(View v) {
shareBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT >= 24) {
try {
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
} catch (Exception e) {
e.printStackTrace();
}
}

Uri imageUri;
if (mTempImage == null){
if (mTempImage == null) {
mTempImage = getLocalBitmapFileFromView(photo);
}

Expand Down
14 changes: 6 additions & 8 deletions src/android/PhotoViewer.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.sarriaroman.PhotoViewer;

import org.apache.cordova.CordovaPlugin;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONException;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;

/**
* Class to Open PhotoViewer with the Required Parameters from Cordova
* <p>
Expand All @@ -37,8 +36,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo

boolean requiresExternalPermission = true;
try {
JSONObject options = this.args.optJSONObject(2);
requiresExternalPermission = options.getBoolean("share");
requiresExternalPermission = this.args.getBoolean(2);
} catch (JSONException exception) {
}

Expand Down
Loading

0 comments on commit 19029eb

Please # to comment.