Search in sources :

Example 56 with PendingIntent

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);
}
Also used : SharedPreferences(android.content.SharedPreferences) AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 57 with PendingIntent

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);
    }
}
Also used : Bundle(android.os.Bundle) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 58 with PendingIntent

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.");
    }
}
Also used : AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent)

Example 59 with PendingIntent

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.");
    }
}
Also used : AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent)

Example 60 with PendingIntent

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;
}
Also used : RemoteViews(android.widget.RemoteViews) ShowsActivity(com.battlelancer.seriesguide.ui.ShowsActivity) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) EpisodesActivity(com.battlelancer.seriesguide.ui.EpisodesActivity) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder)

Aggregations

PendingIntent (android.app.PendingIntent)1208 Intent (android.content.Intent)1010 Notification (android.app.Notification)222 NotificationCompat (android.support.v4.app.NotificationCompat)167 AlarmManager (android.app.AlarmManager)149 NotificationManager (android.app.NotificationManager)148 Bundle (android.os.Bundle)75 RemoteViews (android.widget.RemoteViews)67 RemoteException (android.os.RemoteException)64 Resources (android.content.res.Resources)62 Bitmap (android.graphics.Bitmap)61 Context (android.content.Context)60 ComponentName (android.content.ComponentName)55 Test (org.junit.Test)44 Uri (android.net.Uri)42 IntentFilter (android.content.IntentFilter)41 SharedPreferences (android.content.SharedPreferences)36 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)33 UserHandle (android.os.UserHandle)31 ArrayList (java.util.ArrayList)30