summaryrefslogtreecommitdiffstats
path: root/tests/GridLayoutTest
diff options
context:
space:
mode:
authorPhilip Milne <pmilne@google.com>2011-05-27 18:38:01 -0700
committerPhilip Milne <pmilne@google.com>2011-06-03 13:22:52 -0700
commitaa616f31fe7c0c8e3657bb9a5889ec5e56ee5232 (patch)
tree7ed5a6e67f38bf2bd7264417a41508d5ca23dca9 /tests/GridLayoutTest
parentb2450ce105086d1ac82d273a5292d9581c6ddec4 (diff)
downloadframeworks_base-aa616f31fe7c0c8e3657bb9a5889ec5e56ee5232.zip
frameworks_base-aa616f31fe7c0c8e3657bb9a5889ec5e56ee5232.tar.gz
frameworks_base-aa616f31fe7c0c8e3657bb9a5889ec5e56ee5232.tar.bz2
Response to code review for GridLayout:
. Fixed spelling. . Added comments on internal methods. . Adopted the suggested internal name changes to improve clarity. . Added UNDEFINED constant to public API to avoid making reference to Integer.MAX_VALUE in docs. . Added final everywhere, then removed it. . Make the Interval class package private so that it can be put somewhere more general later. . Tidy code, removing maximize flag throughout. . Remove last of allocations taking place during layout. . Implement measureChild() etc. . Added LinearLayout alignment compatibility mode, and made it the default. Change-Id: I6a4ffa022d97d68138d1903d3830a20278815435 https://android-git.corp.google.com/g/#change,109891
Diffstat (limited to 'tests/GridLayoutTest')
-rw-r--r--tests/GridLayoutTest/AndroidManifest.xml21
-rw-r--r--tests/GridLayoutTest/src/com/android/test/layout/AbstractLayoutTest.java71
-rw-r--r--tests/GridLayoutTest/src/com/android/test/layout/Activity2.java1
-rwxr-xr-xtests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java116
-rw-r--r--tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java52
-rw-r--r--tests/GridLayoutTest/src/com/android/test/layout/LinearLayoutTest.java50
6 files changed, 311 insertions, 0 deletions
diff --git a/tests/GridLayoutTest/AndroidManifest.xml b/tests/GridLayoutTest/AndroidManifest.xml
index 53ca4ce..1b72357 100644
--- a/tests/GridLayoutTest/AndroidManifest.xml
+++ b/tests/GridLayoutTest/AndroidManifest.xml
@@ -76,6 +76,27 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
+
+ <activity android:name="AlignmentTest" android:label="AlignmentTest">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+
+ <activity android:name="LinearLayoutTest" android:label="LinearLayoutTest">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+
+ <activity android:name="GridLayoutTest" android:label="GridLayoutTest">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
</application>
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/AbstractLayoutTest.java b/tests/GridLayoutTest/src/com/android/test/layout/AbstractLayoutTest.java
new file mode 100644
index 0000000..937eacb
--- /dev/null
+++ b/tests/GridLayoutTest/src/com/android/test/layout/AbstractLayoutTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.layout;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Debug;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+
+public abstract class AbstractLayoutTest extends Activity {
+
+ public static final String[] HORIZONTAL_NAMES = new String[] { "LEFT", "center", "east", "fill" };
+ public static final int[] HORIZONTAL_ALIGNMENTS = new int[] { Gravity.LEFT, Gravity.CENTER, Gravity.RIGHT, Gravity.FILL };
+ public static final String[] VERTICAL_NAMES = new String[] { "north", "center", "baseline", "south", "fill" };
+ public static final int[] VERTICAL_ALIGNMENTS = new int[] { Gravity.TOP, Gravity.CENTER, Gravity.NO_GRAVITY, Gravity.BOTTOM, Gravity.FILL };
+
+ public View create(Context context, String name, int size) {
+ Button result = new Button(context);
+ result.setText(name);
+ result.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ animate(v);
+ }
+ });
+ return result;
+ }
+
+ public abstract ViewGroup create(Context context);
+ public abstract String tag();
+
+ public void animate(View v) {
+ long start = System.currentTimeMillis();
+ int N = 1000;
+ for (int i = 0; i < N; i++) {
+ ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
+ lp.topMargin = (lp.topMargin + 1) % 31;
+ lp.leftMargin = (lp.leftMargin + 1) % 31;
+
+ v.requestLayout();
+ v.invalidate();
+ ViewGroup p = (ViewGroup) v.getParent();
+ p.layout(0, 0, 1000 + (i % 2), 500 + (i % 2));
+ }
+ Log.d(tag(), "Time: " + (float) (System.currentTimeMillis() - start) / N * 1000 + "mics");
+ }
+
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(create(getBaseContext()));
+ }
+
+} \ No newline at end of file
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java b/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
index 6359903..5e29cf1 100644
--- a/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
+++ b/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
@@ -32,6 +32,7 @@ public class Activity2 extends Activity {
public static View create(Context context) {
GridLayout vg = new GridLayout(context);
vg.setUseDefaultMargins(true);
+ vg.setMarginsIncludedInAlignment(false);
Group row1 = new Group(1, CENTER);
Group row2 = new Group(2, CENTER);
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java b/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java
new file mode 100755
index 0000000..c6f390e
--- /dev/null
+++ b/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.layout;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewParent;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.GridLayout;
+import android.widget.TextView;
+
+import static android.widget.GridLayout.*;
+
+public class AlignmentTest extends Activity {
+
+ public static final String[] HORIZONTAL_NAMES = new String[]{"LEFT", "center", "east", "fill"};
+ public static final Alignment[] HORIZONTAL_ALIGNMENTS = new Alignment[]{LEFT, CENTER, RIGHT, FILL};
+ public static final String[] VERTICAL_NAMES = new String[]{"north", "center", "baseline", "south", "fill"};
+ public static final Alignment[] VERTICAL_ALIGNMENTS = new Alignment[]{TOP, CENTER, BASELINE, BOTTOM, FILL};
+ private static Context CONTEXT;
+
+ public static interface ViewFactory {
+ View create(String name, int size);
+ }
+
+ public static final ViewFactory BUTTON_FACTORY = new ViewFactory() {
+ public View create(String name, int size) {
+ Button result = new Button(CONTEXT);
+ result.setText(name);
+ result.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ animate(v);
+ }
+ });
+ return result;
+ }
+ };
+
+ public static final ViewFactory LABEL_FACTORY = new ViewFactory() {
+ public View create(String name, int size) {
+ TextView result = new TextView(CONTEXT);
+ result.setText(name);
+ result.setTextSize(40);
+ return result;
+ }
+ };
+
+ public static final ViewFactory TEXT_FIELD_FACTORY = new ViewFactory() {
+ public View create(String name, int size) {
+ EditText result = new EditText(CONTEXT);
+ result.setText(name);
+ return result;
+ }
+ };
+
+ public static final ViewFactory[] FACTORIES = new ViewFactory[]{BUTTON_FACTORY, LABEL_FACTORY, TEXT_FIELD_FACTORY};
+
+ public static ViewGroup create(Context context1) {
+ CONTEXT = context1;
+ GridLayout container = new GridLayout(context1);
+ container.setUseDefaultMargins(true);
+
+ for (int i = 0; i < VERTICAL_ALIGNMENTS.length; i++) {
+ Alignment va = VERTICAL_ALIGNMENTS[i];
+ for (int j = 0; j < HORIZONTAL_ALIGNMENTS.length; j++) {
+ Alignment ha = HORIZONTAL_ALIGNMENTS[j];
+ Group rowGroup = new Group(i, va);
+ Group colGroup = new Group(j, ha);
+ LayoutParams layoutParams = new LayoutParams(rowGroup, colGroup);
+ container.addView(FACTORIES[(i + j) % FACTORIES.length].create(VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20), layoutParams);
+ }
+ }
+
+ return container;
+ }
+
+ public static void animate(View v) {
+
+ long start = System.currentTimeMillis();
+ int N = 1000;
+ for (int i = 0; i < N; i++) {
+ ViewGroup.LayoutParams lp = v.getLayoutParams();
+ lp.width += 1; // width;
+ lp.height += 1; // height;
+ v.requestLayout();
+ GridLayout p = (GridLayout) v.getParent();
+ p.layout(0, 0, 1000 + (i % 2), 500 + (i % 2));
+ }
+ System.out.println("Time: " + (float) (System.currentTimeMillis() - start) / N * 1000 + "mics");
+ }
+
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(create(getBaseContext()));
+ }
+
+} \ No newline at end of file
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java b/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java
new file mode 100644
index 0000000..b4451e8
--- /dev/null
+++ b/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.layout;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.GridLayout;
+
+import static android.widget.GridLayout.*;
+
+public class GridLayoutTest extends AbstractLayoutTest {
+ public ViewGroup create(Context context) {
+ GridLayout container = new GridLayout(context);
+ container.setOrientation(VERTICAL);
+// container.setUseDefaultMargins(true);
+
+ for (int i = 0; i < VERTICAL_ALIGNMENTS.length; i++) {
+ int va = VERTICAL_ALIGNMENTS[i];
+ for (int j = 0; j < HORIZONTAL_ALIGNMENTS.length; j++) {
+ int ha = HORIZONTAL_ALIGNMENTS[j];
+ GridLayout.Group rowGroup = new GridLayout.Group(UNDEFINED, null);
+ GridLayout.Group colGroup = new GridLayout.Group(UNDEFINED, null);
+ GridLayout.LayoutParams lp = new GridLayout.LayoutParams(rowGroup, colGroup);
+ lp.setGravity(va | ha);
+// View v = create(VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20);
+ View v = create(context, VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20);
+ container.addView(v, lp);
+ }
+ }
+
+ return container;
+ }
+
+ public String tag() {
+ return GridLayoutTest.class.getName();
+ }
+}
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/LinearLayoutTest.java b/tests/GridLayoutTest/src/com/android/test/layout/LinearLayoutTest.java
new file mode 100644
index 0000000..fbd1239
--- /dev/null
+++ b/tests/GridLayoutTest/src/com/android/test/layout/LinearLayoutTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.layout;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+
+import static android.widget.LinearLayout.*;
+
+public class LinearLayoutTest extends AbstractLayoutTest {
+ public ViewGroup create(Context context) {
+ LinearLayout container = new LinearLayout(context);
+ container.setOrientation(LinearLayout.VERTICAL);
+// container.setUseDefaultMargins(true);
+
+ for (int i = 0; i < VERTICAL_ALIGNMENTS.length; i++) {
+ int va = VERTICAL_ALIGNMENTS[i];
+ for (int j = 0; j < HORIZONTAL_ALIGNMENTS.length; j++) {
+ int ha = HORIZONTAL_ALIGNMENTS[j];
+ LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ lp.gravity = va | ha;
+// View v = create(VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20);
+ View v = create(context, VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20);
+ container.addView(v, lp);
+ }
+ }
+
+ return container;
+ }
+
+ public String tag() {
+ return LinearLayoutTest.class.getName();
+ }
+}