Example #1
0
 public static RecentLab GetLab()
 {
     if (link == null)
     {
         link = new RecentLab();
     }
     return(link);
 }
Example #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_recent);

            recycle = FindViewById <RecyclerView>(Resource.Id.rec_list);
            recycle.SetLayoutManager(new LinearLayoutManager(this));

            DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recycle.Context, DividerItemDecoration.Vertical);

            recycle.AddItemDecoration(dividerItemDecoration);

            RecentLab   lab  = RecentLab.GetLab();
            List <Note> list = lab.list;

            adapter = new RecentAdapter(list);
            recycle.SetAdapter(adapter);
            recycle.ScrollToPosition(list.Count() - 1);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            text = FindViewById <EditText>(Resource.Id.text_window);
            text.ShowSoftInputOnFocus = false;

            if (Intent.HasExtra("exp"))
            {
                text.Text = Intent.GetStringExtra("exp");
                text.SetSelection(text.Text.Length);
                hooks = Intent.GetIntExtra("hooks", 0);
            }

            recent        = FindViewById <Button>(Resource.Id.button_recent);
            recent.Click += delegate(object sender, EventArgs e)
            {
                Intent intent = new Intent(this, typeof(RecentActivity));
                StartActivity(intent);
            };

            ac        = FindViewById <Button>(Resource.Id.button_ac);
            ac.Click += delegate(object sender, EventArgs e)
            {
                text.Text = "";
                hooks     = 0;
            };

            exp        = FindViewById <Button>(Resource.Id.button_exp);
            exp.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    ChangeOperation();
                    int index = text.SelectionStart;
                    if (index != 0)
                    {
                        text.Text = text.Text.Insert(index, "^");
                        text.SetSelection(index + 1);
                    }
                }
            };

            demul        = FindViewById <Button>(Resource.Id.button_demul);
            demul.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    ChangeOperation();
                    int index = text.SelectionStart;
                    if (index != 0)
                    {
                        text.Text = text.Text.Insert(index, "/");
                        text.SetSelection(index + 1);
                    }
                }
            };

            x        = FindViewById <Button>(Resource.Id.button_x);
            x.Click += delegate(object sender, EventArgs e)
            {
                SymbolsControl();
                int index = text.SelectionStart;
                if (index > 0)
                {
                    if (text.Text[index - 1] == '(')
                    {
                        hooks--;
                    }
                    if (text.Text[index - 1] == ')')
                    {
                        hooks++;
                    }
                    text.Text = text.Text.Remove(index - 1, 1);
                    text.SetSelection(index - 1);
                }
            };

            bt7        = FindViewById <Button>(Resource.Id.button_7);
            bt7.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    text.Text = text.Text.Insert(index, "7");
                    text.SetSelection(index + 1);
                }
            };

            bt8        = FindViewById <Button>(Resource.Id.button_8);
            bt8.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    text.Text = text.Text.Insert(index, "8");
                    text.SetSelection(index + 1);
                }
            };

            bt9        = FindViewById <Button>(Resource.Id.button_9);
            bt9.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    text.Text = text.Text.Insert(index, "9");
                    text.SetSelection(index + 1);
                }
            };

            mul        = FindViewById <Button>(Resource.Id.button_mul);
            mul.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    ChangeOperation();
                    int index = text.SelectionStart;
                    if (index != 0)
                    {
                        text.Text = text.Text.Insert(index, "*");
                        text.SetSelection(index + 1);
                    }
                }
            };
            mul.LongClick += delegate(object sender, View.LongClickEventArgs e)
            {
                if (LengthControl())
                {
                    ChangeOperation();
                    int index = text.SelectionStart;
                    text.Text = text.Text.Insert(index, "!");
                    text.SetSelection(index + 1);
                }
            };


            bt4        = FindViewById <Button>(Resource.Id.button_4);
            bt4.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    text.Text = text.Text.Insert(index, "4");
                    text.SetSelection(index + 1);
                }
            };

            bt5        = FindViewById <Button>(Resource.Id.button_5);
            bt5.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    text.Text = text.Text.Insert(index, "5");
                    text.SetSelection(index + 1);
                }
            };

            bt6        = FindViewById <Button>(Resource.Id.button_6);
            bt6.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    text.Text = text.Text.Insert(index, "6");
                    text.SetSelection(index + 1);
                }
            };

            sub        = FindViewById <Button>(Resource.Id.button_sub);
            sub.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    if (!(index > 1 && text.Text[index - 1] == '-' && (text.Text[index - 2] == '+' || text.Text[index - 2] == '-' ||
                                                                       text.Text[index - 2] == '*' || text.Text[index - 2] == '/' || text.Text[index - 2] == '^')))
                    {
                        text.Text = text.Text.Insert(index, "-");
                        text.SetSelection(index + 1);
                    }
                }
            };

            bt1        = FindViewById <Button>(Resource.Id.button_1);
            bt1.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    text.Text = text.Text.Insert(index, "1");
                    text.SetSelection(index + 1);
                }
            };

            bt2        = FindViewById <Button>(Resource.Id.button_2);
            bt2.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    text.Text = text.Text.Insert(index, "2");
                    text.SetSelection(index + 1);
                }
            };

            bt3        = FindViewById <Button>(Resource.Id.button_3);
            bt3.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    text.Text = text.Text.Insert(index, "3");
                    text.SetSelection(index + 1);
                }
            };

            add        = FindViewById <Button>(Resource.Id.button_add);
            add.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    ChangeOperation();
                    int index = text.SelectionStart;
                    text.Text = text.Text.Insert(index, "+");
                    text.SetSelection(index + 1);
                }
            };

            bt0        = FindViewById <Button>(Resource.Id.button_0);
            bt0.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    text.Text = text.Text.Insert(index, "0");
                    text.SetSelection(index + 1);
                }
            };

            com        = FindViewById <Button>(Resource.Id.button_com);
            com.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    if (index == 0 || text.Text[index - 1] == '+' || text.Text[index - 1] == '-' || text.Text[index - 1] == '*' || text.Text[index - 1] == '/' ||
                        text.Text[index - 1] == '^' || text.Text[index - 1] == '(')
                    {
                        text.Text = text.Text.Insert(index, "0");
                        index++;
                    }
                    if (text.Text[index - 1] != ',')
                    {
                        text.Text = text.Text.Insert(index, ",");
                        text.SetSelection(index + 1);
                    }
                }
            };

            hook        = FindViewById <Button>(Resource.Id.button_hook);
            hook.Click += delegate(object sender, EventArgs e)
            {
                if (LengthControl())
                {
                    int index = text.SelectionStart;
                    if (index == 0 || text.Text[index - 1] == '+' || text.Text[index - 1] == '-' || text.Text[index - 1] == '*' || text.Text[index - 1] == '/' ||
                        text.Text[index - 1] == '^' || text.Text[index - 1] == '(')
                    {
                        text.Text = text.Text.Insert(index, "(");
                        text.SetSelection(index + 1);
                        hooks++;
                    }
                    else if (hooks == 0)
                    {
                        text.Text = text.Text.Insert(index, "*(");
                        text.SetSelection(index + 2);
                        hooks++;
                    }
                    else
                    {
                        text.Text = text.Text.Insert(index, ")");
                        text.SetSelection(index + 1);
                        hooks--;
                    }
                }
            };

            opp        = FindViewById <Button>(Resource.Id.button_opp);
            opp.Click += delegate(object sender, EventArgs e)
            {
                SymbolsControl();
                string result = "";
                if (text.Text.Length != 0)
                {
                    result = Calculate(text.Text).ToString();
                    if (result == "" || result == GetString(Resource.String.not_a_number))
                    {
                        Toast.MakeText(this, Resource.String.expression_error, ToastLength.Short).Show();
                    }
                    else
                    {
                        if (result == GetString(Resource.String.infinity))
                        {
                            result = "∞";
                        }
                        else if (result == GetString(Resource.String.not_a_number))
                        {
                            result = "-∞";
                        }

                        if (!String.Equals(text.Text, result))
                        {
                            RecentLab lab = RecentLab.GetLab();
                            if (lab.list.Count() >= 30)
                            {
                                lab.list.RemoveAt(0);
                            }
                            lab.list.Add(new Note {
                                left = text.Text, right = result, hooks = this.hooks
                            });
                        }

                        text.Text = result;
                        text.SetSelection(result.Length);
                        hooks = 0;
                    }
                }
            };
        }