當前位置: 首頁>>代碼示例>>Java>>正文


Java RemoteViews.setViewPadding方法代碼示例

本文整理匯總了Java中android.widget.RemoteViews.setViewPadding方法的典型用法代碼示例。如果您正苦於以下問題:Java RemoteViews.setViewPadding方法的具體用法?Java RemoteViews.setViewPadding怎麽用?Java RemoteViews.setViewPadding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.RemoteViews的用法示例。


在下文中一共展示了RemoteViews.setViewPadding方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fixIconImage

import android.widget.RemoteViews; //導入方法依賴的package包/類
void fixIconImage(Resources resources, RemoteViews remoteViews, boolean hasIconBitmap, Notification notification) {
    if (remoteViews == null) return;
    if (!mNotificationCompat.isSystemLayout(remoteViews)) {
        return;
    }
    try {
        //noinspection deprecation
        int id = R_Hide.id.icon.get();
        //only fake small icon
        if (!hasIconBitmap && notification.largeIcon == null) {
            Drawable drawable = resources.getDrawable(notification.icon);
            drawable.setLevel(notification.iconLevel);
            Bitmap bitmap = drawableToBitMap(drawable);
            remoteViews.setImageViewBitmap(id, bitmap);
        }
        if (Build.VERSION.SDK_INT >= 21) {
            remoteViews.setInt(id, "setBackgroundColor", Color.TRANSPARENT);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            remoteViews.setViewPadding(id, 0, 0, 0, 0);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:26,代碼來源:NotificationFixer.java

示例2: applyStandardTemplate

import android.widget.RemoteViews; //導入方法依賴的package包/類
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;
    if (largeIcon == null || VERSION.SDK_INT < 16) {
        contentView.setViewVisibility(R.id.icon, 8);
    } else {
        contentView.setViewVisibility(R.id.icon, 0);
        contentView.setImageViewBitmap(R.id.icon, largeIcon);
    }
    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, 0);
        showLine3 = true;
    } else if (number > 0) {
        if (number > context.getResources().getInteger(R.integer.status_bar_notification_info_maxnum)) {
            contentView.setTextViewText(R.id.info, context.getResources().getString(R.string.status_bar_notification_info_overflow));
        } else {
            contentView.setTextViewText(R.id.info, NumberFormat.getIntegerInstance().format((long) number));
        }
        contentView.setViewVisibility(R.id.info, 0);
        showLine3 = true;
    } else {
        contentView.setViewVisibility(R.id.info, 8);
    }
    if (subText != null && VERSION.SDK_INT >= 16) {
        contentView.setTextViewText(R.id.text, subText);
        if (contentText != null) {
            contentView.setTextViewText(R.id.text2, contentText);
            contentView.setViewVisibility(R.id.text2, 0);
            showLine2 = true;
        } else {
            contentView.setViewVisibility(R.id.text2, 8);
        }
    }
    if (showLine2 && VERSION.SDK_INT >= 16) {
        if (fitIn1U) {
            contentView.setTextViewTextSize(R.id.text, 0, (float) context.getResources().getDimensionPixelSize(R.dimen.notification_subtext_size));
        }
        contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
    }
    if (when != 0) {
        if (useChronometer) {
            contentView.setViewVisibility(R.id.chronometer, 0);
            contentView.setLong(R.id.chronometer, "setBase", (SystemClock.elapsedRealtime() - System.currentTimeMillis()) + when);
            contentView.setBoolean(R.id.chronometer, "setStarted", true);
        } else {
            contentView.setViewVisibility(R.id.time, 0);
            contentView.setLong(R.id.time, "setTime", when);
        }
    }
    contentView.setViewVisibility(R.id.line3, showLine3 ? 0 : 8);
    return contentView;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:62,代碼來源:NotificationCompatImplBase.java

示例3: 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);
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:56,代碼來源:CustomNotificationBuilder.java

示例4: getNotificationBuilder

import android.widget.RemoteViews; //導入方法依賴的package包/類
/**
 * Gets Notification.Builder with 2 lines at BigPictureStyle notification text.
 *
 * @param context The application context.
 * @param message Push notification Bundle.
 * @param contentIntent PendingIntent.
 * @param title String with title for push notification.
 * @param messageText String with text for push notification.
 * @param bigPicture Bitmap for BigPictureStyle notification.
 * @param defaultNotificationIconResourceId int Resource id for default push notification icon.
 * @return Notification.Builder or null.
 */
