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

Commit e4c0797a authored by AdrianDC's avatar AdrianDC Committed by Roman Birg
Browse files

QuickSettings: Improve draggable tiles management



 * Hide the carret on dual tiles that don't have details
 * Handle dual label clicks as primary for basic tiles
 * Fix the ripples management to avoid missing effects
 * Prevent a crash on wrong size array to add a tile

Change-Id: I01471ea6e279b3437961c30bcfa922e9e0872388
Signed-off-by: default avatarAdrianDC <radian.dc@gmail.com>
parent a9cdd4ff
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -870,8 +870,6 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
                    @Override
                    public void onAnimationStart(Animator animation) {
                        mDraggingRecord.tileView.setAlpha(1);
                        mDraggingRecord.tileView.setBackground(
                                mDraggingRecord.tileView.newTileBackground());
                    }

                    @Override
@@ -977,15 +975,14 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
        final DragTileRecord record = (DragTileRecord) getRecord(v);
        if (record == null) {
            // TODO couldn't find a matching tag?
            Log.e(TAG, "got a null record on touh down.");
            Log.e(TAG, "got a null record on touch down.");
            return false;
        }

        mDraggingRecord = record;

        mDraggingRecord.tileView.setAlpha(0);
        mDraggingRecord.tileView.setTileBackground(null);
        mDraggingRecord.tileView.setDual(false);
        mDraggingRecord.tileView.setDual(false, false);
        TileShadow mTileShadow = new TileShadow(mDraggingRecord.tileView);

        v.startDrag(null, mTileShadow, null, 0);
