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

Commit 9836a797 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Overflow bubble labels" into rvc-dev am: 38a520e6 am: 22b1d5e2 am: 45b7ef80

Change-Id: I5fa1b9497ac8fc7e3741208ac7ca6c648e67ccbb
parents 6d828089 45b7ef80
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
    android:id="@+id/bubble_overflow_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="@dimen/bubble_overflow_padding"
    android:orientation="vertical"
    android:layout_gravity="center_horizontal">

+41 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2020 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
  -->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/bubble_overflow_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <com.android.systemui.bubbles.BadgedImageView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/bubble_view"
        android:layout_gravity="center"
        android:layout_width="@dimen/individual_bubble_size"
        android:layout_height="@dimen/individual_bubble_size"/>

    <TextView
        android:id="@+id/bubble_view_name"
        android:fontFamily="@*android:string/config_bodyFontFamily"
        android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body2"
        android:textColor="?android:attr/textColorSecondary"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:layout_gravity="center"
        android:gravity="center"/>
</LinearLayout>
+2 −2
Original line number Diff line number Diff line
@@ -1150,8 +1150,8 @@
    <dimen name="bubble_overflow_height">380dp</dimen>
    <!-- Bubble overflow padding when there are no bubbles  -->
    <dimen name="bubble_overflow_empty_state_padding">16dp</dimen>
    <!-- Margin of overflow bubbles -->
    <dimen name="bubble_overflow_margin">16dp</dimen>
    <!-- Padding of container for overflow bubbles -->
    <dimen name="bubble_overflow_padding">5dp</dimen>
    <!-- Height of the triangle that points to the expanded bubble -->
    <dimen name="bubble_pointer_height">4dp</dimen>
    <!-- Width of the triangle that points to the expanded bubble -->
+49 −23
Original line number Diff line number Diff line
@@ -21,14 +21,20 @@ import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_BUBBLES;
import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME;

import android.app.Activity;
import android.app.Notification;
import android.app.Person;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@@ -67,13 +73,22 @@ public class BubbleOverflowActivity extends Activity {

        mEmptyState = findViewById(R.id.bubble_overflow_empty_state);
        mRecyclerView = findViewById(R.id.bubble_overflow_recycler);

        Resources res = getResources();
        final int columns = res.getInteger(R.integer.bubbles_overflow_columns);
        mRecyclerView.setLayoutManager(
                new GridLayoutManager(getApplicationContext(),
                        getResources().getInteger(R.integer.bubbles_overflow_columns)));
                new GridLayoutManager(getApplicationContext(), columns));

        DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        final int viewWidth = displayMetrics.widthPixels / columns;

        final int maxOverflowBubbles = res.getInteger(R.integer.bubbles_max_overflow);
        final int rows = (int) Math.ceil((double) maxOverflowBubbles / columns);
        final int viewHeight = res.getDimensionPixelSize(R.dimen.bubble_overflow_height) / rows;

        int bubbleMargin = getResources().getDimensionPixelSize(R.dimen.bubble_overflow_margin);
        mAdapter = new BubbleOverflowAdapter(mOverflowBubbles,
                mBubbleController::promoteBubbleFromOverflow, bubbleMargin);
                mBubbleController::promoteBubbleFromOverflow, viewWidth, viewHeight);
        mRecyclerView.setAdapter(mAdapter);
        onDataChanged(mBubbleController.getOverflowBubbles());
        mBubbleController.setOverflowCallback(() -> {
@@ -139,39 +154,48 @@ public class BubbleOverflowActivity extends Activity {
class BubbleOverflowAdapter extends RecyclerView.Adapter<BubbleOverflowAdapter.ViewHolder> {
    private Consumer<Bubble> mPromoteBubbleFromOverflow;
    private List<Bubble> mBubbles;
    private int mBubbleMargin;
    private int mWidth;
    private int mHeight;

    public BubbleOverflowAdapter(List<Bubble> list, Consumer<Bubble> promoteBubble,
            int bubbleMargin) {
    public BubbleOverflowAdapter(List<Bubble> list, Consumer<Bubble> promoteBubble, int width,
            int height) {
        mBubbles = list;
        mPromoteBubbleFromOverflow = promoteBubble;
        mBubbleMargin = bubbleMargin;
        mWidth = width;
        mHeight = height;
    }

    @Override
    public BubbleOverflowAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
            int viewType) {
        BadgedImageView view = (BadgedImageView) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.bubble_view, parent, false);
        LinearLayout overflowView = (LinearLayout) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.bubble_overflow_view, parent, false);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
        );
        params.setMargins(mBubbleMargin, mBubbleMargin, mBubbleMargin, mBubbleMargin);
        view.setLayoutParams(params);
        return new ViewHolder(view);
                LinearLayout.LayoutParams.WRAP_CONTENT);
        params.width = mWidth;
        params.height = mHeight;
        overflowView.setLayoutParams(params);
        return new ViewHolder(overflowView);
    }

    @Override
    public void onBindViewHolder(ViewHolder vh, int index) {
        Bubble bubble = mBubbles.get(index);
        Bubble b = mBubbles.get(index);

        vh.mBadgedImageView.update(bubble);
        vh.mBadgedImageView.setOnClickListener(view -> {
            mBubbles.remove(bubble);
        vh.iconView.update(b);
        vh.iconView.setOnClickListener(view -> {
            mBubbles.remove(b);
            notifyDataSetChanged();
            mPromoteBubbleFromOverflow.accept(bubble);
            mPromoteBubbleFromOverflow.accept(b);
        });

        Bubble.FlyoutMessage message = b.getFlyoutMessage();
        if (message != null && message.senderName != null) {
            vh.textView.setText(message.senderName);
        } else {
            vh.textView.setText(b.getAppName());
        }
    }

    @Override
@@ -180,11 +204,13 @@ class BubbleOverflowAdapter extends RecyclerView.Adapter<BubbleOverflowAdapter.V
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public BadgedImageView mBadgedImageView;
        public BadgedImageView iconView;
        public TextView textView;

        public ViewHolder(BadgedImageView v) {
        public ViewHolder(LinearLayout v) {
            super(v);
            mBadgedImageView = v;
            iconView = v.findViewById(R.id.bubble_view);
            textView = v.findViewById(R.id.bubble_view_name);
        }
    }
}
 No newline at end of file