• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 
17 package com.android.egg.neko;
18 
19 import android.content.Context;
20 import android.content.res.TypedArray;
21 import android.graphics.drawable.Icon;
22 
23 import com.android.egg.R;
24 
25 public class Food {
26     private final int mType;
27 
28     private static int[] sIcons;
29     private static String[] sNames;
30 
Food(int type)31     public Food(int type) {
32         mType = type;
33     }
34 
getIcon(Context context)35     public Icon getIcon(Context context) {
36         if (sIcons == null) {
37             TypedArray icons = context.getResources().obtainTypedArray(R.array.food_icons);
38             sIcons = new int[icons.length()];
39             for (int i = 0; i < sIcons.length; i++) {
40                 sIcons[i] = icons.getResourceId(i, 0);
41             }
42             icons.recycle();
43         }
44         return Icon.createWithResource(context, sIcons[mType]);
45     }
46 
getName(Context context)47     public String getName(Context context) {
48         if (sNames == null) {
49             sNames = context.getResources().getStringArray(R.array.food_names);
50         }
51         return sNames[mType];
52     }
53 
getInterval(Context context)54     public long getInterval(Context context) {
55         return context.getResources().getIntArray(R.array.food_intervals)[mType];
56     }
57 
getType()58     public int getType() {
59         return mType;
60     }
61 }
62