Sunday, August 22, 2010

How to Send Email in Android ?

Intent sendIntent;

sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT,
"Test");
sendIntent.putExtra(Intent.EXTRA_TEXT,
"Hy Testing");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"
+ file.getAbsolutePath()));
sendIntent.setType("image/jpeg");
startActivity(Intent.createChooser(sendIntent, "Send Mail"));

AsyncTask background Process / Thread in android

private class AsyncCheckInternet extends AsyncTask {
@Override
protected void onPreExecute() {
dialogProcess = ProgressDialog.show(classname.this, "",
"processing...", true);
}
@Override
protected Boolean doInBackground(Void... voids) {

// Background function logic
}
@Override
protected void onPostExecute(Boolean params) {
dialogProcess.dismiss();
// After background Process end Called params true or false....
}
}
}


// call background AsyncTask

new AsyncCheckInternet().execute();

How to use GestureDetector in Android application ?

// Gesture Detect
private static final int SWIPE_MIN_DISTANCE = 30;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 50;

private GestureDetector gestureDetector;
View.OnTouchListener gestureListener;

img1 = (ImageView) findViewById(R.id.ImageView01);
img2 = (ImageView) findViewById(R.id.ImageView02);
img3 = (ImageView) findViewById(R.id.ImageView03);
img4 = (ImageView) findViewById(R.id.ImageView04);

rel1 = (RelativeLayout) findViewById(R.id.RelativeLayout01);
rel2 = (RelativeLayout) findViewById(R.id.RelativeLayout05);
rel3 = (RelativeLayout) findViewById(R.id.RelativeLayout06);
rel4 = (RelativeLayout) findViewById(R.id.RelativeLayout07);



gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};

rel1.setOnTouchListener(gestureListener);
rel2.setOnTouchListener(gestureListener);
rel3.setOnTouchListener(gestureListener);
rel4.setOnTouchListener(gestureListener);

img1.setOnTouchListener(gestureListener);
img2.setOnTouchListener(gestureListener);
img3.setOnTouchListener(gestureListener);
img4.setOnTouchListener(gestureListener);


class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe

if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY
&& curPage < _totPages - 1) {

//// Logic
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY
&& curPage > 0) {
//// Logic
}

} catch (Exception e) {
// nothing
}
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
// TODO Auto-generated method stub
return super.onScroll(e1, e2, distanceX, distanceY);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event))
return true;
else
return false;
}