Example #1
0
        //TODO: When top most layer textview increases in length, the edit text gets pushed
        public void clonedImageView_Touch(object sender, View.LongClickEventArgs e)
        {
            var       touchedImageView = (sender) as AlgeTilesTextView;
            ViewGroup vg = (ViewGroup)touchedImageView.Parent;

            if (a.removeToggle.Checked)
            {
                Log.Debug(TAG, "Switch: Remove");
                TileUtilities.checkIfUserDropsOnRect(vg.Id,
                                                     touchedImageView.getTileType(),
                                                     touchedImageView.Left + 10,
                                                     touchedImageView.Top + 10,
                                                     Constants.SUBTRACT,
                                                     a.rectTileListList);
                vg.RemoveView(touchedImageView);
                touchedImageView.Visibility = ViewStates.Gone;
                Vibrator vibrator = (Vibrator)a.GetSystemService(Context.VibratorService);
                vibrator.Vibrate(30);

                int id = touchedImageView.Id;

                TileUtilities.checkWhichParentAndUpdate(vg.Id, touchedImageView.getTileType(), Constants.SUBTRACT, a.gridValueList);
            }

            if (a.dragToggle.Checked)
            {
                Log.Debug(TAG, "Switch: Drag");
            }

            //TODO: Not working
            if (a.rotateToggle.Checked)
            {
                Log.Debug(TAG, "Switch: Rotate");
                touchedImageView.Rotation = touchedImageView.Rotation - 90;
            }
        }
