SystemUIOverlayWindow प्रबंधन प्रणाली

SystemUIOverlayWindow प्रबंधन प्रणाली आपको SystemUIOverlayWindow में दृश्य प्रदर्शित करने और प्रबंधित करने का एक तरीका प्रदान करती है। वर्तमान में, इस विंडो का उपयोग पूर्ण स्क्रीन उपयोगकर्ता स्विचर, अधिसूचना पैनल और कीगार्ड सहित दृश्यों के लिए किया जाता है। यह पेज यह नहीं करता:

  • ओईएम विंडो में क्या जोड़ सकता है, इसके बारे में प्रतिबंध बनाएं।
  • आपको इस पृष्ठ पर वर्णित सार-संक्षेपों को अपनाने के लिए बाध्य करें।

अवलोकन

आप कानूनी नोटिस, फ़ुलस्क्रीन उपयोगकर्ता स्विचर, रियर व्यू कैमरा, एचवीएसी नियंत्रण और कीगार्ड जैसे दृश्य दिखाने के लिए SystemUIOverlayWindow प्रबंधन प्रणाली का उपयोग कर सकते हैं। यह विंडो ऐप स्पेस के बाहर स्थित है और आपको दृश्य के Z-ऑर्डरिंग, प्रकट/छिपाने वाले ट्रिगर्स और दृश्य प्लेसमेंट, आकार, पारदर्शिता और रंग सहित समग्र अनुकूलन पर नियंत्रण प्रदान करती है। साथ ही, आपको सिस्टम बार या अन्य सिस्टम यूआई ऑब्जेक्ट्स की स्थिति के बारे में चिंतित होने की आवश्यकता नहीं है जिन्हें छुपाने या दिखाने की आवश्यकता होती है जब उनका संबंधित दृश्य छुपाया या दिखाया जाता है।

SystemUIOverlayWindow का लाभ उठाने के लिए, आप अपने दृश्य मध्यस्थों के लिए दृश्य नियंत्रक बनाते हैं। मध्यस्थों को विंडो के वैश्विक स्थिति नियंत्रक के पास भेज दिया जाता है। ये दृश्य मध्यस्थ:

  • दृश्य नियंत्रकों के बीच समन्वय स्थापित करें।
  • दृश्य नियंत्रकों के लिए गृह व्यवसाय तर्क।

नियंत्रक देखें (दृश्य मध्यस्थों द्वारा समन्वित):

  • इसका अपना नजरिया है.
  • ऐसे सेटर्स बनाएं जिनके माध्यम से OverlayViewsMediator व्यावसायिक तर्क संलग्न कर सके।
  • उनके दृश्य के प्रकट और छुपाने वाले एनिमेशन बनाएं।

SystemUIOverlayWindow प्रबंधक, एक SystemUI घटक, वैश्विक राज्य नियंत्रक के साथ मध्यस्थों को आरंभ करने और पंजीकृत करने के लिए एक प्रवेश बिंदु के रूप में कार्य करता है, जबकि वैश्विक राज्य नियंत्रक दृश्य नियंत्रकों से इस तरह से जुड़ता है कि मध्यस्थ सीधे दृश्य नियंत्रकों को दृश्य दिखाने और छिपाने के लिए कॉल कर सकते हैं खिड़की।

ओवरलेव्यूकंट्रोलर

OverlayViewController SystemUIOverlayWindow में प्रदर्शित दृश्य के लिए ज़िम्मेदार है और यह नियंत्रित करता है कि दृश्य कैसे प्रकट और छिपा हुआ है। यह आवश्यक श्रोताओं को जोड़ने में भी सक्षम बनाता है ताकि इसे व्यावसायिक तर्क से जोड़ा जा सके।

महत्वपूर्ण विधि हस्ताक्षर

/**
 * Owns a {@link View} that is present in SystemUIOverlayWindow.
 */
public class OverlayViewController {

