Esempio n. 1
0
        /// <summary>
        /// Gets the spinner view.
        /// </summary>
        /// <returns>Return the view which represents the spinner on the ActionBar, or null if there isn't one.</returns>
        public View GetSpinnerView()
        {
            try
            {
                Field spinnerField = mActionBarViewClass.GetDeclaredField("mSpinner");
                spinnerField.Accessible = true;

                return((View)spinnerField.Get((Java.Lang.Object)mActionBarView));
            }
            catch (Java.Lang.NoSuchFieldException e)
            {
                Log.Error("TAG", "Failed to find actionbar spinner", e);
            }
            catch (Java.Lang.IllegalAccessException e)
            {
                Log.Error("TAG", "Failed to access actionbar spinner", e);
            }

            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the overflow view.
        /// </summary>
        /// <returns>Return the view which represents the overflow action item on the ActionBar, or null if there isn't one.</returns>
        public View GetOverflowView()
        {
            try
            {
                Field actionMenuPresenterField = mAbsActionBarViewClass.GetDeclaredField("mActionMenuPresenter");
                actionMenuPresenterField.Accessible = true;

                var   actionMenuPresenter = actionMenuPresenterField.Get((Java.Lang.Object)mActionBarView);
                Field overflowButtonField = actionMenuPresenter.Class.GetDeclaredField("mOverflowButton");
                overflowButtonField.Accessible = true;

                return((View)overflowButtonField.Get(actionMenuPresenter));
            }
            catch (Java.Lang.IllegalAccessException e)
            {
                e.PrintStackTrace();
            }
            catch (Java.Lang.NoSuchFieldException e)
            {
                e.PrintStackTrace();
            }
            return(null);
        }
Esempio n. 3
0
        protected View CreateCustomViewInternal(View parent, View view, string name, Context viewContext,
                                                IAttributeSet attrs)
        {
            if (Debug)
            {
                Mvx.TaggedTrace(Tag, "... CreateCustomViewInternal ... {0}", name);
            }

            if (view == null && name.IndexOf('.') > -1)
            {
                // Attempt to inflate with MvvmCross unless we're trying to inflate an internal views
                // since we don't resolve those.
                if (!name.StartsWith("com.android.internal."))
                {
                    view = this.AndroidViewFactory.CreateView(parent, name, viewContext, attrs);
                }

                if (view == null)
                {
                    if (this._constructorArgs == null)
                    {
                        Java.Lang.Class layoutInflaterClass = Java.Lang.Class.FromType(typeof(LayoutInflater));
                        this._constructorArgs            = layoutInflaterClass.GetDeclaredField("mConstructorArgs");
                        this._constructorArgs.Accessible = true;
                    }

                    Java.Lang.Object[] constructorArgsArr = (Java.Lang.Object[]) this._constructorArgs.Get(this);
                    Java.Lang.Object   lastContext        = constructorArgsArr[0];

                    // The LayoutInflater actually finds out the correct context to use. We just need to set
                    // it on the mConstructor for the internal method.
                    // Set the constructor args up for the createView, not sure why we can't pass these in.
                    constructorArgsArr[0] = viewContext;
                    this._constructorArgs.Set(this, constructorArgsArr);
                    try
                    {
                        view = this.CreateView(name, null, attrs);
                    }
                    catch (Java.Lang.ClassNotFoundException) { }
                    finally
                    {
                        constructorArgsArr[0] = lastContext;
                        this._constructorArgs.Set(this, constructorArgsArr);
                    }
                }
            }
            return(view);
        }
Esempio n. 4
0
        /*
         * 设置Tablayout元素的外边距
         */
        // 具体方法(通过反射的方式)
        public void SetIndicator(TabLayout tabs, int leftDip, int rightDip)
        {
            Java.Lang.Class tabLayout = tabs.Class;
            Field           tabStrip  = null;

            try
            {
                tabStrip = tabLayout.GetDeclaredField("mTabStrip");
            }
            catch (Java.Lang.NoSuchFieldException e)
            {
                //e.printStackTrace();
            }

            tabStrip.Accessible = true;
            LinearLayout llTab = null;

            try
            {
                llTab = (LinearLayout)tabStrip.Get(tabs);
            }
            catch (Java.Lang.IllegalAccessException e)
            {
                //e.printStackTrace();
            }

            int left  = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, leftDip, Resources.DisplayMetrics);
            int right = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, rightDip, Resources.DisplayMetrics);

            for (int i = 0; i < llTab.ChildCount; i++)
            {
                View child = llTab.GetChildAt(i);
                //child.GetPadding(0, 0, 0, 0);

                var p = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MatchParent, 1);
                p.LeftMargin           = left;
                p.RightMargin          = right;
                child.LayoutParameters = p;
                child.Invalidate();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Nasty method to inflate custom layouts that haven't been handled else where. If this fails it
        /// will fall back through to the PhoneLayoutInflater method of inflating custom views where
        /// Calligraphy will NOT have a hook into.
        /// </summary>
        /// <returns>view or the View we inflate in here.</returns>
        /// <param name="parent">Parent view.</param>
        /// <param name="view">view if it has been inflated by this point, if this is not null this method just returns this value.</param>
        /// <param name="name">name of the thing to inflate.</param>
        /// <param name="viewContext">Context to inflate by if parent is null</param>
        /// <param name="attrs">Attr for this view which we can steal fontPath from too.</param>
        internal View CreateCustomViewInternal(View parent, View view, string name, Context viewContext, IAttributeSet attrs)
        {
            // I by no means advise anyone to do this normally, but Google have locked down access to
            // the createView() method, so we never get a callback with attributes at the end of the
            // createViewFromTag chain (which would solve all this unnecessary rubbish).
            // We at the very least try to optimise this as much as possible.
            // We only call for customViews (As they are the ones that never go through onCreateView(...)).
            // We also maintain the Field reference and make it accessible which will make a pretty
            // significant difference to performance on Android 4.0+.

            // If CustomViewCreation is off skip this.
            if (!CalligraphyConfig.Get().CustomViewCreation)
            {
                return(view);
            }
            if (view == null && name.IndexOf('.') > -1)
            {
                Java.Lang.Object[] constructorArgsArr = null;
                Java.Lang.Object   lastContext        = null;

                if (Build.VERSION.SdkInt <= BuildVersionCodes.P)
                {
                    if (constructorArgs == null)
                    {
                        Java.Lang.Class layoutInflaterClass = Java.Lang.Class.FromType(typeof(LayoutInflater));
                        constructorArgs            = layoutInflaterClass.GetDeclaredField("mConstructorArgs");
                        constructorArgs.Accessible = true;
                    }

                    constructorArgsArr = (Java.Lang.Object[])constructorArgs.Get(this);
                    lastContext        = constructorArgsArr[0];

                    // The LayoutInflater actually finds out the correct context to use. We just need to set
                    // it on the mConstructor for the internal method.
                    // Set the constructor args up for the createView, not sure why we can't pass these in.
                    constructorArgsArr[0] = viewContext;
                    constructorArgs.Set(this, constructorArgsArr);
                }
                try
                {
#if __ANDROID_29__
                    if (Build.VERSION.SdkInt > BuildVersionCodes.P)
                    {
                        view = CreateView(viewContext, name, null, attrs);
                    }
                    else
#endif
                    view = CreateView(name, null, attrs);
                }
                catch (Java.Lang.ClassNotFoundException)
                {
                }
                finally
                {
                    if (Build.VERSION.SdkInt <= BuildVersionCodes.P)
                    {
                        constructorArgsArr[0] = lastContext;
                        constructorArgs.Set(this, constructorArgsArr);
                    }
                }
            }
            return(view);
        }