Exemplo n.º 1
0
            FileInfo SaveResult(Uri uri)
            {
                var result = IO.CreateTempDirectory(globalCache: false).GetFile($"File.{ShortGuid.NewGuid()}." + "mp4".OnlyWhen(IsVideo).Or("jpg"));

                var fileUri = uri ?? FileUrlPath;

                if (fileUri?.Scheme == "file")
                {
                    var file = new System.Uri(fileUri.ToString()).LocalPath;
                    if (file != result.FullName)
                    {
                        File.Copy(file, result.FullName);
                    }
                }
                else if (fileUri?.Scheme == "content")
                {
                    SaveContentToFile(fileUri, result);
                }

                try { if (PurgeCameraRoll)
                      {
                          ContentResolver.Delete(fileUri, null, null);
                      }
                }
                catch { }

                return(result);
            }
Exemplo n.º 2
0
        public static void EliminarFotoMemoria(string odt, ContentResolver _resolver)
        {
            List <Fotos> Mem = Utils.FotosMemoria;

            if (Mem != null)
            {
                foreach (Fotos f in Mem)
                {
                    if (f.IdODT == odt)
                    {
                        if (System.IO.File.Exists(f.Url))
                        {
                            int i = _resolver.Delete(MediaStore.Images.Thumbnails.ExternalContentUri, MediaStore.Images.Thumbnails.ImageId + " = ?", new String[] { "" + f.UrlId });
                            Application.Context.ContentResolver.Delete(MediaStore.Images.Media.ExternalContentUri, BaseColumns.Id + "=" + f.UrlId, null);
                            if (i > 0)
                            {
                                System.IO.File.Delete(f.Url);
                                Mem.Remove(f);
                            }
                        }
                    }
                }

                Utils.FotosMemoria = Mem;
            }
        }
Exemplo n.º 3
0
        private void RemoveCalendar(long calID)
        {
            Android.Net.Uri.Builder builder1 = CalendarContract.Calendars.ContentUri.BuildUpon();
            builder1.AppendQueryParameter(CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName, Constants.DEVICE_CALENDAR_TITLE);

            String[] selArgs = new String[] { Constants.DEVICE_CALENDAR_TITLE };
            int      deleted = ContentResolver.Delete(CalendarContract.Calendars.ContentUri, CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName + " =? ", selArgs);
        }
