// private NoteModel model; // private XNoteMethod noteMethods; protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_note); SetSupportActionBar(FindViewById <SupportToolbar>(Resource.Id.toolbar)); // Set up field components noteEditText = FindViewById <EditText>(Resource.Id.edit_text); EnableSupportToolbarHomeMenu(); note = new XNoteMethod().GetAllLocalNotes() .Where(g => g.Id == Intent.GetStringExtra(NOTE_ID)) .FirstOrDefault() ?? new Note() { Id = "", Content = "", CreateTimestamp = DateTime.Now, LastChangeTimestamp = DateTime.Now, OwnerId = "-1" }; noteEditText.Text = ""; noteEditText.Append(note?.Content ?? ""); }
void AddMsg(string str) { try { if (str.Equals("正在重新匹配,请稍后...") || str.Equals("匹配成功。")) { msgAll.Text = ""; } msgAll.Append("[TIME] " + DateTime.Now.ToString() + "\r\n"); msgAll.Append(str + "\r\n\r\n"); } catch (Exception ex) { msgAll.Text = "AddMsg Erro" + ex.Message; } }
protected override void OnBindDialogView(View view) { EditText.Text = ""; EditText.Append(Text); IViewParent oldParent = EditText.Parent; if (oldParent != view) { if (oldParent != null) { ((ViewGroup)oldParent).RemoveView(EditText); } OnAddEditTextToDialogView(view, EditText); } }
public void OnData(ScanDataCollection scanDataCollection) { Task.Run(() => { var scanDatas = scanDataCollection.GetScanData(); foreach (ScanDataCollection.ScanData data in scanDatas) { String barcodeData = data.Data; ScanDataCollection.LabelType labelType = data.LabelType; RunOnUiThread(() => { mDataView.Append(barcodeData + " " + labelType + "\n"); }); } }); }
public static void AppendLine(this EditText @this, string text) { @this.Append($"{text}\r\n"); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.HouseRegistration); var user_email = Intent.GetStringExtra("User_email"); var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar1); SetSupportActionBar(toolbar); SupportActionBar.SetTitle(Resource.String.toolbar_houseregistartion); toolbar.SetTitleTextAppearance(this, Resource.Style.ActionBarTitle); SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetHomeButtonEnabled(true); tihouse_id = FindViewById <EditText>(Resource.Id.textInputHouseId); var tihouse_name = FindViewById <EditText>(Resource.Id.textInputHouseName); var tihouse_password = FindViewById <EditText>(Resource.Id.textInputPassword); var btregistration = FindViewById <Button>(Resource.Id.buttonHouseRegister); var btpasswdicon = FindViewById <Button>(Resource.Id.buttonpasswdicon); var line1 = false; var line2 = false; tihouse_id.TextChanged += (e, s) => { if (tihouse_id.Text.Length == 4 && !line1) { tihouse_id.Append("-"); line1 = true; } if (tihouse_id.Text.Length == 9 && !line2) { tihouse_id.Append("-"); line2 = true; } if (tihouse_id.Text.Length < 4) { line1 = false; line2 = false; } else if (tihouse_id.Text.Length < 9) { line1 = true; line2 = false; } else { line1 = true; line2 = true; } }; var passwordtransform = tihouse_password.TransformationMethod; bool longclicked = false; btpasswdicon.Click += (v, e) => { if (longclicked) { tihouse_password.TransformationMethod = passwordtransform; tihouse_password.SetSelection(tihouse_password.Text.Length); btpasswdicon.SetBackgroundResource(Resource.Drawable.Lock_24); longclicked = false; } else { tihouse_password.TransformationMethod = null; tihouse_password.SetSelection(tihouse_password.Text.Length); btpasswdicon.SetBackgroundResource(Resource.Drawable.Unlock_24); longclicked = true; } }; tihouse_password.FocusChange += (e, s) => { if (!s.HasFocus) { tihouse_password.TransformationMethod = passwordtransform; btpasswdicon.SetBackgroundResource(Resource.Drawable.Lock_24); longclicked = false; } }; btregistration.Click += delegate { if (tihouse_password.Text.ToString().Trim().Equals("")) { tihouse_password.Error = "Password is required"; } else if (tihouse_id.Text.ToString().Trim().Equals("")) { tihouse_id.Error = "House id is required!"; } else if (tihouse_id.Text.Length != 16) { tihouse_id.Error = "Id format: xxxx-xxxx-yyxxxx "; } else if (IsMatchIdPattern(tihouse_id.Text)) { ProgressDialog progress = new ProgressDialog(this); progress.Indeterminate = true; progress.SetProgressStyle(ProgressDialogStyle.Spinner); progress.SetMessage("Registring..."); progress.SetCancelable(true); progress.Show(); new Thread(new ThreadStart(() => { var canlogin = RestClient.RegisterHouse(tihouse_id.Text, tihouse_name.Text); if (canlogin) { var adduserhouse = RestClient.AddUserHouse(user_email, tihouse_id.Text, tihouse_password.Text); if (adduserhouse) { RunOnUiThread(() => { progress.Dismiss(); Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this, Resource.Style.MyAlertDialogStyle); alert.SetTitle("Successful"); alert.SetCancelable(true); Dialog dialog = alert.Create(); dialog.Show(); }); } else { RunOnUiThread(() => { progress.Dismiss(); Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this, Resource.Style.MyAlertDialogStyle); alert.SetTitle("Error"); alert.SetMessage("Registerd but don`t added to yout house list"); alert.SetCancelable(true); Dialog dialog = alert.Create(); dialog.Show(); }); } } else { RunOnUiThread(() => { progress.Dismiss(); Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this, Resource.Style.MyAlertDialogStyle); alert.SetTitle("Can`t Registerd"); alert.SetMessage("Try again"); alert.SetCancelable(true); Dialog dialog = alert.Create(); dialog.Show(); }); } })).Start(); } else { tihouse_id.Error = "Id need to be hex number"; } }; }
// MQTT end protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); btn_PopupMenu = FindViewById <Button>(Resource.Id.id_btnPopupMenu); btn_PopupMenu.Click += ShowPopupMenu; ActionBar.NavigationMode = ActionBarNavigationMode.Tabs; ViewPager pager = FindViewById <ViewPager>(Resource.Id.id_pager); GenericFragmentPagerAdaptor adaptor = new GenericFragmentPagerAdaptor(SupportFragmentManager); mp_player = MediaPlayer.Create(this, Resource.Raw.beer_pour); SingletonOxy.Instance.i_Plotchoice = 0; // BASIC adaptor.AddFragmentView((i, v, b) => { var view = i.Inflate(Resource.Layout.Basic, v, false); TextView textSample = view.FindViewById <TextView>(Resource.Id.id_txtBasic); textSample.Text = AdditionalResource.IntroText(); ibtn_beerImage = view.FindViewById <ImageButton>(Resource.Id.id_imgBeer); ibtn_beerImage.Click += ShowCheers; return(view); }); // SHOW DATA adaptor.AddFragmentView((i, v, b) => { var view = i.Inflate(Resource.Layout.ShowData, v, false); btn_RetrieveFromTS = view.FindViewById <Button>(Resource.Id.id_btnRetrieveFromTS); btn_RetrieveFromTS.Click += async(s, arg) => { ListView viewList = view.FindViewById <ListView>(Resource.Id.id_vwListShowData); try { SingletonTSList.Instance.l_dataStoringList.Clear(); ThingSpeakData feeds = await DataStorage.ReadThingspeak(); SingletonTSList.Instance.l_dataStoringList = DataStorage.ThingspeakConverter(feeds); //DataStorage.ArtificialList(); Toast.MakeText(this, string.Format("DATA OBTAINED!"), ToastLength.Long).Show(); } catch /*(Exception ex)*/ { Toast.MakeText(this, string.Format("CANNOT OBTAIN DATA FROM THINGSPEAK!"), ToastLength.Long).Show(); //Toast.MakeText(this, string.Format(ex.ToString()), ToastLength.Long).Show(); } var adapter = new VwAdapter(this, SingletonTSList.Instance.l_dataStoringList, 5); viewList.Adapter = adapter; }; btn_TempShowData1 = view.FindViewById <Button>(Resource.Id.id_btnShowData1); btn_TempShowData1.Click += (s, arg) => { ListView viewList = view.FindViewById <ListView>(Resource.Id.id_vwListShowData); var adapter = new VwAdapter(this, SingletonTSList.Instance.l_dataStoringList, 1); viewList.Adapter = adapter; }; btn_TempShowData2 = view.FindViewById <Button>(Resource.Id.id_btnShowData2); btn_TempShowData2.Click += (s, arg) => { ListView viewList = view.FindViewById <ListView>(Resource.Id.id_vwListShowData); var adapter = new VwAdapter(this, SingletonTSList.Instance.l_dataStoringList, 2); viewList.Adapter = adapter; }; btn_TempShowData3 = view.FindViewById <Button>(Resource.Id.id_btnShowData3); btn_TempShowData3.Click += (s, arg) => { ListView viewList = view.FindViewById <ListView>(Resource.Id.id_vwListShowData); var adapter = new VwAdapter(this, SingletonTSList.Instance.l_dataStoringList, 3); viewList.Adapter = adapter; }; btn_TempShowData4 = view.FindViewById <Button>(Resource.Id.id_btnShowData4); btn_TempShowData4.Click += (s, arg) => { ListView viewList = view.FindViewById <ListView>(Resource.Id.id_vwListShowData); var adapter = new VwAdapter(this, SingletonTSList.Instance.l_dataStoringList, 4); viewList.Adapter = adapter; }; return(view); }); // SHOW CHARTS adaptor.AddFragmentView((i, v, b) => { var view = i.Inflate(Resource.Layout.ShowCharts, v, false); btn_RetrieveFromTS2 = view.FindViewById <Button>(Resource.Id.id_btnRetrieveFromTS2); btn_RetrieveFromTS2.Click += async(s, arg) => { try { SingletonTSList.Instance.l_dataStoringList.Clear(); ThingSpeakData feeds = await DataStorage.ReadThingspeak(); SingletonTSList.Instance.l_dataStoringList = DataStorage.ThingspeakConverter(feeds); Toast.MakeText(this, string.Format("DATA OBTAINED!"), ToastLength.Long).Show(); } catch { Toast.MakeText(this, string.Format("CANNOT OBTAIN DATA FROM THINGSPEAK!"), ToastLength.Long).Show(); } }; btn_PopupShowCharts = view.FindViewById <Button>(Resource.Id.id_btnChangeGraph); btn_PopupShowCharts.Click += ShowPopupCharts; btn_ShowCharts = view.FindViewById <Button>(Resource.Id.id_btnShowGraph); btn_ShowCharts.Click += (s, arg) => { SingletonOxy.Instance.viewPlot = view.FindViewById <PlotView>(Resource.Id.id_plotView); SingletonOxy.Instance.viewPlot.Model = PlotManager.CreatePlotModel(SingletonTSList.Instance.l_dataStoringList); }; return(view); }); // MODIFY PROCESSING adaptor.AddFragmentView((i, v, b) => { var view = i.Inflate(Resource.Layout.ModifyProcessing, v, false); skb_HigherTempBD = view.FindViewById <SeekBar>(Resource.Id.id_skbHigherBoundary); tvw_HigherTempBD = view.FindViewById <TextView>(Resource.Id.id_txtSeekBarHighB); tvw_HigherTempBD.Text = "0"; skb_LowerTempBD = view.FindViewById <SeekBar>(Resource.Id.id_skbLowerBoundary); tvw_LowerTempBD = view.FindViewById <TextView>(Resource.Id.id_txtSeekBarLowB); tvw_LowerTempBD.Text = "0"; skb_HigherTempBD.SetOnSeekBarChangeListener(this); skb_LowerTempBD.SetOnSeekBarChangeListener(this); btn_GetSBSettings = view.FindViewById <Button>(Resource.Id.id_btnGetSBSettings); btn_GetSBSettings.Click += (s, arg) => { double d_vwTxt1 = 0, d_vwTxt2 = 0; if (!Double.TryParse(tvw_HigherTempBD.Text, out d_vwTxt1)) { Toast.MakeText(this, string.Format("Problem with parsing text value."), ToastLength.Long).Show(); } if (!Double.TryParse(tvw_LowerTempBD.Text, out d_vwTxt2)) { Toast.MakeText(this, string.Format("Problem with parsing text value."), ToastLength.Long).Show(); } SingletonTSList.Instance.st_WatchdogStorage.i_FirstskBar = d_vwTxt1; SingletonTSList.Instance.st_WatchdogStorage.i_SecondskBar = d_vwTxt2; Toast.MakeText(this, "Settings obtained!", ToastLength.Long).Show(); }; btn_LaunchWatchdog = view.FindViewById <Button>(Resource.Id.id_btnLaunchWG); btn_StopWatchdog = view.FindViewById <Button>(Resource.Id.id_btnStopWG); btn_LaunchWatchdog.Click += StartStartedService; btn_StopWatchdog.Click += StopStartedService; return(view); }); // MODIFY VALVE adaptor.AddFragmentView((i, v, b) => { var view = i.Inflate(Resource.Layout.ModifyValve, v, false); edt_EdIP1 = view.FindViewById <EditText>(Resource.Id.id_txtEdIP1); edt_EdPort1 = view.FindViewById <EditText>(Resource.Id.id_txtEdPort1); edt_EdOutput1 = view.FindViewById <EditText>(Resource.Id.id_txtEdOutput1); edt_EdIP2 = view.FindViewById <EditText>(Resource.Id.id_txtEdIP2); edt_EdPort2 = view.FindViewById <EditText>(Resource.Id.id_txtEdPort2); edt_EdOutput2 = view.FindViewById <EditText>(Resource.Id.id_txtEdOutput2); worker.DoWork += (s, arg) => { while (client.Connected) { try { receive = STR.ReadLine(); //this.txtEdOutput1.Text = receive;//Dispatcher.Invoke(new Action(delegate () { txtEdOutput1.AppendText("You : " + receive + "\n"); })); receive = ""; } catch (Exception ex) { Toast.MakeText(this, ex.Message.ToString(), ToastLength.Long).Show(); } } }; worker2.DoWork += (s, arg) => { if (client.Connected) { STW.WriteLine(text_to_send); //this.txtEdOutput1.Text = text_to_send; //Dispatcher.Invoke(new Action(delegate () { TextBox2.AppendText("Me : " + text_to_send + "\n"); })); } else { Toast.MakeText(this, "Send failed!", ToastLength.Long).Show(); } worker2.CancelAsync(); }; btn_StartServer = view.FindViewById <Button>(Resource.Id.id_btnStartServer); btn_StartServer.Click += (s, arg) => { Toast.MakeText(this, "Non used in this case, just possibility!", ToastLength.Long).Show(); /*TcpListener listener = new TcpListener(IPAddress.Any, int.Parse(edt_EdPort1.Text)); * listener.Start(); * client = listener.AcceptTcpClient(); * STR = new StreamReader(client.GetStream()); * STW = new StreamWriter(client.GetStream()); * STW.AutoFlush = true; * * worker.RunWorkerAsync(); // Start receiving data from background * worker2.WorkerSupportsCancellation = true; // Ability to cancel thread*/ }; btn_Connect = view.FindViewById <Button>(Resource.Id.id_btnConnect); btn_Connect.Click += (s, arg) => { try { client = new TcpClient(); IPEndPoint IP_End = new IPEndPoint(IPAddress.Parse(edt_EdIP2.Text), int.Parse(edt_EdPort2.Text, CultureInfo.InvariantCulture)); client.Connect(IP_End); if (client.Connected) { edt_EdOutput1.Append("Connected to server"); STW = new StreamWriter(client.GetStream()); STR = new StreamReader(client.GetStream()); STW.AutoFlush = true; worker.RunWorkerAsync(); // Start receiving data from background worker2.WorkerSupportsCancellation = true; // Ability to cancel thread } } catch (Exception ex) { Toast.MakeText(this, "Cannot connect to a server!", ToastLength.Long).Show(); Toast.MakeText(this, ex.Message.ToString(), ToastLength.Long).Show(); } }; btn_Send = view.FindViewById <Button>(Resource.Id.id_btnSend); btn_Send.Click += (s, arg) => { try { if (edt_EdOutput2.Text != "") { text_to_send = edt_EdOutput2.Text; worker2.RunWorkerAsync(); } edt_EdOutput2.Text = ""; } catch { Toast.MakeText(this, "Cannot send a message!", ToastLength.Long).Show(); } }; IPAddress[] localIP = Dns.GetHostAddresses(Dns.GetHostName()); foreach (IPAddress address in localIP) { if (address.AddressFamily == AddressFamily.InterNetwork) { edt_EdIP1.Text = address.ToString(); edt_EdIP2.Text = "10.0.0.71"; edt_EdPort1.Text = "123"; edt_EdPort2.Text = "123"; } } return(view); }); pager.Adapter = adaptor; #pragma warning disable CS0618 // Type or member is obsolete pager.SetOnPageChangeListener(listener: new ViewPageListenerForActionBar(ActionBar)); #pragma warning restore CS0618 // Type or member is obsolete foreach (var element in s_arrangementTab) { ActionBar.AddTab(pager.GetViewPageTab(ActionBar, element)); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); int total = 0; // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); EditText editInput = FindViewById <EditText>(Resource.Id.edtTextInput); TextView textResult = FindViewById <TextView>(Resource.Id.txtResult); //handle buttons Button btnClear = FindViewById <Button>(Resource.Id.btnClear); Button btnBackspace = FindViewById <Button>(Resource.Id.btnBackspace); Button btnDivide = FindViewById <Button>(Resource.Id.btnDivide); Button btnSeven = FindViewById <Button>(Resource.Id.btnSeven); Button btnEight = FindViewById <Button>(Resource.Id.btnEight); Button btnNine = FindViewById <Button>(Resource.Id.btnNine); Button btnMultiply = FindViewById <Button>(Resource.Id.btnMultiply); Button btnFour = FindViewById <Button>(Resource.Id.btnFour); Button btnFive = FindViewById <Button>(Resource.Id.btnFive); Button btnSix = FindViewById <Button>(Resource.Id.btnSix); Button btnMinus = FindViewById <Button>(Resource.Id.btnMinus); Button btnOne = FindViewById <Button>(Resource.Id.btnOne); Button btnTwo = FindViewById <Button>(Resource.Id.btnTwo); Button btnThree = FindViewById <Button>(Resource.Id.btnThree); Button btnPlus = FindViewById <Button>(Resource.Id.btnPlus); Button btnZero = FindViewById <Button>(Resource.Id.btnZero); Button btnSpace = FindViewById <Button>(Resource.Id.btnSpace); Button btnEquals = FindViewById <Button>(Resource.Id.btnEquals); btnClear.Click += delegate { editInput.Text = ""; textResult.Text = "0"; total = 0; }; btnBackspace.Click += delegate { //using append puts the cursor at the end of the edittext box string temp = editInput.Text; if (temp != "") { temp = temp.Remove(temp.Length - 1); } editInput.Text = ""; editInput.Append(temp); }; btnDivide.Click += delegate { if (TextUtils.IsEmpty(editInput.Text)) { editInput.Append("/ "); } else { editInput.Append(" / "); } }; btnSeven.Click += delegate { editInput.Append("7"); }; btnEight.Click += delegate { editInput.Append("8"); }; btnNine.Click += delegate { editInput.Append("9"); }; btnMultiply.Click += delegate { if (TextUtils.IsEmpty(editInput.Text)) { editInput.Append("* "); } else { editInput.Append(" * "); } }; btnFour.Click += delegate { editInput.Append("4"); }; btnFive.Click += delegate { editInput.Append("5"); }; btnSix.Click += delegate { editInput.Append("6"); }; btnMinus.Click += delegate { if (TextUtils.IsEmpty(editInput.Text)) { editInput.Append("- "); } else { editInput.Append(" - "); } }; btnOne.Click += delegate { editInput.Append("1"); }; btnTwo.Click += delegate { editInput.Append("2"); }; btnThree.Click += delegate { editInput.Append("3"); }; btnPlus.Click += delegate { if (TextUtils.IsEmpty(editInput.Text)) { editInput.Append("+ "); } else { editInput.Append(" + "); } }; btnZero.Click += delegate { editInput.Append("0"); }; btnSpace.Click += delegate { editInput.Append(" "); }; btnEquals.Click += delegate { if (!TextUtils.IsEmpty(editInput.Text)) { calculate(); } }; textResult.Text = "0"; void calculate() { Queue <char> operator_queue = new Queue <char>(); Queue <int> number_queue = new Queue <int>(); char operator_char = '$'; string current_number = ""; for (int i = 0; i < editInput.Text.Length; i++) { switch (editInput.Text[i]) { case '+': //need to check for anything in current_number in case they didnt add a space between last number and + if (current_number != "") { number_queue.Enqueue(Int32.Parse(current_number)); current_number = ""; } operator_queue.Enqueue('+'); break; case '-': if (current_number != "") { number_queue.Enqueue(Int32.Parse(current_number)); current_number = ""; } operator_queue.Enqueue('-'); break; case '*': if (current_number != "") { number_queue.Enqueue(Int32.Parse(current_number)); current_number = ""; } operator_queue.Enqueue('*'); break; case '/': if (current_number != "") { number_queue.Enqueue(Int32.Parse(current_number)); current_number = ""; } operator_queue.Enqueue('/'); break; case ' ': if (current_number != "") { number_queue.Enqueue(Int32.Parse(current_number)); current_number = ""; } break; default: current_number = current_number + editInput.Text[i]; break; } } //have opeartors and numbers, now calculate if (total == 0) { total = number_queue.Dequeue(); } while (number_queue.Count != 0) { if (operator_queue.Count != 0) { operator_char = operator_queue.Dequeue(); } switch (operator_char) { case '+': total = total + number_queue.Dequeue(); break; case '-': total = total - number_queue.Dequeue(); break; case '*': total = total * number_queue.Dequeue(); break; case '/': total = total / number_queue.Dequeue(); break; } } textResult.Text = total.ToString(); editInput.Text = ""; } }