Esempio n. 1
0
        public static void AddView(DroidVariable widget, bool alreadyExists)
        {
            var location   = widget.Location;
            var view       = widget.ViewX;
            var parentView = location.ParentView as DroidVariable;
            var parent     = parentView?.ViewLayout;

            //Console.WriteLine("--ADDING {0} {1}, text: {2}, parent: {3}, exists: {4}",
            //                  varName, widgetType, text, parentView == null, alreadyExists);
            //MainActivity.AddView(widget, parentView?.ViewLayout);
            ScriptingFragment.AddView(widget, parent);
            if (parent != null)
            {
                parent.AddView(view);
            }
            else
            {
                TheLayout.AddView(view);
            }
            if (alreadyExists)
            {
                MainActivity.TheLayout.Invalidate();
                MainActivity.TheLayout.RefreshDrawableState();
                view.Invalidate();
                view.RefreshDrawableState();
                //if (parentView != null) {
                parentView?.ViewLayout.Invalidate();
                //}
            }
        }
Esempio n. 2
0
 public static void RemoveView(DroidVariable viewVar)
 {
     if (viewVar == null || viewVar.ViewX == null)
     {
         return;
     }
     ScriptingFragment.RemoveView(viewVar);
 }
Esempio n. 3
0
        public static View GetView(string viewName, ParsingScript script)
        {
            if (viewName.Equals("root", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }
            ParserFunction func = ParserFunction.GetVariable(viewName, script);

            Utils.CheckNotNull(func, viewName, script);
            Variable      viewValue = func.GetValue(script);
            DroidVariable viewVar   = viewValue as DroidVariable;

            return(viewVar.ViewX);
        }
Esempio n. 4
0
        public static void AddView(DroidVariable widget, ViewGroup parent = null)
        {
            var view = widget.ViewX;

            if (m_activeFragment != null)
            {
                m_activeFragment.m_widgets.Add(widget);
            }
            if (parent == null)
            {
                parent = MainActivity.TheLayout;
            }
            m_allViews.Add(widget, parent);
        }
Esempio n. 5
0
        public static int ExtraMargin(DroidVariable widgetFunc, ScreenSize screenSize, double multiplier)
        {
            int offset = 0;

            if (widgetFunc.ViewX is Switch)
            {
                offset = (int)AutoScaleFunction.TransformSize(UtilsDroid.SWITCH_MARGIN, screenSize.Width, 3);
                if (screenSize.Width <= AutoScaleFunction.BASE_WIDTH)
                {
                    offset = SWITCH_MARGIN; // from -45, 480
                }
                //offset = -112; // (before -168) // from 1200
                //offset = -135; // from 1440
            }
            return(offset);
        }
Esempio n. 6
0
        public virtual void AdjustTranslation(DroidVariable location, bool isX, bool sameWidget = true)
        {
            int        offset     = 0;
            ScreenSize screenSize = UtilsDroid.GetScreenSize();

            if (isX && sameWidget && ViewX is Switch)
            {
                offset = (int)AutoScaleFunction.TransformSize(UtilsDroid.SWITCH_MARGIN, screenSize.Width, 3);
                if (screenSize.Width <= AutoScaleFunction.BASE_WIDTH)
                {
                    offset = UtilsDroid.SWITCH_MARGIN; // from -45, 480
                }
                //offset = -112; // (before -168) // from 1200
                //offset = -135; // from 1440
            }
            location.TranslationX += offset;
        }
Esempio n. 7
0
        public void ProcessTranslationY(DroidVariable location)
        {
            if (location.RuleY == "CENTER" && WidgetType == UIType.LABEL)
            {
                int deltaY = (int)AutoScaleFunction.TransformSize(20, UtilsDroid.GetScreenSize().Width);;
                location.TranslationY += deltaY;
            }

            if (location.TranslationY < 0 && location.LayoutRuleY == LayoutRules.AlignParentTop)
            {
                location.TranslationY = 0;
            }
            else if (location.ViewY is Spinner)
            {
                if (location.LayoutRuleY == LayoutRules.AlignParentBottom ||
                    location.LayoutRuleY == LayoutRules.Below)
                {
                    location.ExtraY        = (int)AutoScaleFunction.TransformSize(10, UtilsDroid.GetScreenSize().Width);
                    location.TranslationY -= location.ExtraY;
                }
            }
        }
Esempio n. 8
0
        public static void RemoveView(DroidVariable widget, bool removeFromActive = true)
        {
            var view = widget.ViewX;

            if (removeFromActive && m_activeFragment != null)
            {
                m_activeFragment.m_widgets.Remove(widget);
            }
            m_allViews.Remove(widget);

            var parent = widget.Location?.ParentView as DroidVariable;

            ViewGroup parentView   = parent != null ? parent.ViewLayout : MainActivity.TheLayout;
            View      viewToRemove = widget.ViewX;

            parentView.RemoveView(viewToRemove);

            parentView = viewToRemove.Parent as ViewGroup;
            if (parentView != null && parentView.Parent != null)
            {
                parentView.RemoveView(viewToRemove);
            }
        }
Esempio n. 9
0
        public void SetViewLayout(int width, int height)
        {
            DroidVariable refView = Location?.RefViewX as DroidVariable;

            m_viewX = MainActivity.CreateViewLayout(width, height, refView?.ViewLayout);
        }
Esempio n. 10
0
        public void CreateStepper(int width, int height, string extraLabel)
        {
            DroidVariable refView = Location?.RefViewX as DroidVariable;
            ViewGroup     layout  = MainActivity.CreateViewLayout(width, height, refView?.ViewLayout);

            TextView label = null;

            Button btn1 = new Button(MainActivity.TheView);

            btn1.Text = "-";
            btn1.Id   = ++m_currentTag;
            Button btn2 = new Button(MainActivity.TheView);

            btn2.Text = "+";
            btn2.Id   = ++m_currentTag;

            layout.AddView(btn1);
            layout.AddView(btn2);

            RelativeLayout.LayoutParams layoutParams1 = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent
                )
            {
                Width  = height,
                Height = height
            };

            RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent
                )
            {
                Width  = height,
                Height = height
            };
            layoutParams2.AddRule(LayoutRules.RightOf, btn1.Id);

            if (!string.IsNullOrWhiteSpace(extraLabel))
            {
                label         = new TextView(MainActivity.TheView);
                label.Text    = CurrVal.ToString();
                label.Id      = ++m_currentTag;
                label.Gravity = GravityFlags.Center;

                RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent
                    )
                {
                    Width  = height,
                    Height = height
                };
                if (extraLabel == "left")
                {
                    layoutParams1.AddRule(LayoutRules.RightOf, label.Id);
                    //label.Gravity = GravityFlags.Right | GravityFlags.CenterVertical;
                }
                else
                {
                    layoutParams3.AddRule(LayoutRules.RightOf, btn2.Id);
                    //label.Gravity = GravityFlags.Left | GravityFlags.CenterVertical;
                }
                label.LayoutParameters = layoutParams3;
                layout.AddView(label);
            }

            btn1.Touch += (sender, e) =>
            {
                if (e.Event.Action == MotionEventActions.Up)
                {
                    CurrVal     -= Step;
                    CurrVal      = CurrVal < MinVal ? MinVal : CurrVal;
                    CurrVal      = CurrVal > MaxVal ? MaxVal : CurrVal;
                    btn1.Enabled = CurrVal > MinVal;
                    btn2.Enabled = CurrVal < MaxVal;
                    if (label != null)
                    {
                        label.Text = CurrVal.ToString();
                    }
                    ActionDelegate?.Invoke(WidgetName, CurrVal.ToString());
                }
            };
            btn2.Touch += (sender, e) =>
            {
                if (e.Event.Action == MotionEventActions.Up)
                {
                    CurrVal     += Step;
                    CurrVal      = CurrVal < MinVal ? MinVal : CurrVal;
                    CurrVal      = CurrVal > MaxVal ? MaxVal : CurrVal;
                    btn1.Enabled = CurrVal > MinVal;
                    btn2.Enabled = CurrVal < MaxVal;
                    if (label != null)
                    {
                        label.Text = CurrVal.ToString();
                    }
                    ActionDelegate?.Invoke(WidgetName, CurrVal.ToString());
                }
            };

            btn1.LayoutParameters = layoutParams1;
            btn2.LayoutParameters = layoutParams2;

            m_viewX = layout;
        }
