Search in sources :

Example 41 with RemoteViews

use of android.widget.RemoteViews in project Fairphone by Kwamecorp.

the class WidgetProvider method updateMostUsedAppsList.

private int updateMostUsedAppsList(Context context, int code, RemoteViews widget, List<ApplicationRunInformation> mostUsed) {
    for (ApplicationRunInformation mostUsedInfo : mostUsed) {
        RemoteViews view = null;
        try {
            view = getMostUsedView(context, mostUsedInfo, code);
            if (view != null) {
                widget.addView(R.id.mostUsedApps, view);
            }
        } catch (NameNotFoundException e) {
            // if no information is available log it and continue
            Log.e(TAG, "Could not find the correct package", e);
            continue;
        }
        // update the code
        code++;
    }
    return code;
}
Also used : RemoteViews(android.widget.RemoteViews) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 42 with RemoteViews

use of android.widget.RemoteViews in project Fairphone by Kwamecorp.

the class WidgetProvider method getMostUsedView.

private RemoteViews getMostUsedView(Context context, ApplicationRunInformation info, int code) throws NameNotFoundException {
    // generate the mostUsed row
    RemoteViews mostUsedRow = new RemoteViews(context.getPackageName(), R.layout.fp_most_used_item);
    PackageManager pm = context.getPackageManager();
    // get app icon and label
    Drawable icon = pm.getActivityIcon(info.getComponentName());
    Bitmap iconBitmap = ((BitmapDrawable) icon).getBitmap();
    CharSequence appLabel = pm.getActivityInfo(info.getComponentName(), 0).loadLabel(pm);
    // debug String with app count
    String fullAppLabel = info.getCount() + "# " + appLabel;
    mostUsedRow.setImageViewBitmap(android.R.id.content, iconBitmap);
    mostUsedRow.setTextViewText(R.id.mostUsedButton, APP_SWITCHER_DEBUG_MODE ? fullAppLabel : appLabel);
    Intent launchIntent = generateLaunchIntent(info, appLabel.toString());
    PendingIntent clickRecentApps = PendingIntent.getBroadcast(context, code, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mostUsedRow.setOnClickPendingIntent(R.id.mostUsedButton, clickRecentApps);
    return mostUsedRow;
}
Also used : RemoteViews(android.widget.RemoteViews) Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PendingIntent(android.app.PendingIntent)

Example 43 with RemoteViews

use of android.widget.RemoteViews in project Fairphone by Kwamecorp.

the class WidgetProvider method updateUI.

private void updateUI(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    loadCurrentStats(context);
    // get the widgets
    RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget);
    if (mCurrentStats.mIsOnPeaceOfMind) {
        updateWidgetForPeaceOfMind(context, widget);
    } else {
        updateWidgetForOffPeaceOfMind(context, widget);
    }
    // set the the app link
    Intent intent = new Intent(context, org.fairphone.peaceofmind.PeaceOfMindActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
    widget.setOnClickPendingIntent(R.id.peaceOfMindWidgetLayout, pendingIntent);
    appWidgetManager.updateAppWidget(appWidgetId, widget);
}
Also used : RemoteViews(android.widget.RemoteViews) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 44 with RemoteViews

use of android.widget.RemoteViews in project MWM-for-Android-Gen1 by MetaWatchOpenProjects.

the class MetaWatchService method createNotification.

public void createNotification() {
    notification = new android.app.Notification(R.drawable.disconnected_large, null, System.currentTimeMillis());
    notification.flags |= android.app.Notification.FLAG_ONGOING_EVENT;
    remoteViews = new RemoteViews(getPackageName(), R.layout.notification);
    remoteViews.setImageViewResource(R.id.image, R.drawable.disconnected);
    remoteViews.setTextViewText(R.id.text, "MetaWatch service is running");
    notification.contentView = remoteViews;
    Intent notificationIntent = new Intent(this, MetaWatch.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.contentIntent = contentIntent;
    startForeground(1, notification);
}
Also used : RemoteViews(android.widget.RemoteViews) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 45 with RemoteViews

use of android.widget.RemoteViews in project Notes by MiCode.

the class NoteWidgetProvider method update.

private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, boolean privacyMode) {
    for (int i = 0; i < appWidgetIds.length; i++) {
        if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
            int bgId = ResourceParser.getDefaultBgId(context);
            String snippet = "";
            Intent intent = new Intent(context, NoteEditActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            intent.putExtra(Notes.INTENT_EXTRA_WIDGET_ID, appWidgetIds[i]);
            intent.putExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, getWidgetType());
            Cursor c = getNoteWidgetInfo(context, appWidgetIds[i]);
            if (c != null && c.moveToFirst()) {
                if (c.getCount() > 1) {
                    Log.e(TAG, "Multiple message with same widget id:" + appWidgetIds[i]);
                    c.close();
                    return;
                }
                snippet = c.getString(COLUMN_SNIPPET);
                bgId = c.getInt(COLUMN_BG_COLOR_ID);
                intent.putExtra(Intent.EXTRA_UID, c.getLong(COLUMN_ID));
                intent.setAction(Intent.ACTION_VIEW);
            } else {
                snippet = context.getResources().getString(R.string.widget_havenot_content);
                intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
            }
            if (c != null) {
                c.close();
            }
            RemoteViews rv = new RemoteViews(context.getPackageName(), getLayoutId());
            rv.setImageViewResource(R.id.widget_bg_image, getBgResourceId(bgId));
            intent.putExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, bgId);
            /**
                 * Generate the pending intent to start host for the widget
                 */
            PendingIntent pendingIntent = null;
            if (privacyMode) {
                rv.setTextViewText(R.id.widget_text, context.getString(R.string.widget_under_visit_mode));
                pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], new Intent(context, NotesListActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
            } else {
                rv.setTextViewText(R.id.widget_text, snippet);
                pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent, PendingIntent.FLAG_UPDATE_CURRENT);
            }
            rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent);
            appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
        }
    }
}
Also used : RemoteViews(android.widget.RemoteViews) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Cursor(android.database.Cursor)

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