Fixed bugs in PagedTileLayout, QSAnimator using RTL

* getNumVisibleTiles now returns the correct number when in RTL. It was
not referring to the correct page
* mPageToRestore set properly on configuration changes
* Animation of tiles that do not fit in screen is correct in RTL.

Fixes: 130408545
Test: visual, changing configuration and expanding/collapsing
Change-Id: I62da728631fceaead0f81af1b32a115e961cf58e
diff --git a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
index bb159a9..ebc3a6a 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
@@ -91,6 +91,7 @@
         if (mLayoutOrientation != newConfig.orientation) {
             mLayoutOrientation = newConfig.orientation;
             setCurrentItem(0, false);
+            mPageToRestore = 0;
         }
     }
 
@@ -101,6 +102,7 @@
             mLayoutDirection = layoutDirection;
             setAdapter(mAdapter);
             setCurrentItem(0, false);
+            mPageToRestore = 0;
         }
     }
 
@@ -112,6 +114,17 @@
         super.setCurrentItem(item, smoothScroll);
     }
 
+    /**
+     * Obtains the current page number respecting RTL
+     */
+    private int getCurrentPageNumber() {
+        int page = getCurrentItem();
+        if (mLayoutDirection == LAYOUT_DIRECTION_RTL) {
+            page = mPages.size() - 1 - page;
+        }
+        return page;
+    }
+
     @Override
     public void setListening(boolean listening) {
         if (mListening == listening) return;
@@ -199,7 +212,7 @@
         // marquee. This will ensure that accessibility doesn't announce the TYPE_VIEW_SELECTED
         // event on any of the children.
         setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
-        int currentItem = isLayoutRtl() ? mPages.size() - 1 - getCurrentItem() : getCurrentItem();
+        int currentItem = getCurrentPageNumber();
         for (int i = 0; i < mPages.size(); i++) {
             mPages.get(i).setSelected(i == currentItem ? selected : false);
         }
@@ -328,7 +341,7 @@
 
     public int getNumVisibleTiles() {
         if (mPages.size() == 0) return 0;
-        TilePage currentPage = mPages.get(getCurrentItem());
+        TilePage currentPage = mPages.get(getCurrentPageNumber());
         return currentPage.mRecords.size();
     }