Skip to content

Commit

Permalink
initial commit! some samples for xamarin.forms
Browse files Browse the repository at this point in the history
  • Loading branch information
conceptdev committed May 28, 2014
1 parent 4aad81f commit 600fbd9
Show file tree
Hide file tree
Showing 506 changed files with 79,676 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Xamarin stuff
Components
[Pp]ackages

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Xamarin.Forms;

namespace EmployeeDirectory.Android
{
public class AndroidPhoneFeatureService : IPhoneFeatureService
{
#region IPhoneFeatureService implementation

public bool Email (string emailAddress)
{
var intent = new Intent (Intent.ActionSend);
intent.SetType ("message/rfc822");
intent.PutExtra (Intent.ExtraEmail, new [] { emailAddress });
Forms.Context.StartActivity (Intent.CreateChooser (intent, "Send email"));

return true;
}

public bool Browse (string websiteUrl)
{
var url = websiteUrl.ToUpperInvariant ().StartsWith ("HTTP") ?
websiteUrl :
"http://" + websiteUrl;

var intent = new Intent (Intent.ActionView,
global::Android.Net.Uri.Parse (url));
Forms.Context.StartActivity (intent);

return true;
}

public bool Tweet (string twitterName)
{
var username = twitterName.Trim ();
if (username.StartsWith ("@")) {
username = username.Substring (1);
}
var url = "http://twitter.com/" + username;

var intent = new Intent (Intent.ActionView,
global::Android.Net.Uri.Parse (url));
Forms.Context.StartActivity (intent);

return true;
}

public bool Call (string phoneNumber)
{
var intent = new Intent (Intent.ActionCall, global::Android.Net.Uri.Parse (
"tel:" + Uri.EscapeDataString (phoneNumber)));
Forms.Context.StartActivity (intent);

return true;
}

public bool Map (string address)
{
throw new NotImplementedException ("This wasn't implemented in the original Android app...");
}

#endregion


}
}

Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?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>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B746C87C-7335-4830-AAE2-ACACE4D69DB5}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>EmployeeDirectory.Android</RootNamespace>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<AssemblyName>QuickTodo.Android</AssemblyName>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<TargetFrameworkVersion>v4.0.3</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;__MOBILE__;__ANDROID__;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
<ConsolePause>false</ConsolePause>
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<DefineConstants>__MOBILE__;__ANDROID__;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Mono.Android" />
<Reference Include="Mono.Android.GoogleMaps" />
<Reference Include="PCLStorage.Abstractions">
<HintPath>..\packages\PCLStorage.0.9.3\lib\monoandroid\PCLStorage.Abstractions.dll</HintPath>
</Reference>
<Reference Include="PCLStorage">
<HintPath>..\packages\PCLStorage.0.9.3\lib\monoandroid\PCLStorage.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Android.Support.v4">
<HintPath>..\packages\Xamarin.Android.Support.v4.19.0.2\lib\MonoAndroid10\Xamarin.Android.Support.v4.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform.Android">
<HintPath>..\packages\Xamarin.Forms.1.0.6188\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Core">
<HintPath>..\packages\Xamarin.Forms.1.0.6188\lib\MonoAndroid10\Xamarin.Forms.Core.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Xaml">
<HintPath>..\packages\Xamarin.Forms.1.0.6188\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AndroidPhoneFeatureService.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
<None Include="Properties\AndroidManifest.xml" />
<None Include="packages.config" />
<None Include="Resources\drawable\DetailsPlaceholder_2x.jpg" />
<None Include="Resources\drawable\DetailsPlaceholder.jpg" />
<None Include="Resources\drawable\Placeholder_2x.jpg" />
<None Include="Resources\drawable\Placeholder.jpg" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\Main.axml" />
<AndroidResource Include="Resources\values\Strings.xml" />
<AndroidResource Include="Resources\drawable\Icon.png" />
<AndroidResource Include="Resources\raw\XamarinDirectory.csv" />
<AndroidResource Include="Resources\raw\XamarinFavorites.xml" />
<AndroidResource Include="Resources\drawable\Search.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<Import Project="../packages/Xamarin.Forms.1.0.6188/build/portable-win+net45+wp80+MonoAndroid10+MonoTouch10/Xamarin.Forms.targets" />
<ItemGroup>
<ProjectReference Include="..\EmployeeDirectoryXaml\EmployeeDirectoryXaml.csproj">
<Project>{5F610EA1-9E35-4870-AE9B-5E18B4B4D5B8}</Project>
<Name>EmployeeDirectoryXaml</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\raw\" />
</ItemGroup>
<ItemGroup>
<XamarinComponentReference Include="xamandroidsupportv4-18">
<Version>4.19.0.1</Version>
<Visible>False</Visible>
</XamarinComponentReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.IO;
using EmployeeDirectory;

namespace EmployeeDirectory.Android
{
[Activity (Label = "EmployeeDirectory", MainLauncher = true)]
public class Activity1 : Xamarin.Forms.Platform.Android.AndroidActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

Xamarin.Forms.Forms.Init (this, bundle);

#region Copy static data into working folder
string documentsPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal); // Documents folder

var path = Path.Combine(documentsPath, "XamarinDirectory.csv");
//Console.WriteLine (path);
if (!File.Exists (path)) {
var s = Resources.OpenRawResource(EmployeeDirectory.Android.Resource.Raw.XamarinDirectory); // RESOURCE NAME ###
// create a write stream
FileStream writeStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
// write to the stream
ReadWriteStream(s, writeStream);
}
path = Path.Combine(documentsPath, "XamarinFavorites.xml");
//Console.WriteLine (path);
if (!File.Exists (path)) {
var s = Resources.OpenRawResource(EmployeeDirectory.Android.Resource.Raw.XamarinFavorites); // RESOURCE NAME ###
// create a write stream
FileStream writeStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
// write to the stream
ReadWriteStream(s, writeStream);
}
#endregion

App.PhoneFeatureService = new AndroidPhoneFeatureService ();

SetPage (App.GetMainPage ());
}

void ReadWriteStream(Stream readStream, Stream writeStream)
{
int Length = 256;
Byte[] buffer = new Byte[Length];
int bytesRead = readStream.Read(buffer, 0, Length);
// write the required bytes
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = readStream.Read(buffer, 0, Length);
}
readStream.Close();
writeStream.Close();
}
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="EmployeeDirectory.Android">
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" />
<application android:label="EmployeeDirectoryXaml" android:icon="@drawable/icon">
</application>
<uses-permission android:name="android.permission.CALL_PHONE" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 ("EmployeeDirectory.Android")]
[assembly: AssemblyDescription ("")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyCompany ("")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("craigdunn")]
[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("")]

Original file line number Diff line number Diff line change
@@ -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.
Loading

0 comments on commit 600fbd9

Please sign in to comment.