Permalink
Browse files

Social Sharing plugin

  • Loading branch information...
1 parent f056925 commit 578dbfee18632dbcaa85440c79e442e41ce0d9fb @purplecabbage purplecabbage committed Nov 4, 2011
Showing with 120 additions and 0 deletions.
  1. +76 −0 WindowsPhone/PGSocialShare/PGSocialShare.cs
  2. +44 −0 WindowsPhone/PGSocialShare/PGSocialShare.js
@@ -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();
+ }
+ }
+}
@@ -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);
+ }
+ }
+
+
+
+ });
+
+
+
+})();

0 comments on commit 578dbfe

Please sign in to comment.