Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit 187c433

Browse files
committed
Samples added.
1 parent d3900c4 commit 187c433

File tree

191 files changed

+23257
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+23257
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Any raw assets you want to be deployed with your application can be placed in
2+
this directory (and child directories) and given a Build Action of "AndroidAsset".
3+
4+
These files will be deployed with your package and will be accessible using Android's
5+
AssetManager, like this:
6+
7+
public class ReadAsset : Activity
8+
{
9+
protected override void OnCreate (Bundle bundle)
10+
{
11+
base.OnCreate (bundle);
12+
13+
InputStream input = Assets.Open ("my_asset.txt");
14+
}
15+
}
16+
17+
Additionally, some Android functions will automatically load asset files:
18+
19+
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{D2553545-AAAA-407A-B4FC-5B045EFAE1E5}</ProjectGuid>
7+
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
8+
<TemplateGuid>{c9e5eea5-ca05-42a1-839b-61506e0a37df}</TemplateGuid>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>CSharpForMarkupDemos.Droid</RootNamespace>
11+
<AssemblyName>CSharpForMarkupDemos.Android</AssemblyName>
12+
<AndroidApplication>True</AndroidApplication>
13+
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
14+
<AndroidResgenClass>Resource</AndroidResgenClass>
15+
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
16+
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
17+
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
18+
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
19+
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
20+
<AndroidUseAapt2>true</AndroidUseAapt2>
21+
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
22+
<NuGetPackageImportStamp>
23+
</NuGetPackageImportStamp>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
26+
<DebugSymbols>true</DebugSymbols>
27+
<DebugType>portable</DebugType>
28+
<Optimize>false</Optimize>
29+
<OutputPath>bin\Debug</OutputPath>
30+
<DefineConstants>DEBUG;</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
<AndroidLinkMode>None</AndroidLinkMode>
34+
</PropertyGroup>
35+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
36+
<DebugSymbols>true</DebugSymbols>
37+
<DebugType>portable</DebugType>
38+
<Optimize>true</Optimize>
39+
<OutputPath>bin\Release</OutputPath>
40+
<ErrorReport>prompt</ErrorReport>
41+
<WarningLevel>4</WarningLevel>
42+
<AndroidManagedSymbols>true</AndroidManagedSymbols>
43+
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
44+
</PropertyGroup>
45+
<ItemGroup>
46+
<Reference Include="Mono.Android" />
47+
<Reference Include="System" />
48+
<Reference Include="System.Core" />
49+
<Reference Include="System.Xml.Linq" />
50+
<Reference Include="System.Xml" />
51+
<Reference Include="System.Numerics" />
52+
<Reference Include="System.Numerics.Vectors" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1687" />
56+
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<Compile Include="MainActivity.cs" />
60+
<Compile Include="Resources\Resource.designer.cs" />
61+
<Compile Include="Properties\AssemblyInfo.cs" />
62+
</ItemGroup>
63+
<ItemGroup>
64+
<None Include="Resources\AboutResources.txt" />
65+
<None Include="Assets\AboutAssets.txt" />
66+
<None Include="Properties\AndroidManifest.xml" />
67+
</ItemGroup>
68+
<ItemGroup>
69+
<AndroidResource Include="Resources\layout\Tabbar.xml" />
70+
<AndroidResource Include="Resources\layout\Toolbar.xml" />
71+
<AndroidResource Include="Resources\values\styles.xml" />
72+
<AndroidResource Include="Resources\values\colors.xml" />
73+
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon.xml" />
74+
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon_round.xml" />
75+
<AndroidResource Include="Resources\mipmap-hdpi\icon.png" />
76+
<AndroidResource Include="Resources\mipmap-hdpi\launcher_foreground.png" />
77+
<AndroidResource Include="Resources\mipmap-mdpi\icon.png" />
78+
<AndroidResource Include="Resources\mipmap-mdpi\launcher_foreground.png" />
79+
<AndroidResource Include="Resources\mipmap-xhdpi\icon.png" />
80+
<AndroidResource Include="Resources\mipmap-xhdpi\launcher_foreground.png" />
81+
<AndroidResource Include="Resources\mipmap-xxhdpi\icon.png" />
82+
<AndroidResource Include="Resources\mipmap-xxhdpi\launcher_foreground.png" />
83+
<AndroidResource Include="Resources\mipmap-xxxhdpi\icon.png" />
84+
<AndroidResource Include="Resources\mipmap-xxxhdpi\launcher_foreground.png" />
85+
</ItemGroup>
86+
<ItemGroup>
87+
<Folder Include="Resources\drawable\" />
88+
</ItemGroup>
89+
<ItemGroup>
90+
<ProjectReference Include="..\CSharpForMarkupDemos\CSharpForMarkupDemos.csproj">
91+
<Project>{8770738D-2AD6-4B69-8502-ACC92F55B3F2}</Project>
92+
<Name>CSharpForMarkupDemos</Name>
93+
</ProjectReference>
94+
</ItemGroup>
95+
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
96+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Android.App;
2+
using Android.Content.PM;
3+
using Android.OS;
4+
using Android.Runtime;
5+
using CSharpForMarkupDemos.Helpers;
6+
7+
namespace CSharpForMarkupDemos.Droid
8+
{
9+
[Activity(Label = "CSharpForMarkupDemos", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
10+
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
11+
{
12+
protected override void OnCreate(Bundle savedInstanceState)
13+
{
14+
TaskHelper.InitializeFromUIThread();
15+
TabLayoutResource = Resource.Layout.Tabbar;
16+
ToolbarResource = Resource.Layout.Toolbar;
17+
18+
base.OnCreate(savedInstanceState);
19+
20+
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
21+
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
22+
LoadApplication(new App());
23+
}
24+
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
25+
{
26+
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
27+
28+
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.csharpformarkupdemos">
3+
<uses-sdk android:minSdkVersion="21" />
4+
<application android:label="CSharpForMarkupDemos.Android"></application>
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
using Android.App;
5+
6+
// General Information about an assembly is controlled through the following
7+
// set of attributes. Change these attribute values to modify the information
8+
// associated with an assembly.
9+
[assembly: AssemblyTitle("CSharpForMarkupDemos.Android")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("CSharpForMarkupDemos.Android")]
14+
[assembly: AssemblyCopyright("Copyright © 2014")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
[assembly: ComVisible(false)]
18+
19+
// Version information for an assembly consists of the following four values:
20+
//
21+
// Major Version
22+
// Minor Version
23+
// Build Number
24+
// Revision
25+
//
26+
// You can specify all the values or you can default the Build and Revision Numbers
27+
// by using the '*' as shown below:
28+
// [assembly: AssemblyVersion("1.0.*")]
29+
[assembly: AssemblyVersion("1.0.0.0")]
30+
[assembly: AssemblyFileVersion("1.0.0.0")]
31+
32+
// Add some common permissions, these can be removed if not needed
33+
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
34+
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Images, layout descriptions, binary blobs and string dictionaries can be included
2+
in your application as resource files. Various Android APIs are designed to
3+
operate on the resource IDs instead of dealing with images, strings or binary blobs
4+
directly.
5+
6+
For example, a sample Android app that contains a user interface layout (main.xml),
7+
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
8+
would keep its resources in the "Resources" directory of the application:
9+
10+
Resources/
11+
drawable-hdpi/
12+
icon.png
13+
14+
drawable-ldpi/
15+
icon.png
16+
17+
drawable-mdpi/
18+
icon.png
19+
20+
layout/
21+
main.xml
22+
23+
values/
24+
strings.xml
25+
26+
In order to get the build system to recognize Android resources, set the build action to
27+
"AndroidResource". The native Android APIs do not operate directly with filenames, but
28+
instead operate on resource IDs. When you compile an Android application that uses resources,
29+
the build system will package the resources for distribution and generate a class called
30+
"Resource" that contains the tokens for each one of the resources included. For example,
31+
for the above Resources layout, this is what the Resource class would expose:
32+
33+
public class Resource {
34+
public class drawable {
35+
public const int icon = 0x123;
36+
}
37+
38+
public class layout {
39+
public const int main = 0x456;
40+
}
41+
42+
public class strings {
43+
public const int first_string = 0xabc;
44+
public const int second_string = 0xbcd;
45+
}
46+
}
47+
48+
You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main
49+
to reference the layout/main.xml file, or Resource.strings.first_string to reference the first
50+
string in the dictionary file values/strings.xml.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:tabIndicatorColor="@android:color/white" app:tabGravity="fill" app:tabMode="fixed" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@color/launcher_background" />
4+
<foreground android:drawable="@mipmap/launcher_foreground" />
5+
</adaptive-icon>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@color/launcher_background" />
4+
<foreground android:drawable="@mipmap/launcher_foreground" />
5+
</adaptive-icon>
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="launcher_background">#FFFFFF</color>
4+
<color name="colorPrimary">#3F51B5</color>
5+
<color name="colorPrimaryDark">#303F9F</color>
6+
<color name="colorAccent">#FF4081</color>
7+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<style name="MainTheme" parent="MainTheme.Base">
4+
</style>
5+
<!-- Base theme applied no matter what API -->
6+
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
7+
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
8+
<item name="windowNoTitle">true</item>
9+
<!--We will be using the toolbar so no need to show ActionBar-->
10+
<item name="windowActionBar">false</item>
11+
<!-- Set theme colors from https://aka.ms/material-colors -->
12+
<!-- colorPrimary is used for the default action bar background -->
13+
<item name="colorPrimary">#2196F3</item>
14+
<!-- colorPrimaryDark is used for the status bar -->
15+
<item name="colorPrimaryDark">#1976D2</item>
16+
<!-- colorAccent is used as the default value for colorControlActivated
17+
which is used to tint widgets -->
18+
<item name="colorAccent">#FF4081</item>
19+
<!-- You can also set colorControlNormal, colorControlActivated
20+
colorControlHighlight and colorSwitchThumbNormal. -->
21+
<item name="windowActionModeOverlay">true</item>
22+
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
23+
</style>
24+
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
25+
<item name="colorAccent">#FF4081</item>
26+
</style>
27+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Application
2+
x:Class="CSharpForMarkupDemos.UWP.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:CSharpForMarkupDemos.UWP">
6+
7+
</Application>

0 commit comments

Comments
 (0)