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

Commit 5de624c2 authored by Tony Wickham's avatar Tony Wickham Committed by Android (Google) Code Review
Browse files

Merge "Support blacklisting live wallpapers from showing sysui scrims" into ub-launcher3-master

parents c21eb0f4 d6f917f1
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -81,7 +81,8 @@ public class RecentsRootView extends BaseDragLayer<RecentsActivity> {
        if (!insets.equals(mInsets)) {
            super.setInsets(insets);
        }
        setBackground(insets.top == 0 ? null
        setBackground(insets.top == 0  || !mAllowSysuiScrims
                ? null
                : Themes.getAttrDrawable(getContext(), R.attr.workspaceStatusBarScrim));
    }

+3 −0
Original line number Diff line number Diff line
@@ -176,4 +176,7 @@
        <item>@dimen/swipe_up_fling_min_visible_change</item>
        <item>@dimen/swipe_up_y_overshoot</item>
    </array>

    <string-array name="live_wallpapers_remove_sysui_scrims">
    </string-array>
</resources>
+1 −1
Original line number Diff line number Diff line
@@ -559,7 +559,7 @@ public class DragLayer extends BaseDragLayer<Launcher> {
    @Override
    public void setInsets(Rect insets) {
        super.setInsets(insets);
        mWorkspaceScrim.onInsetsChanged(insets);
        mWorkspaceScrim.onInsetsChanged(insets, mAllowSysuiScrims);
        mOverviewScrim.onInsetsChanged(insets);
    }

+7 −4
Original line number Diff line number Diff line
@@ -194,10 +194,13 @@ public class WorkspaceAndHotseatScrim extends Scrim {
        return anim;
    }

    public void onInsetsChanged(Rect insets) {
        mDrawTopScrim = mTopScrim != null && insets.top > 0;
        mDrawBottomScrim = mBottomMask != null &&
                !mLauncher.getDeviceProfile().isVerticalBarLayout();
    /**
     * Determines whether to draw the top and/or bottom scrim based on new insets.
     */
    public void onInsetsChanged(Rect insets, boolean allowSysuiScrims) {
        mDrawTopScrim = allowSysuiScrims && mTopScrim != null && insets.top > 0;
        mDrawBottomScrim = allowSysuiScrims && mBottomMask != null
                && !mLauncher.getDeviceProfile().isVerticalBarLayout();
    }

    @Override
+59 −0
Original line number Diff line number Diff line
@@ -23,7 +23,11 @@ import static android.view.MotionEvent.ACTION_UP;
import static com.android.launcher3.util.DefaultDisplay.getSingleFrameMs;

import android.annotation.TargetApi;
import android.app.WallpaperInfo;
import android.app.WallpaperManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Insets;
import android.graphics.Rect;
import android.graphics.RectF;
@@ -38,11 +42,15 @@ import android.view.WindowInsets;
import android.view.accessibility.AccessibilityEvent;
import android.widget.FrameLayout;

import androidx.annotation.Nullable;

import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.InsettableFrameLayout;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.MultiValueAlpha;
import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
import com.android.launcher3.util.SimpleBroadcastReceiver;
import com.android.launcher3.util.TouchController;

import java.io.PrintWriter;
@@ -98,6 +106,10 @@ public abstract class BaseDragLayer<T extends Context & ActivityContext>

    protected final T mActivity;
    private final MultiValueAlpha mMultiValueAlpha;
    private final WallpaperManager mWallpaperManager;
    private final SimpleBroadcastReceiver mWallpaperChangeReceiver =
            new SimpleBroadcastReceiver(this::onWallpaperChanged);
    private final String[] mWallpapersWithoutSysuiScrims;

    // All the touch controllers for the view
    protected TouchController[] mControllers;
@@ -108,10 +120,15 @@ public abstract class BaseDragLayer<T extends Context & ActivityContext>

    private TouchCompleteListener mTouchCompleteListener;

    protected boolean mAllowSysuiScrims = true;

    public BaseDragLayer(Context context, AttributeSet attrs, int alphaChannelCount) {
        super(context, attrs);
        mActivity = (T) ActivityContext.lookupContext(context);
        mMultiValueAlpha = new MultiValueAlpha(this, alphaChannelCount);
        mWallpaperManager = context.getSystemService(WallpaperManager.class);
        mWallpapersWithoutSysuiScrims = getResources().getStringArray(
                R.array.live_wallpapers_remove_sysui_scrims);
    }

    /**
@@ -517,4 +534,46 @@ public abstract class BaseDragLayer<T extends Context & ActivityContext>
        }
        return super.dispatchApplyWindowInsets(insets);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        mWallpaperChangeReceiver.register(mActivity, Intent.ACTION_WALLPAPER_CHANGED);
        onWallpaperChanged(null);
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        mActivity.unregisterReceiver(mWallpaperChangeReceiver);
    }

    private void onWallpaperChanged(Intent unusedBroadcastIntent) {
        WallpaperInfo newWallpaperInfo = mWallpaperManager.getWallpaperInfo();
        boolean oldAllowSysuiScrims = mAllowSysuiScrims;
        mAllowSysuiScrims = computeAllowSysuiScrims(newWallpaperInfo);
        if (mAllowSysuiScrims != oldAllowSysuiScrims) {
            // Reapply insets so scrim can be removed or re-added if necessary.
            setInsets(mInsets);
        }
    }

    /**
     * Determines whether we can scrim the status bar and nav bar for the given wallpaper by
     * checking against a list of live wallpapers that we don't show the scrims on.
     */
    private boolean computeAllowSysuiScrims(@Nullable WallpaperInfo newWallpaperInfo) {
        if (newWallpaperInfo == null) {
            // New wallpaper is static, not live. Thus, blacklist isn't applicable.
            return true;
        }
        ComponentName newWallpaper = newWallpaperInfo.getComponent();
        for (String wallpaperWithoutScrim : mWallpapersWithoutSysuiScrims) {
            if (newWallpaper.equals(ComponentName.unflattenFromString(wallpaperWithoutScrim))) {
                // New wallpaper is blacklisted from showing a scrim.
                return false;
            }
        }
        return true;
    }
}