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

Commit 43c2cd1a authored by Mady Mellor's avatar Mady Mellor
Browse files

Create + implement plugin for NotificationSettingsIconRow

This will allow plugins to supply additional menu options to the
menu "behind" a notification.

This CL does not include behavior for when one of these new menu
items is tapped, this will be added in a separate CL.

Test: manual
Change-Id: I322f9f39d33b043bd23dcbede5dd15e6afa73fc1
parent 1597e054
Loading
Loading
Loading
Loading
+43 −0
Original line number Original line Diff line number Diff line

package com.android.systemui.plugins.statusbar;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;

import java.util.ArrayList;

import com.android.systemui.plugins.Plugin;

public interface NotificationMenuRowProvider extends Plugin {

    public static final String ACTION = "com.android.systemui.action.PLUGIN_NOTIFICATION_MENU_ROW";

    public static final int VERSION = 1;

    /**
     * Returns a list of items to populate the menu 'behind' a notification.
     */
    public ArrayList<MenuItem> getMenuItems(Context context);

    public interface OnMenuClickListener {
        public void onMenuClicked(View row, int x, int y, MenuItem menu);

        public void onMenuReset(View row);
    }

    public static class MenuItem {
        public Drawable icon;
        public String menuDescription;
        public View menuView;

        public MenuItem(Drawable i, String s) {
            icon = i;
            menuDescription = s;
        }

        public boolean onTouch(View v, int x, int y) {
            return false;
        }
    }
}
+2 −16
Original line number Original line Diff line number Diff line
@@ -17,20 +17,6 @@
<com.android.systemui.statusbar.NotificationSettingsIconRow
<com.android.systemui.statusbar.NotificationSettingsIconRow
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:systemui="http://schemas.android.com/apk/res-auto"
    xmlns:systemui="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="invisible"
    android:visibility="invisible"/>
    >
 No newline at end of file

    <com.android.systemui.statusbar.AlphaOptimizedImageView
        android:id="@+id/gear_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/notification_gear_padding"
        android:src="@drawable/ic_settings"
        android:tint="@color/notification_gear_color"
        android:alpha="0"
        android:background="?android:attr/selectableItemBackgroundBorderless"
        />

</com.android.systemui.statusbar.NotificationSettingsIconRow>
 No newline at end of file
+1 −1
Original line number Original line Diff line number Diff line
@@ -27,7 +27,7 @@
        android:layout="@layout/notification_settings_icon_row"
        android:layout="@layout/notification_settings_icon_row"
        android:id="@+id/settings_icon_row_stub"
        android:id="@+id/settings_icon_row_stub"
        android:inflatedId="@+id/notification_settings_icon_row"
        android:inflatedId="@+id/notification_settings_icon_row"
        android:layout_width="wrap_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_height="match_parent"
        />
        />


+5 −2
Original line number Original line Diff line number Diff line
@@ -1375,8 +1375,11 @@
    <!-- Notification: Control panel: Label for button that dismisses control panel. [CHAR LIMIT=NONE] -->
    <!-- Notification: Control panel: Label for button that dismisses control panel. [CHAR LIMIT=NONE] -->
    <string name="notification_done">Done</string>
    <string name="notification_done">Done</string>


    <!-- Notification: Gear: Content description for the gear. [CHAR LIMIT=NONE] -->
    <!-- Notification: Menu row: Content description for menu items. [CHAR LIMIT=NONE] -->
    <string name="notification_gear_accessibility"><xliff:g id="app_name" example="YouTube">%1$s</xliff:g> notification controls</string>
    <string name="notification_menu_accessibility"><xliff:g id="app_name" example="YouTube">%1$s</xliff:g> <xliff:g id="menu_description" example="notification controls">%2$s</xliff:g></string>

    <!-- Notification: Menu row: Content description for the gear menu item. [CHAR LIMIT=NONE] -->
    <string name="notification_menu_gear_description">notification controls</string>


    <!-- Title of the battery settings detail panel [CHAR LIMIT=20] -->
    <!-- Title of the battery settings detail panel [CHAR LIMIT=20] -->
    <string name="battery_panel_title">Battery usage</string>
    <string name="battery_panel_title">Battery usage</string>
+15 −2
Original line number Original line Diff line number Diff line
@@ -32,7 +32,9 @@ import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityEvent;


import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.plugins.statusbar.NotificationMenuRowProvider.MenuItem;
import com.android.systemui.statusbar.FlingAnimationUtils;
import com.android.systemui.statusbar.FlingAnimationUtils;
import com.android.systemui.statusbar.NotificationSettingsIconRow;


import java.util.HashMap;
import java.util.HashMap;