    /**
     * Shows content of {@link OverlayViewController}.
     *
     * Should be used to show view externally and in particular by {@link OverlayViewMediator}.
     */
    public final void start();

    /**
     * Hides content of {@link OverlayViewController}.
     *
     * Should be used to hide view externally and in particular by {@link OverlayViewMediator}.
     */
    public final void stop();

    /**
     * Inflate layout owned by controller.
     */
    public final void inflate(ViewGroup baseLayout);

    /**
     * Called once inflate finishes.
     */
    protected void onFinishInflate();

    /**
     * Returns {@code true} if layout owned by controller has been inflated.
     */
    public final boolean isInflated();

    /**
     * Subclasses should override this method to implement reveal animations and implement logic
     * specific to when the layout owned by the controller is shown.
     *
     * Should only be overridden by Superclass but not called by any {@link OverlayViewMediator}.
     */
    protected void showInternal();

    /**
     * Subclasses should override this method to implement conceal animations and implement logic
     * specific to when the layout owned by the controller is hidden.
     *
     * Should only be overridden by Superclass but not called by any {@link OverlayViewMediator}.
     */
    protected void hideInternal();

    /**
     * Provides access to layout owned by controller.
     */
    protected final View getLayout();

    /** Returns the {@link OverlayViewGlobalStateController}. */
    protected final OverlayViewGlobalStateController getOverlayViewGlobalStateController();

    /** Returns whether the view controlled by this controller is visible. */
    public final boolean isVisible();

    /**
     * Returns the ID of the focus area that should receive focus when this view is the
     * topmost view or {@link View#NO_ID} if there is no focus area.
     */
    @IdRes
    protected int getFocusAreaViewId();

    /** Returns whether the view controlled by this controller has rotary focus. */
    protected final boolean hasRotaryFocus();

    /**
     * Sets whether this view allows rotary focus. This should be set to {@code true} for the
     * topmost layer in the overlay window and {@code false} for the others.
     */
    public void setAllowRotaryFocus(boolean allowRotaryFocus);

    /**
     * Refreshes the rotary focus in this view if we are in rotary mode. If the view already has
     * rotary focus, it leaves the focus alone. Returns {@code true} if a new view was focused.
     */
    public boolean refreshRotaryFocusIfNeeded();

    /**
     * Returns {@code true} if heads up notifications should be displayed over this view.
     */
    protected boolean shouldShowHUN();

    /**
     * Returns {@code true} if navigation bar insets should be displayed over this view. Has no
     * effect if {@link #shouldFocusWindow} returns {@code false}.
     */
    protected boolean shouldShowNavigationBarInsets();

    /**
     * Returns {@code true} if status bar insets should be displayed over this view. Has no
     * effect if {@link #shouldFocusWindow} returns {@code false}.
     */
    protected boolean shouldShowStatusBarInsets();

    /**
     * Returns {@code true} if this view should be hidden during the occluded state.
     */
    protected boolean shouldShowWhenOccluded();

    /**
     * Returns {@code true} if the window should be focued when this view is visible. Note that
     * returning {@code false} here means that {@link #shouldShowStatusBarInsets} and
     * {@link #shouldShowNavigationBarInsets} will have no effect.
     */
    protected boolean shouldFocusWindow();

    /**
     * Returns {@code true} if the window should use stable insets. Using stable insets means that
     * even when system bars are temporarily not visible, inset from the system bars will still be
     * applied.
     *
     * NOTE: When system bars are hidden in transient mode, insets from them will not be applied
     * even when the system bars become visible. Setting the return value to {@true} here can
     * prevent the OverlayView from overlapping with the system bars when that happens.
     */
    protected boolean shouldUseStableInsets();

    /**
     * Returns the insets types to fit to the sysui overlay window when this
     * {@link OverlayViewController} is in the foreground.
     */
    @WindowInsets.Type.InsetsType
    protected int getInsetTypesToFit();

