blob: c5be6c417f694aae531abb2f37edbfdb539c74e6 [file] [log] [blame]
ztenghui0923be22014-07-01 13:49:47 -07001/*
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 */
14package com.android.test.dynamic;
15
16import android.app.Activity;
17import android.os.Bundle;
18import android.view.ViewGroup.LayoutParams;
19import android.widget.ImageView;
20import android.widget.TextView;
21import android.widget.GridLayout;
22import android.widget.ScrollView;
23
24@SuppressWarnings({"UnusedDeclaration"})
25public 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
ztenghui9d59a762014-07-17 15:06:03 -070039 protected int icon = R.drawable.bitmap_drawable01;
ztenghui9d59a762014-07-17 15:06:03 -070040 protected int vector_icon = R.drawable.vector_drawable16;
ztenghui35289f12015-01-13 16:21:11 -080041 protected int animated_vector_icon = R.drawable.ic_hourglass_animation;
ztenghui0923be22014-07-01 13:49:47 -070042
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);
ztenghui35289f12015-01-13 16:21:11 -080049 container.setColumnCount(4);
ztenghui0923be22014-07-01 13:49:47 -070050 container.setBackgroundColor(0xFF888888);
51
52 LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
ztenghui35289f12015-01-13 16:21:11 -080053 params.width = 300;
54 params.height = 200;
ztenghui0923be22014-07-01 13:49:47 -070055
ztenghui9d59a762014-07-17 15:06:03 -070056 for (int i = 0; i < scaleTypes.length; i++) {
ztenghui0923be22014-07-01 13:49:47 -070057 TextView t = new TextView(this);
58 t.setText(scaleTypes[i]);
59 container.addView(t);
60
ztenghui9d59a762014-07-17 15:06:03 -070061 ImageView.ScaleType scaleType = ImageView.ScaleType.values()[i];
62
ztenghui0923be22014-07-01 13:49:47 -070063 ImageView png_view = new ImageView(this);
64 png_view.setLayoutParams(params);
ztenghui9d59a762014-07-17 15:06:03 -070065 png_view.setScaleType(scaleType);
66 png_view.setImageResource(icon);
ztenghui0923be22014-07-01 13:49:47 -070067 container.addView(png_view);
68
69 ImageView view = new ImageView(this);
70 view.setLayoutParams(params);
ztenghui9d59a762014-07-17 15:06:03 -070071 view.setScaleType(scaleType);
72 view.setImageResource(vector_icon);
ztenghui0923be22014-07-01 13:49:47 -070073 container.addView(view);
ztenghui35289f12015-01-13 16:21:11 -080074
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
ztenghui0923be22014-07-01 13:49:47 -070081 }
82
83 setContentView(scrollView);
84 }
85}