public class ShakeActivity extends Activity implements SensorEventListener {
private static final int SHAKE_THRESHOLD = 800;
private long lastTime;
private float speed;
private float lastX;
private float lastY;
private float lastZ;
private float x, y, z;
private SensorManager sensorManager;
private Sensor accelerormeterSensor;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
accelerormeterSensor = sensorManager
.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}
@Override
public void onStart() {
super.onStart();
if (accelerormeterSensor != null)
sensorManager.registerListener(this, accelerormeterSensor,
SensorManager.SENSOR_DELAY_GAME);
}
@Override
public void onStop() {
super.onStop();
if (sensorManager != null)
sensorManager.unregisterListener(this);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
long currentTime = System.currentTimeMillis();
long gabOfTime = (currentTime - lastTime);
if (gabOfTime > 100) {
lastTime = currentTime;
x = event.values[SensorManager.DATA_X];
y = event.values[SensorManager.DATA_Y];
z = event.values[SensorManager.DATA_Z];
speed = Math.abs(x + y + z - lastX - lastY - lastZ) / gabOfTime * 10000;
if (speed > SHAKE_THRESHOLD) {
Log.d("TAG","##################### shaked #####################");
}
lastX = event.values[SensorManager.DATA_X];
lastY = event.values[SensorManager.DATA_Y];
lastZ = event.values[SensorManager.DATA_Z];
}
}
}
}
2011년 3월 10일 목요일
Android Screen Capture
View root = view.getRootView();
root.setDrawingCacheEnabled(true);
bm = root.getDrawingCache();
File path = new File("/sdcard/samplecapture");
FileOutputStream out = new FileOutputStream("/sdcard/screen.jpg");
bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
root.setDrawingCacheEnabled(true);
bm = root.getDrawingCache();
File path = new File("/sdcard/samplecapture");
FileOutputStream out = new FileOutputStream("/sdcard/screen.jpg");
bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
Android animation sample
public class AnimationTest extends Activity {
/** Called when the activity is first created. */
private AnimationDrawable aniDraw;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
BitmapDrawable ani1 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani1);
BitmapDrawable ani2 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani2);
BitmapDrawable ani3 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani3);
BitmapDrawable ani4 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani4);
BitmapDrawable ani5 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani5);
aniDraw = new AnimationDrawable();
aniDraw.addFrame(ani1,100);
aniDraw.addFrame(ani2,100);
aniDraw.addFrame(ani3,100);
aniDraw.addFrame(ani4,100);
aniDraw.addFrame(ani5,100);
ImageView imgView = (ImageView)findViewById(R.id.imgView);
imgView.setBackgroundDrawable(aniDraw);
aniDraw.setOneShot(false);
Button btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
aniDraw.start();
}
});
}
}
/** Called when the activity is first created. */
private AnimationDrawable aniDraw;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
BitmapDrawable ani1 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani1);
BitmapDrawable ani2 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani2);
BitmapDrawable ani3 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani3);
BitmapDrawable ani4 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani4);
BitmapDrawable ani5 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani5);
aniDraw = new AnimationDrawable();
aniDraw.addFrame(ani1,100);
aniDraw.addFrame(ani2,100);
aniDraw.addFrame(ani3,100);
aniDraw.addFrame(ani4,100);
aniDraw.addFrame(ani5,100);
ImageView imgView = (ImageView)findViewById(R.id.imgView);
imgView.setBackgroundDrawable(aniDraw);
aniDraw.setOneShot(false);
Button btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
aniDraw.start();
}
});
}
}
Home Apk Search
try {
PackageManager mPm = context.getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_HOME);
rList = mPm.queryIntentActivities( mainIntent, 0 );
} catch ( Exception e ) {
Log.e(LOG_TAG, "getHomeApp() Error", e);
}
for (int i=0; i
ResolveInfo ri = rList.get(i);
Log.v(LOG_TAG ,"[" +cName.getClassName() + "] = [" + ri.activityInfo.name+"]" );
if ( cName.getClassName().equals(ri.activityInfo.name) ) return true;
}
PackageManager mPm = context.getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_HOME);
rList = mPm.queryIntentActivities( mainIntent, 0 );
} catch ( Exception e ) {
Log.e(LOG_TAG, "getHomeApp() Error", e);
}
for (int i=0; i
ResolveInfo ri = rList.get(i);
Log.v(LOG_TAG ,"[" +cName.getClassName() + "] = [" + ri.activityInfo.name+"]" );
if ( cName.getClassName().equals(ri.activityInfo.name) ) return true;
}
피드 구독하기:
글 (Atom)