示例#1
0
        internal static void OpenLogin(Activity context, string provider)
        {
            if (string.IsNullOrEmpty(provider) && Bootlegger.BootleggerClient.CurrentUser != null)
            {
                provider = Bootlegger.BootleggerClient.CurrentUser.profile["provider"].ToString();
            }

            var builder = new CustomTabsIntent.Builder()
                          .SetToolbarColor(ContextCompat.GetColor(context, Resource.Color.blue))
                          .SetSecondaryToolbarColor(Android.Resource.Color.White)
                          .SetShowTitle(true);
            Bitmap icon;

            if (ViewCompat.GetLayoutDirection(context.FindViewById <ViewGroup>(Android.Resource.Id.Content).GetChildAt(0)) != ViewCompat.LayoutDirectionRtl)
            {
                icon = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.ic_arrow_back_white_24dp);
            }
            else
            {
                icon = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.ic_arrow_forward_white_24dp);
            }

            builder.SetCloseButtonIcon(icon);
            var intent = builder.Build();

            intent.Intent.PutExtra(Intent.ExtraReferrer, Android.Net.Uri.Parse("app://" + context.PackageName));
            intent.LaunchUrl(context, Android.Net.Uri.Parse(Bootlegger.BootleggerClient.LoginUrl.ToString() + "/" + provider + "?cbid=" + WhiteLabelConfig.DATASCHEME));
        }
示例#2
0
        private static bool IsViewInDrawer(View child)
        {
            var gravity    = ((LayoutParams)child.LayoutParameters).Gravity;
            var absGravity = GravityCompat.GetAbsoluteGravity(gravity,
                                                              ViewCompat.GetLayoutDirection(child));

            return((absGravity & ((int)GravityFlags.Left | (int)GravityFlags.Right)) != 0);
        }
示例#3
0
        /**
         * Show a toast message with the hex color code below the view.
         */
        public void ShowHint()
        {
            var screenPos = new int[2];
            var displayFrame = new Rect();
            GetLocationOnScreen(screenPos);
            GetWindowVisibleDisplayFrame(displayFrame);
            var context = Context;
            var width = Width;
            var height = Height;
            var midy = screenPos[1] + height / 2;
            var referenceX = screenPos[0] + width / 2;
            if (ViewCompat.GetLayoutDirection(this) == ViewCompat.LayoutDirectionLtr)
            {
                var screenWidth = context.Resources.DisplayMetrics.WidthPixels;
                referenceX = screenWidth - referenceX; // mirror
            }

            var hint = new StringBuilder("#");
            if (Color.GetAlphaComponent(_color) != 255)
            {
                hint.Append(Integer.ToHexString(_color).ToUpper(new CultureInfo("en")));
            }
            else
            {
                hint.Append($"{0xFFFFFF & _color:X6}".ToUpper(new CultureInfo("en")));
            }

            var cheatSheet = Toast.MakeText(context, hint.ToString(), ToastLength.Short);
            if (midy < displayFrame.Height())
            {
                // Show along the top; follow action buttons
                cheatSheet.SetGravity(GravityFlags.Top | GravityFlags.End, referenceX,
                    screenPos[1] + height - displayFrame.Top);
            }
            else
            {
                // Show along the bottom center
                cheatSheet.SetGravity(GravityFlags.Bottom | GravityFlags.CenterHorizontal, 0, height);
            }

            cheatSheet.Show();
        }