    /**
     * Optionally returns the sides of enabled system bar insets to fit to the sysui overlay window
     * when this {@link OverlayViewController} is in the foreground.
     *
     * For example, if the bottom and left system bars are enabled and this method returns
     * WindowInsets.Side.LEFT, then the inset from the bottom system bar will be ignored.
     *
     * NOTE: By default, this method returns {@link #INVALID_INSET_SIDE}, so insets to fit are
     * defined by {@link #getInsetTypesToFit()}, and not by this method, unless it is overridden
     * by subclasses.
     *
     * NOTE: {@link #NO_INSET_SIDE} signifies no insets from any system bars will be honored. Each
     * {@link OverlayViewController} can first take this value and add sides of the system bar
     * insets to honor to it.
     *
     * NOTE: If getInsetSidesToFit is overridden to return {@link WindowInsets.Side}, it always
     * takes precedence over {@link #getInsetTypesToFit()}. That is, the return value of {@link
     * #getInsetTypesToFit()} will be ignored.
     */
    @WindowInsets.Side.InsetsSide
    protected int getInsetSidesToFit();
}

ओवरलेपैनलव्यूकंट्रोलर

OverlayPanelViewController नियंत्रक OverlayViewController का विस्तार करता है और इसके सुपरक्लास में अतिरिक्त ड्रैगिंग एनीमेशन क्षमताएं प्रदान करता है।

ओवरलेव्यूमेडिएटर

OverlayViewMediator में व्यावसायिक तर्क होता है जो कई OverlayViewController उदाहरणों को प्रकट या छुपाता है, इसलिए, एक तरह से यह दृश्य नियंत्रकों के बीच समन्वय का प्रबंधन भी करता है।

/**
 * Controls when to show and hide {@link OverlayViewController}(s).
 */
public interface OverlayViewMediator {

    /**
     * Register listeners that could use ContentVisibilityAdjuster to show/hide content.
     *
     * Note that we do not unregister listeners because SystemUI components are expected to live
     * for the lifecycle of the device.
     */
    void registerListeners();

    /**
     * Allows for post-inflation callbacks and listeners to be set inside required {@link
     * OverlayViewController}(s).
     */
    void setupOverlayContentViewControllers();
}

SystemUIOverlayWindowManager

SystemUIOverlayWindowManager SystemUI ऑब्जेक्ट होने के लिए जिम्मेदार है जो OverlayViewGlobalStateController के साथ OverlayViewMediator इंस्टेंसेस को आरंभ करने और पंजीकृत करने के लिए SystemUIOverlayWindow प्रबंधन सिस्टम के लिए एक प्रवेश बिंदु प्रदान करता है।

प्रवाह देखें दिखाएँ
चित्र 1. SystemUIOverlayWindowManager

ओवरलेव्यूग्लोबलस्टेटकंट्रोलर

OverlayViewGlobalStateController स्वयं को प्रकट करने या छुपाने के लिए OverlayViewController इंस्टेंसेस से कॉल प्राप्त करता है। इसलिए, यह SystemUIOverlayWindow में जो दिखाया या छिपाया गया है उसकी स्थिति भी रखता है।

शो दृश्य प्रवाह नीचे चित्रित किया गया है:

दृश्य प्रवाह दिखाएँ
चित्र 2. दृश्य प्रवाह दिखाएँ

दृश्य प्रवाह छिपाएँ

छिपाने का दृश्य प्रवाह नीचे चित्रित किया गया है:

दृश्य प्रवाह छिपाएँ
चित्र 3. दृश्य प्रवाह छिपाएँ

सार्वजनिक विधि हस्ताक्षर

सार्वजनिक विधि हस्ताक्षर निम्नानुसार एन्कोड किए गए हैं:

​/**
 * This controller is responsible for the following:
 * <p><ul>
 * <li>Holds the global state for SystemUIOverlayWindow.
 * <li>Allows {@link SystemUIOverlayWindowManager} to register {@link OverlayViewMediator}(s).
 * <li>Enables {@link OverlayViewController)(s) to reveal/conceal themselves while respecting the
 * global state of SystemUIOverlayWindow.
 * </ul>
 */
