Example #1
0
        private void randomizeMethod()
        {
            ArrayList tempCoords = new ArrayList(coordsArr);

            Random myRand = new Random();

            foreach (MyTextView any in tilesArr)
            {
                int   randIndex   = myRand.Next(0, tempCoords.Count);
                Point thisRandLoc = (Point)tempCoords[randIndex];

                GridLayout.Spec rowSpec = GridLayout.InvokeSpec(thisRandLoc.Y);
                GridLayout.Spec colSpec = GridLayout.InvokeSpec(thisRandLoc.X);

                GridLayout.LayoutParams randLayoutParam = new GridLayout.LayoutParams(rowSpec, colSpec);

                any.xPos = thisRandLoc.X;
                any.yPos = thisRandLoc.Y;

                randLayoutParam.Width  = tileWidth - 10;
                randLayoutParam.Height = tileWidth - 10;
                randLayoutParam.SetMargins(5, 5, 5, 5);

                any.LayoutParameters = randLayoutParam;

                tempCoords.RemoveAt(randIndex);
            }
            emptySpot = (Point)tempCoords[0];
        }
        private void RandomizeTiles()
        {
            ArrayList tempCoords = new ArrayList(coordsArray);             // 16 elements
            Random    myRand     = new Random();

            foreach (MyTextView any in tilesArray)              // 15 elements
            {
                int   randIndex   = myRand.Next(0, tempCoords.Count);
                Point thisRandLoc = (Point)tempCoords[randIndex];

                GridLayout.Spec         rowSpec         = GridLayout.InvokeSpec(thisRandLoc.Y);
                GridLayout.Spec         colSpec         = GridLayout.InvokeSpec(thisRandLoc.X);
                GridLayout.LayoutParams randLayoutParam = new GridLayout.LayoutParams(rowSpec, colSpec);


                any.xPos = thisRandLoc.X;
                any.yPos = thisRandLoc.Y;

                randLayoutParam.Width  = tileWidth - 10;
                randLayoutParam.Height = tileWidth - 10;
                randLayoutParam.SetMargins(5, 5, 5, 5);


                any.LayoutParameters = randLayoutParam;

                tempCoords.RemoveAt(randIndex);
            }

            Console.WriteLine("\r\r\r\r there are: {0} elements left", tempCoords.Count);
            emptySpot = (Point)tempCoords[0];
        }
Example #3
0
        private void RandomiseTiles()
        {
            Random    randomiser    = new Random();
            ArrayList copyCoordList = new ArrayList(coordList);

            foreach (MyTextView tile in tilesList)
            {
                int   randIndex          = randomiser.Next(0, copyCoordList.Count);
                Point randomisedLocation = (Point)copyCoordList[randIndex];

                GridLayout.Spec         rowSpec        = GridLayout.InvokeSpec(randomisedLocation.X);
                GridLayout.Spec         colSpec        = GridLayout.InvokeSpec(randomisedLocation.Y);
                GridLayout.LayoutParams randTileParams = new GridLayout.LayoutParams(rowSpec, colSpec);

                //keep location of tile
                tile.coordX = randomisedLocation.X;
                tile.coordY = randomisedLocation.Y;

                randTileParams.Width  = tileWidth - 10;
                randTileParams.Height = tileWidth - 10;
                randTileParams.SetMargins(5, 5, 5, 5);

                tile.LayoutParameters = randTileParams;
                copyCoordList.RemoveAt(randIndex);
            }
            emptySpot = (Point)copyCoordList[0];
        }
Example #4
0
        void TouchTile(object sender, View.TouchEventArgs e)
        {
            if (e.Event.Action == MotionEventActions.Up)
            {
                MyTextView tile = (MyTextView)sender;

                Console.WriteLine("tile is at x={0}, y={0}", tile.coordX, tile.coordY);

                //calculate distance between empty spot and the touched tile
                float xDif     = (float)Math.Pow(tile.coordX - emptySpot.X, 2);
                float yDif     = (float)Math.Pow(tile.coordY - emptySpot.Y, 2);
                float distance = (float)Math.Sqrt(xDif + yDif);
                //tile next to empty spot
                if (distance == 1)
                {
                    Point                   currentPoint      = new Point(tile.coordX, tile.coordY);
                    GridLayout.Spec         rowSpec           = GridLayout.InvokeSpec(emptySpot.X);
                    GridLayout.Spec         colSpec           = GridLayout.InvokeSpec(emptySpot.Y);
                    GridLayout.LayoutParams newLocationParams = new GridLayout.LayoutParams(rowSpec, colSpec);
                    tile.coordX = emptySpot.X;
                    tile.coordY = emptySpot.Y;

                    newLocationParams.Width  = tileWidth - 10;
                    newLocationParams.Height = tileWidth - 10;
                    newLocationParams.SetMargins(5, 5, 5, 5);
                    tile.LayoutParameters = newLocationParams;
                    emptySpot             = currentPoint;
                }
            }
        }
Example #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Lecture);
            GridLayout grd = FindViewById <GridLayout>(Resource.Id.lecturegrid);

            Android.Util.DisplayMetrics displayMetrics = new DisplayMetrics();
            WindowManager.DefaultDisplay.GetMetrics(displayMetrics);
            int width = displayMetrics.WidthPixels / 4;

            for (int i = 1; i <= 16; i++)
            {
                Button lbtn = new Button(this)
                {
                    Text = i.ToString()
                };
                lbtn.Click += (sender, evt) => {
                    string html = string.Empty;
                    string url  = @"http://party4bread.xyz/BNCD/getactivelecture.php?no=" + (sender as Button).Text;

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.AutomaticDecompression = DecompressionMethods.GZip;

                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                        using (System.IO.Stream stream = response.GetResponseStream())
                            using (System.IO.StreamReader reader = new StreamReader(stream))
                                html = reader.ReadToEnd();
                    string msg = html;
                    if (!msg.Contains("http"))
                    {
                        Toast.MakeText(this, msg, ToastLength.Long).Show();
                    }
                    else
                    {
                        Intent intent = new Intent(this, typeof(MainActivity));
                        intent.PutExtra("lecture", msg);
                        StartActivity(intent);
                    }
                };
                GridLayout.LayoutParams lp = new GridLayout.LayoutParams();
                //lp.SetGravity(GravityFlags.Fill);
                lp.Width  = width;
                lp.Height = width;
                lp.SetMargins(0, 0, 0, 0);
                int rbpar = i * 16 < 255? i * 16:255, gpar = rbpar == 255?255 - i:255;
                GradientDrawable gd = new GradientDrawable();
                gd.SetStroke(5, new Android.Graphics.Color(0, 0, 0));
                gd.SetCornerRadius(10);
                gd.SetColor(new Android.Graphics.Color(rbpar, gpar, rbpar));
                lbtn.SetBackgroundDrawable(gd);

                lbtn.LayoutParameters = lp;

                rbpar = i * 17 < 255 ? i * 17 : 255;
                gpar  = rbpar == 255 ? 255 - i * 2 : 255;
                grd.SetBackgroundColor(new Android.Graphics.Color(rbpar, gpar, rbpar));
                grd.AddView(lbtn);
            }
            // Create your application here
        }
