use of android.app.PendingIntent in project Reader by TheKeeperOfPie.
the class Receiver method setAlarm.
public static void setAlarm(Context context) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
Intent intentInbox = new Intent(INTENT_INBOX);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intentInbox, PendingIntent.FLAG_UPDATE_CURRENT);
long interval = Long.parseLong(preferences.getString(AppSettings.PREF_INBOX_CHECK_INTERVAL, "1800000"));
if (interval > 0) {
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000, interval, pendingIntent);
}
Log.d(TAG, "setAlarm: " + interval);
}
use of android.app.PendingIntent in project CircularViewPager by TobiasBuchholz.
the class GoogleIabHelper method tryPurchaseItem.
private void tryPurchaseItem(final Activity activity, final String productId, final String itemType) throws RemoteException, IntentSender.SendIntentException {
final Bundle buyIntentBundle = mIABService.getBuyIntent(3, mContext.getPackageName(), productId, itemType, null);
final int responseCode = getResponseCode(buyIntentBundle);
if (responseCode == BILLING_RESPONSE_RESULT_OK) {
mRequestCode = REQUEST_CODE_PURCHASE;
final PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
activity.startIntentSenderForResult(pendingIntent.getIntentSender(), REQUEST_CODE_PURCHASE, new Intent(), 0, 0, 0);
} else {
handlePurchaseError(activity, responseCode);
}
}
use of android.app.PendingIntent in project SeriesGuide by UweTrottmann.
the class ListWidgetProvider method onUpdate.
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// update all added list widgets
for (int appWidgetId : appWidgetIds) {
onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, null);
}
// set an alarm to update widgets every x mins if the device is awake
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (am != null) {
PendingIntent pi = getUpdatePendingIntent(context);
am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + REPETITION_INTERVAL, REPETITION_INTERVAL, pi);
Timber.d("onUpdate: scheduled widget UPDATE alarm.");
}
}
use of android.app.PendingIntent in project SeriesGuide by UweTrottmann.
the class ListWidgetProvider method onDisabled.
@Override
public void onDisabled(Context context) {
// remove the update alarm if the last widget is gone
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (am != null) {
PendingIntent pi = getUpdatePendingIntent(context);
am.cancel(pi);
Timber.d("onDisabled: canceled widget UPDATE alarm.");
}
}
use of android.app.PendingIntent in project SeriesGuide by UweTrottmann.
the class ListWidgetProvider method buildRemoteViews.
public static RemoteViews buildRemoteViews(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
// setup intent pointing to RemoteViewsService providing the views for the collection
Intent intent = new Intent(context, ListWidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
// When intents are compared, the extras are ignored, so we need to
// embed the extras into the data so that the extras will not be
// ignored.
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
// determine layout (current size) and theme (user pref)
final boolean isCompactLayout = isCompactLayout(appWidgetManager, appWidgetId);
final boolean isLightTheme = WidgetSettings.isLightTheme(context, appWidgetId);
int layoutResId;
if (isLightTheme) {
layoutResId = isCompactLayout ? R.layout.appwidget_v11_light_compact : R.layout.appwidget_v11_light;
} else {
layoutResId = isCompactLayout ? R.layout.appwidget_v11_compact : R.layout.appwidget_v11;
}
// build widget views
RemoteViews rv = new RemoteViews(context.getPackageName(), layoutResId);
rv.setRemoteAdapter(R.id.list_view, intent);
// The empty view is displayed when the collection has no items. It
// should be a sibling of the collection view.
rv.setEmptyView(R.id.list_view, R.id.empty_view);
// set the background colors of...
// ...the header
boolean isDarkTheme = WidgetSettings.isDarkTheme(context, appWidgetId);
rv.setInt(R.id.containerWidgetHeader, "setBackgroundColor", isDarkTheme ? Color.TRANSPARENT : ContextCompat.getColor(context, R.color.accent_primary));
// ...the whole widget
int bgColor = WidgetSettings.getWidgetBackgroundColor(context, appWidgetId, isLightTheme);
rv.setInt(R.id.container, "setBackgroundColor", bgColor);
// determine type specific values
final int widgetType = WidgetSettings.getWidgetListType(context, appWidgetId);
int showsTabIndex;
int titleResId;
int emptyResId;
if (widgetType == WidgetSettings.Type.UPCOMING) {
// upcoming
showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_UPCOMING;
titleResId = R.string.upcoming;
emptyResId = R.string.noupcoming;
} else if (widgetType == WidgetSettings.Type.RECENT) {
// recent
showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_RECENT;
titleResId = R.string.recent;
emptyResId = R.string.norecent;
} else {
// shows
showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_SHOWS;
titleResId = R.string.shows;
emptyResId = R.string.no_nextepisode;
}
// change title and empty view based on type
rv.setTextViewText(R.id.empty_view, context.getString(emptyResId));
if (!isCompactLayout) {
// only regular layout has text title
rv.setTextViewText(R.id.widgetTitle, context.getString(titleResId));
}
// app launch button
final Intent appLaunchIntent = new Intent(context, ShowsActivity.class).putExtra(ShowsActivity.InitBundle.SELECTED_TAB, showsTabIndex);
PendingIntent pendingIntent = TaskStackBuilder.create(context).addNextIntent(appLaunchIntent).getPendingIntent(appWidgetId, PendingIntent.FLAG_UPDATE_CURRENT);
rv.setOnClickPendingIntent(R.id.widget_title, pendingIntent);
// item intent template, launches episode detail view
TaskStackBuilder builder = TaskStackBuilder.create(context);
builder.addNextIntent(appLaunchIntent);
builder.addNextIntent(new Intent(context, EpisodesActivity.class));
rv.setPendingIntentTemplate(R.id.list_view, builder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT));
// settings button
Intent settingsIntent = new Intent(context, ListWidgetConfigure.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS).putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
rv.setOnClickPendingIntent(R.id.widget_settings, PendingIntent.getActivity(context, appWidgetId, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT));
return rv;
}
Aggregations