Skip to content

Instantly share code, notes, and snippets.

@imgly-gists
imgly-gists / plugin.xml
Last active June 2, 2017 10:59
PhotoEditor SDK Cordova plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:rim="http://www.blackberry.com/ns/widgets"
id="cordova-plugin-pesdk" version="1.1.0">
<name>PESDK</name>
<description>PhotoEditor SDK Cordova Plugin</description>
<license>Apache 2.0</license>
<keywords>cordova,camera</keywords>
<repo>https://github.com/imgly/pesdk-cordova-demo.git</repo>
- (void)present:(CDVInvokedUrlCommand *)command {
if (self.lastCommand == nil) {
self.lastCommand = command;
PESDKConfiguration *configuration = [[PESDKConfiguration alloc] initWithBuilder:^(PESDKConfigurationBuilder * _Nonnull builder) {
// Customize the SDK to match your requirements:
// ...eg.:
// [builder setBackgroundColor:[UIColor whiteColor]];
}];
var PESDK = {
present: function(success, failure, options) {
cordova.exec(success, failure, "PESDK", "present", [options]);
}
};
module.exports = PESDK;
+ (void)initialize {
if (self == [PESDKPlugin self]) {
[PESDK unlockWithLicenseAt:[[NSBundle mainBundle] URLForResource:@"LICENSE_IOS" withExtension:nil]];
}
}
onDeviceReady: function() {
selectImageBtn = document.getElementById('js-selectImageBtn');
selectImageBtn.addEventListener('click', function() {
// TODO: Open PhotoEditor SDK
});
selectImageBtn.disabled = false;
}
onDeviceReady: function() {
selectImageBtn = document.getElementById('js-selectImageBtn');
selectImageBtn.addEventListener('click', function() {
window.imagePicker.getPictures(
function(results) {
let imageURI = results[0];
PESDK.present(
function(result){ alert('PESDK result: ' + JSON.stringify(result)); },
function(error){ alert('PESDK error: ' + error); },
{ path: imageURI }
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
PESDK.init(cordova.getActivity().getApplication(), "LICENSE_ANDROID");
}
private Runnable present(final Activity mainActivity, final String filepath, final CallbackContext callbackContext) {
callback = callbackContext;
final PESDKPlugin self = this;
return new Runnable() {
public void run() {
if (mainActivity != null) {
SettingsList settingsList = new SettingsList();
settingsList
.getSettingsModel(EditorLoadSettings.class)
.setImageSourcePath(filepath.replace("file://", ""), true) // Load with delete protection true!
func spriteEditControllerPreviewView(_ spriteEditController: SpriteEditController) -> UIView? {
return self.previewViewController?.previewView
}
func stickerSelectionController(_ stickerSelectionController: StickerSelectionController, didSelect sticker: Sticker, with image: UIImage) {
guard let referenceSize = delegate?.stickerViewControllerReferenceSize(self) else { return }
var model = StickerSpriteModel(sticker: sticker)
let aspectRatio = referenceSize.width / referenceSize.height
model.normalizedCenter = CGPoint(x: 0.5, y: 0.5)
model.normalizedSize = CGSize(width: 0.3, height: 0.3 * aspectRatio)
delegate?.stickerViewControllerDidFinish(self, stickerModel: model)
dismiss(animated: true, completion: nil)
}