Skip to content

Commit

Permalink
Telerik-Verified-Plugins#2 Support for iCloud photos on iOS - modific…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
EddyVerbruggen committed Oct 29, 2015
1 parent b88f710 commit 3900d47
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 157 deletions.
53 changes: 53 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<head>
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>ImagePicker demo</title>
</head>
<body>
<div class="app">
<h1>ImagePicker demo</h1>

<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>

<p class="event received">Device is Ready</p>
<button onclick="getPics()">get pics</button>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script>
function getPics() {
imagePicker.getPictures(
function (result) {
var content = '';
for (var i = 0; i < result.length; i++) {
content += '<img src="' + result[i] + '" style="max-width:200px"/>';
//content += '<img src="data:image/jpg;base64,'+result[i]+'" style="max-width:200px"/>';
}
document.getElementById("imageOutput").innerHTML = content;
}, function (error) {
alert('Error: ' + error);
}, {
// if no title is passed, the plugin should use a sane default (preferrably the same as it was, so check the old one.. there are screenshots in the marketplace doc)
maximumImagesCount: 10,
title: 'Select pix',
message: 'Pick max 10 items', // optional default no helper message above the picker UI
// be careful with these options as they require additional processing
width: 400,
quality: 80
// outputType: imagePicker.OutputType.BASE64_STRING
}
);
}
</script>

<div id="imageOutput">
</div>

</body>
</html>
25 changes: 12 additions & 13 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<license>MIT</license>

<engines>
<engine name="cordova" version=">=3.0.0" />
<engine name="cordova" version=">=3.5.0" />
</engines>

<js-module src="www/imagepicker.js" name="ImagePicker">
Expand All @@ -31,8 +31,8 @@
<header-file src="src/ios/SOSPicker.h" />
<source-file src="src/ios/SOSPicker.m" />

<header-file src="src/ios/GMImagePicker/UIImage+fixOrientation.h" />
<source-file src="src/ios/GMImagePicker/UIImage+fixOrientation.m" />
<header-file src="src/ios/GMImagePicker/UIImage+fixOrientation.h" />
<source-file src="src/ios/GMImagePicker/UIImage+fixOrientation.m" />

<header-file src="src/ios/GMImagePicker/GMAlbumsViewCell.h" />
<source-file src="src/ios/GMImagePicker/GMAlbumsViewCell.m" />
Expand Down Expand Up @@ -76,6 +76,9 @@
<asset src="src/ios/GMImagePicker/it.lproj/GMImagePicker.strings" target="res/strings-it/GMImagePicker.strings" />
<asset src="src/ios/GMImagePicker/pt.lproj/GMImagePicker.strings" target="res/strings-pt/GMImagePicker.strings" />

<!-- NOTE that MRProgress (and its dependency AFNetworking) have been added for a semi-useful
progress indicator. We may remove that if we have trouble with these files for some reason. -->

<!-- AF Networking -->
<source-file src="src/ios/GMImagePicker/AFNetworking/LICENSE" target-dir="resources/AFNetworking" />
<source-file src="src/ios/GMImagePicker/AFNetworking/README.md" target-dir="resources/AFNetworking" />
Expand Down Expand Up @@ -187,11 +190,11 @@
<header-file src="src/ios/GMImagePicker/mrprogress/Utils/MRWeakProxy.h" target-dir="mrprogress" />
<source-file src="src/ios/GMImagePicker/mrprogress/Utils/MRWeakProxy.m" target-dir="mrprogress" />

<framework src="Accelerate.framework" />
<framework src="Security.framework" />
<framework src="Photos.framework" />
<framework src="SystemConfiguration.framework" />
<framework src="QuartzCore.framework" />
<framework src="Accelerate.framework" />
<framework src="Security.framework" />
<framework src="Photos.framework" />
<framework src="SystemConfiguration.framework" />
<framework src="QuartzCore.framework" />

</platform>

Expand All @@ -217,8 +220,7 @@

<source-file src="src/android/Library/src/ImageFetcher.java" target-dir="src/com/synconset"/>
<source-file src="src/android/Library/src/MultiImageChooserActivity.java" target-dir="src/com/synconset"/>
<source-file src="src/android/Library/src/FileNameItem.java" target-dir="src/com/synconset"/>


<source-file src="src/android/Library/res/anim/image_pop_in.xml" target-dir="res/anim"/>
<source-file src="src/android/Library/res/drawable/grid_background.xml" target-dir="res/drawable"/>
<source-file src="src/android/Library/res/drawable-hdpi/image_bg.9.png" target-dir="res/drawable-hdpi"/>
Expand Down Expand Up @@ -248,8 +250,5 @@
<source-file src="src/android/Library/res/values-ko/multiimagechooser_strings_ko.xml" target-dir="res/values-ko"/>

<framework src="src/android/ignorelinterrors.gradle" custom="true" type="gradleReference"/>

<source-file src="src/android/Library/libs/commons-io-2.4.jar" target-dir="libs" />
<source-file src="src/android/Library/libs/gson-2.3.1.jar" target-dir="libs" />
</platform>
</plugin>
72 changes: 34 additions & 38 deletions src/android/Library/src/MultiImageChooserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Base64;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.Display;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -105,7 +104,7 @@ public class MultiImageChooserActivity extends Activity implements OnItemClickLi

private int maxImages;
private int maxImageCount;

private int desiredWidth;
private int desiredHeight;
private int quality;
Expand All @@ -117,9 +116,9 @@ public class MultiImageChooserActivity extends Activity implements OnItemClickLi