@SysUISingleton
public class OverlayViewGlobalStateController {
    /**
     * Register {@link OverlayViewMediator} to use in SystemUIOverlayWindow.
     */
    public void registerMediator(OverlayViewMediator overlayViewMediator);

    /**
     * Show content in Overlay Window using {@link OverlayPanelViewController}.
     *
     * This calls {@link OverlayViewGlobalStateController#showView(OverlayViewController, Runnable)}
     * where the runnable is nullified since the actual showing of the panel is handled by the
     * controller itself.
     */
    public void showView(OverlayPanelViewController panelViewController);

    /**
     * Show content in Overlay Window using {@link OverlayViewController}.
     */
    public void showView(OverlayViewController viewController, @Nullable Runnable show);

    /**
     * Hide content in Overlay Window using {@link OverlayPanelViewController}.
     *
     * This calls {@link OverlayViewGlobalStateController#hideView(OverlayViewController, Runnable)}
     * where the runnable is nullified since the actual hiding of the panel is handled by the
     * controller itself.
     */
    public void hideView(OverlayPanelViewController panelViewController);

    /**
     * Hide content in Overlay Window using {@link OverlayViewController}.
     */
    public void hideView(OverlayViewController viewController, @Nullable Runnable hide);

    /** Returns {@code true} is the window is visible. */
    public boolean isWindowVisible();

    /**
     * Sets the {@link android.view.WindowManager.LayoutParams#FLAG_ALT_FOCUSABLE_IM} flag of the
     * sysui overlay window.
     */
    public void setWindowNeedsInput(boolean needsInput);

    /** Returns {@code true} if the window is focusable. */
    public boolean isWindowFocusable();

    /** Sets the focusable flag of the sysui overlawy window. */
    public void setWindowFocusable(boolean focusable);

    /** Inflates the view controlled by the given view controller. */
    public void inflateView(OverlayViewController viewController);

    /**
     * Return {@code true} if OverlayWindow is in a state where HUNs should be displayed above it.
     */
    public boolean shouldShowHUN();

    /**
     * Set the OverlayViewWindow to be in occluded or unoccluded state. When OverlayViewWindow is
     * occluded, all views mounted to it that are not configured to be shown during occlusion will
     * be hidden.
     */
    public void setOccluded(boolean occluded);
}

SysUIOverlayWindow में एक दृश्य कैसे जोड़ें

विवरण के लिए, कोडलैब देखें।

चरण 1: SysUIOverlayWindow में एक ViewStub जोड़ें

विंडो लेआउट में ViewStub जोड़ें।

चरण 2: एक OverlayViewController बनाएं

एक नया इंजेक्टेबल OverlayViewController बनाने के लिए नए ViewStub उपयोग करें।

चरण 3: ओवरलेव्यूमेडिएटर

एक नया इंजेक्टेबल OverlayViewMediator बनाएं या किसी मौजूदा का उपयोग करें (चरण 4 छोड़ें) और नए OverlayViewController छिपाने या दिखाने के लिए श्रोताओं को पंजीकृत करें।

चरण 4: नया OverlayViewMediator कॉन्फ़िगर करें

अपना नया OverlayViewMediator OverlayWindowModule और config_carSystemUIOverlayViewsMediator में जोड़ें।

चेतावनियां

जब SysUIPrimaryWindow पूरी स्क्रीन को कवर करता है, तो विंडो के नीचे कोई भी तत्व स्पर्श घटनाओं को पंजीकृत नहीं करता है। इसलिए, जब विंडो पूरी स्क्रीन को कवर करती है लेकिन उसकी सामग्री कुछ नकारात्मक स्थान छोड़ती है, तो आप नकारात्मक स्थान को धुंधला करना चुन सकते हैं और विंडो में सामग्री को खारिज करने के लिए श्रोताओं को उस स्थान से जोड़ सकते हैं।