Fix layout transitions on foldable devices

This commit is contained in:
Cameron Gutman
2019-09-08 11:11:02 -07:00
parent a2fc62a4a8
commit 593616d2d9
5 changed files with 98 additions and 17 deletions

View File

@@ -26,6 +26,7 @@ import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
@@ -96,8 +97,7 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
try {
appGridAdapter = new AppGridAdapter(AppView.this,
PreferenceConfiguration.readPreferences(AppView.this).listMode,
PreferenceConfiguration.readPreferences(AppView.this).smallIconMode,
PreferenceConfiguration.readPreferences(AppView.this),
computer, localBinder.getUniqueId());
} catch (Exception e) {
e.printStackTrace();
@@ -147,6 +147,27 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
}
};
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// If appGridAdapter is initialized, let it know about the configuration change.
// If not, it will pick it up when it initializes.
if (appGridAdapter != null) {
// Update the app grid adapter to create grid items with the correct layout
appGridAdapter.updateLayoutWithPreferences(this, PreferenceConfiguration.readPreferences(this));
try {
// Reinflate the app grid itself to pick up the layout change
getFragmentManager().beginTransaction()
.replace(R.id.appFragmentContainer, new AdapterFragment())
.commitAllowingStateLoss();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
}
private void startComputerUpdates() {
// Don't start polling if we're not bound or in the foreground
if (managerBinder == null || !inForeground) {