private int selectedColor = 0xff32b2e1;
private boolean shouldRequestThumb = true;

private FakeR fakeR;

private ProgressDialog progress;

@Override
Expand All @@ -138,7 +137,7 @@ public void onCreate(Bundle savedInstanceState) {

Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();

colWidth = width / 4;

gridView = (GridView) findViewById(fakeR.getId("id", "gridview"));
Expand Down Expand Up @@ -181,7 +180,7 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
progress.setTitle("Processing Images");
progress.setMessage("This may take a few moments");
}

@Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
String name = getImageName(position);
Expand All @@ -197,7 +196,7 @@ public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
builder.setTitle("Maximum " + maxImageCount + " Photos");
builder.setMessage("You can only select " + maxImageCount + " photos at a time.");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
Expand Down Expand Up @@ -290,7 +289,7 @@ public void onLoaderReset(Loader<Cursor> loader) {
actualimagecursor = null;
}
}

public void cancelClicked(View ignored) {
setResult(RESULT_CANCELED);
finish();
Expand All @@ -309,8 +308,8 @@ public void selectClicked(View ignored) {
new ResizeImagesTask().execute(fileNames.entrySet());
}
}


/*********************
* Helper Methods
********************/
Expand Down Expand Up @@ -375,7 +374,7 @@ private String getImageName(int position) {
}
return name;
}

private int getImageRotation(int position) {
actualimagecursor.moveToPosition(position);
int rotation = 0;
Expand All @@ -387,13 +386,13 @@ private int getImageRotation(int position) {
}
return rotation;
}

public boolean isChecked(int position) {
boolean ret = checkStatus.get(position);
return ret;
}


/*********************
* Nested Classes
********************/
Expand All @@ -407,8 +406,8 @@ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
}


private class ImageAdapter extends BaseAdapter {
private final Bitmap mPlaceHolderBitmap;

Expand Down Expand Up @@ -465,14 +464,14 @@ public View getView(int pos, View convertView, ViewGroup parent) {
if (android.os.Build.VERSION.SDK_INT>=16) {
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);
} else {
imageView.setAlpha(255);
imageView.setAlpha(255);
}
imageView.setBackgroundColor(Color.TRANSPARENT);
}
Expand All @@ -483,8 +482,8 @@ public View getView(int pos, View convertView, ViewGroup parent) {
return imageView;
}
}


private class ResizeImagesTask extends AsyncTask<Set<Entry<String, Integer>>, Void, ArrayList<String>> {
private Exception asyncTaskError = null;

Expand Down Expand Up @@ -544,7 +543,7 @@ protected ArrayList<String> doInBackground(Set<Entry<String, Integer>>... fileSe

if(outputType == OutputType.FILE_URI) {
file = this.storeImage(bmp, file.getName());
al.add(Uri.fromFile(file).toString());
al.add(Uri.fromFile(file).toString());
} else if (outputType == OutputType.BASE64_STRING){
al.add(getBase64OfImage(bmp));
}
Expand All @@ -558,14 +557,12 @@ protected ArrayList<String> doInBackground(Set<Entry<String, Integer>>... fileSe
File file = new File(uri);
file.delete();
}
} catch(Exception exception) {
// the finally does what we want to do
} finally {
return new ArrayList<String>();
} catch(Exception ignore) {
}
return new ArrayList<String>();
}
}

@Override
protected void onPostExecute(ArrayList<String> al) {
Intent data = new Intent();
Expand Down Expand Up @@ -612,11 +609,11 @@ private Bitmap tryToGetBitmap(File file, BitmapFactory.Options options, int rota
}
return bmp;
}

/*
* 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.
Expand All @@ -637,7 +634,7 @@ private File storeImage(Bitmap bmp, String fileName) throws IOException {
outStream.close();
return file;
}

private Bitmap getResizedBitmap(Bitmap bm, float factor) {
int width = bm.getWidth();
int height = bm.getHeight();
Expand All @@ -646,43 +643,42 @@ private Bitmap getResizedBitmap(Bitmap bm, float factor) {
// resize the bit map
matrix.postScale(factor, factor);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
return resizedBitmap;
return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
}

private String getBase64OfImage(Bitmap bm) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, quality, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();
return Base64.encodeToString(byteArray, Base64.DEFAULT);
}
}

private int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;

// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}

return inSampleSize;
}

private int calculateNextSampleSize(int sampleSize) {
double logBaseTwo = (int)(Math.log(sampleSize) / Math.log(2));
return (int)Math.pow(logBaseTwo + 1, 2);
}

private float calculateScale(int width, int height) {
float widthScale = 1.0f;
float heightScale = 1.0f;
Expand All @@ -706,7 +702,7 @@ private float calculateScale(int width, int height) {
}
}
}

return scale;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ios/GMImagePicker/GMGridViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ - (id)initWithFrame:(CGRect)frame
_fetch.textColor = titleColor;
_fetch.textAlignment = NSTextAlignmentCenter;
_fetch.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
_fetch.text = @"fetching";
_fetch.text = @""; // removed 'fetching'
[self addSubview:_fetch];

}
Expand Down
3 changes: 2 additions & 1 deletion src/ios/GMImagePicker/GMGridViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

fetch_item.be_saving_img_thumb = false;


// TODO pass in quality
if ( ![ UIImageJPEGRepresentation(result, 1.0f ) writeToFile:filePath atomically:YES ] ) {
return;
}
Expand Down
Loading

0 comments on commit 3900d47

Please sign in to comment.