summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorErica Chang <echang@cyngn.com>2016-01-20 16:44:45 -0800
committerRichard MacGregor <rmacgregor@cyngn.com>2016-03-25 11:42:18 -0700
commit0fb9fa4edf2a56f25c6747765c05f3c421261792 (patch)
tree278c1b764d4d2ccb65e9c9850d4b1aef5cc8670f /src
parentefac5527eb3ba754e5efeb12958d741bad414741 (diff)
downloadandroid_packages_apps_ContactsCommon-0fb9fa4edf2a56f25c6747765c05f3c421261792.tar.gz
android_packages_apps_ContactsCommon-0fb9fa4edf2a56f25c6747765c05f3c421261792.tar.bz2
android_packages_apps_ContactsCommon-0fb9fa4edf2a56f25c6747765c05f3c421261792.zip
Stability fixes.
-Check that mIndexForSelection is >=0 in ViewPagerTabStrip -Contact Loader: parse for a JSONarray if num is -1 -Contacts: fixed TrueCaller mimetype contact card parsing -Contacts: fixed tab sliding offset upon onRestore Change-Id: Idf22af57d039ff19979335a7739d44c31dfaad58
Diffstat (limited to 'src')
-rw-r--r--src/com/android/contacts/common/list/ViewPagerTabStrip.java2
-rw-r--r--src/com/android/contacts/common/list/ViewPagerTabs.java26
-rw-r--r--src/com/android/contacts/common/model/ContactLoader.java17
3 files changed, 39 insertions, 6 deletions
diff --git a/src/com/android/contacts/common/list/ViewPagerTabStrip.java b/src/com/android/contacts/common/list/ViewPagerTabStrip.java
index c8ae21a2..125720e6 100644
--- a/src/com/android/contacts/common/list/ViewPagerTabStrip.java
+++ b/src/com/android/contacts/common/list/ViewPagerTabStrip.java
@@ -70,7 +70,7 @@ public class ViewPagerTabStrip extends LinearLayout {
int childCount = getChildCount();
// Thick colored underline below the current selection
- if (childCount > 0) {
+ if (childCount > 0 && mIndexForSelection >= 0 && mIndexForSelection < childCount) {
View selectedTitle = getChildAt(mIndexForSelection);
if (selectedTitle == null) {
diff --git a/src/com/android/contacts/common/list/ViewPagerTabs.java b/src/com/android/contacts/common/list/ViewPagerTabs.java
index 1ecbb4c9..87a0439f 100644
--- a/src/com/android/contacts/common/list/ViewPagerTabs.java
+++ b/src/com/android/contacts/common/list/ViewPagerTabs.java
@@ -26,6 +26,7 @@ import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewOutlineProvider;
+import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
@@ -44,6 +45,9 @@ public class ViewPagerTabs extends HorizontalScrollView implements ViewPager.OnP
ViewPager mPager;
private ViewPagerTabStrip mTabStrip;
+ // Keep track if scrolling to the target tab should be performed after the View has been
+ // rendered (so View.getWidth() returns valid values)
+ ViewTreeObserver mTabLayoutObserver;
/**
* Linearlayout that will contain the TextViews serving as tabs. This is the only child
@@ -230,9 +234,29 @@ public class ViewPagerTabs extends HorizontalScrollView implements ViewPager.OnP
selectedChild.setSelected(true);
// Update scroll position
+ mPrevSelected = position;
+ if (selectedChild.getWidth() == 0) {
+ // this View is not laid out yet, defer scroll calculation
+ mTabLayoutObserver = selectedChild.getViewTreeObserver();
+ mTabLayoutObserver.addOnGlobalLayoutListener(new ViewTreeObserver
+ .OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ if (mTabLayoutObserver != null && mTabLayoutObserver.isAlive()) {
+ performScroll();
+ mTabLayoutObserver.removeOnGlobalLayoutListener(this);
+ }
+ }
+ });
+ } else {
+ performScroll();
+ }
+ }
+
+ public void performScroll() {
+ final View selectedChild = mTabStrip.getChildAt(mPrevSelected);
final int scrollPos = selectedChild.getLeft() - (getWidth() - selectedChild.getWidth()) / 2;
smoothScrollTo(scrollPos, 0);
- mPrevSelected = position;
}
@Override
diff --git a/src/com/android/contacts/common/model/ContactLoader.java b/src/com/android/contacts/common/model/ContactLoader.java
index e27635a7..2741205b 100644
--- a/src/com/android/contacts/common/model/ContactLoader.java
+++ b/src/com/android/contacts/common/model/ContactLoader.java
@@ -451,12 +451,12 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
while (keys.hasNext()) {
final String mimetype = (String) keys.next();
- // Could be single object, int, or array.
+ // Could be single object, int, array or a string.
JSONObject obj = items.optJSONObject(mimetype);
final int num = items.optInt(mimetype, -1);
- if (obj == null && num == -1) {
- // Neither object nor int, thus must be array
- final JSONArray array = items.getJSONArray(mimetype);
+ final JSONArray array = items.optJSONArray(mimetype);
+ final String str = items.optString(mimetype, null);
+ if (array != null) {
for (int i = 0; i < array.length(); i++) {
final JSONObject item = array.getJSONObject(i);
processOneRecord(rawContact, item, mimetype);
@@ -466,7 +466,16 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
obj.put(mimetype, num);
processOneRecord(rawContact, obj, mimetype);
} else if (obj != null) {
+ // when obj is true, str type is true too, so handle obj type first
processOneRecord(rawContact, obj, mimetype);
+ } else if (str != null){
+ // when it's a true string, obj is null
+ obj = new JSONObject();
+ obj.put(mimetype, str);
+ processOneRecord(rawContact, obj, mimetype);
+ } else {
+ // unknown type
+ continue;
}
}