編輯:關於Android編程
public class MainActivity extends Activity implements SensorEventListener
audioManager = (AudioManager) this .getSystemService(Context.AUDIO_SERVICE); mSensorManager = (SensorManager) getSystemService (Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
public void onSensorChanged(SensorEvent event) { // TODO Auto-generated method stub float range = event.values[0]; if (range == mSensor.getMaximumRange()) { Toast.makeText(this, "正常模式", Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "聽筒模式", Toast.LENGTH_LONG).show(); }
public void onSensorChanged(SensorEvent event) { // TODO Auto-generated method stub float range = event.values[0]; if (range == mSensor.getMaximumRange()) { Toast.makeText(this, "正常模式", Toast.LENGTH_LONG).show(); audioManager.setMode(AudioManager.MODE_NORMAL); } else { Toast.makeText(this, "聽筒模式", Toast.LENGTH_LONG).show(); audioManager.setMode(AudioManager.MODE_IN_CALL); }
package com.markjoker.sensortest; import java.io.FileInputStream; import java.io.IOException; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.media.AudioManager; import android.media.MediaPlayer; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.util.Log; import android.view.Menu; import android.widget.Toast; public class MainActivity extends Activity implements SensorEventListener { private AudioManager audioManager; private SensorManager mSensorManager; private Sensor mSensor; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } private void init() { audioManager = (AudioManager) this .getSystemService(Context.AUDIO_SERVICE); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); MediaPlayer mPlayer = new MediaPlayer(); try { mPlayer.reset(); mPlayer.setDataSource(new FileInputStream("/sdcard/snow.mp3").getFD()); mPlayer.prepare(); mPlayer.start(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override protected void onResume() { mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); super.onResume(); } @Override protected void onPause() { // TODO Auto-generated method stub mSensorManager.unregisterListener(this); super.onPause(); } @Override public void onSensorChanged(SensorEvent event) { // TODO Auto-generated method stub float range = event.values[0]; if (range == mSensor.getMaximumRange()) { Toast.makeText(this, "正常模式", Toast.LENGTH_LONG).show(); audioManager.setMode(AudioManager.MODE_NORMAL); } else { Toast.makeText(this, "聽筒模式", Toast.LENGTH_LONG).show(); audioManager.setMode(AudioManager.MODE_IN_CALL); } } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { // TODO Auto-generated method stub } }
本篇來講講 React Native 和 Redux,和其他一上來就啪啪啪丟上來一堆翻譯的東西不同,本文會從簡單的例子入手,讓大家能快速地明白 React Native
1、本地html與本地html裡的js交互2、本地html與本地js交互3、網絡html與網絡js交互4、網絡html與本地js交互5、各個情況動態添加js以上5點都可以
CircleImageView實現圓形頭像代碼分享,供大家參考,具體內容如下一、創建屬性文件(attrs.xml)具體操作:1、在項目的values文件底下創建一新的屬性
主要實現辦法:動態加載各級下拉值的適配器 在監聽本級下拉框,當本級下拉框的選中值改變時,隨之修改下級的適配器的綁定值