Back to project page Do-not-get-annoyed.
The source code is released under:
Apache License
If you think the Android project Do-not-get-annoyed listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package mn100013d.pmu.models; /* w ww . j ava2s . c om*/ import java.io.Serializable; import android.content.Context; import android.view.View; import android.view.animation.Animation; import android.view.animation.ScaleAnimation; import android.widget.ImageView; /** * @author Milutinovic * */ public abstract class Field implements Serializable{ public static final int INITIAL_STATE = 1; public static final int HIGHLIGHTED = 2; public static final int OCCUPIED = 3; public static final int ATTACKED = 4; private View view; private Context context; private Board board; private int state = INITIAL_STATE; protected Pawn onFieldPawn; protected Field(Board board, View view, Context context) { this.board = board; this.view = view; this.context = context; } public int getState() { return state; } /** * int color only if state is OCCUPIED, else return 0 or -1 * */ protected void setState(int state, int color) { this.state = state; switch (state) { case INITIAL_STATE: ((ImageView) view).setImageResource(getInitialStateImageId(color)); view.setAnimation(null); break; case HIGHLIGHTED: ((ImageView) view) .setImageResource(getHighlightedStateImageId(color)); ScaleAnimation animation = new ScaleAnimation((float) 1, (float) (1.1), (float) 1, (float) 1.1, Animation.RELATIVE_TO_SELF, (float) 0.5, Animation.RELATIVE_TO_SELF, (float) 0.5); animation.setDuration(200); animation.setInterpolator(context, android.R.anim.accelerate_decelerate_interpolator); animation.setRepeatMode(Animation.REVERSE); animation.setRepeatCount(Animation.INFINITE); view.setAnimation(animation); break; case OCCUPIED: ((ImageView) view).setImageResource(getOccupiedStateImageId(color)); view.setAnimation(null); break; case ATTACKED: ((ImageView) view).setImageResource(getAttackedStateImageId(color)); ScaleAnimation animation1 = new ScaleAnimation((float) 1, (float) (1.1), (float) 1, (float) 1.1, Animation.RELATIVE_TO_SELF, (float) 0.5, Animation.RELATIVE_TO_SELF, (float) 0.5); animation1.setDuration(200); animation1.setInterpolator(context, android.R.anim.accelerate_decelerate_interpolator); animation1.setRepeatMode(Animation.REVERSE); animation1.setRepeatCount(Animation.INFINITE); view.setAnimation(animation1); break; } } public void setPawn(Pawn pawn) { this.onFieldPawn = pawn; if (pawn == null) setState(Field.INITIAL_STATE, -1); else setState(Field.OCCUPIED, pawn.getColor()); } public Pawn getPawn() { return onFieldPawn; } public void empty() { setPawn(null); setState(Field.INITIAL_STATE, -1); } public void registerOnClickListener(final Pawn pawn) { final Field field = this; view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { board.fieldClicked(field, pawn); } }); } public void removeOnClickListener() { view.setOnClickListener(null); } public void refresh() { removeOnClickListener(); if (onFieldPawn == null) { setState(Field.INITIAL_STATE, -1); } else { setState(Field.OCCUPIED, onFieldPawn.getColor()); } } protected abstract int getInitialStateImageId(int color); protected abstract int getHighlightedStateImageId(int color); protected abstract int getOccupiedStateImageId(int color); protected abstract int getAttackedStateImageId(int color); public void performClick() { view.performClick(); } }