Merge "Badge notification from managed profiles." into lmp-preview-dev
This commit is contained in:
@@ -21,7 +21,10 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
import android.media.session.MediaSessionToken;
|
||||
import android.net.Uri;
|
||||
@@ -32,6 +35,7 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
@@ -2305,7 +2309,23 @@ public class Notification implements Parcelable
|
||||
return this;
|
||||
}
|
||||
|
||||
private Bitmap getProfileBadge() {
|
||||
UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
Drawable badge = userManager.getBadgeForUser(android.os.Process.myUserHandle());
|
||||
if (badge == null) {
|
||||
return null;
|
||||
}
|
||||
final int width = badge.getIntrinsicWidth();
|
||||
final int height = badge.getIntrinsicHeight();
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
badge.setBounds(0, 0, width, height);
|
||||
badge.draw(canvas);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) {
|
||||
Bitmap profileIcon = getProfileBadge();
|
||||
RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId);
|
||||
boolean showLine3 = false;
|
||||
boolean showLine2 = false;
|
||||
@@ -2313,6 +2333,12 @@ public class Notification implements Parcelable
|
||||
if (mPriority < PRIORITY_LOW) {
|
||||
// TODO: Low priority presentation
|
||||
}
|
||||
if (profileIcon != null) {
|
||||
contentView.setImageViewBitmap(R.id.profile_icon, profileIcon);
|
||||
contentView.setViewVisibility(R.id.profile_icon, View.VISIBLE);
|
||||
} else {
|
||||
contentView.setViewVisibility(R.id.profile_icon, View.GONE);
|
||||
}
|
||||
if (mLargeIcon != null) {
|
||||
contentView.setImageViewBitmap(R.id.icon, mLargeIcon);
|
||||
processLargeIcon(mLargeIcon, contentView);
|
||||
|
||||
@@ -690,18 +690,47 @@ public class UserManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the target user is a managed profile of the calling user or the caller
|
||||
* is itself a managed profile, then this returns a drawable to use as a small
|
||||
* icon to include in a view to distinguish it from the original icon.
|
||||
*
|
||||
* @param user The target user.
|
||||
* @return the drawable or null if no drawable is required.
|
||||
* @hide
|
||||
*/
|
||||
public Drawable getBadgeForUser(UserHandle user) {
|
||||
UserInfo userInfo = getUserIfProfile(user.getIdentifier());
|
||||
if (userInfo != null && userInfo.isManagedProfile()) {
|
||||
return Resources.getSystem().getDrawable(
|
||||
com.android.internal.R.drawable.ic_corp_badge);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private int getBadgeResIdForUser(int userHandle) {
|
||||
// Return the framework-provided badge.
|
||||
List<UserInfo> userProfiles = getProfiles(getUserHandle());
|
||||
for (UserInfo user : userProfiles) {
|
||||
if (user.id == userHandle
|
||||
&& user.isManagedProfile()) {
|
||||
return com.android.internal.R.drawable.ic_corp_badge;
|
||||
}
|
||||
UserInfo userInfo = getUserIfProfile(userHandle);
|
||||
if (userInfo != null && userInfo.isManagedProfile()) {
|
||||
return com.android.internal.R.drawable.ic_corp_icon_badge;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UserInfo for userHandle if it exists and is a profile of the current
|
||||
* user or null.
|
||||
*/
|
||||
private UserInfo getUserIfProfile(int userHandle) {
|
||||
List<UserInfo> userProfiles = getProfiles(getUserHandle());
|
||||
for (UserInfo user : userProfiles) {
|
||||
if (user.id == userHandle) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Drawable getMergedDrawable(Drawable icon, Drawable badge) {
|
||||
final int width = icon.getIntrinsicWidth();
|
||||
final int height = icon.getIntrinsicHeight();
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
34
core/res/res/drawable/ic_corp_badge.xml
Normal file
34
core/res/res/drawable/ic_corp_badge.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<!--
|
||||
Copyright (C) 2014 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.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<size
|
||||
android:width="19.0dp"
|
||||
android:height="19.0dp"/>
|
||||
|
||||
<viewport
|
||||
android:viewportWidth="19.0"
|
||||
android:viewportHeight="19.0"/>
|
||||
|
||||
<path
|
||||
android:pathData="M9.5,9.5m-9.5,0.0a9.5,9.5 0.0,1.0 1.0,19.0 0.0a9.5,9.5 0.0,1.0 1.0,-19.0 0.0"
|
||||
android:fill="#FF5722"/>
|
||||
<path
|
||||
android:pathData="M12.667,7.125l-1.583,0.0L11.084,6.333l-0.792,-0.792L8.708,5.5410004L7.917,6.333l0.0,0.792L6.333,7.125c-0.438,0.0 -0.788,0.354 -0.788,0.792l-0.004,4.354c0.0,0.438 0.354,0.792 0.792,0.792l6.333,0.0c0.438,0.0 0.792,-0.354 0.792,-0.792L13.458,7.917C13.458,7.479 13.104,7.125 12.667,7.125zM10.094,10.687L8.906,10.687L8.906,9.5l1.188,0.0L10.094,10.687zM10.292,7.125L8.708,7.125L8.708,6.333l1.583,0.0L10.291,7.125z"
|
||||
android:fill="#FFFFFF"/>
|
||||
<path
|
||||
android:pathData="M4.75,4.75 h9.5 v9.5 h-9.5z"
|
||||
android:fill="#00000000"/>
|
||||
</vector>
|
||||
40
core/res/res/drawable/ic_corp_icon_badge.xml
Normal file
40
core/res/res/drawable/ic_corp_icon_badge.xml
Normal file
@@ -0,0 +1,40 @@
|
||||
<!--
|
||||
Copyright (C) 2014 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.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<size
|
||||
android:width="64.0dp"
|
||||
android:height="64.0dp"/>
|
||||
|
||||
<viewport
|
||||
android:viewportWidth="64.0"
|
||||
android:viewportHeight="64.0"/>
|
||||
|
||||
<path
|
||||
android:fill="#FF000000"
|
||||
android:pathData="M49.062,50.0m-14.0,0.0a14.0,14.0 0.0,1.0 1.0,28.0 0.0a14.0,14.0 0.0,1.0 1.0,-28.0 0.0"/>
|
||||
<path
|
||||
android:fill="#FF000000"
|
||||
android:pathData="M49.0,49.5m-14.0,0.0a14.0,14.0 0.0,1.0 1.0,28.0 0.0a14.0,14.0 0.0,1.0 1.0,-28.0 0.0"/>
|
||||
<path
|
||||
android:pathData="M49.0,49.0m-14.0,0.0a14.0,14.0 0.0,1.0 1.0,28.0 0.0a14.0,14.0 0.0,1.0 1.0,-28.0 0.0"
|
||||
android:fill="#FF5722"/>
|
||||
<path
|
||||
android:pathData="M53.667,45.5l-2.333,0.0l0.0,-1.167l-1.167,-1.167l-2.333,0.0l-1.167,1.167L46.667,45.5l-2.333,0.0c-0.645,0.0 -1.161,0.522 -1.161,1.167l-0.006,6.417c0.0,0.645 0.522,1.167 1.167,1.167l9.333,0.0c0.645,0.0 1.167,-0.522 1.167,-1.167l0.0,-6.417C54.833,46.022 54.311,45.5 53.667,45.5zM49.875,50.75l-1.75,0.0L48.125,49.0l1.75,0.0L49.875,50.75zM50.167,45.5l-2.333,0.0l0.0,-1.167l2.333,0.0L50.167,45.5z"
|
||||
android:fill="#FFFFFF"/>
|
||||
<path
|
||||
android:pathData="M42.0,42.0 h14.0 v14.0 h-14.0z"
|
||||
android:fill="#00000000"/>
|
||||
</vector>
|
||||
@@ -120,6 +120,15 @@
|
||||
android:gravity="center"
|
||||
android:paddingStart="8dp"
|
||||
/>
|
||||
<ImageView android:id="@+id/profile_icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="0"
|
||||
android:layout_marginStart="8dp"
|
||||
android:scaleType="centerInside"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
@@ -127,6 +127,15 @@
|
||||
android:gravity="center"
|
||||
android:paddingStart="8dp"
|
||||
/>
|
||||
<ImageView android:id="@+id/profile_icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="0"
|
||||
android:layout_marginStart="8dp"
|
||||
android:scaleType="centerInside"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<ProgressBar
|
||||
android:id="@android:id/progress"
|
||||
|
||||
@@ -165,6 +165,15 @@
|
||||
android:gravity="center"
|
||||
android:paddingStart="8dp"
|
||||
/>
|
||||
<ImageView android:id="@+id/profile_icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="0"
|
||||
android:layout_marginStart="8dp"
|
||||
android:scaleType="centerInside"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
@@ -249,6 +249,15 @@
|
||||
android:gravity="center"
|
||||
android:paddingStart="8dp"
|
||||
/>
|
||||
<ImageView android:id="@+id/profile_icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="0"
|
||||
android:layout_marginStart="8dp"
|
||||
android:scaleType="centerInside"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
<item type="id" name="empty" />
|
||||
<item type="id" name="hint" />
|
||||
<item type="id" name="icon" />
|
||||
<item type="id" name="icon_badge" />
|
||||
<item type="id" name="icon1" />
|
||||
<item type="id" name="icon2" />
|
||||
<item type="id" name="input" />
|
||||
|
||||
@@ -217,6 +217,7 @@
|
||||
<java-symbol type="id" name="pin_confirm_text" />
|
||||
<java-symbol type="id" name="pin_error_message" />
|
||||
<java-symbol type="id" name="timePickerLayout" />
|
||||
<java-symbol type="id" name="profile_icon" />
|
||||
|
||||
<java-symbol type="attr" name="actionModeShareDrawable" />
|
||||
<java-symbol type="attr" name="alertDialogCenterButtons" />
|
||||
@@ -1119,6 +1120,7 @@
|
||||
<java-symbol type="drawable" name="cling_arrow_up" />
|
||||
<java-symbol type="drawable" name="cling_bg" />
|
||||
<java-symbol type="drawable" name="ic_corp_badge" />
|
||||
<java-symbol type="drawable" name="ic_corp_icon_badge" />
|
||||
|
||||
<java-symbol type="layout" name="action_bar_home" />
|
||||
<java-symbol type="layout" name="action_bar_title_item" />
|
||||
|
||||
@@ -992,7 +992,10 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
title.setText(entry.notification.getPackageName());
|
||||
}
|
||||
|
||||
final ImageView icon = (ImageView) publicViewLocal.findViewById(com.android.internal.R.id.icon);
|
||||
final ImageView icon = (ImageView) publicViewLocal.findViewById(
|
||||
com.android.internal.R.id.icon);
|
||||
final ImageView profileIcon = (ImageView) publicViewLocal.findViewById(
|
||||
com.android.internal.R.id.profile_icon);
|
||||
|
||||
final StatusBarIcon ic = new StatusBarIcon(entry.notification.getPackageName(),
|
||||
entry.notification.getUser(),
|
||||
@@ -1008,7 +1011,19 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
com.android.internal.R.drawable.notification_icon_legacy_bg_inset);
|
||||
}
|
||||
|
||||
final TextView text = (TextView) publicViewLocal.findViewById(com.android.internal.R.id.text);
|
||||
if (profileIcon != null) {
|
||||
Drawable profileDrawable
|
||||
= mUserManager.getBadgeForUser(entry.notification.getUser());
|
||||
if (profileDrawable != null) {
|
||||
profileIcon.setImageDrawable(profileDrawable);
|
||||
profileIcon.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
profileIcon.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
final TextView text = (TextView) publicViewLocal.findViewById(
|
||||
com.android.internal.R.id.text);
|
||||
text.setText("Unlock your device to see this notification.");
|
||||
|
||||
// TODO: fill out "time" as well
|
||||
|
||||
@@ -1187,7 +1187,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
||||
Entry ent = mNotificationData.get(i);
|
||||
if (!(provisioned || showNotificationEvenIfUnprovisioned(ent.notification))) continue;
|
||||
|
||||
// TODO How do we want to badge notifcations from profiles.
|
||||
if (!notificationIsForCurrentProfiles(ent.notification)) continue;
|
||||
|
||||
final int vis = ent.notification.getNotification().visibility;
|
||||
|
||||
Reference in New Issue
Block a user