Beispiel #1
0
        public bool OnDoubleTap(Android.Views.MotionEvent ev)
        {
            if (photoViewAttacher == null)
            {
                return(false);
            }
            try {
                float scale = photoViewAttacher.GetScale();
                float x     = ev.GetX();
                float y     = ev.GetY();

                if (scale < photoViewAttacher.GetMediumScale())
                {
                    photoViewAttacher.SetScale(photoViewAttacher.GetMediumScale(), x, y, true);
                }
                else if (scale >= photoViewAttacher.GetMediumScale() && scale < photoViewAttacher.GetMaximumScale())
                {
                    photoViewAttacher.SetScale(photoViewAttacher.GetMaximumScale(), x, y, true);
                }
                else
                {
                    photoViewAttacher.SetScale(photoViewAttacher.GetMinimumScale(), x, y, true);
                }
            } catch (Java.Lang.ArrayIndexOutOfBoundsException e) {
                // Can sometimes happen when getX() and getY() is called
            }

            return(true);
        }
 public float GetMaximumScale()
 {
     return(mAttacher.GetMaximumScale());
 }
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            switch (item.ItemId)
            {
            case Resource.Id.menu_zoom_toggle:
                mAttacher.SetZoomable(!mAttacher.CanZoom());
                return(true);

            case Resource.Id.menu_scale_fit_center:
                mAttacher.SetScaleType(Android.Widget.ImageView.ScaleType.FitCenter);
                return(true);

            case Resource.Id.menu_scale_fit_start:
                mAttacher.SetScaleType(Android.Widget.ImageView.ScaleType.FitStart);
                return(true);

            case Resource.Id.menu_scale_fit_end:
                mAttacher.SetScaleType(Android.Widget.ImageView.ScaleType.FitEnd);
                return(true);

            case Resource.Id.menu_scale_fit_xy:
                mAttacher.SetScaleType(Android.Widget.ImageView.ScaleType.FitXy);
                return(true);

            case Resource.Id.menu_scale_scale_center:
                mAttacher.SetScaleType(Android.Widget.ImageView.ScaleType.Center);
                return(true);

            case Resource.Id.menu_scale_scale_center_crop:
                mAttacher.SetScaleType(Android.Widget.ImageView.ScaleType.CenterCrop);
                return(true);

            case Resource.Id.menu_scale_scale_center_inside:
                mAttacher.SetScaleType(Android.Widget.ImageView.ScaleType.CenterInside);
                return(true);

            case Resource.Id.menu_scale_random_animate:
            case Resource.Id.menu_scale_random:
                Random r = new Random();

                float minScale    = mAttacher.GetMinimumScale();
                float maxScale    = mAttacher.GetMaximumScale();
                float randomScale = minScale + (float.Parse(r.NextDouble().ToString()) * (maxScale - minScale));
                mAttacher.SetScale(randomScale, item.ItemId == Resource.Id.menu_scale_random_animate);

                ShowToast(SCALE_TOAST_STRING + " " + randomScale);

                return(true);

            case Resource.Id.menu_matrix_restore:
                if (mCurrentDisplayMatrix == null)
                {
                    ShowToast("You need to capture display matrix first");
                }
                else
                {
                    mAttacher.SetDisplayMatrix(mCurrentDisplayMatrix);
                }
                return(true);

            case Resource.Id.menu_matrix_capture:
                mCurrentDisplayMatrix = mAttacher.GetDisplayMatrix();
                return(true);

            case Resource.Id.extract_visible_bitmap:
                return(true);
            }
            return(base.OnOptionsItemSelected(item));
        }