List of usage examples for android.widget RemoteViews setViewVisibility
public void setViewVisibility(int viewId, int visibility)
From source file:android.support.v7.app.NotificationCompatImplBase.java
private static RemoteViews applyStandardTemplate(Context context, CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo, int number, Bitmap largeIcon, CharSequence subText, boolean useChronometer, long when, int resId, boolean fitIn1U) { RemoteViews contentView = new RemoteViews(context.getPackageName(), resId); boolean showLine3 = false; boolean showLine2 = false; // On versions before Jellybean, the large icon was shown by SystemUI, so we need to hide // it here./*from ww w . j a va 2 s . co m*/ if (largeIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { contentView.setViewVisibility(R.id.icon, View.VISIBLE); contentView.setImageViewBitmap(R.id.icon, largeIcon); } else { contentView.setViewVisibility(R.id.icon, View.GONE); } if (contentTitle != null) { contentView.setTextViewText(R.id.title, contentTitle); } if (contentText != null) { contentView.setTextViewText(R.id.text, contentText); showLine3 = true; } if (contentInfo != null) { contentView.setTextViewText(R.id.info, contentInfo); contentView.setViewVisibility(R.id.info, View.VISIBLE); showLine3 = true; } else if (number > 0) { final int tooBig = context.getResources().getInteger(R.integer.status_bar_notification_info_maxnum); if (number > tooBig) { contentView.setTextViewText(R.id.info, context.getResources().getString(R.string.status_bar_notification_info_overflow)); } else { NumberFormat f = NumberFormat.getIntegerInstance(); contentView.setTextViewText(R.id.info, f.format(number)); } contentView.setViewVisibility(R.id.info, View.VISIBLE); showLine3 = true; } else { contentView.setViewVisibility(R.id.info, View.GONE); } // Need to show three lines? Only allow on Jellybean+ if (subText != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { contentView.setTextViewText(R.id.text, subText); if (contentText != null) { contentView.setTextViewText(R.id.text2, contentText); contentView.setViewVisibility(R.id.text2, View.VISIBLE); showLine2 = true; } else { contentView.setViewVisibility(R.id.text2, View.GONE); } } // RemoteViews.setViewPadding and RemoteViews.setTextViewTextSize is not available on ICS- if (showLine2 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (fitIn1U) { // need to shrink all the type to make sure everything fits final Resources res = context.getResources(); final float subTextSize = res.getDimensionPixelSize(R.dimen.notification_subtext_size); contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize); } // vertical centering contentView.setViewPadding(R.id.line1, 0, 0, 0, 0); } if (when != 0) { if (useChronometer) { contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); contentView.setLong(R.id.chronometer, "setBase", when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); contentView.setBoolean(R.id.chronometer, "setStarted", true); } else { contentView.setViewVisibility(R.id.time, View.VISIBLE); contentView.setLong(R.id.time, "setTime", when); } } contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE); return contentView; }
From source file:android.support.v7.app.NotificationCompatImplBase.java
private static <T extends NotificationCompatBase.Action> RemoteViews generateBigContentView(Context context, CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo, int number, Bitmap largeIcon, CharSequence subText, boolean useChronometer, long when, List<T> actions, boolean showCancelButton, PendingIntent cancelButtonIntent) { final int actionCount = Math.min(actions.size(), MAX_MEDIA_BUTTONS); RemoteViews big = applyStandardTemplate(context, contentTitle, contentText, contentInfo, number, largeIcon, subText, useChronometer, when, getBigLayoutResource(actionCount), false /* fitIn1U */); big.removeAllViews(R.id.media_actions); if (actionCount > 0) { for (int i = 0; i < actionCount; i++) { final RemoteViews button = generateMediaActionButton(context, actions.get(i)); big.addView(R.id.media_actions, button); }//from w w w. j a va 2 s . c om } if (showCancelButton) { big.setViewVisibility(R.id.cancel_action, View.VISIBLE); big.setInt(R.id.cancel_action, "setAlpha", context.getResources().getInteger(R.integer.cancel_button_image_alpha)); big.setOnClickPendingIntent(R.id.cancel_action, cancelButtonIntent); } else { big.setViewVisibility(R.id.cancel_action, View.GONE); } return big; }
From source file:com.android.mail.widget.WidgetService.java
/** * Modifies the remoteView for the given account and folder. *///from w ww . j a va2 s .c o m public static void configureValidAccountWidget(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final int folderCapabilities, final Uri folderUri, final Uri folderConversationListUri, String folderDisplayName, Class<?> widgetService) { remoteViews.setViewVisibility(R.id.widget_folder, View.VISIBLE); // If the folder or account name are empty, we don't want to overwrite the valid data that // had been saved previously. Since the launcher will save the state of the remote views // we should rely on the fact that valid data has been saved. But we should still log this, // as it shouldn't happen if (TextUtils.isEmpty(folderDisplayName) || TextUtils.isEmpty(account.getDisplayName())) { LogUtils.e(LOG_TAG, new Error(), "Empty folder or account name. account: %s, folder: %s", account.getEmailAddress(), folderDisplayName); } if (!TextUtils.isEmpty(folderDisplayName)) { remoteViews.setTextViewText(R.id.widget_folder, folderDisplayName); } remoteViews.setViewVisibility(R.id.widget_compose, View.VISIBLE); remoteViews.setViewVisibility(R.id.conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.empty_conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.widget_folder_not_synced, View.GONE); remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); remoteViews.setEmptyView(R.id.conversation_list, R.id.empty_conversation_list); WidgetService.configureValidWidgetIntents(context, remoteViews, appWidgetId, account, folderType, folderCapabilities, folderUri, folderConversationListUri, folderDisplayName, widgetService); }
From source file:com.chen.mail.widget.WidgetService.java
/** * Modifies the remoteView for the given account and folder. */// ww w . j av a 2 s . c o m public static void configureValidAccountWidget(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final Uri folderUri, final Uri folderConversationListUri, String folderDisplayName, Class<?> widgetService) { remoteViews.setViewVisibility(R.id.widget_folder, View.VISIBLE); // If the folder or account name are empty, we don't want to overwrite the valid data that // had been saved previously. Since the launcher will save the state of the remote views // we should rely on the fact that valid data has been saved. But we should still log this, // as it shouldn't happen if (TextUtils.isEmpty(folderDisplayName) || TextUtils.isEmpty(account.name)) { LogUtils.e(LOG_TAG, new Error(), "Empty folder or account name. account: %s, folder: %s", account.name, folderDisplayName); } if (!TextUtils.isEmpty(folderDisplayName)) { remoteViews.setTextViewText(R.id.widget_folder, folderDisplayName); } remoteViews.setViewVisibility(R.id.widget_account_noflip, View.VISIBLE); if (!TextUtils.isEmpty(account.name)) { remoteViews.setTextViewText(R.id.widget_account_noflip, account.name); remoteViews.setTextViewText(R.id.widget_account, account.name); } remoteViews.setViewVisibility(R.id.widget_account_unread_flipper, View.GONE); remoteViews.setViewVisibility(R.id.widget_compose, View.VISIBLE); remoteViews.setViewVisibility(R.id.conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.empty_conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.widget_folder_not_synced, View.GONE); remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); remoteViews.setEmptyView(R.id.conversation_list, R.id.empty_conversation_list); WidgetService.configureValidWidgetIntents(context, remoteViews, appWidgetId, account, folderType, folderUri, folderConversationListUri, folderDisplayName, widgetService); }
From source file:com.android.mail.widget.WidgetService.java
public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final int folderCapabilities, final Uri folderUri, final Uri folderConversationListUri, final String folderDisplayName, Class<?> serviceClass) { remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); // Launch an intent to avoid ANRs final Intent intent = new Intent(context, serviceClass); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize()); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_TYPE, folderType); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CAPABILITIES, folderCapabilities); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_URI, folderUri); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CONVERSATION_LIST_URI, folderConversationListUri); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_DISPLAY_NAME, folderDisplayName); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(R.id.conversation_list, intent); // Open mail app when click on header final Intent mailIntent = Utils.createViewFolderIntent(context, folderUri, account); mailIntent.setPackage(context.getPackageName()); PendingIntent clickIntent = PendingIntent.getActivity(context, 0, mailIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent); // On click intent for Compose final Intent composeIntent = new Intent(); composeIntent.setPackage(context.getPackageName()); composeIntent.setAction(Intent.ACTION_SEND); composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize()); composeIntent.setData(account.composeIntentUri); composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true); if (account.composeIntentUri != null) { composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri); }/*w w w. ja v a 2s . c o m*/ // Build a task stack that forces the conversation list on the stack before the compose // activity. final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); clickIntent = taskStackBuilder.addNextIntent(mailIntent).addNextIntent(composeIntent).getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent); // On click intent for Conversation final Intent conversationIntent = new Intent(); conversationIntent.setPackage(context.getPackageName()); conversationIntent.setAction(Intent.ACTION_VIEW); clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent); }
From source file:com.chen.mail.widget.WidgetService.java
public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final Uri folderUri, final Uri folderConversationListUri, final String folderDisplayName, Class<?> serviceClass) { remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); // Launch an intent to avoid ANRs final Intent intent = new Intent(context, serviceClass); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize()); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_TYPE, folderType); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_URI, folderUri); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CONVERSATION_LIST_URI, folderConversationListUri); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_DISPLAY_NAME, folderDisplayName); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(R.id.conversation_list, intent); // Open mail app when click on header final Intent mailIntent = Utils.createViewFolderIntent(context, folderUri, account); PendingIntent clickIntent = PendingIntent.getActivity(context, 0, mailIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent); // On click intent for Compose final Intent composeIntent = new Intent(); composeIntent.setAction(Intent.ACTION_SEND); composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize()); composeIntent.setData(account.composeIntentUri); composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true); if (account.composeIntentUri != null) { composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri); }/*from w w w . j a v a2 s. com*/ // Build a task stack that forces the conversation list on the stack before the compose // activity. final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); clickIntent = taskStackBuilder.addNextIntent(mailIntent).addNextIntent(composeIntent).getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent); // On click intent for Conversation final Intent conversationIntent = new Intent(); conversationIntent.setAction(Intent.ACTION_VIEW); clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent); }
From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java
/** * Updates moving time.//from ww w.j a v a2 s. c om * * @param context the context * @param remoteViews the remote views * @param ids the item's ids * @param tripStatistics the trip statistics */ private static void updateMovingTime(Context context, RemoteViews remoteViews, int[] ids, TripStatistics tripStatistics) { String movingTime = tripStatistics == null ? context.getString(R.string.value_unknown) : StringUtils.formatElapsedTime(tripStatistics.getMovingTime()); remoteViews.setTextViewText(ids[0], context.getString(R.string.stats_moving_time)); remoteViews.setTextViewText(ids[1], movingTime); remoteViews.setViewVisibility(ids[2], View.GONE); }
From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java
/** * Updates total time./*from w w w . j a va2s.co m*/ * * @param context the context * @param remoteViews the remote views * @param ids the item's ids * @param tripStatistics the trip statistics */ private static void updateTotalTime(Context context, RemoteViews remoteViews, int[] ids, TripStatistics tripStatistics, boolean isRecording, boolean isPaused) { if (isRecording && !isPaused && tripStatistics != null) { long time = tripStatistics.getTotalTime() + System.currentTimeMillis() - tripStatistics.getStopTime(); remoteViews.setChronometer(ids[3], SystemClock.elapsedRealtime() - time, null, true); remoteViews.setViewVisibility(ids[1], View.GONE); remoteViews.setViewVisibility(ids[2], View.GONE); remoteViews.setViewVisibility(ids[3], View.VISIBLE); } else { remoteViews.setChronometer(ids[3], SystemClock.elapsedRealtime(), null, false); remoteViews.setViewVisibility(ids[1], View.VISIBLE); remoteViews.setViewVisibility(ids[2], View.GONE); remoteViews.setViewVisibility(ids[3], View.GONE); String totalTime = tripStatistics == null ? context.getString(R.string.value_unknown) : StringUtils.formatElapsedTime(tripStatistics.getTotalTime()); remoteViews.setTextViewText(ids[0], context.getString(R.string.stats_total_time)); remoteViews.setTextViewText(ids[1], totalTime); } }
From source file:com.tct.mail.widget.WidgetService.java
/** * Modifies the remoteView for the given account and folder. *//* w ww . j a v a 2 s . c o m*/ public static void configureValidAccountWidget(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final int folderCapabilities, final Uri folderUri, final Uri folderConversationListUri, String folderDisplayName, Class<?> widgetService) { remoteViews.setViewVisibility(R.id.widget_folder, View.VISIBLE); // If the folder or account name are empty, we don't want to overwrite the valid data that // had been saved previously. Since the launcher will save the state of the remote views // we should rely on the fact that valid data has been saved. But we should still log this, // as it shouldn't happen if (TextUtils.isEmpty(folderDisplayName) || TextUtils.isEmpty(account.getDisplayName())) { LogUtils.e(LOG_TAG, new Error(), "Empty folder or account name. account: %s, folder: %s", account.getEmailAddress(), folderDisplayName); } if (!TextUtils.isEmpty(folderDisplayName)) { remoteViews.setTextViewText(R.id.widget_folder, folderDisplayName); } //TS: junwei-xu 2014-12-23 EMAIL BUGFIX_850975 ADD_S remoteViews.setViewVisibility(R.id.widget_account_noflip, View.VISIBLE); if (!TextUtils.isEmpty(account.getEmailAddress())) { remoteViews.setTextViewText(R.id.widget_account_noflip, account.getEmailAddress()); remoteViews.setTextViewText(R.id.widget_account, account.getEmailAddress()); } remoteViews.setViewVisibility(R.id.widget_account_unread_flipper, View.GONE); //TS: junwei-xu 2014-12-23 EMAIL BUGFIX_850975 ADD_E remoteViews.setViewVisibility(R.id.widget_compose, View.VISIBLE); remoteViews.setViewVisibility(R.id.conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.empty_conversation_list, View.GONE); //TS: zheng.zou 2015-08-11 EMAIL BUGFIX_1044483 MOD remoteViews.setViewVisibility(R.id.widget_folder_not_synced, View.GONE); remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); // remoteViews.setEmptyView(R.id.conversation_list, R.id.empty_conversation_list); //TS: zheng.zou 2015-08-11 EMAIL BUGFIX_1044483 DEL WidgetService.configureValidWidgetIntents(context, remoteViews, appWidgetId, account, folderType, folderCapabilities, folderUri, folderConversationListUri, folderDisplayName, widgetService); }
From source file:com.tct.mail.widget.WidgetService.java
public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final int folderCapabilities, final Uri folderUri, final Uri folderConversationListUri, final String folderDisplayName, Class<?> serviceClass) { remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); // Launch an intent to avoid ANRs final Intent intent = new Intent(context, serviceClass); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize()); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_TYPE, folderType); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CAPABILITIES, folderCapabilities); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_URI, folderUri); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CONVERSATION_LIST_URI, folderConversationListUri); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_DISPLAY_NAME, folderDisplayName); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(R.id.conversation_list, intent); remoteViews.setEmptyView(R.id.conversation_list, R.id.empty_conversation_list); //TS: zheng.zou 2015-08-11 EMAIL BUGFIX_1044483 ADD // Open mail app when click on header final Intent mailIntent = Utils.createViewFolderIntent(context, folderUri, account); PendingIntent clickIntent = PendingIntent.getActivity(context, 0, mailIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent); // On click intent for Compose final Intent composeIntent = new Intent(); composeIntent.setAction(Intent.ACTION_SEND); //TS: jian.xu 2015-4-24 EMAIL BUGFIX_984619 ADD_S composeIntent.setPackage(context.getPackageName()); //TS: jian.xu 2015-4-24 EMAIL BUGFIX_984619 ADD_E composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize()); composeIntent.setData(account.composeIntentUri); composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true); composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_WIDGET, true); //TS: zheng.zou 2015-12-09 EMAIL BUGFIX_1059178 ADD if (account.composeIntentUri != null) { composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri); }/*from w ww . j ava 2 s . c o m*/ // Build a task stack that forces the conversation list on the stack before the compose // activity. final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); clickIntent = taskStackBuilder.addNextIntent(mailIntent).addNextIntent(composeIntent).getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent); // On click intent for Conversation final Intent conversationIntent = new Intent(); conversationIntent.setAction(Intent.ACTION_VIEW); clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent); }