将接近传感器替换为CMOS传感器以计算更远的距离

时间:2018-07-14 07:53:30

标签: c# android-sensors proximitysensor

将接近传感器替换为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();
        }
    });
}
  1. 这是我用来检测人脸与手机屏幕之间距离的接近传感器,但仅适用于非常短的距离。
  2. 有人有什么想法来激活和替换CMOS传感器吗?

0 个答案:

没有答案