@@ -1261,7 +1258,7 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
                        .setListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator animation) {
                                if (ti.tileView.setDual(dual)) {
                                if (ti.tileView.setDual(dual, ti.tile.hasDualTargetsDetails())) {
                                    if (DEBUG_DRAG) {
                                        Log.w(TAG, ti + " changed dual state to : "
                                                + ti.tileView.isDual());
@@ -1319,9 +1316,12 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
        }
        String[] defaults =
                getContext().getString(R.string.quick_settings_tiles_default).split(",");
        final String[] available = new String[defaults.length + 1
                - (tiles.size() - numBroadcast)];
        final String[] availableTiles = new String[available.length];
        int availableSize = defaults.length + 1 - (tiles.size() - numBroadcast);
        if (availableSize < 1) {
            availableSize = 1;
        }
        final String[] available = new String[availableSize];
        final String[] availableTiles = new String[availableSize];
        int index = 0;
        for (int i = 0; i < defaults.length; i++) {
            if (tiles.contains(defaults[i])) {
+1 −2
Original line number Diff line number Diff line
@@ -58,7 +58,6 @@ public class QSPage extends ViewGroup {
                if (record.page != mPage) continue;
                if (record.tileView.getVisibility() == GONE) continue;

                boolean dual = dualRecord(record);
                if (mPage == 0 && r == 0 && c == 1) {
                    r = 1;
                    c = 0;
@@ -82,7 +81,7 @@ public class QSPage extends ViewGroup {
            if (record.page != record.destinationPage) continue;

            final boolean dual = dualRecord(record);
            if (record.tileView.setDual(dual)) {
            if (record.tileView.setDual(dual, record.tile.hasDualTargetsDetails())) {
                record.tileView.handleStateChanged(record.tile.getState());
            }
            if (record.tileView.getVisibility() == GONE) continue;
+3 −5
Original line number Diff line number Diff line
@@ -483,15 +483,12 @@ public class QSPanel extends ViewGroup {
        int r = -1;
        int c = -1;
        int rows = 0;
        boolean rowIsDual = false;
        for (TileRecord record : mRecords) {
            if (record.tileView.getVisibility() == GONE) continue;
            // wrap to next column if we've reached the max # of columns
            // also don't allow dual + single tiles on the same row
            if (r == -1 || c == (mColumns - 1) || rowIsDual != record.tile.supportsDualTargets()) {
            if (r == -1 || c == (mColumns - 1)) {
                r++;
                c = 0;
                rowIsDual = record.tile.supportsDualTargets();
            } else {
                c++;
            }
@@ -502,7 +499,8 @@ public class QSPanel extends ViewGroup {

        View previousView = mBrightnessView;
        for (TileRecord record : mRecords) {
            if (record.tileView.setDual(record.tile.supportsDualTargets())) {
            final boolean dualTarget = record.tile.hasDualTargetsDetails();
            if (record.tileView.setDual(dualTarget, dualTarget)) {
                record.tileView.handleStateChanged(record.tile.getState());
            }
            if (record.tileView.getVisibility() == GONE) continue;
+2 −2
Original line number Diff line number Diff line
@@ -84,8 +84,8 @@ public abstract class QSTile<TState extends State> implements Listenable {
        mHandler = new H(host.getLooper());
    }

    public boolean supportsDualTargets() {
        return true;
    public boolean hasDualTargetsDetails() {
        return false;
    }

    public Host getHost() {
+21 −14
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 * Copyright (C) 2015 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -66,6 +67,7 @@ public class QSTileView extends ViewGroup {
    private TextView mLabel;
    private QSDualTileLabel mDualLabel;
    private boolean mDual;
    private boolean mDualDetails;
    private OnClickListener mClickPrimary;
    private OnClickListener mClickSecondary;
    private OnLongClickListener mLongClick;
@@ -145,15 +147,18 @@ public class QSTileView extends ViewGroup {
            mDualLabel = new QSDualTileLabel(mContext);
            mDualLabel.setId(View.generateViewId());
            mDualLabel.setBackgroundResource(R.drawable.btn_borderless_rect);
            if (mDualDetails) {
                mDualLabel.setFirstLineCaret(mContext.getDrawable(R.drawable.qs_dual_tile_caret));
            }
            mDualLabel.setTextColor(mContext.getColor(R.color.qs_tile_text));
            mDualLabel.setPadding(0, mDualTileVerticalPaddingPx, 0, mDualTileVerticalPaddingPx);
            mDualLabel.setTypeface(CONDENSED);
            mDualLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                    res.getDimensionPixelSize(R.dimen.qs_tile_text_size));
            mDualLabel.setClickable(true);
            mDualLabel.setOnClickListener(mClickSecondary);
            mDualLabel.setFocusable(true);
            mDualLabel.setOnClickListener(mDualDetails ? mClickSecondary : mClickPrimary);
            mDualLabel.setOnLongClickListener(mLongClick);
            if (labelText != null) {
                mDualLabel.setText(labelText);
            }
@@ -172,6 +177,7 @@ public class QSTileView extends ViewGroup {
            mLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                    res.getDimensionPixelSize(R.dimen.qs_tile_text_size));
            mLabel.setClickable(false);
            mLabel.setFocusable(false);
            if (labelText != null) {
                mLabel.setText(labelText);
            }
@@ -183,45 +189,46 @@ public class QSTileView extends ViewGroup {
        return mDual;
    }

    public boolean setDual(boolean dual) {
    public boolean setDual(boolean dual, boolean hasDetails) {
        final boolean changed = dual != mDual;
        mDual = dual;
        mDualDetails = hasDetails;
        if (changed) {
            recreateLabel();
        }

        if (dual) {
            mTopBackgroundView.setOnClickListener(mClickPrimary);
            mTopBackgroundView.setOnLongClickListener(mLongClick);
            setOnClickListener(null);
            setClickable(false);
            setOnLongClickListener(null);
            setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
        } else {
            mTopBackgroundView.setOnClickListener(null);
            mTopBackgroundView.setClickable(false);
            mTopBackgroundView.setOnLongClickListener(null);
            setOnClickListener(mClickPrimary);
            setOnLongClickListener(mLongClick);
            setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
        }
        setTileBackground(mTileBackground);
        setTileBackground();
        mTopBackgroundView.setClickable(dual);
        mTopBackgroundView.setFocusable(dual);
        setClickable(!dual);
        setFocusable(!dual);
        mDivider.setVisibility(dual ? VISIBLE : GONE);
        mTopBackgroundView.setVisibility(dual ? VISIBLE : GONE);
        postInvalidate();
        return changed;
    }

    protected void setTileBackground(Drawable background) {
        mTileBackground = background;
    protected void setTileBackground() {
        if (mTileBackground instanceof RippleDrawable) {
            setRipple((RippleDrawable) mTileBackground);
        } else {
            setRipple(null);
        }
        if (mDual) {
            mTopBackgroundView.setBackground(mTileBackground);
        } else {
            setBackground(mTileBackground);
        }
        mTopBackgroundView.setBackground(mDual ? mTileBackground : null);
        setBackground(!mDual ? mTileBackground : null);
    }

    private void setRipple(RippleDrawable tileBackground) {
@@ -373,6 +380,7 @@ public class QSTileView extends ViewGroup {
        if (mDual) {
            if (mTopBackgroundView != null) {
                mTopBackgroundView.setFocusable(!editing);
                mTopBackgroundView.setClickable(!editing);
            }
            if (mDualLabel != null) {
                mDualLabel.setFocusable(!editing);
@@ -380,7 +388,6 @@ public class QSTileView extends ViewGroup {
            }
            setClickable(editing);
            setFocusable(editing);
            setOnLongClickListener(editing ? mLongClick : null);
        } else {
            if (mLabel != null) {
                mLabel.setFocusable(!editing);
Loading