/android/support/v7/internal/app/NotificationCompatImplBase.java

https://gitlab.com/Soundar028/mahendra_result_app · Java · 165 lines · 156 code · 9 blank · 0 comment · 46 complexity · 2a1cf72f79c75e1a7dcf971ade7ce305 MD5 · raw file

  1. package android.support.v7.internal.app;
  2. import android.app.Notification;
  3. import android.app.PendingIntent;
  4. import android.content.Context;
  5. import android.graphics.Bitmap;
  6. import android.os.Build.VERSION;
  7. import android.os.SystemClock;
  8. import android.support.v4.app.NotificationBuilderWithBuilderAccessor;
  9. import android.support.v4.app.NotificationCompatBase.Action;
  10. import android.support.v7.appcompat.C0111R;
  11. import android.widget.RemoteViews;
  12. import java.text.NumberFormat;
  13. import java.util.List;
  14. public class NotificationCompatImplBase {
  15. static final int MAX_MEDIA_BUTTONS = 5;
  16. static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3;
  17. public static <T extends Action> void overrideContentView(NotificationBuilderWithBuilderAccessor builder, 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) {
  18. builder.getBuilder().setContent(generateContentView(context, contentTitle, contentText, contentInfo, number, largeIcon, subText, useChronometer, when, actions, actionsToShowInCompact, showCancelButton, cancelButtonIntent));
  19. if (showCancelButton) {
  20. builder.getBuilder().setOngoing(true);
  21. }
  22. }
  23. 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) {
  24. int N;
  25. RemoteViews view = applyStandardTemplate(context, contentTitle, contentText, contentInfo, number, largeIcon, subText, useChronometer, when, C0111R.layout.notification_template_media, true);
  26. int numActions = actions.size();
  27. if (actionsToShowInCompact == null) {
  28. N = 0;
  29. } else {
  30. N = Math.min(actionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT);
  31. }
  32. view.removeAllViews(C0111R.id.media_actions);
  33. if (N > 0) {
  34. for (int i = 0; i < N; i++) {
  35. if (i >= numActions) {
  36. throw new IllegalArgumentException(String.format("setShowActionsInCompactView: action %d out of bounds (max %d)", new Object[]{Integer.valueOf(i), Integer.valueOf(numActions - 1)}));
  37. }
  38. Context context2 = context;
  39. RemoteViews button = generateMediaActionButton(context2, (Action) actions.get(actionsToShowInCompact[i]));
  40. view.addView(C0111R.id.media_actions, button);
  41. }
  42. }
  43. if (showCancelButton) {
  44. view.setViewVisibility(C0111R.id.end_padder, 8);
  45. view.setViewVisibility(C0111R.id.cancel_action, 0);
  46. view.setOnClickPendingIntent(C0111R.id.cancel_action, cancelButtonIntent);
  47. view.setInt(C0111R.id.cancel_action, "setAlpha", context.getResources().getInteger(C0111R.integer.cancel_button_image_alpha));
  48. } else {
  49. view.setViewVisibility(C0111R.id.end_padder, 0);
  50. view.setViewVisibility(C0111R.id.cancel_action, 8);
  51. }
  52. return view;
  53. }
  54. public static <T extends Action> void overrideBigContentView(Notification n, 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) {
  55. n.bigContentView = generateBigContentView(context, contentTitle, contentText, contentInfo, number, largeIcon, subText, useChronometer, when, actions, showCancelButton, cancelButtonIntent);
  56. if (showCancelButton) {
  57. n.flags |= 2;
  58. }
  59. }
  60. 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) {
  61. int actionCount = Math.min(actions.size(), MAX_MEDIA_BUTTONS);
  62. RemoteViews big = applyStandardTemplate(context, contentTitle, contentText, contentInfo, number, largeIcon, subText, useChronometer, when, getBigLayoutResource(actionCount), false);
  63. big.removeAllViews(C0111R.id.media_actions);
  64. if (actionCount > 0) {
  65. for (int i = 0; i < actionCount; i++) {
  66. big.addView(C0111R.id.media_actions, generateMediaActionButton(context, (Action) actions.get(i)));
  67. }
  68. }
  69. if (showCancelButton) {
  70. big.setViewVisibility(C0111R.id.cancel_action, 0);
  71. big.setInt(C0111R.id.cancel_action, "setAlpha", context.getResources().getInteger(C0111R.integer.cancel_button_image_alpha));
  72. big.setOnClickPendingIntent(C0111R.id.cancel_action, cancelButtonIntent);
  73. } else {
  74. big.setViewVisibility(C0111R.id.cancel_action, 8);
  75. }
  76. return big;
  77. }
  78. private static RemoteViews generateMediaActionButton(Context context, Action action) {
  79. boolean tombstone = action.getActionIntent() == null;
  80. RemoteViews button = new RemoteViews(context.getPackageName(), C0111R.layout.notification_media_action);
  81. button.setImageViewResource(C0111R.id.action0, action.getIcon());
  82. if (!tombstone) {
  83. button.setOnClickPendingIntent(C0111R.id.action0, action.getActionIntent());
  84. }
  85. if (VERSION.SDK_INT >= 15) {
  86. button.setContentDescription(C0111R.id.action0, action.getTitle());
  87. }
  88. return button;
  89. }
  90. private static int getBigLayoutResource(int actionCount) {
  91. if (actionCount <= MAX_MEDIA_BUTTONS_IN_COMPACT) {
  92. return C0111R.layout.notification_template_big_media_narrow;
  93. }
  94. return C0111R.layout.notification_template_big_media;
  95. }
  96. 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) {
  97. RemoteViews contentView = new RemoteViews(context.getPackageName(), resId);
  98. boolean showLine3 = false;
  99. boolean showLine2 = false;
  100. if (largeIcon == null || VERSION.SDK_INT < 16) {
  101. contentView.setViewVisibility(C0111R.id.icon, 8);
  102. } else {
  103. contentView.setImageViewBitmap(C0111R.id.icon, largeIcon);
  104. }
  105. if (contentTitle != null) {
  106. contentView.setTextViewText(C0111R.id.title, contentTitle);
  107. }
  108. if (contentText != null) {
  109. contentView.setTextViewText(C0111R.id.text, contentText);
  110. showLine3 = true;
  111. }
  112. if (contentInfo != null) {
  113. contentView.setTextViewText(C0111R.id.info, contentInfo);
  114. contentView.setViewVisibility(C0111R.id.info, 0);
  115. showLine3 = true;
  116. } else if (number > 0) {
  117. if (number > context.getResources().getInteger(C0111R.integer.status_bar_notification_info_maxnum)) {
  118. contentView.setTextViewText(C0111R.id.info, context.getResources().getString(C0111R.string.status_bar_notification_info_overflow));
  119. } else {
  120. contentView.setTextViewText(C0111R.id.info, NumberFormat.getIntegerInstance().format((long) number));
  121. }
  122. contentView.setViewVisibility(C0111R.id.info, 0);
  123. showLine3 = true;
  124. } else {
  125. contentView.setViewVisibility(C0111R.id.info, 8);
  126. }
  127. if (subText != null && VERSION.SDK_INT >= 16) {
  128. contentView.setTextViewText(C0111R.id.text, subText);
  129. if (contentText != null) {
  130. contentView.setTextViewText(C0111R.id.text2, contentText);
  131. contentView.setViewVisibility(C0111R.id.text2, 0);
  132. showLine2 = true;
  133. } else {
  134. contentView.setViewVisibility(C0111R.id.text2, 8);
  135. }
  136. }
  137. if (showLine2 && VERSION.SDK_INT >= 16) {
  138. if (fitIn1U) {
  139. contentView.setTextViewTextSize(C0111R.id.text, 0, (float) context.getResources().getDimensionPixelSize(C0111R.dimen.notification_subtext_size));
  140. }
  141. contentView.setViewPadding(C0111R.id.line1, 0, 0, 0, 0);
  142. }
  143. if (when != 0) {
  144. if (useChronometer) {
  145. contentView.setViewVisibility(C0111R.id.chronometer, 0);
  146. contentView.setLong(C0111R.id.chronometer, "setBase", (SystemClock.elapsedRealtime() - System.currentTimeMillis()) + when);
  147. contentView.setBoolean(C0111R.id.chronometer, "setStarted", true);
  148. } else {
  149. contentView.setViewVisibility(C0111R.id.time, 0);
  150. contentView.setLong(C0111R.id.time, "setTime", when);
  151. }
  152. }
  153. contentView.setViewVisibility(C0111R.id.line3, showLine3 ? 0 : 8);
  154. return contentView;
  155. }
  156. }