From 4761650bc334551ff613be09cb2b9e8e4c00b5c5 Mon Sep 17 00:00:00 2001 From: pnv9folh3 Date: Sun, 14 Apr 2024 22:58:33 +0800 Subject: [PATCH] =?UTF-8?q?ui=E5=8C=85=E6=B3=A8=E9=87=8A=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/AlarmInitReceiver.java | 72 +++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/ui/AlarmInitReceiver.java diff --git a/src/ui/AlarmInitReceiver.java b/src/ui/AlarmInitReceiver.java new file mode 100644 index 0000000..533f0f3 --- /dev/null +++ b/src/ui/AlarmInitReceiver.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//220340038 毛彦翔 2024/4/14 22:57 + +package net.micode.notes.ui; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.ContentUris; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; + +import net.micode.notes.data.Notes; +import net.micode.notes.data.Notes.NoteColumns; + + +public class AlarmInitReceiver extends BroadcastReceiver { //继承了BroadcastReceiver类 这个类在哪呢? + + private static final String [] PROJECTION = new String [] { //名为PROJECTION的私有 final类型的静态字符串数组 好安全 + NoteColumns.ID, //某个ID 是AlarmActivity中的同款检索ID吗 + NoteColumns.ALERTED_DATE //似乎是闹钟提醒的日期。 + }; + + private static final int COLUMN_ID = 0; + private static final int COLUMN_ALERTED_DATE = 1; //变量初始化 + + @Override + public void onReceive(Context context, Intent intent) { //名为onReceive的公有类 + long currentDate = System.currentTimeMillis(); //currentDate 初始化为 当前系统时间 + Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI/*指定了查询的数据源*/, + PROJECTION, //33行中定义的数组 返回ID和ALERTED_DATE + NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE, + //筛选条件 找到ALERTED_DATE大于当前时间并且TYPE等于TYPE_NOTE的便签。type是什么啊。 + new String[] { String.valueOf(currentDate) }, //强制转换?把long类型的currentDate转换成String + null); //干嘛用的null + + if (c != null) { //c不为空 + if (c.moveToFirst()) { + /*将光标移动到结果集中的第一行。如果结果集为空,则此方法将返回 false + *如果结果集非空,则将光标移到第一行,并返回 true + *来自百度 + */ + do { + long alertDate = c.getLong(COLUMN_ALERTED_DATE); + Intent sender = new Intent(context, AlarmReceiver.class); + sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID))); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0); + AlarmManager alermManager = (AlarmManager) context + .getSystemService(Context.ALARM_SERVICE); + alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent); + } while (c.moveToNext()); //遍历查询到的便签挨个设闹钟 + } + c.close(); //释放 + } + } +} //好困 睡觉