Search in sources :

Example 51 with RemoteViews

use of android.widget.RemoteViews in project android_frameworks_base by ParanoidAndroid.

the class TestAppWidgetProvider method onReceive.

public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Log.d(TAG, "intent=" + intent);
    if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
        Log.d(TAG, "ENABLED");
    } else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
        Log.d(TAG, "DISABLED");
    } else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
        if (true)
            return;
        Log.d(TAG, "UPDATE");
        Bundle extras = intent.getExtras();
        int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        AppWidgetManager gm = AppWidgetManager.getInstance(context);
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_appwidget);
        views.setTextViewText(R.id.oh_hai_text, "hai: " + SystemClock.elapsedRealtime());
        if (false) {
            gm.updateAppWidget(appWidgetIds, views);
        } else {
            gm.updateAppWidget(new ComponentName("com.android.tests.appwidgetprovider", "com.android.tests.appwidgetprovider.TestAppWidgetProvider"), views);
        }
    }
}
Also used : RemoteViews(android.widget.RemoteViews) Bundle(android.os.Bundle) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 52 with RemoteViews

use of android.widget.RemoteViews in project android_frameworks_base by ParanoidAndroid.

the class AppWidgetHost method createView.

/**
     * Create the AppWidgetHostView for the given widget.
     * The AppWidgetHost retains a pointer to the newly-created View.
     */
public final AppWidgetHostView createView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget) {
    final int userId = mContext.getUserId();
    AppWidgetHostView view = onCreateView(mContext, appWidgetId, appWidget);
    view.setUserId(userId);
    view.setOnClickHandler(mOnClickHandler);
    view.setAppWidget(appWidgetId, appWidget);
    synchronized (mViews) {
        mViews.put(appWidgetId, view);
    }
    RemoteViews views;
    try {
        views = sService.getAppWidgetViews(appWidgetId, userId);
        if (views != null) {
            views.setUser(new UserHandle(mContext.getUserId()));
        }
    } catch (RemoteException e) {
        throw new RuntimeException("system server dead?", e);
    }
    view.updateAppWidget(views);
    return view;
}
Also used : RemoteViews(android.widget.RemoteViews) UserHandle(android.os.UserHandle) RemoteException(android.os.RemoteException)

Example 53 with RemoteViews

use of android.widget.RemoteViews in project android_frameworks_base by ParanoidAndroid.

the class BaseStatusBar method updateNotification.

