1c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez/* 2c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * Copyright (C) 2016 The Android Open Source Project 3c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * 4c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * Licensed under the Apache License, Version 2.0 (the "License"); 5c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * you may not use this file except in compliance with the License. 6c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * You may obtain a copy of the License at 7c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * 8c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * http://www.apache.org/licenses/LICENSE-2.0 9c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * 10c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * Unless required by applicable law or agreed to in writing, software 11c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * distributed under the License is distributed on an "AS IS" BASIS, 12c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * See the License for the specific language governing permissions and 14c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez * limitations under the License. 15c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez */ 16c318f0b40872a91215801f851e38189f42c4b7eaDiego Perez 17642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Guptapackage com.android.layoutlib.test.myapplication; 18642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta 19642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Guptaimport android.content.Context; 20642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Guptaimport android.content.res.Resources; 21642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Guptaimport android.util.AttributeSet; 22642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Guptaimport android.widget.LinearLayout; 23642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Guptaimport android.widget.TextView; 24642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta 25642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta/** 26642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta * A widget to test obtaining arrays from resources. 27642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta */ 28642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Guptapublic class ArraysCheckWidget extends LinearLayout { 29642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta public ArraysCheckWidget(Context context, AttributeSet attrs) { 30642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta this(context, attrs, 0); 31642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta } 32642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta 33642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta public ArraysCheckWidget(Context context, AttributeSet attrs, int defStyleAttr) { 34642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta this(context, attrs, defStyleAttr, 0); 35642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta } 36642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta 37642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta public ArraysCheckWidget(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 38642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta super(context, attrs, defStyleAttr, defStyleRes); 39642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta Resources resources = context.getResources(); 40642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta for (CharSequence chars : resources.getTextArray(R.array.array)) { 41642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta addTextView(context, chars); 42642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta } 43642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta for (int i : resources.getIntArray(R.array.int_array)) { 44642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta addTextView(context, String.valueOf(i)); 45642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta } 46642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta for (String string : resources.getStringArray(R.array.string_array)) { 47642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta addTextView(context, string); 48642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta } 49642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta } 50642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta 51642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta private void addTextView(Context context, CharSequence string) { 52642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta TextView textView = new TextView(context); 53642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta textView.setText(string); 54642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta textView.setTextSize(30); 55642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta addView(textView); 56642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta } 57642cff50f8f7a67eed09eac1e56d7133b26a192cDeepanshu Gupta} 58