public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SqlHelper = new Databasehelper(Context); Db = SqlHelper.WritableDatabase; }
public string[] GetTime(Context context, long id) { SqlHelper = new Databasehelper(context); Db = SqlHelper.WritableDatabase; cursor = Db.Query(Databasehelper.TEXTTABLE, new string[] { Databasehelper.COLUMN_TIME }, "_id = ?", new string[] { id.ToString() }, null, null, null); cursor.MoveToFirst(); // TimeSpan time = TimeSpan.FromMilliseconds(cursor.GetLong(0)); var date = DateTimeOffset.FromUnixTimeMilliseconds(cursor.GetLong(0)).UtcDateTime.ToLocalTime(); string[] timeAndDate = { date.ToString("d"), date.ToString("HH:mm") }; return(timeAndDate); }
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(); } }
public override void OnReceive(Context context, Intent intent) { Intent resultIntent; int id = Convert.ToInt32(intent.GetLongExtra("_id", 0)); databasehelper = new Databasehelper(context); Db = databasehelper.WritableDatabase; resultIntent = new Intent(context, typeof(WriteActivity)); resultIntent.PutExtra("_id", id.ToString()); ContentValues cv = new ContentValues(); cv.Put(Databasehelper.COLUMN_NOTIFY, 0); Db.Update(Databasehelper.TEXTTABLE, cv, "_id= ?", new string[] { id.ToString() }); Db.ExecSQL("VACUUM"); Android.App.PendingIntent resultPendingIntent = Android.App.PendingIntent.GetActivity(context, id, resultIntent, Android.App.PendingIntentFlags.UpdateCurrent); NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "ID") .SetSmallIcon(Android.Resource.Drawable.IcButtonSpeakNow) .SetContentTitle("Вам напоминание!") .SetContentText(intent.GetStringExtra("message")) .SetPriority((int)Android.App.NotificationPriority.Default) .SetContentIntent(resultPendingIntent) .SetAutoCancel(true) ; Android.App.NotificationManager manager = (Android.App.NotificationManager)context.GetSystemService(Context.NotificationService); Android.App.Notification notification = builder.Build(); Multitools.createChannelIfNeeded(manager); manager.Notify(id, notification); }
//изменить цвет фона public override View GetView(int position, View convertView, ViewGroup parent) { base.GetView(position, convertView, parent); string title; string[] nameNote; if (Build.VERSION.SdkInt >= BuildVersionCodes.N) { nameNote = Html.FromHtml(Cursor.GetString(Cursor.GetColumnIndex("ColumnText")), FromHtmlOptions.ModeCompact).ToString().Split("\n"); } else { nameNote = Html.FromHtml(Cursor.GetString(Cursor.GetColumnIndex("ColumnText"))).ToString().Split("\n"); } int IsNotify = Cursor.GetInt(Cursor.GetColumnIndex(Databasehelper.COLUMN_NOTIFY)); SqlHelper = new Databasehelper(context); Db = SqlHelper.ReadableDatabase; if (convertView == null) { convertView = View.Inflate(context, Resource.Layout.activity_rows, null); Cursor.MoveToPosition(position); viewHolder = new ViewHolder(convertView); convertView.Tag = viewHolder; } else { viewHolder = (ViewHolder)convertView.Tag; } try { cursor1 = Db.RawQuery("select " + Databasehelper.COLUMN_IMGPATH + " from " + Databasehelper.CONTENTTABLE + " where _id == " + GetItemId(position).ToString(), null); title = Multitools.GetNameNote(nameNote[0], cursor1); } catch { title = nameNote[0]; } viewHolder.namenotes.Text = title; //Set Title In List if (IsNotify == 1) { viewHolder.image.Visibility = ViewStates.Visible; } else { viewHolder.image.Visibility = ViewStates.Invisible; } viewHolder.editingTime.Text = Cursor.GetString(Cursor.GetColumnIndex(Databasehelper.COLUMN_EDITINGTIME)); Color c = new Color(Cursor.GetInt(Cursor.GetColumnIndex(Databasehelper.COLUMN_COLOR))); viewHolder.layout.SetBackgroundColor(c); if (IsShow) { viewHolder.checkBox.Visibility = ViewStates.Visible; } else { viewHolder.checkBox.Visibility = ViewStates.Invisible; } if (IsShow) { viewHolder.checkBox.Checked = IsChecked[position]; } if (!viewHolder.checkBox.HasOnClickListeners) { viewHolder.checkBox.Click += (sender, e) => { IsChecked[position] = !IsChecked[position]; } } ; return(convertView); }
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 }