Search in sources :

Example 11 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 12 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 13 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)) {
        Log.d(TAG, "UPDATE");
        // BEGIN_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
        Bundle extras = intent.getExtras();
        int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        // END_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
        SharedPreferences prefs = context.getSharedPreferences(TestAppWidgetProvider.PREFS_NAME, 0);
        String prefix = prefs.getString(PREF_PREFIX_KEY, "hai");
        AppWidgetManager gm = AppWidgetManager.getInstance(context);
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_appwidget);
        views.setTextViewText(R.id.oh_hai_text, prefix + ": " + SystemClock.elapsedRealtime());
        if (false) {
            gm.updateAppWidget(appWidgetIds, views);
        } else {
            gm.updateAppWidget(new ComponentName("com.android.tests.appwidgethost", "com.android.tests.appwidgethost.TestAppWidgetProvider"), views);
        }
    }
}
Also used : RemoteViews(android.widget.RemoteViews) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 14 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 15 with RemoteViews

use of android.widget.RemoteViews in project SeriesGuide by UweTrottmann.

the class ListWidgetConfigure method onUpdateWidget.

private void onUpdateWidget() {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    RemoteViews views = ListWidgetProvider.buildRemoteViews(this, appWidgetManager, mAppWidgetId);
    appWidgetManager.updateAppWidget(mAppWidgetId, views);
    appWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.list_view);
    Intent resultValue = new Intent();
    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
    setResult(RESULT_OK, resultValue);
    finish();
}
Also used : RemoteViews(android.widget.RemoteViews) AppWidgetManager(android.appwidget.AppWidgetManager) Intent(android.content.Intent)

Aggregations

RemoteViews (android.widget.RemoteViews)211 Intent (android.content.Intent)83 PendingIntent (android.app.PendingIntent)75 TextView (android.widget.TextView)35 Test (org.junit.Test)35 View (android.view.View)32 Notification (android.app.Notification)30 SmallTest (android.support.test.filters.SmallTest)30 ImageView (android.widget.ImageView)28 AppWidgetManager (android.appwidget.AppWidgetManager)25 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