Example #6
0
        private void RandomMethod()
        {
            ArrayList tempCoords = new ArrayList(coordsTile);

            Random random = new Random();

            foreach (MyTextView any in tileArr)
            {
                int randomIndex = random.Next(0, tempCoords.Count);

                Point thisRandomLocation = (Point)tempCoords[randomIndex];


                GridLayout.Spec rowSpec  = GridLayout.InvokeSpec(thisRandomLocation.Y);
                GridLayout.Spec collSpec = GridLayout.InvokeSpec(thisRandomLocation.X);

                GridLayout.LayoutParams randomLayoutParams = new GridLayout.LayoutParams(rowSpec, collSpec);

                any.xPos = thisRandomLocation.X;
                any.yPos = thisRandomLocation.Y;

                randomLayoutParams.Width  = tileWidth - 10;
                randomLayoutParams.Height = tileWidth - 10;
                randomLayoutParams.SetMargins(6, 6, 6, 6);


                any.LayoutParameters = randomLayoutParams;

                tempCoords.RemoveAt(randomIndex);
            }

            emptyTile = (Point)tempCoords[0];
        }
Example #7
0
        public void TextTile_Touch(object sender, View.TouchEventArgs e)
        {
            if (e.Event.Action == MotionEventActions.Up)
            {
                MyImageView thisTile = (MyImageView)sender;
                Console.WriteLine("\r tile is at: \r x={0} \r y={1}", thisTile.xPos, thisTile.yPos);

                float xDif = (float)System.Math.Pow(thisTile.xPos - _emptySlot.X, 2);
                float yDif = (float)System.Math.Pow(thisTile.yPos - _emptySlot.Y, 2);
                float dist = (float)System.Math.Sqrt(xDif + yDif);

                if (dist == 1)
                {
                    Point curPoint = new Point(thisTile.xPos, thisTile.yPos);

                    GridLayout.Spec rowSpec = GridLayout.InvokeSpec(_emptySlot.Y);
                    GridLayout.Spec colSpec = GridLayout.InvokeSpec(_emptySlot.X);

                    GridLayout.LayoutParams newLocParams = new GridLayout.LayoutParams(rowSpec, colSpec);

                    thisTile.xPos = _emptySlot.X;
                    thisTile.yPos = _emptySlot.Y;

                    newLocParams.Width  = _tileWidth - 10;
                    newLocParams.Height = _tileWidth - 10;
                    newLocParams.SetMargins(5, 5, 5, 5);

                    thisTile.LayoutParameters = newLocParams;
                    _emptySlot = curPoint;
                }
            }
        }
Example #8
0
        private void randomizeMethod()
        {
            Random    myRand         = new Random();
            ArrayList copyCoordsList = new ArrayList(_coordinatesList);

            foreach (MyImageView any in _tilesList)
            {
                int   randIndex   = myRand.Next(0, copyCoordsList.Count);
                Point thisRandLoc = (Point)copyCoordsList[randIndex];

                GridLayout.Spec         rowSpec          = GridLayout.InvokeSpec(thisRandLoc.Y);
                GridLayout.Spec         colSpec          = GridLayout.InvokeSpec(thisRandLoc.X);
                GridLayout.LayoutParams randLayoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);

                any.xPos = thisRandLoc.X;
                any.yPos = thisRandLoc.Y;

                randLayoutParams.Width  = _tileWidth - 10;
                randLayoutParams.Height = _tileWidth - 10;
                randLayoutParams.SetMargins(5, 5, 5, 5);

                any.LayoutParameters = randLayoutParams;
                copyCoordsList.RemoveAt(randIndex);
            }
            _emptySlot = (Point)copyCoordsList[0];
        }
        /// <summary>
        /// Randomizes the location of each of the value tiles and the empty space
        /// </summary>
        private void RandomizeTiles()
        {
            _isPuzzleSolved = false;
            List <Point> tempCoords = new List <Point>(_coords);

            Random rand = new Random();

            foreach (MyTextView view in _tiles)
            {
                int   randIndex = rand.Next(0, tempCoords.Count);
                Point randLoc   = tempCoords[randIndex];

                GridLayout.Spec         rowSpec = GridLayout.InvokeSpec(randLoc.Y);
                GridLayout.Spec         colSpec = GridLayout.InvokeSpec(randLoc.X);
                GridLayout.LayoutParams randLayoutParameters = new GridLayout.LayoutParams(rowSpec, colSpec);

                randLayoutParameters.Width  = _tileWidth - 10;
                randLayoutParameters.Height = _tileWidth - 10;
                randLayoutParameters.SetMargins(5, 5, 5, 5);

                view.XPos = randLoc.X;
                view.YPos = randLoc.Y;
                TileIsInCorrectPosition(view);
                view.LayoutParameters = randLayoutParameters;

                tempCoords.RemoveAt(randIndex);
            }
            _emptyLocation = tempCoords[0];
        }
Example #10
0
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
        {
            LayoutInflater inflater = LayoutInflater.From(parent.Context);

            if (_btnList.Count < 61)
            {
                View itemView = inflater.Inflate(Resource.Layout.imglayout, parent, false);
                GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
                layoutParams.SetMargins(20, 20, 20, 20);
                layoutParams.Width        = 100;
                layoutParams.Height       = 100;
                itemView.LayoutParameters = layoutParams;
                return(new RecyclerViewHolder(itemView));
            }
            else
            {
                View itemViewSmall = inflater.Inflate(Resource.Layout.imglayoutsmall, parent, false);
                GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
                layoutParams.SetMargins(15, 15, 15, 15);
                layoutParams.Width             = 65;
                layoutParams.Height            = 65;
                itemViewSmall.LayoutParameters = layoutParams;
                return(new RecyclerViewHolder(itemViewSmall));
            }
        }
Example #11
0
        private void MakeTiles()
        {
            tileWidth = gameViewWidth / 4;

            tilesArray  = new ArrayList();
            coordsArray = new ArrayList();

            int counter = 1;

            #region MyRegion
            for (int h = 0; h < 4; h++)
            {
                for (int v = 0; v < 4; v++)
                {
                    MyTextView textTile = new MyTextView(this);

                    GridLayout.Spec rowSpec = GridLayout.InvokeSpec(h);
                    GridLayout.Spec colSpec = GridLayout.InvokeSpec(v);

                    GridLayout.LayoutParams tileLayoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);

                    //	 0 1 2 3 v/x
                    // 0 T T T T
                    // 1 T T T T
                    // 2 T T T T
                    // 3 T T T T

                    textTile.Text = counter.ToString();
                    textTile.SetTextColor(Color.Black);
                    textTile.TextSize = 40;
                    textTile.Gravity  = GravityFlags.Center;

                    tileLayoutParams.Width  = tileWidth - 10;
                    tileLayoutParams.Height = tileWidth - 10;
                    tileLayoutParams.SetMargins(5, 5, 5, 5);

                    textTile.LayoutParameters = tileLayoutParams;
                    textTile.SetBackgroundColor(Color.Green);

                    Point thisLoc = new Point(v, h);
                    coordsArray.Add(thisLoc);

                    textTile.xPos = thisLoc.X;
                    textTile.yPos = thisLoc.Y;

                    textTile.Touch += TextTile_Touch;

                    tilesArray.Add(textTile);

                    mainLayout.AddView(textTile);
                    counter++;
                }
            }
            #endregion


            mainLayout.RemoveView((MyTextView)tilesArray[15]);
            tilesArray.RemoveAt(15);
        }
