Sharebutton vollständig implementiert.

This commit is contained in:
2016-02-03 16:15:27 +01:00
parent 4fdd18bb11
commit 4439b7320c
53 changed files with 3831 additions and 129 deletions

View File

@@ -31,7 +31,7 @@
<file leaf-file-name="AndroidManifest.xml" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/AndroidManifest.xml">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-10.88">
<state vertical-scroll-proportion="0.0">
<caret line="16" column="0" selection-start-line="16" selection-start-column="0" selection-end-line="16" selection-end-column="0" />
<folding />
</state>
@@ -66,7 +66,7 @@
<entry file="file://$PROJECT_DIR$/assets/www/js/controllers.js">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="452" column="0" selection-start-line="452" selection-start-column="0" selection-end-line="452" selection-end-column="0" />
<caret line="477" column="0" selection-start-line="477" selection-start-column="0" selection-end-line="477" selection-end-column="0" />
<folding />
</state>
</provider>
@@ -1264,7 +1264,7 @@
</option>
<option name="modificationStamps">
<map>
<entry key="$PROJECT_DIR$" value="5817827086448" />
<entry key="$PROJECT_DIR$" value="5817832518370" />
</map>
</option>
<option name="projectBuildClasspath">
@@ -1680,46 +1680,6 @@
<option name="myItemType" value="com.android.tools.idea.navigator.nodes.AndroidViewProjectNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="android" />
<option name="myItemType" value="com.android.tools.idea.navigator.nodes.AndroidViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="android" />
<option name="myItemType" value="com.android.tools.idea.navigator.nodes.AndroidModuleNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="assets" />
<option name="myItemType" value="com.android.tools.idea.navigator.nodes.AndroidSourceTypeNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="www" />
<option name="myItemType" value="com.android.tools.idea.navigator.nodes.AndroidPsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="android" />
<option name="myItemType" value="com.android.tools.idea.navigator.nodes.AndroidViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="android" />
<option name="myItemType" value="com.android.tools.idea.navigator.nodes.AndroidModuleNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="assets" />
<option name="myItemType" value="com.android.tools.idea.navigator.nodes.AndroidSourceTypeNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="www" />
<option name="myItemType" value="com.android.tools.idea.navigator.nodes.AndroidPsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="js" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="android" />
@@ -1893,7 +1853,7 @@
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1696" height="922" extended-state="6" />
<editor active="true" />
<editor active="false" />
<layout>
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Messages" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.57310706" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
@@ -1978,15 +1938,7 @@
<entry file="file://$PROJECT_DIR$/assets/www/js/controllers.js">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="452" column="0" selection-start-line="452" selection-start-column="0" selection-end-line="452" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/AndroidManifest.xml">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-10.88">
<caret line="16" column="0" selection-start-line="16" selection-start-column="0" selection-end-line="16" selection-end-column="0" />
<caret line="477" column="0" selection-start-line="477" selection-start-column="0" selection-end-line="477" selection-end-column="0" />
<folding />
</state>
</provider>
@@ -1999,6 +1951,14 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/AndroidManifest.xml">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="16" column="0" selection-start-line="16" selection-start-column="0" selection-end-line="16" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/org/apache/cordova/inappbrowser/InAppBrowser.java">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.8160535">

View File

@@ -20,7 +20,7 @@
"/*": [
{
"xml": "<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" />",
"count": 2
"count": 3
}
]
}
@@ -71,6 +71,10 @@
{
"xml": "<feature name=\"sqlDB\"><param name=\"android-package\" value=\"me.rahul.plugins.sqlDB.sqlDB\" /></feature>",
"count": 1
},
{
"xml": "<feature name=\"SocialSharing\"><param name=\"android-package\" value=\"nl.xservices.plugins.SocialSharing\" /></feature>",
"count": 1
}
]
}
@@ -134,6 +138,9 @@
},
"me.rahul.plugins.sqlDB": {
"PACKAGE_NAME": "com.raataar.wolle_rosen_kaufen"
},
"cordova-plugin-x-socialsharing": {
"PACKAGE_NAME": "com.raataar.wolle_rosen_kaufen"
}
},
"dependent_plugins": {},
@@ -360,6 +367,13 @@
"clobbers": [
"window.plugins.sqlDB"
]
},
{
"file": "plugins/cordova-plugin-x-socialsharing/www/SocialSharing.js",
"id": "cordova-plugin-x-socialsharing.SocialSharing",
"clobbers": [
"window.plugins.socialsharing"
]
}
]
}

View File

@@ -222,6 +222,13 @@ module.exports = [
"clobbers": [
"window.plugins.sqlDB"
]
},
{
"file": "plugins/cordova-plugin-x-socialsharing/www/SocialSharing.js",
"id": "cordova-plugin-x-socialsharing.SocialSharing",
"clobbers": [
"window.plugins.socialsharing"
]
}
];
module.exports.metadata =

View File

