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;
}
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;
}
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);
}
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);
}
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);
}
}
}
Aggregations