Small Michaeluan sticky note notes-Source Research (2)-Notes for timed reminders

Source: Internet
Author: User


This article describes the timing reminders feature in Xiaomi notes.
Note, can be understood as one thing, a task, there is a function of timing reminders, or pretty good ~

Xiaomi Sticky note timing function, when editing the note, there is a menu item, after the selection, it pops up a "date dialog box",
When the date is selected, the Timer function is set.


The following explains the technical realization of the overall idea (many places I do not understand, do not understand the search)

Androidmanifest.xml Configuration

<receiver android:name= ". UI. Alarminitreceiver ">            <intent-filter>                <action android:name=" android.intent.action.BOOT_ Completed "/>            </intent-filter>        </receiver>        <receiver            android:name=" Net.micode.notes.ui.AlarmReceiver "            android:process=": remote >        </receiver>        <activity            android:name= ". UI. Alarmalertactivity "            android:label=" @string/app_name "            android:launchmode=" SingleInstance            " Android:theme= "@android: Style/theme.holo.wallpaper.notitlebar" >        </activity>



2 receiver and one activity are defined.

Broadcast receiver (broadcast receiver) is one of the four components of Android.

The configuration "Android.intent.action.BOOT_COMPLETED" of the alarminitreceiver indicates that
When the Android phone is powered on, it will send Android.intent.action.BOOT_COMPLETED broadcasts and listen to the radio to monitor the boot.
After the boot, to deal with the existing notes, the comparison date, if there is an expiry, use Alarmmanager to remind users.

