Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Merge d96dafb into c366087
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno authored Mar 6, 2020
2 parents c366087 + d96dafb commit 31079b4
Show file tree
Hide file tree
Showing 25 changed files with 5,722 additions and 3,123 deletions.
30 changes: 19 additions & 11 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ root = true

# Don't use tabs for indentation.
[*]
indent_style = tab
indent_style = space
# (Please don't specify an indent_size here; that has too many unintended consequences.)

# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4

# Code files
[*.sln]
indent_size = 4

# Xml project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2
Expand All @@ -23,10 +27,14 @@ indent_size = 2
[*.json]
indent_size = 2

# XML files
[*.xml]
indent_size = 2

# Dotnet code style settings:
[*.{cs,vb}]
# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = false
dotnet_sort_system_directives_first = true
# Avoid "this." and "Me." if not necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
Expand All @@ -36,6 +44,7 @@ dotnet_style_qualification_for_event = false:suggestion
# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
dotnet_style_require_accessibility_modifiers = omit_if_default:warning

# Suggest more modern language features when available
dotnet_style_object_initializer = true:suggestion
Expand All @@ -55,7 +64,7 @@ dotnet_naming_rule.methods_and_properties_must_be_pascal_case.symbols = method_a
dotnet_naming_rule.methods_and_properties_must_be_pascal_case.style = pascal_case_style

# Non-public members must be lower-case
dotnet_naming_symbols.non_public_symbols.applicable_kinds = field,event,delegate
dotnet_naming_symbols.non_public_symbols.applicable_kinds = field
dotnet_naming_symbols.non_public_symbols.applicable_accessibilities = private
dotnet_naming_style.all_lower_case_style.capitalization = camel_case

Expand All @@ -66,19 +75,19 @@ dotnet_naming_rule.non_public_members_must_be_lower_case.style = all_lower_case_
# CSharp code style settings:
[*.cs]
# Do not prefer "var" everywhere
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = true:error
csharp_style_var_when_type_is_apparent = true:error
csharp_style_var_elsewhere = true:error

# Prefer method-like constructs to have a block body
csharp_style_expression_bodied_methods = true:suggestion
csharp_style_expression_bodied_constructors = true:none
csharp_style_expression_bodied_operators = true:none
csharp_style_expression_bodied_constructors = true:suggestion
csharp_style_expression_bodied_operators = true:suggestion

# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none
csharp_style_expression_bodied_indexers = true:suggestion
csharp_style_expression_bodied_accessors = true:suggestion

# Suggest more modern language features when available
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
Expand All @@ -94,4 +103,3 @@ csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true

