summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com/android/systemui/qs/QSPage.java
blob: 7871a62bb2a5a2360dde58a1443a59d84e404ec8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package com.android.systemui.qs;

import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import com.android.systemui.R;

public class QSPage extends ViewGroup {

    private static final String TAG = "QSPage";

    static final float TILE_ASPECT = 1.2f;

    private int mCellWidth;
    private int mCellHeight;
    private int mLargeCellWidth;
    private int mLargeCellHeight;
    private int mGridHeight;

    private QSDragPanel mPanel;

    private int mPage;

    private boolean mAdapterEditingState;

    public QSPage(Context context, QSDragPanel panel, int page) {
        super(context);
        mPanel = panel;
        mPage = page;
        updateResources();
        setClipChildren(false);
        setClipToPadding(false);
        setClipToOutline(false);
    }

    @Override
    public boolean hasOverlappingRendering() {
        return false;
    }

    public int getPageIndex() {
        return mPage;
    }

    public void updateResources() {
        final Resources res = mContext.getResources();
        final int columns = Math.max(1, res.getInteger(R.integer.quick_settings_num_columns));
        mCellHeight = res.getDimensionPixelSize(R.dimen.qs_tile_height);
        mCellWidth = (int)(mCellHeight * TILE_ASPECT);
        mLargeCellHeight = res.getDimensionPixelSize(R.dimen.qs_dual_tile_height);
        mLargeCellWidth = (int)(mLargeCellHeight * TILE_ASPECT);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int width = MeasureSpec.getSize(widthMeasureSpec);
        if (mPanel.mCurrentlyAnimating.isEmpty() && !mPanel.isDragging()) {
            int r = -1;
            int c = -1;
            int rows = 0;
            for (QSPanel.TileRecord ts : mPanel.mRecords) {
                QSDragPanel.DragTileRecord record = (QSDragPanel.DragTileRecord) ts;
                if (record.page != mPage) continue;
                if (record.tileView.getVisibility() == GONE) continue;

                if (mPage == 0 && r == 0 && c == 1 && mPanel.mFirstRowLarge) {
                    r = 1;
                    c = 0;
                } else if (r == -1 || c == (mPanel.getColumnCount() - 1)) {
                    r++;
                    c = 0;
                } else {
                    c++;
                }
                record.row = r;
                record.col = c;
                rows = r + 1;
            }
            mGridHeight = mPanel.getRowTop(rows);
        }

        View previousView = mPanel.getBrightnessView();
        for (QSPanel.TileRecord ts : mPanel.mRecords) {
            QSDragPanel.DragTileRecord record = (QSDragPanel.DragTileRecord) ts;
            if (record.page != mPage) continue;
            if (record.page != record.destinationPage) continue;

            final boolean dual = dualRecord(record);
            if (record.tileView.setDual(dual, record.tile.hasDualTargetsDetails())) {
                record.tileView.handleStateChanged(record.tile.getState());
            }
            if (record.tileView.getVisibility() == GONE) continue;
            final int cw = dual ? mLargeCellWidth : mCellWidth;
            final int ch = dual ? mLargeCellHeight : mCellHeight;
            record.tileView.measure(exactly(cw), exactly(ch));
            previousView = record.tileView.updateAccessibilityOrder(previousView);
        }
        setMeasuredDimension(width, mGridHeight);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        final int w = getWidth();
        boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
        for (QSPanel.TileRecord ts : mPanel.mRecords) {
            QSDragPanel.DragTileRecord record = (QSDragPanel.DragTileRecord) ts;
            if (record.page != mPage) continue;
            if (record.page != record.destinationPage) continue;
            if (record.tileView.getVisibility() == GONE) continue;

            final int cols = mPanel.getColumnCount(mPage, record.row);

            int left = mPanel.getLeft(record.row, record.col, cols, dualRecord(record));
            final int top = mPanel.getRowTop(record.row);
            int right;
            int tileWith = record.tileView.getMeasuredWidth();
            if (isRtl) {
                right = w - left;
                left = right - tileWith;
            } else {
                right = left + tileWith;
            }
            if (mPanel.isAnimating(record)) {
                record.tileView.layout(record.tileView.getLeft(), record.tileView.getTop(),
                        record.tileView.getRight(), record.tileView.getBottom());
                continue;
            }
            if (false) {
                Log.v(TAG + "-" + mPage, "laying out " + record + ", top: " + top + ", left: " + left);
                Log.d(TAG, record + " wiping translations: "
                        + record.tileView.getTranslationX()
                        + ", " + record.tileView.getTranslationY());
            }
            record.tileView.setTranslationX(0);
            record.tileView.setTranslationY(0);

            record.destination.x = record.tileView.getX();
            record.destination.y = record.tileView.getY();

            record.tileView.layout(left, top, right, top + record.tileView.getMeasuredHeight());
        }
    }

    public boolean getAdapterEditingState() {
        return mAdapterEditingState;
    }

    public void setAdapterEditingState(boolean editing) {
        this.mAdapterEditingState = editing;
    }

    public boolean dualRecord(QSPanel.TileRecord record) {
        return mPanel.mFirstRowLarge && record.row == 0 && mPage == 0;
    }

    private static int exactly(int size) {
        return MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);
    }
}