Scenario 1. Just mentioned, when booting, you need to deal with the existing notes.
public class Alarminitreceiver extends Broadcastreceiver {@Override public void onreceive (context context, Intent int        ENT) {Long currentdate = System.currenttimemillis (); Cursor C = context.getcontentresolver (). Query (Notes.content_note_uri, PROJECTION, Notecolumn S.alerted_date + ";                and "+ notecolumns.type +" = "+ Notes.type_note, new string[] {string.valueof (currentdate)},        NULL); if (c! = null) {if (C.movetofirst ()) {do {long alertdate = C.getlong (colum                    N_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 (); }    }}




Scenario 2: When editing a note, you need to set the date.


Menu events for Nodeeditactivity

Case R.id.menu_delete_remind:mworkingnote.setalertdate (0, false); Workingnote public void setalertdate (long date, Boolean set) {if (date! = malertdate) {malertdate = Date;mnote.setnoteval UE (NOTECOLUMNS.ALERTED_DATE,STRING.VALUEOF (Malertdate));}    if (Mnotesettingstatuslistener! = null) {mnotesettingstatuslistener.onclockalertchanged (date, set);}} Event Listener, eventually nodeeditactivity public void onclockalertchanged (long date, Boolean set) {/** * User could set clock to an UNSA Ved note, so before setting the alert * clock, we should save the note first */if (!mworkingnote.existindatabase ()) {Saven OTE ();} if (Mworkingnote.getnoteid () > 0) {Intent Intent = new Intent (this, alarmreceiver.class); Intent.setdata ( Contenturis.withappendedid (Notes.content_note_uri,mworkingnote.getnoteid ())); Pendingintent pendingintent = Pendingintent.getbroadcast (this, 0,intent, 0); Alarmmanager Alarmmanager = ((Alarmmanager) Getsystemservice (Alarm_service)); Showalertheader (); if (!set) { Alarmmanager.cancel (Pendingintent);} else {Alarmmanager.set (alarmmanager.rtc_wakeup, date, pendingintent);}} else {/** * There is the condition that user had input nothing (the note was * not worthy saving) and we have no note ID, Remi nd the user that he * should input something */log.e (TAG, "Clock Alert setting error"); Showtoast (R.string.error_note_empty _for_clock);}}


If the user sets the time, a listener is put through Alarmmanager.

Scenario 3: Remind the final performer of the broadcast
Alarminitreceiver is responsible for handling notes when the system starts.
Alarmreceiver has been waiting for a "note to remind users" of the broadcast.
public class Alarmreceiver extends Broadcastreceiver {@Overridepublic void OnReceive (context context, Intent Intent) {int Ent.setclass (context, alarmalertactivity.class); Intent.addflags (Intent.flag_activity_new_task); Context.startactivity (intent);}} Time expires, reminders of the activity is alarmalertactivity. public class Alarmalertactivity extends Activity implements Onclicklistener,ondismisslistener {protected void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (Window.feature_no_title); Final Window win = GetWindow (); Win.addflags (WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); if (!isscreenon ()) { Win.addflags (windowmanager.layoutparams.flag_keep_screen_on| windowmanager.layoutparams.flag_turn_screen_on| windowmanager.layoutparams.flag_allow_lock_while_screen_on| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);} Intent Intent = getintent (); try {Mnoteid = long.valueof (Intent.getdata (). Getpathsegments (). Get (1)); Msnippet = Datautils.getsnippetbyid (This.getcontentresolvER (), mnoteid); msnippet = Msnippet.length () > Snippet_prew_max_len? Msnippet.substring (0, Snippet_prew_max_len) + getresources (). getString (R.string.notelist_string_info): MSnippet;} catch (IllegalArgumentException e) {e.printstacktrace (); return;} MPlayer = new MediaPlayer (), if (Datautils.visibleinnotedatabase (Getcontentresolver (), mnoteid,notes.type_note)) { Showactiondialog ();p layalarmsound ();} else {finish ();}}}




Android mechanisms and class libraries that require special learning.
A.alarmmanager
Alarmmanager, as the name implies, is a "reminder", a system-level cue service commonly used in Android, that broadcasts a specified intent for us at specific times.
Simply put, we set a time, and then when that time comes, Alarmmanager broadcasts a intent we set for us.
Usually we use pendingintent,pendingintent can be understood as intent package, in short, is in the intent on the addition of a specified action.
When using intent, we also need to perform startactivity, StartService, or sendbroadcast to make intent useful.
And Pendingintent's words are to include this action inside.
B.mediaplayer play sound.
C.ringtonemanager ringtones.
D.powermanager and WindowManager.
When playing the ringtone, first judge Powermanager.isscreenon to determine whether the screen is "bright", if not bright need to do some processing.
WindowManager allows the app to interact with the window (the interface. )。
Should be in the lock screen, and so on, do a bit of special treatment, has not been specifically to examine.

PowerManager, Power Management ~

written at the end:
The research process, encountered a lot of not very understand the code, on-line search learning, basic know how to go.
In 2011, 4 years ago, there was a 2-month period of study.
It's been working for several years now, and all kinds of techniques have been researched or learned.
Now, it's not a big challenge to look at Android app development again.
The overall understanding of Android, read a few books, you can study and write code.
Do not understand, find information on the Internet, and then summarize their own, a long time, estimated 1-2 years, even if it is a skilled worker.
It is expected that by the second half of 2016, my Android level will be very good.
In Wuhan this second-tier city, if let me engage in the development of Android, salary is around 8k~15k ~
maybe ~


References
Android Boot broadcast Android.intent.action.BOOT_COMPLETED
http://my.oschina.net/onlytwo/blog/281892

Androidmanifest.xml file Details (receiver)
http://blog.csdn.net/think_soft/article/details/7583047

Broadcast receiver components in Android
http://blog.csdn.net/zuolongsnail/article/details/6450156

The use of Alarmmanager in Android
http://blog.csdn.net/wangxingwu_314/article/details/8060312

"Android Notes" MediaPlayer Basic usage mode
Http://blog.csdn.net/ddna/article/details/5176233#reply

Media Development Ringtone settings (Ringtonemanager)
http://rocking-kaan-126-com.iteye.com/blog/1228215

Overview of how Android determines screen lock screen
Http://www.2cto.com/kf/201404/296615.html

Android PowerManager and Power management
http://blog.csdn.net/xieqibao/article/details/6562256

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Small Michaeluan sticky note notes-Source Research (2)-Notes for timed reminders

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.