Example #12
0
 private GridLayout.LayoutParams GetTileLayoutParams(int x, int y, int colWidth)
 {
     GridLayout.Spec         rowSpec          = GridLayout.InvokeSpec(x);
     GridLayout.Spec         colSpec          = GridLayout.InvokeSpec(y);
     GridLayout.LayoutParams tileLayoutParams = new GridLayout.LayoutParams(rowSpec, colSpec)
     {
         Width  = colWidth - 20,
         Height = ViewGroup.LayoutParams.WrapContent
     };
     tileLayoutParams.SetMargins(5, 5, 5, 5);
     return(tileLayoutParams);
 }
Example #13
0
        private GridLayout.LayoutParams GetTileLayoutParams(int x, int y)
        {
            // Create the specifications that establish in which row and column the tile is going to be rendered
            GridLayout.Spec rowSpec = GridLayout.InvokeSpec(x);
            GridLayout.Spec colSpec = GridLayout.InvokeSpec(y);

            // Create a new layout parameter object for the tile using the previous specs
            GridLayout.LayoutParams tileLayoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);
            tileLayoutParams.Width  = tileWidth - 10;
            tileLayoutParams.Height = tileWidth - 10;
            tileLayoutParams.SetMargins(5, 5, 5, 5);
            return(tileLayoutParams);
        }
Example #14
0
        private void TilesMethod()
        {
            tileWidth = viewGameWidth / 4;

            tileArr    = new ArrayList();
            coordsTile = new ArrayList();

            int counter = 1;

            for (int rows = 0; rows < 4; rows++)
            {
                for (int colls = 0; colls < 4; colls++)
                {
                    MyTextView txtTile = new MyTextView(this);
                    txtTile.Text = counter.ToString();
                    txtTile.SetTextColor(Color.White);
                    txtTile.Gravity  = GravityFlags.Center;
                    txtTile.TextSize = 30;

                    GridLayout.Spec rowSpec  = GridLayout.InvokeSpec(txtTile.xPos);
                    GridLayout.Spec collSpec = GridLayout.InvokeSpec(txtTile.yPos);

                    GridLayout.LayoutParams tileLayoutParams = new GridLayout.LayoutParams(rowSpec, collSpec);

                    tileLayoutParams.Width  = tileWidth - 10;
                    tileLayoutParams.Height = tileWidth - 10;
                    tileLayoutParams.SetMargins(6, 6, 6, 6);

                    txtTile.LayoutParameters = tileLayoutParams;

                    txtTile.SetBackgroundColor(Color.Green);

                    Point point = new Point(colls, rows);
                    coordsTile.Add(point);

                    txtTile.xPos = point.X;
                    txtTile.yPos = point.Y;

                    txtTile.Touch += TxtTile_Touch;

                    tileArr.Add(txtTile);

                    gridLayout.AddView(txtTile);

                    counter++;
                }
            }

            gridLayout.RemoveView((MyTextView)tileArr[15]);
            tileArr.RemoveAt(15);
        }
Example #15
0
        private void MakeTiles()
        {
            tileWidth = gameViewWidth / 4;
            int tileCount = 1;

            for (int row = 0; row < 4; row++)
            {
                for (int col = 0; col < 4; col++)
                {
                    MyTextView      tileText = new MyTextView(this);
                    GridLayout.Spec rowSpec  = GridLayout.InvokeSpec(row);
                    GridLayout.Spec colSpec  = GridLayout.InvokeSpec(col);

                    GridLayout.LayoutParams tileLayoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);
                    tileText.Text = tileCount.ToString();
                    tileText.SetTextColor(Color.Black);
                    tileText.TextSize = 40;
                    tileText.Gravity  = GravityFlags.Center;


                    tileLayoutParams.Width  = tileWidth - 10;
                    tileLayoutParams.Height = tileWidth - 10;
                    tileLayoutParams.SetMargins(5, 5, 5, 5);

                    tileText.LayoutParameters = tileLayoutParams;
                    tileText.SetBackgroundColor(Color.Green);

                    //save coordinates of tile
                    Point tileLocation = new Point(col, row);
                    coordList.Add(tileLocation);
                    tilesList.Add(tileText);

                    //remember the position of the tile
                    tileText.coordX = tileLocation.X;
                    tileText.coordY = tileLocation.Y;

                    tileText.Touch += TouchTile;
                    mainLayout.AddView(tileText);

                    tileCount = tileCount + 1;
                }
            }
            mainLayout.RemoveView((MyTextView)tilesList[15]);
            tilesList.RemoveAt(15);
        }
Example #16
0
        private void TxtTile_Touch(object sender, View.TouchEventArgs e)
        {
            if (e.Event.Action == MotionEventActions.Up)
            {
                if (tileArr.Contains(sender))
                {
                    MyTextView thisTile = (MyTextView)sender;

                    float xDifference = (float)Math.Pow(thisTile.xPos - emptyTile.X, 2);
                    float yDifference = (float)Math.Pow(thisTile.yPos - emptyTile.Y, 2);

                    float distanceXY = (float)Math.Sqrt(xDifference + yDifference);

                    //Tile can move
                    if (distanceXY == 1)
                    {
                        //Memorize where the tile use to be
                        Point currentPoint = new Point(thisTile.xPos, thisTile.yPos);

                        //take the empty tile
                        GridLayout.Spec rowSpec  = GridLayout.InvokeSpec(emptyTile.Y);
                        GridLayout.Spec collSpec = GridLayout.InvokeSpec(emptyTile.X);

                        GridLayout.LayoutParams newLayoutParams = new GridLayout.LayoutParams(rowSpec, collSpec);

                        thisTile.xPos = emptyTile.X;
                        thisTile.yPos = emptyTile.Y;

                        newLayoutParams.Width  = tileWidth - 10;
                        newLayoutParams.Height = tileWidth - 10;
                        newLayoutParams.SetMargins(6, 6, 6, 6);

                        thisTile.LayoutParameters = newLayoutParams;

                        emptyTile = currentPoint;
                    }

                    //#region Test positions touch tile and empty tile
                    //Console.WriteLine($"tile position\nx: {thisTile.xPos}\ny: {thisTile.yPos} ");
                    //Console.WriteLine($"empty tile position\nx: {emptyTile.X}\ny: {emptyTile.Y} ");
                    //#endregion
                }
            }
        }
        void createModalView <T>(T dataRow)
        {
            Type m_tipo = null;

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

            ScrollView scroll = new ScrollView(this);

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

            GridLayout contentModal = new GridLayout(this);

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

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

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

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

            scroll.AddView(contentModal);

            AlertDialog.Builder ventanaModalAlert = new AlertDialog.Builder(this);
            ventanaModalAlert.SetView(scroll);
            ventanaModalAlert.SetNegativeButton("Aceptar", delegate { });
            ventanaModalAlert.Create().Show();
        }