Esempio n. 11
0
        public override Variable Clone()
        {
            DroidVariable newVar = (DroidVariable)this.MemberwiseClone();

            return(newVar);
        }
Esempio n. 12
0
        public static void SetValues(DroidVariable widgetFunc, string valueStr)
        {
            if (string.IsNullOrWhiteSpace(valueStr))
            {
                return;
            }
            widgetFunc.InitValue = new Variable(valueStr);

            // currValue:minValue:maxValue:step

            double minValue = 0, maxValue = 1, currValue = 0, step = 1.0;

            string[] vals = valueStr.Split(new char[] { ',', ':' });
            Double.TryParse(vals[0].Trim(), out currValue);

            if (vals.Length > 1)
            {
                Double.TryParse(vals[1].Trim(), out minValue);
                if (vals.Length > 2)
                {
                    Double.TryParse(vals[2].Trim(), out maxValue);
                }
                if (vals.Length > 3)
                {
                    Double.TryParse(vals[3].Trim(), out step);
                }
            }
            else
            {
                minValue = maxValue = currValue;
            }

            if (widgetFunc.WidgetType == UIVariable.UIType.SEGMENTED)
            {
                Switch seg = widgetFunc.ViewX as Switch;
                if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
                {
                    seg.ShowText = true;
                }
                seg.TextOn  = vals[vals.Length - 1];
                seg.TextOff = vals[0];
                seg.Checked = false;
            }
            else if (widgetFunc.ViewX is Switch)
            {
                Switch sw = widgetFunc.ViewX as Switch;
                sw.Checked = (int)currValue == 1;
            }
            else if (widgetFunc.ViewX is SeekBar)
            {
                SeekBar slider = widgetFunc.ViewX as SeekBar;
                //slider.Max = (int)maxValue - (int)minValue;
                slider.Max         = (int)maxValue;
                slider.Min         = (int)minValue;
                slider.Progress    = (int)currValue;
                widgetFunc.MinVal  = minValue;
                widgetFunc.MaxVal  = maxValue;
                widgetFunc.CurrVal = currValue;
            }
            else
            {
                widgetFunc.MinVal  = minValue;
                widgetFunc.MaxVal  = maxValue;
                widgetFunc.CurrVal = currValue;
                widgetFunc.Step    = step;
            }
        }
