Make ViewPagerTabs and FABController RTL aware

* Underline in ViewPagerTabStrips is correctly drawn in RTL mode
* Clicking on ViewPagerTabs propogates correct onPageSelected position
to ViewPager
* FAB is now end aligned instead of right aligned
* ViewPager in Dialer is correctly reversed and behaves correctly
* Call Log groups headers in call log are now correctly aligned in RTL
Bug: 16162264
Bug: 16464471
Change-Id: I2db6b9147a628a68fba5bbbdb7276855d483bad5
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index bf2af13..249e0c1 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -93,6 +93,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 
 /**
  * The dialer tab's title is 'phone', a more common name (see strings.xml).
@@ -1104,11 +1105,20 @@
 
     @Override
     public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+        position = mListsFragment.getRtlPosition(position);
         // Only scroll the button when the first tab is selected. The button should scroll from
         // the middle to right position only on the transition from the first tab to the second
         // tab.
-        if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
-            mFloatingActionButtonController.onPageScrolled(positionOffset);
+        // If the app is in RTL mode, we need to check against the second tab, rather than the
+        // first. This is because if we are scrolling between the first and second tabs, the
+        // viewpager will report that the starting tab position is 1 rather than 0, due to the
+        // reversal of the order of the tabs.
+        final boolean isLayoutRtl = DialerUtils.isRtl();
+        final boolean shouldScrollButton = position == (isLayoutRtl
+                ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
+        if (shouldScrollButton && !mIsLandscape) {
+            mFloatingActionButtonController.onPageScrolled(
+                    isLayoutRtl ? 1 - positionOffset : positionOffset);
         } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
             mFloatingActionButtonController.onPageScrolled(1);
         }
@@ -1116,6 +1126,7 @@
 
     @Override
     public void onPageSelected(int position) {
+        position = mListsFragment.getRtlPosition(position);
         mCurrentTabPosition = position;
     }
 
@@ -1163,15 +1174,15 @@
     private void updateFloatingActionButtonControllerAlignment(boolean animate) {
         int align;
         if (mIsDialpadShown) {
-            align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
+            align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_END
                     : FloatingActionButtonController.ALIGN_MIDDLE;
         } else {
             if (!mIsLandscape) {
                 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
                         ? FloatingActionButtonController.ALIGN_MIDDLE
-                            : FloatingActionButtonController.ALIGN_RIGHT;
+                            : FloatingActionButtonController.ALIGN_END;
             } else {
-                align = FloatingActionButtonController.ALIGN_RIGHT;
+                align = FloatingActionButtonController.ALIGN_END;
             }
         }
         mFloatingActionButtonController.align(align,