端末の発着信履歴を表示

public class CallLogActivity implements SensorEventListener {
	SensorManager sensorManager;
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
		
		Cursor c = getContentResolver().query(
				android.provider.CallLog.Calls.CONTENT_URI, null, null, null,
				android.provider.CallLog.Calls.DATE+ " DESC");
		startManagingCursor(c);
		ListAdapter adapter = new SimpleCursorAdapter(this,
				R.layout.calllog_row, c, new String[] {
				android.provider.CallLog.Calls.TYPE,
				android.provider.CallLog.Calls.NUMBER,
				android.provider.CallLog.Calls.CACHED_NAME },
				new int[] { R.id.type, R.id.number, R.id.name }) {
			@Override
			public void setViewImage(ImageView v, String value){
				switch (Integer.parseInt(value)){
				case android.provider.CallLog.Calls.INCOMING_TYPE:
					v.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_call_incoming));
					break;
				case android.provider.CallLog.Calls.MISSED_TYPE:
					v.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_call_missed));
					break;
				case android.provider.CallLog.Calls.OUTGOING_TYPE:
					v.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_call_outgoing));
					break;
					default:
						break;
				}
			}
		};
		setListAdapter(adapter);
	}
	
	// activity
	@Override
	protected void onResume(){
		super.onResume();
		sensorManager.registerListener(this,
				sensorManager.getDefaultSensor(Sensor.TYPE_ACCELERAOMETER),
				SensorManager.SENSOR_DELAY_UI);
	}
	@Override
	protected void onStop(){
		sensorManager.unregisterListener(this);
		super.onStop();
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id){
		telTo(((TextView) v.findViewById(R.id.number)).getText());
	}
	
	public void onSensorChanged(SensorEvent event){
		switch(event.sensor.getType()){
		case Sencor.TYPE_ACCELEROMETER:
			if (getSelectedItemPosition() > -1){
				if (Math.abs(event.values[0]) > SensorManager.GRAVITY_EARTH
				|| Math.abs(event.values[1]) > SensorManager.GRAVITY_EARTH
				|| Math.abs(event.values[2]) > SensorManager.GRAVITY_EARTH) {
					telTo(((TextView) getListView().getChildAt(
							getSelectedItemPosition()).findViewById(R.id.number)).getText());
				}
			}
			default:
		}
}