Java Code Examples for android.app.Notification#BigPictureStyle

The following examples show how to use android.app.Notification#BigPictureStyle . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LeanplumNotificationHelper.java    From Leanplum-Android-SDK with Apache License 2.0 5 votes vote down vote up
/**
 * Gets Notification.BigPictureStyle with 2 lines text.
 *
 * @param message Push notification Bundle.
 * @param bigPicture Bitmap for BigPictureStyle notification.
 * @param title String with title for push notification.
 * @param messageText String with text for push notification.
 * @return Notification.BigPictureStyle or null.
 */
@TargetApi(16)
static Notification.BigPictureStyle getBigPictureStyle(Bundle message, Bitmap bigPicture,
    String title, final String messageText) {
  if (Build.VERSION.SDK_INT < 16 || message == null || bigPicture == null) {
    return null;
  }

  Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle() {
    @Override
    protected RemoteViews getStandardView(int layoutId) {
      RemoteViews remoteViews = super.getStandardView(layoutId);
      if (messageText != null && messageText.length() >= MAX_ONE_LINE_TEXT_LENGTH) {
        // Modifications of standard 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));

  return bigPictureStyle;
}
 
Example 2
Source File: NotificationCompatJellybean.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void addBigPictureStyle(CharSequence bigContentTitle, boolean useSummary,
        CharSequence summaryText, Bitmap bigPicture, Bitmap bigLargeIcon,
        boolean bigLargeIconSet) {
   Notification.BigPictureStyle style = new Notification.BigPictureStyle(b)
       .setBigContentTitle(bigContentTitle)
       .bigPicture(bigPicture);
   if (bigLargeIconSet) {
       style.bigLargeIcon(bigLargeIcon);
   }
    if (useSummary) {
        style.setSummaryText(summaryText);
     }
}
 
Example 3
Source File: NotificationCompatJellybean.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
public static void addBigPictureStyle(NotificationBuilderWithBuilderAccessor b,
        CharSequence bigContentTitle, boolean useSummary,
        CharSequence summaryText, Bitmap bigPicture, Bitmap bigLargeIcon,
        boolean bigLargeIconSet) {
    Notification.BigPictureStyle style = new Notification.BigPictureStyle(b.getBuilder())
        .setBigContentTitle(bigContentTitle)
        .bigPicture(bigPicture);
    if (bigLargeIconSet) {
        style.bigLargeIcon(bigLargeIcon);
    }
    if (useSummary) {
        style.setSummaryText(summaryText);
    }
}
 
Example 4
Source File: NotificationCompatJellybean.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
public void addBigPictureStyle(CharSequence bigContentTitle, boolean useSummary,
        CharSequence summaryText, Bitmap bigPicture, Bitmap bigLargeIcon,
        boolean bigLargeIconSet) {
   Notification.BigPictureStyle style = new Notification.BigPictureStyle(b)
       .setBigContentTitle(bigContentTitle)
       .bigPicture(bigPicture);
   if (bigLargeIconSet) {
       style.bigLargeIcon(bigLargeIcon);
   }
    if (useSummary) {
        style.setSummaryText(summaryText);
     }
}
 
Example 5
Source File: NotificationCompatJellybean.java    From guideshow with MIT License 5 votes vote down vote up
public void addBigPictureStyle(CharSequence bigContentTitle, boolean useSummary,
        CharSequence summaryText, Bitmap bigPicture, Bitmap bigLargeIcon,
        boolean bigLargeIconSet) {
   Notification.BigPictureStyle style = new Notification.BigPictureStyle(b)
       .setBigContentTitle(bigContentTitle)
       .bigPicture(bigPicture);
   if (bigLargeIconSet) {
       style.bigLargeIcon(bigLargeIcon);
   }
    if (useSummary) {
        style.setSummaryText(summaryText);
     }
}
 
Example 6
Source File: StandardNotificationBuilder.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public Notification build() {
    // Note: this is not a NotificationCompat builder so be mindful of the
    // API level of methods you call on the builder.
    Notification.Builder builder = new Notification.Builder(mContext);
    builder.setContentTitle(mTitle);
    builder.setContentText(mBody);
    builder.setSubText(mOrigin);
    builder.setTicker(mTickerText);
    if (mImage != null) {
        Notification.BigPictureStyle style =
                new Notification.BigPictureStyle().bigPicture(mImage);
        if (Build.VERSION.CODENAME.equals("N")
                || Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
            // Android N doesn't show content text when expanded, so duplicate body text as a
            // summary for the big picture.
            style.setSummaryText(mBody);
        }
        builder.setStyle(style);
    } else {
        // If there is no image, let the body text wrap only multiple lines when expanded.
        builder.setStyle(new Notification.BigTextStyle().bigText(mBody));
    }
    builder.setLargeIcon(getNormalizedLargeIcon());
    setSmallIconOnBuilder(builder, mSmallIconId, mSmallIconBitmap);
    builder.setContentIntent(mContentIntent);
    builder.setDeleteIntent(mDeleteIntent);
    for (Action action : mActions) {
        addActionToBuilder(builder, action);
    }
    if (mSettingsAction != null) {
        addActionToBuilder(builder, mSettingsAction);
    }
    builder.setDefaults(mDefaults);
    builder.setVibrate(mVibratePattern);
    builder.setWhen(mTimestamp);
    builder.setOnlyAlertOnce(!mRenotify);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Notification.Builder.setPublicVersion was added in Android L.
        builder.setPublicVersion(createPublicNotification(mContext));
    }
    return builder.build();
}
 
Example 7
Source File: StandardNotificationBuilder.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public Notification build() {
    // Note: this is not a NotificationCompat builder so be mindful of the
    // API level of methods you call on the builder.
    // TODO(crbug.com/697104) We should probably use a Compat builder.
    ChromeNotificationBuilder builder =
            NotificationBuilderFactory.createChromeNotificationBuilder(
                    false /* preferCompat */, mChannelId);

    builder.setContentTitle(mTitle);
    builder.setContentText(mBody);
    builder.setSubText(mOrigin);
    builder.setTicker(mTickerText);
    if (mImage != null) {
        Notification.BigPictureStyle style =
                new Notification.BigPictureStyle().bigPicture(mImage);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            // Android N doesn't show content text when expanded, so duplicate body text as a
            // summary for the big picture.
            style.setSummaryText(mBody);
        }
        builder.setStyle(style);
    } else {
        // If there is no image, let the body text wrap only multiple lines when expanded.
        builder.setStyle(new Notification.BigTextStyle().bigText(mBody));
    }
    builder.setLargeIcon(getNormalizedLargeIcon());
    setSmallIconOnBuilder(builder, mSmallIconId, mSmallIconBitmap);
    builder.setContentIntent(mContentIntent);
    builder.setDeleteIntent(mDeleteIntent);
    for (Action action : mActions) {
        addActionToBuilder(builder, action);
    }
    if (mSettingsAction != null) {
        addActionToBuilder(builder, mSettingsAction);
    }
    builder.setDefaults(mDefaults);
    builder.setVibrate(mVibratePattern);
    builder.setWhen(mTimestamp);
    builder.setOnlyAlertOnce(!mRenotify);
    setGroupOnBuilder(builder, mOrigin);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Public versions only supported since L, and createPublicNotification requires L+.
        builder.setPublicVersion(createPublicNotification(mContext));
    }
    return builder.build();
}
 
Example 8
Source File: NotificationCompatBuilder.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public ChromeNotificationBuilder setStyle(Notification.BigPictureStyle style) {
    assert false; // unused
    return this;
}
 
Example 9
Source File: NotificationBuilder.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public ChromeNotificationBuilder setStyle(Notification.BigPictureStyle style) {
    mBuilder.setStyle(style);
    return this;
}
 
Example 10
Source File: ChromeNotificationBuilder.java    From 365browser with Apache License 2.0 votes vote down vote up
ChromeNotificationBuilder setStyle(Notification.BigPictureStyle style);