@@ -85,10 +87,12 @@ public class SwipeHelper implements Gefingerpoken {
    private int mFalsingThreshold;
    private int mFalsingThreshold;
    private boolean mTouchAboveFalsingThreshold;
    private boolean mTouchAboveFalsingThreshold;
    private boolean mDisableHwLayers;
    private boolean mDisableHwLayers;
    private Context mContext;


    private HashMap<View, Animator> mDismissPendingMap = new HashMap<>();
    private HashMap<View, Animator> mDismissPendingMap = new HashMap<>();


    public SwipeHelper(int swipeDirection, Callback callback, Context context) {
    public SwipeHelper(int swipeDirection, Callback callback, Context context) {
        mContext = context;
        mCallback = callback;
        mCallback = callback;
        mHandler = new Handler();
        mHandler = new Handler();
        mSwipeDirection = swipeDirection;
        mSwipeDirection = swipeDirection;
@@ -249,6 +253,7 @@ public class SwipeHelper implements Gefingerpoken {
        }
        }
    }
    }


    @Override
    public boolean onInterceptTouchEvent(final MotionEvent ev) {
    public boolean onInterceptTouchEvent(final MotionEvent ev) {
        final int action = ev.getAction();
        final int action = ev.getAction();


@@ -280,7 +285,9 @@ public class SwipeHelper implements Gefingerpoken {
                                        mCurrView.getLocationOnScreen(mTmpPos);
                                        mCurrView.getLocationOnScreen(mTmpPos);
                                        final int x = (int) ev.getRawX() - mTmpPos[0];
                                        final int x = (int) ev.getRawX() - mTmpPos[0];
                                        final int y = (int) ev.getRawY() - mTmpPos[1];
                                        final int y = (int) ev.getRawY() - mTmpPos[1];
                                        mLongPressListener.onLongPress(mCurrView, x, y);
                                        mLongPressListener.onLongPress(mCurrView, x, y,
                                                NotificationSettingsIconRow
                                                        .getSettingsMenuItem(mContext));
                                    }
                                    }
                                }
                                }
                            };
                            };
@@ -379,6 +386,7 @@ public class SwipeHelper implements Gefingerpoken {
            animView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            animView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        }
        AnimatorUpdateListener updateListener = new AnimatorUpdateListener() {
        AnimatorUpdateListener updateListener = new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
            public void onAnimationUpdate(ValueAnimator animation) {
                onTranslationUpdate(animView, (float) animation.getAnimatedValue(), canBeDismissed);
                onTranslationUpdate(animView, (float) animation.getAnimatedValue(), canBeDismissed);
            }
            }
@@ -401,10 +409,12 @@ public class SwipeHelper implements Gefingerpoken {
        anim.addListener(new AnimatorListenerAdapter() {
        anim.addListener(new AnimatorListenerAdapter() {
            private boolean mCancelled;
            private boolean mCancelled;


            @Override
            public void onAnimationCancel(Animator animation) {
            public void onAnimationCancel(Animator animation) {
                mCancelled = true;
                mCancelled = true;
            }
            }


            @Override
            public void onAnimationEnd(Animator animation) {
            public void onAnimationEnd(Animator animation) {
                updateSwipeProgressFromOffset(animView, canBeDismissed);
                updateSwipeProgressFromOffset(animView, canBeDismissed);
                mDismissPendingMap.remove(animView);
                mDismissPendingMap.remove(animView);
@@ -435,6 +445,7 @@ public class SwipeHelper implements Gefingerpoken {
    public void snapChild(final View animView, final float targetLeft, float velocity) {
    public void snapChild(final View animView, final float targetLeft, float velocity) {
        final boolean canBeDismissed = mCallback.canChildBeDismissed(animView);
        final boolean canBeDismissed = mCallback.canChildBeDismissed(animView);
        AnimatorUpdateListener updateListener = new AnimatorUpdateListener() {
        AnimatorUpdateListener updateListener = new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
            public void onAnimationUpdate(ValueAnimator animation) {
                onTranslationUpdate(animView, (float) animation.getAnimatedValue(), canBeDismissed);
                onTranslationUpdate(animView, (float) animation.getAnimatedValue(), canBeDismissed);
            }
            }
@@ -447,6 +458,7 @@ public class SwipeHelper implements Gefingerpoken {
        int duration = SNAP_ANIM_LEN;
        int duration = SNAP_ANIM_LEN;
        anim.setDuration(duration);
        anim.setDuration(duration);
        anim.addListener(new AnimatorListenerAdapter() {
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animator) {
            public void onAnimationEnd(Animator animator) {
                mSnappingChild = false;
                mSnappingChild = false;
                updateSwipeProgressFromOffset(animView, canBeDismissed);
                updateSwipeProgressFromOffset(animView, canBeDismissed);
@@ -522,6 +534,7 @@ public class SwipeHelper implements Gefingerpoken {
        }
        }
    }
    }


    @Override
    public boolean onTouchEvent(MotionEvent ev) {
    public boolean onTouchEvent(MotionEvent ev) {
        if (mLongPressSent) {
        if (mLongPressSent) {
            return true;
            return true;
@@ -690,6 +703,6 @@ public class SwipeHelper implements Gefingerpoken {
         * Equivalent to {@link View.OnLongClickListener#onLongClick(View)} with coordinates
         * Equivalent to {@link View.OnLongClickListener#onLongClick(View)} with coordinates
         * @return whether the longpress was handled
         * @return whether the longpress was handled
         */
         */
        boolean onLongPress(View v, int x, int y);
        boolean onLongPress(View v, int x, int y, MenuItem item);
    }
    }
}
}
Loading