ztenghui | 0923be2 | 2014-07-01 13:49:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | * in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | * or implied. See the License for the specific language governing permissions and limitations under |
| 12 | * the License. |
| 13 | */ |
| 14 | package com.android.test.dynamic; |
| 15 | |
| 16 | import android.app.Activity; |
| 17 | import android.os.Bundle; |
| 18 | import android.view.ViewGroup.LayoutParams; |
| 19 | import android.widget.ImageView; |
| 20 | import android.widget.TextView; |
| 21 | import android.widget.GridLayout; |
| 22 | import android.widget.ScrollView; |
| 23 | |
| 24 | @SuppressWarnings({"UnusedDeclaration"}) |
| 25 | public class ScaleDrawableTests extends Activity { |
| 26 | private static final String LOGCAT = "VectorDrawable1"; |
| 27 | |
| 28 | private String[] scaleTypes = { |
| 29 | "MATRIX (0)", |
| 30 | "FIT_XY (1)", |
| 31 | "FIT_START (2)", |
| 32 | "FIT_CENTER (3)", |
| 33 | "FIT_END (4)", |
| 34 | "CENTER (5)", |
| 35 | "CENTER_CROP (6)", |
| 36 | "CENTER_INSIDE (7)" |
| 37 | }; |
| 38 | |
ztenghui | 9d59a76 | 2014-07-17 15:06:03 -0700 | [diff] [blame] | 39 | protected int icon = R.drawable.bitmap_drawable01; |
ztenghui | 9d59a76 | 2014-07-17 15:06:03 -0700 | [diff] [blame] | 40 | protected int vector_icon = R.drawable.vector_drawable16; |
ztenghui | 35289f1 | 2015-01-13 16:21:11 -0800 | [diff] [blame] | 41 | protected int animated_vector_icon = R.drawable.ic_hourglass_animation; |
ztenghui | 0923be2 | 2014-07-01 13:49:47 -0700 | [diff] [blame] | 42 | |
| 43 | @Override |
| 44 | protected void onCreate(Bundle savedInstanceState) { |
| 45 | super.onCreate(savedInstanceState); |
| 46 | ScrollView scrollView = new ScrollView(this); |
| 47 | GridLayout container = new GridLayout(this); |
| 48 | scrollView.addView(container); |
ztenghui | 35289f1 | 2015-01-13 16:21:11 -0800 | [diff] [blame] | 49 | container.setColumnCount(4); |
ztenghui | 0923be2 | 2014-07-01 13:49:47 -0700 | [diff] [blame] | 50 | container.setBackgroundColor(0xFF888888); |
| 51 | |
| 52 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); |
ztenghui | 35289f1 | 2015-01-13 16:21:11 -0800 | [diff] [blame] | 53 | params.width = 300; |
| 54 | params.height = 200; |
ztenghui | 0923be2 | 2014-07-01 13:49:47 -0700 | [diff] [blame] | 55 | |
ztenghui | 9d59a76 | 2014-07-17 15:06:03 -0700 | [diff] [blame] | 56 | for (int i = 0; i < scaleTypes.length; i++) { |
ztenghui | 0923be2 | 2014-07-01 13:49:47 -0700 | [diff] [blame] | 57 | TextView t = new TextView(this); |
| 58 | t.setText(scaleTypes[i]); |
| 59 | container.addView(t); |
| 60 | |
ztenghui | 9d59a76 | 2014-07-17 15:06:03 -0700 | [diff] [blame] | 61 | ImageView.ScaleType scaleType = ImageView.ScaleType.values()[i]; |
| 62 | |
ztenghui | 0923be2 | 2014-07-01 13:49:47 -0700 | [diff] [blame] | 63 | ImageView png_view = new ImageView(this); |
| 64 | png_view.setLayoutParams(params); |
ztenghui | 9d59a76 | 2014-07-17 15:06:03 -0700 | [diff] [blame] | 65 | png_view.setScaleType(scaleType); |
| 66 | png_view.setImageResource(icon); |
ztenghui | 0923be2 | 2014-07-01 13:49:47 -0700 | [diff] [blame] | 67 | container.addView(png_view); |
| 68 | |
| 69 | ImageView view = new ImageView(this); |
| 70 | view.setLayoutParams(params); |
ztenghui | 9d59a76 | 2014-07-17 15:06:03 -0700 | [diff] [blame] | 71 | view.setScaleType(scaleType); |
| 72 | view.setImageResource(vector_icon); |
ztenghui | 0923be2 | 2014-07-01 13:49:47 -0700 | [diff] [blame] | 73 | container.addView(view); |
ztenghui | 35289f1 | 2015-01-13 16:21:11 -0800 | [diff] [blame] | 74 | |
| 75 | ImageView avd_view = new ImageView(this); |
| 76 | avd_view.setLayoutParams(params); |
| 77 | avd_view.setScaleType(scaleType); |
| 78 | avd_view.setImageResource(animated_vector_icon); |
| 79 | container.addView(avd_view); |
| 80 | |
ztenghui | 0923be2 | 2014-07-01 13:49:47 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | setContentView(scrollView); |
| 84 | } |
| 85 | } |