Skip to content

Commit

Permalink
added Xamarin.Forms sample
Browse files Browse the repository at this point in the history
  • Loading branch information
NateRickard committed Sep 21, 2017
1 parent 9006526 commit 3123b87
Show file tree
Hide file tree
Showing 91 changed files with 1,825 additions and 24 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Expand Up @@ -223,3 +223,11 @@ Samples/AudioRecord.UWP/project.lock.json
Plugin.AudioRecorder.NuGet/Plugin.AudioRecorder.NuGet.nuget.props

Plugin.AudioRecorder.NuGet/Plugin.AudioRecorder.NuGet.nuget.targets
Plugin.AudioRecorder.UWP/Plugin.AudioRecorder.UWP.nuget.props
Plugin.AudioRecorder.UWP/Plugin.AudioRecorder.UWP.nuget.props
Samples/Forms/AudioRecord.Forms.UWP/AudioRecord.Forms.UWP.nuget.targets
Samples/Forms/AudioRecord.Forms.UWP/project.lock.json
Samples/Native/AudioRecord.UWP/AudioRecord.UWP.nuget.props
Samples/Native/AudioRecord.UWP/project.lock.json
Samples/Native/AudioRecord.UWP/project.lock.json
Plugin.AudioRecorder.UWP/Plugin.AudioRecorder.UWP.nuget.props
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">C:\Users\Administrator\Documents\Repos\PartnerTeam\Projects\Plugin.AudioRecorder\Plugin.AudioRecorder.UWP\project.lock.json</ProjectAssetsFile>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">C:\Repos\PartnerTeam\Projects\Plugin.AudioRecorder\Plugin.AudioRecorder.UWP\project.lock.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Administrator\.nuget\packages\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">ProjectJson</NuGetProjectStyle>
Expand Down
187 changes: 187 additions & 0 deletions Plugin.AudioRecorder.sln

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions Samples/Forms/AudioRecord.Forms.Android/Assets/AboutAssets.txt
@@ -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 you 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");
72 changes: 72 additions & 0 deletions Samples/Forms/AudioRecord.Forms.Android/AudioPlayer.cs
@@ -0,0 +1,72 @@
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 Android.Media;

namespace AudioRecord.Forms
{
public partial class AudioPlayer
{
private MediaPlayer _mediaPlayer;

public event EventHandler FinishedPlaying;

public AudioPlayer ()
{
}


public void Play (string pathToAudioFile)
{
if (_mediaPlayer != null)
{
_mediaPlayer.Completion -= MediaPlayer_Completion;
_mediaPlayer.Stop ();
}

if (pathToAudioFile != null)
{
if (_mediaPlayer == null)
{
_mediaPlayer = new MediaPlayer ();

_mediaPlayer.Prepared += (sender, args) =>
{
_mediaPlayer.Start ();
_mediaPlayer.Completion += MediaPlayer_Completion;
};
}

_mediaPlayer.Reset ();
//_mediaPlayer.SetVolume (1.0f, 1.0f);

_mediaPlayer.SetDataSource (pathToAudioFile);
_mediaPlayer.PrepareAsync ();
}
}


void MediaPlayer_Completion (object sender, EventArgs e)
{
FinishedPlaying?.Invoke (this, EventArgs.Empty);
}

public void Pause ()
{
_mediaPlayer?.Pause ();
}

public void Play ()
{
_mediaPlayer?.Start ();
}
}
}

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions Samples/Forms/AudioRecord.Forms.Android/MainActivity.cs
@@ -0,0 +1,27 @@
using System;

using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace AudioRecord.Forms.Droid
{
[Activity (Label = "AudioRecord.Forms", Icon = "@drawable/icon", Theme="@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate (Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate (bundle);

global::Xamarin.Forms.Forms.Init (this, bundle);
LoadApplication (new AudioRecord.Forms.App ());
}
}
}

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application android:label="AudioRecord.Forms.Android"></application>
</manifest>
34 changes: 34 additions & 0 deletions Samples/Forms/AudioRecord.Forms.Android/Properties/AssemblyInfo.cs
@@ -0,0 +1,34 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AudioRecord.Forms.Android")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AudioRecord.Forms.Android")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

// Add some common permissions, these can be removed if not needed
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
@@ -0,0 +1,50 @@
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-hdpi/
icon.png

drawable-ldpi/
icon.png

drawable-mdpi/
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" 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 R.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.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
@@ -0,0 +1,9 @@
<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" />

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<resources>

<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>

<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
</style>

<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
</resources>
22 changes: 22 additions & 0 deletions Samples/Forms/AudioRecord.Forms.Android/packages.config
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Plugin.AudioRecorder" version="0.8.0" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.Annotations" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.Compat" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.Core.UI" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.Core.Utils" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.Design" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.Fragment" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.Media.Compat" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.Transition" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.v4" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.v7.CardView" version="23.3.0" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.v7.MediaRouter" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.v7.Palette" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.v7.RecyclerView" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="25.3.1" targetFramework="monoandroid71" />
<package id="Xamarin.Build.Download" version="0.4.3" targetFramework="monoandroid71" />
<package id="Xamarin.Forms" version="2.3.4.270" targetFramework="monoandroid71" />
</packages>
8 changes: 8 additions & 0 deletions Samples/Forms/AudioRecord.Forms.UWP/App.xaml
@@ -0,0 +1,8 @@
<Application
x:Class="AudioRecord.Forms.UWP.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AudioRecord.Forms.UWP"
RequestedTheme="Light">

</Application>

0 comments on commit 3123b87

Please sign in to comment.