diff options
author | Philip Milne <pmilne@google.com> | 2011-05-27 18:38:01 -0700 |
---|---|---|
committer | Philip Milne <pmilne@google.com> | 2011-06-03 13:22:52 -0700 |
commit | aa616f31fe7c0c8e3657bb9a5889ec5e56ee5232 (patch) | |
tree | 7ed5a6e67f38bf2bd7264417a41508d5ca23dca9 /tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java | |
parent | b2450ce105086d1ac82d273a5292d9581c6ddec4 (diff) | |
download | frameworks_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/src/com/android/test/layout/AlignmentTest.java')
-rwxr-xr-x | tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java | 116 |
1 files changed, 116 insertions, 0 deletions
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 |