问题描述
客户需求:
竖屏时快捷设置栏一行6个、横屏时快捷设置栏一行8个; 竖屏时快捷栏展开一行5个、横屏时快捷栏展开一行8个。
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// We only care about clipping on the right side
mClippingBounds.set(0, 0, r - l, 10000);
setClipBounds(mClippingBounds);
calculateColumns();
for (int i = 0; i < mRecords.size(); i++) {
//这里设置gone掉多余的显示
mRecords.get(i).tileView.setVisibility( i < getResources().getInteger(R.integer.quick_qs_panel_columns) ? View.VISIBLE : View.GONE);
}
setAccessibilityOrder();
layoutTileRecords(mColumns);
}
private boolean calculateColumns() {
int prevNumColumns = mColumns;
//这里修改最大显示个数
int maxTiles = /*mRecords.size()*/getResources().getInteger(R.integer.quick_qs_panel_columns);
if (maxTiles == 0){ // Early return during setup
mColumns = 0;
return true;
}
final int availableWidth = getMeasuredWidth() - getPaddingStart() - getPaddingEnd();
final int leftoverWhitespace = availableWidth - maxTiles * mCellWidth;
final int smallestHorizontalMarginNeeded;
smallestHorizontalMarginNeeded = leftoverWhitespace / Math.max(1, maxTiles - 1);
if (smallestHorizontalMarginNeeded > 0){
mCellMarginHorizontal = smallestHorizontalMarginNeeded;
mColumns = maxTiles;
} else{
mColumns = mCellWidth == 0 ? 1 :
Math.min(maxTiles, availableWidth / mCellWidth );
// If we can only fit one column, use mCellMarginHorizontal to center it.
if (mColumns == 1) {
mCellMarginHorizontal = (availableWidth - mCellWidth) / 2;
} else {
mCellMarginHorizontal =
(availableWidth - mColumns * mCellWidth) / (mColumns - 1);
}
}
return mColumns != prevNumColumns;
}
存在问题:
当用户手动删除多余的快捷设置图标,只剩下6个的时候。 这时候如果切换横屏,因为横屏要显示8个,maxTiles = 8 ,mColumns = 8。
1、vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/TileLayout.java
layoutTileRecords(mColumns);中,就会数组越界。
2、vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java
public void setListening(boolean listening)数组越界。
编辑展开一行显示的个数
<integer name="quick_settings_num_columns">5</integer>
快捷设置栏最少图标总数,长按拖出到小于6时,会提示并拖拽失败
<integer name="quick_settings_min_num_tiles">6</integer>
|