Example #18
0
        // function that executes when the tile is touched
        void TextTile_Touch(object sender, View.TouchEventArgs e)
        {
            if (e.Event.Action == MotionEventActions.Up)
            {
                MyTextView thisTile = (MyTextView)sender;

                // just write the position of the tile in the Xamarin console, to see each tile when moves
                Console.WriteLine("\r tile is at: \r x={0} \r y={1}", thisTile.xPos, thisTile.yPos);

                // compute the distace between the tile which was pressed and the empty space
                float xDif = (float)Math.Pow(thisTile.xPos - emptySpot.X, 2);
                float yDif = (float)Math.Pow(thisTile.yPos - emptySpot.Y, 2);
                float dist = (float)Math.Sqrt(xDif + yDif);

                // if the tile was near the empty space
                if (dist == 1)
                {
                    // memorize the current position of the tile
                    Point curPoint = new Point(thisTile.xPos, thisTile.yPos);

                    // we want to put the tile on the place of the empty space
                    GridLayout.Spec rowSpec = GridLayout.InvokeSpec(emptySpot.Y);
                    GridLayout.Spec colSpec = GridLayout.InvokeSpec(emptySpot.X);

                    GridLayout.LayoutParams newLocParams = new GridLayout.LayoutParams(rowSpec, colSpec);

                    // the tile moves in the empty space
                    thisTile.xPos = emptySpot.X;
                    thisTile.yPos = emptySpot.Y;

                    // we set the appearance of the tile
                    newLocParams.Width  = tileWidth - 10;
                    newLocParams.Height = tileWidth - 10;
                    newLocParams.SetMargins(5, 5, 5, 5);

                    thisTile.LayoutParameters = newLocParams;

                    // the empty place goes where was the pressed tile before
                    emptySpot = curPoint;
                }
            }
        }
Example #19
0
        void TextTile_Touch(object sender, View.TouchEventArgs e)
        {
            if (e.Event.Action == MotionEventActions.Up)
            {
                if (tilesArr.Contains(sender))
                {
                    MyTextView thisTile = (MyTextView)sender;

                    Console.WriteLine("Tile Position X:{0} -- Y:{1}", thisTile.xPos, thisTile.yPos);
                    Console.WriteLine("Empty Position X:{0} -- Y:{1}", emptySpot.X, emptySpot.Y);

                    float xDif = (float)Math.Pow(thisTile.xPos - emptySpot.X, 2);
                    float yDif = (float)Math.Pow(thisTile.yPos - emptySpot.Y, 2);

                    float dist = (float)Math.Sqrt(xDif + yDif);

                    if (dist == 1) // si es verdadero, puede mover
                    {
                        // memoriza donde estaba el tile
                        Point curPoint = new Point(thisTile.xPos, thisTile.yPos);

                        // mueve el tile al lugar vacio
                        GridLayout.Spec rowSpec = GridLayout.InvokeSpec(emptySpot.Y);
                        GridLayout.Spec colSpec = GridLayout.InvokeSpec(emptySpot.X);

                        GridLayout.LayoutParams newLocParams = new GridLayout.LayoutParams(rowSpec, colSpec);

                        thisTile.xPos = emptySpot.X;
                        thisTile.yPos = emptySpot.Y;

                        newLocParams.Width  = tileWidth - 10;
                        newLocParams.Height = tileWidth - 10;
                        newLocParams.SetMargins(5, 5, 5, 5);

                        thisTile.LayoutParameters = newLocParams;

                        // el vacio se mueve donde estaba el tile que tocamos
                        emptySpot = curPoint;
                    }
                }
            }
        }
Example #20
0
        private void randomizeMethod()
        {
            // take a helper to created random number
            Random myRand = new Random();

            // store a copy of the coordinates list
            ArrayList copyCoordsList = new ArrayList(coordinatesList);

            // take each tile (in the variable any) and shuffle it to a new position
            foreach (MyTextView any in tilesList)
            {
                // take random coordinates where to put this tile (tile any)
                int randIndex = myRand.Next(0, copyCoordsList.Count);
                // and store the coordinates in a variable (which is a point in space)
                Point thisRandLoc = (Point)copyCoordsList[randIndex];

                // create a new tile (which is a 1 x 1 part of the whole grid)
                GridLayout.Spec         rowSpec         = GridLayout.InvokeSpec(thisRandLoc.Y);
                GridLayout.Spec         colSpec         = GridLayout.InvokeSpec(thisRandLoc.X);
                GridLayout.LayoutParams randLayoutParam = new GridLayout.LayoutParams(rowSpec, colSpec);

                // also keep the location of the tile any
                any.xPos = thisRandLoc.X;
                any.yPos = thisRandLoc.Y;

                // set the appearance of the tile to look similar
                randLayoutParam.Width  = tileWidth - 10;
                randLayoutParam.Height = tileWidth - 10;
                randLayoutParam.SetMargins(5, 5, 5, 5);

                // set the tile position to be the new shuffled position
                any.LayoutParameters = randLayoutParam;

                // remove the coordinate, so we can't use it anymore for another tile
                copyCoordsList.RemoveAt(randIndex);
            }

            // we have deleted 15 out of 16 tiles, so the remaining one is the one that is empty
            emptySpot = (Point)copyCoordsList[0];
        }
        private void MakeTiles()
        {
            _tileWidth = _gameViewWidth / 4;
            int counter = 1;

            for (int h = 0; h < 4; h++)
            {
                for (int v = 0; v < 4; v++)
                {
                    MyTextView textTile = new MyTextView(this);

                    GridLayout.Spec         rowSpec          = GridLayout.InvokeSpec(h);
                    GridLayout.Spec         colSpec          = GridLayout.InvokeSpec(v);
                    GridLayout.LayoutParams tileLayoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);
                    Point thisLoc = new Point(v, h);

                    tileLayoutParams.Width  = _tileWidth - 10;
                    tileLayoutParams.Height = _tileWidth - 10;
                    tileLayoutParams.SetMargins(5, 5, 5, 5);

                    textTile.Text     = (counter++).ToString();
                    textTile.TextSize = 40;
                    textTile.SetTextColor(Color.Black);

                    textTile.Gravity = GravityFlags.Center;

                    textTile.LayoutParameters = tileLayoutParams;
                    textTile.SetBackgroundColor(_wrongCoordColor);
                    textTile.Touch += TextTile_Touch;

                    textTile.XPos = thisLoc.X;
                    textTile.YPos = thisLoc.Y;
                    _coords.Add(thisLoc);
                    _tiles.Add(textTile);
                    _mainLayout.AddView(textTile);
                }
            }
            _mainLayout.RemoveView(_tiles[15]);
            _tiles.RemoveAt(15);
        }
