Search in sources :

Example 1 with TaskStackBuilder

use of android.support.v4.app.TaskStackBuilder 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)

Example 2 with TaskStackBuilder

use of android.support.v4.app.TaskStackBuilder in project Fairphone by Kwamecorp.

the class UpdaterService method setNotification.

private void setNotification() {
    Context context = getApplicationContext();
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.fairphone_updater_tray_icon_small).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.fairphone_updater_tray_icon)).setContentTitle(context.getResources().getString(R.string.app_name)).setContentText(getResources().getString(R.string.fairphoneUpdateMessage));
    Intent resultIntent = new Intent(context, FairphoneUpdater.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(FairphoneUpdater.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    Notification notificationWhileRunnig = builder.build();
    // Add notification
    manager.notify(0, notificationWhileRunnig);
    //to update the activity
    Intent updateIntent = new Intent(FairphoneUpdater.FAIRPHONE_UPDATER_NEW_VERSION_RECEIVED);
    sendBroadcast(updateIntent);
}
Also used : Context(android.content.Context) NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.app.TaskStackBuilder) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) Notification(android.app.Notification)

Example 3 with TaskStackBuilder

use of android.support.v4.app.TaskStackBuilder in project DeepLinkDispatch by airbnb.

the class DeepLinkDelegate method dispatchFrom.

public DeepLinkResult dispatchFrom(Activity activity, Intent sourceIntent) {
    if (activity == null) {
        throw new NullPointerException("activity == null");
    }
    if (sourceIntent == null) {
        throw new NullPointerException("sourceIntent == null");
    }
    Uri uri = sourceIntent.getData();
    if (uri == null) {
        return createResultAndNotify(activity, false, null, "No Uri in given activity's intent.");
    }
    String uriString = uri.toString();
    DeepLinkEntry entry = findEntry(uriString);
    if (entry != null) {
        DeepLinkUri deepLinkUri = DeepLinkUri.parse(uriString);
        Map<String, String> parameterMap = entry.getParameters(uriString);
        for (String queryParameter : deepLinkUri.queryParameterNames()) {
            for (String queryParameterValue : deepLinkUri.queryParameterValues(queryParameter)) {
                if (parameterMap.containsKey(queryParameter)) {
                    Log.w(TAG, "Duplicate parameter name in path and query param: " + queryParameter);
                }
                parameterMap.put(queryParameter, queryParameterValue);
            }
        }
        parameterMap.put(DeepLink.URI, uri.toString());
        Bundle parameters;
        if (sourceIntent.getExtras() != null) {
            parameters = new Bundle(sourceIntent.getExtras());
        } else {
            parameters = new Bundle();
        }
        for (Map.Entry<String, String> parameterEntry : parameterMap.entrySet()) {
            parameters.putString(parameterEntry.getKey(), parameterEntry.getValue());
        }
        try {
            Class<?> c = entry.getActivityClass();
            Intent newIntent;
            TaskStackBuilder taskStackBuilder = null;
            if (entry.getType() == DeepLinkEntry.Type.CLASS) {
                newIntent = new Intent(activity, c);
            } else {
                Method method;
                try {
                    method = c.getMethod(entry.getMethod(), Context.class);
                    if (method.getReturnType().equals(TaskStackBuilder.class)) {
                        taskStackBuilder = (TaskStackBuilder) method.invoke(c, activity);
                        if (taskStackBuilder.getIntentCount() == 0) {
                            return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod() + " intents length == 0");
                        }
                        newIntent = taskStackBuilder.editIntentAt(taskStackBuilder.getIntentCount() - 1);
                    } else {
                        newIntent = (Intent) method.invoke(c, activity);
                    }
                } catch (NoSuchMethodException exception) {
                    method = c.getMethod(entry.getMethod(), Context.class, Bundle.class);
                    if (method.getReturnType().equals(TaskStackBuilder.class)) {
                        taskStackBuilder = (TaskStackBuilder) method.invoke(c, activity, parameters);
                        if (taskStackBuilder.getIntentCount() == 0) {
                            return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod() + " intents length == 0");
                        }
                        newIntent = taskStackBuilder.editIntentAt(taskStackBuilder.getIntentCount() - 1);
                    } else {
                        newIntent = (Intent) method.invoke(c, activity, parameters);
                    }
                }
            }
            if (newIntent.getAction() == null) {
                newIntent.setAction(sourceIntent.getAction());
            }
            if (newIntent.getData() == null) {
                newIntent.setData(sourceIntent.getData());
            }
            newIntent.putExtras(parameters);
            newIntent.putExtra(DeepLink.IS_DEEP_LINK, true);
            newIntent.putExtra(DeepLink.REFERRER_URI, uri);
            if (activity.getCallingActivity() != null) {
                newIntent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
            }
            if (taskStackBuilder != null) {
                taskStackBuilder.startActivities();
            } else {
                activity.startActivity(newIntent);
            }
            return createResultAndNotify(activity, true, uri, null);
        } catch (NoSuchMethodException exception) {
            return createResultAndNotify(activity, false, uri, "Deep link to non-existent method: " + entry.getMethod());
        } catch (IllegalAccessException exception) {
            return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod());
        } catch (InvocationTargetException exception) {
            return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod());
        }
    } else {
        return createResultAndNotify(activity, false, uri, "No registered entity to handle deep link: " + uri.toString());
    }
}
Also used : Context(android.content.Context) DeepLinkUri(com.airbnb.deeplinkdispatch.DeepLinkUri) Bundle(android.os.Bundle) Intent(android.content.Intent) String(java.lang.String) Method(java.lang.reflect.Method) DeepLinkUri(com.airbnb.deeplinkdispatch.DeepLinkUri) Uri(android.net.Uri) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchMethodException(java.lang.NoSuchMethodException) NullPointerException(java.lang.NullPointerException) DeepLinkEntry(com.airbnb.deeplinkdispatch.DeepLinkEntry) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) Map(java.util.Map)

