Beispiel #1
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);
                }
            }
        }
Beispiel #2
0
        public static void generateInnerLayoutTileArrays(int heightInPx, int widthInPx,
                                                         List <ViewGroup> innerGridLayoutList,
                                                         List <List <RectTile> > rectTileListList)
        {
            Log.Debug(TAG, "generateInnerLayoutTileArrays");
            List <string> midUp    = new List <string>();
            List <string> midLeft  = new List <string>();
            List <string> midRight = new List <string>();
            List <string> midDown  = new List <string>();

            List <List <string> > output = new List <List <string> >();

            output.Add(midUp);
            output.Add(midLeft);
            output.Add(midRight);
            output.Add(midDown);

            //midup, midleft, midright, middown
            for (int i = 0; i < innerGridLayoutList.Count; ++i)
            {
                Log.Debug(TAG, i + "");
                GridLayout gl = (GridLayout)innerGridLayoutList[i];
                for (int j = 0; j < gl.ChildCount; ++j)
                {
                    AlgeTilesTextView al = gl.GetChildAt(j) as AlgeTilesTextView;
                    Log.Debug(TAG, al.getTileType());

                    switch (al.getTileType())
                    {
                    case Constants.X_TILE:
                        output[i].Add(al.getTileType());
                        break;

                    case Constants.Y_TILE:
                        output[i].Add(al.getTileType());
                        break;

                    case Constants.ONE_TILE:
                        output[i].Add(al.getTileType());
                        break;
                    }
                }
            }

            int height = heightInPx;
            int width  = widthInPx;

            //upmid x midRight = quadrant1
            if (midUp.Count != 0 || midRight.Count != 0)
            {
                Log.Debug(TAG, "in upmid x midright");
                int top    = height;              //height of relative layout
                int bottom = height;              //height of relative layout
                for (int i = 0; i < midUp.Count; ++i)
                {
                    int  left      = 0;
                    int  right     = 0;
                    bool firstPass = true;
                    for (int j = 0; j < midRight.Count; ++j)
                    {
                        int[] productDimensions = getDimensionsOfProduct(height, midUp[i], midRight[j]);
                        if (firstPass)
                        {
                            //top = subtract height of first tile in midup ( then subtract next tile  ) etc...
                            top -= productDimensions[0];
                            //bottom = height at i = 0, else bottom = previous top
                            bottom    = top + productDimensions[0];                          //don't add to stack since only getting the latest top/height
                            firstPass = false;
                        }
                        //right = width of midleft (then add next tile) etc...
                        right += productDimensions[1];                         //width adds up
                        //left = 0 at start, else width of midleft
                        left = right - productDimensions[1];

                        Rect r = new Rect(left, top, right, bottom);
                        rectTileListList[0].Add(new RectTile(r, getTileTypeOfProduct(midUp[i], midRight[j])));
                    }
                }
            }

            //upmid x midLeft = quadrant2
            if (midUp.Count != 0 || midLeft.Count != 0)
            {
                Log.Debug(TAG, "in upmid x midLeft");
                int top    = height;
                int bottom = height;
                for (int i = 0; i < midUp.Count; ++i)
                {
                    int  left      = width;
                    int  right     = width;
                    bool firstPass = true;
                    for (int j = 0; j < midLeft.Count; ++j)
                    {
                        int[] productDimensions = getDimensionsOfProduct(height, midUp[i], midLeft[j]);
                        if (firstPass)
                        {
                            top      -= productDimensions[0];
                            bottom    = top + productDimensions[0];
                            firstPass = false;
                        }
                        left -= productDimensions[1];
                        right = left + productDimensions[1];

                        Rect r = new Rect(left, top, right, bottom);
                        rectTileListList[1].Add(new RectTile(r, getTileTypeOfProduct(midUp[i], midLeft[j])));
                    }
                }
            }

            //loMid x midLeft = quadrant3
            if (midDown.Count != 0 || midLeft.Count != 0)
            {
                Log.Debug(TAG, "in loMid x midLeft");
                int top    = 0;
                int bottom = 0;
                for (int i = 0; i < midDown.Count; ++i)
                {
                    int  left      = width;
                    int  right     = width;
                    bool firstPass = true;
                    for (int j = 0; j < midLeft.Count; ++j)
                    {
                        int[] productDimensions = getDimensionsOfProduct(height, midDown[i], midLeft[j]);
                        if (firstPass)
                        {
                            bottom   += productDimensions[0];
                            top       = bottom - productDimensions[0];
                            firstPass = false;
                        }
                        left -= productDimensions[1];
                        right = left + productDimensions[1];

                        Rect r = new Rect(left, top, right, bottom);
                        rectTileListList[2].Add(new RectTile(r, getTileTypeOfProduct(midDown[i], midLeft[j])));
                    }
                }
            }

            //loMid x midRight = quadrant4
            if (midDown.Count != 0 || midRight.Count != 0)
            {
                Log.Debug(TAG, "in loMid x midRight");
                int top    = 0;
                int bottom = 0;
                for (int i = 0; i < midDown.Count; ++i)
                {
                    int  left      = 0;
                    int  right     = 0;
                    bool firstPass = true;
                    for (int j = 0; j < midRight.Count; ++j)
                    {
                        int[] productDimensions = getDimensionsOfProduct(height, midDown[i], midRight[j]);
                        if (firstPass)
                        {
                            bottom   += productDimensions[0];
                            top       = bottom - productDimensions[0];
                            firstPass = false;
                        }
                        right += productDimensions[1];
                        left   = right - productDimensions[1];
                        Rect r = new Rect(left, top, right, bottom);
                        rectTileListList[3].Add(new RectTile(r, getTileTypeOfProduct(midDown[i], midRight[j])));
                    }
                }
            }
        }
Beispiel #3
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;
            }
        }
Beispiel #4
0
 public static Rect getRectOfView(AlgeTilesTextView alIV)
 {
     RelativeLayout.LayoutParams rPrms = (RelativeLayout.LayoutParams)alIV.LayoutParameters;
     return(new Rect(rPrms.LeftMargin, rPrms.TopMargin, rPrms.LeftMargin + rPrms.Width, rPrms.TopMargin + rPrms.Height));
 }