This repository was archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 488
[Enhancement] Save To Gallery #1628
Closed
Closed
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
819c6f9
init SaveToGalery
dimonovdd a5d1a9f
fixed typos
dimonovdd 6cc65af
Merge branch 'main' into featureSaveToGalery
mattleibow be537b6
Merge branch 'main' into featureSaveToGalery
dimonovdd e78d168
Merge branch 'main' into featureSaveToGalery
dimonovdd 797bc90
added SaveToGaleryTestPhoto.jpg
dimonovdd ebde333
implementation for creating photos albums on ios
dimonovdd b376239
implementation for saving images and video files with metada on ios
dimonovdd eaa70f2
Merge branch 'main' into featureSaveToGalery
dimonovdd 7e358a5
- implementation for saving images and video files from filePath on ios
dimonovdd 9743df7
- implementation for saving images and video files from byte array, f…
dimonovdd ba09fb3
init SaveToGalery
dimonovdd 3fa012b
fixed typos
dimonovdd 37f8c02
added SaveToGaleryTestPhoto.jpg
dimonovdd c8a35d6
implementation for creating photos albums on ios
dimonovdd 9c83cd9
implementation for saving images and video files with metada on ios
dimonovdd 702dbbf
- implementation for saving images and video files from filePath on ios
dimonovdd 7e3b885
- implementation for saving images and video files from byte array, f…
dimonovdd b647ab9
Merge branch 'featureSaveToGalery' of https://github.com/dimonovdd/Es…
dimonovdd 42396aa
added macos implementation
dimonovdd e914f8e
Merge branch 'main' into featureSaveToGalery
dimonovdd c53a910
- impl UWP
dimonovdd 665b88a
cleanup android implementation
dimonovdd fe8ba32
changes for PHAuthorizationStatus.Limited (iOS)
dimonovdd d8b4045
Removed DATE_TAKEN from SaveAsync method on droid
dimonovdd ee6335b
Merge branch 'main' into featureSaveToGalery
dimonovdd 4d919db
reset DeviceTests.Android.csproj
dimonovdd 3d79bfb
Renaming from SaveToGallery to MediaGallery
dimonovdd 8cee060
updating sample and adding sample media files
dimonovdd 8f14db4
added test for Save to gallery
dimonovdd 5d95923
removed the functionality for creating albums
dimonovdd b71de73
fix typos in MediaGallery Tests
dimonovdd b5d5a6e
add docs and fix uwp
dimonovdd c722861
Merge branch 'main' into featureSaveToGalery
dimonovdd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,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> |
This file contains hidden or 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,10 @@ | ||
| namespace Samples.View | ||
| { | ||
| public partial class SaveToGalleryPage : BasePage | ||
| { | ||
| public SaveToGalleryPage() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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,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); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,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) => { }); | ||
| return Task.CompletedTask; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,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); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
Xamarin.Essentials/SaveToGallery/SaveToGallery.uwp.tizen.macos.netstandard.tvos.watchos.cs
This file contains hidden or 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,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; | ||
| } | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.