use of android.widget.RemoteViews in project k-9 by k9mail.
the class UnreadWidgetProvider method updateWidget.
public static void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, String accountUuid) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.unread_widget_layout);
int unreadCount = 0;
String accountName = context.getString(R.string.app_name);
Intent clickIntent = null;
try {
BaseAccount account = null;
AccountStats stats = null;
SearchAccount searchAccount = null;
if (SearchAccount.UNIFIED_INBOX.equals(accountUuid)) {
searchAccount = SearchAccount.createUnifiedInboxAccount(context);
} else if (SearchAccount.ALL_MESSAGES.equals(accountUuid)) {
searchAccount = SearchAccount.createAllMessagesAccount(context);
}
if (searchAccount != null) {
account = searchAccount;
MessagingController controller = MessagingController.getInstance(context);
stats = controller.getSearchAccountStatsSynchronous(searchAccount, null);
clickIntent = MessageList.intentDisplaySearch(context, searchAccount.getRelatedSearch(), false, true, true);
} else {
Account realAccount = Preferences.getPreferences(context).getAccount(accountUuid);
if (realAccount != null) {
account = realAccount;
stats = realAccount.getStats(context);
if (K9.FOLDER_NONE.equals(realAccount.getAutoExpandFolderName())) {
clickIntent = FolderList.actionHandleAccountIntent(context, realAccount, false);
} else {
LocalSearch search = new LocalSearch(realAccount.getAutoExpandFolderName());
search.addAllowedFolder(realAccount.getAutoExpandFolderName());
search.addAccountUuid(account.getUuid());
clickIntent = MessageList.intentDisplaySearch(context, search, false, true, true);
}
clickIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
}
}
if (account != null) {
accountName = account.getDescription();
}
if (stats != null) {
unreadCount = stats.unreadMessageCount;
}
} catch (Exception e) {
Timber.e(e, "Error getting widget configuration");
}
if (unreadCount <= 0) {
// Hide TextView for unread count if there are no unread messages.
remoteViews.setViewVisibility(R.id.unread_count, View.GONE);
} else {
remoteViews.setViewVisibility(R.id.unread_count, View.VISIBLE);
String displayCount = (unreadCount <= MAX_COUNT) ? String.valueOf(unreadCount) : String.valueOf(MAX_COUNT) + "+";
remoteViews.setTextViewText(R.id.unread_count, displayCount);
}
remoteViews.setTextViewText(R.id.account_name, accountName);
if (clickIntent == null) {
// If the widget configuration couldn't be loaded we open the configuration
// activity when the user clicks the widget.
clickIntent = new Intent(context, UnreadWidgetConfiguration.class);
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
}
clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0);
remoteViews.setOnClickPendingIntent(R.id.unread_widget_layout, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, 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;
}
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);
}
use of android.widget.RemoteViews in project mobile-android by photo.
the class AbstractUploaderService method showUploadNotification.
private Notification showUploadNotification(File file) {
int icon = getNotificationIcon();
CharSequence tickerText = getString(R.string.notification_uploading_photo, file.getName());
long when = System.currentTimeMillis();
CharSequence contentMessageTitle = getString(R.string.notification_uploading_photo, file.getName());
PendingIntent contentIntent = getStandardPendingIntent();
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_upload);
contentView.setImageViewResource(R.id.image, icon);
contentView.setTextViewText(R.id.title, contentMessageTitle);
contentView.setProgressBar(R.id.progress, 100, 0, true);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
if (contentIntent != null) {
builder.setContentIntent(contentIntent);
}
Notification notification = builder.setTicker(tickerText).setWhen(when).setSmallIcon(icon).setContent(contentView).build();
CommonUtils.debug(TAG, "Is notification content view null: " + (notification.contentView == null));
// need to explicitly set contentView again because of bug in compat
// library. Solution found here
// http://stackoverflow.com/a/12574534/527759
notification.contentView = contentView;
mNotificationManager.notify(NOTIFICATION_UPLOAD_PROGRESS, notification);
return notification;
}
use of android.widget.RemoteViews in project JamsMusicPlayer by psaravan.
the class AsyncUpdateLargeWidgetTask method doInBackground.
@SuppressLint("NewApi")
@Override
protected Boolean doInBackground(String... params) {
//Perform this loop procedure for each App Widget that belongs to this mApp
for (int i = 0; i < mNumWidgets; i++) {
currentAppWidgetId = mAppWidgetIds[i];
String widgetColor = mApp.getSharedPreferences().getString("" + currentAppWidgetId, "DARK");
//Initialize the RemoteView object to gain access to the widget's UI elements.
views = new RemoteViews(mContext.getPackageName(), R.layout.large_widget_layout);
if (widgetColor.equals("DARK")) {
views.setInt(R.id.large_widget_parent_layout, "setBackgroundResource", R.drawable.appwidget_dark_bg);
views.setImageViewResource(R.id.widget_play, R.drawable.btn_playback_play_light);
views.setImageViewResource(R.id.widget_previous_track, R.drawable.btn_playback_previous_light);
views.setImageViewResource(R.id.widget_next_track, R.drawable.btn_playback_next_light);
} else if (widgetColor.equals("LIGHT")) {
views.setInt(R.id.large_widget_parent_layout, "setBackgroundResource", R.drawable.appwidget_bg);
views.setImageViewResource(R.id.widget_play, R.drawable.btn_playback_play);
views.setImageViewResource(R.id.widget_previous_track, R.drawable.btn_playback_previous);
views.setImageViewResource(R.id.widget_next_track, R.drawable.btn_playback_next);
}
/* Create a pendingIntent that will serve as a general template for the clickListener.
* We'll create a fillInIntent in LargeWidgetAdapterService.java that will provide the
* index of the listview item that's been clicked. */
Intent intent = new Intent();
intent.setAction("com.jams.music.player.WIDGET_CHANGE_TRACK");
PendingIntent pendingIntentTemplate = PendingIntent.getBroadcast(mContext, 0, intent, 0);
views.setPendingIntentTemplate(R.id.widget_listview, pendingIntentTemplate);
//Create the intent to fire up the service that will back the adapter of the listview.
Intent serviceIntent = new Intent(mContext, LargeWidgetAdapterService.class);
serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetIds[i]);
serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
serviceIntent.putExtra("WIDGET_COLOR", widgetColor);
views.setRemoteAdapter(R.id.widget_listview, serviceIntent);
mAppWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetIds, R.id.widget_listview);
//Check if the service is running and update the widget elements.
if (mApp.isServiceRunning()) {
//Set the album art.
views.setViewVisibility(R.id.widget_listview, View.VISIBLE);
views.setImageViewBitmap(R.id.widget_album_art, getAlbumArt());
final Intent notificationIntent = new Intent(mContext, NowPlayingActivity.class);
notificationIntent.putExtra("CALLED_FROM_FOOTER", true);
notificationIntent.putExtra("CALLED_FROM_NOTIF", true);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0);
views.setOnClickPendingIntent(R.id.widget_album_art, pendingIntent);
} else {
songTitle = "";
albumName = mContext.getResources().getString(R.string.no_music_playing);
//Set the default album art.
views.setImageViewResource(R.id.widget_album_art, R.drawable.default_album_art);
views.setViewVisibility(R.id.widget_listview, View.INVISIBLE);
if (widgetColor.equals("DARK")) {
views.setImageViewResource(R.id.app_widget_small_play, R.drawable.btn_playback_play_light);
} else if (widgetColor.equals("LIGHT")) {
views.setImageViewResource(R.id.app_widget_small_play, R.drawable.btn_playback_play);
}
final Intent notificationIntent = new Intent(mContext, LauncherActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0);
views.setOnClickPendingIntent(R.id.widget_album_art, pendingIntent);
}
//Set the song title, artist name, and album name.
views.setTextViewText(R.id.widget_song_title_text, songTitle);
views.setTextViewText(R.id.widget_album_text, albumName);
views.setTextViewText(R.id.widget_artist_text, artistName);
if (widgetColor.equals("LIGHT")) {
views.setTextColor(R.id.widget_song_title_text, Color.BLACK);
views.setTextColor(R.id.widget_album_text, Color.BLACK);
views.setTextColor(R.id.widget_artist_text, Color.BLACK);
}
//Attach PendingIntents to the widget controls.
Intent previousTrackIntent = new Intent();
previousTrackIntent.setAction(PREVIOUS_ACTION);
PendingIntent previousPendingIntent = PendingIntent.getBroadcast(mContext, 0, previousTrackIntent, 0);
Intent playPauseTrackIntent = new Intent();
playPauseTrackIntent.setAction(PLAY_PAUSE_ACTION);
PendingIntent playPausePendingIntent = PendingIntent.getBroadcast(mContext, 0, playPauseTrackIntent, 0);
Intent nextTrackIntent = new Intent();
nextTrackIntent.setAction(NEXT_ACTION);
PendingIntent nextPendingIntent = PendingIntent.getBroadcast(mContext, 0, nextTrackIntent, 0);
//Set the pending intents on the buttons.
views.setOnClickPendingIntent(R.id.widget_play, playPausePendingIntent);
views.setOnClickPendingIntent(R.id.widget_previous_track, previousPendingIntent);
views.setOnClickPendingIntent(R.id.widget_next_track, nextPendingIntent);
if (mApp.isServiceRunning()) {
try {
if (mApp.getService().getCurrentMediaPlayer().isPlaying()) {
if (widgetColor.equals("DARK")) {
views.setImageViewResource(R.id.widget_play, R.drawable.btn_playback_pause_light);
} else if (widgetColor.equals("LIGHT")) {
views.setImageViewResource(R.id.widget_play, R.drawable.btn_playback_pause);
}
} else {
if (widgetColor.equals("DARK")) {
views.setImageViewResource(R.id.widget_play, R.drawable.btn_playback_play_light);
} else if (widgetColor.equals("LIGHT")) {
views.setImageViewResource(R.id.widget_play, R.drawable.btn_playback_play);
}
}
} catch (Exception e) {
// TODO Auto-generated method stub
e.printStackTrace();
}
}
//Tell the AppWidgetManager to perform an update on the current app widget.
try {
mAppWidgetManager.updateAppWidget(currentAppWidgetId, views);
} catch (Exception e) {
continue;
}
}
return true;
}
Aggregations