blob: 4d3a843cdf87cb2aec2e9f259f5648b76c7c71af [file] [log] [blame]
Philip Milneaa616f32011-05-27 18:38:01 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.test.layout;
18
19import android.app.Activity;
20import android.content.Context;
21import android.os.Bundle;
Philip Milneaa616f32011-05-27 18:38:01 -070022import android.util.Log;
Philip Milneaa616f32011-05-27 18:38:01 -070023import android.view.View;
24import android.view.ViewGroup;
25import android.widget.Button;
26
Philip Milnef4748702011-06-09 18:30:32 -070027import static android.view.Gravity.*;
28
Philip Milneaa616f32011-05-27 18:38:01 -070029public abstract class AbstractLayoutTest extends Activity {
30
Philip Milnef4748702011-06-09 18:30:32 -070031 public static final String[] HORIZONTAL_NAMES = { "LEFT", "CENTER", "RIGHT", "FILL" };
32 public static final int[] HORIZONTAL_ALIGNMENTS = { LEFT, CENTER, RIGHT, FILL };
33 public static final String[] VERTICAL_NAMES = { "TOP", "CENTER", "BASELINE", "BOTTOM", "FILL" };
34 public static final int[] VERTICAL_ALIGNMENTS = { TOP, CENTER, NO_GRAVITY, BOTTOM, FILL };
Philip Milneaa616f32011-05-27 18:38:01 -070035
36 public View create(Context context, String name, int size) {
37 Button result = new Button(context);
38 result.setText(name);
39 result.setOnClickListener(new View.OnClickListener() {
40 public void onClick(View v) {
41 animate(v);
42 }
43 });
44 return result;
45 }
46
47 public abstract ViewGroup create(Context context);
48 public abstract String tag();
49
50 public void animate(View v) {
51 long start = System.currentTimeMillis();
52 int N = 1000;
53 for (int i = 0; i < N; i++) {
54 ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
55 lp.topMargin = (lp.topMargin + 1) % 31;
56 lp.leftMargin = (lp.leftMargin + 1) % 31;
57
58 v.requestLayout();
59 v.invalidate();
60 ViewGroup p = (ViewGroup) v.getParent();
61 p.layout(0, 0, 1000 + (i % 2), 500 + (i % 2));
62 }
63 Log.d(tag(), "Time: " + (float) (System.currentTimeMillis() - start) / N * 1000 + "mics");
64 }
65
66 protected void onCreate(Bundle savedInstanceState) {
67 super.onCreate(savedInstanceState);
68 setContentView(create(getBaseContext()));
69 }
70
71}