public void updateNotification(IBinder key, StatusBarNotification notification) {
    if (DEBUG)
        Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ")");
    final NotificationData.Entry oldEntry = mNotificationData.findByKey(key);
    if (oldEntry == null) {
        Slog.w(TAG, "updateNotification for unknown key: " + key);
        return;
    }
    final StatusBarNotification oldNotification = oldEntry.notification;
    // XXX: modify when we do something more intelligent with the two content views
    final RemoteViews oldContentView = oldNotification.getNotification().contentView;
    final RemoteViews contentView = notification.getNotification().contentView;
    final RemoteViews oldBigContentView = oldNotification.getNotification().bigContentView;
    final RemoteViews bigContentView = notification.getNotification().bigContentView;
    if (DEBUG) {
        Slog.d(TAG, "old notification: when=" + oldNotification.getNotification().when + " ongoing=" + oldNotification.isOngoing() + " expanded=" + oldEntry.expanded + " contentView=" + oldContentView + " bigContentView=" + oldBigContentView + " rowParent=" + oldEntry.row.getParent());
        Slog.d(TAG, "new notification: when=" + notification.getNotification().when + " ongoing=" + oldNotification.isOngoing() + " contentView=" + contentView + " bigContentView=" + bigContentView);
    }
    // Can we just reapply the RemoteViews in place?  If when didn't change, the order
    // didn't change.
    // 1U is never null
    boolean contentsUnchanged = oldEntry.expanded != null && contentView.getPackage() != null && oldContentView.getPackage() != null && oldContentView.getPackage().equals(contentView.getPackage()) && oldContentView.getLayoutId() == contentView.getLayoutId();
    // large view may be null
    boolean bigContentsUnchanged = (oldEntry.getLargeView() == null && bigContentView == null) || ((oldEntry.getLargeView() != null && bigContentView != null) && bigContentView.getPackage() != null && oldBigContentView.getPackage() != null && oldBigContentView.getPackage().equals(bigContentView.getPackage()) && oldBigContentView.getLayoutId() == bigContentView.getLayoutId());
    ViewGroup rowParent = (ViewGroup) oldEntry.row.getParent();
    boolean orderUnchanged = notification.getNotification().when == oldNotification.getNotification().when && notification.getScore() == oldNotification.getScore();
    // score now encompasses/supersedes isOngoing()
    boolean updateTicker = notification.getNotification().tickerText != null && !TextUtils.equals(notification.getNotification().tickerText, oldEntry.notification.getNotification().tickerText) || mHaloActive;
    boolean isTopAnyway = isTopNotification(rowParent, oldEntry);
    if (contentsUnchanged && bigContentsUnchanged && (orderUnchanged || isTopAnyway)) {
        if (DEBUG)
            Slog.d(TAG, "reusing notification for key: " + key);
        oldEntry.notification = notification;
        try {
            // Reapply the RemoteViews
            contentView.reapply(mContext, oldEntry.expanded, mOnClickHandler);
            if (bigContentView != null && oldEntry.getLargeView() != null) {
                bigContentView.reapply(mContext, oldEntry.getLargeView(), mOnClickHandler);
            }
            // update the contentIntent
            final PendingIntent contentIntent = notification.getNotification().contentIntent;
            if (contentIntent != null) {
                final View.OnClickListener listener = makeClicker(contentIntent, notification.getPackageName(), notification.getTag(), notification.getId());
                oldEntry.content.setOnClickListener(listener);
                oldEntry.floatingIntent = makeClicker(contentIntent, notification.getPackageName(), notification.getTag(), notification.getId());
                oldEntry.floatingIntent.makeFloating(true);
            } else {
                oldEntry.content.setOnClickListener(null);
                oldEntry.floatingIntent = null;
            }
            // Update the roundIcon
            prepareHaloNotification(oldEntry, notification, true);
            // Update the icon.
            final StatusBarIcon ic = new StatusBarIcon(notification.getPackageName(), notification.getUser(), notification.getNotification().icon, notification.getNotification().iconLevel, notification.getNotification().number, notification.getNotification().tickerText);
            if (!oldEntry.icon.set(ic)) {
                handleNotificationError(key, notification, "Couldn't update icon: " + ic);
                return;
            }
            updateExpansionStates();
        } catch (RuntimeException e) {
            // It failed to add cleanly.  Log, and remove the view from the panel.
            Slog.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e);
            removeNotificationViews(key);
            addNotificationViews(key, notification);
        }
    } else {
        if (DEBUG)
            Slog.d(TAG, "not reusing notification for key: " + key);
        if (DEBUG)
            Slog.d(TAG, "contents was " + (contentsUnchanged ? "unchanged" : "changed"));
        if (DEBUG)
            Slog.d(TAG, "order was " + (orderUnchanged ? "unchanged" : "changed"));
        if (DEBUG)
            Slog.d(TAG, "notification is " + (isTopAnyway ? "top" : "not top"));
        final boolean wasExpanded = oldEntry.userExpanded();
        removeNotificationViews(key);
        addNotificationViews(key, notification);
        if (wasExpanded) {
            final NotificationData.Entry newEntry = mNotificationData.findByKey(key);
            expandView(newEntry, true);
            newEntry.setUserExpanded(true);
        }
    }
    // Update the veto button accordingly (and as a result, whether this row is
    // swipe-dismissable)
    updateNotificationVetoButton(oldEntry.row, notification);
    // Is this for you?
    boolean isForCurrentUser = notificationIsForCurrentUser(notification);
    if (DEBUG)
        Slog.d(TAG, "notification is " + (isForCurrentUser ? "" : "not ") + "for you");
    // Restart the ticker if it's still running
    if (updateTicker && isForCurrentUser) {
        haltTicker();
        tick(key, notification, false);
    }
    // Recalculate the position of the sliding windows and the titles.
    setAreThereNotifications();
    updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
    // See if we need to update the intruder.
    if (ENABLE_INTRUDERS && oldNotification == mCurrentlyIntrudingNotification) {
        if (DEBUG)
            Slog.d(TAG, "updating the current intruder:" + notification);
        // the intruder.
        if (notification.getNotification().fullScreenIntent == null) {
            // TODO(dsandler): consistent logic with add()
            if (DEBUG)
                Slog.d(TAG, "no longer intrudes!");
            mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER);
        }
    }
    // Update halo
    if (mHalo != null)
        mHalo.update();
}
Also used : RemoteViews(android.widget.RemoteViews) StatusBarNotification(android.service.notification.StatusBarNotification) ViewGroup(android.view.ViewGroup) PendingIntent(android.app.PendingIntent) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon) ImageView(android.widget.ImageView) QuickSettingsContainerView(com.android.systemui.statusbar.phone.QuickSettingsContainerView) View(android.view.View) TextView(android.widget.TextView) SearchPanelView(com.android.systemui.SearchPanelView)

