Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit a71f5ff

Browse filesBrowse files
authored
Merge pull request #2 from wcoder/feature/xamarin-forms-android-sample
Sample of using library for Xamarin.Forms Android project
2 parents 7c99f3c + 50c71e4 commit a71f5ff
Copy full SHA for a71f5ff
Expand file treeCollapse file tree

31 files changed

+8018
-0
lines changed
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27703.2018
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlurViewFormsSample.Android", "BlurViewFormsSample\BlurViewFormsSample.Android\BlurViewFormsSample.Android.csproj", "{DFCA9516-E5D9-4A46-8467-012E0E934A8B}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlurViewFormsSample", "BlurViewFormsSample\BlurViewFormsSample\BlurViewFormsSample.csproj", "{52663B09-6AC5-4FB5-B43F-CD11C8569A8B}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{DFCA9516-E5D9-4A46-8467-012E0E934A8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{DFCA9516-E5D9-4A46-8467-012E0E934A8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{DFCA9516-E5D9-4A46-8467-012E0E934A8B}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
19+
{DFCA9516-E5D9-4A46-8467-012E0E934A8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{DFCA9516-E5D9-4A46-8467-012E0E934A8B}.Release|Any CPU.Build.0 = Release|Any CPU
21+
{DFCA9516-E5D9-4A46-8467-012E0E934A8B}.Release|Any CPU.Deploy.0 = Release|Any CPU
22+
{52663B09-6AC5-4FB5-B43F-CD11C8569A8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{52663B09-6AC5-4FB5-B43F-CD11C8569A8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{52663B09-6AC5-4FB5-B43F-CD11C8569A8B}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
25+
{52663B09-6AC5-4FB5-B43F-CD11C8569A8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{52663B09-6AC5-4FB5-B43F-CD11C8569A8B}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{52663B09-6AC5-4FB5-B43F-CD11C8569A8B}.Release|Any CPU.Deploy.0 = Release|Any CPU
28+
EndGlobalSection
29+
GlobalSection(SolutionProperties) = preSolution
30+
HideSolutionNode = FALSE
31+
EndGlobalSection
32+
GlobalSection(ExtensibilityGlobals) = postSolution
33+
SolutionGuid = {5E1F3DAF-C44A-4BE9-8839-9D3E7274F724}
34+
EndGlobalSection
35+
EndGlobal
+19Lines changed: 19 additions & 0 deletions
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 you 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,104 @@
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>{DFCA9516-E5D9-4A46-8467-012E0E934A8B}</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>BlurViewFormsSample.Droid</RootNamespace>
11+
<AssemblyName>BlurViewFormsSample.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+
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
19+
<TargetFrameworkVersion>v8.1</TargetFrameworkVersion>
20+
<NuGetPackageImportStamp>
21+
</NuGetPackageImportStamp>
22+
</PropertyGroup>
23+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
24+
<DebugSymbols>true</DebugSymbols>
25+
<DebugType>full</DebugType>
26+
<Optimize>false</Optimize>
27+
<OutputPath>bin\Debug</OutputPath>
28+
<DefineConstants>DEBUG;</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
<AndroidLinkMode>None</AndroidLinkMode>
32+
</PropertyGroup>
33+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
34+
<DebugSymbols>true</DebugSymbols>
35+
<DebugType>pdbonly</DebugType>
36+
<Optimize>true</Optimize>
37+
<OutputPath>bin\Release</OutputPath>
38+
<ErrorReport>prompt</ErrorReport>
39+
<WarningLevel>4</WarningLevel>
40+
<AndroidManagedSymbols>true</AndroidManagedSymbols>
41+
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
42+
</PropertyGroup>
43+
<ItemGroup>
44+
<Reference Include="Mono.Android" />
45+
<Reference Include="System" />
46+
<Reference Include="System.Core" />
47+
<Reference Include="System.Xml.Linq" />
48+
<Reference Include="System.Xml" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<PackageReference Include="Xamarin.BlurView">
52+
<Version>1.3.4</Version>
53+
</PackageReference>
54+
<PackageReference Include="Xamarin.Forms" Version="3.0.0.482510" />
55+
<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2" />
56+
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2" />
57+
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2" />
58+
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="27.0.2" />
59+
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="27.0.2" />
60+
</ItemGroup>
61+
<ItemGroup>
62+
<Compile Include="FormsBlurViewRenderer.cs" />
63+
<Compile Include="MainActivity.cs" />
64+
<Compile Include="Resources\Resource.Designer.cs" />
65+
<Compile Include="Properties\AssemblyInfo.cs" />
66+
</ItemGroup>
67+
<ItemGroup>
68+
<None Include="Resources\AboutResources.txt" />
69+
<None Include="Assets\AboutAssets.txt" />
70+
<None Include="Properties\AndroidManifest.xml" />
71+
</ItemGroup>
72+
<ItemGroup>
73+
<AndroidResource Include="Resources\layout\Tabbar.axml" />
74+
<AndroidResource Include="Resources\layout\Toolbar.axml" />
75+
<AndroidResource Include="Resources\values\styles.xml" />
76+
<AndroidResource Include="Resources\values\colors.xml" />
77+
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon.xml" />
78+
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon_round.xml" />
79+
<AndroidResource Include="Resources\mipmap-hdpi\Icon.png" />
80+
<AndroidResource Include="Resources\mipmap-hdpi\launcher_foreground.png" />
81+
<AndroidResource Include="Resources\mipmap-mdpi\Icon.png" />
82+
<AndroidResource Include="Resources\mipmap-mdpi\launcher_foreground.png" />
83+
<AndroidResource Include="Resources\mipmap-xhdpi\Icon.png" />
84+
<AndroidResource Include="Resources\mipmap-xhdpi\launcher_foreground.png" />
85+
<AndroidResource Include="Resources\mipmap-xxhdpi\Icon.png" />
86+
<AndroidResource Include="Resources\mipmap-xxhdpi\launcher_foreground.png" />
87+
<AndroidResource Include="Resources\mipmap-xxxhdpi\Icon.png" />
88+
<AndroidResource Include="Resources\mipmap-xxxhdpi\launcher_foreground.png" />
89+
</ItemGroup>
90+
<ItemGroup>
91+
<Folder Include="Resources\drawable-hdpi\" />
92+
<Folder Include="Resources\drawable-xhdpi\" />
93+
<Folder Include="Resources\drawable-xxhdpi\" />
94+
<Folder Include="Resources\drawable-xxxhdpi\" />
95+
<Folder Include="Resources\drawable\" />
96+
</ItemGroup>
97+
<ItemGroup>
98+
<ProjectReference Include="..\BlurViewFormsSample\BlurViewFormsSample.csproj">
99+
<Project>{1C0E1B6E-FC6E-40BB-9726-E32CCC718501}</Project>
100+
<Name>BlurViewFormsSample</Name>
101+
</ProjectReference>
102+
</ItemGroup>
103+
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
104+
</Project>
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Android.App;
2+
using Android.Content;
3+
using Android.Views;
4+
using Android.Widget;
5+
6+
using Xamarin.Forms;
7+
using Xamarin.Forms.Platform.Android;
8+
9+
using Com.EightbitLab.BlurViewBinding;
10+
11+
using BlurViewFormsSample;
12+
using BlurViewFormsSample.Droid;
13+
14+
[assembly: ExportRenderer(typeof(FormsBlurView), typeof(FormsBlurViewRenderer))]
15+
16+
namespace BlurViewFormsSample.Droid
17+
{
18+
public class FormsBlurViewRenderer : ViewRenderer<FormsBlurView, FrameLayout>
19+
{
20+
public FormsBlurViewRenderer(Context context) : base(context)
21+
{
22+
}
23+
24+
protected override void OnElementChanged(ElementChangedEventArgs<FormsBlurView> e)
25+
{
26+
base.OnElementChanged(e);
27+
28+
if (Control == null)
29+
{
30+
var context = Context;
31+
var activity = context as Activity;
32+
33+
var rootView = (ViewGroup) activity.Window.DecorView.FindViewById(Android.Resource.Id.Content);
34+
var windowBackground = activity.Window.DecorView.Background;
35+
36+
var blurView = new BlurView(context);
37+
38+
blurView.SetOverlayColor(Resource.Color.colorOverlay);
39+
40+
blurView.SetupWith(rootView)
41+
.WindowBackground(windowBackground)
42+
.BlurAlgorithm(new RenderScriptBlur(context))
43+
.BlurRadius(10f);
44+
45+
SetNativeControl(blurView);
46+
}
47+
}
48+
}
49+
}
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
3+
using Android.App;
4+
using Android.Content.PM;
5+
using Android.Runtime;
6+
using Android.Views;
7+
using Android.Widget;
8+
using Android.OS;
9+
10+
namespace BlurViewFormsSample.Droid
11+
{
12+
[Activity(Label = "BlurViewFormsSample", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
13+
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
14+
{
15+
protected override void OnCreate(Bundle bundle)
16+
{
17+
TabLayoutResource = Resource.Layout.Tabbar;
18+
ToolbarResource = Resource.Layout.Toolbar;
19+
20+
base.OnCreate(bundle);
21+
22+
global::Xamarin.Forms.Forms.Init(this, bundle);
23+
LoadApplication(new App());
24+
}
25+
}
26+
}
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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">
3+
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
4+
<application android:label="BlurViewFormsSample.Android"></application>
5+
</manifest>
+34Lines changed: 34 additions & 0 deletions
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("BlurViewFormsSample.Android")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("BlurViewFormsSample.Android")]
14+
[assembly: AssemblyCopyright("Copyright © Yauheni Pakala 2018")]
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.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.