将接近传感器替换为CMOS传感器,以计算人脸与手机之间的更远距离
public class GameActivity extends AppCompatActivity implements SensorEventListener {
// Player enumeration
private enum Player {
X("X"), O("O"), NEITHER("");
private String value;
Player(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
private SensorManager mSensorManager;
private Sensor mProximity;
private static final int SENSOR_SENSITIVITY = 5;
private static final int BOARD_SIZE = 3;
private MediaPlayer backgroundMediaPlayer;
private MediaPlayer popUpMediaPlayer;
private TableLayout board;
private RelativeLayout rlResultSection;
private TextView tvInfo;
private Player[][] playerBoard;
private Player nextPlayer;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
getSupportActionBar().setDisplayHomeAsUpEnabled(Boolean.TRUE);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
backgroundMediaPlayer = MediaPlayer.create(this, R.raw.up_your_street_background_music);
backgroundMediaPlayer.setLooping(Boolean.TRUE);
backgroundMediaPlayer.setVolume(100, 100);
popUpMediaPlayer = MediaPlayer.create(this, R.raw.blur_pop_up);
popUpMediaPlayer.setLooping(Boolean.TRUE);
popUpMediaPlayer.setVolume(100, 100);
playerBoard = new Player[BOARD_SIZE][BOARD_SIZE];
board = (TableLayout) findViewById(R.id.board);
tvInfo = (TextView) findViewById(R.id.tvInfo);
rlResultSection = (RelativeLayout) findViewById(R.id.rlResultSection);
resetGame();
Button btnReset = (Button) findViewById(R.id.btnReset);
btnReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
resetGame();
}
});
Button btnQuit = (Button) findViewById(R.id.btnQuit);
btnQuit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GameActivity.this.onBackPressed();
}
});
}