Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d991c048 authored by Steve Elliott's avatar Steve Elliott
Browse files

Minified people row

Bug: 146664602
Test: manual, atest
Change-Id: Id007cc64a6d37dea51bbdd5d70d7eac4df7556ac
parent b47f1c7d
Loading
Loading
Loading
Loading
+41 −181
Original line number Diff line number Diff line
@@ -18,7 +18,10 @@
<com.android.systemui.statusbar.notification.stack.PeopleHubView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="105dp">
    android:layout_height="@dimen/notification_section_header_height"
    android:focusable="true"
    android:clickable="true"
>

    <com.android.systemui.statusbar.notification.row.NotificationBackgroundView
        android:id="@+id/backgroundNormal"
@@ -34,199 +37,56 @@
        android:id="@+id/people_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="12dp"
        android:paddingBottom="12dp"
        android:gravity="center"
        android:orientation="horizontal">

        <View
            android:layout_width="8dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
        />

        <LinearLayout
            android:layout_width="70dp"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:orientation="vertical"
            android:visibility="invisible">

            <ImageView
                android:id="@+id/person_icon"
                android:layout_width="36dp"
                android:layout_height="36dp"
                android:scaleType="fitCenter"
            />

        <TextView
                android:id="@+id/person_name"
                android:layout_width="match_parent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
                android:paddingTop="8dp"
                android:ellipsize="end"
                android:maxLines="2"
                android:textAlignment="center"
            />

        </LinearLayout>

        <View
            android:layout_width="8dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_marginStart="@dimen/notification_section_header_padding_left"
            android:gravity="start"
            android:textAlignment="gravity"
            android:text="@string/notification_section_header_conversations"
            android:textSize="12sp"
            android:textColor="@color/notification_section_header_label_color"
            android:fontFamily="@*android:string/config_headlineFontFamilyMedium"
        />

        <View
            android:layout_width="8dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
        />

        <LinearLayout
            android:layout_width="70dp"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:orientation="vertical"
            android:visibility="invisible">

        <ImageView
                android:id="@+id/person_icon"
                android:layout_width="36dp"
                android:layout_height="36dp"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:padding="8dp"
            android:scaleType="fitCenter"
        />

            <TextView
                android:id="@+id/person_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingTop="8dp"
                android:ellipsize="end"
                android:maxLines="2"
                android:textAlignment="center"
            />

        </LinearLayout>

        <View
            android:layout_width="8dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
        />

        <View
            android:layout_width="8dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
        />

        <LinearLayout
            android:layout_width="70dp"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:orientation="vertical"
            android:visibility="invisible">

        <ImageView
                android:id="@+id/person_icon"
                android:layout_width="36dp"
                android:layout_height="36dp"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:padding="8dp"
            android:scaleType="fitCenter"
        />

            <TextView
                android:id="@+id/person_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingTop="8dp"
                android:ellipsize="end"
                android:maxLines="2"
                android:textAlignment="center"
            />

        </LinearLayout>

        <View
            android:layout_width="8dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
        />

        <View
            android:layout_width="8dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
        />

        <LinearLayout
            android:layout_width="70dp"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:orientation="vertical"
            android:visibility="invisible">

        <ImageView
                android:id="@+id/person_icon"
                android:layout_width="36dp"
                android:layout_height="36dp"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:padding="8dp"
            android:scaleType="fitCenter"
        />

            <TextView
                android:id="@+id/person_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingTop="8dp"
                android:ellipsize="end"
                android:maxLines="2"
                android:textAlignment="center"
            />

        </LinearLayout>

        <View
            android:layout_width="8dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
        />

        <View
            android:layout_width="8dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
        />

        <LinearLayout
            android:layout_width="70dp"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:orientation="vertical"
            android:visibility="invisible">

        <ImageView
                android:id="@+id/person_icon"
                android:layout_width="36dp"
                android:layout_height="36dp"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:padding="8dp"
            android:scaleType="fitCenter"
        />

            <TextView
                android:id="@+id/person_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingTop="8dp"
                android:ellipsize="end"
                android:maxLines="2"
                android:textAlignment="center"
            />

        </LinearLayout>

        <View
            android:layout_width="8dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
        <ImageView
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_marginEnd="8dp"
            android:padding="8dp"
            android:scaleType="fitCenter"
        />

    </LinearLayout>
+3 −0
Original line number Diff line number Diff line
@@ -1163,6 +1163,9 @@
    <!-- Section title for notifications that do not vibrate or make noise. [CHAR LIMIT=40] -->
    <string name="notification_section_header_gentle">Silent notifications</string>

    <!-- Section title for conversational notifications. [CHAR LIMIT=40] -->
    <string name="notification_section_header_conversations">Conversations</string>

    <!-- Content description for accessibility: Tapping this button will dismiss all gentle notifications [CHAR LIMIT=NONE] -->
    <string name="accessibility_notification_section_header_gentle_clear_all">Clear all silent notifications</string>