示例#4
0
        public static void ShowHelp(Android.App.Activity context, string link)
        {
            var builder = new CustomTabsIntent.Builder()
                          .SetToolbarColor(ContextCompat.GetColor(context, Resource.Color.blue))
                          .SetSecondaryToolbarColor(Android.Resource.Color.White)
                          .SetShowTitle(true);
            Bitmap icon;

            if (ViewCompat.GetLayoutDirection(context.FindViewById <ViewGroup>(Android.Resource.Id.Content).GetChildAt(0)) != ViewCompat.LayoutDirectionRtl)
            {
                icon = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.ic_arrow_back_white_24dp);
            }
            else
            {
                icon = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.ic_arrow_forward_white_24dp);
            }

            builder.SetCloseButtonIcon(icon);
            var intent = builder.Build();

            intent.Intent.PutExtra(Intent.ExtraReferrer, Android.Net.Uri.Parse("app://" + context.PackageName));
            intent.LaunchUrl(context, Android.Net.Uri.Parse(context.Resources.GetString(Resource.String.HelpLink) + link));
        }
        public void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            if (_disposed || _renderer == null || _element == null)
            {
                return;
            }

            AButton view = View;

            if (view == null)
            {
                return;
            }

            Drawable drawable = null;

            Drawable[] drawables = TextViewCompat.GetCompoundDrawablesRelative(view);
            if (drawables != null)
            {
                foreach (var compoundDrawable in drawables)
                {
                    if (compoundDrawable != null)
                    {
                        drawable = compoundDrawable;
                        break;
                    }
                }
            }

            if (drawable != null)
            {
                int iconWidth = drawable.IntrinsicWidth;
                drawable.CopyBounds(_drawableBounds);

                // Center the drawable in the button if there is no text.
                // We do not need to undo this as when we get some text, the drawable recreated
                if (string.IsNullOrEmpty(_element.Text))
                {
                    var newLeft = (right - left - iconWidth) / 2 - view.PaddingLeft;

                    _drawableBounds.Set(newLeft, _drawableBounds.Top, newLeft + iconWidth, _drawableBounds.Bottom);
                    drawable.Bounds = _drawableBounds;
                }
                else
                {
                    if (_alignIconWithText && _element.ContentLayout.IsHorizontal())
                    {
                        var buttonText = view.TextFormatted;

                        // if text is transformed, add that transformation to to ensure correct calculation of icon padding
                        if (view.TransformationMethod != null)
                        {
                            buttonText = view.TransformationMethod.GetTransformationFormatted(buttonText, view);
                        }

                        var measuredTextWidth = view.Paint.MeasureText(buttonText, 0, buttonText.Length());
                        var textWidth         = Math.Min((int)measuredTextWidth, view.Layout.Width);
                        var contentsWidth     = ViewCompat.GetPaddingStart(view) + iconWidth + view.CompoundDrawablePadding + textWidth + ViewCompat.GetPaddingEnd(view);

                        var newLeft = (view.MeasuredWidth - contentsWidth) / 2;
                        if (_element.ContentLayout.Position == Button.ButtonContentLayout.ImagePosition.Right)
                        {
                            newLeft = -newLeft;
                        }
                        if (ViewCompat.GetLayoutDirection(view) == ViewCompat.LayoutDirectionRtl)
                        {
                            newLeft = -newLeft;
                        }

                        _drawableBounds.Set(newLeft, _drawableBounds.Top, newLeft + iconWidth, _drawableBounds.Bottom);
                        drawable.Bounds = _drawableBounds;
                    }
                }
            }

            _hasLayoutOccurred = true;
        }
 public bool IsRtl()
 {
     return((ViewCompat.GetLayoutDirection(this) == (int)LayoutDirectionRtl) && mMirrorForRtl);
 }
