Social Sharing plugin

This commit is contained in:
Jesse MacFadyen
2011-11-04 09:19:40 +08:00
committed by Jesse MacFadyen
parent 27d57c1e40
commit 64e8d34d6d
2 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.Serialization;
using Microsoft.Phone.Tasks;
namespace WP7GapClassLib.PhoneGap.Commands
{
public class PGSocialShare : BaseCommand
{
public enum ShareType
{
Status = 0, // status update to twitter/facebook/... all supported device accounts
Link // share a link on twitter/facebook/ ... all supported device accounts
}
[DataContract]
public class ShareOptions
{
[DataMember]
public string url;
[DataMember]
public string title;
[DataMember]
public string message;
[DataMember]
public ShareType shareType = ShareType.Status; // default
}
public void share(string options)
{
ShareOptions opts = JSON.JsonHelper.Deserialize<ShareOptions>(options);
switch (opts.shareType)
{
case ShareType.Status :
shareStatus(opts.message);
break;
case ShareType.Link :
shareLink(opts.title, opts.url, opts.message);
break;
}
}
protected void shareStatus(string msg)
{
ShareStatusTask shareStatusTask = new ShareStatusTask();
shareStatusTask.Status = msg;
shareStatusTask.Show();
this.DispatchCommandResult();
}
protected void shareLink(string title, string url, string msg)
{
ShareLinkTask shareLinkTask = new ShareLinkTask();
shareLinkTask.Title = title;
shareLinkTask.LinkUri = new Uri(url, UriKind.Absolute);
shareLinkTask.Message = msg;
shareLinkTask.Show();
this.DispatchCommandResult();
}
}
}

View File

@@ -0,0 +1,44 @@
/* MIT licensed */
// (c) 2011 Jesse MacFadyen, Adobe Systems Incorporated
(function(){
var PGSocialShare =
{
ShareType:
{
status:0,
link:1
}
}
PhoneGap.addConstructor(function() {
navigator.plugins.pgSocialShare =
{
shareStatus:function(msg)
{
var options = {"message":msg,"shareType":PGSocialShare.ShareType.status};
PhoneGap.exec(null,null,"PGSocialShare","share",options);
},
shareLink:function(title,url,msg)
{
var options = {"message":msg,
"title":title,
"url":url,
"shareType":PGSocialShare.ShareType.link};
PhoneGap.exec(null,null,"PGSocialShare","share",options);
}
}
});
})();