Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 716fe59b authored by Roy Chou's avatar Roy Chou Committed by Android (Google) Code Review
Browse files

Merge "fix(non linear font scaling): qs customizer page tile height is not...

Merge "fix(non linear font scaling): qs customizer page tile height is not scaling with font size" into udc-dev
parents 49235d04 5a2d70e1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="@dimen/qs_tile_height"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_marginTop="@dimen/qs_tile_margin_top_bottom"
    android:layout_marginBottom="@dimen/qs_tile_margin_top_bottom"
+8 −0
Original line number Diff line number Diff line
@@ -114,11 +114,18 @@ public class QSCustomizer extends LinearLayout {
        mQs = qs;
    }

    private void reloadAdapterTileHeight(@Nullable RecyclerView.Adapter adapter) {
        if (adapter instanceof TileAdapter) {
            ((TileAdapter) adapter).reloadTileHeight();
        }
    }

    /** Animate and show QSCustomizer panel.
     * @param x,y Location on screen of {@code edit} button to determine center of animation.
     */
    void show(int x, int y, TileAdapter tileAdapter) {
        if (!isShown) {
            reloadAdapterTileHeight(tileAdapter);
            mRecyclerView.getLayoutManager().scrollToPosition(0);
            int[] containerLocation = findViewById(R.id.customize_container).getLocationOnScreen();
            mX = x - containerLocation[0];
@@ -136,6 +143,7 @@ public class QSCustomizer extends LinearLayout {

    void showImmediately() {
        if (!isShown) {
            reloadAdapterTileHeight(mRecyclerView.getAdapter());
            mRecyclerView.getLayoutManager().scrollToPosition(0);
            setVisibility(VISIBLE);
            mClipper.cancelAnimator();
+26 −0
Original line number Diff line number Diff line
@@ -43,9 +43,11 @@ import androidx.recyclerview.widget.RecyclerView.State;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;

import com.android.internal.logging.UiEventLogger;
import com.android.systemui.FontSizeUtils;
import com.android.systemui.R;
import com.android.systemui.qs.QSEditEvent;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.TileLayout;
import com.android.systemui.qs.customize.TileAdapter.Holder;
import com.android.systemui.qs.customize.TileQueryHelper.TileInfo;
import com.android.systemui.qs.customize.TileQueryHelper.TileStateListener;
@@ -114,6 +116,9 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
    private RecyclerView mRecyclerView;
    private int mNumColumns;

    private TextView mTempTextView;
    private int mMinTileViewHeight;

    @Inject
    public TileAdapter(
            @QSThemedContext Context context,
@@ -129,6 +134,8 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
        mNumColumns = context.getResources().getInteger(NUM_COLUMNS_ID);
        mAccessibilityDelegate = new TileAdapterDelegate();
        mSizeLookup.setSpanIndexCacheEnabled(true);
        mTempTextView = new TextView(context);
        mMinTileViewHeight = context.getResources().getDimensionPixelSize(R.dimen.qs_tile_height);
    }

    @Override
@@ -318,6 +325,10 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta

    @Override
    public void onBindViewHolder(final Holder holder, int position) {
        if (holder.mTileView != null) {
            holder.mTileView.setMinimumHeight(mMinTileViewHeight);
        }

        if (holder.getItemViewType() == TYPE_HEADER) {
            setSelectableForHeaders(holder.itemView);
            return;
@@ -860,4 +871,19 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
                - buttonMinWidth
                - res.getDimensionPixelSize(R.dimen.qs_tile_margin_top_bottom);
    }

    /**
     * Re-estimate the tile view height based under current font scaling. Like
     * {@link TileLayout#estimateCellHeight()}, the tile view height would be estimated with 2
     * labels as general case.
     */
    public void reloadTileHeight() {
        final int minHeight = mContext.getResources().getDimensionPixelSize(R.dimen.qs_tile_height);
        FontSizeUtils.updateFontSize(mTempTextView, R.dimen.qs_tile_text_size);
        int unspecifiedSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        mTempTextView.measure(unspecifiedSpec, unspecifiedSpec);
        int padding = mContext.getResources().getDimensionPixelSize(R.dimen.qs_tile_padding);
        int estimatedTileViewHeight = mTempTextView.getMeasuredHeight() * 2 + padding * 2;
        mMinTileViewHeight = Math.max(minHeight, estimatedTileViewHeight);
    }
}