Ejemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.NoteLayout);
            Init();
            SqlHelper = new Databasehelper(this);
            Db        = SqlHelper.WritableDatabase;

            EditText.SetPadding(40, 10, 40, 10);



            textWatcher = new TextWatcher(EditText);

            EditText.AddTextChangedListener(textWatcher);
            notifyFragment = new NotifyFragment(EditText.EditableText, Args);

            Args = Intent.Extras;
            if (Args != null)
            {
                NoteNumber = Convert.ToInt32(Args.GetString(Databasehelper.COLUMN_ID));
                cursor     = Db.RawQuery("Select * from " + Databasehelper.TEXTTABLE + " Where _id =="
                                         + Args.GetString(Databasehelper.COLUMN_ID), null);
                cursor.MoveToFirst();
                ISpanned text;
                if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
                {
                    text = Html.FromHtml(cursor.GetString(cursor.GetColumnIndex("ColumnText")), FromHtmlOptions.ModeCompact);
                }
                else
                {
                    text = Html.FromHtml(cursor.GetString(cursor.GetColumnIndex("ColumnText")));
                }
                EditText.SetText(text, EditText.BufferType.Editable);
                cursor = Db.RawQuery("Select *" + " from " + Databasehelper.CONTENTTABLE
                                     + " Where _id==" + Args.GetString(Databasehelper.COLUMN_ID), null);
                setImages(cursor);
                notifyFragment.Id = NoteNumber;
            }
            else
            {
                EditText.RequestFocus();
            }
        }
Ejemplo n.º 2
0
        private const int REQUEST_RETURN_NOTE = 1; //Возвращаемое значение текста
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            addToList = FindViewById <ImageButton>(Resource.Id.notebut);
            CancelBut = (ImageButton)FindViewById(Resource.Id.CancelBut);
            DeleteBut = (ImageButton)FindViewById(Resource.Id.DeleteBut);
            ColorBut  = (ImageButton)FindViewById(Resource.Id.ColorBut);


            list = (ListView)FindViewById(Resource.Id.values);
            list.RequestFocus();

            //views
            sqlHelper = new Databasehelper(this);
            db        = sqlHelper.ReadableDatabase;


            cursor = db.RawQuery("select ColumnText,_id," + Databasehelper.COLUMN_NOTIFY + "," + Databasehelper.COLUMN_EDITINGTIME + "," + Databasehelper.COLUMN_COLOR + " from " + Databasehelper.TEXTTABLE, null);

            string[] headers = new string[] { Databasehelper.COLUMN_TEXT }; //used columns in note


            cursorAdapter = new Listadapter(this, Resource.Layout.activity_rows,
                                            cursor, headers, new int[] { Resource.Id.namenote }, 0);

            list.Adapter     = cursorAdapter;
            ColorBut.Click  += ColorClick;
            CancelBut.Click += (sender, e) =>
            {
                if (SystemClock.ElapsedRealtime() - LastClickTime < 1000)
                {
                    return;
                }
                LastClickTime = SystemClock.ElapsedRealtime();
                cursorAdapter.IsShowCheckbox(false);
                CancelBut.Visibility = ViewStates.Invisible;
                DeleteBut.Visibility = ViewStates.Invisible;
                addToList.Visibility = ViewStates.Visible;
                ColorBut.Visibility  = ViewStates.Gone;
            };
            DeleteBut.Click += (sender, e) =>
            {
                cursor = db.Query(Databasehelper.TEXTTABLE, new string[] { Databasehelper.COLUMN_ID }, Databasehelper.COLUMN_NOTIFY + "= ?", new string[] { "1" }, null, null, null);
                List <int> checkedpos = cursorAdapter.GetChecked();
                for (int i = 0; i < checkedpos.Count; i++)
                {
                    NotifyFragment a = new NotifyFragment(null, null);
                    cursor = db.Query(Databasehelper.TEXTTABLE, new string[] { Databasehelper.COLUMN_NOTIFY }, "_id = ?", new string[] { cursorAdapter.GetItemId(checkedpos[i]).ToString() }, null, null, null);
                    cursor.MoveToFirst();
                    db.ExecSQL("Delete from " + Databasehelper.TEXTTABLE + " Where _id == " + cursorAdapter.GetItemId(checkedpos[i]).ToString());
                    db.ExecSQL("Delete from " + Databasehelper.CONTENTTABLE + " Where _id == " + cursorAdapter.GetItemId(checkedpos[i]).ToString());
                    if (cursor.GetInt(0) == 1)
                    {
                        a.CancelAlarm(this, cursorAdapter.GetItemId(checkedpos[i]));
                    }
                }
                DeleteBut.Visibility = ViewStates.Gone;
                CancelBut.Visibility = ViewStates.Gone;
                ColorBut.Visibility  = ViewStates.Gone;
                addToList.Visibility = ViewStates.Visible;
                cursor = db.RawQuery("select ColumnText,_id," + Databasehelper.COLUMN_NOTIFY + "," + Databasehelper.COLUMN_EDITINGTIME + "," + Databasehelper.COLUMN_COLOR + " from " + Databasehelper.TEXTTABLE, null);
                cursorAdapter.ChangeCursor(cursor);
                cursorAdapter.IsShowCheckbox(false);
            };
            addToList.Click += addToListClick;
            list.ItemClick  += (sender, e) =>
            {
                if (cursorAdapter.IsShow)
                {
                    cursorAdapter.ChangeChecked(e.Position);
                }
                else
                {
                    if (SystemClock.ElapsedRealtime() - LastClickTime < 800)
                    {
                        return;
                    }
                    LastClickTime = SystemClock.ElapsedRealtime();
                    Intent intent = new Intent(this, typeof(WriteActivity));
                    intent.PutExtra("_id", cursorAdapter.GetItemId(e.Position).ToString());
                    StartActivityForResult(intent, REQUEST_RETURN_NOTE);
                }
            };
            list.ItemLongClick += (sender, e) =>
            {
                addToList.Visibility = ViewStates.Invisible;
                ColorBut.Visibility  = ViewStates.Visible;
                CancelBut.Visibility = ViewStates.Visible;
                DeleteBut.Visibility = ViewStates.Visible;
                cursorAdapter.IsShowCheckbox(true);
                cursorAdapter.ChangeChecked(e.Position);
            };
            //listeners
        }