summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErica Chang <echang@cyngn.com>2016-03-29 14:01:09 -0700
committerRichard MacGregor <rmacgregor@cyngn.com>2016-04-07 12:09:53 -0700
commit3ac79f50384f41e05c0b6314bea2fd7455a851e6 (patch)
tree4dcbf33abbee09eea44919d547e837037cce4171
parent2f2dd2e9d4bbf0be58b749413ac44747d7aa0bdd (diff)
downloadandroid_packages_apps_ContactsCommon-3ac79f50384f41e05c0b6314bea2fd7455a851e6.tar.gz
android_packages_apps_ContactsCommon-3ac79f50384f41e05c0b6314bea2fd7455a851e6.tar.bz2
android_packages_apps_ContactsCommon-3ac79f50384f41e05c0b6314bea2fd7455a851e6.zip
Contacts : fix RTL ViewPager offset on configuration change
Specifically in RTL, during a screen rotation to landscape, there's a window during init where ViewPagerTabs is not yet attached to a parent. Without a parent, View.getLayoutDirection() cannot resolve layout directions and as a result is unable to restore the previously selected ViewPager tab. CYNGNOS-2281 Change-Id: I25c12efda856b38b9a2a38c0d538eb283edffaa1
-rw-r--r--src/com/android/contacts/common/list/ViewPagerTabs.java18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/com/android/contacts/common/list/ViewPagerTabs.java b/src/com/android/contacts/common/list/ViewPagerTabs.java
index 87a0439f..c43f4211 100644
--- a/src/com/android/contacts/common/list/ViewPagerTabs.java
+++ b/src/com/android/contacts/common/list/ViewPagerTabs.java
@@ -21,6 +21,7 @@ import android.content.res.TypedArray;
import android.graphics.Outline;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
@@ -35,6 +36,8 @@ import android.widget.Toast;
import com.android.contacts.common.R;
+import java.util.Locale;
+
/**
* Lightweight implementation of ViewPager tabs. This looks similar to traditional actionBar tabs,
* but allows for the view containing the tabs to be placed anywhere on screen. Text-related
@@ -264,10 +267,19 @@ public class ViewPagerTabs extends HorizontalScrollView implements ViewPager.OnP
}
private int getRtlPosition(int position) {
- if (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
- return mTabStrip.getChildCount() - 1 - position;
+ boolean isRtl;
+ // This function may be called before this View is attached to a parent. During this
+ // window in time, View.getLayoutDirection() may not return the right layout direction so
+ // this check is needed
+ if (canResolveLayoutDirection()) {
+ isRtl = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
+ } else {
+ // cannot resolve layout direction from view (usually during on configuration change),
+ // fall back to using locale
+ final Locale locale = Locale.getDefault();
+ isRtl = TextUtils.getLayoutDirectionFromLocale(locale) == View.LAYOUT_DIRECTION_RTL;
}
- return position;
+ return isRtl ? (mTabStrip.getChildCount() - 1 - position) : position;
}
}