Showing posts from March, 2016

Dismiss or Cancel dialog by swipe gesture

Dismiss dialog by all four swipe gestures as swipe right to left, left to right, top to bottom, bottom to top First, create a inner class in custom dialogFragment class for the the SimpleGestureListener as, class MyGestureDetector extends GestureDetector.SimpleOnGestureListener { private static final int SWIPE_MIN_DISTANCE = 120; private static final int SWIPE_THRESHOLD_VELOCITY = 200; public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { // swipe right to left dismiss(); } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { // swipe left to right dismiss(); } else if (…

Add Button and onClick on Custom Notification in Android

Add a broadcast receiver with action and pass the Intent with action to PendingIntent The code snippet is as follows, Intent intent = new Intent("action.cancel.notification"); PendingIntent pi = PendingIntent.getBroadCast(this, id, intent, PendingIntent.FLAG_UPDATE_CUREENT); Also add the receiver in manifest <receiver android:name="CancelNotificationReceiver"> <intent-filter> <action android:name="action.cancel.notification"/> </intent-filter> </receiver> After that, to the pictureView add the pendingIntnet as, pictureView.setOnClickPendingIntent(, pi); The last part is define the receiver class as, public class CancelNotificationReceiver extends Broadcastreceiver { public void onReceive(Context context, Intent intent) { if ("action.cancel.notification".equalsIgnoreCase(intent.getAction())) { // .. do what ever you want } } }