14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

Animation in;<br />

Animation out;<br />

TextPosition newPosition;<br />

Chapter 11: Advanced Android <strong>Development</strong><br />

if (_directionPressed == TextPosition.Left){<br />

in = slideInLeft;<br />

out = slideOutLeft;<br />

}<br />

else if (_directionPressed == TextPosition.Right){<br />

in = slideInRight;<br />

out = slideOutRight;<br />

}<br />

else if (_directionPressed == TextPosition.Top){<br />

in = slideInTop;<br />

out = slideOutTop;<br />

}<br />

else {<br />

in = slideInBottom;<br />

out = slideOutBottom;<br />

}<br />

int newPosValue = _current.ordinal();<br />

int currentValue = _current.ordinal();<br />

// To simulate the effect of ‘tilting’ the device moving in one<br />

// direction should make text for the opposite direction appear.<br />

// Ie. Tilting right should make left appear.<br />

if (_directionPressed == TextPosition.Bottom)<br />

newPosValue = currentValue - 3;<br />

else if (_directionPressed == TextPosition.Top)<br />

newPosValue = currentValue + 3;<br />

else if (_directionPressed == TextPosition.Right) {<br />

if (currentValue % 3 != 0)<br />

newPosValue = currentValue - 1;<br />

}<br />

else if (_directionPressed == TextPosition.Left) {<br />

if ((currentValue+1) % 3 != 0)<br />

newPosValue = currentValue + 1;<br />

}<br />

if (newPosValue != currentValue &&<br />

newPosValue > -1 &&<br />

newPosValue < 9){<br />

newPosition = TextPosition.values()[newPosValue];<br />

}<br />

applyAnimation(in, out, newPosition.toString());<br />

textPosition = newPosition;<br />

8. Wire up the D-pad by overriding the Activity’s onKeyDown handler to listen for key presses and<br />

trigger movePosition accordingly.<br />

@Override<br />

public boolean onKeyDown(int _keyCode, KeyEvent _event) {<br />

369

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!