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

Commit ff4696cf authored by yoshiki iguchi's avatar yoshiki iguchi
Browse files

Decouple HeadsUpManager and ScrollContainer from remote input classes

This cl removes the dependency to the status bar related classes from
the remote input classes (RemoteInputController and RemoteInputView),
so that we can reuse the remote input code from statusbar-less Android
environment like ARC.

Bug: 63874929
Bug: 62602530
Test: Compiled and ran
Change-Id: Id594446592dd9b74ff8ef844ce8eace301b22b56
parent 6872c2e3
Loading
Loading
Loading
Loading
+30 −5
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.statusbar;
import com.android.internal.util.Preconditions;
import com.android.systemui.Dependency;
import com.android.systemui.statusbar.phone.StatusBarWindowManager;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.RemoteInputView;

import android.util.ArrayMap;
@@ -38,11 +37,11 @@ public class RemoteInputController {
            = new ArrayList<>();
    private final ArrayMap<String, Object> mSpinning = new ArrayMap<>();
    private final ArrayList<Callback> mCallbacks = new ArrayList<>(3);
    private final HeadsUpManager mHeadsUpManager;
    private final Delegate mDelegate;

    public RemoteInputController(HeadsUpManager headsUpManager) {
    public RemoteInputController(Delegate delegate) {
        addCallback(Dependency.get(StatusBarWindowManager.class));
        mHeadsUpManager = headsUpManager;
        mDelegate = delegate;
    }

    /**
@@ -114,7 +113,7 @@ public class RemoteInputController {
    }

    private void apply(NotificationData.Entry entry) {
        mHeadsUpManager.setRemoteInputActive(entry, isRemoteInputActive(entry));
        mDelegate.setRemoteInputActive(entry, isRemoteInputActive(entry));
        boolean remoteInputActive = isRemoteInputActive();
        int N = mCallbacks.size();
        for (int i = 0; i < N; i++) {
@@ -204,9 +203,35 @@ public class RemoteInputController {
        }
    }

    public void requestDisallowLongPressAndDismiss() {
        mDelegate.requestDisallowLongPressAndDismiss();
    }

    public void lockScrollTo(NotificationData.Entry entry) {
        mDelegate.lockScrollTo(entry);
    }

    public interface Callback {
        default void onRemoteInputActive(boolean active) {}

        default void onRemoteInputSent(NotificationData.Entry entry) {}
    }

    public interface Delegate {
        /**
         * Activate remote input if necessary.
         */
        void setRemoteInputActive(NotificationData.Entry entry, boolean remoteInputActive);

       /**
        * Request that the view does not dismiss nor perform long press for the current touch.
        */
       void requestDisallowLongPressAndDismiss();

      /**
       * Request that the view is made visible by scrolling to it, and keep the scroll locked until
       * the user scrolls, or {@param v} loses focus or is detached.
       */
       void lockScrollTo(NotificationData.Entry entry);
    }
}
+13 −1
Original line number Diff line number Diff line
@@ -3393,7 +3393,19 @@ public class StatusBar extends SystemUI implements DemoMode,
    private void addStatusBarWindow() {
        makeStatusBarView();
        mStatusBarWindowManager = Dependency.get(StatusBarWindowManager.class);
        mRemoteInputController = new RemoteInputController(mHeadsUpManager);
        mRemoteInputController = new RemoteInputController(new RemoteInputController.Delegate() {
          public void setRemoteInputActive(NotificationData.Entry entry,
                  boolean remoteInputActive) {
              mHeadsUpManager.setRemoteInputActive(entry, remoteInputActive);
          }
          public void lockScrollTo(NotificationData.Entry entry) {
              mStackScroller.lockScrollTo(entry.row);
          }
          public void requestDisallowLongPressAndDismiss() {
              mStackScroller.requestDisallowLongPress();
              mStackScroller.requestDisallowDismiss();
          }
        });
        mStatusBarWindowManager.add(mStatusBarWindow, getStatusBarHeight());
    }

