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

Commit 46767b77 authored by Jason Monk's avatar Jason Monk
Browse files

Extract plugin interface for QS

Users must implement the QSContainer interface to be returned by
a ViewProvider plugin.  The QSContainer must contain a
BaseStatusBarHeader and have the id of quick_settings_container.

Test: Manual
Change-Id: Ibfaa835cad20855a530e4ae142d8a2aeba4a277b
parent d58ca27b
Loading
Loading
Loading
Loading
+124 −0
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.plugins.qs;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

public abstract class QSContainer extends FrameLayout {

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

    // This should be incremented any time this class or ActivityStarter or BaseStatusBarHeader
    // change in incompatible ways.
    public static final int VERSION = 1;

    public QSContainer(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public abstract void setPanelView(HeightListener notificationPanelView);
    public abstract BaseStatusBarHeader getHeader();

    public abstract int getQsMinExpansionHeight();
    public abstract int getDesiredHeight();
    public abstract void setHeightOverride(int desiredHeight);
    public abstract void setHeaderClickable(boolean qsExpansionEnabled);
    public abstract boolean isCustomizing();
    public abstract void setOverscrolling(boolean overscrolling);
    public abstract void setExpanded(boolean qsExpanded);
    public abstract void setListening(boolean listening);
    public abstract boolean isShowingDetail();
    public abstract void closeDetail();
    public abstract void setKeyguardShowing(boolean keyguardShowing);
    public abstract void animateHeaderSlidingIn(long delay);
    public abstract void animateHeaderSlidingOut();
    public abstract void setQsExpansion(float qsExpansionFraction, float headerTranslation);
    public abstract void setHeaderListening(boolean listening);
    public abstract void notifyCustomizeChanged();

    public abstract void setContainer(ViewGroup container);

    public interface HeightListener {
        void onQsHeightChanged();
    }

    public interface Callback {
        void onShowingDetail(DetailAdapter detail, int x, int y);
        void onToggleStateChanged(boolean state);
        void onScanStateChanged(boolean state);
    }

    public interface DetailAdapter {
        CharSequence getTitle();
        Boolean getToggleState();
        default boolean getToggleEnabled() {
            return true;
        }
        View createDetailView(Context context, View convertView, ViewGroup parent);
        Intent getSettingsIntent();
        void setToggleState(boolean state);
        int getMetricsCategory();

        /**
         * Indicates whether the detail view wants to have its header (back button, title and
         * toggle) shown.
         */
        default boolean hasHeader() { return true; }
    }

    public abstract static class BaseStatusBarHeader extends RelativeLayout {

        public BaseStatusBarHeader(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public abstract int getCollapsedHeight();
        public abstract int getExpandedHeight();

        public abstract void setExpanded(boolean b);
        public abstract void setExpansion(float headerExpansionFraction);
        public abstract void setListening(boolean listening);
        public abstract void updateEverything();
        public abstract void setActivityStarter(ActivityStarter activityStarter);
        public abstract void setCallback(Callback qsPanelCallback);
        public abstract View getExpandView();
    }

    /**
     * An interface to start activities. This is used to as a callback from the views to
     * {@link PhoneStatusBar} to allow custom handling for starting the activity, i.e. dismissing the
     * Keyguard.
     */
    public static interface ActivityStarter {

        void startPendingIntentDismissingKeyguard(PendingIntent intent);
        void startActivity(Intent intent, boolean dismissShade);
        void startActivity(Intent intent, boolean dismissShade, Callback callback);
        void preventNextAnimation();

        interface Callback {
            void onActivityStarted(int resultCode);
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<com.android.systemui.qs.QSContainer
<com.android.systemui.qs.QSContainerImpl
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/quick_settings_container"
        android:layout_width="match_parent"
@@ -38,4 +38,4 @@
    <include android:id="@+id/qs_customize" layout="@layout/qs_customize_panel"
        android:visibility="gone" />

</com.android.systemui.qs.QSContainer>
</com.android.systemui.qs.QSContainerImpl>
+4 −3
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@

<com.android.systemui.statusbar.phone.NotificationPanelView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
    xmlns:systemui="http://schemas.android.com/apk/res-auto"
    android:id="@+id/notification_panel"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
@@ -39,14 +39,15 @@
        android:clipToPadding="false"
        android:clipChildren="false">

        <com.android.systemui.AutoReinflateContainer
        <com.android.systemui.PluginInflateContainer
            android:id="@+id/qs_auto_reinflate_container"
            android:layout="@layout/qs_panel"
            android:layout_width="@dimen/notification_panel_width"
            android:layout_height="match_parent"
            android:layout_gravity="@integer/notification_panel_layout_gravity"
            android:clipToPadding="false"
            android:clipChildren="false" />
            android:clipChildren="false"
            systemui:viewType="com.android.systemui.plugins.qs.QSContainer" />

        <com.android.systemui.statusbar.stack.NotificationStackScrollLayout
            android:id="@+id/notification_stack_scroller"
+1 −1
Original line number Diff line number Diff line
@@ -14,13 +14,13 @@

package com.android.systemui.qs;

import android.graphics.Path;
import android.util.Log;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnLayoutChangeListener;
import android.widget.TextView;

import com.android.systemui.plugins.qs.QSContainer;
import com.android.systemui.qs.PagedTileLayout.PageListener;
import com.android.systemui.qs.QSPanel.QSTileLayout;
import com.android.systemui.qs.QSTile.Host.Callback;
+23 −9
Original line number Diff line number Diff line
@@ -24,14 +24,16 @@ import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;

import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.plugins.qs.QSContainer;
import com.android.systemui.qs.customize.QSCustomizer;
import com.android.systemui.statusbar.phone.BaseStatusBarHeader;
import com.android.systemui.statusbar.phone.NotificationPanelView;
import com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer;
import com.android.systemui.statusbar.phone.QSTileHost;
import com.android.systemui.statusbar.phone.QuickStatusBarHeader;
import com.android.systemui.statusbar.stack.StackStateAnimator;

/**
@@ -39,7 +41,7 @@ import com.android.systemui.statusbar.stack.StackStateAnimator;
 *
 * Also manages animations for the QS Header and Panel.
 */
public class QSContainer extends FrameLayout {
public class QSContainerImpl extends QSContainer {
    private static final String TAG = "QSContainer";
    private static final boolean DEBUG = false;

@@ -49,7 +51,7 @@ public class QSContainer extends FrameLayout {
    private int mHeightOverride = -1;
    protected QSPanel mQSPanel;
    private QSDetail mQSDetail;
    protected BaseStatusBarHeader mHeader;
    protected QuickStatusBarHeader mHeader;
    protected float mQsExpansion;
    private boolean mQsExpanded;
    private boolean mHeaderAnimating;
@@ -59,10 +61,10 @@ public class QSContainer extends FrameLayout {
    private long mDelay;
    private QSAnimator mQSAnimator;
    private QSCustomizer mQSCustomizer;
    private NotificationPanelView mPanelView;
    private HeightListener mPanelView;
    private boolean mListening;

    public QSContainer(Context context, AttributeSet attrs) {
    public QSContainerImpl(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

@@ -71,7 +73,7 @@ public class QSContainer extends FrameLayout {
        super.onFinishInflate();
        mQSPanel = (QSPanel) findViewById(R.id.quick_settings_panel);
        mQSDetail = (QSDetail) findViewById(R.id.qs_detail);
        mHeader = (BaseStatusBarHeader) findViewById(R.id.header);
        mHeader = (QuickStatusBarHeader) findViewById(R.id.header);
        mQSDetail.setQsPanel(mQSPanel, mHeader);
        mQSAnimator = new QSAnimator(this, (QuickQSPanel) mHeader.findViewById(R.id.quick_qs_panel),
                mQSPanel);
@@ -92,7 +94,7 @@ public class QSContainer extends FrameLayout {
        mQSAnimator.setHost(qsh);
    }

    public void setPanelView(NotificationPanelView panelView) {
    public void setPanelView(HeightListener panelView) {
        mPanelView = panelView;
    }

@@ -137,6 +139,13 @@ public class QSContainer extends FrameLayout {
        updateBottom();
    }

    @Override
    public void setContainer(ViewGroup container) {
        if (container instanceof NotificationsQuickSettingsContainer) {
            mQSCustomizer.setContainer((NotificationsQuickSettingsContainer) container);
        }
    }

    /**
     * The height this view wants to be. This is different from {@link #getMeasuredHeight} such that
     * during closing the detail panel, this already returns the smaller height.
@@ -291,6 +300,11 @@ public class QSContainer extends FrameLayout {
                .start();
    }

    @Override
    public void closeDetail() {
        mQSPanel.closeDetail();
    }

    private final ViewTreeObserver.OnPreDrawListener mStartHeaderSlidingIn
            = new ViewTreeObserver.OnPreDrawListener() {
        @Override
Loading