[QS] Add PageIndicator to footer

Allow the footer to provide a new PageIndicator to the QSPanel.
Wrapped the cellular text/info in a LinearLayout such that it
fills the space available and updated params for the action
container depending on what orientation we're in.

Since we're swapping the page indicator, it's important not to
lose num pages/location, so additionally storing & resetting
those values when swapping.

Test: Visually
Change-Id: Iffa8a47601a20d3386abd6f77ed120ece552b726
Fixes: 77152480
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
index 6368a6b..43780f7 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
@@ -16,6 +16,7 @@
 
 package com.android.systemui.qs;
 
+import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
 import static com.android.systemui.qs.tileimpl.QSTileImpl.getColorForState;
 
 import android.annotation.Nullable;
@@ -63,7 +64,6 @@
     protected final ArrayList<TileRecord> mRecords = new ArrayList<>();
     protected final View mBrightnessView;
     private final H mHandler = new H();
-    private final View mPageIndicator;
     private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
     private final QSTileRevealController mQsTileRevealController;
 
@@ -75,6 +75,8 @@
     protected QSTileHost mHost;
 
     protected QSSecurityFooter mFooter;
+    private PageIndicator mPanelPageIndicator;
+    private PageIndicator mFooterPageIndicator;
     private boolean mGridContentVisible = true;
 
     protected QSTileLayout mTileLayout;
@@ -104,13 +106,13 @@
         mTileLayout.setListening(mListening);
         addView((View) mTileLayout);
 
-        mPageIndicator = LayoutInflater.from(context).inflate(
+        mPanelPageIndicator = (PageIndicator) LayoutInflater.from(context).inflate(
                 R.layout.qs_page_indicator, this, false);
-        addView(mPageIndicator);
+        addView(mPanelPageIndicator);
 
-        ((PagedTileLayout) mTileLayout).setPageIndicator((PageIndicator) mPageIndicator);
+        ((PagedTileLayout) mTileLayout).setPageIndicator(mPanelPageIndicator);
         mQsTileRevealController = new QSTileRevealController(mContext, this,
-                ((PagedTileLayout) mTileLayout));
+                (PagedTileLayout) mTileLayout);
 
         addDivider();
 
@@ -136,7 +138,7 @@
     }
 
     public View getPageIndicator() {
-        return mPageIndicator;
+        return mPanelPageIndicator;
     }
 
     public QSTileRevealController getQsTileRevealController() {
@@ -241,6 +243,38 @@
         }
     }
 
+    /**
+     * Links the footer's page indicator, which is used in landscape orientation to save space.
+     *
+     * @param pageIndicator indicator to use for page scrolling
+     */
+    public void setFooterPageIndicator(PageIndicator pageIndicator) {
+        if (mTileLayout instanceof PagedTileLayout) {
+            mFooterPageIndicator = pageIndicator;
+            updatePageIndicator();
+        }
+    }
+
+    private void updatePageIndicator() {
+        if (mTileLayout instanceof PagedTileLayout) {
+            // If we're in landscape, and we have the footer page indicator (which we should if the
+            // footer has been initialized & linked), then we'll show the footer page indicator to
+            // save space in the main QS tile area. Otherwise, we'll use the default one under the
+            // tiles/above the footer.
+            boolean shouldUseFooterPageIndicator =
+                    getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE
+                            && mFooterPageIndicator != null;
+
+            mPanelPageIndicator.setVisibility(View.GONE);
+            if (mFooterPageIndicator != null) {
+                mFooterPageIndicator.setVisibility(View.GONE);
+            }
+
+            ((PagedTileLayout) mTileLayout).setPageIndicator(
+                    shouldUseFooterPageIndicator ? mFooterPageIndicator : mPanelPageIndicator);
+        }
+    }
+
     public QSTileHost getHost() {
         return mHost;
     }
@@ -248,6 +282,9 @@
     public void updateResources() {
         final Resources res = mContext.getResources();
         setPadding(0, res.getDimensionPixelSize(R.dimen.qs_panel_padding_top), 0, res.getDimensionPixelSize(R.dimen.qs_panel_padding_bottom));
+
+        updatePageIndicator();
+
         for (TileRecord r : mRecords) {
             r.tile.clearState();
         }