Example #22
0
        // x=2, y=3
        // x=3, y=3

        private void TextTile_Touch(object sender, View.TouchEventArgs e)
        {
            if (e.Event.Action == MotionEventActions.Up)
            {
                MyTextView thisTile = (MyTextView)sender;

                Console.WriteLine("\r\r\r this tile is at: \r x={0} y={1}", thisTile.xPos, thisTile.yPos);
                Console.WriteLine("\r\r\r empty tile is at: \r x={0} y={1}", emptySpot.X, emptySpot.Y);

                float xDiff = (float)Math.Pow(thisTile.xPos - emptySpot.X, 2);
                float yDiff = (float)Math.Pow(thisTile.yPos - emptySpot.Y, 2);
                float dist  = (float)Math.Sqrt(xDiff + yDiff);

                if (dist == 1)
                {
                    // tile can move
                    // memorize where the tile used to be
                    Point currPoint = new Point(thisTile.xPos, thisTile.yPos);

                    // now take the tile to the empty
                    GridLayout.Spec rowSpec = GridLayout.InvokeSpec(emptySpot.Y);
                    GridLayout.Spec colSpec = GridLayout.InvokeSpec(emptySpot.X);

                    GridLayout.LayoutParams newLocalParams = new GridLayout.LayoutParams(rowSpec, colSpec);

                    thisTile.xPos = emptySpot.X;
                    thisTile.yPos = emptySpot.Y;

                    newLocalParams.Width  = tileWidth - 10;
                    newLocalParams.Height = tileWidth - 10;
                    newLocalParams.SetMargins(5, 5, 5, 5);


                    thisTile.LayoutParameters = newLocalParams;

                    emptySpot = currPoint;
                }
            }
        }
Example #23
0
        public GridXCellView(Context context, GenGrid gridgen, int x, int y) : base(context)
        {
            char ltr = gridgen._chars[x, y];

            this._ltr = ltr;
            var layoutParam = new GridLayout.LayoutParams();

            layoutParam.SetMargins(margin, margin, margin, margin);
            if (MainActivity._instance._ptScreenSize.X > MainActivity._instance._ptScreenSize.Y) //landscape
            {
                layoutParam.Width = MainActivity._instance._ptScreenSize.X / 2 / MainActivity._instance._nCols - 2 * margin;
            }
            else
            {
                layoutParam.Width = MainActivity._instance._ptScreenSize.X / MainActivity._instance._nCols - 2 * margin;
            }
            this.TextAlignment    = Android.Views.TextAlignment.Center;
            this.LayoutParameters = layoutParam;
            if (this._ltr != GenGrid.Blank)
            {
                var fontSize = 14;
                if (gridgen._MaxX > 12)
                {
                    fontSize = 12;
                }
                SetBackgroundColor(Color.DarkCyan);
                SetTextColor(Color.White);
                this.TextSize = fontSize;
                this.SetTypeface(null, TypefaceStyle.Bold);
                this.Touch += GridXCellView_Touch;
            }
            else
            {
                this.Visibility = Android.Views.ViewStates.Invisible;
                IsShowing       = true;
            }
        }
        private void TextTile_Touch(object sender, View.TouchEventArgs e)
        {
            if (!_isPuzzleSolved)
            {
                if (e.Event.Action == MotionEventActions.Up)
                {
                    MyTextView thisTile = sender as MyTextView;

                    //determine if the square that was clicked is next to the open space
                    if (Math.Sqrt(Math.Pow((thisTile.XPos - _emptyLocation.X), 2) +
                                  Math.Pow(thisTile.YPos - _emptyLocation.Y, 2)) == 1)
                    {
                        //save the location of the clicked button before moving it to the location that the empty square occupies
                        Point currentPoint = new Point(thisTile.XPos, thisTile.YPos);

                        GridLayout.Spec rowSpec = GridLayout.InvokeSpec(_emptyLocation.Y);
                        GridLayout.Spec colSpec = GridLayout.InvokeSpec(_emptyLocation.X);

                        GridLayout.LayoutParams newLocParams = new GridLayout.LayoutParams(rowSpec, colSpec);

                        thisTile.XPos = _emptyLocation.X;
                        thisTile.YPos = _emptyLocation.Y;

                        newLocParams.Width  = _tileWidth - 10;
                        newLocParams.Height = _tileWidth - 10;
                        newLocParams.SetMargins(5, 5, 5, 5);

                        thisTile.LayoutParameters = newLocParams;
                        //move the empty square to the location originally occupied by the tile
                        _emptyLocation = currentPoint;
                        TileIsInCorrectPosition(thisTile);
                    }
                    System.Diagnostics.Debug.WriteLine($"\r\r\rThis tile is at ({thisTile.XPos},{thisTile.YPos})");
                }
            }
        }
