Exemplo n.º 1
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View row = convertView;

            if (row == null)
            {
                row = LayoutInflater.From(context_).Inflate(Resource.Layout.SearchRow, null, false);
            }

            // Title
            TextView txtTitle = row.FindViewById <TextView>(Resource.Id.textViewRow);

            txtTitle.Text = items_[position].Title;

            // Url
            string valueUrl = items_[position].Url;

            // Thumbnail
            ImageView imageView = row.FindViewById <ImageView>(Resource.Id.imageView);

            // Author
            TextView txtAuthor = row.FindViewById <TextView>(Resource.Id.textViewRowAuthor);

            txtAuthor.Text = items_[position].Author;

            try
            {
                if (!String.IsNullOrEmpty(items_[position].Thumbnail))
                {
                    Picasso.With(this.context_).Load(items_[position].Thumbnail).Into(imageView);
                }
                else
                {
                    Picasso.With(this.context_).Load("file:///android_asset/Thumbnail.png").Into(imageView);
                }
            }
            catch
            {
            }

            // Duration
            TextView txtDuration = row.FindViewById <TextView>(Resource.Id.textViewDuration);

            txtDuration.Text = items_[position].Duration;

            // Play
            Button buttonPlay = row.FindViewById <Button>(Resource.Id.buttonRowPlay);

            var localPlay = new LocalOnclickListener();

            localPlay.HandleOnClick = () =>
            {
                ActivityContext.mActivity.RunOnUiThread(delegate
                {
                    if (valueUrl.Contains("youtube"))
                    {
                        new Android.Support.V7.App.AlertDialog.Builder(ActivityContext.mActivity)
                        .SetPositiveButton("Audio", (sender, e) =>
                        {
                            Thread thread = new Thread(() => play(valueUrl, txtTitle.Text, position, false));
                            thread.Start();
                        })
                        .SetNegativeButton("Video", (sender, e) =>
                        {
                            Thread thread = new Thread(() => play(valueUrl, txtTitle.Text, position, true));
                            thread.Start();
                        })
                        .SetTitle(txtTitle.Text)
                        .SetIcon(Resource.Drawable.Icon)
                        .Show();
                    }
                    else if (valueUrl.Contains("ccmixter"))
                    {
                        Thread thread = new Thread(() => play(valueUrl, txtTitle.Text, position, false));
                        thread.Start();
                    }
                    else
                    {
                        Thread thread = new Thread(() => play(valueUrl, txtTitle.Text, position, true));
                        thread.Start();
                    }
                });
            };

            buttonPlay.SetOnClickListener(localPlay);

            // Download
            Button buttonDownload = row.FindViewById <Button>(Resource.Id.buttonRowDownload);

            var localDownload = new LocalOnclickListener();

            localDownload.HandleOnClick = () =>
            {
                // Request permissions
#pragma warning disable CS4014
                ActivityContext.mActivity.RunOnUiThread(() => requestPermissionsAsync());
#pragma warning restore CS4014

                ActivityContext.mActivity.RunOnUiThread(delegate
                {
                    if (valueUrl.Contains("youtube"))
                    {
                        ActivityContext.mActivity.RunOnUiThread(delegate
                        {
                            new Android.Support.V7.App.AlertDialog.Builder(ActivityContext.mActivity)
                            .SetPositiveButton("Audio", (sender, e) =>
                            {
                                Thread thread = new Thread(() => searchActivity_.Download(txtTitle.Text, valueUrl, false));
                                thread.Start();
                            })
                            .SetNegativeButton("Video", (sender, e) =>
                            {
                                Thread thread = new Thread(() => searchActivity_.Download(txtTitle.Text, valueUrl, true));
                                thread.Start();
                            })
                            .SetTitle(txtTitle.Text)
                            .SetIcon(Resource.Drawable.Icon)
                            .Show();
                        });
                    }
                    else if (valueUrl.Contains("ccmixter"))
                    {
                        Thread thread = new Thread(() => searchActivity_.Download(txtTitle.Text, valueUrl, false));
                        thread.Start();
                    }
                    else
                    {
                        Thread thread = new Thread(() => searchActivity_.Download(txtTitle.Text, valueUrl, true));
                        thread.Start();
                    }
                });
            };

            buttonDownload.SetOnClickListener(localDownload);

            return(row);
        }
