public static ButtonStroked CreateDeviceButton(BluetoothConnectionActivity activity, BluetoothDevice device, TetrisColor color, int minHeight, string text) { ButtonStroked button = new ButtonStroked(activity); button.Settings = DeviceButtonUI.Clone(); button.Settings.StrokeColor = Utils.getAndroidColor(color, button.Settings.StrokeShade); button.Settings.FillColor = Utils.getAndroidColor(color, button.Settings.FillShade); button.SetMinimumHeight(minHeight); int padding = Utils.GetPixelsFromDP(activity, button.Settings.Padding); button.SetPadding(padding, padding, padding, padding); button.Text = text; if(device != null) { button.Tag = device.Address; button.Click += delegate { activity.DeviceListClick(button); }; } else { button.Enabled = false; } return button; }
private void addTouchEventToButton(ButtonStroked button, Timer repeatTimer, ElapsedEventHandler action, bool changeGameTimer) { repeatTimer.Elapsed += action; repeatTimer.AutoReset = true; button.Touch += delegate(object sender, View.TouchEventArgs e) { e.Handled = false; // so the button can change it's state switch (e.Event.Action) { case MotionEventActions.Up: // The user release the button so we stop the timer repeatTimer.Stop(); if(changeGameTimer) { _gameTimer.Start(); _player1View.Draw(); //update score } break; case MotionEventActions.Down: if( !repeatTimer.Enabled) { repeatTimer.Start(); if(changeGameTimer) { _gameTimer.Stop(); } } action.Invoke(null, null); break; case MotionEventActions.Move: int x = (int) e.Event.GetX(); int y = (int) e.Event.GetY(); // Be lenient about moving outside of buttons int slop = ViewConfiguration.Get(button.Context).ScaledTouchSlop; if ((x < 0 - slop) || (x >= button.Width + slop) || (y < 0 - slop) || (y >= button.Height + slop)) { repeatTimer.Stop(); if(changeGameTimer) { _gameTimer.Start(); _player1View.Draw(); //update score } } break; } }; }
private void EnableMenuCategory(LinearLayout layout, ButtonStroked button) { _devicesLayout.AddView(layout, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent)); button.Selected = true; button.Clickable = false; }
private void DisableMenuCategory(LinearLayout layout, ButtonStroked button) { _devicesLayout.RemoveView(layout); button.Selected = false; button.Clickable = true; }
// The on-click listener for all devices in the ListViews public void DeviceListClick(ButtonStroked sender) { if(_bluetoothAdapter.IsDiscovering) { // Cancel discovery because it's costly and we're about to connect _bluetoothAdapter.CancelDiscovery(); } // Get the device MAC address, which is the last 17 chars in the View //string info = (sender).Text; string address = (sender).Tag.ToString(); if(Network.Instance.Enabled) { displayWaitingDialog(Resource.String.waiting_for_opponent); // Get the BLuetoothDevice object BluetoothDevice device = BluetoothAdapter.DefaultAdapter.GetRemoteDevice(address); // Attempt to connect to the device Network.Instance.CommunicationWay.Connect(device); } }
//-------------------------------------------------------------- // EVENT CATCHING METHODS //-------------------------------------------------------------- protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate (savedInstanceState); RequestWindowFeature(WindowFeatures.NoTitle); Window.SetBackgroundDrawable(new ColorDrawable(Color.Transparent)); SetContentView(Resource.Layout.Dialog); _root = FindViewById<LinearLayout>(Resource.Id.alertContainer); _root.SetPadding(Builder.StrokeBorderWidth, Builder.StrokeBorderWidth, Builder.StrokeBorderWidth, Builder.StrokeBorderWidth); _root.SetMinimumWidth ((int)(WindowManager.DefaultDisplay.Width * MinWidthRatio)); _root.SetMinimumHeight((int)(WindowManager.DefaultDisplay.Height * MinHeightRatio)); if(_root.ViewTreeObserver.IsAlive) { _root.ViewTreeObserver.AddOnGlobalLayoutListener(this); } _title = FindViewById<TextView>(Resource.Id.alertTitle); _title.SetTextColor(Builder.StrokeColor); _title.Gravity = GravityFlags.CenterHorizontal; if(String.IsNullOrEmpty(Builder.Title)) { _title.Visibility = ViewStates.Gone; } else { _title.Text = Builder.Title; } _content = FindViewById<LinearLayout>(Resource.Id.alertContent); switch (Builder.ContentType) { case DialogBuilder.DialogContentType.TextView: if(!String.IsNullOrEmpty(Builder.Message)) { _message = new TextView(this); _message.Text = Builder.Message; _message.SetTextSize(Android.Util.ComplexUnitType.Dip, TextSize); _message.SetTextColor(Builder.TextColor); _message.Gravity = GravityFlags.CenterHorizontal; _content.AddView(_message, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); } break; case DialogBuilder.DialogContentType.EditText: _field = new EditText(this); _field.Hint = Builder.Message; _field.SetTextSize(Android.Util.ComplexUnitType.Dip, TextSize); // Limit the length _field.SetFilters( new IInputFilter[] { new InputFilterLengthFilter(Constants.MaxLengthName) } ); _content.AddView(_field, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); break; case DialogBuilder.DialogContentType.None: foreach(View view in Builder.Content) { _content.AddView(view, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); } break; default: break; } _buttonLayout = FindViewById<LinearLayout>(Resource.Id.buttonLayout); LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) _buttonLayout.LayoutParameters; lp.TopMargin = Builder.StrokeBorderWidth; _buttonLayout.LayoutParameters = lp; _positiveButton = FindViewById<ButtonStroked>(Resource.Id.positiveButton); _negativeButton = FindViewById<ButtonStroked>(Resource.Id.negativeButton); if(String.IsNullOrEmpty(Builder.PositiveText) && String.IsNullOrEmpty(Builder.NegativeText)) { _positiveButton.Visibility = ViewStates.Gone; _negativeButton.Visibility = ViewStates.Gone; } else if(String.IsNullOrEmpty(Builder.PositiveText)) { _positiveButton.Visibility = ViewStates.Gone; LinearLayout.LayoutParams lpNeg = (LinearLayout.LayoutParams) _negativeButton.LayoutParameters; lpNeg.Weight = 2; _negativeButton.LayoutParameters = lpNeg; } else if(String.IsNullOrEmpty(Builder.NegativeText)) { _negativeButton.Visibility = ViewStates.Gone; LinearLayout.LayoutParams lpPos = (LinearLayout.LayoutParams) _positiveButton.LayoutParameters; lpPos.Weight = 2; _positiveButton.LayoutParameters = lpPos; } else { LinearLayout.LayoutParams lpPos = (LinearLayout.LayoutParams) _positiveButton.LayoutParameters; lpPos.LeftMargin = Builder.StrokeBorderWidth/2; _positiveButton.LayoutParameters = lpPos; LinearLayout.LayoutParams lpNeg = (LinearLayout.LayoutParams) _negativeButton.LayoutParameters; lpNeg.RightMargin = Builder.StrokeBorderWidth/2; _negativeButton.LayoutParameters = lpNeg; } UtilsUI.SetDialogButton(this, _positiveButton, _field, TetrisColor.Green, Builder.PositiveText, Builder.PositiveAction, true); UtilsUI.SetDialogButton(this, _negativeButton, _field, TetrisColor.Yellow, Builder.NegativeText, Builder.NegativeAction, false); CloseAllDialog += Finish; }
private static void SetBaseIconButton(ButtonStroked button, TetrisColor color, int height, int textsize) { button.Text = button.Tag.ToString(); button.SetMaxHeight(height); button.SetMinimumHeight(height); button.Settings.StrokeColor = Utils.getAndroidColor(color, button.Settings.StrokeShade); button.Settings.FillColor = Utils.getAndroidColor(color, button.Settings.FillShade); }
public static void SetMenuButtonWithHeight(ButtonStroked button, TetrisColor color) { SetMenuButton(button, color); button.LayoutParameters.Width = ViewGroup.LayoutParams.MatchParent; button.LayoutParameters.Height = MenuButtonHeight; }
private static void SetBaseIconButton(ButtonStroked button, TetrisColor color, int height) { SetBaseIconButton(button, color, height, height); }
//-------------------------------------------------------------- // BUTTONS INITIALIZATION //-------------------------------------------------------------- public static void SetMenuButton(ButtonStroked button, TetrisColor color) { button.Settings = MenuButtonUI.Clone(); button.Settings.StrokeColor = Utils.getAndroidColor(color, button.Settings.StrokeShade); button.Settings.FillColor = Utils.getAndroidColor(color, button.Settings.FillShade); }
public static void SetIconButtonWithHeight(ButtonStroked button, TetrisColor color) { button.Settings = IconButtonUI.Clone(); button.LayoutParameters.Width = MenuButtonHeight*2/3; button.LayoutParameters.Height = MenuButtonHeight*2/3; SetBaseIconButton(button, color, button.LayoutParameters.Height, button.LayoutParameters.Height/2); }
public static void SetIconButton(ButtonStroked button, TetrisColor color, int difference) { button.Settings = IconButtonUI.Clone(); SetBaseIconButton(button, color, button.MeasuredWidth + difference, (button.MeasuredWidth + difference)/2); }
public static void SetDialogButton(DialogActivity activity, ButtonStroked button, EditText field, TetrisColor color, string text, EventHandler action, bool answer) { if(!String.IsNullOrEmpty(text)) { button.Settings = DialogButtonUI.Clone(); button.Settings.StrokeColor = Utils.getAndroidColor(color, button.Settings.StrokeShade); button.Settings.FillColor = Utils.getAndroidColor(color, button.Settings.FillShade); button.Text = text; button.Click += delegate { DialogBuilder.ReturnText = (DialogActivity.Builder.RequestCode == DialogBuilder.DialogRequestCode.Text ) ? field.Text : null; }; button.Click += action; button.Click += delegate { Intent intent = new Intent(); switch(DialogActivity.Builder.RequestCode) { case DialogBuilder.DialogRequestCode.PosOrNeg: intent.PutExtra(DialogActivity.Builder.RequestCode.ToString(), answer); activity.SetResult(Result.Ok, intent); activity.Finish(); break; case DialogBuilder.DialogRequestCode.Text: if(answer) { if(!String.IsNullOrWhiteSpace(field.Text)) { intent.PutExtra(DialogActivity.Builder.RequestCode.ToString(), field.Text); activity.SetResult(Result.Ok, intent); activity.Finish(); } } else { activity.SetResult(Result.Canceled); activity.Finish(); } break; default: break; } }; } }
public static void SetDeviceMenuButton(Activity activity, ref ButtonStroked button, int id, TetrisColor color) { button = activity.FindViewById<ButtonStroked>(id); button.Settings = DeviceMenuButtonUI.Clone(); button.Settings.StrokeColor = Utils.getAndroidColor(color, button.Settings.StrokeShade); button.Settings.FillColor = Utils.getAndroidColor(color, button.Settings.FillShade); }