Example #25
0
		async Task DrawBoard(int tileCount)
		{
			await Task.Factory.StartNew(() =>
			{
				try
				{
					for(var i = 0; i < tileCount; i++)
					{
						var tile = new LinearLayout(this);
						tile.SetBackgroundColor(Resources.GetColor(Resource.Color.white));
						var p = new GridLayout.LayoutParams() { Height = 112, Width = 112 };
						p.SetMargins(4, 4, 4, 4);
						tile.LayoutParameters = p;
						RunOnUiThread(() =>
						{
							tile.Click += TileClick;
							tile.LongClick += TileLongClick;
							_grid.AddView(tile);
							_subViews[_grid.IndexOfChild(tile)] = tile;
						});
					}
				}
				catch(Exception ex)
				{
					Console.WriteLine(ex);
				}
			});
		}
		//--->TERMINAN COSAS DE SELECCIONAR IMAGEN DE LA CAMARA<---//

		//INICIA PROCESAR IMAGENES
		public void ProcesarImagenes (GridLayout imgcomprev, int limite, TextView imgrestantes){

			if(imgcount<limite){
				GetImage(((b, p) => {
					int countimage = p.Count;
					Log.Debug("GetImage","Imagenes en el list: "+countimage);
					int imgcount2=imgcount+countimage;
					Log.Debug("GetImage","Imagenes totales: "+imgcount2);

					if(imgcount2>limite){
						//int total = limite-imgcount;
						var fabee = FindViewById<CoordinatorLayout> (Resource.Id.snackbarPosition);
						Snackbar
							.Make (fabee, "No puedes publicar mas de "+limite+" imágenes!", Snackbar.LengthLong)
							.SetAction ("Ok", (view) => {  })
							.Show ();	
					}else{
						//ya aqui se hace lo de poner cada imagen
						imgcount=imgcount2;
						Log.Debug("GetImage","Nuevo imgcount: "+imgcount);


						for(int i=0; i<countimage; i++){
							//filenameres= p[i].Substring (p[i].LastIndexOf ("/") + 1);
							//fileextres= filenameres.Substring (filenameres.LastIndexOf(".")+1);

							//Si por algún acaso la memoria no ha sido liberada, la liberamos primero.
							if (imagencomentario != null && !imagencomentario.IsRecycled) {
								imagencomentario.Recycle();
								imagencomentario = null; 
							}

							Java.IO.File f = new Java.IO.File(p[i]);
							stream = this.ContentResolver.OpenInputStream(Android.Net.Uri.FromFile(f));
							imagencomentario=BitmapFactory.DecodeStream(stream);
							//POR AHORA VAMOS A QUITAR ESTO PARA QUE LO HAGA MAS RAPIDO Y DEJAMOS QUE EL SERVIDOR SE ENCARGUE

							/*
							try{
								Android.Media.ExifInterface ei = new Android.Media.ExifInterface(p[i]);
								var orientation= ei.GetAttributeInt(Android.Media.ExifInterface.TagOrientation, -1);
								Log.Debug("GetImageCamera","El orientation es: "+orientation);

								if(orientation==1){
									//No hagas nada, si está bien la imagen. No tiene caso .-.
								}else{


								Log.Debug("Orientation", "Inicia Mutable");
								Bitmap mutable;
								Canvas cnv;
								Matrix matrix;
								Log.Debug("Orientation", "Termina Mutable");

								Log.Debug("Orientation", "Inicia Switch");
								switch(orientation){
								case 6:
									//90 grados
									mutable = imagencomentario.Copy(Bitmap.Config.Argb8888, true);
									cnv = new Canvas(mutable);
									matrix = new Matrix();
									Log.Debug("Orientation", "90 Grados");
									matrix.PostRotate(90);
									imagencomentario=Bitmap.CreateBitmap(mutable, 0, 0,  imagencomentario.Width, imagencomentario.Height, matrix, true);
									break;

								case 3:
									//180 grados
									mutable = imagencomentario.Copy(Bitmap.Config.Argb8888, true);
									cnv = new Canvas(mutable);
									matrix = new Matrix();
									Log.Debug("Orientation", "180 Grados");
									matrix.PostRotate(180);
									imagencomentario=Bitmap.CreateBitmap(mutable, 0, 0,  imagencomentario.Width, imagencomentario.Height, matrix, true);
									break;

								case 8:
									//270 grados
									mutable = imagencomentario.Copy(Bitmap.Config.Argb8888, true);
									cnv = new Canvas(mutable);
									matrix = new Matrix();
									Log.Debug("Orientation", "270 Grados");
									matrix.PostRotate(270);
									imagencomentario=Bitmap.CreateBitmap(mutable, 0, 0,  imagencomentario.Width, imagencomentario.Height, matrix, true);
									break;

								default:
									Log.Debug("Orientation", "0 Grados (0 360, como se quiera ver :P)");
									//0 grados
									//No hagas nada
									break;
								};

								Log.Debug("Orientation", "Termina Switch");
								}//ELSE orientation = 1
							}catch(Exception ex){
								Log.Debug("Orientation", "ERROR! Posiblemente no hay EXIF: "+ex);
							}
							*/

							if(imagencomentario!=null){
								//Toast.MakeText(this, "Si se creó el Bitmap!!!", ToastLength.Long).Show();
								//Lo añadimos a la lista
								//Bitmap tmp = imagencomentario;

								Log.Debug("FOSSBYTES","Inicia conversión a bytes!");
								byte[] tmp2 = PathToByte2(p[i]);
								Log.Debug("FOSSBYTES","Termina conversión a bytes!");
								fossbytes.Add(tmp2);
								//Toast.MakeText(this, "Elementos en lista: "+contenedorimagenes.Count, ToastLength.Long).Show();

								//aqui haremos el img


								//Creamos el imageview con sus parámetros
								ImageView prev = new ImageView(this);
								imgcomprev.AddView(prev);
								GridLayout.LayoutParams lp = new  GridLayout.LayoutParams();    
								lp.SetMargins(15,15,0,15);
								lp.Width=130;
								lp.Height=130;
								prev.LayoutParameters=lp;
								prev.SetScaleType(ImageView.ScaleType.CenterCrop);
								prev.SetImageBitmap(Bitmap.CreateScaledBitmap(imagencomentario, 175, 175, false));
								//prev.StartAnimation(bounce);





								//imgcount++;

								//Liberamos la memoria Inmediatamente!
								if (imagencomentario != null && !imagencomentario.IsRecycled) {
									imagencomentario.Recycle();
									imagencomentario = null; 
								}
								//Mala idea, esto causó que tronara .-. si lo voy a hacer pero cuando no tenga que usarlo

							}else{//por si algun acaso intenta procesar una ruta null
								var fabee = FindViewById<CoordinatorLayout> (Resource.Id.snackbarPosition);
								Snackbar
									.Make (fabee, "Ocurrió un error. Por favor intenta con una imágen diferente", Snackbar.LengthLong)
									.SetAction ("Ok", (view) => {  })
									.Show ();	
								break;
							}

						}//TERMINA EL FOR PARA CADA IMAGEN 


						int restantes=limite-imgcount;
						if(restantes==0){
							imgrestantes.Text="¡Excelente!";
						}else{
							imgrestantes.Text="Puedes cargar "+restantes+" imágenes más!";
						}



					}//TERMINA EL ELSE DE COMPROBAR SI HAY MAS IMAGENES DE LAS QUE SE PUEDEN CARGAR

				}));//GETIMAGE

			}else{

				var fabee = FindViewById<CoordinatorLayout> (Resource.Id.snackbarPosition);
				Snackbar
					.Make (fabee, "Solo puedes subir hasta 3 imágenes!", Snackbar.LengthLong)
					.SetAction ("Ok", (view) => {  })
					.Show ();	

			}//ELSE COUNTIMAGES < 3

		}
