Skip to content

Commit c40a7fe

Browse files
dsandlerAndroid (Google) Code Review
authored andcommitted
Merge "Fix three-line notifications." into jb-dev
2 parents 1957fd2 + 9f7936a commit c40a7fe

File tree

9 files changed

+105
-75
lines changed

9 files changed

+105
-75
lines changed

core/java/android/app/Notification.java

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import android.content.Context;
2222
import android.content.Intent;
23+
import android.content.res.Resources;
2324
import android.graphics.Bitmap;
2425
import android.media.AudioManager;
2526
import android.net.Uri;
@@ -31,6 +32,8 @@
3132
import android.text.TextUtils;
3233
import android.util.IntProperty;
3334
import android.util.Log;
35+
import android.util.Slog;
36+
import android.util.TypedValue;
3437
import android.view.View;
3538
import android.widget.ProgressBar;
3639
import android.widget.RemoteViews;
@@ -1378,8 +1381,8 @@ private void setFlag(int mask, boolean value) {
13781381

13791382
private RemoteViews applyStandardTemplate(int resId) {
13801383
RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId);
1381-
boolean hasLine3 = false;
1382-
boolean hasLine2 = false;
1384+
boolean showLine3 = false;
1385+
boolean showLine2 = false;
13831386
int smallIconImageViewId = R.id.icon;
13841387
if (mLargeIcon != null) {
13851388
contentView.setImageViewBitmap(R.id.icon, mLargeIcon);
@@ -1401,15 +1404,13 @@ private RemoteViews applyStandardTemplate(int resId) {
14011404
contentView.setTextViewText(R.id.title, mContentTitle);
14021405
}
14031406
if (mContentText != null) {
1404-
contentView.setTextViewText(
1405-
(mSubText != null) ? R.id.text2 : R.id.text,
1406-
mContentText);
1407-
hasLine3 = true;
1407+
contentView.setTextViewText(R.id.text, mContentText);
1408+
showLine3 = true;
14081409
}
14091410
if (mContentInfo != null) {
14101411
contentView.setTextViewText(R.id.info, mContentInfo);
14111412
contentView.setViewVisibility(R.id.info, View.VISIBLE);
1412-
hasLine3 = true;
1413+
showLine3 = true;
14131414
} else if (mNumber > 0) {
14141415
final int tooBig = mContext.getResources().getInteger(
14151416
R.integer.status_bar_notification_info_maxnum);
@@ -1421,25 +1422,42 @@ private RemoteViews applyStandardTemplate(int resId) {
14211422
contentView.setTextViewText(R.id.info, f.format(mNumber));
14221423
}
14231424
contentView.setViewVisibility(R.id.info, View.VISIBLE);
1424-
hasLine3 = true;
1425+
showLine3 = true;
14251426
} else {
14261427
contentView.setViewVisibility(R.id.info, View.GONE);
14271428
}
14281429

1430+
// Need to show three lines?
14291431
if (mSubText != null) {
14301432
contentView.setTextViewText(R.id.text, mSubText);
1431-
contentView.setViewVisibility(R.id.text2,
1432-
mContentText != null ? View.VISIBLE : View.GONE);
1433+
if (mContentText != null) {
1434+
contentView.setTextViewText(R.id.text2, mContentText);
1435+
// need to shrink all the type to make sure everything fits
1436+
contentView.setViewVisibility(R.id.text2, View.VISIBLE);
1437+
showLine2 = true;
1438+
} else {
1439+
contentView.setViewVisibility(R.id.text2, View.GONE);
1440+
}
14331441
} else {
14341442
contentView.setViewVisibility(R.id.text2, View.GONE);
14351443
if (mProgressMax != 0 || mProgressIndeterminate) {
14361444
contentView.setProgressBar(
14371445
R.id.progress, mProgressMax, mProgress, mProgressIndeterminate);
14381446
contentView.setViewVisibility(R.id.progress, View.VISIBLE);
1447+
showLine2 = true;
14391448
} else {
14401449
contentView.setViewVisibility(R.id.progress, View.GONE);
14411450
}
14421451
}
1452+
if (showLine2) {
1453+
final Resources res = mContext.getResources();
1454+
final float subTextSize = res.getDimensionPixelSize(
1455+
R.dimen.notification_subtext_size);
1456+
contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize);
1457+
// vertical centering
1458+
contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
1459+
}
1460+
14431461
if (mWhen != 0) {
14441462
if (mUseChronometer) {
14451463
contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
@@ -1451,7 +1469,7 @@ private RemoteViews applyStandardTemplate(int resId) {
14511469
contentView.setLong(R.id.time, "setTime", mWhen);
14521470
}
14531471
}
1454-
contentView.setViewVisibility(R.id.line3, hasLine3 ? View.VISIBLE : View.GONE);
1472+
contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE);
14551473
return contentView;
14561474
}
14571475

