forked from dotnet/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add .NET 6+ template for Android wear
Fixes dotnet#7003 This speaks for itself, lets add a template for Wear applications.
- Loading branch information
1 parent
1efa0cf
commit 1e464a1
Showing
14 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/Microsoft.Android.Templates/android-wear/.template.config/template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
"author": "Microsoft", | ||
"classifications": [ "Android", "Mobile" ], | ||
"identity": "Microsoft.Android.AndroidWearApp", | ||
"name": "Android Wear Application", | ||
"description": "A project for creating a .NET Android Wear application", | ||
"shortName": "androidwear", | ||
"tags": { | ||
"language": "C#", | ||
"type": "project" | ||
}, | ||
"sourceName": "AndroidApp1", | ||
"sources": [ | ||
{ | ||
"source": "./", | ||
"target": "./", | ||
"copyOnly": "**/Resources/**/*.png" | ||
} | ||
], | ||
"preferNameDirectory": true, | ||
"primaryOutputs": [ | ||
{ "path": "AndroidApp1.csproj" } | ||
], | ||
"symbols": { | ||
"packageName": { | ||
"type": "parameter", | ||
"description": "Overrides the package name in the AndroidManifest.xml", | ||
"datatype": "string", | ||
"replaces": "com.companyname.AndroidApp1" | ||
}, | ||
"supportedOSVersion": { | ||
"type": "parameter", | ||
"description": "Overrides $(SupportedOSPlatformVersion) in the project", | ||
"datatype": "string", | ||
"replaces": "SUPPORTED_OS_PLATFORM_VERSION", | ||
"defaultValue": "23" | ||
} | ||
}, | ||
"defaultName": "AndroidApp1" | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Microsoft.Android.Templates/android-wear/AndroidApp1.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net7.0-android</TargetFramework> | ||
<SupportedOSPlatformVersion>SUPPORTED_OS_PLATFORM_VERSION</SupportedOSPlatformVersion> | ||
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">AndroidApp1</RootNamespace> | ||
<OutputType>Exe</OutputType> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<ApplicationId>com.companyname.AndroidApp1</ApplicationId> | ||
<ApplicationVersion>1</ApplicationVersion> | ||
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Xamarin.AndroidX.Wear" Version="1.2.0.5" /> | ||
<PackageReference Include="Xamarin.AndroidX.PercentLayout" Version="1.0.0.14" /> | ||
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.Core.UI" Version="1.0.0.14" /> | ||
<PackageReference Include="Xamarin.GooglePlayServices.Wearable" Version="117.1.0.5" /> | ||
</ItemGroup> | ||
</Project> |
14 changes: 14 additions & 0 deletions
14
src/Microsoft.Android.Templates/android-wear/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0"> | ||
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="31" /> | ||
<uses-feature android:name="android.hardware.type.watch" /> | ||
<uses-permission android:name="android.permission.WAKE_LOCK" /> | ||
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@android:style/Theme.DeviceDefault"> | ||
<uses-library android:name="com.google.android.wearable" android:required="true" /> | ||
<!-- | ||
Set to true if your app is Standalone, that is, it does not require the handheld | ||
app to run. | ||
--> | ||
<meta-data android:name="com.google.android.wearable.standalone" android:value="true" /> | ||
</application> | ||
</manifest> |
13 changes: 13 additions & 0 deletions
13
src/Microsoft.Android.Templates/android-wear/MainActivity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace AndroidApp1; | ||
|
||
[Activity(Label = "@string/app_name", MainLauncher = true)] | ||
public class MainActivity : Activity | ||
{ | ||
protected override void OnCreate(Bundle? savedInstanceState) | ||
{ | ||
base.OnCreate(savedInstanceState); | ||
|
||
// Set our view from the "main" layout resource | ||
SetContentView(Resource.Layout.activity_main); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Microsoft.Android.Templates/android-wear/Resources/AboutResources.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.xml), | ||
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.xml | ||
|
||
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 "Resource" | ||
(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 Resource class would expose: | ||
|
||
public class Resource { | ||
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 Resource.Drawable.icon to reference the drawable/icon.png file, or | ||
Resource.Layout.main to reference the layout/main.xml file, or Resource.Strings.first_string | ||
to reference the first string in the dictionary file values/strings.xml. |
19 changes: 19 additions & 0 deletions
19
src/Microsoft.Android.Templates/android-wear/Resources/layout/activity_main.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.wear.widget.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:padding="@dimen/box_inset_layout_padding" | ||
tools:deviceIds="wear"> | ||
<FrameLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:padding="@dimen/inner_frame_layout_padding" | ||
app:boxedEdges="all"> | ||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/apptext" /> | ||
</FrameLayout> | ||
</androidx.wear.widget.BoxInsetLayout> |
Binary file added
BIN
+1.6 KB
src/Microsoft.Android.Templates/android-wear/Resources/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.33 KB
src/Microsoft.Android.Templates/android-wear/Resources/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.25 KB
...Microsoft.Android.Templates/android-wear/Resources/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.78 KB
...icrosoft.Android.Templates/android-wear/Resources/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.9 KB
...crosoft.Android.Templates/android-wear/Resources/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
src/Microsoft.Android.Templates/android-wear/Resources/values-round/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_text">Hello, Android!</string> | ||
</resources> |
15 changes: 15 additions & 0 deletions
15
src/Microsoft.Android.Templates/android-wear/Resources/values/dimens.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<!-- | ||
Because the window insets on round devices are larger than 15dp, this padding only applies | ||
to square screens. | ||
--> | ||
<dimen name="box_inset_layout_padding">0dp</dimen> | ||
|
||
<!-- | ||
This padding applies to both square and round screens. The total padding between the buttons | ||
and the window insets is box_inset_layout_padding (above variable) on square screens and | ||
inner_frame_layout_padding (below variable) on round screens. | ||
--> | ||
<dimen name="inner_frame_layout_padding">5dp</dimen> | ||
</resources> |
9 changes: 9 additions & 0 deletions
9
src/Microsoft.Android.Templates/android-wear/Resources/values/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name">AndroidApp1</string> | ||
<!-- | ||
This string is used for square devices and overridden by hello_world in | ||
values-round/strings.xml for round devices. | ||
--> | ||
<string name="app_text">Hello, Android!</string> | ||
</resources> |