Skip to content

Commit

Permalink
[samples/HelloWorld] Add Hello World sample.
Browse files Browse the repository at this point in the history
Update README.md to describe how to build, install, and run the sample.
  • Loading branch information
jonpryor committed May 4, 2016
1 parent ff1993a commit 00128ac
Show file tree
Hide file tree
Showing 16 changed files with 359 additions and 4 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,37 @@ For example, to generate `Mono.Android.dll` for API-19 (Android 4.4):
xbuild /p:AndroidApiLevel=19 /p:AndroidFrameworkVersion=v4.4
# creates bin\Debug\lib\xbuild-frameworks\MonoAndroid\v4.4\Mono.Android.dll

## Contributing ##
# Samples

### Mailing Lists
The [HelloWorld](samples/HelloWorld) sample may be built with the
[xabuild](tools/scripts/xabuild) script:

$ tools/scripts/xabuild /t:SignAndroidPackage samples/HelloWorld/HelloWorld.csproj

`xabuild /t:SignAndroidPackage` will generate an `.apk` file, which may be
installed onto an Android device with the [`adb install`][adb-commands]
command:

[adb-commands]: http://developer.android.com/tools/help/adb.html#commandsummary

$ adb install samples/HelloWorld/bin/Debug/com.xamarin.android.helloworld-Signed.apk

**HelloWorld** may be launched manually through the Android app launcher,
or via `adb shell am`:

$ adb shell am start com.xamarin.android.helloworld/example.MainActivity

# Contributing

## Mailing Lists

To discuss this project, and participate in the design, we use the [android-devel@lists.xamarin.com](http://lists.xamarin.com/mailman/listinfo/android-devel) mailing list.

### Coding Guidelines
## Coding Guidelines

We use [Mono's Coding Guidelines](http://www.mono-project.com/community/contributing/coding-guidelines/).

### Reporting Bugs
## Reporting Bugs

We use [Bugzilla](https://bugzilla.xamarin.com/enter_bug.cgi?product=Android) to track issues.

17 changes: 17 additions & 0 deletions Xamarin.Android.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "monodroid", "src\monodroid\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "api-xml-adjuster", "tools\api-xml-adjuster\api-xml-adjuster.csproj", "{8A6CB07C-E493-4A4F-AB94-038645A27118}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{99CBCF85-E4EB-41C8-9089-1A2B740681F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "samples\HelloWorld\HelloWorld.csproj", "{2305B00D-DE81-4744-B0DA-357835CAFE5A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|AnyCPU = Debug|AnyCPU
Expand Down Expand Up @@ -194,6 +198,18 @@ Global
{E8492EFB-D14A-4F32-AA28-88848322ECEA}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU
{E8492EFB-D14A-4F32-AA28-88848322ECEA}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU
{E8492EFB-D14A-4F32-AA28-88848322ECEA}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.Release|AnyCPU.ActiveCfg = Release|Any CPU
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.Release|AnyCPU.Build.0 = Release|Any CPU
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.XAIntegrationDebug|AnyCPU.ActiveCfg = Debug|Any CPU
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8FF78EB6-6FC8-46A7-8A15-EBBA9045C5FA} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62}
Expand All @@ -219,6 +235,7 @@ Global
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD} = {864062D3-A415-4A6F-9324-5820237BA058}
{53EE4C57-1C03-405A-8243-8DA539546C88} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
{8A6CB07C-E493-4A4F-AB94-038645A27118} = {864062D3-A415-4A6F-9324-5820237BA058}
{2305B00D-DE81-4744-B0DA-357835CAFE5A} = {99CBCF85-E4EB-41C8-9089-1A2B740681F0}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0
Expand Down
19 changes: 19 additions & 0 deletions samples/HelloWorld/Assets/AboutAssets.txt
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");
68 changes: 68 additions & 0 deletions samples/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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>
<ProjectGuid>{2305B00D-DE81-4744-B0DA-357835CAFE5A}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>HelloWorld</RootNamespace>
<AssemblyName>HelloWorld</AssemblyName>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
</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' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Mono.Android" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
<None Include="Properties\AndroidManifest.xml" />
<None Include="Assets\AboutAssets.txt" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\Main.axml" />
<AndroidResource Include="Resources\values\Strings.xml" />
<AndroidResource Include="Resources\mipmap-hdpi\Icon.png" />
<AndroidResource Include="Resources\mipmap-mdpi\Icon.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\Icon.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\Icon.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\Icon.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\drawable\" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
32 changes: 32 additions & 0 deletions samples/HelloWorld/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Android.App;
using Android.Widget;
using Android.OS;

namespace HelloWorld
{
[Activity (
Icon = "@mipmap/icon",
Label = "HelloWorld",
MainLauncher = true,
Name = "example.MainActivity")]
public class MainActivity : Activity
{
int count = 1;

protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);

// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);

// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button> (Resource.Id.myButton);

button.Click += delegate { button.Text = string.Format ("{0} clicks!", count++); };
}
}
}


6 changes: 6 additions & 0 deletions samples/HelloWorld/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?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="com.xamarin.android.helloworld">
<uses-sdk android:minSdkVersion="21" />
<application android:allowBackup="true" android:icon="@mipmap/icon" android:label="@string/app_name">
</application>
</manifest>
28 changes: 28 additions & 0 deletions samples/HelloWorld/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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 ("HelloWorld")]
[assembly: AssemblyDescription ("")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyCompany ("Xamarin Inc.")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("Xamarin Inc.")]
[assembly: AssemblyTrademark ("Xamarin")]
[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("")]

44 changes: 44 additions & 0 deletions samples/HelloWorld/Resources/AboutResources.txt
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.
112 changes: 112 additions & 0 deletions samples/HelloWorld/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 00128ac

Please sign in to comment.