Exemplo n.º 4
0
 public void DeleteCallLogByNumber(string number)
 {
     try
     {
         Android.Net.Uri CALLLOG_URI = Android.Net.Uri.Parse("content://call_log/calls");
         ContentResolver.Delete(CALLLOG_URI, CallLog.Calls.Number + "=?", new string[] { number });
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 5
0
        private void AddPlaylistToIndex(bool utf8)
        {
            string name = utf8 ? "haplaylist8" : "haplaylist";

            ContentResolver.Delete(MediaStore.Audio.Playlists.ExternalContentUri, "name == ?", new string[] { name });
            ContentValues cv = new ContentValues();

            cv.Put("name", name);
            cv.Put("_data", getPlaylistPath(utf8));
            cv.Put("date_added", DateTime.Now.ToFileTime());
            cv.Put("date_modified", DateTime.Now.ToFileTime());
            ContentResolver.Insert(MediaStore.Audio.Playlists.ExternalContentUri, cv);
        }
Exemplo n.º 6
0
 private void RemoveEvent(long eventID)
 {
     String[] selArgs = new String[] { eventID.ToString() };
     int      deleted = ContentResolver.Delete(CalendarContract.Events.ContentUri, "_id =? ", selArgs);
 }
Exemplo n.º 7
0
        public static Dictionary <long, string> GetMediaThumbnailsPaths(ContentResolver contentResolver, ThumbnailKind kind)
        {
            string[] columns =
            {
                MediaStore.Images.Thumbnails.Data,
                MediaStore.Images.Thumbnails.ImageId
            };

            var cursor = contentResolver.Query(MediaStore.Images.Thumbnails.ExternalContentUri, columns, $"{MediaStore.Images.Thumbnails.Kind} = {(int)kind}", null, null);

            var dic       = new Dictionary <long, string>();
            var dublicate = new HashSet <long>();

            if (cursor != null)
            {
                var count           = cursor.Count;
                var dataColumnIndex = cursor.GetColumnIndex(MediaStore.Images.Thumbnails.Data);
                var idColumnIndex   = cursor.GetColumnIndex(MediaStore.Images.Thumbnails.ImageId);

                for (var i = 0; i < count; i++)
                {
                    cursor.MoveToPosition(i);
                    var key   = cursor.GetLong(idColumnIndex);
                    var value = cursor.GetString(dataColumnIndex);
                    if (dic.ContainsKey(key))
                    {
                        dublicate.Add(key);
                        var file = new File(dic[key]);
                        if (file.Exists())
                        {
                            file.Delete();
                        }

                        file = new File(value);
                        if (file.Exists())
                        {
                            file.Delete();
                        }

                        contentResolver.Delete(MediaStore.Images.Thumbnails.ExternalContentUri, MediaStore.Images.Thumbnails.ImageId + "=?", new[] { key.ToString() });

                        dic.Remove(key);
                    }
                    else if (dublicate.Contains(key))
                    {
                        var file = new File(value);
                        if (file.Exists())
                        {
                            file.Delete();
                        }
                    }
                    else
                    {
                        dic.Add(key, value);
                    }
                }

                cursor.Close();
            }
            return(dic);
        }
Exemplo n.º 8
0
        public static String insertImage(ContentResolver cr,
                                         Bitmap source,
                                         String title,
                                         String description)
        {
            ContentValues values = new ContentValues();

            values.Put(MediaStore.Images.ImageColumns.Title, title);
            values.Put(MediaStore.Images.ImageColumns.DisplayName, title);
            values.Put(MediaStore.Images.ImageColumns.Description, description);
            values.Put(MediaStore.Images.ImageColumns.MimeType, "image/jpeg");
            // Add the date meta data to ensure the image is added at the front of the gallery
            values.Put(MediaStore.Images.ImageColumns.DateAdded, CurrentTimeMillis());// System.currentTimeMillis());
            values.Put(MediaStore.Images.ImageColumns.DateTaken, CurrentTimeMillis());

            Android.Net.Uri url       = null;
            String          stringUrl = null; /* value to be returned */

            try
            {
                url = cr.Insert(MediaStore.Images.Media.InternalContentUri, values);

                if (source != null)
                {
                    System.IO.Stream imageOut = cr.OpenOutputStream(url);
                    try
                    {
                        source.Compress(Bitmap.CompressFormat.Jpeg, 50, imageOut);
                    }
                    finally
                    {
                        imageOut.Close();
                    }

                    long id = ContentUris.ParseId(url);
                    // Wait until MINI_KIND thumbnail is generated.
                    Bitmap miniThumb = MediaStore.Images.Thumbnails.GetThumbnail(cr, id, ThumbnailKind.MiniKind, null);
                    // This is for backward compatibility.
                    storeThumbnail(cr, miniThumb, id, 50F, 50F, 3); //ThumbnailKind id
                }
                else
                {
                    cr.Delete(url, null, null);
                    url = null;
                }
            }
            catch (Exception e)
            {
                if (url != null)
                {
                    cr.Delete(url, null, null);
                    url = null;
                }
            }

            if (url != null)
            {
                stringUrl = url.ToString();
            }

            return(stringUrl);
        }
Exemplo n.º 9
0
        public async void DownloadPlaylist(List <DownloadFile> files, long LocalID, bool keepDeleted)
        {
            if (LocalID != -1)
            {
                List <Song> songs = await PlaylistManager.GetTracksFromLocalPlaylist(LocalID);

                await Task.Run(() =>
                {
                    foreach (Song song in songs)
                    {
                        LocalManager.CompleteItem(song);
                    }
                });

                for (int i = 0; i < files.Count; i++)
                {
                    Song song = songs.Find(x => x.YoutubeID == files[i].YoutubeID);
                    if (song != null)
                    {
                        //Video is already in the playlist, we want to check if this item has been reordered.
                        if (int.Parse(song.TrackID) != i)
                        {
                            //The plus one is because android playlists have one-based indexes.
                            PlaylistManager.SetQueueSlot(LocalID, song.LocalID, i + 1);
                        }

                        //Video is already downloaded:
                        if (files[i].State == DownloadState.None)
                        {
                            files[i].State = DownloadState.UpToDate;
                        }

                        currentStrike++;
                        songs.Remove(song);
                    }
                }

                queue.RemoveAll(x => x.State == DownloadState.Completed || x.State == DownloadState.UpToDate || x.State == DownloadState.Canceled);
                if (files.Count(x => x.State == DownloadState.None) > 0)
                {
                    queue.AddRange(files);
                    StartDownload();
                }
                else
                {
                    Toast.MakeText(MainActivity.instance, Resource.String.playlist_uptodate, ToastLength.Long).Show();
                }

                await Task.Run(() =>
                {
                    if (Looper.MyLooper() == null)
                    {
                        Looper.Prepare();
                    }

                    for (int i = 0; i < songs.Count; i++)
                    {
                        //Video has been removed from the playlist but still exist on local storage
                        ContentResolver resolver = Application.ContentResolver;
                        Uri uri = Playlists.Members.GetContentUri("external", LocalID);
                        resolver.Delete(uri, Playlists.Members.Id + "=?", new string[] { songs[i].LocalID.ToString() });

                        if (!keepDeleted)
                        {
                            File.Delete(songs[i].Path);
                        }
                    }
                });
            }

            await Task.Delay(1000);

            Playlist.instance?.CheckForSync();
        }
Exemplo n.º 10
0
        async Task <bool> ValidateChanges(bool displayActionIfMountFail = false)
        {
            System.Console.WriteLine("&Validaing changes");
            if (song.Title == title.Text && song.Artist == artist.Text && song.YoutubeID == youtubeID.Text && song.Album == album.Text && artURI == null)
            {
                return(true);
            }

            System.Console.WriteLine("&Requesting permission");
            const string permission = Manifest.Permission.WriteExternalStorage;

            hasPermission = Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this, permission) == (int)Permission.Granted;
            if (!hasPermission)
            {
                string[] permissions = new string[] { permission };
                RequestPermissions(permissions, RequestCode);

                while (!hasPermission)
                {
                    await Task.Delay(1000);
                }
            }

            if (!Environment.MediaMounted.Equals(Environment.GetExternalStorageState(new Java.IO.File(song.Path))))
            {
                Snackbar snackBar = Snackbar.Make(FindViewById <CoordinatorLayout>(Resource.Id.snackBar), Resource.String.mount_error, Snackbar.LengthLong);
                snackBar.View.FindViewById <TextView>(Resource.Id.snackbar_text).SetTextColor(Color.White);
                if (displayActionIfMountFail)
                {
                    snackBar.SetAction(Resource.String.mount_error_action, (v) =>
                    {
                        Finish();
                    });
                }
                snackBar.Show();
                return(false);
            }

            try
            {
                System.Console.WriteLine("&Creating write stream");
                Stream stream = new FileStream(song.Path, FileMode.Open, FileAccess.ReadWrite);
                var    meta   = TagLib.File.Create(new StreamFileAbstraction(song.Path, stream, stream));

                System.Console.WriteLine("&Writing tags");
                meta.Tag.Title      = title.Text;
                song.Title          = title.Text;
                meta.Tag.Performers = new string[] { artist.Text };
                song.Artist         = artist.Text;
                meta.Tag.Album      = album.Text;
                song.Album          = album.Text;
                meta.Tag.Comment    = youtubeID.Text;
                if (queuePosition != -1 && MusicPlayer.queue.Count > queuePosition)
                {
                    MusicPlayer.queue[queuePosition] = song;
                    Player.instance?.RefreshPlayer();
                    Queue.instance.NotifyItemChanged(queuePosition);
                }

                if (ytThumbUri != null)
                {
                    System.Console.WriteLine("&Writing YT Thumb");
                    await Task.Run(() =>
                    {
                        IPicture[] pictures = new IPicture[1];
                        Bitmap bitmap       = Picasso.With(Application.Context).Load(ytThumbUri).Transform(new RemoveBlackBorder(true)).Get();
                        byte[] data;
                        using (var MemoryStream = new MemoryStream())
                        {
                            bitmap.Compress(Bitmap.CompressFormat.Png, 0, MemoryStream);
                            data = MemoryStream.ToArray();
                        }
                        bitmap.Recycle();
                        pictures[0]       = new Picture(data);
                        meta.Tag.Pictures = pictures;

                        ytThumbUri = null;
                    });
                }
                else if (artURI != null)
                {
                    System.Console.WriteLine("&Writing ArtURI");
                    IPicture[] pictures = new IPicture[1];

                    Bitmap bitmap = null;
                    if (tempFile)
                    {
                        await Task.Run(() =>
                        {
                            bitmap = Picasso.With(this).Load(artURI).Transform(new RemoveBlackBorder(true)).Get();
                        });
                    }
                    else
                    {
                        await Task.Run(() =>
                        {
                            bitmap = Picasso.With(this).Load(artURI).Get();
                        });
                    }

                    MemoryStream memoryStream = new MemoryStream();
                    bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, memoryStream);
                    byte[] data = memoryStream.ToArray();
                    pictures[0]       = new Picture(data);
                    meta.Tag.Pictures = pictures;

                    if (!tempFile)
                    {
                        artURI = null;
                    }

                    ContentResolver.Delete(ContentUris.WithAppendedId(Android.Net.Uri.Parse("content://media/external/audio/albumart"), song.AlbumArt), null, null);
                }

                System.Console.WriteLine("&Saving");
                meta.Save();
                stream.Dispose();
            }
            catch (System.Exception e)
            {
                Toast.MakeText(this, Resource.String.format_unsupported, ToastLength.Long).Show();
                System.Console.WriteLine("&EditMetadata Validate exception: (probably due to an unsupported format) - " + e.Message);
            }

            System.Console.WriteLine("&Deleting temp file");
            if (tempFile)
            {
                tempFile = false;
                System.IO.File.Delete(artURI.Path);
                artURI = null;
            }

            System.Console.WriteLine("&Scanning file");
            await Task.Delay(10);

            Android.Media.MediaScannerConnection.ScanFile(this, new string[] { song.Path }, null, null);

            Toast.MakeText(this, Resource.String.changes_saved, ToastLength.Short).Show();
            return(true);
        }