Example #27
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            //游戏开始
            ImageView imgStart = FindViewById<ImageView>(Resource.Id.imgStart);
            imgStart.Click += delegate
            {
                var intent = new Intent(this, typeof(GameActivity));
                intent.PutExtra("game", GameIndex);
                StartActivityForResult(intent, 0);
                Finish();
            };
            //游戏退出
            ImageView imgExit = FindViewById<ImageView>(Resource.Id.imgExit);
            imgExit.Click += delegate
            {
                Finish();
            };
            //绑定关卡列表
            glBarriers = FindViewById<GridLayout>(Resource.Id.glBarriers);
            //BarrierList = _db.QueryAllBarriers();
            BarrierList = new List<Barrier>();
            var names = Resources.GetStringArray(Resource.Array.barrier_names);
            var titles = Resources.GetStringArray(Resource.Array.barrier_titles);
            for (int i = 0; i < names.Length; i++)
            {
                var barrier = DB.QueryBarrier(i);
                if (barrier == null)
                {
                    barrier = new Barrier() { Id = i, Title = titles[i], Name = names[i], Star = 0, State = (i == 0 ? true : false), NextID = (i == names.Length - 1) ? 0 : (i + 1) };
                    DB.Insert(barrier);
                }
                BarrierList.Add(barrier);
                LinearLayout linear = new LinearLayout(this);
                GridLayout.LayoutParams g = new GridLayout.LayoutParams();
                g.Width = GridLayout.LayoutParams.WrapContent;
                g.Height = GridLayout.LayoutParams.WrapContent;

                if (Resources.DisplayMetrics.Density == 1)
                {
                    g.SetMargins(17, 20, 17, 20);
                }
                else
                {
                    g.SetMargins(17, 20, 17, 20);
                }
                linear.LayoutParameters = g;
                linear.Orientation = Orientation.Vertical;
                linear.SetGravity(GravityFlags.Center);
                linear.Clickable = false;
                LinearLayout linearLayout = new LinearLayout(this);
                LinearLayout.LayoutParams m = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
                linearLayout.LayoutParameters = m;
                if (barrier.State)
                {
                    linearLayout.SetBackgroundResource(Resource.Drawable.home_icon_on);
                }
                else if (!barrier.State)
                {
                    linearLayout.SetBackgroundResource(Resource.Drawable.home_icon_off);
                }
                linearLayout.SetGravity(GravityFlags.Bottom);
                linearLayout.Orientation = Orientation.Vertical;
                linearLayout.Id = barrier.Id;
                linearLayout.SetOnClickListener(this);
                if (barrier.Id == 0)
                {
                    linearLayout.SetBackgroundResource(Resource.Drawable.home_icon_on_selected);
                }

                TextView textView = new TextView(this);
                LinearLayout.LayoutParams t = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent);
                if (Resources.DisplayMetrics.Density == 1)
                {
                    t.BottomMargin = 10;
                    textView.SetTextSize(Android.Util.ComplexUnitType.Sp, 15);
                }
                else
                {
                    t.BottomMargin = 5;
                    textView.SetTextSize(Android.Util.ComplexUnitType.Sp, 10);
                }
                textView.LayoutParameters = t;
                textView.Text = barrier.Title;
                textView.SetTextColor(Android.Graphics.Color.White);
                textView.Gravity = GravityFlags.Center;

                linearLayout.AddView(textView);

                LinearLayout ll = new LinearLayout(this);
                LinearLayout.LayoutParams l = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);

                ll.LayoutParameters = l;
                ll.Orientation = Orientation.Horizontal;
                ll.SetGravity(GravityFlags.Center);
                for (int j = 1; j <= 3; j++)
                {
                    ImageView imageView = new ImageView(this);
                    LinearLayout.LayoutParams imageLayout;
                    if (Resources.DisplayMetrics.Density == 1)
                    {
                        imageLayout = new LinearLayout.LayoutParams(30, 30);
                    }
                    else
                    {
                        imageLayout = new LinearLayout.LayoutParams(30, 30);
                    }
                    imageView.LayoutParameters = imageLayout;
                    if (j <= barrier.Star)
                    {
                        imageView.SetImageResource(Resource.Drawable.game_star_1);
                    }
                    else
                    {
                        imageView.SetImageResource(Resource.Drawable.game_star_2);
                    }
                    if (barrier.Star == 0)
                    {
                        imageView.Visibility = ViewStates.Invisible;
                    }
                    ll.AddView(imageView);
                }
                linear.AddView(linearLayout);
                linear.AddView(ll);
                glBarriers.AddView(linear);
            }
        }
Example #28
0
        private void makeTilesMethod()
        {
            _tileWidth = _gameViewWidth / 3;

            int    counter    = 1;
            string imgsource  = "piece" + counter;
            string fullsource = "Resource.Drawable." + imgsource;

            _tilesList       = new ArrayList();
            _coordinatesList = new ArrayList();

            for (int row = 0; row < 3; ++row)
            {
                for (int column = 0; column < 3; ++column)
                {
                    MyImageView ImageTile = new MyImageView(_context);

                    GridLayout.Spec rowSpec = GridLayout.InvokeSpec(row);
                    GridLayout.Spec colSpec = GridLayout.InvokeSpec(column);

                    GridLayout.LayoutParams tileLayoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);

                    //ImageTile.Text = counter.ToString();
                    //ImageTile.SetTextColor(Color.Black);
                    //ImageTile.TextSize = 40;
                    //ImageTile.Gravity = GravityFlags.Center;

                    if (counter == 1)
                    {
                        ImageTile.SetImageResource(Resource.Drawable.piece1);
                    }
                    else if (counter == 2)
                    {
                        ImageTile.SetImageResource(Resource.Drawable.piece2);
                    }
                    else if (counter == 3)
                    {
                        ImageTile.SetImageResource(Resource.Drawable.piece3);
                    }
                    else if (counter == 4)
                    {
                        ImageTile.SetImageResource(Resource.Drawable.piece4);
                    }
                    else if (counter == 5)
                    {
                        ImageTile.SetImageResource(Resource.Drawable.piece5);
                    }
                    else if (counter == 6)
                    {
                        ImageTile.SetImageResource(Resource.Drawable.piece6);
                    }
                    else if (counter == 7)
                    {
                        ImageTile.SetImageResource(Resource.Drawable.piece7);
                    }
                    else if (counter == 8)
                    {
                        ImageTile.SetImageResource(Resource.Drawable.piece8);
                    }

                    tileLayoutParams.Width  = _tileWidth - 10;
                    tileLayoutParams.Height = _tileWidth - 10;
                    tileLayoutParams.SetMargins(5, 5, 5, 5);

                    ImageTile.LayoutParameters = tileLayoutParams;
                    //textTile.SetBackgroundColor(Color.Green);

                    Point thisLocation = new Point(column, row);
                    _coordinatesList.Add(thisLocation);
                    _tilesList.Add(ImageTile);

                    ImageTile.xPos = thisLocation.X;
                    ImageTile.yPos = thisLocation.Y;

                    ImageTile.Touch += TextTile_Touch;

                    _puzzleLayout.AddView(ImageTile);

                    counter += 1;
                }
            }
            _puzzleLayout.RemoveView((MyImageView)_tilesList[8]);
            _tilesList.RemoveAt(8);
        }
