10. Tips: ハードウェアキーの補足
public boolean onKeyDown(int keyCode, KeyEvent event) {
super.onKeyDown(keyCode, event);
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_DPAD_RIGHT:
case KeyEvent.KEYCODE_SPACE:
case KeyEvent.KEYCODE_ENTER:
... (省略) ...
return true;
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DEL:
... (省略) ...
return true;
}
return false;
}
10
16. サンプル(SimpleCalc)の用意②
package jp.probsc.simplecalc;
?src/.../Calculator.java
/**
*計算クラス
*/
public class Calculator {
/** 足し算 */
public static int Add(int a, int b) {
return a + b;
}
/** 引き算 */
public static int Sub(int a, int b) {
return a - b;
}
/** 掛け算 */
public static int Mul(int a, int b) {
return a * b;
}
/** 割り算 */
public static double Div(int a, int b) {
return a / b;
}
} 16