+2 −31
Original line number Diff line number Diff line
@@ -53,11 +53,9 @@ import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.statusbar.ExpandableView;
import com.android.systemui.statusbar.NotificationData;
import com.android.systemui.statusbar.RemoteInputController;
import com.android.systemui.statusbar.notification.NotificationViewWrapper;
import com.android.systemui.statusbar.stack.ScrollContainer;
import com.android.systemui.statusbar.stack.StackStateAnimator;

/**
@@ -82,8 +80,6 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene

    private NotificationData.Entry mEntry;

    private ScrollContainer mScrollContainer;
    private View mScrollContainerChild;
    private boolean mRemoved;

    private int mRevealCx;
@@ -347,41 +343,16 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            findScrollContainer();
            if (mScrollContainer != null) {
                mScrollContainer.requestDisallowLongPress();
                mScrollContainer.requestDisallowDismiss();
            }
            mController.requestDisallowLongPressAndDismiss();
        }
        return super.onInterceptTouchEvent(ev);
    }

    public boolean requestScrollTo() {
        findScrollContainer();
        mScrollContainer.lockScrollTo(mScrollContainerChild);
        mController.lockScrollTo(mEntry);
        return true;
    }

    private void findScrollContainer() {
        if (mScrollContainer == null) {
            mScrollContainerChild = null;
            ViewParent p = this;
            while (p != null) {
                if (mScrollContainerChild == null && p instanceof ExpandableView) {
                    mScrollContainerChild = (View) p;
                }
                if (p.getParent() instanceof ScrollContainer) {
                    mScrollContainer = (ScrollContainer) p.getParent();
                    if (mScrollContainerChild == null) {
                        mScrollContainerChild = (View) p;
                    }
                    break;
                }
                p = p.getParent();
            }
        }
    }

    public boolean isActive() {
        return mEditText.isFocused() && mEditText.isEnabled();
    }
+1 −6
Original line number Diff line number Diff line
@@ -108,8 +108,7 @@ import java.util.List;
public class NotificationStackScrollLayout extends ViewGroup
        implements SwipeHelper.Callback, ExpandHelper.Callback, ScrollAdapter,
        ExpandableView.OnHeightChangedListener, NotificationGroupManager.OnGroupChangeListener,
        NotificationMenuRowPlugin.OnMenuEventListener, ScrollContainer,
        VisibilityLocationProvider {
        NotificationMenuRowPlugin.OnMenuEventListener, VisibilityLocationProvider {

    public static final float BACKGROUND_ALPHA_DIMMED = 0.7f;
    private static final String TAG = "StackScroller";
@@ -1195,7 +1194,6 @@ public class NotificationStackScrollLayout extends ViewGroup
        mScrollingEnabled = enable;
    }

    @Override
    public void lockScrollTo(View v) {
        if (mForcedScroll == v) {
            return;
@@ -1204,7 +1202,6 @@ public class NotificationStackScrollLayout extends ViewGroup
        scrollTo(v);
    }

    @Override
    public boolean scrollTo(View v) {
        ExpandableView expandableView = (ExpandableView) v;
        int positionInLinearLayout = getPositionInLinearLayout(v);
@@ -3321,12 +3318,10 @@ public class NotificationStackScrollLayout extends ViewGroup
        }
    }

    @Override
    public void requestDisallowLongPress() {
        cancelLongPress();
    }

    @Override
    public void requestDisallowDismiss() {
        mDisallowDismissInThisMotion = true;
    }
+0 −48
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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.statusbar.stack;

import android.view.View;

/**
 * Interface for container layouts that scroll and listen for long presses. A child that
 * wants to handle long press can use this to cancel the parents long press logic or request
 * to be made visible by scrolling to it.
 */
public interface ScrollContainer {
    /**
     * Request that the view does not perform long press for the current touch.
     */
    void requestDisallowLongPress();

    /**
     * Request that the view is made visible by scrolling to it.
     * Return true if it scrolls.
     */
    boolean scrollTo(View v);

    /**
     * Like {@link #scrollTo(View)}, but keeps the scroll locked until the user
     * scrolls, or {@param v} loses focus or is detached.
     */
    void lockScrollTo(View v);

    /**
     * Request that the view does not dismiss for the current touch.
     */
    void requestDisallowDismiss();
}