Exemplo n.º 2
0
        private void ZoomImageFromThumb(object sender, EventArgs eventArgs)
        {
            View thumbView = (View)sender;

            // If there's an animation in progress, cancel it immediately and proceed with this one.
            if (_currentAnimator != null)
            {
                _currentAnimator.Cancel();
            }

            // Load the high-resolution "zoomed-in" image.
            // ImageView expandedImageView = (ImageView)FindViewById(Resource.Id.expanded_image);
            // expandedImageView.SetImageResource(imageResId);

            expandedImageView = this.FindViewById <ImageView>(Resource.Id.expanded_image);

            Glide.With(this).Load(Uri.Parse((thumbView.Tag).ToString()))
            .Into(expandedImageView);

            // Calculate the starting and ending bounds for the zoomed-in image.
            Rect  startBounds  = new Rect();
            Rect  finalBounds  = new Rect();
            Point globalOffset = new Point();

            // The start bounds are the global visible rectangle of the thumbnail, and the
            // final bounds are the global visible rectangle of the container view. Also
            // set the container view's offset as the origin for the bounds, since that's
            // the origin for the positioning animation properties (X, Y).
            thumbView.GetGlobalVisibleRect(startBounds);
            FindViewById(Resource.Id.container).GetGlobalVisibleRect(finalBounds, globalOffset);
            startBounds.Offset(-globalOffset.X, -globalOffset.Y);
            finalBounds.Offset(-globalOffset.X, -globalOffset.Y);

            // Adjust the start bounds to be the same aspect ratio as the final bounds using the
            // "center crop" technique. This prevents undesirable stretching during the animation.
            // Also calculate the start scaling factor (the end scaling factor is always 1.0).
            float startScale;

            if ((float)finalBounds.Width() / finalBounds.Height()
                > (float)startBounds.Width() / startBounds.Height())
            {
                // Extend start bounds horizontally
                startScale = (float)startBounds.Height() / finalBounds.Height();
                float startWidth = startScale * finalBounds.Width();
                float deltaWidth = (startWidth - startBounds.Width()) / 2;
                startBounds.Left  -= (int)deltaWidth;
                startBounds.Right += (int)deltaWidth;
            }
            else
            {
                // Extend start bounds vertically
                startScale = (float)startBounds.Width() / finalBounds.Width();
                float startHeight = startScale * finalBounds.Height();
                float deltaHeight = (startHeight - startBounds.Height()) / 2;
                startBounds.Top    -= (int)deltaHeight;
                startBounds.Bottom += (int)deltaHeight;
            }

            // Hide the thumbnail and show the zoomed-in view. When the animation begins,
            // it will position the zoomed-in view in the place of the thumbnail.
            thumbView.Alpha = 0f;
            expandedImageView.Visibility = ViewStates.Visible;

            // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of
            // the zoomed-in view (the default is the center of the view).
            expandedImageView.PivotX = 0f;
            expandedImageView.PivotY = 0f;

            AnimatorSet expandSet = new AnimatorSet();

            expandSet.Play(ObjectAnimator.OfFloat(expandedImageView, View.X, startBounds.Left, finalBounds.Left))
            .With(ObjectAnimator.OfFloat(expandedImageView, View.Y, startBounds.Top, finalBounds.Top))
            .With(ObjectAnimator.OfFloat(expandedImageView, View.ScaleXs, startScale, 1f))
            .With(ObjectAnimator.OfFloat(expandedImageView, View.ScaleYs, startScale, 1f));
            expandSet.SetDuration(_shortAnimationDuration);
            expandSet.SetInterpolator(new DecelerateInterpolator());
            // expandSet.AnimationEnd += NullOutCurrentAnimator;
            // expandSet.AnimationCancel += NullOutCurrentAnimator;

            expandSet.AnimationEnd += (sender1, args1) =>
            {
                _currentAnimator = null;
            };
            expandSet.AnimationCancel += (sender1, args1) =>
            {
                _currentAnimator = null;
            };

            expandSet.Start();
            _currentAnimator = expandSet;

            // Upon clicking the zoomed-in image, it should zoom back down to the original bounds
            // and show the thumbnail instead of the expanded image.
            float startScaleFinal = startScale;

            // Create a custom clickListener so that click listeners won't be set multiple times
            var local = new LocalOnclickListener();

            expandedImageView.SetOnClickListener(local);

            local.HandleOnClick = () =>
            {
                if (_currentAnimator != null)
                {
                    _currentAnimator.Cancel();
                }

                AnimatorSet shrinkSet = new AnimatorSet();
                shrinkSet.Play(ObjectAnimator.OfFloat(expandedImageView, View.X, startBounds.Left))
                .With(ObjectAnimator.OfFloat(expandedImageView, View.Y, startBounds.Top))
                .With(ObjectAnimator.OfFloat(expandedImageView, View.ScaleXs, startScaleFinal))
                .With(ObjectAnimator.OfFloat(expandedImageView, View.ScaleYs, startScaleFinal));
                shrinkSet.SetDuration(_shortAnimationDuration);
                shrinkSet.SetInterpolator(new DecelerateInterpolator());

                shrinkSet.AnimationEnd += (sender1, args1) =>
                {
                    thumbView.Alpha = 1.0f;
                    expandedImageView.Visibility = ViewStates.Gone;
                    _currentAnimator             = null;
                };
                shrinkSet.AnimationCancel += (sender1, args1) =>
                {
                    thumbView.Alpha = 1.0f;
                    expandedImageView.Visibility = ViewStates.Gone;
                    _currentAnimator             = null;
                };
                shrinkSet.Start();
                _currentAnimator = shrinkSet;
            };
        }
