Example #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Window.AddFlags(WindowManagerFlags.Fullscreen);
            Window.ClearFlags(WindowManagerFlags.ForceNotFullscreen);
            ActionBar.Hide();

            numberOfVariables = Intent.GetIntExtra(Constants.VARIABLE_COUNT, 0);

            SetContentView(Resource.Layout.MultiplyTwoVar);

            // Create your application here
            activityType = Constants.MULTIPLY;
            listeners    = new Listeners(this);

            result = (TextView)FindViewById(Resource.Id.result);

            tile_1  = (AlgeTilesTextView)FindViewById(Resource.Id.tile_1);
            x_tile  = (AlgeTilesTextView)FindViewById(Resource.Id.x_tile);
            y_tile  = (AlgeTilesTextView)FindViewById(Resource.Id.y_tile);
            xy_tile = (AlgeTilesTextView)FindViewById(Resource.Id.xy_tile);
            x2_tile = (AlgeTilesTextView)FindViewById(Resource.Id.x2_tile);
            y2_tile = (AlgeTilesTextView)FindViewById(Resource.Id.y2_tile);

            tile_1.LongClick  += listeners.tile_LongClick;
            x_tile.LongClick  += listeners.tile_LongClick;
            y_tile.LongClick  += listeners.tile_LongClick;
            x2_tile.LongClick += listeners.tile_LongClick;
            y2_tile.LongClick += listeners.tile_LongClick;
            xy_tile.LongClick += listeners.tile_LongClick;

            upperLeftGrid  = FindViewById <AlgeTilesRelativeLayout>(Resource.Id.upperLeft);
            upperRightGrid = FindViewById <AlgeTilesRelativeLayout>(Resource.Id.upperRight);
            lowerLeftGrid  = FindViewById <AlgeTilesRelativeLayout>(Resource.Id.lowerLeft);
            lowerRightGrid = FindViewById <AlgeTilesRelativeLayout>(Resource.Id.lowerRight);

            upperMiddleGrid = FindViewById <GridLayout>(Resource.Id.upperMiddle);
            middleLeftGrid  = FindViewById <GridLayout>(Resource.Id.middleLeft);
            middleRightGrid = FindViewById <GridLayout>(Resource.Id.middleRight);
            lowerMiddleGrid = FindViewById <GridLayout>(Resource.Id.lowerMiddle);

            ViewTreeObserver vto2 = upperLeftGrid.ViewTreeObserver;

            vto2.GlobalLayout += (sender, e) =>
            {
                if (!isFirstTime)
                {
                    heightInPx = upperLeftGrid.Height;
                    widthInPx  = upperLeftGrid.Width;
                    upperLeftGrid.SetMinimumHeight(0);
                    upperLeftGrid.SetMinimumWidth(0);
                    isFirstTime = true;

                    LinearLayout.LayoutParams par_1 = (LinearLayout.LayoutParams)tile_1.LayoutParameters;
                    TileUtilities.TileFactor  tF    = TileUtilities.getTileFactors(tile_1.getTileType());
                    par_1.Height = (int)(heightInPx / 7);
                    par_1.Width  = (int)(heightInPx / 7);
                    tile_1.SetBackgroundResource(tF.id);
                    tile_1.Text             = tF.text;
                    tile_1.LayoutParameters = par_1;

                    LinearLayout.LayoutParams par_x = (LinearLayout.LayoutParams)x_tile.LayoutParameters;
                    tF           = TileUtilities.getTileFactors(x_tile.getTileType());
                    par_x.Height = (int)(heightInPx / tF.heightFactor);
                    par_x.Width  = (int)(heightInPx / 7);
                    x_tile.SetBackgroundResource(tF.id);
                    x_tile.Text             = tF.text;
                    x_tile.LayoutParameters = par_x;

                    LinearLayout.LayoutParams par_y = (LinearLayout.LayoutParams)y_tile.LayoutParameters;
                    tF           = TileUtilities.getTileFactors(y_tile.getTileType());
                    par_y.Height = (int)(heightInPx / tF.heightFactor);
                    par_y.Width  = (int)(heightInPx / 7);
                    y_tile.SetBackgroundResource(tF.id);
                    y_tile.Text             = tF.text;
                    y_tile.LayoutParameters = par_y;

                    LinearLayout.LayoutParams par_x2 = (LinearLayout.LayoutParams)x2_tile.LayoutParameters;
                    tF            = TileUtilities.getTileFactors(x2_tile.getTileType());
                    par_x2.Height = (int)(heightInPx / tF.heightFactor);
                    par_x2.Width  = (int)(heightInPx / tF.widthFactor);
                    x2_tile.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);
                        x2_tile.TextFormatted = cs;
                    }
                    else
                    {
                        x2_tile.Text = tF.text;
                    }
                    x2_tile.LayoutParameters = par_x2;

                    LinearLayout.LayoutParams par_y2 = (LinearLayout.LayoutParams)y2_tile.LayoutParameters;
                    tF            = TileUtilities.getTileFactors(y2_tile.getTileType());
                    par_y2.Height = (int)(heightInPx / tF.heightFactor);
                    par_y2.Width  = (int)(heightInPx / tF.widthFactor);
                    y2_tile.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);
                        y2_tile.TextFormatted = cs;
                    }
                    else
                    {
                        y2_tile.Text = tF.text;
                    }
                    y2_tile.LayoutParameters = par_y2;

                    LinearLayout.LayoutParams par_xy = (LinearLayout.LayoutParams)xy_tile.LayoutParameters;
                    tF            = TileUtilities.getTileFactors(xy_tile.getTileType());
                    par_xy.Height = (int)(heightInPx / tF.heightFactor);
                    par_xy.Width  = (int)(heightInPx / tF.widthFactor);
                    xy_tile.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);
                        xy_tile.TextFormatted = cs;
                    }
                    else
                    {
                        xy_tile.Text = tF.text;
                    }
                    xy_tile.LayoutParameters = par_xy;
                }
            };

            outerGridLayoutList.Add(upperLeftGrid);
            outerGridLayoutList.Add(upperRightGrid);
            outerGridLayoutList.Add(lowerLeftGrid);
            outerGridLayoutList.Add(lowerRightGrid);

            innerGridLayoutList.Add(upperMiddleGrid);
            innerGridLayoutList.Add(middleLeftGrid);
            innerGridLayoutList.Add(middleRightGrid);
            innerGridLayoutList.Add(lowerMiddleGrid);

            //For multiply this is the initial grid available
            //Together form one Part of the formula
            upperMiddleGrid.Drag += listeners.GridLayout_Drag;
            lowerMiddleGrid.Drag += listeners.GridLayout_Drag;

            //Together form one Part of the formula
            middleLeftGrid.Drag  += listeners.GridLayout_Drag;
            middleRightGrid.Drag += listeners.GridLayout_Drag;

            //Shade red the other grids
            for (int i = 0; i < outerGridLayoutList.Count; ++i)
            {
                outerGridLayoutList[i].SetBackgroundResource(Resource.Drawable.unavailable);
            }

            removeToggle = (ToggleButton)FindViewById(Resource.Id.remove);
            dragToggle   = (ToggleButton)FindViewById(Resource.Id.drag);
            rotateToggle = (ToggleButton)FindViewById(Resource.Id.rotate);
            muteToggle   = (ToggleButton)FindViewById(Resource.Id.mute);

            removeToggle.Click += listeners.toggle_click;
            dragToggle.Click   += listeners.toggle_click;
            rotateToggle.Click += listeners.toggle_click;
            muteToggle.Click   += listeners.toggle_click;

            tutorialButton        = FindViewById <Button>(Resource.Id.tutorial);
            tutorialButton.Click += listeners.toggle_click;

            prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            muteToggle.Checked = prefs.GetBoolean(Constants.MUTE, false);

            newQuestionButton = (Button)FindViewById <Button>(Resource.Id.new_question_button);
            refreshButton     = (Button)FindViewById <Button>(Resource.Id.refresh_button);
            checkButton       = (Button)FindViewById <Button>(Resource.Id.check_button);

            newQuestionButton.Click += button_click;
            refreshButton.Click     += button_click;
            checkButton.Click       += button_click;

            upperLeftGV  = new GridValue();
            upperRightGV = new GridValue();
            lowerLeftGV  = new GridValue();
            lowerRightGV = new GridValue();

            midUpGV    = new GridValue();
            midLowGV   = new GridValue();
            midLeftGV  = new GridValue();
            midRightGV = new GridValue();

            gridValueList.Add(upperLeftGV);
            gridValueList.Add(upperRightGV);
            gridValueList.Add(lowerLeftGV);
            gridValueList.Add(lowerRightGV);

            gridValueList.Add(midUpGV);
            gridValueList.Add(midLowGV);
            gridValueList.Add(midLeftGV);
            gridValueList.Add(midRightGV);

            setupNewQuestion();

            correct   = MediaPlayer.Create(this, Resource.Raw.correct);
            incorrect = MediaPlayer.Create(this, Resource.Raw.wrong);

            x2ET  = FindViewById <EditText>(Resource.Id.x2_value);
            y2ET  = FindViewById <EditText>(Resource.Id.y2_value);
            xyET  = FindViewById <EditText>(Resource.Id.xy_value);
            xET   = FindViewById <EditText>(Resource.Id.x_value);
            yET   = FindViewById <EditText>(Resource.Id.y_value);
            oneET = FindViewById <EditText>(Resource.Id.one_value);

            editTextList.Add(x2ET);
            editTextList.Add(y2ET);
            editTextList.Add(xyET);
            editTextList.Add(xET);
            editTextList.Add(yET);
            editTextList.Add(oneET);

            sv = FindViewById <ScrollView>(Resource.Id.sv);

            refreshScreen(Constants.MULTIPLY, gridValueList, innerGridLayoutList, outerGridLayoutList);

            rectTileListList.Add(upperRightRectTileList);
            rectTileListList.Add(upperLeftRectTileList);
            rectTileListList.Add(lowerLeftRectTileList);
            rectTileListList.Add(lowerRightRectTileList);

            settingsDialog = new Dialog(this);
            settingsDialog.Window.RequestFeature(WindowFeatures.NoTitle);
        }
Example #2
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;
            }
        }