Licenced under the Creative Commons Attribution 4.0 licence. For full text see
http://creativecommons.org/licenses/by/4.0/
If you think the Android project 101AndroidApps listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.hulzenga.ioi.android.app_005;
/*www.java2s.com*/import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.hulzenga.ioi.android.R;
import java.util.Random;
publicenum Element {
EARTH(R.drawable.app_005_earth_element, R.drawable.app_005_earth),
AIR(R.drawable.app_005_air_element, R.drawable.app_005_air),
FIRE(R.drawable.app_005_fire_element, R.drawable.app_005_fire),
WATER(R.drawable.app_005_water_element, R.drawable.app_005_water);
privatestaticboolean mBitmapsLoaded = false;
privatestatic Random mRandom = new Random();
privatestatic Bitmap mEmptyIcon;
privateint mIconId;
privateint mShadowId;
private Bitmap mIcon;
private Bitmap mShadow;
private Element(int iconId, int shadowId) {
mIconId = iconId;
mShadowId = shadowId;
}
publicstatic Element getRandomElement() {
switch (mRandom.nextInt(4)) {
case 0:
return Element.EARTH;
case 1:
return Element.AIR;
case 2:
return Element.FIRE;
case 3:
return Element.WATER;
default:
thrownew AssertionError("mRandom.nextInt(4) returned something other than 0,1,2 or 3. " +
"Check device for radiation damage");
}
}
publicstaticvoid loadBitmaps(Context context) {
for (Element element: Element.values()) {
element.mIcon = BitmapFactory.decodeResource(context.getResources(), element.mIconId);
element.mShadow = BitmapFactory.decodeResource(context.getResources(), element.mShadowId);
}
mEmptyIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.app_005_empty_element);
}
publicstatic Bitmap getmEmptyIcon() {
return mEmptyIcon;
}
public Bitmap getIcon() {
if (mIcon != null) {
return mIcon;
} else {
thrownew IllegalStateException("Element.loadBitmaps(context) needs to be called before getIcon()!");
}
}
public Bitmap getShadow() {
if (mShadow != null) {
return mShadow;
} else {
thrownew IllegalStateException("Element.loadBitmaps(context) needs to be called before getIcon()!");
}
}
}