Example #29
0
        public GridLayout AddFriendLayout(int givenID, byte[] pictureCode, string username, string message)
        {
            //TODO: Add Binding programmatically
            this.CreateBindingSet <FriendlistUI, FriendlistFragmentViewModel>();

            GridLayout.Spec gridColumn = GridLayout.InvokeSpec(16, GridLayout.BaselineAlighment);
            GridLayout.Spec gridRow    = GridLayout.InvokeSpec(16, GridLayout.BaselineAlighment);

            GridLayout.LayoutParams gl = new GridLayout.LayoutParams(gridRow, gridColumn);

            GridLayout gridLayout = new GridLayout(Context);

            gridLayout.LayoutParameters = gl;

            /* gridLayout.Orientation = GridOrientation.Horizontal;
             * gridLayout.Id = givenID;*/

            GridLayout.Spec imageColumn = GridLayout.InvokeSpec(0, GridLayout.BaselineAlighment);
            GridLayout.Spec imageRow    = GridLayout.InvokeSpec(0, GridLayout.BaselineAlighment);

            GridLayout.Spec usernameColumn = GridLayout.InvokeSpec(0, GridLayout.BaselineAlighment);
            GridLayout.Spec usernameRow    = GridLayout.InvokeSpec(0, GridLayout.BaselineAlighment);

            GridLayout.Spec messageColumn = GridLayout.InvokeSpec(0, GridLayout.BaselineAlighment);
            GridLayout.Spec messageRow    = GridLayout.InvokeSpec(0, GridLayout.BaselineAlighment);

            GridLayout.LayoutParams usernameLayout = new GridLayout.LayoutParams(usernameRow, usernameColumn);
            usernameLayout.SetMargins(256, 32, 0, 0);

            GridLayout.LayoutParams messageLayout = new GridLayout.LayoutParams(messageRow, messageColumn);
            messageLayout.SetMargins(248, 112, 0, 0);

            GridLayout.LayoutParams imageLayout = new GridLayout.LayoutParams(imageRow, imageColumn);
            imageLayout.SetMargins(48, 32, 0, 0);
            imageLayout.Width  = 196;
            imageLayout.Height = 196;

            ImageView imageView = new ImageView(Context);
            Bitmap    bmp       = BitmapFactory.DecodeByteArray(pictureCode, 0, pictureCode.Length);

            imageView.SetImageBitmap(bmp);
            imageView.LayoutParameters = imageLayout;

            TextView usernameView = new TextView(Context);

            usernameView.Text = username;
            usernameView.SetTextColor(Color.White);
            usernameView.SetTextSize(Android.Util.ComplexUnitType.Px, 64);
            usernameView.LayoutParameters = usernameLayout;

            TextView messageView = new TextView(Context);

            messageView.Text = message;
            messageView.SetTextColor(Color.White);
            messageView.SetTextSize(Android.Util.ComplexUnitType.Px, 48);
            messageView.LayoutParameters = messageLayout;

            gridLayout.AddView(imageView, imageLayout);
            gridLayout.AddView(usernameView, usernameLayout);
            gridLayout.AddView(messageView, messageLayout);

            return(gridLayout);
        }
Example #30
0
        // method to create the grid layout
        private void makeTilesMethod()
        {
            // the grid is 4 x 4 -> the width of a tile is a quarter of the width of the grid
            tileWidth = gameViewWidth / 4;

            // create a counter to keep in mind the number of the tile
            int counter = 1;

            // initialize the lists for storing the coordinates of the tiles
            tilesList       = new ArrayList();
            coordinatesList = new ArrayList();

            // we need to create all 16 tiles, they being placed on 4 rows and 4 columns
            for (int row = 0; row < 4; ++row)
            {
                for (int column = 0; column < 4; ++column)
                {
                    // we want to make a tile and add it in our main layout
                    MyTextView textTile = new MyTextView(this);

                    // we want to put a tile on the row 'row' and column 'column'
                    GridLayout.Spec rowSpec = GridLayout.InvokeSpec(row);
                    GridLayout.Spec colSpec = GridLayout.InvokeSpec(column);

                    GridLayout.LayoutParams tileLayoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);

                    // print the number of the tile on it
                    textTile.Text = counter.ToString();
                    textTile.SetTextColor(Color.Black);
                    textTile.TextSize = 40;
                    textTile.Gravity  = GravityFlags.Center; // put the text in the center of the tile

                    // set the width and height of the tile
                    tileLayoutParams.Width  = tileWidth - 10; // (-10) for visibility
                    tileLayoutParams.Height = tileWidth - 10; // (-10) for visibility
                    tileLayoutParams.SetMargins(5, 5, 5, 5);  // for making a nice looking contour


                    // make the changes in the actual textTile
                    textTile.LayoutParameters = tileLayoutParams;
                    textTile.SetBackgroundColor(Color.Green);

                    // keep the coordinates of a tile (as a point in space, where the X coordinate is the column and Y coordiante is the row)
                    Point thisLocation = new Point(column, row);
                    // add the coordiante of this point in the coordinatesList
                    coordinatesList.Add(thisLocation);
                    // add the tile in the list, to use it later
                    tilesList.Add(textTile);

                    // remember the position if the tile
                    textTile.xPos = thisLocation.X;
                    textTile.yPos = thisLocation.Y;

                    // assign a method to execute when we toch the button
                    textTile.Touch += TextTile_Touch;

                    // add the tile in the main layout
                    mainLayout.AddView(textTile);

                    // increase the counter to the next number
                    counter = counter + 1;
                }
            }

            // remove the 16th tile -> tilesList start from the position 0 (not 1 as expected), so the 16th element is on the position 15
            mainLayout.RemoveView((MyTextView)tilesList[15]);
            // remove the 16th tile also from our list
            tilesList.RemoveAt(15);
        }
Example #31
0
        /// <summary>
        /// ������ϷTitle�Ͷ�Ӧʡ���б�
        /// </summary>
        public void SetGameTitle()
        {
            txtTitle.Text = Barrier.Title;
            List<Barrier> list = ShengDaoList.ToList();
            list.Sort(delegate(Barrier a, Barrier b) { return (new Random()).Next(-1, 1); });
            glShengList.RemoveAllViews();
            foreach (var item in list)
            {
                TextView textView = new TextView(this);

                GridLayout.LayoutParams m = new GridLayout.LayoutParams();
                m.Width = GridLayout.LayoutParams.WrapContent;
                m.Height = GridLayout.LayoutParams.WrapContent;
                if (Resources.DisplayMetrics.Density == 1)
                {
                    m.SetMargins(10, 10, 10, 10);
                    textView.SetTextSize(Android.Util.ComplexUnitType.Sp, 22);
                }
                else
                {
                    m.SetMargins(5, 5, 5, 5);
                }
                textView.LayoutParameters = m;
                textView.SetTextColor(Android.Graphics.Color.White);
                textView.SetBackgroundResource(Resource.Drawable.game_sheng);
                textView.Gravity = GravityFlags.Center;
                textView.Text = item.Name;
                textView.Id = item.Id;
                textView.SetOnClickListener(this);

                glShengList.AddView(textView);
            }
            switch (Barrier.Id)
            {
                case 0:
                    imgPeople.SetImageResource(Resource.Drawable.game_people_jian);
                    break;
                case 1:
                    imgPeople.SetImageResource(Resource.Drawable.game_people_ling);
                    break;
                case 2:
                    imgPeople.SetImageResource(Resource.Drawable.game_people_qian);
                    break;
                case 3:
                    imgPeople.SetImageResource(Resource.Drawable.game_people_yao);
                    break;
                case 4:
                    imgPeople.SetImageResource(Resource.Drawable.game_people_ye);
                    break;
            }
        }