use of android.app.AlarmManager in project Signal-Android by WhisperSystems.
the class PersistentAlarmManagerListener method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
long scheduledTime = getNextScheduledExecutionTime(context);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent = new Intent(context, getClass());
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);
if (System.currentTimeMillis() >= scheduledTime) {
scheduledTime = onAlarm(context, scheduledTime);
}
Log.w(TAG, getClass() + " scheduling for: " + scheduledTime);
alarmManager.cancel(pendingIntent);
alarmManager.set(AlarmManager.RTC_WAKEUP, scheduledTime, pendingIntent);
}
use of android.app.AlarmManager in project Signal-Android by WhisperSystems.
the class KeyCachingService method handleActivityStarted.
private void handleActivityStarted() {
Log.w("KeyCachingService", "Incrementing activity count...");
AlarmManager alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE);
alarmManager.cancel(pending);
activitiesRunning++;
}
use of android.app.AlarmManager in project Talon-for-Twitter by klinker24.
the class ActivityFragment method onRefreshStarted.
@Override
public void onRefreshStarted() {
new AsyncTask<Void, Void, Cursor>() {
private boolean update = false;
@Override
protected void onPreExecute() {
DrawerActivity.canSwitch = false;
}
@Override
protected Cursor doInBackground(Void... params) {
ActivityUtils utils = new ActivityUtils(getActivity());
update = utils.refreshActivity();
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long now = new Date().getTime();
long alarm = now + DrawerActivity.settings.activityRefresh;
PendingIntent pendingIntent = PendingIntent.getService(context, ACTIVITY_REFRESH_ID, new Intent(context, ActivityRefreshService.class), 0);
if (DrawerActivity.settings.activityRefresh != 0)
am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, DrawerActivity.settings.activityRefresh, pendingIntent);
else
am.cancel(pendingIntent);
if (settings.syncSecondMentions) {
context.startService(new Intent(context, SecondActivityRefreshService.class));
}
return ActivityDataSource.getInstance(context).getCursor(currentAccount);
}
@Override
protected void onPostExecute(Cursor cursor) {
Cursor c = null;
try {
c = cursorAdapter.getCursor();
} catch (Exception e) {
}
cursorAdapter = setAdapter(cursor);
try {
listView.setAdapter(cursorAdapter);
} catch (Exception e) {
}
if (cursor.getCount() == 0) {
spinner.setVisibility(View.VISIBLE);
} else {
spinner.setVisibility(View.GONE);
}
try {
if (update) {
showToastBar(getString(R.string.new_activity), getString(R.string.ok), 400, true, toTopListener);
}
} catch (Exception e) {
// user closed the app before it was done
}
refreshLayout.setRefreshing(false);
DrawerActivity.canSwitch = true;
try {
c.close();
} catch (Exception e) {
}
}
}.execute();
}
use of android.app.AlarmManager in project Talon-for-Twitter by klinker24.
the class NewScheduledTweet method createAlarm.
public void createAlarm(int alarmId) {
Intent serviceIntent = new Intent(getApplicationContext(), SendScheduledTweet.class);
serviceIntent.putExtra(ViewScheduledTweets.EXTRA_TEXT, mEditText.getText().toString());
serviceIntent.putExtra("account", settings.currentAccount);
serviceIntent.putExtra("alarm_id", alarmId);
PendingIntent pi = getDistinctPendingIntent(serviceIntent, alarmId);
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, setDate.getTime(), pi);
}
use of android.app.AlarmManager in project Talon-for-Twitter by klinker24.
the class ViewScheduledTweets method cancelAlarm.
public void cancelAlarm(int alarmId) {
Intent serviceIntent = new Intent(getApplicationContext(), SendScheduledTweet.class);
PendingIntent pi = getDistinctPendingIntent(serviceIntent, alarmId);
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.cancel(pi);
}
Aggregations