Esempio n. 13
0
        public virtual DroidVariable GetWidget(string widgetType, string widgetName, string initArg,
                                               int width, int height)
        {
            UIVariable.UIType type = UIVariable.UIType.NONE;
            View widget            = null;

            switch (widgetType)
            {
            case "View":
                type   = UIVariable.UIType.VIEW;
                widget = new View(MainActivity.TheView);
                break;

            case "Button":
                type   = UIVariable.UIType.BUTTON;
                widget = new Button(MainActivity.TheView);
                ((Button)widget).SetTextColor(Color.Black);
                ((Button)widget).Text = initArg;
                UtilsDroid.AddViewBorder(widget, Color.Black);
                break;

            case "TextView":
                type   = UIVariable.UIType.TEXT_VIEW;
                widget = new TextView(MainActivity.TheView);
                ((TextView)widget).SetTextColor(Color.Black);
                ((TextView)widget).Text                       = initArg;
                ((TextView)widget).Gravity                    = GravityFlags.Top | GravityFlags.Left;
                ((TextView)widget).TextAlignment              = TextAlignment.TextStart;
                ((TextView)widget).MovementMethod             = new ScrollingMovementMethod();
                ((TextView)widget).VerticalScrollBarEnabled   = true;
                ((TextView)widget).HorizontalScrollBarEnabled = true;
                //((TextView)widget).SetMaxLines(40);
                //((TextView)widget).ScrollBarStyle = ScrollbarStyles.OutsideOverlay;
                //((TextView)widget).ScrollBarSize = 2;
                break;

            case "Label":
                type   = UIVariable.UIType.LABEL;
                widget = new TextView(MainActivity.TheView);
                ((TextView)widget).SetTextColor(Color.Black);
                ((TextView)widget).Text    = initArg;
                ((TextView)widget).Gravity = GravityFlags.CenterVertical | GravityFlags.Left;
                break;

            case "TextEdit":
                type   = UIVariable.UIType.TEXT_FIELD;
                widget = new EditText(MainActivity.TheView);
                ((EditText)widget).SetTextColor(Color.Black);
                ((EditText)widget).SetBackgroundColor(Color.White);
                ((EditText)widget).SetTextIsSelectable(true);
                ((EditText)widget).Focusable     = true;
                ((EditText)widget).LongClickable = true;
                ((EditText)widget).Hint          = initArg;
                break;

            case "TextEditView":
                type   = UIVariable.UIType.EDIT_VIEW;
                widget = new EditText(MainActivity.TheView);
                ((EditText)widget).SetTextColor(Color.Black);
                ((EditText)widget).SetBackgroundColor(Color.White);
                ((EditText)widget).Hint                       = initArg;
                ((EditText)widget).Gravity                    = GravityFlags.Top | GravityFlags.Left;
                ((EditText)widget).TextAlignment              = TextAlignment.TextStart;
                ((EditText)widget).MovementMethod             = new ScrollingMovementMethod();
                ((EditText)widget).VerticalScrollBarEnabled   = true;
                ((EditText)widget).HorizontalScrollBarEnabled = true;
                ((EditText)widget).SetTextIsSelectable(true);
                ((EditText)widget).Focusable     = true;
                ((EditText)widget).LongClickable = true;
                break;

            case "ImageView":
                type   = UIVariable.UIType.IMAGE_VIEW;
                widget = new ImageView(MainActivity.TheView);
                if (!string.IsNullOrWhiteSpace(initArg))
                {
                    int resourceID = MainActivity.String2Pic(initArg);
                    widget.SetBackgroundResource(resourceID);
                }
                break;

            case "Combobox":
                type   = UIVariable.UIType.COMBOBOX;
                widget = new Spinner(MainActivity.TheView);
                ((Spinner)widget).DescendantFocusability = DescendantFocusability.BlockDescendants;
                break;

            case "TypePicker":
                type   = UIVariable.UIType.PICKER_VIEW;
                widget = new NumberPicker(MainActivity.TheView);
                // Don't show the cursor on the picker:
                ((NumberPicker)widget).DescendantFocusability = DescendantFocusability.BlockDescendants;
                break;

            case "Picker":
                type   = UIVariable.UIType.PICKER_IMAGES;
                widget = new Spinner(MainActivity.TheView);
                // Don't show the cursor on the picker:
                ((Spinner)widget).DescendantFocusability = DescendantFocusability.BlockDescendants;
                break;

            case "ListView":
                type   = UIVariable.UIType.LIST_VIEW;
                widget = new ListView(MainActivity.TheView);
                // Don't show the cursor on the list view:
                ((ListView)widget).DescendantFocusability = DescendantFocusability.BlockDescendants;
                break;

            case "Switch":
                type   = UIVariable.UIType.SWITCH;
                widget = new Switch(MainActivity.TheView);
                break;

            case "SegmentedControl":
                type   = UIVariable.UIType.SEGMENTED;
                widget = new Switch(MainActivity.TheView);
                //widget = new Info.Hoang8f.Android.Segmented.SegmentedGroup(MainActivity.TheView);
                break;

            case "Slider":
                type   = UIVariable.UIType.SLIDER;
                widget = new SeekBar(MainActivity.TheView);
                break;

            case "Stepper":
                type   = UIVariable.UIType.STEPPER;
                widget = new View(MainActivity.TheView);
                break;
            }

            DroidVariable widgetFunc = new DroidVariable(type, widgetName, widget);

            widgetFunc.AddAction(widgetName, widgetName + "_click");

            SetValues(widgetFunc, initArg);
            return(widgetFunc);
        }