@@ -375,8 +375,6 @@ $scope.show = function() {
* Rosen konsuieren ENDE
*/
})
.controller('BuysCtrl', function($scope, $database,$location,$ionicModal,$ionicLoading,$timeout,$cordovaFile,$ionicPopup) {
@@ -390,17 +388,19 @@ $scope.show = function() {
function fill_list(){
$scope.items=[];
$database.getAllBuys().then(function (result) {
if(result.length>0){
for(i=0;i<result.length;i++){
$scope.items.push(result[i]);
}
} else {
$scope.items=[];
$scope.items=[];
$database.getAllBuys().then(function (result) {
if(result.length>0){
for(i=0;i<result.length;i++){
$scope.items.push(result[i]);
}
});
$scope.hide($ionicLoading);
}
else {
$scope.items=[];
}
});
$scope.hide($ionicLoading);
}
@@ -452,16 +452,42 @@ $scope.show = function() {
});
}
$scope.showImages = function(imagesrc) {
$scope.showImages = function(imagesrc,imagefile) {
//Sicherstellen, das Bild im Publicfolder vorhanden ist
$cordovaFile.copyFile(cordova.file.applicationStorageDirectory, imagefile, cordova.file.externalRootDirectory + "/WolleRosenKaufen", imagefile)
.then(function (success) {
// success
}, function (error) {
// error
});
//Bild im dialog anzeigen
$scope.imagesrc=imagesrc;
$scope.showModal('templates/image-popover.html');
}
$scope.shareimage = function(imagesrc,imagefile) {
//Sicherstellen, das Bild im Publicfolder vorhanden ist
$cordovaFile.copyFile(cordova.file.applicationStorageDirectory, imagefile, cordova.file.externalRootDirectory + "/WolleRosenKaufen", imagefile)
.then(function (success) {
// success
}, function (error) {
// error
});
//Bild im dialog anzeigen
$scope.imagesrc=imagesrc;
window.plugins.socialsharing.share(null, null, $scope.imagesrc, null);
}
$scope.showModal = function(templateUrl) {
$ionicModal.fromTemplateUrl(templateUrl, {
scope: $scope,

View File

@@ -0,0 +1,122 @@
cordova.define("cordova-plugin-x-socialsharing.SocialSharing", function(require, exports, module) {
var cordova = require('cordova');
function SocialSharing() {
}
// Override this method (after deviceready) to set the location where you want the iPad popup arrow to appear.
// If not overridden with different values, the popup is not used. Example:
//
// window.plugins.socialsharing.iPadPopupCoordinates = function() {
// return "100,100,200,300";
// };
SocialSharing.prototype.iPadPopupCoordinates = function () {
// left,top,width,height
return "-1,-1,-1,-1";
};
SocialSharing.prototype.setIPadPopupCoordinates = function (coords) {
// left,top,width,height
cordova.exec(function() {}, this._getErrorCallback(function() {}, "setIPadPopupCoordinates"), "SocialSharing", "setIPadPopupCoordinates", [coords]);
};
SocialSharing.prototype.available = function (callback) {
cordova.exec(function (avail) {
callback(avail ? true : false);
}, null, "SocialSharing", "available", []);
};
SocialSharing.prototype.share = function (message, subject, fileOrFileArray, url, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "share"), "SocialSharing", "share", [message, subject, this._asArray(fileOrFileArray), url]);
};
SocialSharing.prototype.shareViaTwitter = function (message, file /* multiple not allowed by twitter */, url, successCallback, errorCallback) {
var fileArray = this._asArray(file);
var ecb = this._getErrorCallback(errorCallback, "shareViaTwitter");
if (fileArray.length > 1) {
ecb("shareViaTwitter supports max one file");
} else {
cordova.exec(successCallback, ecb, "SocialSharing", "shareViaTwitter", [message, null, fileArray, url]);
}
};
SocialSharing.prototype.shareViaFacebook = function (message, fileOrFileArray, url, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaFacebook"), "SocialSharing", "shareViaFacebook", [message, null, this._asArray(fileOrFileArray), url]);
};
SocialSharing.prototype.shareViaFacebookWithPasteMessageHint = function (message, fileOrFileArray, url, pasteMessageHint, successCallback, errorCallback) {
pasteMessageHint = pasteMessageHint || "If you like you can paste a message from your clipboard";
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaFacebookWithPasteMessageHint"), "SocialSharing", "shareViaFacebookWithPasteMessageHint", [message, null, this._asArray(fileOrFileArray), url, pasteMessageHint]);
};
SocialSharing.prototype.shareViaWhatsApp = function (message, fileOrFileArray, url, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaWhatsApp"), "SocialSharing", "shareViaWhatsApp", [message, null, this._asArray(fileOrFileArray), url, null]);
};
SocialSharing.prototype.shareViaWhatsAppToReceiver = function (receiver, message, fileOrFileArray, url, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaWhatsAppToReceiver"), "SocialSharing", "shareViaWhatsApp", [message, null, this._asArray(fileOrFileArray), url, receiver]);
};
SocialSharing.prototype.shareViaSMS = function (options, phonenumbers, successCallback, errorCallback) {
var opts = options;
if (typeof options == "string") {
opts = {"message":options}; // for backward compatibility as the options param used to be the message
}
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaSMS"), "SocialSharing", "shareViaSMS", [opts, phonenumbers]);
};
SocialSharing.prototype.shareViaEmail = function (message, subject, toArray, ccArray, bccArray, fileOrFileArray, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaEmail"), "SocialSharing", "shareViaEmail", [message, subject, this._asArray(toArray), this._asArray(ccArray), this._asArray(bccArray), this._asArray(fileOrFileArray)]);
};
SocialSharing.prototype.canShareVia = function (via, message, subject, fileOrFileArray, url, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "canShareVia"), "SocialSharing", "canShareVia", [message, subject, this._asArray(fileOrFileArray), url, via]);
};
SocialSharing.prototype.canShareViaEmail = function (successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "canShareViaEmail"), "SocialSharing", "canShareViaEmail", []);
};
SocialSharing.prototype.shareViaInstagram = function (message, fileOrFileArray, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaInstagram"), "SocialSharing", "shareViaInstagram", [message, null, this._asArray(fileOrFileArray), null]);
};
SocialSharing.prototype.shareVia = function (via, message, subject, fileOrFileArray, url, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareVia"), "SocialSharing", "shareVia", [message, subject, this._asArray(fileOrFileArray), url, via]);
};
SocialSharing.prototype.saveToPhotoAlbum = function (fileOrFileArray, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "saveToPhotoAlbum"), "SocialSharing", "saveToPhotoAlbum", [this._asArray(fileOrFileArray)]);
};
SocialSharing.prototype._asArray = function (param) {
if (param == null) {
param = [];
} else if (typeof param === 'string') {
param = new Array(param);
}
return param;
};
SocialSharing.prototype._getErrorCallback = function (ecb, functionName) {
if (typeof ecb === 'function') {
return ecb;
} else {
return function (result) {
console.log("The injected error callback of '" + functionName + "' received: " + JSON.stringify(result));
}
}
};
SocialSharing.install = function () {
if (!window.plugins) {
window.plugins = {};
}
window.plugins.socialsharing = new SocialSharing();
return window.plugins.socialsharing;
};
cordova.addConstructor(SocialSharing.install);
});

