Skip to content

Commit

Permalink
Adding picasso options
Browse files Browse the repository at this point in the history
  • Loading branch information
Román A. Sarria committed Jan 9, 2019
1 parent ed71cfe commit 6ee2ff8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ PhotoViewer.show('http://my_site.com/my_image.jpg', 'Optional Title', options);
(1.1.17)
- Additional options added for iOS
- Fix share issue with SDK version 24 or above on Android

(1.1.9)
- Support for Headers
- Enable or Disable Picasso Options ( Only Android ): fit, centerInside, centerCrop.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com-sarriaroman-photoviewer",
"version": "1.1.18",
"version": "1.1.19",
"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 Down
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.18" 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.19" 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: 25 additions & 7 deletions src/android/PhotoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class PhotoActivity extends Activity {
private String mTitle;
private boolean mShare;
private JSONObject mHeaders;
private JSONObject pOptions;
private File mTempImage;
private int shareBtnVisibility;

Expand All @@ -70,6 +71,7 @@ protected void onCreate(Bundle savedInstanceState) {
this.mTitle = mArgs.getString(1);
this.mShare = mArgs.getBoolean(2);
this.mHeaders = parseHeaders(mArgs.getString(5));
this.pOptions = mArgs.getJSONObject(6);

//Set the share button visibility
shareBtnVisibility = this.mShare ? View.VISIBLE : View.INVISIBLE;
Expand Down Expand Up @@ -164,6 +166,22 @@ private void hideLoadingAndUpdate() {
mAttacher.update();
}

private Piccasso setOptions(Piccasso picasso) throws JSONException {
if(this.pOptions.has("fit") && this.pOptions.optBoolean("fit")) {
picasso.fit();
}

if(this.pOptions.has("centerInside") && this.pOptions.optBoolean("centerInside")) {
picasso.centerInside();
}

if(this.pOptions.has("centerCrop") && this.pOptions.optBoolean("centerCrop")) {
picasso.centerCrop();
}

return picasso;
}

/**
* Load the image using Picasso
*/
Expand All @@ -176,9 +194,9 @@ private void loadImage() {
picasso = getImageLoader(this);
}

picasso.load(mImage)
.fit()
.centerInside()
picasso.load(mImage);

this.setOptions(picasso)
.into(photo, new com.squareup.picasso.Callback() {
@Override
public void onSuccess() {
Expand All @@ -203,10 +221,10 @@ protected File doInBackground(Void... params) {

protected void onPostExecute(File file) {
mTempImage = file;
Picasso.with(PhotoActivity.this)
.load(mTempImage)
.fit()
.centerCrop()
Piccasso picasso = Picasso.with(PhotoActivity.this)
.load(mTempImage);

this.setOptions(picasso)
.into(photo, new com.squareup.picasso.Callback() {
@Override
public void onSuccess() {
Expand Down
12 changes: 11 additions & 1 deletion www/PhotoViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ exports.show = function(url, title, options) {
options.headers = '';
}

var args = [url, title, options.share, options.closeButton, options.copyToReference, options.headers];
var piccasoOptions = {
fit: true,
centerInside: true,
centerCrop: false
};

if(options.picassoOptions) {
piccasoOptions = Object.assign(piccasoOptions, options.picassoOptions);
}

var args = [url, title, options.share, options.closeButton, options.copyToReference, options.headers, picassoOptions];

exec(function() {}, function() {}, "PhotoViewer", "show", args);
};

0 comments on commit 6ee2ff8

Please # to comment.