Philip Milne | aa616f3 | 2011-05-27 18:38:01 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.test.layout; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.content.Context; |
| 21 | import android.os.Bundle; |
Philip Milne | aa616f3 | 2011-05-27 18:38:01 -0700 | [diff] [blame] | 22 | import android.util.Log; |
Philip Milne | aa616f3 | 2011-05-27 18:38:01 -0700 | [diff] [blame] | 23 | import android.view.View; |
| 24 | import android.view.ViewGroup; |
| 25 | import android.widget.Button; |
| 26 | |
Philip Milne | f474870 | 2011-06-09 18:30:32 -0700 | [diff] [blame] | 27 | import static android.view.Gravity.*; |
| 28 | |
Philip Milne | aa616f3 | 2011-05-27 18:38:01 -0700 | [diff] [blame] | 29 | public abstract class AbstractLayoutTest extends Activity { |
| 30 | |
Philip Milne | f474870 | 2011-06-09 18:30:32 -0700 | [diff] [blame] | 31 | 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 Milne | aa616f3 | 2011-05-27 18:38:01 -0700 | [diff] [blame] | 35 | |
| 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 | } |