Dream settings refactor.
We will be re-using the grid UI for the dream complication picker, so this change refactors some of that logic so it can be re-used in the complication controller. We also update some of the UI here to match the most recent UX decisions. http://screen/BxhAwZwQSVoxUmN.png Test: locally on device Test: make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.dream.DreamPickerControllerTest" Bug: 214250590 Bug: 215703483 Change-Id: I9fbfa0f0cd31ae3d119c7cd1a9562d4cdb203d6c
This commit is contained in:
44
src/com/android/settings/dream/AutoFitGridLayoutManager.java
Normal file
44
src/com/android/settings/dream/AutoFitGridLayoutManager.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/** Grid layout manager that calculates the number of columns for the screen size. */
|
||||
final class AutoFitGridLayoutManager extends GridLayoutManager {
|
||||
private final float mColumnWidth;
|
||||
|
||||
AutoFitGridLayoutManager(Context context) {
|
||||
super(context, /* spanCount= */ 1);
|
||||
this.mColumnWidth = context
|
||||
.getResources()
|
||||
.getDimensionPixelSize(R.dimen.dream_item_min_column_width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||
final int totalSpace = getWidth() - getPaddingRight() - getPaddingLeft();
|
||||
final int spanCount = Math.max(1, (int) (totalSpace / mColumnWidth));
|
||||
setSpanCount(spanCount);
|
||||
super.onLayoutChildren(recycler, state);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user