static Notification.Builder getNotificationBuilder(Context context, Bundle message,
    PendingIntent contentIntent, String title, final String messageText, Bitmap bigPicture,
    int defaultNotificationIconResourceId) {
  if (Build.VERSION.SDK_INT < 16) {
    return null;
  }
  Notification.Builder notificationBuilder =
      getNotificationBuilder(context, message);
  if (defaultNotificationIconResourceId == 0) {
    notificationBuilder.setSmallIcon(context.getApplicationInfo().icon);
  } else {
    notificationBuilder.setSmallIcon(defaultNotificationIconResourceId);
  }
  notificationBuilder.setContentTitle(title)
      .setContentText(messageText);
  Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle() {
    @Override
    protected RemoteViews getStandardView(int layoutId) {
      RemoteViews remoteViews = super.getStandardView(layoutId);
      // Modifications of stanxdard push RemoteView.
      try {
        int id = Resources.getSystem().getIdentifier("text", "id", "android");
        remoteViews.setBoolean(id, "setSingleLine", false);
        remoteViews.setInt(id, "setLines", 2);
        if (Build.VERSION.SDK_INT < 23) {
          // Make text smaller.
          remoteViews.setViewPadding(id, 0, BIGPICTURE_TEXT_TOP_PADDING, 0, 0);
          remoteViews.setTextViewTextSize(id, TypedValue.COMPLEX_UNIT_SP, BIGPICTURE_TEXT_SIZE);
        }
      } catch (Throwable throwable) {
        Log.e("Cannot modify push notification layout.");
      }
      return remoteViews;
    }
  };

  bigPictureStyle.bigPicture(bigPicture)
      .setBigContentTitle(title)
      .setSummaryText(message.getString(Constants.Keys.PUSH_MESSAGE_TEXT));
  notificationBuilder.setStyle(bigPictureStyle);

  if (Build.VERSION.SDK_INT >= 24) {
    // By default we cannot reach getStandardView method on API>=24. I we call
    // createBigContentView, Android will call getStandardView method and we can get
    // modified RemoteView.
    try {
      RemoteViews remoteView = notificationBuilder.createBigContentView();
      if (remoteView != null) {
        // We need to set received RemoteView as a custom big content view.
        notificationBuilder.setCustomBigContentView(remoteView);
      }
    } catch (Throwable t) {
      Log.e("Cannot modify push notification layout.", t);
    }
  }

  notificationBuilder.setAutoCancel(true);
  notificationBuilder.setContentIntent(contentIntent);
  return notificationBuilder;
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:73,代碼來源:LeanplumNotificationHelper.java

示例5: fixIconImage

import android.widget.RemoteViews; //導入方法依賴的package包/類
void fixIconImage(Resources resources, RemoteViews remoteViews, boolean hasIconBitmap, Notification notification) {
		if (remoteViews == null) return;
		if (!mNotificationCompat.isSystemLayout(remoteViews)) {
			VLog.w(TAG, "ignore not system contentView");
			return;
		}
//        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
		try {
			//noinspection deprecation
			int id = R_Hide.id.icon.get();
			if (!hasIconBitmap) {
				Drawable drawable = resources.getDrawable(android.R.drawable.sym_def_app_icon);//notification.icon);
				drawable.setLevel(notification.iconLevel);
				Bitmap bitmap = drawableToBitMap(drawable);
//                Log.i(NotificationHandler.TAG, "den" + resources.getConfiguration().densityDpi);
				remoteViews.setImageViewBitmap(id, bitmap);
			}
			if (Build.VERSION.SDK_INT >= 21) {
				remoteViews.setInt(id, "setBackgroundColor", Color.TRANSPARENT);
			}
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
				remoteViews.setViewPadding(id, 0, 0, 0, 0);
			}
		} catch (Exception e) {
			e.printStackTrace();
			VLog.w(TAG, "fix icon", e);
		}
//        } else {
//            try {
//                int id = R_Hide.id.icon.get();
//                Icon icon = notification.getLargeIcon();
//                if (icon == null) {
//                    icon = notification.getSmallIcon();
//                }
//                remoteViews.setImageViewIcon(id, icon);
//                if (Build.VERSION.SDK_INT >= 21) {
//                    remoteViews.setInt(id, "setBackgroundColor", Color.TRANSPARENT);
//                }
//                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
//                    remoteViews.setViewPadding(id, 0, 0, 0, 0);
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
	}
 
開發者ID:codehz,項目名稱:container,代碼行數:47,代碼來源:NotificationFixer.java


注:本文中的android.widget.RemoteViews.setViewPadding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。