Example 54 with RemoteViews

use of android.widget.RemoteViews in project k-9 by k9mail.

the class MessageListRemoteViewFactory method getViewAt.

@Override
public RemoteViews getViewAt(int position) {
    RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.message_list_widget_list_item);
    MailItem item = mailItems.get(position);
    CharSequence sender = item.unread ? bold(item.sender) : item.sender;
    CharSequence subject = item.unread ? bold(item.subject) : item.subject;
    if (senderAboveSubject) {
        remoteView.setTextViewText(R.id.sender, sender);
        remoteView.setTextViewText(R.id.mail_subject, subject);
    } else {
        remoteView.setTextViewText(R.id.sender, subject);
        remoteView.setTextViewText(R.id.mail_subject, sender);
    }
    remoteView.setTextViewText(R.id.mail_date, item.getDateFormatted("%d %s"));
    remoteView.setTextViewText(R.id.mail_preview, item.preview);
    int textColor = item.getTextColor();
    remoteView.setTextColor(R.id.sender, textColor);
    remoteView.setTextColor(R.id.mail_subject, textColor);
    remoteView.setTextColor(R.id.mail_date, textColor);
    remoteView.setTextColor(R.id.mail_preview, textColor);
    if (item.hasAttachment) {
        remoteView.setInt(R.id.attachment, "setVisibility", View.VISIBLE);
    } else {
        remoteView.setInt(R.id.attachment, "setVisibility", View.GONE);
    }
    Intent intent = new Intent();
    intent.setData(item.uri);
    remoteView.setOnClickFillInIntent(R.id.mail_list_item, intent);
    return remoteView;
}
Also used : RemoteViews(android.widget.RemoteViews) Intent(android.content.Intent)

Example 55 with RemoteViews

use of android.widget.RemoteViews in project k-9 by k9mail.

the class MessageListWidgetProvider method updateAppWidget.

private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.message_list_widget_layout);
    views.setTextViewText(R.id.folder, context.getString(R.string.integrated_inbox_title));
    Intent intent = new Intent(context, MessageListWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    views.setRemoteAdapter(R.id.listView, intent);
    PendingIntent viewAction = viewActionTemplatePendingIntent(context);
    views.setPendingIntentTemplate(R.id.listView, viewAction);
    PendingIntent composeAction = composeActionPendingIntent(context);
    views.setOnClickPendingIntent(R.id.new_message, composeAction);
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
Also used : RemoteViews(android.widget.RemoteViews) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Aggregations

RemoteViews (android.widget.RemoteViews)217 Intent (android.content.Intent)86 PendingIntent (android.app.PendingIntent)77 TextView (android.widget.TextView)35 Test (org.junit.Test)35 Notification (android.app.Notification)30 SmallTest (android.support.test.filters.SmallTest)30 View (android.view.View)29 ImageView (android.widget.ImageView)28 AppWidgetManager (android.appwidget.AppWidgetManager)26 ComponentName (android.content.ComponentName)24 Bitmap (android.graphics.Bitmap)24 Bundle (android.os.Bundle)16 NavigationBarView (com.android.systemui.statusbar.phone.NavigationBarView)15 RemoteInputView (com.android.systemui.statusbar.policy.RemoteInputView)15 NotificationCompat (android.support.v4.app.NotificationCompat)14 Resources (android.content.res.Resources)12 StatusBarNotification (android.service.notification.StatusBarNotification)12 SharedPreferences (android.content.SharedPreferences)11 NotificationPanelView (com.android.systemui.statusbar.phone.NotificationPanelView)11