summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author Cassy Chun-Crogan <cassycc@google.com> 2025-03-19 01:26:23 +0000
committer Cassy Chun-Crogan <cassycc@google.com> 2025-03-20 04:27:08 +0000
commitf9ecf70950aebdee209df17d3b20c3821f448e86 (patch)
tree7d1a02a19ef2d562739d9745b2de23c21e8d7237 /src
parent351a3e2f8408f527d408d55d956558493c507d8c (diff)
[DocsUI M3] Re-layout file list on window size change
Previously only a directory load or an app bar layout change would re-layout the file list. A lot of small, incremental window size changes would not trigger a re-layout leading to a strange UI or overcrowded items or excessive space. Update the layout whenever the AnimationView (the directory fragment) observes a size change. Introduce an OnSizeChangedListener to trigger the re-layout. Also use the dimens grid_width, grid_height and grid_item_margin on the grid item (item_doc_grid.xml) as these are also used by the DirectoryFragment.java to get the correct spacing for the layout. See bug for demo video. Bug: 404625076 Test: m DocumentsUIGoogle && manual inspection Flag: com.android.documentsui.flags.use_material3 Change-Id: I5e2a94757b8effc2462f818bc2fa286fefcd4740
Diffstat (limited to 'src')
-rw-r--r--src/com/android/documentsui/dirlist/AnimationView.java43
-rw-r--r--src/com/android/documentsui/dirlist/DirectoryFragment.java24
2 files changed, 62 insertions, 5 deletions
diff --git a/src/com/android/documentsui/dirlist/AnimationView.java b/src/com/android/documentsui/dirlist/AnimationView.java
index d17bddf98..5813085b3 100644
--- a/src/com/android/documentsui/dirlist/AnimationView.java
+++ b/src/com/android/documentsui/dirlist/AnimationView.java
@@ -16,19 +16,22 @@
package com.android.documentsui.dirlist;
-import androidx.annotation.IntDef;
-import androidx.fragment.app.FragmentTransaction;
+import static com.android.documentsui.util.FlagUtils.isUseMaterial3FlagEnabled;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.widget.LinearLayout;
+import androidx.annotation.IntDef;
+import androidx.fragment.app.FragmentTransaction;
+
import com.android.documentsui.R;
import com.android.documentsui.base.Shared;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.ArrayList;
/**
* This class exists solely to support animated transition of our directory fragment.
@@ -51,6 +54,8 @@ public class AnimationView extends LinearLayout {
public static final int ANIM_LEAVE = 3;
public static final int ANIM_ENTER = 4;
+ private final ArrayList<OnSizeChangedListener> mOnSizeChangedListeners = new ArrayList<>();
+
private float mPosition = 0f;
// The distance the animation will cover...currently matches the height of the
@@ -65,11 +70,45 @@ public class AnimationView extends LinearLayout {
super(context, attrs);
}
+ /**
+ * A listener of the onSizeChanged method.
+ */
+ public interface OnSizeChangedListener {
+ /**
+ * Called on the View's onSizeChanged.
+ */
+ void onSizeChanged();
+ }
+
+ /**
+ * Adds a listener of the onSizeChanged method.
+ */
+ public void addOnSizeChangedListener(OnSizeChangedListener listener) {
+ if (isUseMaterial3FlagEnabled()) {
+ mOnSizeChangedListeners.add(listener);
+ }
+ }
+
+ /**
+ * Removes a listener of the onSizeChanged method.
+ */
+ public void removeOnSizeChangedListener(OnSizeChangedListener listener) {
+ if (isUseMaterial3FlagEnabled()) {
+ mOnSizeChangedListeners.remove(listener);
+ }
+ }
+
+
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mSpan = h;
setPosition(mPosition);
+ if (isUseMaterial3FlagEnabled()) {
+ for (int i = mOnSizeChangedListeners.size() - 1; i >= 0; --i) {
+ mOnSizeChangedListeners.get(i).onSizeChanged();
+ }
+ }
}
public float getPosition() {
diff --git a/src/com/android/documentsui/dirlist/DirectoryFragment.java b/src/com/android/documentsui/dirlist/DirectoryFragment.java
index 2ea906a60..2911d04e9 100644
--- a/src/com/android/documentsui/dirlist/DirectoryFragment.java
+++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java
@@ -108,6 +108,7 @@ import com.android.documentsui.clipping.ClipStore;
import com.android.documentsui.clipping.DocumentClipper;
import com.android.documentsui.clipping.UrisSupplier;
import com.android.documentsui.dirlist.AnimationView.AnimationType;
+import com.android.documentsui.dirlist.AnimationView.OnSizeChangedListener;
import com.android.documentsui.picker.PickActivity;
import com.android.documentsui.services.FileOperation;
import com.android.documentsui.services.FileOperationService;
@@ -188,7 +189,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
private SelectionMetadata mSelectionMetadata;
private KeyInputHandler mKeyListener;
private @Nullable DragHoverListener mDragHoverListener;
- private View mRootView;
+ private AnimationView mRootView;
private IconHelper mIconHelper;
private SwipeRefreshLayout mRefreshLayout;
private RecyclerView mRecView;
@@ -416,13 +417,27 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
|| Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action);
}
+ private OnSizeChangedListener mOnSizeChangedListener =
+ new AnimationView.OnSizeChangedListener() {
+ @Override
+ public void onSizeChanged() {
+ if (isUseMaterial3FlagEnabled() && mState.derivedMode != MODE_LIST) {
+ // Update the grid layout when the window size changes.
+ updateLayout(mState.derivedMode);
+ }
+ }
+ };
+
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mHandler = new Handler(Looper.getMainLooper());
mActivity = (BaseActivity) getActivity();
- mRootView = inflater.inflate(R.layout.fragment_directory, container, false);
+ mRootView = (AnimationView) inflater.inflate(R.layout.fragment_directory, container, false);
+ if (isUseMaterial3FlagEnabled()) {
+ mRootView.addOnSizeChangedListener(mOnSizeChangedListener);
+ }
mProgressBar = mRootView.findViewById(R.id.progressbar);
assert mProgressBar != null;
@@ -497,6 +512,10 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
mModel.removeUpdateListener(mAdapter.getModelUpdateListener());
setPreDrawListenerEnabled(false);
+ if (isUseMaterial3FlagEnabled()) {
+ mRootView.removeOnSizeChangedListener(mOnSizeChangedListener);
+ }
+
super.onDestroyView();
}
@@ -809,7 +828,6 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
if (mLayout != null) {
mLayout.setSpanCount(mColumnCount);
}
-
int pad = getDirectoryPadding(mode);
mAppBarHeight = getAppBarLayoutHeight();
mSaveLayoutHeight = getSaveLayoutHeight();