示例#7
0
        /// <summary>
        /// We can finally handle layout direction. </summary>
        /// <param name="view"> View providing layout direction. </param>
        private void resolveLayoutDirection(View view)
        {
            if (layoutDirectionResolved)
            {
                return;
            }
            layoutDirectionResolved = true;
            int layoutDirection = ViewCompat.GetLayoutDirection(view);

            mSpacing.ResolveLayoutDirection(layoutDirection);

            switch (layoutDirection)
            {
            case ViewCompat.LayoutDirectionRtl:
                if (mStart.padding != UNSET)
                {
                    mRight.padding      = mStart.padding;
                    mRight.paddingFlags = mStart.paddingFlags;
                }
                if (mStart.drawable != null)
                {
                    mRight.drawable      = mStart.drawable;
                    mRight.drawableFlags = mStart.drawableFlags;
                }
                if (mEnd.padding != UNSET)
                {
                    mLeft.padding      = mEnd.padding;
                    mLeft.paddingFlags = mEnd.paddingFlags;
                }
                if (mEnd.drawable != null)
                {
                    mLeft.drawable      = mEnd.drawable;
                    mLeft.drawableFlags = mEnd.drawableFlags;
                }
                break;

            case ViewCompat.LayoutDirectionLtr:
            default:
                if (mStart.padding != UNSET)
                {
                    mLeft.padding      = mStart.padding;
                    mLeft.paddingFlags = mStart.paddingFlags;
                }
                if (mStart.drawable != null)
                {
                    mLeft.drawable      = mStart.drawable;
                    mLeft.drawableFlags = mStart.drawableFlags;
                }
                if (mEnd.padding != UNSET)
                {
                    mRight.padding      = mEnd.padding;
                    mRight.paddingFlags = mEnd.paddingFlags;
                }
                if (mEnd.drawable != null)
                {
                    mRight.drawable      = mEnd.drawable;
                    mRight.drawableFlags = mEnd.drawableFlags;
                }
                break;
            }
        }
        void video_Touch(object sender, View.TouchEventArgs e)
        {
            if (e.Event.Action == MotionEventActions.Up && camera.GetParameters().SupportedFocusModes.Contains(Android.Hardware.Camera.Parameters.FocusModeAuto) && !focussing)
            {
                focussing = true;
                try
                {
                    camera.CancelAutoFocus();
                }
                catch
                {
                }

                float x         = e.Event.GetX();
                float y         = e.Event.GetY();
                Rect  touchRect = new Rect(
                    (int)(x - 70),
                    (int)(y - 70),
                    (int)(x + 70),
                    (int)(y + 70));
                Rect targetFocusRect = new Rect(
                    touchRect.Left * 2000 / View.Width - 1000,
                    touchRect.Top * 2000 / View.Height - 1000,
                    touchRect.Right * 2000 / View.Width - 1000,
                    touchRect.Bottom * 2000 / View.Height - 1000);

                List <Android.Hardware.Camera.Area> focusList = new List <Android.Hardware.Camera.Area>();
                Android.Hardware.Camera.Area        focusArea = new Android.Hardware.Camera.Area(targetFocusRect, 1000);
                focusList.Add(focusArea);

                Android.Hardware.Camera.Parameters param = camera.GetParameters();
                param.FocusAreas    = focusList;
                param.MeteringAreas = focusList;

                if (ViewCompat.GetLayoutDirection(focusring) == ViewCompat.LayoutDirectionRtl)
                {
                    focusring.LayoutParameters = new FrameLayout.LayoutParams(focusring.LayoutParameters)
                    {
                        MarginStart = Resources.DisplayMetrics.WidthPixels - ((int)x + (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics)), TopMargin = (int)y - (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics)
                    };
                }
                else
                {
                    focusring.LayoutParameters = new FrameLayout.LayoutParams(focusring.LayoutParameters)
                    {
                        MarginStart = (int)x - (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics), TopMargin = (int)y - (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics)
                    };
                }

                focusring.Visibility = ViewStates.Visible;

                Animation scaleup = AnimationUtils.LoadAnimation(Context, Resource.Animation.scaleup);
                scaleup.Interpolator = new DecelerateInterpolator();
                scaleup.Duration     = 300;
                inner_ring.StartAnimation(scaleup);

                Animation scaledown = AnimationUtils.LoadAnimation(Context, Resource.Animation.scaledown);
                scaledown.Duration     = 300;
                scaledown.Interpolator = new DecelerateInterpolator();
                outer_ring.StartAnimation(scaledown);

                //View.SetHaveTouch(true, touchRect);
                //drawingView.Invalidate();
                //        // Remove the square indicator after 1000 msec



                try
                {
                    camera.SetParameters(param);
                    camera.AutoFocus(this);
                    //drawingView.setHaveTouch(true, touchRect);
                    //drawingView.Invalidate();
                    // Remove the square indicator after 1000 msec
                }
                catch (Exception ef)
                {
                    Console.WriteLine(ef);
                    focussing = false;
                }

                Handler handler = new Handler();
                handler.PostDelayed(() => {
                    focusring.Visibility = ViewStates.Invisible;
                }, 800);
            }
        }
        public override void OnDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)
        {
            RecyclerView.Adapter adapter = parent.GetAdapter();
            if (adapter == null)
            {
                return;
            }

            int itemCount = adapter.ItemCount;

            if (orientation == VERTICAL)
            {
                bool isRtl = ViewCompat.GetLayoutDirection(parent) == ViewCompat.LayoutDirectionRtl;
                int  paddingLeft;
                int  paddingRight;
                if (isRtl)
                {
                    paddingLeft  = paddingEnd;
                    paddingRight = paddingStart;
                }
                else
                {
                    paddingLeft  = paddingStart;
                    paddingRight = paddingEnd;
                }

                int left       = parent.PaddingLeft + paddingLeft;
                int right      = parent.Width - parent.PaddingRight - paddingRight;
                int childCount = parent.ChildCount;

                for (int i = 0; i < childCount; i++)
                {
                    View child = parent.GetChildAt(i);
                    RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams)child.LayoutParameters;
                    int position = parent.GetChildLayoutPosition(child);

                    bool show;
                    if (showDividerHelper != null)
                    {
                        show = showDividerHelper.ShowDivider(position + 1);
                    }
                    else
                    {
                        show = (position != itemCount - 1) || showLastDivider;
                    }
                    if (show)
                    {
                        int top = child.Bottom + lp.BottomMargin;
                        if (overlap)
                        {
                            top -= thickness;
                        }
                        int bottom = top + thickness;
                        rect.Set(left, top, right, bottom);
                        c.DrawRect(rect, paint);
                    }

                    if (position == 0)
                    {
                        if (showDividerHelper != null)
                        {
                            show = showDividerHelper.ShowDivider(0);
                        }
                        else
                        {
                            show = showFirstDivider;
                        }
                        if (show)
                        {
                            int bottom = child.Top + lp.TopMargin;
                            if (overlap)
                            {
                                bottom += thickness;
                            }
                            int top = bottom - thickness;
                            rect.Set(left, top, right, bottom);
                            c.DrawRect(rect, paint);
                        }
                    }
                }
            }
            else
            {
                int top        = parent.PaddingTop + paddingStart;
                int bottom     = parent.Height - parent.PaddingBottom - paddingEnd;
                int childCount = parent.ChildCount;

                for (int i = 0; i < childCount; i++)
                {
                    View child = parent.GetChildAt(i);
                    RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams)child.LayoutParameters;
                    int position = parent.GetChildLayoutPosition(child);

                    bool show;
                    if (showDividerHelper != null)
                    {
                        show = showDividerHelper.ShowDivider(position + 1);
                    }
                    else
                    {
                        show = (position != itemCount - 1) || showLastDivider;
                    }
                    if (show)
                    {
                        int left = child.Right + lp.RightMargin;
                        if (overlap)
                        {
                            left -= thickness;
                        }
                        int right = left + thickness;
                        rect.Set(left, top, right, bottom);
                        c.DrawRect(rect, paint);
                    }

                    if (position == 0)
                    {
                        if (showDividerHelper != null)
                        {
                            show = showDividerHelper.ShowDivider(0);
                        }
                        else
                        {
                            show = showFirstDivider;
                        }
                        if (show)
                        {
                            int right = child.Left + lp.LeftMargin;
                            if (overlap)
                            {
                                right += thickness;
                            }
                            int left = right - thickness;
                            rect.Set(left, top, right, bottom);
                            c.DrawRect(rect, paint);
                        }
                    }
                }
            }
        }