View File

@@ -18,11 +18,12 @@
</div>
<ion-item>
<div class="item tabs tabs-secondary tabs-icon-left">
<a href="#" class="tab-item"ng-click="deleteBuy(i.id,i.bild)"><i class="icon ion-trash-a button-custom"></i>Löschen</a>
<a href="#" class="tab-item" ng-click="showImages(i.appimgpublicpath)"><i class="icon ion-android-image button-custom"></i>Anzeigen</a>
<a href="#" class="tab-item"><i class="icon ion-share button-custom"></i>Teilen</a>
<a href="#" class="tab-item" ng-click="showImages(i.appimgpublicpath,i.bild)"><i class="icon ion-android-image button-custom"></i>Anzeigen</a>
<a href="#" class="tab-item" ng-click="shareimage(i.appimgpublicpath,i.bild)"><i class="icon ion-share button-custom"></i>Teilen</a>
</div>
</ion-item>

View File

@@ -222,6 +222,13 @@ module.exports = [
"clobbers": [
"window.plugins.sqlDB"
]
},
{
"file": "plugins/cordova-plugin-x-socialsharing/www/SocialSharing.js",
"id": "cordova-plugin-x-socialsharing.SocialSharing",
"clobbers": [
"window.plugins.socialsharing"
]
}
];
module.exports.metadata =

View File

