Dan Sandler | 27a9fcc | 2016-06-22 00:05:11 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except 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 |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.egg.neko; |
| 16 | |
| 17 | import android.content.Context; |
| 18 | import android.content.res.TypedArray; |
| 19 | import android.graphics.drawable.Drawable; |
| 20 | import android.graphics.drawable.Icon; |
| 21 | |
| 22 | import com.android.egg.R; |
| 23 | |
| 24 | public class Food { |
| 25 | private final int mType; |
| 26 | |
| 27 | private static int[] sIcons; |
| 28 | private static String[] sNames; |
| 29 | |
| 30 | public Food(int type) { |
| 31 | mType = type; |
| 32 | } |
| 33 | |
| 34 | public Icon getIcon(Context context) { |
| 35 | if (sIcons == null) { |
| 36 | TypedArray icons = context.getResources().obtainTypedArray(R.array.food_icons); |
| 37 | sIcons = new int[icons.length()]; |
| 38 | for (int i = 0; i < sIcons.length; i++) { |
| 39 | sIcons[i] = icons.getResourceId(i, 0); |
| 40 | } |
| 41 | icons.recycle(); |
| 42 | } |
| 43 | return Icon.createWithResource(context, sIcons[mType]); |
| 44 | } |
| 45 | |
| 46 | public String getName(Context context) { |
| 47 | if (sNames == null) { |
| 48 | sNames = context.getResources().getStringArray(R.array.food_names); |
| 49 | } |
| 50 | return sNames[mType]; |
| 51 | } |
| 52 | |
| 53 | public long getInterval(Context context) { |
| 54 | return context.getResources().getIntArray(R.array.food_intervals)[mType]; |
| 55 | } |
| 56 | |
| 57 | public int getType() { |
| 58 | return mType; |
| 59 | } |
| 60 | } |