us.the.mac.board
Class Board.Piece

java.lang.Object
  extended by android.view.View
      extended by android.widget.ImageView
          extended by us.the.mac.board.Board.Piece
All Implemented Interfaces:
Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback
Enclosing class:
Board

public abstract static class Board.Piece
extends ImageView

This class contains all the general functions of a piece.

It is used as a parent class of other types of pieces (Knight, Pawn, etc.),
and contains all the board data.


Nested Class Summary
 
Nested classes/interfaces inherited from class android.widget.ImageView
ImageView.ScaleType
 
Nested classes/interfaces inherited from class android.view.View
View.BaseSavedState, View.MeasureSpec, View.OnClickListener, View.OnCreateContextMenuListener, View.OnFocusChangeListener, View.OnKeyListener, View.OnLongClickListener, View.OnTouchListener
 
Field Summary
protected  ArrayList<Board.PGNEvent> alternateLineHistory
           
protected  Board.Color color
           
protected  int cur_pos
           
protected  byte[] FILE_A
           
protected  byte[] FILE_B
           
protected  byte[] FILE_G
           
protected  byte[] FILE_H
           
static int INVALID_MOVE
          The constant that disallows a piece to move.

It can be used in conjunction with the move_# variables
protected  ArrayList<Board.PGNEvent> mainLineHistory
           
 int move_1
           
 int move_2
           
 int move_3
           
 int move_4
           
 int move_5
           
 int move_6
           
 int move_7
           
 int move_8
           
static int MOVE_DOWN
          The constant that allows a piece to move down.

It can be used in conjunction with other MOVE constants
static int MOVE_DOWN_LEFT
          The constant that allows a piece to move down and to the left.

It can be used in conjunction with other MOVE constants
static int MOVE_DOWN_RIGHT
          The constant that allows a piece to move down and to the right.

It can be used in conjunction with other MOVE constants
static int MOVE_LEFT
          The constant that allows a piece to move to the left.

It can be used in conjunction with other MOVE constants
static int MOVE_RIGHT
          The constant that allows a piece to move to the right.

It can be used in conjunction with other MOVE constants
static int MOVE_UP
          The constant that allows a piece to move up.

It can be used in conjunction with other MOVE constants
static int MOVE_UP_LEFT
          The constant that allows a piece to move up and to the left.

It can be used in conjunction with other MOVE constants
static int MOVE_UP_RIGHT
          The constant that allows a piece to move up and to the right.

It can be used in conjunction with other MOVE constants
 
Fields inherited from class android.view.View
DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, INVISIBLE, KEEP_SCREEN_ON, NO_ID, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET
 
Constructor Summary
Board.Piece(Board.Piece original)
          This constructor is used to copy piece data from an existing Piece.

Board.Piece(Context context, AttributeSet attrs)
          This constructor is used to create a Piece from android xml layout files.

 
Method Summary
 void addPiece(Board.Piece piece)
           
 void deselectCurrentPiece()
           
protected abstract  int firstColor()
          This firstColor method is used to create an image of this Piece's R.drawable.resources.

protected  int fromCurPos(int move)
          This method is used to assign the location of the possible moves for a Piece.

static Board.Piece getPieceAt(int p)
          This method accesses the squares container and returns its piece
static boolean hasSelectedPiece()
           
protected  void invalidateSquares()
           
protected  boolean isLegal(Board.Square square)
           
 boolean isOpponent(Board.Color other)
          This method depicts whether the passed color is the opponent's
protected  void moveTo(int move)
          This sets up a move position for the piece
protected abstract  String pieceLetter()
          This pieceLetter method is used to designate the Piece's letter for PGN format.

 void promoteTo(Board.Piece p)
          This method accepts the new piece to promote to
protected  void resetPossibleMove(int move)
          This resets the move at the passed position to no longer be displayed
protected  void resetPossibleMoves()
           
protected abstract  int secondColor()
          This secondColor method is used to create an image of this Piece's R.drawable.resources.

static Board.Piece selectedPiece()
           
 void selectPiece()
           
 void sendToBack()
           
protected  void setUpLegalSquare(int move)
          This sets up a move position as a legal square to be displayed
protected  void setUpLegalSquares()
          This sets up a move position as a legal square to be displayed
abstract  void setUpMoves()
          This is called each time a piece moves, and should use the MOVE constants (MOVE_UP, etc.).
protected  void showMoves()
           
 String toString()
           
 
