1976b6a8c18550ace670e0410453741d11dafa474Ian Lake/* 2976b6a8c18550ace670e0410453741d11dafa474Ian Lake * Copyright (C) 2015 The Android Open Source Project 3976b6a8c18550ace670e0410453741d11dafa474Ian Lake * 4976b6a8c18550ace670e0410453741d11dafa474Ian Lake * Licensed under the Apache License, Version 2.0 (the "License"); 5976b6a8c18550ace670e0410453741d11dafa474Ian Lake * you may not use this file except in compliance with the License. 6976b6a8c18550ace670e0410453741d11dafa474Ian Lake * You may obtain a copy of the License at 7976b6a8c18550ace670e0410453741d11dafa474Ian Lake * 8976b6a8c18550ace670e0410453741d11dafa474Ian Lake * http://www.apache.org/licenses/LICENSE-2.0 9976b6a8c18550ace670e0410453741d11dafa474Ian Lake * 10976b6a8c18550ace670e0410453741d11dafa474Ian Lake * Unless required by applicable law or agreed to in writing, software 11976b6a8c18550ace670e0410453741d11dafa474Ian Lake * distributed under the License is distributed on an "AS IS" BASIS, 12976b6a8c18550ace670e0410453741d11dafa474Ian Lake * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13976b6a8c18550ace670e0410453741d11dafa474Ian Lake * See the License for the specific language governing permissions and 14976b6a8c18550ace670e0410453741d11dafa474Ian Lake * limitations under the License 15976b6a8c18550ace670e0410453741d11dafa474Ian Lake */ 16976b6a8c18550ace670e0410453741d11dafa474Ian Lake 1766698bb15ba0f873aa1c2290cc50d6bb839a474aChris Banespackage android.support.v7.app; 18976b6a8c18550ace670e0410453741d11dafa474Ian Lake 19976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport android.app.Notification; 20976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport android.app.PendingIntent; 21976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport android.content.Context; 22976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport android.content.res.Resources; 23976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport android.graphics.Bitmap; 24976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport android.os.Build; 25976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport android.os.SystemClock; 26976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport android.support.v4.app.NotificationBuilderWithBuilderAccessor; 27976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport android.support.v4.app.NotificationCompatBase; 2866698bb15ba0f873aa1c2290cc50d6bb839a474aChris Banesimport android.support.v7.appcompat.R; 29976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport android.util.TypedValue; 30976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport android.view.View; 31976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport android.widget.RemoteViews; 32976b6a8c18550ace670e0410453741d11dafa474Ian Lake 33976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport java.text.NumberFormat; 34976b6a8c18550ace670e0410453741d11dafa474Ian Lakeimport java.util.List; 35976b6a8c18550ace670e0410453741d11dafa474Ian Lake 36976b6a8c18550ace670e0410453741d11dafa474Ian Lake/** 37976b6a8c18550ace670e0410453741d11dafa474Ian Lake * Helper class to generate MediaStyle notifications for pre-Lollipop platforms. Overrides 38976b6a8c18550ace670e0410453741d11dafa474Ian Lake * contentView and bigContentView of the notification. 39976b6a8c18550ace670e0410453741d11dafa474Ian Lake */ 4066698bb15ba0f873aa1c2290cc50d6bb839a474aChris Banesclass NotificationCompatImplBase { 41976b6a8c18550ace670e0410453741d11dafa474Ian Lake 42976b6a8c18550ace670e0410453741d11dafa474Ian Lake static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; 43976b6a8c18550ace670e0410453741d11dafa474Ian Lake static final int MAX_MEDIA_BUTTONS = 5; 44976b6a8c18550ace670e0410453741d11dafa474Ian Lake 45976b6a8c18550ace670e0410453741d11dafa474Ian Lake public static <T extends NotificationCompatBase.Action> void overrideContentView( 46976b6a8c18550ace670e0410453741d11dafa474Ian Lake NotificationBuilderWithBuilderAccessor builder, 47976b6a8c18550ace670e0410453741d11dafa474Ian Lake Context context, CharSequence contentTitle, CharSequence contentText, 48976b6a8c18550ace670e0410453741d11dafa474Ian Lake CharSequence contentInfo, int number, Bitmap largeIcon, CharSequence subText, 49976b6a8c18550ace670e0410453741d11dafa474Ian Lake boolean useChronometer, long when, List<T> actions, int[] actionsToShowInCompact, 50976b6a8c18550ace670e0410453741d11dafa474Ian Lake boolean showCancelButton, PendingIntent cancelButtonIntent) { 51976b6a8c18550ace670e0410453741d11dafa474Ian Lake RemoteViews views = generateContentView(context, contentTitle, contentText, contentInfo, 52976b6a8c18550ace670e0410453741d11dafa474Ian Lake number, largeIcon, subText, useChronometer, when, actions, actionsToShowInCompact, 53976b6a8c18550ace670e0410453741d11dafa474Ian Lake showCancelButton, cancelButtonIntent); 54976b6a8c18550ace670e0410453741d11dafa474Ian Lake builder.getBuilder().setContent(views); 55976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (showCancelButton) { 56976b6a8c18550ace670e0410453741d11dafa474Ian Lake builder.getBuilder().setOngoing(true); 57976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 58976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 59976b6a8c18550ace670e0410453741d11dafa474Ian Lake 60976b6a8c18550ace670e0410453741d11dafa474Ian Lake private static <T extends NotificationCompatBase.Action> RemoteViews generateContentView( 61976b6a8c18550ace670e0410453741d11dafa474Ian Lake Context context, CharSequence contentTitle, CharSequence contentText, 62976b6a8c18550ace670e0410453741d11dafa474Ian Lake CharSequence contentInfo, int number, Bitmap largeIcon, CharSequence subText, 63976b6a8c18550ace670e0410453741d11dafa474Ian Lake boolean useChronometer, long when, List<T> actions, int[] actionsToShowInCompact, 64976b6a8c18550ace670e0410453741d11dafa474Ian Lake boolean showCancelButton, PendingIntent cancelButtonIntent) { 65976b6a8c18550ace670e0410453741d11dafa474Ian Lake RemoteViews view = applyStandardTemplate(context, contentTitle, contentText, contentInfo, 66976b6a8c18550ace670e0410453741d11dafa474Ian Lake number, largeIcon, subText, useChronometer, when, 67976b6a8c18550ace670e0410453741d11dafa474Ian Lake R.layout.notification_template_media, true /* fitIn1U */); 68976b6a8c18550ace670e0410453741d11dafa474Ian Lake 69976b6a8c18550ace670e0410453741d11dafa474Ian Lake final int numActions = actions.size(); 70976b6a8c18550ace670e0410453741d11dafa474Ian Lake final int N = actionsToShowInCompact == null 71976b6a8c18550ace670e0410453741d11dafa474Ian Lake ? 0 72976b6a8c18550ace670e0410453741d11dafa474Ian Lake : Math.min(actionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); 73976b6a8c18550ace670e0410453741d11dafa474Ian Lake view.removeAllViews(R.id.media_actions); 74976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (N > 0) { 75976b6a8c18550ace670e0410453741d11dafa474Ian Lake for (int i = 0; i < N; i++) { 76976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (i >= numActions) { 77976b6a8c18550ace670e0410453741d11dafa474Ian Lake throw new IllegalArgumentException(String.format( 78976b6a8c18550ace670e0410453741d11dafa474Ian Lake "setShowActionsInCompactView: action %d out of bounds (max %d)", 79976b6a8c18550ace670e0410453741d11dafa474Ian Lake i, numActions - 1)); 80976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 81976b6a8c18550ace670e0410453741d11dafa474Ian Lake 82976b6a8c18550ace670e0410453741d11dafa474Ian Lake final NotificationCompatBase.Action action = actions.get(actionsToShowInCompact[i]); 83976b6a8c18550ace670e0410453741d11dafa474Ian Lake final RemoteViews button = generateMediaActionButton(context, action); 84976b6a8c18550ace670e0410453741d11dafa474Ian Lake view.addView(R.id.media_actions, button); 85976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 86976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 87976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (showCancelButton) { 88976b6a8c18550ace670e0410453741d11dafa474Ian Lake view.setViewVisibility(R.id.end_padder, View.GONE); 89976b6a8c18550ace670e0410453741d11dafa474Ian Lake view.setViewVisibility(R.id.cancel_action, View.VISIBLE); 90976b6a8c18550ace670e0410453741d11dafa474Ian Lake view.setOnClickPendingIntent(R.id.cancel_action, cancelButtonIntent); 91976b6a8c18550ace670e0410453741d11dafa474Ian Lake view.setInt(R.id.cancel_action, "setAlpha", 92976b6a8c18550ace670e0410453741d11dafa474Ian Lake context.getResources().getInteger(R.integer.cancel_button_image_alpha)); 93976b6a8c18550ace670e0410453741d11dafa474Ian Lake } else { 94976b6a8c18550ace670e0410453741d11dafa474Ian Lake view.setViewVisibility(R.id.end_padder, View.VISIBLE); 95976b6a8c18550ace670e0410453741d11dafa474Ian Lake view.setViewVisibility(R.id.cancel_action, View.GONE); 96976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 97976b6a8c18550ace670e0410453741d11dafa474Ian Lake return view; 98976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 99976b6a8c18550ace670e0410453741d11dafa474Ian Lake 100976b6a8c18550ace670e0410453741d11dafa474Ian Lake public static <T extends NotificationCompatBase.Action> void overrideBigContentView( 101976b6a8c18550ace670e0410453741d11dafa474Ian Lake Notification n, Context context, CharSequence contentTitle, CharSequence contentText, 102976b6a8c18550ace670e0410453741d11dafa474Ian Lake CharSequence contentInfo, int number, Bitmap largeIcon, CharSequence subText, 103976b6a8c18550ace670e0410453741d11dafa474Ian Lake boolean useChronometer, long when, List<T> actions, boolean showCancelButton, 104976b6a8c18550ace670e0410453741d11dafa474Ian Lake PendingIntent cancelButtonIntent) { 105976b6a8c18550ace670e0410453741d11dafa474Ian Lake n.bigContentView = generateBigContentView(context, contentTitle, contentText, contentInfo, 106976b6a8c18550ace670e0410453741d11dafa474Ian Lake number, largeIcon, subText, useChronometer, when, actions, showCancelButton, 107976b6a8c18550ace670e0410453741d11dafa474Ian Lake cancelButtonIntent); 108976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (showCancelButton) { 109976b6a8c18550ace670e0410453741d11dafa474Ian Lake n.flags |= Notification.FLAG_ONGOING_EVENT; 110976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 111976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 112976b6a8c18550ace670e0410453741d11dafa474Ian Lake 113976b6a8c18550ace670e0410453741d11dafa474Ian Lake private static <T extends NotificationCompatBase.Action> RemoteViews generateBigContentView( 114976b6a8c18550ace670e0410453741d11dafa474Ian Lake Context context, CharSequence contentTitle, CharSequence contentText, 115976b6a8c18550ace670e0410453741d11dafa474Ian Lake CharSequence contentInfo, int number, Bitmap largeIcon, CharSequence subText, 116976b6a8c18550ace670e0410453741d11dafa474Ian Lake boolean useChronometer, long when, List<T> actions, boolean showCancelButton, 117976b6a8c18550ace670e0410453741d11dafa474Ian Lake PendingIntent cancelButtonIntent) { 118976b6a8c18550ace670e0410453741d11dafa474Ian Lake final int actionCount = Math.min(actions.size(), MAX_MEDIA_BUTTONS); 119976b6a8c18550ace670e0410453741d11dafa474Ian Lake RemoteViews big = applyStandardTemplate(context, contentTitle, contentText, contentInfo, 120976b6a8c18550ace670e0410453741d11dafa474Ian Lake number, largeIcon, subText, useChronometer, when, 121976b6a8c18550ace670e0410453741d11dafa474Ian Lake getBigLayoutResource(actionCount), false /* fitIn1U */); 122976b6a8c18550ace670e0410453741d11dafa474Ian Lake 123976b6a8c18550ace670e0410453741d11dafa474Ian Lake big.removeAllViews(R.id.media_actions); 124976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (actionCount > 0) { 125976b6a8c18550ace670e0410453741d11dafa474Ian Lake for (int i = 0; i < actionCount; i++) { 126976b6a8c18550ace670e0410453741d11dafa474Ian Lake final RemoteViews button = generateMediaActionButton(context, actions.get(i)); 127976b6a8c18550ace670e0410453741d11dafa474Ian Lake big.addView(R.id.media_actions, button); 128976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 129976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 130976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (showCancelButton) { 131976b6a8c18550ace670e0410453741d11dafa474Ian Lake big.setViewVisibility(R.id.cancel_action, View.VISIBLE); 132976b6a8c18550ace670e0410453741d11dafa474Ian Lake big.setInt(R.id.cancel_action, "setAlpha", 133976b6a8c18550ace670e0410453741d11dafa474Ian Lake context.getResources().getInteger(R.integer.cancel_button_image_alpha)); 134976b6a8c18550ace670e0410453741d11dafa474Ian Lake big.setOnClickPendingIntent(R.id.cancel_action, cancelButtonIntent); 135976b6a8c18550ace670e0410453741d11dafa474Ian Lake } else { 136976b6a8c18550ace670e0410453741d11dafa474Ian Lake big.setViewVisibility(R.id.cancel_action, View.GONE); 137976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 138976b6a8c18550ace670e0410453741d11dafa474Ian Lake return big; 139976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 140976b6a8c18550ace670e0410453741d11dafa474Ian Lake 141976b6a8c18550ace670e0410453741d11dafa474Ian Lake private static RemoteViews generateMediaActionButton(Context context, 142976b6a8c18550ace670e0410453741d11dafa474Ian Lake NotificationCompatBase.Action action) { 143976b6a8c18550ace670e0410453741d11dafa474Ian Lake final boolean tombstone = (action.getActionIntent() == null); 144976b6a8c18550ace670e0410453741d11dafa474Ian Lake RemoteViews button = new RemoteViews(context.getPackageName(), 145976b6a8c18550ace670e0410453741d11dafa474Ian Lake R.layout.notification_media_action); 146976b6a8c18550ace670e0410453741d11dafa474Ian Lake button.setImageViewResource(R.id.action0, action.getIcon()); 147976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (!tombstone) { 148976b6a8c18550ace670e0410453741d11dafa474Ian Lake button.setOnClickPendingIntent(R.id.action0, action.getActionIntent()); 149976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 150956192ae5d9dd882c91c9cb607954f0eebcb7976Ian Lake if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { 151956192ae5d9dd882c91c9cb607954f0eebcb7976Ian Lake button.setContentDescription(R.id.action0, action.getTitle()); 152956192ae5d9dd882c91c9cb607954f0eebcb7976Ian Lake } 153976b6a8c18550ace670e0410453741d11dafa474Ian Lake return button; 154976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 155976b6a8c18550ace670e0410453741d11dafa474Ian Lake 156976b6a8c18550ace670e0410453741d11dafa474Ian Lake private static int getBigLayoutResource(int actionCount) { 157976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (actionCount <= 3) { 158976b6a8c18550ace670e0410453741d11dafa474Ian Lake return R.layout.notification_template_big_media_narrow; 159976b6a8c18550ace670e0410453741d11dafa474Ian Lake } else { 160976b6a8c18550ace670e0410453741d11dafa474Ian Lake return R.layout.notification_template_big_media; 161976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 162976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 163976b6a8c18550ace670e0410453741d11dafa474Ian Lake 164976b6a8c18550ace670e0410453741d11dafa474Ian Lake private static RemoteViews applyStandardTemplate(Context context, 165976b6a8c18550ace670e0410453741d11dafa474Ian Lake CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo, 166976b6a8c18550ace670e0410453741d11dafa474Ian Lake int number, Bitmap largeIcon, CharSequence subText, boolean useChronometer, long when, 167976b6a8c18550ace670e0410453741d11dafa474Ian Lake int resId, boolean fitIn1U) { 168976b6a8c18550ace670e0410453741d11dafa474Ian Lake RemoteViews contentView = new RemoteViews(context.getPackageName(), resId); 169976b6a8c18550ace670e0410453741d11dafa474Ian Lake boolean showLine3 = false; 170976b6a8c18550ace670e0410453741d11dafa474Ian Lake boolean showLine2 = false; 171976b6a8c18550ace670e0410453741d11dafa474Ian Lake 172976b6a8c18550ace670e0410453741d11dafa474Ian Lake // On versions before Jellybean, the large icon was shown by SystemUI, so we need to hide 173976b6a8c18550ace670e0410453741d11dafa474Ian Lake // it here. 174976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (largeIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 175b5d323aec7885d728503cc080c6c5e5a20e5850cIan Lake contentView.setViewVisibility(R.id.icon, View.VISIBLE); 176976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setImageViewBitmap(R.id.icon, largeIcon); 177976b6a8c18550ace670e0410453741d11dafa474Ian Lake } else { 178976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setViewVisibility(R.id.icon, View.GONE); 179976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 180976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (contentTitle != null) { 181976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setTextViewText(R.id.title, contentTitle); 182976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 183976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (contentText != null) { 184976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setTextViewText(R.id.text, contentText); 185976b6a8c18550ace670e0410453741d11dafa474Ian Lake showLine3 = true; 186976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 187976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (contentInfo != null) { 188976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setTextViewText(R.id.info, contentInfo); 189976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setViewVisibility(R.id.info, View.VISIBLE); 190976b6a8c18550ace670e0410453741d11dafa474Ian Lake showLine3 = true; 191976b6a8c18550ace670e0410453741d11dafa474Ian Lake } else if (number > 0) { 192976b6a8c18550ace670e0410453741d11dafa474Ian Lake final int tooBig = context.getResources().getInteger( 193976b6a8c18550ace670e0410453741d11dafa474Ian Lake R.integer.status_bar_notification_info_maxnum); 194976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (number > tooBig) { 195976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setTextViewText(R.id.info, context.getResources().getString( 196976b6a8c18550ace670e0410453741d11dafa474Ian Lake R.string.status_bar_notification_info_overflow)); 197976b6a8c18550ace670e0410453741d11dafa474Ian Lake } else { 198976b6a8c18550ace670e0410453741d11dafa474Ian Lake NumberFormat f = NumberFormat.getIntegerInstance(); 199976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setTextViewText(R.id.info, f.format(number)); 200976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 201976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setViewVisibility(R.id.info, View.VISIBLE); 202976b6a8c18550ace670e0410453741d11dafa474Ian Lake showLine3 = true; 203976b6a8c18550ace670e0410453741d11dafa474Ian Lake } else { 204976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setViewVisibility(R.id.info, View.GONE); 205976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 206976b6a8c18550ace670e0410453741d11dafa474Ian Lake 207976b6a8c18550ace670e0410453741d11dafa474Ian Lake // Need to show three lines? Only allow on Jellybean+ 208976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (subText != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 209976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setTextViewText(R.id.text, subText); 210976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (contentText != null) { 211976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setTextViewText(R.id.text2, contentText); 212976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setViewVisibility(R.id.text2, View.VISIBLE); 213976b6a8c18550ace670e0410453741d11dafa474Ian Lake showLine2 = true; 214976b6a8c18550ace670e0410453741d11dafa474Ian Lake } else { 215976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setViewVisibility(R.id.text2, View.GONE); 216976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 217976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 218976b6a8c18550ace670e0410453741d11dafa474Ian Lake 219976b6a8c18550ace670e0410453741d11dafa474Ian Lake // RemoteViews.setViewPadding and RemoteViews.setTextViewTextSize is not available on ICS- 220976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (showLine2 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 221976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (fitIn1U) { 222976b6a8c18550ace670e0410453741d11dafa474Ian Lake // need to shrink all the type to make sure everything fits 223976b6a8c18550ace670e0410453741d11dafa474Ian Lake final Resources res = context.getResources(); 224976b6a8c18550ace670e0410453741d11dafa474Ian Lake final float subTextSize = res.getDimensionPixelSize( 225976b6a8c18550ace670e0410453741d11dafa474Ian Lake R.dimen.notification_subtext_size); 226976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize); 227976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 228976b6a8c18550ace670e0410453741d11dafa474Ian Lake // vertical centering 229976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setViewPadding(R.id.line1, 0, 0, 0, 0); 230976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 231976b6a8c18550ace670e0410453741d11dafa474Ian Lake 232976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (when != 0) { 233976b6a8c18550ace670e0410453741d11dafa474Ian Lake if (useChronometer) { 234976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); 235976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setLong(R.id.chronometer, "setBase", 236976b6a8c18550ace670e0410453741d11dafa474Ian Lake when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); 237976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setBoolean(R.id.chronometer, "setStarted", true); 238976b6a8c18550ace670e0410453741d11dafa474Ian Lake } else { 239976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setViewVisibility(R.id.time, View.VISIBLE); 240976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setLong(R.id.time, "setTime", when); 241976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 242976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 243976b6a8c18550ace670e0410453741d11dafa474Ian Lake contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE); 244976b6a8c18550ace670e0410453741d11dafa474Ian Lake return contentView; 245976b6a8c18550ace670e0410453741d11dafa474Ian Lake } 246976b6a8c18550ace670e0410453741d11dafa474Ian Lake} 247