Example #2
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 #3
0
        public async void checkAnswers()
        {
            if (!isFirstAnswerCorrect)
            {
                GridValue[] gvArr = { midUpGV, midLowGV, midLeftGV, midRightGV };
                if (AlgorithmUtilities.isFirstAnswerCorrect(vars, gvArr, numberOfVariables))
                {
                    isFirstAnswerCorrect = true;

                    //Change color of draggable areas to signify "Done/Correct"
                    upperLeftGrid.Drag  += listeners.GridLayout_Drag;
                    upperRightGrid.Drag += listeners.GridLayout_Drag;

                    lowerLeftGrid.Drag  += listeners.GridLayout_Drag;
                    lowerRightGrid.Drag += listeners.GridLayout_Drag;

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

                    for (int i = 0; i < innerGridLayoutList.Count; ++i)
                    {
                        innerGridLayoutList[i].SetBackgroundResource(Resource.Drawable.ok);
                        innerGridLayoutList[i].Drag -= listeners.GridLayout_Drag;
                        for (int j = 0; j < innerGridLayoutList[i].ChildCount; ++j)
                        {
                            var iv = innerGridLayoutList[i].GetChildAt(j) as AlgeTilesTextView;
                            iv.LongClick -= listeners.clonedImageView_Touch;
                            //iv.Visibility = ViewStates.Gone;
                        }
                    }

                    expandedVars = AlgorithmUtilities.expandingVars(vars);
                    foreach (var i in expandedVars)
                    {
                        Log.Debug(TAG, "Expanded in activity: " + i);
                    }
                    Toast.MakeText(Application.Context, "1:correct", ToastLength.Short).Show();

                    if (Constants.ONE_VAR == numberOfVariables)
                    {
                        x2ET.Enabled  = true;
                        xET.Enabled   = true;
                        oneET.Enabled = true;
                    }
                    else
                    {
                        x2ET.Enabled  = true;
                        y2ET.Enabled  = true;
                        xyET.Enabled  = true;
                        xET.Enabled   = true;
                        yET.Enabled   = true;
                        oneET.Enabled = true;
                    }

                    if (!muteToggle.Checked)
                    {
                        correct.Start();
                    }

                    TileUtilities.generateInnerLayoutTileArrays(heightInPx, widthInPx, innerGridLayoutList, rectTileListList);
                    upperRightGrid.drawRects(upperRightRectTileList);
                    upperLeftGrid.drawRects(upperLeftRectTileList);
                    lowerRightGrid.drawRects(lowerRightRectTileList);
                    lowerLeftGrid.drawRects(lowerLeftRectTileList);
                }
                else
                {
                    for (int i = 0; i < outerGridLayoutList.Count; ++i)
                    {
                        outerGridLayoutList[i].Drag -= listeners.GridLayout_Drag;
                    }

                    incorrectPrompt(innerGridLayoutList);

                    Toast.MakeText(Application.Context, "1:incorrect", ToastLength.Short).Show();
                }
            }
            else if (!isSecondAnswerCorrect)
            {
                Log.Debug(TAG, "isSecondAnswerCorrect branch");
                GridValue[] gvArr = { upperLeftGV, upperRightGV, lowerLeftGV, lowerRightGV };

                for (int i = 0; i < gvArr.Length; ++i)
                {
                    Log.Debug(TAG, gvArr[i].ToString());
                }
                if (AlgorithmUtilities.isSecondAnswerCorrect(expandedVars, gvArr, numberOfVariables))
                {
                    //Cancelling out
                    int       posX   = 0;
                    ViewGroup posXVG = null;
                    if (upperRightGV.xVal != 0)
                    {
                        posX   = upperRightGV.xVal;
                        posXVG = upperRightGrid;
                    }
                    else
                    {
                        if (lowerLeftGV.xVal != 0)
                        {
                            posX   = lowerLeftGV.xVal;
                            posXVG = lowerLeftGrid;
                        }
                    }

                    int       posY   = 0;
                    ViewGroup posYVG = null;
                    if (upperRightGV.yVal != 0)
                    {
                        posY   = upperRightGV.yVal;
                        posYVG = upperRightGrid;
                    }
                    else
                    {
                        if (lowerLeftGV.yVal != 0)
                        {
                            posY   = lowerLeftGV.yVal;
                            posYVG = lowerLeftGrid;
                        }
                    }

                    int       posXY   = 0;
                    ViewGroup posXYVG = null;
                    if (upperRightGV.xyVal != 0)
                    {
                        posXY   = upperRightGV.xyVal;
                        posXYVG = upperRightGrid;
                    }
                    else
                    {
                        if (lowerLeftGV.xyVal != 0)
                        {
                            posXY   = lowerLeftGV.xyVal;
                            posXYVG = lowerLeftGrid;
                        }
                    }

                    int       negX   = 0;
                    ViewGroup negXVG = null;
                    if (upperLeftGV.xVal != 0)
                    {
                        negX   = upperLeftGV.xVal;
                        negXVG = upperLeftGrid;
                    }
                    else
                    {
                        if (lowerRightGV.xVal != 0)
                        {
                            negX   = lowerRightGV.xVal;
                            negXVG = lowerRightGrid;
                        }
                    }

                    int       negY   = 0;
                    ViewGroup negYVG = null;
                    if (upperLeftGV.yVal != 0)
                    {
                        negY   = upperLeftGV.yVal;
                        negYVG = upperLeftGrid;
                    }
                    else
                    {
                        if (lowerRightGV.yVal != 0)
                        {
                            negY   = lowerRightGV.yVal;
                            negYVG = lowerRightGrid;
                        }
                    }

                    int       negXY   = 0;
                    ViewGroup negXYVG = null;
                    if (upperLeftGV.xyVal != 0)
                    {
                        negXY   = upperLeftGV.xyVal;
                        negXYVG = upperLeftGrid;
                    }
                    else
                    {
                        if (lowerRightGV.xyVal != 0)
                        {
                            negXY   = lowerRightGV.xyVal;
                            negXYVG = lowerRightGrid;
                        }
                    }

                    int xToRemove = posX > negX ? negX : posX;
                    List <AlgeTilesTextView> tobeRemovedX    = new List <AlgeTilesTextView>();
                    List <AlgeTilesTextView> negTobeRemovedX = new List <AlgeTilesTextView>();
                    if (posX != 0 && negX != 0)
                    {
                        Log.Debug(TAG, "Cancelling out: " + posX + ", " + negX);
                        Log.Debug(TAG, "To remove: " + xToRemove);
                        for (int j = 0; j < posXVG.ChildCount; ++j)
                        {
                            AlgeTilesTextView alIV = posXVG.GetChildAt(j) as AlgeTilesTextView;
                            if (alIV.getTileType().Equals(Constants.X_TILE) ||
                                alIV.getTileType().Equals(Constants.X_TILE_ROT))
                            {
                                tobeRemovedX.Add(alIV);
                            }
                        }

                        for (int j = 0; j < negXVG.ChildCount; ++j)
                        {
                            AlgeTilesTextView negalIV = negXVG.GetChildAt(j) as AlgeTilesTextView;
                            if (negalIV.getTileType().Equals(Constants.X_TILE) ||
                                negalIV.getTileType().Equals(Constants.X_TILE_ROT))
                            {
                                negTobeRemovedX.Add(negalIV);
                            }
                        }
                    }

                    int yToRemove = posY > negY ? negY : posY;
                    List <AlgeTilesTextView> tobeRemovedY    = new List <AlgeTilesTextView>();
                    List <AlgeTilesTextView> negTobeRemovedY = new List <AlgeTilesTextView>();
                    if (posY != 0 && negY != 0)
                    {
                        Log.Debug(TAG, "Cancelling out: " + posY + ", " + negY);
                        Log.Debug(TAG, "To remove: " + yToRemove);
                        for (int j = 0; j < posYVG.ChildCount; ++j)
                        {
                            AlgeTilesTextView alIV = posYVG.GetChildAt(j) as AlgeTilesTextView;
                            if (alIV.getTileType().Equals(Constants.Y_TILE) ||
                                alIV.getTileType().Equals(Constants.Y_TILE_ROT))
                            {
                                tobeRemovedY.Add(alIV);
                            }
                        }

                        for (int j = 0; j < negYVG.ChildCount; ++j)
                        {
                            AlgeTilesTextView negalIV = negYVG.GetChildAt(j) as AlgeTilesTextView;
                            if (negalIV.getTileType().Equals(Constants.Y_TILE) ||
                                negalIV.getTileType().Equals(Constants.Y_TILE_ROT))
                            {
                                negTobeRemovedY.Add(negalIV);
                            }
                        }
                    }

                    int xyToRemove = posXY > negXY ? negXY : posXY;
                    List <AlgeTilesTextView> tobeRemovedXY    = new List <AlgeTilesTextView>();
                    List <AlgeTilesTextView> negTobeRemovedXY = new List <AlgeTilesTextView>();
                    if (posXY != 0 && negXY != 0)
                    {
                        Log.Debug(TAG, "Cancelling out: " + posXY + ", " + negXY);
                        Log.Debug(TAG, "To remove: " + xyToRemove);

                        for (int j = 0; j < posXYVG.ChildCount; ++j)
                        {
                            AlgeTilesTextView alIV = posXYVG.GetChildAt(j) as AlgeTilesTextView;
                            if (alIV.getTileType().Equals(Constants.XY_TILE) ||
                                alIV.getTileType().Equals(Constants.XY_TILE_ROT))
                            {
                                tobeRemovedXY.Add(alIV);
                            }
                        }


                        for (int j = 0; j < negXYVG.ChildCount; ++j)
                        {
                            AlgeTilesTextView negalIV = negXYVG.GetChildAt(j) as AlgeTilesTextView;
                            if (negalIV.getTileType().Equals(Constants.XY_TILE) ||
                                negalIV.getTileType().Equals(Constants.XY_TILE_ROT))
                            {
                                negTobeRemovedXY.Add(negalIV);
                            }
                        }
                    }

                    //Added changing color of tiles to be cancelled and 2 second delay before cancelling out
                    for (int j = 0; j < xToRemove; ++j)
                    {
                        tobeRemovedX[j].SetBackgroundResource(Resource.Drawable.cancelling);
                        negTobeRemovedX[j].SetBackgroundResource(Resource.Drawable.cancelling);
                    }

                    for (int j = 0; j < yToRemove; ++j)
                    {
                        tobeRemovedY[j].SetBackgroundResource(Resource.Drawable.cancelling);
                        negTobeRemovedY[j].SetBackgroundResource(Resource.Drawable.cancelling);
                    }


                    for (int j = 0; j < xyToRemove; ++j)
                    {
                        tobeRemovedXY[j].SetBackgroundResource(Resource.Drawable.cancelling);
                        negTobeRemovedXY[j].SetBackgroundResource(Resource.Drawable.cancelling);
                    }

                    if (xToRemove + yToRemove + xyToRemove > 0)
                    {
                        await Task.Delay(Constants.CANCELOUT_DELAY);
                    }

                    for (int j = 0; j < xToRemove; ++j)
                    {
                        posXVG.RemoveView(tobeRemovedX[j]);
                        negXVG.RemoveView(negTobeRemovedX[j]);
                    }

                    for (int j = 0; j < yToRemove; ++j)
                    {
                        posYVG.RemoveView(tobeRemovedY[j]);
                        negYVG.RemoveView(negTobeRemovedY[j]);
                    }


                    for (int j = 0; j < xyToRemove; ++j)
                    {
                        posXYVG.RemoveView(tobeRemovedXY[j]);
                        negXYVG.RemoveView(negTobeRemovedXY[j]);
                    }
                    //End Cancelling out

                    Toast.MakeText(Application.Context, "2:correct", ToastLength.Short).Show();
                    if (!muteToggle.Checked)
                    {
                        correct.Start();
                    }

                    //Loop through inner and prevent deletions by removing: listeners.clonedImageView_Touch
                    for (int i = 0; i < outerGridLayoutList.Count; ++i)
                    {
                        outerGridLayoutList[i].SetBackgroundResource(Resource.Drawable.ok);
                        outerGridLayoutList[i].Drag -= listeners.GridLayout_Drag;
                        for (int j = 0; j < outerGridLayoutList[i].ChildCount; ++j)
                        {
                            var iv = outerGridLayoutList[i].GetChildAt(j) as AlgeTilesTextView;
                            iv.LongClick -= listeners.clonedImageView_Touch;
                        }
                    }

                    //Removing outer grid after 2nd correct (10-28-2016)
                    upperRightGrid.clearRects(heightInPx, widthInPx);
                    upperLeftGrid.clearRects(heightInPx, widthInPx);
                    lowerRightGrid.clearRects(heightInPx, widthInPx);
                    lowerLeftGrid.clearRects(heightInPx, widthInPx);

                    upperRightRectTileList.Clear();
                    upperLeftRectTileList.Clear();
                    lowerRightRectTileList.Clear();
                    lowerLeftRectTileList.Clear();

                    isSecondAnswerCorrect = true;
                }
                else
                {
                    Toast.MakeText(Application.Context, "2:incorrect", ToastLength.Short).Show();
                    incorrectPrompt(outerGridLayoutList);
                }
            }
            else if (!isThirdAnswerCorrect)
            {
                //TODO: Accomodate for two variables
                if (Constants.ONE_VAR == numberOfVariables)
                {
                    int[] answer = new int[3];
                    int   temp   = 0;
                    answer[0] = int.TryParse(x2ET.Text, out temp) ? temp : 0;
                    answer[1] = int.TryParse(xET.Text, out temp) ? temp : 0;
                    answer[2] = int.TryParse(oneET.Text, out temp) ? temp : 0;

                    if ((Math.Abs(answer[0]) +
                         Math.Abs(answer[1]) +
                         Math.Abs(answer[2])) == 0)
                    {
                        isThirdAnswerCorrect = false;
                    }
                    else
                    {
                        if (expandedVars[0] == answer[0] &&
                            expandedVars[1] == answer[1] &&
                            expandedVars[2] == answer[2])
                        {
                            isThirdAnswerCorrect = true;
                        }
                    }
                }
                else
                {
                    int[] answer = new int[6];
                    int   temp   = 0;
                    answer[0] = int.TryParse(x2ET.Text, out temp) ? temp : 0;
                    answer[1] = int.TryParse(y2ET.Text, out temp) ? temp : 0;
                    answer[2] = int.TryParse(xyET.Text, out temp) ? temp : 0;
                    answer[3] = int.TryParse(xET.Text, out temp) ? temp : 0;
                    answer[4] = int.TryParse(yET.Text, out temp) ? temp : 0;
                    answer[5] = int.TryParse(oneET.Text, out temp) ? temp : 0;

                    foreach (int i in answer)
                    {
                        Log.Debug(TAG, "answer:" + i);
                    }

                    foreach (int i in expandedVars)
                    {
                        Log.Debug(TAG, "expandedVars:" + i);
                    }

                    if ((Math.Abs(answer[0]) +
                         Math.Abs(answer[1]) +
                         Math.Abs(answer[2]) +
                         Math.Abs(answer[3]) +
                         Math.Abs(answer[4]) +
                         Math.Abs(answer[5])) == 0)
                    {
                        isThirdAnswerCorrect = false;
                    }
                    else
                    {
                        if (expandedVars[0] == answer[0] &&
                            expandedVars[1] == answer[1] &&
                            expandedVars[2] == answer[2] &&
                            expandedVars[3] == answer[3] &&
                            expandedVars[4] == answer[4] &&
                            expandedVars[5] == answer[5])
                        {
                            isThirdAnswerCorrect = true;
                        }
                    }
                }


                if (isThirdAnswerCorrect)
                {
                    Toast.MakeText(Application.Context, "3:correct", ToastLength.Short).Show();
                    for (int i = 0; i < editTextList.Count; ++i)
                    {
                        editTextList[i].SetBackgroundResource(Resource.Drawable.ok);
                        editTextList[i].Enabled = false;
                    }
                    if (!muteToggle.Checked)
                    {
                        correct.Start();
                    }
                }
                else
                {
                    Toast.MakeText(Application.Context, "3:incorrect", ToastLength.Short).Show();
                    incorrectPrompt(editTextList);
                }
            }
        }
Example #4
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;
            }
        }