Now, Your Friends Are Alarmed
setAlarm(isBatteryLow.get()? POLL_PERIOD* 10 : POLL_PERIOD);
}
private void setAlarm(long period) {
alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime()+period,
pi);
}
private void poll(Account l) {
try {
Twitter client=new Twitter(l.user, l.password);
client.setAPIRootUrl("https://identi.ca/api");
List<Twitter.Status> timeline=client.getFriendsTimeline();
for (Twitter.Status s : timeline) {
if (!seenStatus.contains(s.id)) {
try {
Intent broadcast=new Intent(STATUS_UPDATE);
broadcast.putExtra(FRIEND, s.user.screenName);
broadcast.putExtra(STATUS, s.text);
broadcast.putExtra(CREATED_AT,
s.createdAt.toString());
sendBroadcast(broadcast);
}
catch (Throwable t) {
Log.e("PostMonitor", "Exception in callback", t);
}
seenStatus.add(s.id);
if (s.text.indexOf(NOTIFY_KEYWORD)>- 1 ) {
showNotification();
}
}
}
}
catch (Throwable t) {
android.util.Log.e("PostMonitor",
"Exception in poll()", t);
}
}
private void showNotification() {
final NotificationManager mgr=
(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification note=new Notification(R.drawable.status,
"New matching post!",
System.currentTimeMillis());
Intent i=new Intent(this, Patchy.class);