Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
819c6f9
init SaveToGalery
dimonovdd Jan 9, 2021
a5d1a9f
fixed typos
dimonovdd Jan 10, 2021
6cc65af
Merge branch 'main' into featureSaveToGalery
mattleibow Jan 15, 2021
be537b6
Merge branch 'main' into featureSaveToGalery
dimonovdd Jan 16, 2021
e78d168
Merge branch 'main' into featureSaveToGalery
dimonovdd Jan 24, 2021
797bc90
added SaveToGaleryTestPhoto.jpg
dimonovdd Jan 24, 2021
ebde333
implementation for creating photos albums on ios
dimonovdd Jan 24, 2021
b376239
implementation for saving images and video files with metada on ios
dimonovdd Jan 25, 2021
eaa70f2
Merge branch 'main' into featureSaveToGalery
dimonovdd Jan 26, 2021
7e358a5
- implementation for saving images and video files from filePath on ios
dimonovdd Jan 26, 2021
9743df7
- implementation for saving images and video files from byte array, f…
dimonovdd Jan 30, 2021
ba09fb3
init SaveToGalery
dimonovdd Jan 9, 2021
3fa012b
fixed typos
dimonovdd Jan 10, 2021
37f8c02
added SaveToGaleryTestPhoto.jpg
dimonovdd Jan 24, 2021
c8a35d6
implementation for creating photos albums on ios
dimonovdd Jan 24, 2021
9c83cd9
implementation for saving images and video files with metada on ios
dimonovdd Jan 25, 2021
702dbbf
- implementation for saving images and video files from filePath on ios
dimonovdd Jan 26, 2021
7e3b885
- implementation for saving images and video files from byte array, f…
dimonovdd Jan 30, 2021
b647ab9
Merge branch 'featureSaveToGalery' of https://github.com/dimonovdd/Es…
dimonovdd Jan 30, 2021
42396aa
added macos implementation
dimonovdd Jan 30, 2021
e914f8e
Merge branch 'main' into featureSaveToGalery
dimonovdd Feb 13, 2021
c53a910
- impl UWP
dimonovdd Feb 13, 2021
665b88a
cleanup android implementation
dimonovdd Feb 13, 2021
fe8ba32
changes for PHAuthorizationStatus.Limited (iOS)
dimonovdd Feb 14, 2021
d8b4045
Removed DATE_TAKEN from SaveAsync method on droid
dimonovdd Feb 19, 2021
ee6335b
Merge branch 'main' into featureSaveToGalery
dimonovdd Feb 19, 2021
4d919db
reset DeviceTests.Android.csproj
dimonovdd Feb 20, 2021
3d79bfb
Renaming from SaveToGallery to MediaGallery
dimonovdd Feb 28, 2021
8cee060
updating sample and adding sample media files
dimonovdd Feb 28, 2021
8f14db4
added test for Save to gallery
dimonovdd Feb 28, 2021
5d95923
removed the functionality for creating albums
dimonovdd Apr 11, 2021
b71de73
fix typos in MediaGallery Tests
dimonovdd Apr 14, 2021
b5d5a6e
add docs and fix uwp
dimonovdd Apr 22, 2021
c722861
Merge branch 'main' into featureSaveToGalery
dimonovdd Jul 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions DeviceTests/DeviceTests.Android/DeviceTests.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<RootNamespace>DeviceTests.Droid</RootNamespace>
<AssemblyName>XamarinEssentialsDeviceTestsAndroid</AssemblyName>
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<AndroidApplication>True</AndroidApplication>
<AndroidUseIntermediateDesignerFile>true</AndroidUseIntermediateDesignerFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
Expand All @@ -19,6 +18,7 @@
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<AndroidSupportedAbis>armeabi-v7a;x86;x86_64;arm64-v8a</AndroidSupportedAbis>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -29,7 +29,6 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
<AndroidSupportedAbis>armeabi-v7a;x86;x86_64;arm64-v8a</AndroidSupportedAbis>
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
<AotAssemblies>false</AotAssemblies>
<EnableLLVM>false</EnableLLVM>
Expand All @@ -47,7 +46,6 @@
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<AndroidSupportedAbis>armeabi-v7a;x86;x86_64;arm64-v8a</AndroidSupportedAbis>
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
</PropertyGroup>
Expand Down
18 changes: 18 additions & 0 deletions Samples/Samples/View/SaveToGalleryPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<views:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Samples.View"
xmlns:viewmodels="clr-namespace:Samples.ViewModel"
x:Class="Samples.View.SaveToGalleryPage"
Title="Vibration">
<views:BasePage.BindingContext>
<viewmodels:SaveToGalleryViewModel />
</views:BasePage.BindingContext>

<ScrollView>
<StackLayout Padding="12" Spacing="12">
<Image Source="{Binding ImageUrl}"/>
<Button Text="Save image" Command="{Binding SaveCommand}" />
</StackLayout>
</ScrollView>

</views:BasePage>
10 changes: 10 additions & 0 deletions Samples/Samples/View/SaveToGalleryPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Samples.View
{
public partial class SaveToGalleryPage : BasePage
{
public SaveToGalleryPage()
{
InitializeComponent();
}
}
}
6 changes: 6 additions & 0 deletions Samples/Samples/ViewModel/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ public HomeViewModel()
typeof(WebAuthenticatorPage),
"Quickly and easily authenticate and wait for a callback.",
new[] { "auth", "authenticate", "authenticator", "web", "webauth" }),
new SampleItem(
"🖼",
"Save To Gallery",
typeof(SaveToGalleryPage),
"Save To Gallery",
new[] { "save", "gallery", "image", "jpg", "png" })
};
filteredItems = samples;
filterText = string.Empty;
Expand Down
34 changes: 34 additions & 0 deletions Samples/Samples/ViewModel/SaveToGalleryViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Net;
using System.Windows.Input;
using Xamarin.Essentials;
using Xamarin.Essentials.SaveToGallery;
using Xamarin.Forms;