Example 4 with TaskStackBuilder

use of android.support.v4.app.TaskStackBuilder in project Klyph by jonathangerbaud.

the class KlyphNotification method sendNotification.

public static void sendNotification(Context context, Builder builder, Notification notification) {
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    Intent resultIntent = null;
    final String id = notification.getObject_id();
    final String name = notification.getObject_name();
    final String type = notification.getObject_type();
    if (type.equals(Notification.TYPE_FRIEND) || type.equals(Notification.TYPE_POKE) || type.equals(Notification.TYPE_USER)) {
        resultIntent = Klyph.getIntentForParams(context, id, name, Notification.TYPE_FRIEND);
        stackBuilder.addParentStack(UserActivity.class);
    } else if (type.equals(Notification.TYPE_EVENT)) {
        resultIntent = Klyph.getIntentForParams(context, id, name, type);
        stackBuilder.addParentStack(EventActivity.class);
    } else if (type.equals(Notification.TYPE_PAGE)) {
        resultIntent = Klyph.getIntentForParams(context, id, name, type);
        stackBuilder.addParentStack(PageActivity.class);
    } else if (type.equals(Notification.TYPE_GROUP)) {
        if (notification.getGroup().getGid().length() == 0) {
            // That is not a group but a post in a group
            resultIntent = new Intent(context, StreamActivity.class);
            resultIntent.putExtra(KlyphBundleExtras.STREAM_GROUP, true);
            resultIntent.putExtra(KlyphBundleExtras.STREAM_ID, id);
            stackBuilder.addParentStack(StreamActivity.class);
        } else {
            resultIntent = Klyph.getIntentForParams(context, id, name, type);
            stackBuilder.addParentStack(GroupActivity.class);
        }
    } else if (type.equals(Notification.TYPE_PHOTO)) {
        resultIntent = new Intent(context, ImageActivity.class);
        resultIntent.putExtra(KlyphBundleExtras.PHOTO_ID, id);
        stackBuilder.addParentStack(ImageActivity.class);
    } else if (type.equals(Notification.TYPE_ALBUM)) {
        resultIntent = new Intent(context, AlbumPhotosActivity.class);
        resultIntent.putExtra(KlyphBundleExtras.ALBUM_ID, id);
        resultIntent.putExtra(KlyphBundleExtras.ALBUM_NAME, name);
    } else if (type.equals(Notification.TYPE_APP_REQUEST)) {
        resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(notification.getHref()));
    } else if (type.equals(Notification.TYPE_VIDEO)) {
        resultIntent = new Intent(context, MainActivity.class);
    // ???
    // resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(notification.getHref()));
    } else {
        // Stream
        resultIntent = new Intent(context, StreamActivity.class);
        resultIntent.putExtra(KlyphBundleExtras.STREAM_ID, id);
        stackBuilder.addParentStack(StreamActivity.class);
    }
    resultIntent.putExtra(KlyphBundleExtras.SET_NOTIFICATION_AS_READ, true);
    resultIntent.putExtra(KlyphBundleExtras.NOTIFICATION_ID, notification.getNotification_id());
    // Adds the Intent to the top of the stack
    stackBuilder.addNextIntentWithParentStack(resultIntent);
    int intentCode = (int) Math.round(Math.random() * 1000000);
    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(intentCode, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    Intent intent = new Intent(context, NotificationDeletedReceiver.class);
    intent.putExtra(KlyphBundleExtras.NOTIFICATION_ID, notification.getNotification_id());
    int random = (int) Math.round(Math.random() * 100000);
    builder.setDeleteIntent(PendingIntent.getBroadcast(context.getApplicationContext(), random, intent, 0));
    final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Log.d("NotificationService", "Notify " + notification.getNotification_id());
    final String tag = context.getPackageName() + "_" + notification.getNotification_id();
    // pair (tag, id) must be unique
    // because notificationId may not be converted to an int
    // tag is the unique key
    mNotificationManager.notify(tag, 0, builder.build());
}
Also used : ImageActivity(com.abewy.android.apps.klyph.app.ImageActivity) NotificationManager(android.app.NotificationManager) StreamActivity(com.abewy.android.apps.klyph.app.StreamActivity) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) EventActivity(com.abewy.android.apps.klyph.app.EventActivity) GroupActivity(com.abewy.android.apps.klyph.app.GroupActivity)

