本文整理汇总了Java中android.widget.RemoteViews.addView方法的典型用法代码示例。如果您正苦于以下问题:Java RemoteViews.addView方法的具体用法?Java RemoteViews.addView怎么用?Java RemoteViews.addView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.RemoteViews
的用法示例。
在下文中一共展示了RemoteViews.addView方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateBigContentView
import android.widget.RemoteViews; //导入方法依赖的package包/类
private static <T extends 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) {
int actionCount = Math.min(actions.size(), 5);
RemoteViews big = applyStandardTemplate(context, contentTitle, contentText, contentInfo, number, largeIcon, subText, useChronometer, when, getBigLayoutResource(actionCount), false);
big.removeAllViews(R.id.media_actions);
if (actionCount > 0) {
for (int i = 0; i < actionCount; i++) {
big.addView(R.id.media_actions, generateMediaActionButton(context, (Action) actions.get(i)));
}
}
if (showCancelButton) {
big.setViewVisibility(R.id.cancel_action, 0);
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, 8);
}
return big;
}
示例2: updateAppWidget
import android.widget.RemoteViews; //导入方法依赖的package包/类
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
Recipe recipe, int appWidgetId) {
Intent intent = RecipeDetailActivity.newIntent(context, recipe);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.recipe_widget);
views.removeAllViews(R.id.ll_recipe_widget_ingredient_list);
views.setTextViewText(R.id.recipe_widget_title, recipe.getName());
views.setOnClickPendingIntent(R.id.recipe_widget_holder, pendingIntent);
for(Ingredient ingredient : recipe.getIngredients()) {
RemoteViews rvIngredient = new RemoteViews(context.getPackageName(),
R.layout.recipe_widget_list_item);
rvIngredient.setTextViewText(R.id.tv_recipe_widget_ingredient_item,
String.valueOf(ingredient.getQuantity()) +
String.valueOf(ingredient.getMeasure()) + " " + ingredient.getIngredient());
views.addView(R.id.ll_recipe_widget_ingredient_list, rvIngredient);
}
appWidgetManager.updateAppWidget(appWidgetId, views);
}
示例3: generateContentView
import android.widget.RemoteViews; //导入方法依赖的package包/类
private static <T extends Action> RemoteViews generateContentView(Context context, CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo, int number, Bitmap largeIcon, CharSequence subText, boolean useChronometer, long when, List<T> actions, int[] actionsToShowInCompact, boolean showCancelButton, PendingIntent cancelButtonIntent) {
int N;
RemoteViews view = applyStandardTemplate(context, contentTitle, contentText, contentInfo, number, largeIcon, subText, useChronometer, when, R.layout.notification_template_media, true);
int numActions = actions.size();
if (actionsToShowInCompact == null) {
N = 0;
} else {
N = Math.min(actionsToShowInCompact.length, 3);
}
view.removeAllViews(R.id.media_actions);
if (N > 0) {
for (int i = 0; i < N; i++) {
if (i >= numActions) {
throw new IllegalArgumentException(String.format("setShowActionsInCompactView: action %d out of bounds (max %d)", new Object[]{Integer.valueOf(i), Integer.valueOf(numActions - 1)}));
}
Context context2 = context;
RemoteViews button = generateMediaActionButton(context2, (Action) actions.get(actionsToShowInCompact[i]));
view.addView(R.id.media_actions, button);
}
}
if (showCancelButton) {
view.setViewVisibility(R.id.end_padder, 8);
view.setViewVisibility(R.id.cancel_action, 0);
view.setOnClickPendingIntent(R.id.cancel_action, cancelButtonIntent);
view.setInt(R.id.cancel_action, "setAlpha", context.getResources().getInteger(R.integer.cancel_button_image_alpha));
} else {
view.setViewVisibility(R.id.end_padder, 0);
view.setViewVisibility(R.id.cancel_action, 8);
}
return view;
}
示例4: onReceive
import android.widget.RemoteViews; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getBooleanExtra(ArcadeCommon.STATUS_RESET_SCORE, false)) {
score = 0;
} else {
score += intent.getIntExtra(ArcadeCommon.STATUS_INCREMENT_SCORE, 0);
}
RemoteViews notifViews = new RemoteViews(context.getPackageName(),
R.layout.status_notification);
notifViews.setTextViewText(R.id.title, getString(titleResID));
notifViews.setImageViewResource(R.id.notif_icon, notifIconResID);
NotificationManager notifMgr =
(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
notifViews.setTextViewText(R.id.score, getString(R.string.score, score));
int newLevel = intent.getIntExtra(ArcadeCommon.STATUS_LEVEL, level);
if (newLevel != level) {
setLevel(newLevel);
}
if (level >= 0) {
notifViews.setTextViewText(R.id.level, getString(R.string.level, level));
}
setLives(intent.getIntExtra(ArcadeCommon.STATUS_LIVES, lives));
if (previewActive) {
return;
}
notifViews.removeAllViews(R.id.lives_area);
if (lives < 0) {
// Game over, man
RemoteViews gameOver = new RemoteViews(getPackageName(), R.layout.status_text);
gameOver.setTextViewText(R.id.status_text, "Game Over");
notifViews.addView(R.id.lives_area, gameOver);
if (!isPaused) {
onPause();
}
} else {
Bitmap lifeBitmap = BitmapFactory.decodeResource(getResources(), lifeIconResId);
for (int i = 0; i < lives; i++) {
RemoteViews thisLife = new RemoteViews(getPackageName(), R.layout.status_life_icon);
thisLife.setBitmap(R.id.life_icon, "setImageBitmap", lifeBitmap);
notifViews.addView(R.id.lives_area, thisLife);
}
}
Bitmap pauseBtn = BitmapFactory.decodeResource(getResources(),
isPaused || (readyTime > 0)
? R.drawable.ic_play_circle_outline_white_48dp
: R.drawable.ic_pause_circle_outline_white_48dp);
notifViews.setBitmap(R.id.play_pause, "setImageBitmap", pauseBtn);
notifViews.setOnClickPendingIntent(R.id.play_pause,
PendingIntent.getBroadcast(context, 0,
new Intent(ArcadeCommon.ACTION_PAUSE), 0));
final NotificationCompat.Builder notif = new NotificationCompat.Builder(context)
.setSmallIcon(notifIconResID)
.setContent(notifViews)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVisibility(VISIBILITY_SECRET); // keep the scroreboard off the lock screen
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// This forces a heads-up notification
notif.setVibrate(new long[0]);
}
notifMgr.notify(0, notif.build());
}
示例5: addActionButtons
import android.widget.RemoteViews; //导入方法依赖的package包/类
/**
* If there are actions, shows the button related views, and adds a button for each action.
*/
private void addActionButtons(RemoteViews bigView) {
// Remove the existing buttons in case an existing notification is being updated.
bigView.removeAllViews(R.id.buttons);
// Always set the visibility of the views associated with the action buttons. The current
// visibility state is not known as perhaps an existing notification is being updated.
int visibility = mActions.isEmpty() ? View.GONE : View.VISIBLE;
bigView.setViewVisibility(R.id.button_divider, visibility);
bigView.setViewVisibility(R.id.buttons, visibility);
Resources resources = mContext.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
for (Action action : mActions) {
RemoteViews view =
new RemoteViews(mContext.getPackageName(), R.layout.web_notification_button);
// If there is an icon then set it and add some padding.
if (action.iconBitmap != null || action.iconId != 0) {
if (useMaterial()) {
view.setInt(R.id.button_icon, "setColorFilter", BUTTON_ICON_COLOR_MATERIAL);
}
int iconWidth = 0;
if (action.iconBitmap != null) {
view.setImageViewBitmap(R.id.button_icon, action.iconBitmap);
iconWidth = action.iconBitmap.getWidth();
} else if (action.iconId != 0) {
view.setImageViewResource(R.id.button_icon, action.iconId);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(resources, action.iconId, options);
iconWidth = options.outWidth;
}
iconWidth = dpToPx(
Math.min(pxToDp(iconWidth, metrics), MAX_ACTION_ICON_WIDTH_DP), metrics);
// Set the padding of the button so the text does not overlap with the icon. Flip
// between left and right manually as RemoteViews does not expose a method that sets
// padding in a writing-direction independent way.
int buttonPadding =
dpToPx(BUTTON_PADDING_START_DP + BUTTON_ICON_PADDING_DP, metrics)
+ iconWidth;
int buttonPaddingLeft = LocalizationUtils.isLayoutRtl() ? 0 : buttonPadding;
int buttonPaddingRight = LocalizationUtils.isLayoutRtl() ? buttonPadding : 0;
view.setViewPadding(R.id.button, buttonPaddingLeft, 0, buttonPaddingRight, 0);
}
view.setTextViewText(R.id.button, action.title);
view.setOnClickPendingIntent(R.id.button, action.intent);
bigView.addView(R.id.buttons, view);
}
}