Exemplo n.º 3
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View row = convertView;

            if (row == null)
            {
                row = LayoutInflater.From(context_).Inflate(Resource.Layout.FilesRow, null, false);
            }

            // Title
            TextView txtTitle = row.FindViewById <TextView>(Resource.Id.textViewRow_);

            txtTitle.Text = items_[position].Title;

            // Url
            string valueUrl = items_[position].Url;

            // Media type
            TextView txtMediaType = row.FindViewById <TextView>(Resource.Id.textViewMediaType);

            if (valueUrl.EndsWith(".mp3") || valueUrl.EndsWith(".m4a"))
            {
                txtMediaType.Text = "Audio";
            }
            else
            {
                txtMediaType.Text = "Video";
            }

            // Duration
            TextView txtDuration = row.FindViewById <TextView>(Resource.Id.textViewDuration_);

            if (items_[position].Duration.Length > 8)
            {
                txtDuration.Text = items_[position].Duration.Substring(0, 8);
            }
            else
            {
                txtDuration.Text = items_[position].Duration;
            }

            // Play
            Button buttonPlay = row.FindViewById <Button>(Resource.Id.buttonRowPlay_);

            var localPlay = new LocalOnclickListener();

            localPlay.HandleOnClick = () =>
            {
#if DEBUG
                Console.WriteLine(valueUrl);
#endif

                Log.println(valueUrl);

                Thread thread = new Thread(() => play(valueUrl, position));
                thread.Start();
            };

            buttonPlay.SetOnClickListener(localPlay);

            // Delete
            Button buttonDelete = row.FindViewById <Button>(Resource.Id.buttonRowDelete);

            var localDelete = new LocalOnclickListener();

            localDelete.HandleOnClick = () =>
            {
                File.Delete(valueUrl);
                ActivityContext.mActivity.RunOnUiThread(() => filesActivity_.loadAsync());
            };

            buttonDelete.SetOnClickListener(localDelete);

            return(row);
        }