Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added ShareActionProvider sample from ICS article.

  • Loading branch information...
commit c9066d8601d2d1e57f128df3607eb2c93f06bd15 1 parent c691de2
@mikebluestein mikebluestein authored
View
73 ShareActionProviderDemo/Activity1.cs
@@ -0,0 +1,73 @@
+using System;
+
+using Android.App;
+using Android.Content;
+using Android.Runtime;
+using Android.Views;
+using Android.Widget;
+using Android.OS;
+using System.IO;
+
+namespace ShareActionProviderDemo
+{
+ [Activity (Label = "ShareActionProviderDemo", MainLauncher = true)]
+ public class Activity1 : Activity
+ {
+
+ protected override void OnCreate (Bundle bundle)
+ {
+ base.OnCreate (bundle);
+
+ CopyToPublic ("monkey.png");
+
+ // Set our view from the "main" layout resource
+ SetContentView (Resource.Layout.Main);
+ }
+
+ public override bool OnCreateOptionsMenu (IMenu menu)
+ {
+ MenuInflater.Inflate (Resource.Menu.ActionBarMenu, menu);
+
+ var shareMenuItem = menu.FindItem (Resource.Id.shareMenuItem);
+ var shareActionProvider = (ShareActionProvider)shareMenuItem.ActionProvider;
+ shareActionProvider.SetShareIntent (CreateIntent ());
+
+ var overflow_item = menu.FindItem (Resource.Id.overflowMenuItem);
+ var overflow_provider = (ShareActionProvider)overflow_item.ActionProvider;
+ overflow_provider.SetShareIntent (CreateIntent ());
+
+ return true;
+ }
+
+ Intent CreateIntent ()
+ {
+ var sendPictureIntent = new Intent (Intent.ActionSend);
+ sendPictureIntent.SetType ("image/*");
+ var uri = Android.Net.Uri.FromFile (GetFileStreamPath ("monkey.png"));
+ sendPictureIntent.PutExtra (Intent.ExtraStream, uri);
+
+ return sendPictureIntent;
+ }
+
+ void CopyToPublic (String fileName)
+ {
+ using (Stream fromStream = Assets.Open (fileName)) {
+
+ string filePath = Path.Combine (new string[]{"data", "data", PackageName, "files", fileName});
+
+ int size = 32 * 1024;
+
+ using (FileStream toStream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite)) {
+
+ int n = -1;
+ byte[] buffer = new byte[size];
+
+ while ((n = fromStream.Read(buffer, 0, size)) > 0) {
+ toStream.Write (buffer, 0, n);
+ }
+ }
+ }
+ }
+
+ }
+}
View
19 ShareActionProviderDemo/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 you 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");
View
BIN  ShareActionProviderDemo/Assets/monkey.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
7 ShareActionProviderDemo/Metadata.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<SampleMetadata>
+ <ID>3d5eb666-c03d-4390-93c3-6861e17f4ce4</ID>
+ <IsFullApplication>false</IsFullApplication>
+ <Level>Beginning</Level>
+ <Tags>User Interface, Shared Resources</Tags>
+</SampleMetadata>
View
28 ShareActionProviderDemo/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("ShareActionProviderDemo")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("mike_bluestein")]
+[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("")]
+
View
4 ShareActionProviderDemo/README.md
@@ -0,0 +1,4 @@
+ShareActionProvider Demo
+========================
+
+This example shows how to use the ShareActionProvider to share an image using Ice Cream Sandwich.
View
44 ShareActionProviderDemo/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.
View
BIN  ShareActionProviderDemo/Resources/drawable/Icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
11 ShareActionProviderDemo/Resources/layout/Main.axml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+<TextView android:text="Click the device Menu button"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" />
+</LinearLayout>
+
View
13 ShareActionProviderDemo/Resources/menu/ActionBarMenu.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item android:id="@+id/shareMenuItem"
+ android:showAsAction="always"
+ android:title="@string/sharePicture"
+ android:actionProviderClass="android.widget.ShareActionProvider" />
+
+ <item android:id="@+id/overflowMenuItem"
+ android:showAsAction="never"
+ android:title="@string/sharePicture"
+ android:actionProviderClass="android.widget.ShareActionProvider" />
+</menu>
View
5 ShareActionProviderDemo/Resources/values/Strings.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">ShareActionProviderDemo</string>
+ <string name="sharePicture">Share Picture</string>
+</resources>
View
BIN  ShareActionProviderDemo/Screenshots/ShareActionProvider1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  ShareActionProviderDemo/Screenshots/ShareActionProvider2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
69 ShareActionProviderDemo/ShareActionProviderDemo.csproj
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>10.0.0</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E010B79F-B465-49DE-84B5-647097FDB2BF}</ProjectGuid>
+ <ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <OutputType>Library</OutputType>
+ <RootNamespace>ShareActionProviderDemo</RootNamespace>
+ <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
+ <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
+ <AndroidResgenClass>Resource</AndroidResgenClass>
+ <AndroidApplication>True</AndroidApplication>
+ <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
+ <AssemblyName>ShareActionProviderDemo</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ <AndroidLinkMode>None</AndroidLinkMode>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>none</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
+ <AndroidLinkMode>SdkOnly</AndroidLinkMode>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ <Reference Include="Mono.Android" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Activity1.cs" />
+ <Compile Include="Resources\Resource.designer.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\AboutResources.txt" />
+ <None Include="Assets\AboutAssets.txt" />
+ </ItemGroup>
+ <ItemGroup>
+ <AndroidResource Include="Resources\layout\Main.axml" />
+ <AndroidResource Include="Resources\values\Strings.xml" />
+ <AndroidResource Include="Resources\drawable\Icon.png" />
+ <AndroidResource Include="Resources\menu\ActionBarMenu.xml" />
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
+ <ItemGroup>
+ <Folder Include="Resources\menu\" />
+ </ItemGroup>
+ <ItemGroup>
+ <AndroidAsset Include="Assets\monkey.png" />
+ </ItemGroup>
+</Project>
View
20 ShareActionProviderDemo/ShareActionProviderDemo.sln
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShareActionProviderDemo", "ShareActionProviderDemo.csproj", "{E010B79F-B465-49DE-84B5-647097FDB2BF}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {E010B79F-B465-49DE-84B5-647097FDB2BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E010B79F-B465-49DE-84B5-647097FDB2BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E010B79F-B465-49DE-84B5-647097FDB2BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E010B79F-B465-49DE-84B5-647097FDB2BF}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = ShareActionProviderDemo.csproj
+ EndGlobalSection
+EndGlobal
Please sign in to comment.
Something went wrong with that request. Please try again.