diff --git a/ShareExample/App.cs b/ShareExample/App.cs new file mode 100644 index 0000000..89619c8 --- /dev/null +++ b/ShareExample/App.cs @@ -0,0 +1,14 @@ +using Xamarin.Forms; + +namespace ShareExample +{ + public class App : Application + { + public App() + { + var navigationPage = new NavigationPage(new ShareImagePage() { Title = "Share Logo" }); + + MainPage = navigationPage; + } + } +} diff --git a/ShareExample/Droid/Assets/AboutAssets.txt b/ShareExample/Droid/Assets/AboutAssets.txt new file mode 100644 index 0000000..a9b0638 --- /dev/null +++ b/ShareExample/Droid/Assets/AboutAssets.txt @@ -0,0 +1,19 @@ +Any raw assets you want to be deployed with your application can be placed in +this directory (and child directories) and given a Build Action of "AndroidAsset". + +These files will be deployed with your package and will be accessible using Android's +AssetManager, like this: + +public class ReadAsset : Activity +{ + protected override void OnCreate (Bundle bundle) + { + base.OnCreate (bundle); + + InputStream input = Assets.Open ("my_asset.txt"); + } +} + +Additionally, some Android functions will automatically load asset files: + +Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); diff --git a/ShareExample/Droid/MainActivity.cs b/ShareExample/Droid/MainActivity.cs new file mode 100644 index 0000000..4e5d92a --- /dev/null +++ b/ShareExample/Droid/MainActivity.cs @@ -0,0 +1,49 @@ +using Android.App; +using Android.Content.PM; +using Android.OS; +using Xamarin.Forms; +using Android.Content; +using Android.Graphics; +using Xamarin.Forms.Platform.Android; + +namespace ShareExample.Droid +{ + [Activity(Label = "ShareExample.Droid", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] + public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity + { + const int ShareImageId = 1000; + + protected override void OnCreate(Bundle bundle) + { + base.OnCreate(bundle); + + Forms.Init(this, bundle); + + LoadApplication(new App()); + + MessagingCenter.Subscribe (this, "Share", Share, null); + } + + async void Share (ImageSource imageSource) + { + var intent = new Intent (Intent.ActionSend); + intent.SetType ("image/png"); + + var handler = new ImageLoaderSourceHandler(); + var bitmap = await handler.LoadImageAsync(imageSource, this); + + var path = Environment.GetExternalStoragePublicDirectory (Environment.DirectoryDownloads + + Java.IO.File.Separator + "logo.png"); + + using (var os = new System.IO.FileStream (path.AbsolutePath, System.IO.FileMode.Create)) { + bitmap.Compress (Bitmap.CompressFormat.Png, 100, os); + } + + intent.PutExtra (Intent.ExtraStream, Android.Net.Uri.FromFile (path)); + + var intentChooser = Intent.CreateChooser (intent, "Share via"); + + StartActivityForResult (intentChooser, ShareImageId); + } + } +} diff --git a/ShareExample/Droid/Properties/AndroidManifest.xml b/ShareExample/Droid/Properties/AndroidManifest.xml new file mode 100644 index 0000000..381a28a --- /dev/null +++ b/ShareExample/Droid/Properties/AndroidManifest.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/ShareExample/Droid/Properties/AssemblyInfo.cs b/ShareExample/Droid/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f0712d0 --- /dev/null +++ b/ShareExample/Droid/Properties/AssemblyInfo.cs @@ -0,0 +1,28 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using Android.App; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("ShareExample.Droid")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("jonwood")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.0")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/ShareExample/Droid/Resources/AboutResources.txt b/ShareExample/Droid/Resources/AboutResources.txt new file mode 100644 index 0000000..10f52d4 --- /dev/null +++ b/ShareExample/Droid/Resources/AboutResources.txt @@ -0,0 +1,44 @@ +Images, layout descriptions, binary blobs and string dictionaries can be included +in your application as resource files. Various Android APIs are designed to +operate on the resource IDs instead of dealing with images, strings or binary blobs +directly. + +For example, a sample Android app that contains a user interface layout (main.axml), +an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) +would keep its resources in the "Resources" directory of the application: + +Resources/ + drawable/ + icon.png + + layout/ + main.axml + + values/ + strings.xml + +In order to get the build system to recognize Android resources, set the build action to +"AndroidResource". The native Android APIs do not operate directly with filenames, but +instead operate on resource IDs. When you compile an Android application that uses resources, +the build system will package the resources for distribution and generate a class called "R" +(this is an Android convention) that contains the tokens for each one of the resources +included. For example, for the above Resources layout, this is what the R class would expose: + +public class R { + public class drawable { + public const int icon = 0x123; + } + + public class layout { + public const int main = 0x456; + } + + public class strings { + public const int first_string = 0xabc; + public const int second_string = 0xbcd; + } +} + +You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main +to reference the layout/main.axml file, or R.strings.first_string to reference the first +string in the dictionary file values/strings.xml. diff --git a/ShareExample/Droid/Resources/Resource.designer.cs b/ShareExample/Droid/Resources/Resource.designer.cs new file mode 100644 index 0000000..a3e8b3b --- /dev/null +++ b/ShareExample/Droid/Resources/Resource.designer.cs @@ -0,0 +1,82 @@ +#pragma warning disable 1591 +// ------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Mono Runtime Version: 4.0.30319.17020 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ + +[assembly: Android.Runtime.ResourceDesignerAttribute("ShareExample.Droid.Resource", IsApplication=true)] + +namespace ShareExample.Droid +{ + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] + public partial class Resource + { + + static Resource() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + public static void UpdateIdValues() + { + global::Xamarin.Forms.Platform.Resource.String.ApplicationName = global::ShareExample.Droid.Resource.String.ApplicationName; + global::Xamarin.Forms.Platform.Resource.String.Hello = global::ShareExample.Droid.Resource.String.Hello; + } + + public partial class Attribute + { + + static Attribute() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private Attribute() + { + } + } + + public partial class Drawable + { + + // aapt resource value: 0x7f020000 + public const int icon = 2130837504; + + static Drawable() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private Drawable() + { + } + } + + public partial class String + { + + // aapt resource value: 0x7f030001 + public const int ApplicationName = 2130903041; + + // aapt resource value: 0x7f030000 + public const int Hello = 2130903040; + + static String() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private String() + { + } + } + } +} +#pragma warning restore 1591 diff --git a/ShareExample/Droid/Resources/drawable-hdpi/icon.png b/ShareExample/Droid/Resources/drawable-hdpi/icon.png new file mode 100644 index 0000000..964f110 Binary files /dev/null and b/ShareExample/Droid/Resources/drawable-hdpi/icon.png differ diff --git a/ShareExample/Droid/Resources/drawable-xhdpi/icon.png b/ShareExample/Droid/Resources/drawable-xhdpi/icon.png new file mode 100644 index 0000000..3c01e60 Binary files /dev/null and b/ShareExample/Droid/Resources/drawable-xhdpi/icon.png differ diff --git a/ShareExample/Droid/Resources/drawable-xxhdpi/icon.png b/ShareExample/Droid/Resources/drawable-xxhdpi/icon.png new file mode 100644 index 0000000..0d8c1c5 Binary files /dev/null and b/ShareExample/Droid/Resources/drawable-xxhdpi/icon.png differ diff --git a/ShareExample/Droid/Resources/drawable/icon.png b/ShareExample/Droid/Resources/drawable/icon.png new file mode 100644 index 0000000..b0ba715 Binary files /dev/null and b/ShareExample/Droid/Resources/drawable/icon.png differ diff --git a/ShareExample/Droid/ShareExample.Droid.csproj b/ShareExample/Droid/ShareExample.Droid.csproj new file mode 100644 index 0000000..2051703 --- /dev/null +++ b/ShareExample/Droid/ShareExample.Droid.csproj @@ -0,0 +1,93 @@ + + + + Debug + AnyCPU + {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0} + Library + ShareExample.Droid + Assets + Resources + Properties\AndroidManifest.xml + Resource + Resources\Resource.designer.cs + True + True + ShareExample.Droid + v5.1 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + None + false + + + full + true + bin\Release + prompt + 4 + false + false + + + + + + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\MonoAndroid10\FormsViewGroup.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\MonoAndroid10\Xamarin.Forms.Core.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\MonoAndroid10\Xamarin.Forms.Platform.dll + + + ..\packages\Xamarin.Android.Support.v4.22.2.1.0\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll + + + + + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8} + ShareExample + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShareExample/Droid/packages.config b/ShareExample/Droid/packages.config new file mode 100644 index 0000000..2e9e7a1 --- /dev/null +++ b/ShareExample/Droid/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/ShareExample/Properties/AssemblyInfo.cs b/ShareExample/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2317874 --- /dev/null +++ b/ShareExample/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("ShareExample")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("jonwood")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/ShareExample/ShareExample.csproj b/ShareExample/ShareExample.csproj new file mode 100644 index 0000000..508abf4 --- /dev/null +++ b/ShareExample/ShareExample.csproj @@ -0,0 +1,61 @@ + + + + Debug + AnyCPU + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8} + Library + ShareExample + ShareExample + v4.5 + Profile78 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + + + + + ShareImagePage.xaml + + + + + + + + + packages\Xamarin.Forms.1.4.4.6392\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Core.dll + + + packages\Xamarin.Forms.1.4.4.6392\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Xaml.dll + + + packages\Xamarin.Forms.1.4.4.6392\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Platform.dll + + + + + + + + MSBuild:UpdateDesignTimeXaml + + + \ No newline at end of file diff --git a/ShareExample/ShareExample.sln b/ShareExample/ShareExample.sln new file mode 100644 index 0000000..93edfd2 --- /dev/null +++ b/ShareExample/ShareExample.sln @@ -0,0 +1,57 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShareExample", "ShareExample.csproj", "{934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShareExample.iOS", "iOS\ShareExample.iOS.csproj", "{4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShareExample.Droid", "Droid\ShareExample.Droid.csproj", "{B5F6E99B-DCD0-49E1-BB33-76249BB398E0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + Debug|iPhoneSimulator = Debug|iPhoneSimulator + Release|iPhone = Release|iPhone + Release|iPhoneSimulator = Release|iPhoneSimulator + Debug|iPhone = Debug|iPhone + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}.Debug|iPhone.ActiveCfg = Debug|iPhone + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}.Debug|iPhone.Build.0 = Debug|iPhone + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}.Release|Any CPU.ActiveCfg = Release|iPhone + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}.Release|Any CPU.Build.0 = Release|iPhone + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}.Release|iPhone.ActiveCfg = Release|iPhone + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}.Release|iPhone.Build.0 = Release|iPhone + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}.Debug|iPhone.Build.0 = Debug|Any CPU + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}.Release|Any CPU.Build.0 = Release|Any CPU + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}.Release|iPhone.ActiveCfg = Release|Any CPU + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}.Release|iPhone.Build.0 = Release|Any CPU + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0}.Debug|iPhone.Build.0 = Debug|Any CPU + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0}.Release|Any CPU.Build.0 = Release|Any CPU + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0}.Release|iPhone.ActiveCfg = Release|Any CPU + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0}.Release|iPhone.Build.0 = Release|Any CPU + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {B5F6E99B-DCD0-49E1-BB33-76249BB398E0}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/ShareExample/ShareImagePage.xaml b/ShareExample/ShareImagePage.xaml new file mode 100644 index 0000000..134ea9e --- /dev/null +++ b/ShareExample/ShareImagePage.xaml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/ShareExample/ShareImagePage.xaml.cs b/ShareExample/ShareImagePage.xaml.cs new file mode 100644 index 0000000..2206b18 --- /dev/null +++ b/ShareExample/ShareImagePage.xaml.cs @@ -0,0 +1,20 @@ +using Xamarin.Forms; + +namespace ShareExample +{ + public partial class ShareImagePage : ContentPage + { + ShareImageViewModel _shareImageViewModel; + + public ShareImagePage() + { + InitializeComponent(); + + _shareImageViewModel = new ShareImageViewModel(); + + _shareImageViewModel.Source = LogoImage.Source; + + BindingContext = _shareImageViewModel; + } + } +} diff --git a/ShareExample/ShareImageViewModel.cs b/ShareExample/ShareImageViewModel.cs new file mode 100644 index 0000000..919d680 --- /dev/null +++ b/ShareExample/ShareImageViewModel.cs @@ -0,0 +1,21 @@ +using Xamarin.Forms; + +namespace ShareExample +{ + public class ShareImageViewModel + { + public Command Share { get; set; } + + public ImageSource Source { get; set; } + + public ShareImageViewModel() + { + Share = new Command(ShareCommand); + } + + void ShareCommand() + { + MessagingCenter.Send(this.Source, "Share"); + } + } +} diff --git a/ShareExample/iOS/AppDelegate.cs b/ShareExample/iOS/AppDelegate.cs new file mode 100644 index 0000000..b0ef574 --- /dev/null +++ b/ShareExample/iOS/AppDelegate.cs @@ -0,0 +1,45 @@ +using Foundation; +using UIKit; +using Xamarin.Forms; +using Xamarin.Forms.Platform.iOS; + +namespace ShareExample.iOS +{ + [Register("AppDelegate")] + public partial class AppDelegate : FormsApplicationDelegate + { + public override bool FinishedLaunching(UIApplication app, NSDictionary options) + { + Forms.Init(); + + // Code for starting up the Xamarin Test Cloud Agent + #if ENABLE_TEST_CLOUD + Xamarin.Calabash.Start(); + #endif + + LoadApplication(new App()); + + MessagingCenter.Subscribe (this, "Share", Share, null); + + return base.FinishedLaunching(app, options); + } + + async void Share (ImageSource imageSource) + { + var handler = new ImageLoaderSourceHandler(); + var uiImage = await handler.LoadImageAsync(imageSource); + + var item = NSObject.FromObject (uiImage); + var activityItems = new[] { item }; + var activityController = new UIActivityViewController (activityItems, null); + + var topController = UIApplication.SharedApplication.KeyWindow.RootViewController; + + while (topController.PresentedViewController != null) { + topController = topController.PresentedViewController; + } + + topController.PresentViewController (activityController, true, () => {}); + } + } +} diff --git a/ShareExample/iOS/Entitlements.plist b/ShareExample/iOS/Entitlements.plist new file mode 100644 index 0000000..e9a3005 --- /dev/null +++ b/ShareExample/iOS/Entitlements.plist @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ShareExample/iOS/ITunesArtwork b/ShareExample/iOS/ITunesArtwork new file mode 100644 index 0000000..d0136ea Binary files /dev/null and b/ShareExample/iOS/ITunesArtwork differ diff --git a/ShareExample/iOS/ITunesArtwork@2x b/ShareExample/iOS/ITunesArtwork@2x new file mode 100644 index 0000000..fa2ebf7 Binary files /dev/null and b/ShareExample/iOS/ITunesArtwork@2x differ diff --git a/ShareExample/iOS/Info.plist b/ShareExample/iOS/Info.plist new file mode 100644 index 0000000..93110d6 --- /dev/null +++ b/ShareExample/iOS/Info.plist @@ -0,0 +1,64 @@ + + + + + CFBundleDisplayName + ShareExample + CFBundleIdentifier + com.companyname.shareexample + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + MinimumOSVersion + 7.0 + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + CFBundleIconFiles + + Icon-60@2x + Icon-60@3x + Icon-76 + Icon-76@2x + Default + Default@2x + Default-568h + Default-568h@2x + Default-Landscape + Default-Landscape@2x + Default-Portrait + Default-Portrait@2x + Icon-Small-40 + Icon-Small-40@2x + Icon-Small-40@3x + Icon-Small + Icon-Small@2x + Icon-Small@3x + + UILaunchStoryboardName + LaunchScreen + + + diff --git a/ShareExample/iOS/Main.cs b/ShareExample/iOS/Main.cs new file mode 100644 index 0000000..e22bc64 --- /dev/null +++ b/ShareExample/iOS/Main.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using Foundation; +using UIKit; + +namespace ShareExample.iOS +{ + public class Application + { + // This is the main entry point of the application. + static void Main(string[] args) + { + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, "AppDelegate"); + } + } +} + diff --git a/ShareExample/iOS/Resources/Default-568h@2x.png b/ShareExample/iOS/Resources/Default-568h@2x.png new file mode 100644 index 0000000..26c6461 Binary files /dev/null and b/ShareExample/iOS/Resources/Default-568h@2x.png differ diff --git a/ShareExample/iOS/Resources/Default-Portrait.png b/ShareExample/iOS/Resources/Default-Portrait.png new file mode 100644 index 0000000..5d0d1ab Binary files /dev/null and b/ShareExample/iOS/Resources/Default-Portrait.png differ diff --git a/ShareExample/iOS/Resources/Default-Portrait@2x.png b/ShareExample/iOS/Resources/Default-Portrait@2x.png new file mode 100644 index 0000000..0ee2688 Binary files /dev/null and b/ShareExample/iOS/Resources/Default-Portrait@2x.png differ diff --git a/ShareExample/iOS/Resources/Default.png b/ShareExample/iOS/Resources/Default.png new file mode 100644 index 0000000..b74643c Binary files /dev/null and b/ShareExample/iOS/Resources/Default.png differ diff --git a/ShareExample/iOS/Resources/Default@2x.png b/ShareExample/iOS/Resources/Default@2x.png new file mode 100644 index 0000000..dbd6bd3 Binary files /dev/null and b/ShareExample/iOS/Resources/Default@2x.png differ diff --git a/ShareExample/iOS/Resources/Icon-60@2x.png b/ShareExample/iOS/Resources/Icon-60@2x.png new file mode 100644 index 0000000..4b03c42 Binary files /dev/null and b/ShareExample/iOS/Resources/Icon-60@2x.png differ diff --git a/ShareExample/iOS/Resources/Icon-60@3x.png b/ShareExample/iOS/Resources/Icon-60@3x.png new file mode 100644 index 0000000..b03ca1b Binary files /dev/null and b/ShareExample/iOS/Resources/Icon-60@3x.png differ diff --git a/ShareExample/iOS/Resources/Icon-76.png b/ShareExample/iOS/Resources/Icon-76.png new file mode 100644 index 0000000..587982e Binary files /dev/null and b/ShareExample/iOS/Resources/Icon-76.png differ diff --git a/ShareExample/iOS/Resources/Icon-76@2x.png b/ShareExample/iOS/Resources/Icon-76@2x.png new file mode 100644 index 0000000..cd4e2c8 Binary files /dev/null and b/ShareExample/iOS/Resources/Icon-76@2x.png differ diff --git a/ShareExample/iOS/Resources/Icon-Small-40.png b/ShareExample/iOS/Resources/Icon-Small-40.png new file mode 100644 index 0000000..6acff94 Binary files /dev/null and b/ShareExample/iOS/Resources/Icon-Small-40.png differ diff --git a/ShareExample/iOS/Resources/Icon-Small-40@2x.png b/ShareExample/iOS/Resources/Icon-Small-40@2x.png new file mode 100644 index 0000000..b833aac Binary files /dev/null and b/ShareExample/iOS/Resources/Icon-Small-40@2x.png differ diff --git a/ShareExample/iOS/Resources/Icon-Small-40@3x.png b/ShareExample/iOS/Resources/Icon-Small-40@3x.png new file mode 100644 index 0000000..ab8654e Binary files /dev/null and b/ShareExample/iOS/Resources/Icon-Small-40@3x.png differ diff --git a/ShareExample/iOS/Resources/Icon-Small.png b/ShareExample/iOS/Resources/Icon-Small.png new file mode 100644 index 0000000..33db7e7 Binary files /dev/null and b/ShareExample/iOS/Resources/Icon-Small.png differ diff --git a/ShareExample/iOS/Resources/Icon-Small@2x.png b/ShareExample/iOS/Resources/Icon-Small@2x.png new file mode 100644 index 0000000..bf45e25 Binary files /dev/null and b/ShareExample/iOS/Resources/Icon-Small@2x.png differ diff --git a/ShareExample/iOS/Resources/Icon-Small@3x.png b/ShareExample/iOS/Resources/Icon-Small@3x.png new file mode 100644 index 0000000..7ad3891 Binary files /dev/null and b/ShareExample/iOS/Resources/Icon-Small@3x.png differ diff --git a/ShareExample/iOS/Resources/LaunchScreen.storyboard b/ShareExample/iOS/Resources/LaunchScreen.storyboard new file mode 100644 index 0000000..a639c2f --- /dev/null +++ b/ShareExample/iOS/Resources/LaunchScreen.storyboard @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ShareExample/iOS/SecondaryToolbarRenderer.cs b/ShareExample/iOS/SecondaryToolbarRenderer.cs new file mode 100644 index 0000000..7ab117e --- /dev/null +++ b/ShareExample/iOS/SecondaryToolbarRenderer.cs @@ -0,0 +1,124 @@ +using Xamarin.Forms.Platform.iOS; +using Xamarin.Forms; +using UIKit; +using System.Linq; +using CoreGraphics; +using System; +using System.Collections.Generic; +using System.Windows.Input; +using ShareExample.iOS; + +[assembly: ExportRenderer (typeof(Page), typeof(PatchedPageRenderer))] +[assembly: ExportRenderer (typeof(NavigationPage), typeof(SecondaryToolbarRenderer))] + +namespace ShareExample.iOS +{ + public class SecondaryToolbarRenderer : NavigationRenderer + { + public override void ViewWillAppear (bool animated) + { + var badBar = View.Subviews.OfType ().FirstOrDefault (v => v.GetType () != typeof(UIToolbar)); + if (badBar != null) { + badBar.RemoveFromSuperview (); + } + base.ViewWillAppear (animated); + } + + public override void ViewDidLayoutSubviews () + { + base.ViewDidLayoutSubviews (); + + UIView[] subviews = View.Subviews.Where (v => v != NavigationBar).ToArray (); + var toolBarViews = subviews.Where (v => v is UIToolbar).ToArray (); + var otherViews = subviews.Where (v => !(v is UIToolbar)).ToArray (); + + nfloat toolbarHeight = 0; + + foreach (var uIView in toolBarViews) { + uIView.SizeToFit (); + uIView.Frame = new CGRect { + X = 0, + Y = View.Bounds.Height - uIView.Frame.Height, + Width = View.Bounds.Width, + Height = uIView.Frame.Height, + }; + var thisToolbarHeight = uIView.Frame.Height; + if (toolbarHeight < thisToolbarHeight) { + toolbarHeight = thisToolbarHeight; + } + } + + var othersHeight = View.Bounds.Height - toolbarHeight; + var othersFrame = new CGRect (View.Bounds.X, View.Bounds.Y, View.Bounds.Width, othersHeight); + + foreach (var uIView in otherViews) { + uIView.Frame = othersFrame; + } + } + } + + public class PatchedPageRenderer : PageRenderer + { + UIToolbar _toolbar; + List _secondaryItems; + Dictionary _buttonCommands = new Dictionary (); + + protected override void OnElementChanged (VisualElementChangedEventArgs e) + { + var page = e.NewElement as Page; + if (page != null) { + _secondaryItems = page.ToolbarItems.Where (i => i.Order == ToolbarItemOrder.Secondary).ToList (); + _secondaryItems.ForEach (t => page.ToolbarItems.Remove (t)); + } + base.OnElementChanged (e); + } + + public override void ViewWillAppear (bool animated) + { + var badBar = View.Subviews.OfType ().FirstOrDefault (v => v.GetType () != typeof(UIToolbar)); + if (badBar != null) { + badBar.RemoveFromSuperview (); + } + + if (_secondaryItems != null && _secondaryItems.Count > 0) { + var tools = new List (); + _buttonCommands.Clear (); + foreach (var tool in _secondaryItems) { + #pragma warning disable 618 + var systemItemName = tool.Name; + #pragma warning restore 618 + UIBarButtonItem button; + UIBarButtonSystemItem systemItem; + button = Enum.TryParse (systemItemName, out systemItem) + ? new UIBarButtonItem (systemItem, ToolClicked) + : new UIBarButtonItem (tool.Text, UIBarButtonItemStyle.Plain, ToolClicked); + _buttonCommands.Add (button, tool.Command); + tools.Add (button); + } + + NavigationController.SetToolbarHidden (false, animated); + _toolbar = new UIToolbar (CGRect.Empty) { Items = tools.ToArray () }; + NavigationController.View.Add (_toolbar); + } + + base.ViewWillAppear (animated); + } + + void ToolClicked(object sender, EventArgs args) + { + var tool = sender as UIBarButtonItem; + var command = _buttonCommands [tool]; + command.Execute (null); + } + + public override void ViewWillDisappear (bool animated) + { + if (_toolbar != null) { + NavigationController.SetToolbarHidden (true, animated); + _toolbar.RemoveFromSuperview (); + _toolbar = null; + } + base.ViewWillDisappear (animated); + } + } +} diff --git a/ShareExample/iOS/ShareExample.iOS.csproj b/ShareExample/iOS/ShareExample.iOS.csproj new file mode 100644 index 0000000..cfd315c --- /dev/null +++ b/ShareExample/iOS/ShareExample.iOS.csproj @@ -0,0 +1,126 @@ + + + + Debug + iPhoneSimulator + {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {4EBF6422-AA70-4F77-B4C9-68E3F6A53A2C} + Exe + ShareExample.iOS + Resources + ShareExample.iOS + + + true + full + false + bin\iPhoneSimulator\Debug + DEBUG;ENABLE_TEST_CLOUD; + prompt + 4 + false + i386 + None + true + true + + + full + true + bin\iPhone\Release + prompt + 4 + Entitlements.plist + ARMv7, ARM64 + false + iPhone Developer + + + full + true + bin\iPhoneSimulator\Release + prompt + 4 + i386 + false + None + + + true + full + false + bin\iPhone\Debug + DEBUG;ENABLE_TEST_CLOUD; + prompt + 4 + false + ARMv7, ARM64 + Entitlements.plist + true + iPhone Developer + true + + + + + + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll + + + ..\packages\Xamarin.TestCloud.Agent.0.14.3\lib\Xamarin.iOS10\Calabash.dll + + + + + {934AF0F1-46EC-4E0F-BBB4-8EDAF2CCF6A8} + ShareExample + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShareExample/iOS/packages.config b/ShareExample/iOS/packages.config new file mode 100644 index 0000000..2d77feb --- /dev/null +++ b/ShareExample/iOS/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/ShareExample/packages.config b/ShareExample/packages.config new file mode 100644 index 0000000..192ce41 --- /dev/null +++ b/ShareExample/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file