If you think the Android project GhostStories 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 games.ghoststories.views.common;
/*fromwww.java2s.com*/import games.ghoststories.R;
import games.ghoststories.data.DragData;
import games.ghoststories.data.TokenSupplyData;
import games.ghoststories.enums.EColor;
import games.ghoststories.enums.EDragItem;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import com.interfaces.IDraggable;
/**
* View representing a stack of tao tokens.
*/publicclass TaoTokenView extends AbstractNumberedTokenView implements IDraggable<DragData>{
/**
* Class used to hold the drag data for this view
*/publicclass TokenDragData {
/** The color of the token **/public EColor mColor;
/** The player data for this token **/public TokenSupplyData mData;
}
/**
* Constructor
* @param pContext The context the view is running in
*/public TaoTokenView(Context pContext) {
super(pContext);
}
/**
* Constructor
* @param pContext The context the view is running in
* @param pAttrs The attributes of this view
*/public TaoTokenView(Context pContext, AttributeSet pAttrs) {
this(pContext, pAttrs, 0);
}
/**
* Constructor
* @param pContext The context the view is running in
* @param pAttrs The attributes of this view
* @param pDefStyle The default style applied to this view
*/public TaoTokenView(Context pContext, AttributeSet pAttrs, int pDefStyle) {
super(pContext, pAttrs, pDefStyle);
//Read in the attributes and set the values if specified
TypedArray a = pContext.obtainStyledAttributes(pAttrs,
R.styleable.TaoTokenView);
for (int i = 0; i < a.getIndexCount(); ++i)
{
int attr = a.getIndex(i);
switch (attr)
{
case R.styleable.TaoTokenView_token_color:
int color = a.getInteger(attr, 0);
mTokenColor = EColor.values()[color];
break;
}
}
a.recycle();
}
/**
* @return The color of this token
*/public EColor getColor() {
return mTokenColor;
}
/*
* (non-Javadoc)
* @see com.interfaces.IDraggable#getDragData()
*/public DragData getDragData() {
TokenDragData data = new TokenDragData();
data.mColor = mTokenColor;
data.mData = mData;
returnnew DragData(EDragItem.COMBAT_TAO, data, this);
}
/*
* (non-Javadoc)
* @see games.ghoststories.data.interfaces.ITokenListener#tokenDataUpdated()
*/publicvoid tokenDataUpdated() {
int numTokens = mData.getNumTaoTokens(mTokenColor);
if(numTokens != getNumber()) {
setNumber(numTokens);
}
}
/*
* (non-Javadoc)
* @see games.ghoststories.views.common.AbstractNumberedTokenView#setData(games.ghoststories.data.TokenSupplyData)
*/
@Override
publicvoid setData(TokenSupplyData pData) {
super.setData(pData);
setNumber(mData.getNumTaoTokens(mTokenColor));
}
/** The color of the token this view represents **/private EColor mTokenColor = EColor.BLACK;
}