@@ -375,8 +375,6 @@ $scope.show = function() {
* Rosen konsuieren ENDE
*/
})
.controller('BuysCtrl', function($scope, $database,$location,$ionicModal,$ionicLoading,$timeout,$cordovaFile,$ionicPopup) {
@@ -390,17 +388,19 @@ $scope.show = function() {
function fill_list(){
$scope.items=[];
$database.getAllBuys().then(function (result) {
if(result.length>0){
for(i=0;i<result.length;i++){
$scope.items.push(result[i]);
}
} else {
$scope.items=[];
$scope.items=[];
$database.getAllBuys().then(function (result) {
if(result.length>0){
for(i=0;i<result.length;i++){
$scope.items.push(result[i]);
}
});
$scope.hide($ionicLoading);
}
else {
$scope.items=[];
}
});
$scope.hide($ionicLoading);
}
@@ -452,16 +452,42 @@ $scope.show = function() {
});
}
$scope.showImages = function(imagesrc) {
$scope.showImages = function(imagesrc,imagefile) {
//Sicherstellen, das Bild im Publicfolder vorhanden ist
$cordovaFile.copyFile(cordova.file.applicationStorageDirectory, imagefile, cordova.file.externalRootDirectory + "/WolleRosenKaufen", imagefile)
.then(function (success) {
// success
}, function (error) {
// error
});
//Bild im dialog anzeigen
$scope.imagesrc=imagesrc;
$scope.showModal('templates/image-popover.html');
}
$scope.shareimage = function(imagesrc,imagefile) {
//Sicherstellen, das Bild im Publicfolder vorhanden ist
$cordovaFile.copyFile(cordova.file.applicationStorageDirectory, imagefile, cordova.file.externalRootDirectory + "/WolleRosenKaufen", imagefile)
.then(function (success) {
// success
}, function (error) {
// error
});
//Bild im dialog anzeigen
$scope.imagesrc=imagesrc;
window.plugins.socialsharing.share(null, null, $scope.imagesrc, null);
}
$scope.showModal = function(templateUrl) {
$ionicModal.fromTemplateUrl(templateUrl, {
scope: $scope,

View File

@@ -18,11 +18,12 @@
</div>
<ion-item>
<div class="item tabs tabs-secondary tabs-icon-left">
<a href="#" class="tab-item"ng-click="deleteBuy(i.id,i.bild)"><i class="icon ion-trash-a button-custom"></i>Löschen</a>
<a href="#" class="tab-item" ng-click="showImages(i.appimgpublicpath)"><i class="icon ion-android-image button-custom"></i>Anzeigen</a>
<a href="#" class="tab-item"><i class="icon ion-share button-custom"></i>Teilen</a>
<a href="#" class="tab-item" ng-click="showImages(i.appimgpublicpath,i.bild)"><i class="icon ion-android-image button-custom"></i>Anzeigen</a>
<a href="#" class="tab-item" ng-click="shareimage(i.appimgpublicpath,i.bild)"><i class="icon ion-share button-custom"></i>Teilen</a>
</div>
</ion-item>

View File

@@ -222,6 +222,13 @@ module.exports = [
"clobbers": [
"window.plugins.sqlDB"
]
},
{
"file": "plugins/cordova-plugin-x-socialsharing/www/SocialSharing.js",
"id": "cordova-plugin-x-socialsharing.SocialSharing",
"clobbers": [
"window.plugins.socialsharing"
]
}
];
module.exports.metadata =

View File

@@ -375,8 +375,6 @@ $scope.show = function() {
* Rosen konsuieren ENDE
*/
})
.controller('BuysCtrl', function($scope, $database,$location,$ionicModal,$ionicLoading,$timeout,$cordovaFile,$ionicPopup) {
@@ -390,17 +388,19 @@ $scope.show = function() {
function fill_list(){
$scope.items=[];
$database.getAllBuys().then(function (result) {
if(result.length>0){
for(i=0;i<result.length;i++){
$scope.items.push(result[i]);
}
} else {
$scope.items=[];
$scope.items=[];
$database.getAllBuys().then(function (result) {
if(result.length>0){
for(i=0;i<result.length;i++){
$scope.items.push(result[i]);
}
});
$scope.hide($ionicLoading);
}
else {
$scope.items=[];
}
});
$scope.hide($ionicLoading);
}
@@ -452,16 +452,42 @@ $scope.show = function() {
});
}
$scope.showImages = function(imagesrc) {
$scope.showImages = function(imagesrc,imagefile) {
//Sicherstellen, das Bild im Publicfolder vorhanden ist
$cordovaFile.copyFile(cordova.file.applicationStorageDirectory, imagefile, cordova.file.externalRootDirectory + "/WolleRosenKaufen", imagefile)
.then(function (success) {
// success
}, function (error) {
// error
});
//Bild im dialog anzeigen
$scope.imagesrc=imagesrc;
$scope.showModal('templates/image-popover.html');
}
$scope.shareimage = function(imagesrc,imagefile) {
//Sicherstellen, das Bild im Publicfolder vorhanden ist
$cordovaFile.copyFile(cordova.file.applicationStorageDirectory, imagefile, cordova.file.externalRootDirectory + "/WolleRosenKaufen", imagefile)
.then(function (success) {
// success
}, function (error) {
// error
});
//Bild im dialog anzeigen
$scope.imagesrc=imagesrc;
window.plugins.socialsharing.share(null, null, $scope.imagesrc, null);
}
$scope.showModal = function(templateUrl) {
$ionicModal.fromTemplateUrl(templateUrl, {
scope: $scope,

View File

@@ -18,11 +18,12 @@
</div>
<ion-item>
<div class="item tabs tabs-secondary tabs-icon-left">
<a href="#" class="tab-item"ng-click="deleteBuy(i.id,i.bild)"><i class="icon ion-trash-a button-custom"></i>Löschen</a>
<a href="#" class="tab-item" ng-click="showImages(i.appimgpublicpath)"><i class="icon ion-android-image button-custom"></i>Anzeigen</a>
<a href="#" class="tab-item"><i class="icon ion-share button-custom"></i>Teilen</a>
<a href="#" class="tab-item" ng-click="showImages(i.appimgpublicpath,i.bild)"><i class="icon ion-android-image button-custom"></i>Anzeigen</a>
<a href="#" class="tab-item" ng-click="shareimage(i.appimgpublicpath,i.bild)"><i class="icon ion-share button-custom"></i>Teilen</a>
</div>
</ion-item>

View File

@@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<items version="2" >
<item
jar="G:\Projekte\Android\wolle-rosen-kaufen\platforms\android\build\intermediates\exploded-aar\android\CordovaLib\unspecified\debug\jars\classes.jar"
jumboMode="false"
revision="23.0.2"
sha1="1c8581ae10780ee3b58ed093c37fb9ea21c3f8be">
<dex dex="G:\Projekte\Android\wolle-rosen-kaufen\platforms\android\build\intermediates\pre-dexed\debug\CordovaLib-unspecified-debug_baa7b2802c7e608972132669b5434fcf4c170efe.jar" />
</item>
<item
jar="G:\Projekte\Android\wolle-rosen-kaufen\platforms\android\libs\sqlite-connector.jar"
jumboMode="false"
@@ -15,12 +22,5 @@
sha1="15c0a9c99566dad4c9d65fd5921c8a8644e1dc25">
<dex dex="G:\Projekte\Android\wolle-rosen-kaufen\platforms\android\build\intermediates\pre-dexed\release\CordovaLib-unspecified-release_a4670fbdfaee2098ca089d4912dd2c9bbd997f8d.jar" />
</item>
<item
jar="G:\Projekte\Android\wolle-rosen-kaufen\platforms\android\build\intermediates\exploded-aar\android\CordovaLib\unspecified\debug\jars\classes.jar"
jumboMode="false"
revision="23.0.2"
sha1="1c8581ae10780ee3b58ed093c37fb9ea21c3f8be">
<dex dex="G:\Projekte\Android\wolle-rosen-kaufen\platforms\android\build\intermediates\pre-dexed\debug\CordovaLib-unspecified-debug_baa7b2802c7e608972132669b5434fcf4c170efe.jar" />
</item>
</items>

View File

@@ -18,7 +18,7 @@ document.getElementById(id+'Link').style.display = 'none';
<body>
<h1>Lint Report</h1>
<div class="titleSeparator"></div>
Check performed at Wed Feb 03 13:46:44 CET 2016.<br/>
Check performed at Wed Feb 03 14:31:51 CET 2016.<br/>
6 errors and 0 warnings found:<br/><br/>
<table class="overview">
<tr><td></td><td class="categoryColumn"><a href="#Correctness">Correctness</a>

View File

@@ -222,6 +222,13 @@ module.exports = [
"clobbers": [
"window.plugins.sqlDB"
]
},
{
"file": "plugins/cordova-plugin-x-socialsharing/www/SocialSharing.js",
"id": "cordova-plugin-x-socialsharing.SocialSharing",
"clobbers": [
"window.plugins.socialsharing"
]
}
];
module.exports.metadata =

View File

@@ -0,0 +1,122 @@
cordova.define("cordova-plugin-x-socialsharing.SocialSharing", function(require, exports, module) {
var cordova = require('cordova');
function SocialSharing() {
}
// Override this method (after deviceready) to set the location where you want the iPad popup arrow to appear.
// If not overridden with different values, the popup is not used. Example:
//
// window.plugins.socialsharing.iPadPopupCoordinates = function() {
// return "100,100,200,300";
// };
SocialSharing.prototype.iPadPopupCoordinates = function () {
// left,top,width,height
return "-1,-1,-1,-1";
};
SocialSharing.prototype.setIPadPopupCoordinates = function (coords) {
// left,top,width,height
cordova.exec(function() {}, this._getErrorCallback(function() {}, "setIPadPopupCoordinates"), "SocialSharing", "setIPadPopupCoordinates", [coords]);
};
SocialSharing.prototype.available = function (callback) {
cordova.exec(function (avail) {
callback(avail ? true : false);
}, null, "SocialSharing", "available", []);
};
SocialSharing.prototype.share = function (message, subject, fileOrFileArray, url, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "share"), "SocialSharing", "share", [message, subject, this._asArray(fileOrFileArray), url]);
};
SocialSharing.prototype.shareViaTwitter = function (message, file /* multiple not allowed by twitter */, url, successCallback, errorCallback) {
var fileArray = this._asArray(file);
var ecb = this._getErrorCallback(errorCallback, "shareViaTwitter");
if (fileArray.length > 1) {
ecb("shareViaTwitter supports max one file");
} else {
cordova.exec(successCallback, ecb, "SocialSharing", "shareViaTwitter", [message, null, fileArray, url]);
}
};
SocialSharing.prototype.shareViaFacebook = function (message, fileOrFileArray, url, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaFacebook"), "SocialSharing", "shareViaFacebook", [message, null, this._asArray(fileOrFileArray), url]);
};
SocialSharing.prototype.shareViaFacebookWithPasteMessageHint = function (message, fileOrFileArray, url, pasteMessageHint, successCallback, errorCallback) {
pasteMessageHint = pasteMessageHint || "If you like you can paste a message from your clipboard";
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaFacebookWithPasteMessageHint"), "SocialSharing", "shareViaFacebookWithPasteMessageHint", [message, null, this._asArray(fileOrFileArray), url, pasteMessageHint]);
};
SocialSharing.prototype.shareViaWhatsApp = function (message, fileOrFileArray, url, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaWhatsApp"), "SocialSharing", "shareViaWhatsApp", [message, null, this._asArray(fileOrFileArray), url, null]);
};
SocialSharing.prototype.shareViaWhatsAppToReceiver = function (receiver, message, fileOrFileArray, url, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaWhatsAppToReceiver"), "SocialSharing", "shareViaWhatsApp", [message, null, this._asArray(fileOrFileArray), url, receiver]);
};
SocialSharing.prototype.shareViaSMS = function (options, phonenumbers, successCallback, errorCallback) {
var opts = options;
if (typeof options == "string") {
opts = {"message":options}; // for backward compatibility as the options param used to be the message
}
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaSMS"), "SocialSharing", "shareViaSMS", [opts, phonenumbers]);
};
SocialSharing.prototype.shareViaEmail = function (message, subject, toArray, ccArray, bccArray, fileOrFileArray, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaEmail"), "SocialSharing", "shareViaEmail", [message, subject, this._asArray(toArray), this._asArray(ccArray), this._asArray(bccArray), this._asArray(fileOrFileArray)]);
};
SocialSharing.prototype.canShareVia = function (via, message, subject, fileOrFileArray, url, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "canShareVia"), "SocialSharing", "canShareVia", [message, subject, this._asArray(fileOrFileArray), url, via]);
};
SocialSharing.prototype.canShareViaEmail = function (successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "canShareViaEmail"), "SocialSharing", "canShareViaEmail", []);
};
SocialSharing.prototype.shareViaInstagram = function (message, fileOrFileArray, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaInstagram"), "SocialSharing", "shareViaInstagram", [message, null, this._asArray(fileOrFileArray), null]);
};
SocialSharing.prototype.shareVia = function (via, message, subject, fileOrFileArray, url, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareVia"), "SocialSharing", "shareVia", [message, subject, this._asArray(fileOrFileArray), url, via]);
};
SocialSharing.prototype.saveToPhotoAlbum = function (fileOrFileArray, successCallback, errorCallback) {
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "saveToPhotoAlbum"), "SocialSharing", "saveToPhotoAlbum", [this._asArray(fileOrFileArray)]);
};
SocialSharing.prototype._asArray = function (param) {
if (param == null) {
param = [];
} else if (typeof param === 'string') {
param = new Array(param);
}
return param;
};
SocialSharing.prototype._getErrorCallback = function (ecb, functionName) {
if (typeof ecb === 'function') {
return ecb;
} else {
return function (result) {
console.log("The injected error callback of '" + functionName + "' received: " + JSON.stringify(result));
}
}
};
SocialSharing.install = function () {
if (!window.plugins) {
window.plugins = {};
}
window.plugins.socialsharing = new SocialSharing();
return window.plugins.socialsharing;
};
cordova.addConstructor(SocialSharing.install);
});

View File

@@ -39,6 +39,9 @@
<feature name="sqlDB">
<param name="android-package" value="me.rahul.plugins.sqlDB.sqlDB" />
</feature>
<feature name="SocialSharing">
<param name="android-package" value="nl.xservices.plugins.SocialSharing" />
</feature>
<preference name="AndroidPersistentFileLocation" value="Internal" />
<icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
<icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />

View File

@@ -0,0 +1,602 @@
package nl.xservices.plugins;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.*;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.text.Html;
import android.util.Base64;
import android.view.Gravity;
import android.widget.Toast;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SocialSharing extends CordovaPlugin {
private static final String ACTION_AVAILABLE_EVENT = "available";
private static final String ACTION_SHARE_EVENT = "share";
private static final String ACTION_CAN_SHARE_VIA = "canShareVia";
private static final String ACTION_CAN_SHARE_VIA_EMAIL = "canShareViaEmail";
private static final String ACTION_SHARE_VIA = "shareVia";
private static final String ACTION_SHARE_VIA_TWITTER_EVENT = "shareViaTwitter";
private static final String ACTION_SHARE_VIA_FACEBOOK_EVENT = "shareViaFacebook";
private static final String ACTION_SHARE_VIA_FACEBOOK_WITH_PASTEMESSAGEHINT = "shareViaFacebookWithPasteMessageHint";
private static final String ACTION_SHARE_VIA_WHATSAPP_EVENT = "shareViaWhatsApp";
private static final String ACTION_SHARE_VIA_INSTAGRAM_EVENT = "shareViaInstagram";
private static final String ACTION_SHARE_VIA_SMS_EVENT = "shareViaSMS";
private static final String ACTION_SHARE_VIA_EMAIL_EVENT = "shareViaEmail";
private static final int ACTIVITY_CODE_SEND = 1;
private static final int ACTIVITY_CODE_SENDVIAEMAIL = 2;
private static final int ACTIVITY_CODE_SENDVIAWHATSAPP = 3;
private CallbackContext _callbackContext;
private String pasteMessage;
private abstract class SocialSharingRunnable implements Runnable {
public CallbackContext callbackContext;
SocialSharingRunnable(CallbackContext cb) {
this.callbackContext = cb;
}
}
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
this._callbackContext = callbackContext; // only used for onActivityResult
this.pasteMessage = null;
if (ACTION_AVAILABLE_EVENT.equals(action)) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
return true;
} else if (ACTION_SHARE_EVENT.equals(action)) {
return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), null, false);
} else if (ACTION_SHARE_VIA_TWITTER_EVENT.equals(action)) {
return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "twitter", false);
} else if (ACTION_SHARE_VIA_FACEBOOK_EVENT.equals(action)) {
return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "com.facebook.katana", false);
} else if (ACTION_SHARE_VIA_FACEBOOK_WITH_PASTEMESSAGEHINT.equals(action)) {
this.pasteMessage = args.getString(4);
return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "com.facebook.katana", false);
} else if (ACTION_SHARE_VIA_WHATSAPP_EVENT.equals(action)) {
if (notEmpty(args.getString(4))) {
return shareViaWhatsAppDirectly(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), args.getString(4));
} else {
return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "whatsapp", false);
}
} else if (ACTION_SHARE_VIA_INSTAGRAM_EVENT.equals(action)) {
if (notEmpty(args.getString(0))) {
copyHintToClipboard(args.getString(0), "Instagram paste message");
}
return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "instagram", false);
} else if (ACTION_CAN_SHARE_VIA.equals(action)) {
return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), args.getString(4), true);
} else if (ACTION_CAN_SHARE_VIA_EMAIL.equals(action)) {
if (isEmailAvailable()) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
return true;
} else {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "not available"));
return false;
}
} else if (ACTION_SHARE_VIA.equals(action)) {
return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), args.getString(4), false);
} else if (ACTION_SHARE_VIA_SMS_EVENT.equals(action)) {
return invokeSMSIntent(callbackContext, args.getJSONObject(0), args.getString(1));
} else if (ACTION_SHARE_VIA_EMAIL_EVENT.equals(action)) {
return invokeEmailIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.isNull(3) ? null : args.getJSONArray(3), args.isNull(4) ? null : args.getJSONArray(4), args.isNull(5) ? null : args.getJSONArray(5));
} else {
callbackContext.error("socialSharing." + action + " is not a supported function. Did you mean '" + ACTION_SHARE_EVENT + "'?");
return false;
}
}
private boolean isEmailAvailable() {
final Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "someone@domain.com", null));
return cordova.getActivity().getPackageManager().queryIntentActivities(intent, 0).size() > 0;
}
private boolean invokeEmailIntent(final CallbackContext callbackContext, final String message, final String subject, final JSONArray to, final JSONArray cc, final JSONArray bcc, final JSONArray files) throws JSONException {
final SocialSharing plugin = this;
cordova.getThreadPool().execute(new SocialSharingRunnable(callbackContext) {
public void run() {
final Intent draft = new Intent(Intent.ACTION_SEND_MULTIPLE);
if (notEmpty(message)) {
Pattern htmlPattern = Pattern.compile(".*\\<[^>]+>.*", Pattern.DOTALL);
if (htmlPattern.matcher(message).matches()) {
draft.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(message));
draft.setType("text/html");
} else {
draft.putExtra(android.content.Intent.EXTRA_TEXT, message);
draft.setType("text/plain");
}
}
if (notEmpty(subject)) {
draft.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
}
try {
if (to != null && to.length() > 0) {
draft.putExtra(android.content.Intent.EXTRA_EMAIL, toStringArray(to));
}
if (cc != null && cc.length() > 0) {
draft.putExtra(android.content.Intent.EXTRA_CC, toStringArray(cc));
}
if (bcc != null && bcc.length() > 0) {
draft.putExtra(android.content.Intent.EXTRA_BCC, toStringArray(bcc));
}
if (files.length() > 0) {
final String dir = getDownloadDir();
if (dir != null) {
ArrayList<Uri> fileUris = new ArrayList<Uri>();
for (int i = 0; i < files.length(); i++) {
final Uri fileUri = getFileUriAndSetType(draft, dir, files.getString(i), subject, i);
if (fileUri != null) {
fileUris.add(fileUri);
}
}
if (!fileUris.isEmpty()) {
draft.putExtra(Intent.EXTRA_STREAM, fileUris);
}
}
}
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
draft.setType("application/octet-stream");
cordova.startActivityForResult(plugin, Intent.createChooser(draft, "Choose Email App"), ACTIVITY_CODE_SENDVIAEMAIL);
}
});
return true;
}
private String getDownloadDir() throws IOException {
// better check, otherwise it may crash the app
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
// we need to use external storage since we need to share to another app
final String dir = webView.getContext().getExternalFilesDir(null) + "/socialsharing-downloads";
createOrCleanDir(dir);
return dir;
} else {
return null;
}
}
private boolean doSendIntent(final CallbackContext callbackContext, final String msg, final String subject, final JSONArray files, final String url, final String appPackageName, final boolean peek) {
final CordovaInterface mycordova = cordova;
final CordovaPlugin plugin = this;
cordova.getThreadPool().execute(new SocialSharingRunnable(callbackContext) {
public void run() {
String message = msg;
final boolean hasMultipleAttachments = files.length() > 1;
final Intent sendIntent = new Intent(hasMultipleAttachments ? Intent.ACTION_SEND_MULTIPLE : Intent.ACTION_SEND);
sendIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
try {
if (files.length() > 0 && !"".equals(files.getString(0))) {
final String dir = getDownloadDir();
if (dir != null) {
ArrayList<Uri> fileUris = new ArrayList<Uri>();
Uri fileUri = null;
for (int i = 0; i < files.length(); i++) {
fileUri = getFileUriAndSetType(sendIntent, dir, files.getString(i), subject, i);
if (fileUri != null) {
fileUris.add(fileUri);
}
}
if (!fileUris.isEmpty()) {
if (hasMultipleAttachments) {
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUris);
} else {
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
}
}
} else {
sendIntent.setType("text/plain");
}
} else {
sendIntent.setType("text/plain");
}
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
if (notEmpty(subject)) {
sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
}
// add the URL to the message, as there seems to be no separate field
if (notEmpty(url)) {
if (notEmpty(message)) {
message += " " + url;
} else {
message = url;
}
}
if (notEmpty(message)) {
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
// sometimes required when the user picks share via sms
if (Build.VERSION.SDK_INT < 21) { // LOLLIPOP
sendIntent.putExtra("sms_body", message);
}
}
if (appPackageName != null) {
String packageName = appPackageName;
String passedActivityName = null;
if (packageName.contains("/")) {
String[] items = appPackageName.split("/");
packageName = items[0];
passedActivityName = items[1];
}
final ActivityInfo activity = getActivity(callbackContext, sendIntent, packageName);
if (activity != null) {
if (peek) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
} else {
sendIntent.addCategory(Intent.CATEGORY_LAUNCHER);
sendIntent.setComponent(new ComponentName(activity.applicationInfo.packageName,
passedActivityName != null ? passedActivityName : activity.name));
mycordova.startActivityForResult(plugin, sendIntent, 0);
if (pasteMessage != null) {
// add a little delay because target app (facebook only atm) needs to be started first
new Timer().schedule(new TimerTask() {
public void run() {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
copyHintToClipboard(msg, pasteMessage);
showPasteMessage(pasteMessage);
}
});
}
}, 2000);
}
}
}
} else {
if (peek) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
} else {
mycordova.startActivityForResult(plugin, Intent.createChooser(sendIntent, null), ACTIVITY_CODE_SEND);
}
}
}
});
return true;
}
@SuppressLint("NewApi")
private void copyHintToClipboard(String msg, String label) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
return;
}
final ClipboardManager clipboard = (android.content.ClipboardManager) cordova.getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
final ClipData clip = android.content.ClipData.newPlainText(label, msg);
clipboard.setPrimaryClip(clip);
}
@SuppressLint("NewApi")
private void showPasteMessage(String label) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
return;
}
final Toast toast = Toast.makeText(webView.getContext(), label, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
private Uri getFileUriAndSetType(Intent sendIntent, String dir, String image, String subject, int nthFile) throws IOException {
// we're assuming an image, but this can be any filetype you like
String localImage = image;
sendIntent.setType("image/*");
if (image.startsWith("http") || image.startsWith("www/")) {
String filename = getFileName(image);
localImage = "file://" + dir + "/" + filename;
if (image.startsWith("http")) {
// filename optimisation taken from https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/pull/56
URLConnection connection = new URL(image).openConnection();
String disposition = connection.getHeaderField("Content-Disposition");
if (disposition != null) {
final Pattern dispositionPattern = Pattern.compile("filename=([^;]+)");
Matcher matcher = dispositionPattern.matcher(disposition);
if (matcher.find()) {
filename = matcher.group(1).replaceAll("[^a-zA-Z0-9._-]", "");
if (filename.length() == 0) {
// in this case we can't determine a filetype so some targets (gmail) may not render it correctly
filename = "file";
}
localImage = "file://" + dir + "/" + filename;
}
}
saveFile(getBytes(connection.getInputStream()), dir, filename);
} else {
saveFile(getBytes(webView.getContext().getAssets().open(image)), dir, filename);
}
} else if (image.startsWith("data:")) {
// safeguard for https://code.google.com/p/android/issues/detail?id=7901#c43
if (!image.contains(";base64,")) {
sendIntent.setType("text/plain");
return null;
}
// image looks like this: data:image/png;base64,R0lGODlhDAA...
final String encodedImg = image.substring(image.indexOf(";base64,") + 8);
// correct the intent type if anything else was passed, like a pdf: data:application/pdf;base64,..
if (!image.contains("data:image/")) {
sendIntent.setType(image.substring(image.indexOf("data:") + 5, image.indexOf(";base64")));
}
// the filename needs a valid extension, so it renders correctly in target apps
final String imgExtension = image.substring(image.indexOf("/") + 1, image.indexOf(";base64"));
String fileName;
// if a subject was passed, use it as the filename
// filenames must be unique when passing in multiple files [#158]
if (notEmpty(subject)) {
fileName = sanitizeFilename(subject) + (nthFile == 0 ? "" : "_" + nthFile) + "." + imgExtension;
} else {
fileName = "file" + (nthFile == 0 ? "" : "_" + nthFile) + "." + imgExtension;
}
saveFile(Base64.decode(encodedImg, Base64.DEFAULT), dir, fileName);
localImage = "file://" + dir + "/" + fileName;
} else if (image.startsWith("df:")) {
// safeguard for https://code.google.com/p/android/issues/detail?id=7901#c43
if (!image.contains(";base64,")) {
sendIntent.setType("text/plain");
return null;
}
// format looks like this : df:filename.txt;data:image/png;base64,R0lGODlhDAA...
final String fileName = image.substring(image.indexOf("df:") + 3, image.indexOf(";data:"));
final String fileType = image.substring(image.indexOf(";data:") + 6, image.indexOf(";base64,"));
final String encodedImg = image.substring(image.indexOf(";base64,") + 8);
sendIntent.setType(fileType);
saveFile(Base64.decode(encodedImg, Base64.DEFAULT), dir, sanitizeFilename(fileName));
localImage = "file://" + dir + "/" + fileName;
} else if (!image.startsWith("file://")) {
throw new IllegalArgumentException("URL_NOT_SUPPORTED");
}
return Uri.parse(localImage);
}
private boolean shareViaWhatsAppDirectly(final CallbackContext callbackContext, String message, final String subject, final JSONArray files, final String url, final String number) {
// add the URL to the message, as there seems to be no separate field
if (notEmpty(url)) {
if (notEmpty(message)) {
message += " " + url;
} else {
message = url;
}
}
final String shareMessage = message;
final SocialSharing plugin = this;
cordova.getThreadPool().execute(new SocialSharingRunnable(callbackContext) {
public void run() {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:" + number));
intent.putExtra("sms_body", shareMessage);
intent.putExtra("sms_subject", subject);
intent.setPackage("com.whatsapp");
try {
if (files.length() > 0 && !"".equals(files.getString(0))) {
final boolean hasMultipleAttachments = files.length() > 1;
final String dir = getDownloadDir();
if (dir != null) {
ArrayList<Uri> fileUris = new ArrayList<Uri>();
Uri fileUri = null;
for (int i = 0; i < files.length(); i++) {
fileUri = getFileUriAndSetType(intent, dir, files.getString(i), subject, i);
if (fileUri != null) {
fileUris.add(fileUri);
}
}
if (!fileUris.isEmpty()) {
if (hasMultipleAttachments) {
intent.putExtra(Intent.EXTRA_STREAM, fileUris);
} else {
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
}
}
}
}
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
try {
cordova.startActivityForResult(plugin, intent, ACTIVITY_CODE_SENDVIAWHATSAPP);
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
}
});
return true;
}
private boolean invokeSMSIntent(final CallbackContext callbackContext, JSONObject options, String p_phonenumbers) {
final String message = options.optString("message");
// TODO test this on a real SMS enabled device before releasing it
// final String subject = options.optString("subject");
// final String image = options.optString("image");
final String subject = null; //options.optString("subject");
final String image = null; // options.optString("image");
final String phonenumbers = getPhoneNumbersWithManufacturerSpecificSeparators(p_phonenumbers);
final SocialSharing plugin = this;
cordova.getThreadPool().execute(new SocialSharingRunnable(callbackContext) {
public void run() {
Intent intent;
if (Build.VERSION.SDK_INT >= 19) { // Build.VERSION_CODES.KITKAT) {
// passing in no phonenumbers for kitkat may result in an error,
// but it may also work for some devices, so documentation will need to cover this case
intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:" + (notEmpty(phonenumbers) ? phonenumbers : "")));
} else {
intent = new Intent(Intent.ACTION_VIEW);
intent.setType("vnd.android-dir/mms-sms");
if (phonenumbers != null) {
intent.putExtra("address", phonenumbers);
}
}
intent.putExtra("sms_body", message);
intent.putExtra("sms_subject", subject);
try {
if (image != null && !"".equals(image)) {
final Uri fileUri = getFileUriAndSetType(intent, getDownloadDir(), image, subject, 0);
if (fileUri != null) {
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
}
}
cordova.startActivityForResult(plugin, intent, 0);
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
}
});
return true;
}
private static String getPhoneNumbersWithManufacturerSpecificSeparators(String phonenumbers) {
if (notEmpty(phonenumbers)) {
char separator;
if (android.os.Build.MANUFACTURER.equalsIgnoreCase("samsung")) {
separator = ',';
} else {
separator = ';';
}
return phonenumbers.replace(';', separator).replace(',', separator);
}
return null;
}
private ActivityInfo getActivity(final CallbackContext callbackContext, final Intent shareIntent, final String appPackageName) {
final PackageManager pm = webView.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ((app.activityInfo.packageName).contains(appPackageName)) {
return app.activityInfo;
}
}
// no matching app found
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, getShareActivities(activityList)));
return null;
}
private JSONArray getShareActivities(List<ResolveInfo> activityList) {
List<String> packages = new ArrayList<String>();
for (final ResolveInfo app : activityList) {
packages.add(app.activityInfo.packageName);
}
return new JSONArray(packages);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (_callbackContext != null) {
if (ACTIVITY_CODE_SENDVIAEMAIL == requestCode) {
_callbackContext.success();
} else {
_callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, resultCode == Activity.RESULT_OK));
}
}
}
private void createOrCleanDir(final String downloadDir) throws IOException {
final File dir = new File(downloadDir);
if (!dir.exists()) {
if (!dir.mkdirs()) {
throw new IOException("CREATE_DIRS_FAILED");
}
} else {
cleanupOldFiles(dir);
}
}
private static String getFileName(String url) {
if (url.endsWith("/")) {
url = url.substring(0, url.length()-1);
}
final String pattern = ".*/([^?#]+)?";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(url);
if (m.find()) {
return m.group(1);
} else {
return "file";
}
}
private byte[] getBytes(InputStream is) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
return buffer.toByteArray();
}
private void saveFile(byte[] bytes, String dirName, String fileName) throws IOException {
final File dir = new File(dirName);
final FileOutputStream fos = new FileOutputStream(new File(dir, fileName));
fos.write(bytes);
fos.flush();
fos.close();
}
/**
* As file.deleteOnExit does not work on Android, we need to delete files manually.
* Deleting them in onActivityResult is not a good idea, because for example a base64 encoded file
* will not be available for upload to Facebook (it's deleted before it's uploaded).
* So the best approach is deleting old files when saving (sharing) a new one.
*/
private void cleanupOldFiles(File dir) {
for (File f : dir.listFiles()) {
//noinspection ResultOfMethodCallIgnored
f.delete();
}
}
private static boolean notEmpty(String what) {
return what != null &&
!"".equals(what) &&
!"null".equalsIgnoreCase(what);
}
private static String[] toStringArray(JSONArray jsonArray) throws JSONException {
String[] result = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
result[i] = jsonArray.getString(i);
}
return result;
}
public static String sanitizeFilename(String name) {
return name.replaceAll("[:\\\\/*?|<> ]", "_");
}
}