@@ -1629,18 +1647,8 @@ protected RemoteViews getStandardView(int layoutId) {
16291647
mBuilder.setContentTitle(mBigContentTitle);
16301648
}
16311649

1632-
if (mBuilder.mSubText == null) {
1633-
mBuilder.setContentText(null);
1634-
}
1635-
16361650
RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId);
16371651

1638-
if (mBuilder.mSubText == null) {
1639-
contentView.setViewVisibility(R.id.line3, View.GONE);
1640-
} else {
1641-
contentView.setViewVisibility(R.id.line3, View.VISIBLE);
1642-
}
1643-
16441652
if (mBigContentTitle != null && mBigContentTitle.equals("")) {
16451653
contentView.setViewVisibility(R.id.line1, View.GONE);
16461654
} else {
@@ -1650,8 +1658,10 @@ protected RemoteViews getStandardView(int layoutId) {
16501658
if (mSummaryText != null && !mSummaryText.equals("")) {
16511659
contentView.setViewVisibility(R.id.overflow_title, View.VISIBLE);
16521660
contentView.setTextViewText(R.id.overflow_title, mSummaryText);
1661+
contentView.setViewVisibility(R.id.line3, View.GONE);
16531662
} else {
16541663
contentView.setViewVisibility(R.id.overflow_title, View.GONE);
1664+
contentView.setViewVisibility(R.id.line3, View.VISIBLE);
16551665
}
16561666

16571667
return contentView;

core/res/res/layout/notification_template_base.xml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@
3838
android:orientation="vertical"
3939
android:paddingLeft="12dp"
4040
android:paddingRight="12dp"
41-
android:paddingTop="4dp"
42-
android:paddingBottom="4dp"
43-
android:gravity="center_vertical"
41+
android:paddingTop="2dp"
42+
android:paddingBottom="2dp"
43+
android:gravity="top"
4444
>
4545
<LinearLayout
4646
android:id="@+id/line1"
4747
android:layout_width="match_parent"
4848
android:layout_height="wrap_content"
49+
android:paddingTop="6dp"
4950
android:orientation="horizontal"
5051
>
5152
<TextView android:id="@+id/title"
@@ -85,8 +86,15 @@
8586
android:ellipsize="marquee"
8687
android:visibility="gone"
8788
/>
89+
<ProgressBar
90+
android:id="@android:id/progress"
91+
android:layout_width="match_parent"
92+
android:layout_height="12dp"
93+
android:visibility="gone"
94+
style="?android:attr/progressBarStyleHorizontal"
95+
/>
8896
<TextView android:id="@+id/overflow_title"
89-
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
97+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
9098
android:layout_width="match_parent"
9199
android:layout_height="wrap_content"
92100
android:singleLine="true"
@@ -123,21 +131,14 @@
123131
/>
124132
<ImageView android:id="@+id/right_icon"
125133
android:layout_width="wrap_content"
126-
android:layout_height="wrap_content"
134+
android:layout_height="match_parent"
127135
android:layout_gravity="center"
128136
android:layout_weight="0"
129-
android:scaleType="center"
137+
android:scaleType="centerInside"
130138
android:paddingLeft="8dp"
131139
android:visibility="gone"
132140
android:drawableAlpha="180"
133141
/>
134142
</LinearLayout>
135-
<ProgressBar
136-
android:id="@android:id/progress"
137-
android:layout_width="match_parent"
138-
android:layout_height="wrap_content"
139-
android:visibility="gone"
140-
style="?android:attr/progressBarStyleHorizontal"
141-
/>
142143
</LinearLayout>
143144
</FrameLayout>

core/res/res/layout/notification_template_big_base.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
android:orientation="vertical"
3939
android:paddingLeft="12dp"
4040
android:paddingRight="12dp"
41-
android:paddingTop="4dp"
42-
android:paddingBottom="4dp"
43-
android:gravity="center_vertical"
41+
android:paddingTop="2dp"
42+
android:paddingBottom="2dp"
43+
android:gravity="top"
4444
>
4545
<LinearLayout
4646
android:layout_width="match_parent"
@@ -52,6 +52,7 @@
5252
android:id="@+id/line1"
5353
android:layout_width="match_parent"
5454
android:layout_height="wrap_content"
55+
android:paddingTop="6dp"
5556
android:orientation="horizontal"
5657
>
5758
<TextView android:id="@+id/title"
@@ -126,10 +127,10 @@
126127
/>
127128
<ImageView android:id="@+id/right_icon"
128129
android:layout_width="wrap_content"
129-
android:layout_height="wrap_content"
130+
android:layout_height="match_parent"
130131
android:layout_gravity="center"
131132
android:layout_weight="0"
132-
android:scaleType="center"
133+
android:scaleType="centerInside"
133134
android:paddingLeft="8dp"
134135
android:visibility="gone"
135136
android:drawableAlpha="180"
@@ -138,7 +139,7 @@
138139
<ProgressBar
139140
android:id="@android:id/progress"
140141
android:layout_width="match_parent"
141-
android:layout_height="wrap_content"
142+
android:layout_height="12dp"
142143
android:visibility="gone"
143144
style="?android:attr/progressBarStyleHorizontal"
144145
/>

core/res/res/layout/notification_template_big_picture.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
android:layout_gravity="bottom"
3232
android:scaleType="centerCrop"
3333
/>
34+
<ImageView
35+
android:layout_width="match_parent"
36+
android:layout_height="6dp"
37+
android:layout_marginTop="64dp"
38+
android:scaleType="fitXY"
39+
android:src="@drawable/title_bar_shadow"
40+
/>
3441
<include layout="@layout/notification_template_base"
3542
android:layout_width="match_parent"
3643
android:layout_height="wrap_content"

core/res/res/layout/notification_template_big_text.xml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
android:orientation="vertical"
3737
android:paddingLeft="12dp"
3838
android:paddingRight="12dp"
39-
android:paddingTop="4dp"
40-
android:paddingBottom="4dp"
41-
android:gravity="center_vertical"
39+
android:paddingTop="2dp"
40+
android:paddingBottom="2dp"
41+
android:gravity="top"
4242
>
4343
<LinearLayout
4444
android:layout_width="match_parent"
@@ -50,6 +50,7 @@
5050
android:id="@+id/line1"
5151
android:layout_width="match_parent"
5252
android:layout_height="wrap_content"
53+
android:paddingTop="6dp"
5354
android:orientation="horizontal"
5455
android:layout_gravity="top"
5556
android:layout_weight="0"
@@ -92,11 +93,18 @@
9293
android:layout_weight="0"
9394
android:visibility="gone"
9495
/>
96+
<ProgressBar
97+
android:id="@android:id/progress"
98+
android:layout_width="match_parent"
99+
android:layout_height="12dp"
100+
android:visibility="gone"
101+
android:layout_weight="0"
102+
style="?android:attr/progressBarStyleHorizontal"
103+
/>
95104
<TextView android:id="@+id/big_text"
96105
android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
97106
android:layout_width="match_parent"
98107
android:layout_height="0dp"
99-
android:layout_marginTop="2dp"
100108
android:layout_marginBottom="2dp"
101109
android:singleLine="false"
102110
android:visibility="gone"
@@ -113,7 +121,7 @@
113121
android:layout_weight="1"
114122
/>
115123
<TextView android:id="@+id/overflow_title"
116-
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
124+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
117125
android:layout_width="match_parent"
118126
android:layout_height="wrap_content"
119127
android:singleLine="true"
@@ -127,7 +135,7 @@
127135
android:layout_width="match_parent"
128136
android:layout_height="wrap_content"
129137
android:orientation="horizontal"
130-
android:layout_weight="1"
138+
android:layout_weight="0"
131139
>
132140
<TextView android:id="@+id/text"
133141
android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
@@ -151,22 +159,14 @@
151159
/>
152160
<ImageView android:id="@+id/right_icon"
153161
android:layout_width="wrap_content"
154-
android:layout_height="wrap_content"
162+
android:layout_height="match_parent"
155163
android:layout_gravity="center"
156164
android:layout_weight="0"
157-
android:scaleType="center"
165+
android:scaleType="centerInside"
158166
android:paddingLeft="8dp"
159167
android:visibility="gone"
160168
android:drawableAlpha="180"
161169
/>
162170
</LinearLayout>
163-
<ProgressBar
164-
android:id="@android:id/progress"
165-
android:layout_width="match_parent"
166-
android:layout_height="wrap_content"
167-
android:visibility="gone"
168-
android:layout_weight="0"
169-
style="?android:attr/progressBarStyleHorizontal"
170-
/>
171171
</LinearLayout>
172172
</FrameLayout>

0 commit comments

Comments
 (0)