59 changes: 15 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Ported from [Xamarin.Mobile](http://www.github.com/xamarin/xamarin.mobile) to a

### Setup
* Available on NuGet: http://www.nuget.org/packages/Xam.Plugin.Media [![NuGet](https://img.shields.io/nuget/v/Xam.Plugin.Media.svg?label=NuGet)](https://www.nuget.org/packages/Xam.Plugin.Media/)
* Install into your PCL/.NET Standard project and Client projects.
* Install into your .NET Standard project and Client projects.
* Please see the additional setup for each platforms permissions.

Build Status:
Expand Down Expand Up @@ -253,24 +253,11 @@ public override void OnRequestPermissionsResult(int requestCode, string[] permis
}
```

## Android Current Activity Setup
## Android Required Setup

This plugin uses the [Current Activity Plugin](https://github.com/jamesmontemagno/CurrentActivityPlugin/blob/master/README.md) to get access to the current Android Activity. Be sure to complete the full setup if a MainApplication.cs file was not automatically added to your application. Please fully read through the [Current Activity Plugin Documentation](https://github.com/jamesmontemagno/CurrentActivityPlugin/blob/master/README.md). At an absolute minimum you must set the following in your Activity's OnCreate method:
This plugin uses the Xamarin.Essentials, please follow the setup guide.

```csharp
CrossCurrentActivity.Current.Init(this, bundle);
```

It is highly recommended that you use a custom Application that are outlined in the Current Activity Plugin Documentation](https://github.com/jamesmontemagno/CurrentActivityPlugin/blob/master/README.md)

## Android Misc Setup

By default, the library adds `android.hardware.camera` and `android.hardware.camera.autofocus` to your apps manifest as optional features. It is your responsbility to check whether your device supports the hardware before using it. If instead you'd like [Google Play to filter out devices](http://developer.android.com/guide/topics/manifest/uses-feature-element.html#permissions-features) without the required hardware, add the following to your AssemblyInfo.cs file in your Android project:

```
[assembly: UsesFeature("android.hardware.camera", Required = true)]
[assembly: UsesFeature("android.hardware.camera.autofocus", Required = true)]
```
Xamarin.Essentials.Platform.Init(this, bundle);


#### Android File Provider Setup
Expand Down Expand Up @@ -302,6 +289,15 @@ Add the following code:

You can read more at: https://developer.android.com/training/camera/photobasics.html

## Android Optional Setup

By default, the library adds `android.hardware.camera` and `android.hardware.camera.autofocus` to your apps manifest as optional features. It is your responsbility to check whether your device supports the hardware before using it. If instead you'd like [Google Play to filter out devices](http://developer.android.com/guide/topics/manifest/uses-feature-element.html#permissions-features) without the required hardware, add the following to your AssemblyInfo.cs file in your Android project:

```
[assembly: UsesFeature("android.hardware.camera", Required = true)]
[assembly: UsesFeature("android.hardware.camera.autofocus", Required = true)]
```


#### iOS

Expand All @@ -328,34 +324,9 @@ Set `Webcam` permission.


### Permission Recommendations
By default, the Media Plugin will attempt to request multiple permissions, but each platform handles this a bit differently, such as iOS which will only pop up permissions once. I recommend adding the [Permissions Plugin](http://github.com/jamesmontemagno/PermissionsPlugin) into your application and before taking any photo or picking photos that you check permissions ahead of time.

Here is an example:
```csharp
var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync<CameraPermission>();
var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync<StoragePermission>();
By default, the Media Plugin will attempt to request multiple permissions, but each platform handles this a bit differently, such as iOS which will only pop up permissions once.

if (cameraStatus != PermissionStatus.Granted || storageStatus != PermissionStatus.Granted)
{
cameraStatus = await CrossPermissions.Current.RequestPermissionAsync<CameraPermission>();
storageStatus = await CrossPermissions.Current.RequestPermissionAsync<StoragePermission>();
}

if (cameraStatus == PermissionStatus.Granted && storageStatus == PermissionStatus.Granted)
{
var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
{
Directory = "Sample",
Name = "test.jpg"
});
}
else
{
await DisplayAlert("Permissions Denied", "Unable to take photos.", "OK");
//On iOS you may want to send your user to the settings screen.
//CrossPermissions.Current.OpenAppSettings();
}
```
You can use Xamarin.Essentials to request and check permissions manually.

#### FAQ
Here are some common answers to questions:
Expand Down
12 changes: 3 additions & 9 deletions nuget/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,12 @@ You must also add a few additional configuration files to adhere to the new stri

You can read more at: https://developer.android.com/training/camera/photobasics.html

Android Current Activity Setup
Android:

This plugin uses the Current Activity Plugin (https://github.com/jamesmontemagno/CurrentActivityPlugin/blob/master/README.md) to get access to the current Android Activity.
Be sure to complete the full setup if a MainApplication.cs file was not automatically added to your application.
This plugin uses the Xamarin.Essentials, please follow the setup guide.

Please fully read through the Current Activity Plugin Documentation at https://github.com/jamesmontemagno/CurrentActivityPlugin/blob/master/README.md.
At an absolute MINIMUM you must set the following in your Activity's OnCreate method:
Xamarin.Essentials.Platform.Init(this, bundle);

CrossCurrentActivity.Current.Init(this, bundle);


It is highly recommended that you use a custom Application that are outlined in the Current Activity Plugin Documentation https://github.com/jamesmontemagno/CurrentActivityPlugin/blob/master/README.md

iOS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using Android.Views;
using Android.Widget;
using Android.OS;
using Plugin.CurrentActivity;
using Plugin.Permissions;

namespace Media.Plugin.Sample.Droid
{
Expand All @@ -21,17 +19,18 @@ protected override void OnCreate(Bundle bundle)

base.OnCreate(bundle);
FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true);
CrossCurrentActivity.Current.Init(this, bundle);
Xamarin.Essentials.Platform.Init(this, bundle);
Xamarin.Forms.Forms.Init(this, bundle);
Android.Glide.Forms.Init(this);
LoadApplication(new App());
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults)
{
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
Expand Down Expand Up @@ -49,20 +49,15 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="glidex.forms">
<Version>2.0.0.336</Version>
<Version>2.0.1.394</Version>
</PackageReference>
<PackageReference Include="Plugin.Permissions">
<Version>5.0.0-beta</Version>
<PackageReference Include="Xamarin.Essentials">
<Version>1.5.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.FFImageLoading.Forms">
<Version>2.4.11.982</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="4.3.0.947036" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Forms" Version="4.5.0.356" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +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.companyname.Media.Plugin.Sample">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28" />
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="29" />
<application android:label="Media.Plugin.Sample.Android">
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
Expand Down
Loading

0 comments on commit 31079b4

Please sign in to comment.