1c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez/*
2c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez * Copyright (C) 2016 The Android Open Source Project
3c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez *
4c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez * Licensed under the Apache License, Version 2.0 (the "License");
5c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez * you may not use this file except in compliance with the License.
6c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez * You may obtain a copy of the License at
7c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez *
8c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez *      http://www.apache.org/licenses/LICENSE-2.0
9c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez *
10c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez * Unless required by applicable law or agreed to in writing, software
11c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez * distributed under the License is distributed on an "AS IS" BASIS,
12c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez * See the License for the specific language governing permissions and
14c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez * limitations under the License.
15c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez */
16c702b276058dc81072b9db892d7ac9dd35da1935Diego Perez
1797ec2750d907c8bf9293358f210d991729319098Deepanshu Guptapackage com.android.layoutlib.test.myapplication;
1897ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta
1997ec2750d907c8bf9293358f210d991729319098Deepanshu Guptaimport android.content.Context;
2097ec2750d907c8bf9293358f210d991729319098Deepanshu Guptaimport android.content.res.Resources;
2197ec2750d907c8bf9293358f210d991729319098Deepanshu Guptaimport android.util.AttributeSet;
2297ec2750d907c8bf9293358f210d991729319098Deepanshu Guptaimport android.widget.LinearLayout;
2397ec2750d907c8bf9293358f210d991729319098Deepanshu Guptaimport android.widget.TextView;
2497ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta
2597ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta/**
2697ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta * A widget to test obtaining arrays from resources.
2797ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta */
2897ec2750d907c8bf9293358f210d991729319098Deepanshu Guptapublic class ArraysCheckWidget extends LinearLayout {
2997ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta    public ArraysCheckWidget(Context context, AttributeSet attrs) {
3097ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        this(context, attrs, 0);
3197ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta    }
3297ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta
3397ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta    public ArraysCheckWidget(Context context, AttributeSet attrs, int defStyleAttr) {
3497ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        this(context, attrs, defStyleAttr, 0);
3597ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta    }
3697ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta
3797ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta    public ArraysCheckWidget(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
3897ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        super(context, attrs, defStyleAttr, defStyleRes);
3997ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        Resources resources = context.getResources();
4097ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        for (CharSequence chars : resources.getTextArray(R.array.array)) {
4197ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta            addTextView(context, chars);
4297ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        }
4397ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        for (int i : resources.getIntArray(R.array.int_array)) {
4497ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta            addTextView(context, String.valueOf(i));
4597ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        }
4697ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        for (String string : resources.getStringArray(R.array.string_array)) {
4797ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta            addTextView(context, string);
4897ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        }
4997ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta    }
5097ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta
5197ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta    private void addTextView(Context context, CharSequence string) {
5297ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        TextView textView = new TextView(context);
5397ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        textView.setText(string);
5497ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        textView.setTextSize(30);
5597ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta        addView(textView);
5697ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta    }
5797ec2750d907c8bf9293358f210d991729319098Deepanshu Gupta}
58