Methods inherited from class android.widget.ImageView
clearColorFilter, drawableStateChanged, getBaseline, getDrawable, getImageMatrix, getScaleType, invalidateDrawable, onCreateDrawableState, onDraw, onMeasure, onSetAlpha, setAdjustViewBounds, setAlpha, setColorFilter, setColorFilter, setColorFilter, setFrame, setImageBitmap, setImageDrawable, setImageLevel, setImageMatrix, setImageResource, setImageState, setImageURI, setMaxHeight, setMaxWidth, setScaleType, setSelected, verifyDrawable
 
Methods inherited from class android.view.View
addFocusables, addFocusables, addTouchables, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, cancelLongPress, checkInputConnectionProxy, clearAnimation, clearFocus, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createContextMenu, destroyDrawingCache, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDraw, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetPressed, dispatchSetSelected, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, draw, findFocus, findViewById, findViewWithTag, fitSystemWindows, focusSearch, forceLayout, getAnimation, getApplicationWindowToken, getBackground, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getId, getKeepScreenOn, getKeyDispatcherState, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMeasuredHeight, getMeasuredWidth, getNextFocusDownId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getResources, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getTag, getTag, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getVerticalFadingEdgeLength, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, hasFocus, hasFocusable, hasWindowFocus, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, isClickable, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isInEditMode, isInTouchMode, isLayoutRequested, isLongClickable, isOpaque, isPaddingOffsetRequired, isPressed, isSaveEnabled, isScrollbarFadingEnabled, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, layout, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onAnimationEnd, onAnimationStart, onAttachedToWindow, onCheckIsTextEditor, onConfigurationChanged, onCreateContextMenu, onCreateInputConnection, onDetachedFromWindow, onDisplayHint, onDrawScrollBars, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onLayout, onRestoreInstanceState, onSaveInstanceState, onScrollChanged, onSizeChanged, onStartTemporaryDetach, onTouchEvent, onTrackballEvent, onVisibilityChanged, onWindowFocusChanged, onWindowVisibilityChanged, performClick, performHapticFeedback, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, refreshDrawableState, removeCallbacks, requestFocus, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAnimation, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setClickable, setContentDescription, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFocusable, setFocusableInTouchMode, setHapticFeedbackEnabled, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setId, setKeepScreenOn, setLayoutParams, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnFocusChangeListener, setOnKeyListener, setOnLongClickListener, setOnTouchListener, setPadding, setPressed, setSaveEnabled, setScrollbarFadingEnabled, setScrollBarStyle, setScrollContainer, setSoundEffectsEnabled, setTag, setTag, setTouchDelegate, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVisibility, setWillNotCacheDrawing, setWillNotDraw, showContextMenu, startAnimation, unscheduleDrawable, unscheduleDrawable, willNotCacheDrawing, willNotDraw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MOVE_RIGHT

public static final int MOVE_RIGHT
The constant that allows a piece to move to the right.

It can be used in conjunction with other MOVE constants

See Also:
Constant Field Values

MOVE_UP_RIGHT

public static final int MOVE_UP_RIGHT
The constant that allows a piece to move up and to the right.

It can be used in conjunction with other MOVE constants

See Also:
Constant Field Values

MOVE_UP

public static final int MOVE_UP
The constant that allows a piece to move up.

It can be used in conjunction with other MOVE constants

See Also:
Constant Field Values

MOVE_UP_LEFT

public static final int MOVE_UP_LEFT
The constant that allows a piece to move up and to the left.

It can be used in conjunction with other MOVE constants

See Also:
Constant Field Values

MOVE_LEFT

public static final int MOVE_LEFT
The constant that allows a piece to move to the left.

It can be used in conjunction with other MOVE constants

See Also:
Constant Field Values

MOVE_DOWN_LEFT

public static final int MOVE_DOWN_LEFT
The constant that allows a piece to move down and to the left.

It can be used in conjunction with other MOVE constants

See Also:
Constant Field Values

MOVE_DOWN

public static final int MOVE_DOWN
The constant that allows a piece to move down.

It can be used in conjunction with other MOVE constants

See Also:
Constant Field Values

MOVE_DOWN_RIGHT

public static final int MOVE_DOWN_RIGHT
The constant that allows a piece to move down and to the right.

It can be used in conjunction with other MOVE constants

See Also:
Constant Field Values

INVALID_MOVE