Example 5 with TaskStackBuilder

use of android.support.v4.app.TaskStackBuilder in project k-9 by k9mail.

the class NotificationActionCreator method buildFolderListBackStack.

private TaskStackBuilder buildFolderListBackStack(Account account) {
    TaskStackBuilder stack = buildAccountsBackStack();
    Intent intent = FolderList.actionHandleAccountIntent(context, account, false);
    stack.addNextIntent(intent);
    return stack;
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder)

Aggregations

Intent (android.content.Intent)39 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)38 PendingIntent (android.app.PendingIntent)34 NotificationCompat (android.support.v4.app.NotificationCompat)20 NotificationManager (android.app.NotificationManager)14 Bitmap (android.graphics.Bitmap)13 InputStream (java.io.InputStream)10 IOException (java.io.IOException)8 URL (java.net.URL)8 Notification (android.app.Notification)7 Context (android.content.Context)5 Uri (android.net.Uri)5 SharedPreferences (android.content.SharedPreferences)3 Resources (android.content.res.Resources)3 Cursor (android.database.Cursor)3 RemoteViews (android.widget.RemoteViews)3 TaskStackBuilder (android.app.TaskStackBuilder)2 ContentResolver (android.content.ContentResolver)2 Bundle (android.os.Bundle)2 NonNull (android.support.annotation.NonNull)2