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

Commit d573aae5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add Plugin interface for Toasts"

parents 0b94a0eb b7ef5de9
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ import com.android.internal.util.ArrayUtils;
public class ToastPresenter {
    private static final String TAG = "ToastPresenter";
    private static final String WINDOW_TITLE = "Toast";

    // exclusively used to guarantee window timeouts
    private static final long SHORT_DURATION_TIMEOUT = 4000;
    private static final long LONG_DURATION_TIMEOUT = 7000;

@@ -145,7 +147,7 @@ public class ToastPresenter {
     */
    private void adjustLayoutParams(WindowManager.LayoutParams params, IBinder windowToken,
            int duration, int gravity, int xOffset, int yOffset, float horizontalMargin,
            float verticalMargin) {
            float verticalMargin, boolean removeWindowAnimations) {
        Configuration config = mResources.getConfiguration();
        int absGravity = Gravity.getAbsoluteGravity(gravity, config.getLayoutDirection());
        params.gravity = absGravity;
@@ -163,6 +165,10 @@ public class ToastPresenter {
        params.hideTimeoutMilliseconds =
                (duration == Toast.LENGTH_LONG) ? LONG_DURATION_TIMEOUT : SHORT_DURATION_TIMEOUT;
        params.token = windowToken;

        if (removeWindowAnimations && params.windowAnimations == R.style.Animation_Toast) {
            params.windowAnimations = 0;
        }
    }

    /**
@@ -193,16 +199,28 @@ public class ToastPresenter {

    /**
     * Shows the toast in {@code view} with the parameters passed and callback {@code callback}.
     * Uses window animations to animate the toast.
     */
    public void show(View view, IBinder token, IBinder windowToken, int duration, int gravity,
            int xOffset, int yOffset, float horizontalMargin, float verticalMargin,
            @Nullable ITransientNotificationCallback callback) {
        show(view, token, windowToken, duration, gravity, xOffset, yOffset, horizontalMargin,
                verticalMargin, callback, false /* removeWindowAnimations */);
    }

    /**
     * Shows the toast in {@code view} with the parameters passed and callback {@code callback}.
     * Can optionally remove window animations from the toast window.
     */
    public void show(View view, IBinder token, IBinder windowToken, int duration, int gravity,
            int xOffset, int yOffset, float horizontalMargin, float verticalMargin,
            @Nullable ITransientNotificationCallback callback, boolean removeWindowAnimations) {
        checkState(mView == null, "Only one toast at a time is allowed, call hide() first.");
        mView = view;
        mToken = token;

        adjustLayoutParams(mParams, windowToken, duration, gravity, xOffset, yOffset,
                horizontalMargin, verticalMargin);
                horizontalMargin, verticalMargin, removeWindowAnimations);
        if (mView.getParent() != null) {
            mWindowManager.removeView(mView);
        }
@@ -247,7 +265,8 @@ public class ToastPresenter {
            try {
                callback.onToastHidden();
            } catch (RemoteException e) {
                Log.w(TAG, "Error calling back " + mPackageName + " to notify onToastHide()", e);
                Log.w(TAG, "Error calling back " + mPackageName + " to notify onToastHide()",
                        e);
            }
        }
        mView = null;
+19 −12
Original line number Diff line number Diff line
# Plugin hooks
### Action: com.android.systemui.action.PLUGIN_OVERLAY
Expected interface: [OverlayPlugin](/packages/SystemUI/plugin/src/com/android/systemui/plugins/OverlayPlugin.java)
Expected interface: [OverlayPlugin](/frameworks/base/packages/SystemUI/plugin/src/com/android
/systemui/plugins/OverlayPlugin.java)

Use: Allows plugin access to the status bar and nav bar window for whatever nefarious purposes you can imagine.

### Action: com.android.systemui.action.PLUGIN_QS
Expected interface: [QS](/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QS.java)
Expected interface: [QS](/frameworks/base/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QS.java)

Use: Allows the entire QS panel to be replaced with something else that is optionally expandable.

Notes: To not mess up the notification panel interaction, much of the QSContainer interface needs to actually be implemented.

### Action: com.android.systemui.action.PLUGIN_QS_FACTORY
Expected interface: [QSFactory](/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSFactory.java)
Expected interface: [QSFactory](/frameworks/base/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSFactory.java)

Use: Controls the creation of QS Tiles and their views, can used to add or change system QS tiles, can also be used to change the layout/interaction of the tile views.

### Action: com.android.systemui.action.PLUGIN_NAV_BUTTON
Expected interface: [NavBarButtonProvider](/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavBarButtonProvider.java)
Expected interface: [NavBarButtonProvider](/frameworks/base/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavBarButtonProvider.java)

Use: Allows a plugin to create a new nav bar button, or override an existing one with a view of its own.

### Action: com.android.systemui.action.PLUGIN_NAV_GESTURE
Expected interface: [NavGesture](/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavGesture.java)
Expected interface: [NavGesture](/frameworks/base/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavGesture.java)

Use: Allows touch events from the nav bar to be intercepted and used for other gestures.

### Action: com.android.systemui.action.PLUGIN_LOCKSCREEN_RIGHT_BUTTON
Expected interface: [IntentButtonProvider](/packages/SystemUI/plugin/src/com/android/systemui/plugins/IntentButtonProvider.java)
Expected interface: [IntentButtonProvider](/frameworks/base/packages/SystemUI/plugin/src/com/android/systemui/plugins/IntentButtonProvider.java)

Use: Allows a plugin to specify the icon for the bottom right lock screen button, and the intent that gets launched when it is activated.

@@ -37,28 +38,34 @@ Expected interface: [IntentButtonProvider](/packages/SystemUI/plugin/src/com/and
Use: Allows a plugin to specify the icon for the bottom left lock screen button, and the intent that gets launched when it is activated.

### Action: com.android.systemui.action.PLUGIN_GLOBAL_ACTIONS
Expected interface: [GlobalActions](/packages/SystemUI/plugin/src/com/android/systemui/plugins/GlobalActions.java)
Expected interface: [GlobalActions](/frameworks/base/packages/SystemUI/plugin/src/com/android/systemui/plugins/GlobalActions.java)

Use: Allows the long-press power menu to be completely replaced.

### Action: com.android.systemui.action.PLUGIN_VOLUME
Expected interface: [VolumeDialog](/packages/SystemUI/plugin/src/com/android/systemui/plugins/VolumeDialog.java)
Expected interface: [VolumeDialog](/frameworks/base/packages/SystemUI/plugin/src/com/android/systemui/plugins/VolumeDialog.java)

Use: Allows replacement of the volume dialog.

### Action: com.android.systemui.action.PLUGIN_NOTIFICATION_SWIPE_ACTION
Expected interface: [NotificationSwipeActionHelper](/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/NotificationSwipeActionHelper.java)
Expected interface: [NotificationSwipeActionHelper](/frameworks/base/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/NotificationSwipeActionHelper.java)

Use: Control over swipes/input for notification views, can be used to control what happens when you swipe/long-press

### Action: com.android.systemui.action.PLUGIN_CLOCK
Expected interface: [ClockPlugin](/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockPlugin.java)
Expected interface: [ClockPlugin](/frameworks/base/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockPlugin.java)

Use: Allows replacement of the keyguard main clock.

### Action: com.android.systemui.action.PLUGIN_TOAST
Expected interface: [ToastPlugin](/frameworks/base/packages/SystemUI/plugin/src/com/android
/systemui/plugins/ClockPlugin.java)

Use: Allows replacement of uncustomized toasts created via Toast.makeText().

# Global plugin dependencies
These classes can be accessed by any plugin using PluginDependency as long as they @Requires them.

[VolumeDialogController](/packages/SystemUI/plugin/src/com/android/systemui/plugins/VolumeDialogController.java) - Mostly just API for the volume plugin
[VolumeDialogController](/frameworks/base/packages/SystemUI/plugin/src/com/android/systemui/plugins/VolumeDialogController.java) - Mostly just API for the volume plugin

[ActivityStarter](/packages/SystemUI/plugin/src/com/android/systemui/plugins/ActivityStarter.java) - Allows starting of intents while co-operating with keyguard unlocks.
[ActivityStarter](/frameworks/base/packages/SystemUI/plugin/src/com/android/systemui/plugins/ActivityStarter.java) - Allows starting of intents while co-operating with keyguard unlocks.
+107 −0
Original line number Diff line number Diff line
/*
 * 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.
 */

package com.android.systemui.plugins;

import android.animation.Animator;
import android.annotation.NonNull;
import android.view.View;

import com.android.systemui.plugins.annotations.ProvidesInterface;

/**
 * Customize toasts displayed by SystemUI (via Toast#makeText)
 */
@ProvidesInterface(action = ToastPlugin.ACTION, version = ToastPlugin.VERSION)
public interface ToastPlugin extends Plugin {

    String ACTION = "com.android.systemui.action.PLUGIN_TOAST";
    int VERSION = 1;

    /**
     * Creates a CustomPluginToast.
     */
    @NonNull Toast createToast(CharSequence text, String packageName, int userId);

    /**
     * Custom Toast with the ability to change toast positioning, styling and animations.
     */
    interface Toast {
        /**
         * Retrieve the Toast view's gravity.
         * If no changes, returns null.
         */
        default Integer getGravity() {
            return null;
        }

        /**
         * Retrieve the Toast view's X-offset.
         * If no changes, returns null.
         */
        default Integer getXOffset() {
            return null;
        }

        /**
         * Retrieve the Toast view's Y-offset.
         * If no changes, returns null.
         */
        default Integer getYOffset() {
            return null;
        }

        /**
         * Retrieve the Toast view's horizontal margin.
         * If no changes, returns null.
         */
        default Integer getHorizontalMargin()  {
            return null;
        }

        /**
         * Retrieve the Toast view's vertical margin.
         * If no changes, returns null.
         */
        default Integer getVerticalMargin()  {
            return null;
        }

        /**
         * Retrieve the Toast view to show.
         * If no changes, returns null.
         */
        default View getView() {
            return null;
        }

        /**
         * Retrieve the Toast's animate in.
         * If no changes, returns null.
         */
        default Animator getInAnimation() {
            return null;
        }

        /**
         * Retrieve the Toast's animate out.
         * If no changes, returns null.
         */
        default Animator getOutAnimation() {
            return null;
        }
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -108,6 +108,18 @@ public class LogModule {
        return buffer;
    }

    /** Provides a logging buffer for all logs related to Toasts shown by SystemUI. */
    @Provides
    @SysUISingleton
    @ToastLog
    public static LogBuffer provideToastLogBuffer(
            LogcatEchoTracker bufferFilter,
            DumpManager dumpManager) {
        LogBuffer buffer = new LogBuffer("ToastLog", 50, 10, bufferFilter);
        buffer.attach(dumpManager);
        return buffer;
    }

    /** Allows logging buffers to be tweaked via adb on debug builds but not on prod builds. */
    @Provides
    @SysUISingleton
+33 −0
Original line number Diff line number Diff line
/*
 * 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.
 */

package com.android.systemui.log.dagger;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import com.android.systemui.log.LogBuffer;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

import javax.inject.Qualifier;

/** A {@link LogBuffer} for ToastLog-related messages. */
@Qualifier
@Documented
@Retention(RUNTIME)
public @interface ToastLog {
}
Loading