Exemplo n.º 1
0
        private RelativeLayout CreateMovieContainer()
        {
            RelativeLayout container = new RelativeLayout(this);

            GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
            layoutParams.SetGravity(GravityFlags.Center);
            layoutParams.Height        = 810;
            layoutParams.Width         = 420;
            layoutParams.LeftMargin    = layoutParams.RightMargin = 60;
            layoutParams.TopMargin     = layoutParams.BottomMargin = 30;
            container.LayoutParameters = layoutParams;
            return(container);
        }
        private void AddSymbol(Symbol symbol)
        {
            var sd = new SymbolDisplay(this)
            {
                Symbol = symbol
            };

            sd.SetMaxHeight(40);
            var p = new GridLayout.LayoutParams();

            p.SetGravity(GravityFlags.Center);
            sd.LayoutParameters = p;
            rootLayout.AddView(sd);
        }
        void createModalView <T>(T dataRow)
        {
            Type m_tipo = null;

            PropertyInfo[] m_propiedades = null;
            m_tipo        = dataRow.GetType();
            m_propiedades = m_tipo.GetProperties();

            ScrollView scroll = new ScrollView(this);

            scroll.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);

            GridLayout contentModal = new GridLayout(this);

            contentModal.RowCount    = m_propiedades.Count();
            contentModal.ColumnCount = 2;
            GridLayout.LayoutParams hola = new GridLayout.LayoutParams();
            hola.SetMargins(10, 10, 10, 10);
            hola.SetGravity(GravityFlags.Center);
            contentModal.LayoutParameters = hola;

            foreach (PropertyInfo propiedad in m_propiedades)
            {
                TextView campoNombreModal = new TextView(this);
                campoNombreModal.Text          = propiedad.Name;
                campoNombreModal.TextAlignment = TextAlignment.Center;

                TextView campoValorModal = new TextView(this);
                campoValorModal.Text          = propiedad.GetValue(dataRow, null).ToString();
                campoValorModal.TextAlignment = TextAlignment.Center;

                contentModal.AddView(campoNombreModal);
                contentModal.AddView(campoValorModal);
            }

            scroll.AddView(contentModal);

            AlertDialog.Builder ventanaModalAlert = new AlertDialog.Builder(this);
            ventanaModalAlert.SetView(scroll);
            ventanaModalAlert.SetNegativeButton("Aceptar", delegate { });
            ventanaModalAlert.Create().Show();
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Dialog.Window.RequestFeature(WindowFeatures.NoTitle);
            var        panelLayout = GetPanelLayout();
            var        view        = inflater.Inflate(Resource.Layout.circuit_breaker_panel_fragment, container, false);
            GridLayout circuitBreakerPanelRowIdGridLayout = view.FindViewById <GridLayout>(Resource.Id.circuitBreakerPanelRowIdGridLayout);
            GridLayout circuitBreakerPanelGridLayout      = view.FindViewById <GridLayout>(Resource.Id.circuitBreakerPanelGridLayout);

            circuitBreakerPanelRowIdGridLayout.RowCount = panelLayout.Item2 + 1;
            circuitBreakerPanelGridLayout.RowCount      = panelLayout.Item2 + 1;
            circuitBreakerPanelGridLayout.ColumnCount   = panelLayout.Item1;
            Tuple <int, int> tuple = GetSelectedCircuitBreaker();
            bool             valid = (tuple.Item1 > -1 && tuple.Item2 > -1);

            for (int i = 0; i < panelLayout.Item2 + 1; i++)
            {
                for (int j = 0; j < panelLayout.Item1; j++)
                {
                    if (i == 0)
                    {
                        TextView columNumber = new TextView(Context)
                        {
                            Text    = (j + 1).ToString(),
                            Gravity = GravityFlags.Center
                        };
                        GridLayout.LayoutParams columNumberLayoutParams = new GridLayout.LayoutParams()
                        {
                            ColumnSpec = GridLayout.InvokeSpec(j), RowSpec = GridLayout.InvokeSpec(i)
                        };
                        columNumberLayoutParams.SetGravity(GravityFlags.CenterHorizontal);
                        columNumber.LayoutParameters = columNumberLayoutParams;
                        circuitBreakerPanelGridLayout.AddView(columNumber);
                    }
                    else if (i != 0)
                    {
                        ImageView imageView = new ImageView(Context);
                        if (valid && i == tuple.Item1 + 1 && j == tuple.Item2 - 1)
                        {
                            imageView.SetImageResource(Resource.Drawable.ic_green_cb);
                        }
                        else
                        {
                            imageView.SetImageResource(Resource.Drawable.ic_black_cb);
                        }
                        GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams()
                        {
                            ColumnSpec = GridLayout.InvokeSpec(j), RowSpec = GridLayout.InvokeSpec(i)
                        };
                        imageView.LayoutParameters = layoutParams;
                        imageView.SetBackgroundResource(Resource.Xml.cb_grid_divider);
                        circuitBreakerPanelGridLayout.AddView(imageView);
                    }
                }
            }

            circuitBreakerPanelGridLayout.GetChildAt((panelLayout.Item1 * panelLayout.Item2) - 1).LayoutChange += (s, e) =>
            {
                for (int i = 0; i < panelLayout.Item2 + 1; i++)
                {
                    if (i > 0)
                    {
                        TextView rowLetter = new TextView(Context)
                        {
                            Text = rowLetters[i - 1]
                        };
                        GridLayout.LayoutParams rowLetterLayoutParams = new GridLayout.LayoutParams()
                        {
                            ColumnSpec = GridLayout.InvokeSpec(0), RowSpec = GridLayout.InvokeSpec(i)
                        };
                        rowLetterLayoutParams.SetGravity(GravityFlags.Center);
                        rowLetter.SetTextColor(new Color(ContextCompat.GetColor(Context, Resource.Color.blueGrey100)));
                        rowLetterLayoutParams.Height = (s as View).Height;
                        rowLetter.SetTextSize(Android.Util.ComplexUnitType.Sp, 14);
                        rowLetter.LayoutParameters = rowLetterLayoutParams;
                        //rowLetter.SetBackgroundResource(Resource.Xml.cb_grid_divider);
                        circuitBreakerPanelRowIdGridLayout.AddView(rowLetter);
                    }
                }
            };

            return(view);
        }
