OSDN Git Service

Fix ListView can not be moved after rotation.
authorJiongxuan Gao <jiongxuan.xa.gao@sonymobile.com>
Thu, 24 Nov 2016 11:20:27 +0000 (20:20 +0900)
committerAdam Powell <adamp@google.com>
Tue, 29 Aug 2017 17:26:39 +0000 (10:26 -0700)
Symptom:
"Share with" popup displayed incompletely, and cannot be slid after
rotated the screen twice.

Root cause:
Since ChooserActivity's configChanges attribute contains
"screenSize|orientation" , when user rotates device, Android will
not recreate ChooserActivity, its content view ResolverDrawerLayout
is also not recreated. In ResolverDrawerLayout's onMeasure, it will
call getHeightUsed to calculate the ListView's height. getHeightUsed
will check against the lowest child view plus padding and margin
instead of the actual measured height of the ListView. This lets the
ListView hang off the edge when all of the content would fit on-screen
. Because of ResolverDrawerLayout has not been drawn yet, we can not
get the actual showing items' count of ListView before it's drawn, the
result of getChildCount for ListView will return the value in landscape
mode. The heightUsed of ListView might be smaller. mCollapsibleHeight
will be 0. When received a move action, the mCollapseOffset and new
position might both be 0.

Solution:
When configuration changed, we should rebuild the list and refresh
adapter's data set. Just like onRestart does.

Bug: 34365764

Change-Id: I4be0f9afc68588fbb0d8d152c41509650d04c754

core/java/com/android/internal/app/ResolverActivity.java

index 5c1bafd..b2ed8b5 100644 (file)
@@ -36,6 +36,7 @@ import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
 import android.content.pm.UserInfo;
+import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
@@ -332,6 +333,12 @@ public class ResolverActivity extends Activity {
                         + (categories != null ? Arrays.toString(categories.toArray()) : ""));
     }
 
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+        mAdapter.handlePackagesChanged();
+    }
+
     /**
      * Perform any initialization needed for voice interaction.
      */