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]; }
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 }
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]; }
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]; }
private void randomizeMethod() { // 16 tiles. //16 locations. //go through tiles in order //assign a random coord to them. Random myRandom = new Random(); foreach (ImageView any in tilesArr) { int randomIndex = myRandom.Next(0, coordsArr.Count); Point newRandCoord = coordsArr[randomIndex]; GridLayout.Spec randomRowSpec = GridLayout.InvokeSpec(newRandCoord.X); GridLayout.Spec randomColSpec = GridLayout.InvokeSpec(newRandCoord.Y); GridLayout.LayoutParams randGridParams = new GridLayout.LayoutParams(randomRowSpec, randomColSpec); randGridParams.Width = tileWidth; randGridParams.Height = tileWidth; any.LayoutParameters = randGridParams; coordsArr.RemoveAt(randomIndex); } }
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; } } }
private void randomizeMethod( ) { Random myRandom = new Random( ); foreach (ImageView any in tilesArr) { int randomIndex = myRandom.Next(0, coordsArr.Count); Point newRandCoord = coordsArr[randomIndex]; GridLayout.Spec randomRowSpec = GridLayout.InvokeSpec(newRandCoord.X); GridLayout.Spec randomColSPec = GridLayout.InvokeSpec(newRandCoord.Y); GridLayout.LayoutParams randGirdParams = new GridLayout.LayoutParams(randomRowSpec, randomColSPec); randGirdParams.Width = tileWidth; randGirdParams.Height = tileWidth; any.LayoutParameters = randGirdParams; coordsArr.RemoveAt(randomIndex); } }
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)); } }
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]; }
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; } } }
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]; }
public void SetWordList(IEnumerable <FoundWord> lstWords) { _grdWordList.RemoveAllViews(); int ndx = 0; if (lstWords != null && _mainActivity._chkShowWordList.Checked) { foreach (var item in lstWords) { LetterWheelLayout.GetColorFromFoundWordType(item.foundWordType, out var forecolr, out var backColr); var tv = new TextView(_mainActivity) { Text = item.word, }; tv.SetBackgroundColor(backColr); tv.SetTextColor(forecolr); tv.Click += (o, e) => { MainActivity.DoLookupOnlineDictionary(tv.Text); }; var x = ndx / _grdWordList.RowCount; var y = ndx - x * _grdWordList.RowCount; var parms = new GridLayout.LayoutParams(GridLayout.InvokeSpec(y), GridLayout.InvokeSpec(x)); tv.LayoutParameters = parms; parms.RightMargin = 5; // ((GridLayout.LayoutParams)(tv.LayoutParameters)).RightMargin = 2; _grdWordList.AddView(tv); ndx++; } } _mainActivity._txtWordListLen.Text = ndx.ToString(); }
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); }
private void tileMakerMethod() { // know the grid size ... gridSize // know the tile width and height //know where to place tile in grid layout //know which image to display on tiles tileWidth = screenWidth / gridSize; System.String imageName; int imgNumber = 0; for (int h = 0; h < gridSize; h++) { for (int v = 0; v < gridSize; v++) { ImageView imgTile = new ImageView(this); Point thisCoord = new Point(h, v); coordsArr.Add(thisCoord); GridLayout.Spec rowSpec = GridLayout.InvokeSpec(thisCoord.X); GridLayout.Spec colSpec = GridLayout.InvokeSpec(thisCoord.Y); GridLayout.LayoutParams tileParams = new GridLayout.LayoutParams(rowSpec, colSpec); tileParams.Width = tileWidth; tileParams.Height = tileWidth; if (imgNumber == gridSize * gridSize / 2) { imgNumber = 0; } imageName = imgsArr[imgNumber] as string; int resId = Resources.GetIdentifier(imageName, "drawable", PackageName); imgTile.SetImageResource(resId); imgTile.LayoutParameters = tileParams; imgTile.SetOnTouchListener(this); tilesArr.Add(imgTile); gameGridLayout.AddView(imgTile); imgNumber++; } } // have an array of all tiles //ORDERED from 0 to gridsize X gridSize // and have an array of all coords. }
private void tileMakerMethod( ) { tileWidth = screenWidth / gridSize; System.String imageName; int imgNumber = 0; for (int h = 0; h < gridSize; h++) { for (int v = 0; v < gridSize; v++) { ImageView imgTile = new ImageView(this); Point thisCoord = new Point(h, v); coordsArr.Add(thisCoord); GridLayout.Spec rowSpec = GridLayout.InvokeSpec(h); GridLayout.Spec colSpec = GridLayout.InvokeSpec(v); GridLayout.LayoutParams tileParams = new GridLayout.LayoutParams(rowSpec, colSpec); tileParams.Width = tileWidth; tileParams.Height = tileWidth; if (imgNumber == gridSize * gridSize / 2) { imgNumber = 0; } imageName = imgsArr[imgNumber] as string; int resId = Resources.GetIdentifier(imageName, "drawable", PackageName); imgTile.SetImageResource(resId); imgTile.LayoutParameters = tileParams; imgTile.SetOnTouchListener(this); tilesArr.Add(imgTile); gameGridLayout.AddView(imgTile); imgNumber++; } } }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var view = inflater.Inflate(Resource.Layout.fragment_select_game, container, false); root = view.FindViewById <ViewGroup>(Resource.Id.root); var label = view.FindViewById <TextView>(Resource.Id.text); label.Text = GameSet.Name; root.SetBackgroundColor(Android.Graphics.Color.ParseColor(GameSet.Color)); grid = view.FindViewById <SquareGridLayout>(Resource.Id.grid); int gameCount = GameSet.GameCount; var cols = (int)Math.Sqrt(gameCount); var rows = (int)(gameCount / cols); if ((cols * rows) < gameCount) { rows++; } grid.ColumnCount = cols; grid.RowCount = rows; grid.RemoveAllViews(); for (int i = 0; i < GameSet.GameCount; i++) { int row = i / grid.ColumnCount; int col = i % grid.ColumnCount; var gameDefinition = GameSet.Games[i]; var highScore = GameData.Current.GetGameHighScore(gameDefinition); if (string.IsNullOrWhiteSpace(gameDefinition.Name)) { gameDefinition.Name = (i + 1).ToString(); } var squareWidget = new SquareWidget(Context); squareWidget.GameDefinition = gameDefinition; squareWidget.Text = gameDefinition.Name; //squareWidget.IsSelected = false; squareWidget.ShowBackground = highScore == null; var layoutParams = new GridLayout.LayoutParams( GridLayout.InvokeSpec(row, 1f), // Row GridLayout.InvokeSpec(col, 1f)); // Col grid.AddView(squareWidget, layoutParams); squareWidget.Click += SquareView_Click; } return(view); }
protected override void OnElementChanged(ElementChangedEventArgs <RoundedComboBox> e) { base.OnElementChanged(e); if (e.OldElement != null || Element == null) { return; } if (Control == null) { var grid = new GridLayout(this.Context); grid.SetPadding(0, 0, 0, 0); grid.Clickable = false; grid.SetBackgroundColor(Xamarin.Forms.Color.Transparent.ToAndroid()); spinnerAlert = new AlertDialog.Builder(this.Context); textView = new TextView(this.Context); //alert = spinnerAlert.Create(); textViewLayoutParam = new GridLayout.LayoutParams(); textViewLayoutParam.RowSpec = GridLayout.InvokeSpec(0, GridLayout.Fill); textViewLayoutParam.ColumnSpec = GridLayout.InvokeSpec(0, GridLayout.Fill); grid.AddView(textView, textViewLayoutParam); SetNativeControl(grid); SetTextAlignment(); SetText(); SetTextColor(); CreateShapeDrawable(); SetSpinnerAdapter(new List <string>()); SetItemsSource(); SetTypeface(); textView.Click += async(s, ev) => { if (alert != null) { if (Element.IsEnabled) { alert.Show(); SetSelectedIndex(); } } //spinnerAlert.Show(); }; this.Background = new ColorDrawable(Xamarin.Forms.Color.Transparent.ToAndroid()); } }
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); }
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); }
private RelativeLayout CreateMovieContainer() { RelativeLayout container = new RelativeLayout(this); GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); layoutParams.SetGravity(GravityFlags.Center); layoutParams.Height = 810; layoutParams.Width = 420; layoutParams.LeftMargin = layoutParams.RightMargin = 60; layoutParams.TopMargin = layoutParams.BottomMargin = 30; container.LayoutParameters = layoutParams; return(container); }
private void 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); }
private void AddSymbol(Symbol symbol) { var sd = new SymbolDisplay(this) { Symbol = symbol }; sd.SetMaxHeight(40); var p = new GridLayout.LayoutParams(); p.SetGravity(GravityFlags.Center); sd.LayoutParameters = p; rootLayout.AddView(sd); }
protected override void OnCreate(Bundle savedInstanceState) { SetTheme(AppConst.targetTheme); base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.DetectiveGame); _gameTileGrid = FindViewById <GridLayout>(Resource.Id.GameTileGrid); GridLayout.LayoutParams parm = new GridLayout.LayoutParams(); //parm.ColumnSpec = 0; base.OnCreate(savedInstanceState); // Create your application here }
private Button CreateSessionTile(Session session) { Button tile = new Button(this); tile.Text = session.Time; tile.SetTextColor(Android.Graphics.Color.Black); tile.SetBackgroundColor(Android.Graphics.Color.White); tile.TextSize = 20; tile.SetPadding(60, 0, 60, 0); GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); layoutParams.LeftMargin = layoutParams.RightMargin = 40; layoutParams.TopMargin = 20; tile.LayoutParameters = layoutParams; tile.Touch += (object sender, View.TouchEventArgs e) => { SelectSession(tile, session); }; return(tile); }
private View GetCircularVideoPlayer() { LinearLayout linearLayout = new LinearLayout(this.context) { Orientation = Orientation.Vertical }; this.videoPlayerProgressBar = new SfCircularProgressBar(this.context) { Progress = 100, ShowProgressValue = true, TrackInnerRadius = 0f, IndicatorOuterRadius = 0.7f, IndicatorInnerRadius = 0.65f, AnimationDuration = 10000, LayoutParameters = this.layoutParams }; GridLayout.LayoutParams gridLayoutParams = new GridLayout.LayoutParams { RowSpec = GridLayout.InvokeSpec(0), ColumnSpec = GridLayout.InvokeSpec(0) }; GridLayout custContentLayout = new GridLayout(this.context); this.playButton = new ImageButton(this.context) { Visibility = ViewStates.Invisible }; this.playButton.SetImageResource(Resource.Drawable.SfProgressPlay); this.playButton.SetBackgroundColor(Color.ParseColor("#00FFFFFF")); this.playButton.Click += this.PlayButton_Click; custContentLayout.AddView(this.playButton, gridLayoutParams); this.pauseButton = new ImageButton(this.context); this.pauseButton.SetImageResource(Resource.Drawable.SfProgressPause); this.pauseButton.SetBackgroundColor(Color.ParseColor("#00FFFFFF")); this.pauseButton.Click += this.PauseButton_Click; custContentLayout.AddView(this.pauseButton, gridLayoutParams); this.videoPlayerProgressBar.Content = custContentLayout; this.videoPlayerProgressBar.ValueChanged += this.ProgressBar_ValueChanged100; linearLayout.AddView(this.videoPlayerProgressBar); return(linearLayout); }
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); }
private void SelectGridSquare(int newX, int newY) { if (sectorSelected && selectedX == newX && selectedY == newY) { ClearSelection(); } else { var gridLayout = new GridLayout.LayoutParams(GridLayout.InvokeSpec(newY), GridLayout.InvokeSpec(newX)); gridLayout.Width = kGridSize; gridLayout.Height = kGridSize; selectionView.LayoutParameters = gridLayout; selectionView.Visibility = ViewStates.Visible; selectedX = newX; selectedY = newY; } UpdateBtns(); }
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 } } }
// 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; } } }
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 }
/// <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; } }
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); } }