1/*
2 * Copyright (C) 2016 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.layoutlib.test.myapplication;
18
19import android.content.Context;
20import android.content.res.Resources;
21import android.util.AttributeSet;
22import android.widget.LinearLayout;
23import android.widget.TextView;
24
25/**
26 * A widget to test obtaining arrays from resources.
27 */
28public class ArraysCheckWidget extends LinearLayout {
29    public ArraysCheckWidget(Context context, AttributeSet attrs) {
30        this(context, attrs, 0);
31    }
32
33    public ArraysCheckWidget(Context context, AttributeSet attrs, int defStyleAttr) {
34        this(context, attrs, defStyleAttr, 0);
35    }
36
37    public ArraysCheckWidget(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
38        super(context, attrs, defStyleAttr, defStyleRes);
39        Resources resources = context.getResources();
40        for (CharSequence chars : resources.getTextArray(R.array.array)) {
41            addTextView(context, chars);
42        }
43        for (int i : resources.getIntArray(R.array.int_array)) {
44            addTextView(context, String.valueOf(i));
45        }
46        for (String string : resources.getStringArray(R.array.string_array)) {
47            addTextView(context, string);
48        }
49    }
50
51    private void addTextView(Context context, CharSequence string) {
52        TextView textView = new TextView(context);
53        textView.setText(string);
54        textView.setTextSize(30);
55        addView(textView);
56    }
57}
58