毕业论文

当前位置: 毕业论文 > 范文 >

android光线传感器开发(2)

时间:2019-03-07 13:03来源:优尔论文
} ck_bright.setOnCheckedChangeListener(this); tv_light = (TextView) findViewById(R.id.tv_light); mSensroMgr = (SensorManager) getSystemService(Context.SENSOR_SERVICE); } @Override public void onChecke


        }
        ck_bright.setOnCheckedChangeListener(this);
        tv_light = (TextView) findViewById(R.id.tv_light);
        mSensroMgr = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (buttonView.getId() == R.id.ck_bright) {
            SwitchUtil.setAutoBrightStatus(this, isChecked);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        mSensroMgr.unregisterListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mSensroMgr.registerListener(this, mSensroMgr.getDefaultSensor(Sensor.TYPE_LIGHT),
                SensorManager.SENSOR_DELAY_NORMAL);
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
        if (event.sensor.getType() == Sensor.TYPE_LIGHT) {
            float light_strength = event.values[0];
            tv_light.setText(Utils.getNowDateTimeFormat() + "\n当前光线强度为" + light_strength);
        }
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
        //当传感器精度改变时回调该方法,一般无需处理
    }
} android光线传感器开发(2):http://www.youerw.com/fanwen/lunwen_30827.html
------分隔线----------------------------
推荐内容