Esempio n. 14
0
        /*public static View ConvertFormsToNative(Xamarin.Forms.View view,
         *                                      Xamarin.Forms.Rectangle size)
         * {
         * var vRenderer = Platform.CreateRendererWithContext(view, MainActivity.TheView);
         * var androidView = vRenderer.View;
         * vRenderer.Tracker.UpdateLayout();
         * var layoutParams = new ViewGroup.LayoutParams((int)size.Width, (int)size.Height);
         * androidView.LayoutParameters = layoutParams;
         * view.Layout(size);
         * androidView.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest);
         * return androidView;
         * }*/

        public static LayoutRules String2LayoutParam(DroidVariable location, bool isX)
        {
            View   referenceView = isX ? location.ViewX : location.ViewY;
            string param         = isX ? location.RuleX : location.RuleY;

            bool useRoot = referenceView == null;

            DroidVariable refLocation = isX ? location.RefViewX?.Location as DroidVariable :
                                        location.RefViewY?.Location as DroidVariable;

            // If the reference view has a margin, add it to the current view.
            // This is the iOS functionality.
            if (isX && refLocation != null && !location.IsAdjustedX)
            {
                location.TranslationX += refLocation.TranslationX;
                //} else if (!isX && refLocation != null && !location.IsAdjustedY) {
                //  location.TranslationY += refLocation.TranslationY - refLocation.ExtraY;
            }
            else if (!isX && refLocation != null)
            {
                location.TranslationY += refLocation.TranslationY;
            }

            switch (param)
            {
            case "LEFT":
                return(useRoot ? LayoutRules.AlignParentLeft :
                       LayoutRules.LeftOf);

            case "RIGHT":
                return(useRoot ? LayoutRules.AlignParentRight :
                       LayoutRules.RightOf);

            case "TOP":
                return(useRoot ? LayoutRules.AlignParentTop :
                       LayoutRules.Above);

            case "BOTTOM":
                return(useRoot ? LayoutRules.AlignParentBottom :
                       LayoutRules.Below);

            case "CENTER":
                if (useRoot)
                {
                    return(isX ? LayoutRules.CenterHorizontal :
                           LayoutRules.CenterVertical);
                }
                else
                {
                    if (isX)
                    {
                        location.TranslationX += (refLocation.Width - location.Width) / 2;
                        return(LayoutRules.AlignLeft);
                    }
                    else
                    {
                        location.TranslationY += (refLocation.Height - location.Height) / 2;
                        return(LayoutRules.AlignTop);   // .AlignBaseline;
                    }
                }

            case "ALIGN_LEFT":
                return(LayoutRules.AlignLeft);

            case "ALIGN_RIGHT":
                return(LayoutRules.AlignRight);

            case "ALIGN_TOP":
                return(LayoutRules.AlignTop);

            case "ALIGN_BOTTOM":
                return(LayoutRules.AlignBottom);

            case "ALIGN_PARENT_TOP":
                return(LayoutRules.AlignParentTop);

            case "ALIGN_PARENT_BOTTOM":
                return(LayoutRules.AlignParentBottom);

            default:
                return(LayoutRules.AlignStart);
            }
        }