Give some background protection to custom layouts in legacy notifications.
Pre-HC it was extremely common for apps to hardcode text colors in
layouts. Since this can lead to black text on a dark background in
HC/ICS, give these older apps that target SDK < 11 a light gray
background.
Change-Id: Iab3dea4beb9172b2f9a5cae53991cf952d0c8cde
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:exitFadeDuration="@android:integer/config_mediumAnimTime">
+
+ <item android:state_pressed="true" android:drawable="@drawable/notification_item_background_color_pressed" />
+ <item android:state_pressed="false" android:drawable="@drawable/notification_item_background_legacy_color" />
+</selector>
<drawable name="notification_tracking_bg">#d8000000</drawable>
<color name="notification_list_shadow_top">#80000000</color>
<drawable name="recents_callout_line">#99ffffff</drawable>
+ <drawable name="notification_item_background_legacy_color">#ffaaaaaa</drawable>
</resources>
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
+import android.os.Build;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.Handler;
row.setDrawingCacheEnabled(true);
}
+ applyLegacyRowBackground(notification, content);
+
return new View[] { row, content, expanded };
}
row.setDrawingCacheEnabled(true);
}
+ applyLegacyRowBackground(sbn, content);
+
entry.row = row;
entry.content = content;
entry.expanded = expanded;
return true;
}
+ void applyLegacyRowBackground(StatusBarNotification sbn, View content) {
+ if (sbn.notification.contentView.getLayoutId() !=
+ com.android.internal.R.layout.status_bar_latest_event_content) {
+ int version = 0;
+ try {
+ ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(sbn.pkg, 0);
+ version = info.targetSdkVersion;
+ } catch (NameNotFoundException ex) {
+ Slog.e(TAG, "Failed looking up ApplicationInfo for " + sbn.pkg, ex);
+ }
+ if (version > 0 && version < Build.VERSION_CODES.HONEYCOMB) {
+ content.setBackgroundResource(R.drawable.notification_row_legacy_bg);
+ } else {
+ content.setBackgroundResource(R.drawable.notification_row_bg);
+ }
+ }
+ }
+
StatusBarNotification removeNotificationViews(IBinder key) {
NotificationData.Entry entry = mNotificationData.remove(key);
if (entry == null) {
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.inputmethodservice.InputMethodService;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
+import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
}
void workAroundBadLayerDrawableOpacity(View v) {
- LayerDrawable d = (LayerDrawable)v.getBackground();
- if (d == null) return;
+ Drawable bgd = v.getBackground();
+ if (!(bgd instanceof LayerDrawable)) return;
+
+ LayerDrawable d = (LayerDrawable) bgd;
v.setBackgroundDrawable(null);
d.setOpacity(PixelFormat.TRANSLUCENT);
v.setBackgroundDrawable(d);
row.setDrawingCacheEnabled(true);
}
+ applyLegacyRowBackground(sbn, content);
+
entry.row = row;
entry.content = content;
entry.expanded = expanded;
return true;
}
+ void applyLegacyRowBackground(StatusBarNotification sbn, View content) {
+ if (sbn.notification.contentView.getLayoutId() !=
+ com.android.internal.R.layout.status_bar_latest_event_content) {
+ int version = 0;
+ try {
+ ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(sbn.pkg, 0);
+ version = info.targetSdkVersion;
+ } catch (NameNotFoundException ex) {
+ Slog.e(TAG, "Failed looking up ApplicationInfo for " + sbn.pkg, ex);
+ }
+ if (version > 0 && version < Build.VERSION_CODES.HONEYCOMB) {
+ content.setBackgroundResource(R.drawable.notification_row_legacy_bg);
+ } else {
+ content.setBackgroundResource(R.drawable.notification_row_bg);
+ }
+ }
+ }
+
public void clearAll() {
try {
mBarService.onClearAllNotifications();