namespace Samples.ViewModel
{
public class SaveToGalleryViewModel : BaseViewModel
{
public SaveToGalleryViewModel()
=> SaveCommand = new Command(Save);

public ICommand SaveCommand { get; }

public string ImageUrl
=> "https://raw.githubusercontent.com/xamarin/Essentials/main/Assets/xamarin.essentials_128x128.png";

async void Save()
{
try
{
using var client = new WebClient();
var data = await client.DownloadDataTaskAsync(ImageUrl);
await SaveToGallery.SaveImageAsync(data, "hhhh.png");
}
catch (Exception ex)
{
await DisplayAlertAsync(ex.Message);
}
}
}
}
82 changes: 82 additions & 0 deletions Xamarin.Essentials/SaveToGallery/SaveToGallery.android.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Android.Content;
using Android.Graphics;
using Android.Media;
using Android.OS;
using Android.Provider;
using Java.IO;
using Environment = Android.OS.Environment;
using File = Java.IO.File;
using Path = System.IO.Path;

namespace Xamarin.Essentials.SaveToGallery
{
public static partial class SaveToGallery
{
static async Task PlatformSaveImageAsync(byte[] data, string filename, string hhh)
{
try
{
#if MONOANDROID10_0
var bitmap = BitmapFactory.DecodeByteArray(data, 0, data.Length);
var resolver = Platform.AppContext.ContentResolver;
var contentValues = new ContentValues();
contentValues.Put(MediaStore.MediaColumns.DisplayName, filename);
contentValues.Put(MediaStore.MediaColumns.MimeType, "image/*");
contentValues.Put(MediaStore.MediaColumns.RelativePath, Environment.DirectoryPictures);
contentValues.Put(
MediaStore.MediaColumns.RelativePath,
Path.Combine(Environment.DirectoryPictures, AppInfo.Name));
var imageUri = resolver.Insert(MediaStore.Images.Media.ExternalContentUri, contentValues);
var fos = resolver.OpenOutputStream(imageUri);
var result = await bitmap.CompressAsync(Bitmap.CompressFormat.Jpeg, 100, fos);
fos?.Close();
#endif
#if !MONOANDROID10_0
var imagesDir = new File(
Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures),
AppInfo.Name);
imagesDir.Mkdirs();
var fos = new FileOutputStream(new File(imagesDir, filename));
await fos.WriteAsync(data);
fos?.Close();
#endif
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"HapticFeedback Exception: {ex.Message}");
}

// var folderDirectory = Platform.AppContext.GetExternalFilesDir(Environment.DirectoryDcim);

// using (var bitmapFile = new File(folderDirectory, filename))
// {
// bitmapFile.CreateNewFile();

// using (var outputStream = new FileOutputStream(bitmapFile))
// await outputStream.WriteAsync(data);

// MediaScannerConnection.ScanFile(
// Platform.CurrentActivity,
// new string[] { bitmapFile.Path },
// new string[] { "image/png", "image/jpeg" },
// null);
// }
// MediaStore.Images.Media.InsertImage

// var picturesDirectory = Environment.DirectoryPictures;

// var backingFile = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures), "count.png");
// await System.IO.File.WriteAllBytesAsync(backingFile, data);

// MediaScannerConnection.ScanFile(
// Platform.CurrentActivity,
// new string[] { backingFile },
// new string[] { "image/png", "image/jpeg" },
// null);
}
}
}
17 changes: 17 additions & 0 deletions Xamarin.Essentials/SaveToGallery/SaveToGallery.ios.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Threading.Tasks;
using Foundation;
using UIKit;

namespace Xamarin.Essentials.SaveToGallery
{
public static partial class SaveToGallery
{
static Task PlatformSaveImageAsync(byte[] data, string filename, string albumName)
{
var image = new UIImage(NSData.FromArray(data));
image.SaveToPhotosAlbum((UIImage img, NSError error) => { });
Comment thread
dimonovdd marked this conversation as resolved.
Outdated
return Task.CompletedTask;
}
}
}
11 changes: 11 additions & 0 deletions Xamarin.Essentials/SaveToGallery/SaveToGallery.shared.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Threading.Tasks;

namespace Xamarin.Essentials.SaveToGallery
{
public static partial class SaveToGallery
{
public static Task SaveImageAsync(byte[] data, string filename, string albumName = null)
=> PlatformSaveImageAsync(data, filename, albumName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Threading.Tasks;

namespace Xamarin.Essentials.SaveToGallery
{
public static partial class SaveToGallery
{
static Task PlatformSaveImageAsync(byte[] data, string filename, string albumName)
=> throw ExceptionUtils.NotSupportedOrImplementedException;
}
}
3 changes: 3 additions & 0 deletions Xamarin.Essentials/Xamarin.Essentials.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,8 @@
<ItemGroup>
<None Remove="mdoc.targets" />
</ItemGroup>
<ItemGroup>
<Folder Include="SaveToGallery\" />
</ItemGroup>
<Import Project="$(MSBuildThisFileDirectory)mdoc.targets" />
</Project>