Exemplo n.º 5
0
        public void GridLayout_Drag(object sender, Android.Views.View.DragEventArgs e)
        {
            var  v    = (ViewGroup)sender;
            View view = (View)e.Event.LocalState;
            //can just get currentButtonType from view.getTileType()
            var   drag_data         = e.Event.ClipData;
            bool  isDroppedAtCenter = false;
            float x = 0.0f;
            float y = 0.0f;

            switch (e.Event.Action)
            {
            case DragAction.Started:
                a.hasButtonBeenDroppedInCorrectzone = false;
                AlgeTilesTextView aTv = (AlgeTilesTextView)view;
                a.currentButtonType = aTv.getTileType();
                //if (null != drag_data)
                //{
                //	a.currentButtonType = drag_data.GetItemAt(0).Text;
                //}
                break;

            case DragAction.Entered:
                v.SetBackgroundResource(Resource.Drawable.shape_droptarget);
                break;

            case DragAction.Exited:
                a.currentOwner = (ViewGroup)view.Parent;
                a.hasButtonBeenDroppedInCorrectzone = false;
                v.SetBackgroundResource(Resource.Drawable.shape);
                break;

            case DragAction.Location:
                x = e.Event.GetX();                         //width
                y = e.Event.GetY();                         //height
                break;

            case DragAction.Drop:
                if (null != drag_data)
                {
                    a.currentButtonType = drag_data.GetItemAt(0).Text;
                }
                Log.Debug(TAG, "Dropped: " + a.currentButtonType);

                AlgeTilesTextView algeTilesIV     = new AlgeTilesTextView(a);
                Boolean           wasImageDropped = false;

                if (a.activityType.Equals(Constants.MULTIPLY))
                {
                    if (!a.isFirstAnswerCorrect &&
                        (a.currentButtonType.Equals(Constants.X_TILE) ||
                         a.currentButtonType.Equals(Constants.Y_TILE) ||
                         a.currentButtonType.Equals(Constants.ONE_TILE)))
                    {
                        if (v.Id == Resource.Id.middleLeft)
                        {
                            algeTilesIV.RotationY = 180;
                        }
                        if (v.Id == Resource.Id.upperMiddle)
                        {
                            algeTilesIV.RotationX = 180;
                        }

                        wasImageDropped   = true;
                        isDroppedAtCenter = true;
                    }
                    else if (a.isFirstAnswerCorrect)
                    {
                        wasImageDropped = true;
                    }
                }
                else
                {
                    if (a.isFirstAnswerCorrect &&
                        (a.currentButtonType.Equals(Constants.X_TILE) ||
                         a.currentButtonType.Equals(Constants.Y_TILE) ||
                         a.currentButtonType.Equals(Constants.ONE_TILE)))
                    {
                        if (v.Id == Resource.Id.middleLeft)
                        {
                            algeTilesIV.RotationY = 180;
                        }
                        if (v.Id == Resource.Id.upperMiddle)
                        {
                            algeTilesIV.RotationX = 180;
                        }
                        wasImageDropped   = true;
                        isDroppedAtCenter = true;
                    }
                    else if (!a.isFirstAnswerCorrect)
                    {
                        wasImageDropped = true;
                    }
                }

                algeTilesIV.setTileType(a.currentButtonType);

                if (wasImageDropped)
                {
                    ViewGroup container = (ViewGroup)v;
                    Log.Debug(TAG, a.currentButtonType);
                    double heightFactor         = 0;
                    double widthFactor          = 0;
                    TileUtilities.TileFactor tF = TileUtilities.getTileFactors(a.currentButtonType);
                    algeTilesIV.SetBackgroundResource(tF.id);

                    if (tF.text.Length > 1 && !tF.text.Equals("xy"))
                    {
                        var cs = new SpannableStringBuilder(tF.text);
                        cs.SetSpan(new SuperscriptSpan(), 1, 2, SpanTypes.ExclusiveExclusive);
                        cs.SetSpan(new RelativeSizeSpan(0.75f), 1, 2, SpanTypes.ExclusiveExclusive);
                        algeTilesIV.TextFormatted = cs;
                    }
                    else
                    {
                        algeTilesIV.Text = tF.text;
                    }

                    heightFactor = tF.heightFactor;
                    widthFactor  = tF.widthFactor;
                    x            = e.Event.GetX();
                    y            = e.Event.GetY();

                    if (!isDroppedAtCenter)
                    {
                        Rect r = TileUtilities.checkIfUserDropsOnRect(v.Id, a.currentButtonType, x, y, Constants.ADD, a.rectTileListList);
                        if (null != r)
                        {
                            RelativeLayout.LayoutParams par = new RelativeLayout.LayoutParams(
                                ViewGroup.LayoutParams.WrapContent,
                                ViewGroup.LayoutParams.WrapContent);
                            par.Height     = r.Height();
                            par.Width      = r.Width();
                            par.TopMargin  = r.Top;
                            par.LeftMargin = r.Left;
                            algeTilesIV.LayoutParameters = par;
                            algeTilesIV.LongClick       += a.listeners.clonedImageView_Touch;
                            container.AddView(algeTilesIV);
                            TileUtilities.checkWhichParentAndUpdate(v.Id, a.currentButtonType, Constants.ADD, a.gridValueList);
                            a.hasButtonBeenDroppedInCorrectzone = true;
                            //algeTilesIV.setDimensions(par.Height, par.Width);
                        }
                    }
                    else
                    {
                        GridLayout.LayoutParams gParms = new GridLayout.LayoutParams();
                        if (v.Id == Resource.Id.middleLeft || v.Id == Resource.Id.middleRight)
                        {
                            gParms.SetGravity(GravityFlags.Center);
                            gParms.Height = (int)(a.heightInPx / widthFactor);
                            gParms.Width  = (int)(a.heightInPx / heightFactor);
                        }
                        else
                        {
                            gParms.SetGravity(GravityFlags.Center);
                            gParms.Height = (int)(a.heightInPx / heightFactor);
                            gParms.Width  = (int)(a.heightInPx / widthFactor);
                        }
                        //algeTilesIV.setDimensions(gParms.Height, gParms.Width);

                        algeTilesIV.LayoutParameters = gParms;
                        algeTilesIV.LongClick       += a.listeners.clonedImageView_Touch;
                        container.AddView(algeTilesIV);
                        TileUtilities.checkWhichParentAndUpdate(v.Id, a.currentButtonType, Constants.ADD, a.gridValueList);

                        //Auto re-arrange of center tiles
                        List <AlgeTilesTextView> centerTileList = new List <AlgeTilesTextView>();
                        for (int i = 0; i < container.ChildCount; ++i)
                        {
                            AlgeTilesTextView a = (AlgeTilesTextView)container.GetChildAt(i);
                            centerTileList.Add(a);
                        }
                        container.RemoveAllViews();

                        List <AlgeTilesTextView> sortedList = centerTileList.OrderByDescending(o => o.getTileType()).ToList();
                        for (int i = 0; i < sortedList.Count; ++i)
                        {
                            container.AddView(sortedList[i]);
                        }
                        //End of auto re-arrange
                    }

                    view.Visibility = ViewStates.Visible;
                    v.SetBackgroundResource(Resource.Drawable.shape);
                }
                break;

            case DragAction.Ended:
                v.SetBackgroundResource(Resource.Drawable.shape);
                if (!a.hasButtonBeenDroppedInCorrectzone &&
                    a.currentButtonType.Equals(Constants.CLONED_BUTTON))
                {
                    a.currentOwner.RemoveView(view);
                }
                else
                {
                    view.Visibility = ViewStates.Visible;
                }
                break;

            default:
                break;
            }
        }