+6 −72
Original line number Diff line number Diff line
@@ -17,24 +17,16 @@
package com.android.systemui.statusbar.notification.people

import android.app.Notification
import android.content.Context
import android.content.pm.UserInfo
import android.graphics.Canvas
import android.graphics.ColorFilter
import android.graphics.PixelFormat
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.UserHandle
import android.os.UserManager
import android.service.notification.StatusBarNotification
import android.util.SparseArray
import android.util.TypedValue
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.android.internal.statusbar.NotificationVisibility
import com.android.internal.widget.MessagingGroup
import com.android.launcher3.icons.BaseIconFactory
import com.android.systemui.R
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
@@ -59,8 +51,7 @@ interface NotificationPersonExtractor {

@Singleton
class NotificationPersonExtractorPluginBoundary @Inject constructor(
    extensionController: ExtensionController,
    private val context: Context
    extensionController: ExtensionController
) : NotificationPersonExtractor {

    private var plugin: NotificationPersonExtractorPlugin? = null
@@ -77,9 +68,8 @@ class NotificationPersonExtractorPluginBoundary @Inject constructor(
    }

    override fun extractPerson(sbn: StatusBarNotification) =
            plugin?.extractPerson(sbn)?.let { data ->
                val badged = addBadgeToDrawable(data.avatar, context, sbn.packageName, sbn.user)
                PersonModel(data.key, data.name, badged, data.clickIntent, sbn.user.identifier)
            plugin?.extractPerson(sbn)?.run {
                PersonModel(key, name, avatar, clickIntent, sbn.user.identifier)
            }

    override fun extractPersonKey(sbn: StatusBarNotification) = plugin?.extractPersonKey(sbn)
@@ -214,7 +204,7 @@ class PeopleHubManager {
            if (inactivePeople.size >= MAX_STORED_INACTIVE_PEOPLE) {
                inactivePeople.removeLast()
            }
            inactivePeople.push(data)
            inactivePeople.add(data)
            return true
        }
        return false
@@ -247,63 +237,7 @@ private fun NotificationEntry.extractPerson(): PersonModel? {
            ?: extras.getString(Notification.EXTRA_TITLE)
            ?: return null
    val drawable = extractAvatarFromRow(this) ?: return null
    val badgedAvatar = addBadgeToDrawable(drawable, row.context, sbn.packageName, sbn.user)
    return PersonModel(key, name, badgedAvatar, clickIntent, sbn.user.identifier)
}

private fun addBadgeToDrawable(
    drawable: Drawable,
    context: Context,
    packageName: String,
    user: UserHandle
): Drawable {
    val pm = context.packageManager
    val appInfo = pm.getApplicationInfoAsUser(packageName, 0, user)
    return object : Drawable() {
        override fun draw(canvas: Canvas) {
            val iconBounds = getBounds()
            val factory = object : BaseIconFactory(
                    context,
                    0 /* unused */,
                    iconBounds.width(),
                    true) {}
            val badge = factory.createBadgedIconBitmap(
                    appInfo.loadIcon(pm),
                    user,
                    true,
                    appInfo.isInstantApp,
                    null)
            val badgeDrawable = BitmapDrawable(context.resources, badge.icon)
                    .apply {
                        alpha = drawable.alpha
                        colorFilter = drawable.colorFilter
                        val badgeWidth = TypedValue.applyDimension(
                                TypedValue.COMPLEX_UNIT_DIP,
                                15f,
                                context.resources.displayMetrics
                        ).toInt()
                        setBounds(
                                iconBounds.left + (iconBounds.width() - badgeWidth),
                                iconBounds.top + (iconBounds.height() - badgeWidth),
                                iconBounds.right,
                                iconBounds.bottom)
                    }
            drawable.bounds = iconBounds
            drawable.draw(canvas)
            badgeDrawable.draw(canvas)
        }

        override fun setAlpha(alpha: Int) {
            drawable.alpha = alpha
        }

        override fun setColorFilter(colorFilter: ColorFilter?) {
            drawable.colorFilter = colorFilter
        }

        @PixelFormat.Opacity
        override fun getOpacity(): Int = PixelFormat.OPAQUE
    }
    return PersonModel(key, name, drawable, clickIntent, sbn.user.identifier)
}

fun extractAvatarFromRow(entry: NotificationEntry): Drawable? =
+34 −19
Original line number Diff line number Diff line
@@ -187,18 +187,18 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
    @Override
    public boolean beginsSection(@NonNull View view, @Nullable View previous) {
        boolean begin = false;
        if (view instanceof ExpandableNotificationRow) {
            if (previous instanceof ExpandableNotificationRow) {
        if (view instanceof ActivatableNotificationView) {
            if (previous instanceof ActivatableNotificationView) {
                // If we're drawing the first non-person notification, break out a section
                ExpandableNotificationRow curr = (ExpandableNotificationRow) view;
                ExpandableNotificationRow prev = (ExpandableNotificationRow) previous;
                ActivatableNotificationView curr = (ActivatableNotificationView) view;
                ActivatableNotificationView prev = (ActivatableNotificationView) previous;

                begin =  curr.getEntry().getBucket() != prev.getEntry().getBucket();
                begin = getBucket(curr) != getBucket(prev);
            }
        }

        if (!begin) {
            begin = view == mGentleHeader || previous == mPeopleHubView;
            begin = view == mGentleHeader || view == mPeopleHubView;
        }

        return begin;
@@ -230,29 +230,42 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
            return;
        }

        int lastPersonIndex = -1;
        int firstGentleNotifIndex = -1;
        boolean peopleNotificationsPresent = false;
        int firstNonHeadsUpIndex = -1;
        int firstGentleIndex = -1;
        int notifCount = 0;

        final int n = mParent.getChildCount();
        for (int i = 0; i < n; i++) {
            View child = mParent.getChildAt(i);
            if (child instanceof ExpandableNotificationRow
                    && child.getVisibility() != View.GONE) {
            if (child instanceof ExpandableNotificationRow && child.getVisibility() != View.GONE) {
                notifCount++;
                ExpandableNotificationRow row = (ExpandableNotificationRow) child;
                if (firstNonHeadsUpIndex == -1 && !row.isHeadsUp()) {
                    firstNonHeadsUpIndex = i;
                }
                if (row.getEntry().getBucket() == BUCKET_PEOPLE) {
                    lastPersonIndex = i;
                    peopleNotificationsPresent = true;
                }
                if (row.getEntry().getBucket() == BUCKET_SILENT) {
                    firstGentleNotifIndex = i;
                    firstGentleIndex = i;
                    break;
                }
            }
        }

        if (firstNonHeadsUpIndex == -1) {
            firstNonHeadsUpIndex = firstGentleIndex != -1 ? firstGentleIndex : notifCount;
        }

        // make room for peopleHub
        firstGentleNotifIndex += adjustPeopleHubVisibilityAndPosition(lastPersonIndex);
        int offset = adjustPeopleHubVisibilityAndPosition(
                firstNonHeadsUpIndex, peopleNotificationsPresent);
        if (firstGentleIndex != -1) {
            firstGentleIndex += offset;
        }

        adjustGentleHeaderVisibilityAndPosition(firstGentleNotifIndex);
        adjustGentleHeaderVisibilityAndPosition(firstGentleIndex);

        mGentleHeader.setAreThereDismissableGentleNotifs(
                mParent.hasActiveClearableNotifications(ROWS_GENTLE));
@@ -294,13 +307,15 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
        }
    }

    private int adjustPeopleHubVisibilityAndPosition(int lastPersonIndex) {
        final boolean showPeopleHeader = mPeopleHubVisible
                && mNumberOfSections > 2
                && mStatusBarStateController.getState() != StatusBarState.KEYGUARD;
    private int adjustPeopleHubVisibilityAndPosition(
            int targetIndex, boolean peopleNotificationsPresent) {
        final boolean showPeopleHeader = mNumberOfSections > 2
                && mStatusBarStateController.getState() != StatusBarState.KEYGUARD
                && (peopleNotificationsPresent || mPeopleHubVisible);
        final int currentHubIndex = mParent.indexOfChild(mPeopleHubView);
        final boolean currentlyVisible = currentHubIndex >= 0;
        int targetIndex = lastPersonIndex + 1;

        mPeopleHubView.setCanSwipe(showPeopleHeader && !peopleNotificationsPresent);

        if (!showPeopleHeader) {
            if (currentlyVisible) {
+3 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.SwipeHelper;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.ExpandableView;

class NotificationSwipeHelper extends SwipeHelper implements NotificationSwipeActionHelper {
@@ -298,8 +299,8 @@ class NotificationSwipeHelper extends SwipeHelper implements NotificationSwipeAc
    @Override
    public Animator getViewTranslationAnimator(View v, float target,
            ValueAnimator.AnimatorUpdateListener listener) {
        if (v instanceof SwipeableView) {
            return ((SwipeableView) v).getTranslateViewAnimator(target, listener);
        if (v instanceof ExpandableNotificationRow) {
            return ((ExpandableNotificationRow) v).getTranslateViewAnimator(target, listener);
        } else {
            return superGetViewTranslationAnimator(v, target, listener);
        }
Loading