public static final int INVALID_MOVE
The constant that disallows a piece to move.

It can be used in conjunction with the move_# variables

See Also:
Constant Field Values

color

protected Board.Color color

cur_pos

protected int cur_pos

mainLineHistory

protected ArrayList<Board.PGNEvent> mainLineHistory

alternateLineHistory

protected ArrayList<Board.PGNEvent> alternateLineHistory

move_1

public int move_1

move_2

public int move_2

move_3

public int move_3

move_4

public int move_4

move_5

public int move_5

move_6

public int move_6

move_7

public int move_7

move_8

public int move_8

FILE_A

protected final byte[] FILE_A

FILE_B

protected final byte[] FILE_B

FILE_G

protected final byte[] FILE_G

FILE_H

protected final byte[] FILE_H
Constructor Detail

Board.Piece

public Board.Piece(Board.Piece original)
This constructor is used to copy piece data from an existing Piece.

Parameters:
original - The new Piece to be promoted to

Board.Piece

public Board.Piece(Context context,
                   AttributeSet attrs)
This constructor is used to create a Piece from android xml layout files.

Parameters:
context - The Application/Activity context
attrs - The xml attributes passed (i.e. position/coordinate [a4])
Method Detail

firstColor

protected abstract int firstColor()
This firstColor method is used to create an image of this Piece's R.drawable.resources.


secondColor

protected abstract int secondColor()
This secondColor method is used to create an image of this Piece's R.drawable.resources.


pieceLetter

protected abstract String pieceLetter()
This pieceLetter method is used to designate the Piece's letter for PGN format.


addPiece

public void addPiece(Board.Piece piece)

selectPiece

public void selectPiece()

deselectCurrentPiece

public void deselectCurrentPiece()

sendToBack

public void sendToBack()

hasSelectedPiece

public static boolean hasSelectedPiece()

selectedPiece

public static Board.Piece selectedPiece()

getPieceAt

public static Board.Piece getPieceAt(int p)
This method accesses the squares container and returns its piece

Parameters:
p - the position of the square to access
Returns:
The #Piece that is available, otherwise null

isOpponent

public boolean isOpponent(Board.Color other)
This method depicts whether the passed color is the opponent's

Parameters:
other - The color that is received
Returns:
Whether the pieces are opposing colors

promoteTo

public void promoteTo(Board.Piece p)
This method accepts the new piece to promote to

Parameters:
p - The new Piece that is promoted to

isLegal

protected boolean isLegal(Board.Square square)
Parameters:
square - The currently clicked square to check if it is a legal move
Returns:
The value is true if the square that was clicked is a legal move

resetPossibleMoves

protected void resetPossibleMoves()

resetPossibleMove

protected void resetPossibleMove(int move)
This resets the move at the passed position to no longer be displayed

Parameters:
move - The current square to remove data from

setUpLegalSquares

protected void setUpLegalSquares()
This sets up a move position as a legal square to be displayed

Parameters:
square - The current move to check if it is a legal

setUpLegalSquare

protected void setUpLegalSquare(int move)
This sets up a move position as a legal square to be displayed

Parameters:
move - The currently clicked square to check if it is a legal move

moveTo

protected void moveTo(int move)
This sets up a move position for the piece

Parameters:
move - The position/square to move to

invalidateSquares

protected void invalidateSquares()

showMoves

protected void showMoves()

setUpMoves

public abstract void setUpMoves()
This is called each time a piece moves, and should use the MOVE constants (MOVE_UP, etc.). When assigning the
move values from 1 - 8, you can use a clockwise motion (move_1 - top left, move_2 - top, etc.). These moves
are used set up the direction of movement and final position of a move.
For example with the Knight in Knighted or Chess:

move_1 = fromCurPos(MOVE_UP_LEFT + MOVE_LEFT); // 6
move_2 = fromCurPos(MOVE_UP_LEFT + MOVE_UP); // 15

...etc.
   14| 15| 16| 17| 18
   ------------------
   6 | 7 | 8 | 9 | 10
   ------------------
  -2 |-1 |pos| 1 | 2
   ------------------
 -10 |-9 |-8 |-7 | 10
   ------------------
 -18 |-17|-16|-15|-14
 


fromCurPos

protected int fromCurPos(int move)
This method is used to assign the location of the possible moves for a Piece.

Parameters:
move - The change from the original position (to make the move)

toString

public String toString()
Overrides:
toString in class Object