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

Commit c26ff124 authored by Lyn Han's avatar Lyn Han
Browse files

Replace bubble header with adaptive settings icon

Bug: 128010178
Test: manual
Change-Id: Ia0a0f72d7ed1da3fd7dbdcff235cf0bcb39100c4
parent de11a5ae
Loading
Loading
Loading
Loading
+7 −29
Original line number Diff line number Diff line
@@ -33,35 +33,13 @@
        android:layout_height="wrap_content"
        android:animateLayoutChanges="true">

        <LinearLayout
            android:id="@+id/header_layout"
            android:layout_height="@dimen/bubble_expanded_header_height"
            android:layout_width="match_parent"
            android:animateLayoutChanges="true"
            android:gravity="end|center_vertical"
            android:orientation="horizontal">

            <ImageButton
                android:id="@+id/deep_link_button"
                android:layout_width="@dimen/bubble_header_icon_size"
                android:layout_height="@dimen/bubble_header_icon_size"
                android:src="@drawable/ic_open_in_new"
                android:scaleType="center"
                android:tint="?android:attr/colorForeground"
                android:background="?android:attr/selectableItemBackground"
            />

            <ImageButton
                android:id="@id/settings_button"
        <ImageView
            android:id="@+id/settings_button"
            android:layout_width="@dimen/bubble_header_icon_size"
            android:layout_height="@dimen/bubble_header_icon_size"
            android:src="@drawable/ic_settings"
            android:scaleType="center"
                android:tint="?android:attr/colorForeground"
                android:background="?android:attr/selectableItemBackground"
            />

        </LinearLayout>
            android:layout_gravity="end"/>

        <include layout="@layout/bubble_permission_view"
                 android:id="@+id/permission_layout"
+36 −37
Original line number Diff line number Diff line
@@ -38,8 +38,11 @@ import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -53,7 +56,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -80,10 +82,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
    private View mPointerView;
    private int mPointerMargin;

    // Header
    private View mHeaderView;
    private ImageButton mDeepLinkIcon;
    private ImageButton mSettingsIcon;
    private ImageView mSettingsIcon;

    // Permission view
    private View mPermissionView;
@@ -195,7 +194,6 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        mPointerView.setBackground(triangleDrawable);

        FrameLayout viewWrapper = findViewById(R.id.header_permission_wrapper);
        viewWrapper.setBackground(createHeaderPermissionBackground(bgColor));

        LayoutTransition transition = new LayoutTransition();
        transition.setDuration(200);
@@ -212,18 +210,16 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        viewWrapper.setLayoutTransition(transition);
        viewWrapper.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);


        mHeaderHeight = getContext().getResources().getDimensionPixelSize(
                R.dimen.bubble_expanded_header_height);
        mPermissionHeight = getContext().getResources().getDimensionPixelSize(
                R.dimen.bubble_permission_height);
        mHeaderView = findViewById(R.id.header_layout);
        mDeepLinkIcon = findViewById(R.id.deep_link_button);

        mPermissionView = findViewById(R.id.permission_layout);
        mSettingsIcon = findViewById(R.id.settings_button);
        mDeepLinkIcon.setOnClickListener(this);
        mSettingsIcon.setOnClickListener(this);
        updateHeaderColor();

        mPermissionView = findViewById(R.id.permission_layout);
        findViewById(R.id.no_bubbles_button).setOnClickListener(this);
        findViewById(R.id.yes_bubbles_button).setOnClickListener(this);

@@ -381,25 +377,31 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
    }

    /**
     * Update header color when user toggles dark mode.
     * Update header color and icon shape when theme changes.
     */
    void updateHeaderColor() {
        TypedArray ta = mContext.obtainStyledAttributes(
                new int[] {android.R.attr.colorBackgroundFloating, android.R.attr.colorForeground});
        int bgColor = ta.getColor(0, Color.WHITE /* default */);
        int btnColor = ta.getColor(1, Color.BLACK /* default */);
        int backgroundColor = ta.getColor(0, Color.WHITE /* default */);
        int foregroundColor = ta.getColor(1, Color.BLACK /* default */);
        ta.recycle();

        mHeaderView.setBackgroundColor(bgColor);
        mSettingsIcon.setColorFilter(btnColor);
        mDeepLinkIcon.setColorFilter(btnColor);
        mPermissionView.setBackground(createHeaderPermissionBackground(backgroundColor));

        Drawable settingsIcon =  mSettingsIcon.getDrawable();
        settingsIcon.setTint(foregroundColor);

        int mIconInset = getResources().getDimensionPixelSize(R.dimen.bubble_icon_inset);
        InsetDrawable foreground = new InsetDrawable(settingsIcon, mIconInset);
        ColorDrawable background = new ColorDrawable(backgroundColor);
        AdaptiveIconDrawable adaptiveIcon = new AdaptiveIconDrawable(background,
                foreground);
        mSettingsIcon.setImageDrawable(adaptiveIcon);
    }

    private void updateHeaderView() {
        mSettingsIcon.setContentDescription(getResources().getString(
                R.string.bubbles_settings_button_description, mAppName));
        mDeepLinkIcon.setContentDescription(getResources().getString(
                R.string.bubbles_deep_link_button_description, mAppName));
    }

    private void updatePermissionView() {
@@ -412,11 +414,9 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
            Log.w(TAG, e);
        }
        if (hasUserApprovedBubblesForPackage) {
            mHeaderView.setVisibility(VISIBLE);
            mPermissionView.setVisibility(GONE);
            showSettingsIcon();
        } else {
            mHeaderView.setVisibility(GONE);
            mPermissionView.setVisibility(VISIBLE);
            showPermissionView();
            ((ImageView) mPermissionView.findViewById(R.id.pkgicon)).setImageDrawable(mAppIcon);
            ((TextView) mPermissionView.findViewById(R.id.pkgname)).setText(mAppName);
            ((TextView) mPermissionView.findViewById(R.id.prompt)).setText(
@@ -513,18 +513,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        }
        Notification n = mEntry.notification.getNotification();
        int id = view.getId();
        if (id == R.id.deep_link_button) {
            mStackView.collapseStack(() -> {
                try {
                    n.contentIntent.send();
                    logBubbleClickEvent(mEntry,
                            StatsLog.BUBBLE_UICHANGED__ACTION__HEADER_GO_TO_APP);
                } catch (PendingIntent.CanceledException e) {
                    Log.w(TAG, "Failed to send intent for bubble with key: "
                            + (mEntry != null ? mEntry.key : " null entry"));
                }
            });
        } else if (id == R.id.settings_button) {
        if (id == R.id.settings_button) {
            Intent intent = getSettingsIntent(mEntry.notification.getPackageName(),
                    mEntry.notification.getUid());
            mStackView.collapseStack(() -> {
@@ -546,8 +535,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
                    mEntry.notification.getUid(),
                    allowed);
            if (allowed) {
                mPermissionView.setVisibility(GONE);
                mHeaderView.setVisibility(VISIBLE);
                showSettingsIcon();
            } else if (mOnBubbleBlockedListener != null) {
                mOnBubbleBlockedListener.onBubbleBlocked(mEntry);
            }
@@ -560,6 +548,17 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        }
    }

    void showSettingsIcon() {
        mPermissionView.setVisibility(GONE);
        mSettingsIcon.setVisibility(VISIBLE);
    }

    void showPermissionView() {
        mSettingsIcon.setVisibility(GONE);
        mPermissionView.setVisibility(VISIBLE);

    }

    /**
     * Update appearance of the expanded view being displayed.
     */