summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorDanesh Mondegarian <daneshm90@gmail.com>2013-05-12 18:52:46 -0400
committerDanesh Mondegarian <daneshm90@gmail.com>2013-05-12 19:21:08 -0400
commita0278c23f0dd159475366c6175409ab51878375e (patch)
tree89549503767111719363e58d9e05c2ddcd6f1794 /src/com/android
parentcc41032d68756851eb2d01457cabbc3153f7423f (diff)
downloadpackages_apps_settings-a0278c23f0dd159475366c6175409ab51878375e.zip
packages_apps_settings-a0278c23f0dd159475366c6175409ab51878375e.tar.gz
packages_apps_settings-a0278c23f0dd159475366c6175409ab51878375e.tar.bz2
QuickSettings : Fix layout
Make layout more inline with framework. Scale appropriately on larger devices. Adjust columns according to orientation/device type Change-Id: I20872a42344936b0643a7eff0007c50aaaa5fdd6
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/settings/cyanogenmod/DraggableGridView.java153
-rw-r--r--src/com/android/settings/cyanogenmod/QuickSettingsTiles.java44
2 files changed, 117 insertions, 80 deletions
diff --git a/src/com/android/settings/cyanogenmod/DraggableGridView.java b/src/com/android/settings/cyanogenmod/DraggableGridView.java
index a0ac1bc..ed782fe 100644
--- a/src/com/android/settings/cyanogenmod/DraggableGridView.java
+++ b/src/com/android/settings/cyanogenmod/DraggableGridView.java
@@ -27,7 +27,8 @@ import android.graphics.PorterDuff.Mode;
import android.os.Handler;
import android.os.SystemClock;
import android.util.AttributeSet;
-import android.util.DisplayMetrics;
+import android.view.View.MeasureSpec;
+import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
@@ -46,8 +47,7 @@ import com.android.settings.cyanogenmod.QuickSettingsTiles.OnRearrangeListener;
public class DraggableGridView extends ViewGroup implements
View.OnTouchListener, View.OnClickListener, View.OnLongClickListener {
- public static float childRatio = .95f;
- protected int colCount, childSize, padding, dpi, scroll = 0;
+ protected int colCount, childWidth, childHeight, cellGap, scroll = 0;
protected float lastDelta = 0;
protected Handler handler = new Handler();
protected int dragged = -1, lastX = -1, lastY = -1, lastTarget = -1;
@@ -58,13 +58,14 @@ public class DraggableGridView extends ViewGroup implements
protected OnClickListener secondaryOnClickListener;
private OnItemClickListener onItemClickListener;
+ public DraggableGridView(Context context) {
+ super(context);
+ init(context);
+ }
+
public DraggableGridView(Context context, AttributeSet attrs) {
super(context, attrs);
- setListeners();
- setChildrenDrawingOrderEnabled(true);
- DisplayMetrics metrics = new DisplayMetrics();
- ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
- dpi = metrics.densityDpi;
+ init(context);
}
protected void setListeners() {
@@ -73,6 +74,26 @@ public class DraggableGridView extends ViewGroup implements
setOnLongClickListener(this);
}
+ private void init(Context context) {
+ setListeners();
+ setChildrenDrawingOrderEnabled(true);
+ setClipChildren(false);
+ setClipToPadding(false);
+ colCount = 3;
+ }
+
+ public void setColumnCount(int count) {
+ colCount = count;
+ }
+
+ public void setCellHeight(int height) {
+ childHeight = height;
+ }
+
+ public void setCellGap(int gap) {
+ cellGap = gap;
+ }
+
@Override
public void setOnClickListener(OnClickListener l) {
secondaryOnClickListener = l;
@@ -81,9 +102,9 @@ public class DraggableGridView extends ViewGroup implements
protected Runnable updateTask = new Runnable() {
public void run() {
if (dragged != -1) {
- if (lastY < padding * 3 && scroll > 0)
+ if (lastY < cellGap * 3 && scroll > 0)
scroll -= 20;
- else if (lastY > getBottom() - getTop() - (padding * 3)
+ else if (lastY > getBottom() - getTop() - (cellGap * 3)
&& scroll < getMaxScroll())
scroll += 20;
} else if (lastDelta != 0 && !touching) {
@@ -120,22 +141,12 @@ public class DraggableGridView extends ViewGroup implements
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
- // compute width of view, in dp
- float w = (r - l) / (dpi / 160f);
-
- // determine number of columns, at least 2
- colCount = 3;
-
- // determine childSize and padding, in px
- childSize = (r - l) / colCount;
- childSize = Math.round(childSize * childRatio);
- padding = ((r - l) - (childSize * colCount)) / (colCount + 1);
-
- for (int i = 0; i < getChildCount(); i++) {
- if (i != dragged) {
+ int N = getChildCount();
+ for (int i = 0; i < N; i++) {
+ View v = (View) getChildAt(i);
+ if (v.getVisibility() != GONE) {
Point xy = getCoorFromIndex(i);
- getChildAt(i).layout(xy.x, xy.y, xy.x + childSize,
- xy.y + childSize);
+ v.layout(xy.x, xy.y, xy.x + v.getMeasuredWidth(), xy.y + v.getMeasuredHeight());
}
}
}
@@ -144,46 +155,22 @@ public class DraggableGridView extends ViewGroup implements
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Calculate the cell width dynamically
int width = MeasureSpec.getSize(widthMeasureSpec);
- int height = MeasureSpec.getSize(heightMeasureSpec);
- int availableWidth = (int) (width - getPaddingLeft()
- - getPaddingRight() - (3 - 1) * 0);
- float cellWidth = (float) Math.ceil(((float) availableWidth) / 3);
+ int availableWidth = (int) (width - getPaddingLeft() - getPaddingRight() -
+ (colCount - 1) * cellGap);
+ childWidth = (int) Math.ceil(((float) availableWidth) / colCount);
// Update each of the children's widths accordingly to the cell width
int N = getChildCount();
- int cellHeight = 0;
- int cursor = 0;
- for (int i = 0; i < N; ++i) {
- // Update the child's width
+ for (int i = 0; i < N; i++) {
View v = (View) getChildAt(i);
+ ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) v.getLayoutParams();
+ lp.width = childWidth;
+ lp.height = childHeight;
if (v.getVisibility() != View.GONE) {
- ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) v
- .getLayoutParams();
- int colSpan = 1;
- lp.width = (int) ((colSpan * cellWidth) + (colSpan - 1) * 0);
-
- // Measure the child
- int newWidthSpec = MeasureSpec.makeMeasureSpec(lp.width,
- MeasureSpec.EXACTLY);
- int newHeightSpec = MeasureSpec.makeMeasureSpec(lp.height,
- MeasureSpec.EXACTLY);
- v.measure(newWidthSpec, newHeightSpec);
-
- // Save the cell height
- if (cellHeight <= 0) {
- cellHeight = height;
- }
- cursor += colSpan;
+ measureChild(v,MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY),
+ MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.AT_MOST));
}
}
-
- // Set the measured dimensions. We always fill the tray width, but wrap
- // to the height of
- // all the tiles.
- int numRows = (int) Math.ceil((float) cursor / 3);
- int newHeight = (int) ((numRows * cellHeight) + ((numRows - 1) * 0))
- + getPaddingTop() + getPaddingBottom();
- // setMeasuredDimension(width, newHeight);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@@ -199,7 +186,7 @@ public class DraggableGridView extends ViewGroup implements
}
public int getIndexFromCoor(int x, int y) {
- int col = getColOrRowFromCoor(x), row = getColOrRowFromCoor(y + scroll);
+ int col = getColumnFromCoor(x), row = getRowFromCoor(y + scroll);
if (col == -1 || row == -1) // touch is between columns or rows
return -1;
int index = row * colCount + col;
@@ -208,22 +195,32 @@ public class DraggableGridView extends ViewGroup implements
return index;
}
- protected int getColOrRowFromCoor(int coor) {
- coor -= padding;
+ protected int getColumnFromCoor(int coor) {
+ coor -= cellGap;
+ for (int i = 0; coor > 0; i++) {
+ if (coor < childWidth)
+ return i;
+ coor -= (childWidth + cellGap);
+ }
+ return -1;
+ }
+
+ protected int getRowFromCoor(int coor) {
+ coor -= cellGap;
for (int i = 0; coor > 0; i++) {
- if (coor < childSize)
+ if (coor < childHeight)
return i;
- coor -= (childSize + padding);
+ coor -= (childHeight + cellGap);
}
return -1;
}
protected int getTargetFromCoor(int x, int y) {
- if (getColOrRowFromCoor(y + scroll) == -1) // touch is between rows
+ if (getRowFromCoor(y + scroll) == -1) // touch is between rows
return -1;
- int leftPos = getIndexFromCoor(x - (childSize / 4), y);
- int rightPos = getIndexFromCoor(x + (childSize / 4), y);
+ int leftPos = getIndexFromCoor(x - (childWidth / 4), y);
+ int rightPos = getIndexFromCoor(x + (childWidth / 4), y);
if (leftPos == -1 && rightPos == -1) // touch is in the middle of
// nowhere
return -1;
@@ -244,8 +241,8 @@ public class DraggableGridView extends ViewGroup implements
protected Point getCoorFromIndex(int index) {
int col = index % colCount;
int row = index / colCount;
- return new Point(padding / 2 + (childSize + padding / 2) * col, padding
- / 2 + (childSize + padding / 2) * row - scroll);
+ return new Point(cellGap / 2 + (childWidth + cellGap / 2) * col, cellGap
+ / 2 + (childHeight + cellGap / 2) * row - scroll);
}
public int getIndexOf(View child) {
@@ -306,9 +303,9 @@ public class DraggableGridView extends ViewGroup implements
if (dragged != -1) {
// change draw location of dragged visual
int x = (int) event.getX(), y = (int) event.getY();
- int l = x - (3 * childSize / 4), t = y - (3 * childSize / 4);
- getChildAt(dragged).layout(l, t, l + (childSize * 3 / 2),
- t + (childSize * 3 / 2));
+ int l = x - (3 * childWidth / 4), t = y - (3 * childHeight / 4);
+ getChildAt(dragged).layout(l, t, l + (childWidth * 3 / 2),
+ t + (childHeight * 3 / 2));
// check for new target hover
int target = getTargetFromCoor(x, y);
@@ -346,7 +343,7 @@ public class DraggableGridView extends ViewGroup implements
reorderChildren(true);
else {
Point xy = getCoorFromIndex(dragged);
- v.layout(xy.x, xy.y, xy.x + childSize, xy.y + childSize);
+ v.layout(xy.x, xy.y, xy.x + childWidth, xy.y + childHeight);
}
v.clearAnimation();
if (v instanceof ImageView)
@@ -374,13 +371,13 @@ public class DraggableGridView extends ViewGroup implements
// EVENT HELPERS
protected void animateDragged() {
View v = getChildAt(dragged);
- int x = getCoorFromIndex(dragged).x + childSize / 2, y = getCoorFromIndex(dragged).y
- + childSize / 2;
- int l = x - (3 * childSize / 4), t = y - (3 * childSize / 4);
- v.layout(l, t, l + (childSize * 3 / 2), t + (childSize * 3 / 2));
+ int x = getCoorFromIndex(dragged).x + childWidth / 2, y = getCoorFromIndex(dragged).y
+ + childWidth / 2;
+ int l = x - (3 * childWidth / 4), t = y - (3 * childHeight / 4);
+ v.layout(l, t, l + (childWidth * 3 / 2), t + (childHeight * 3 / 2));
AnimationSet animSet = new AnimationSet(true);
ScaleAnimation scale = new ScaleAnimation(.667f, 1, .667f, 1,
- childSize * 3 / 4, childSize * 3 / 4);
+ childWidth * 3 / 4, childHeight * 3 / 4);
scale.setDuration(animT);
AlphaAnimation alpha = new AlphaAnimation(1, .5f);
alpha.setDuration(animT);
@@ -495,7 +492,7 @@ public class DraggableGridView extends ViewGroup implements
protected int getMaxScroll() {
int rowCount = (int) Math.ceil((double) getChildCount() / colCount), max = rowCount
- * childSize + (rowCount + 1) * padding - getHeight();
+ * childHeight + (rowCount + 1) * cellGap - getHeight();
return max;
}
diff --git a/src/com/android/settings/cyanogenmod/QuickSettingsTiles.java b/src/com/android/settings/cyanogenmod/QuickSettingsTiles.java
index 8a91832..9342f64 100644
--- a/src/com/android/settings/cyanogenmod/QuickSettingsTiles.java
+++ b/src/com/android/settings/cyanogenmod/QuickSettingsTiles.java
@@ -22,8 +22,10 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.content.res.Resources;
+import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -32,6 +34,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
+import android.widget.FrameLayout;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
@@ -54,8 +57,10 @@ public class QuickSettingsTiles extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- mDragView = new DraggableGridView(getActivity(), null);
+ mDragView = new DraggableGridView(getActivity());
mContainer = container;
+ mContainer.setClipChildren(false);
+ mContainer.setClipToPadding(false);
mInflater = inflater;
PackageManager pm = getActivity().getPackageManager();
if (pm != null) {
@@ -65,10 +70,45 @@ public class QuickSettingsTiles extends Fragment {
mSystemUiResources = null;
}
}
+ int panelWidth = getItemFromSystemUi("notification_panel_width", "dimen");
+ if (panelWidth != 0) {
+ FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(panelWidth,
+ FrameLayout.LayoutParams.MATCH_PARENT, Gravity.CENTER_HORIZONTAL);
+ mDragView.setLayoutParams(params);
+ }
+ int cellHeight = getItemFromSystemUi("quick_settings_cell_height", "dimen");
+ if (cellHeight != 0) {
+ mDragView.setCellHeight(cellHeight);
+ }
+ int cellGap = getItemFromSystemUi("quick_settings_cell_gap", "dimen");
+ if (cellGap != 0) {
+ mDragView.setCellGap(cellGap);
+ }
+ int columnCount = getItemFromSystemUi("quick_settings_num_columns", "integer");
+ if (columnCount != 0) {
+ mDragView.setColumnCount(columnCount);
+ }
mTileAdapter = new TileAdapter(getActivity(), 0);
return mDragView;
}
+ private int getItemFromSystemUi(String name, String type) {
+ if (mSystemUiResources != null) {
+ int resId = (int) mSystemUiResources.getIdentifier(name, type, "com.android.systemui");
+ if (resId > 0) {
+ try {
+ if (type.equals("dimen")) {
+ return (int) mSystemUiResources.getDimension(resId);
+ } else {
+ return mSystemUiResources.getInteger(resId);
+ }
+ } catch (NotFoundException e) {
+ }
+ }
+ }
+ return 0;
+ }
+
void genTiles() {
mDragView.removeAllViews();
ArrayList<String> tiles = QuickSettingsUtil.getTileListFromString(QuickSettingsUtil.getCurrentTiles(getActivity()));
@@ -174,7 +214,7 @@ public class QuickSettingsTiles extends Fragment {
public void onResume() {
super.onResume();
if (Utils.isPhone(getActivity())) {
- mContainer.setPadding(20, 0, 0, 0);
+ mContainer.setPadding(20, 0, 20, 0);
}
}