askerov / DynamicGrid

Drag and drop GridView for Android
Apache License 2.0
926 stars 288 forks source link

Cell visibility issues when reordering on Android L #39

Open SteveMil opened 9 years ago

SteveMil commented 9 years ago

I'm running the 'official' pre-release version of Android L (LPV79) on my Nexus 5. Both DynamicGridExample and my app have cell visibility issues when reordering. I was able to fix it just by stubbing out two calls to setVisibility() in handleCellSwitch() in DynamicGridView.java. I added the following code to dynamically check for L and only make the calls if on a pre-L OS. I'm not sure this is the best fix, but is working for me at the moment.

/**
 * The GridView from Android L requires some different setVisibility() logic
 * when switching cells. Unfortunately, both 4.4W and the pre-release L
 * report 20 for the SDK_INT, but we want to return true for 4.4W and false
 * for Android L. So, we check the release name for "L" if we see SDK 20.
 * Hopefully, Android L will actually be SDK 21 or later when it ships.   
 *
 * @return
 */
private boolean isPreL() {
    final int KITKAT_WATCH = 20;
    return (Build.VERSION.SDK_INT < KITKAT_WATCH) ||
           ((Build.VERSION.SDK_INT == KITKAT_WATCH) && !"L".equals(Build.VERSION.RELEASE));
}

private void handleCellSwitch() {
...
        if (isPreL()) {
            mobileView.setVisibility(View.VISIBLE);
        }
        if (isPostHoneycomb() && isPreL()) {
            targetView.setVisibility(View.INVISIBLE);
        }
...
}
JohNan commented 9 years ago

I have added another fix to the problem described above. See pull request #41