0

Following... this link ..How to set image as wall paper in viewpager app?. I am able to set wallpaper directly located in my drawable folder. However, i want to give user a chance to set wallpaper by displaying pop up dialogue box which should be displayed. When user clicks on images for 3-5 sec.

I am kind of new to android programming.. So, please help..

Community
  • 1
  • 1

2 Answers2

0
  1. android framework already supporting class "alertDialogue.builder". you can set message whatever you wanna show in addition to dialogue buttons, title etc.

http://developer.android.com/reference/android/app/AlertDialog.Builder.html

  1. 5sec is too long to stay in one fingerpoint. in onsimplegesturedetector class, there is already "long press" detector

http://developer.android.com/reference/android/view/GestureDetector.SimpleOnGestureListener.html

ejin
  • 68
  • 5
0

you can set your own ontouchListener that implements onTouchListener that has gesture detector, detects long press and can show dialogue .

there can be better way but I'm using this logic in my project so you can reference and fix it if you find better way

findViewById("your wall paper image id").onTouchListener(new MyOnTouchListener());



class MyOnTouchListener implements onTouchListener{
    GestureDetector gd = new GestureDetector(new SimpleOnGestureListener(){
        @Override
        public void onLongPress(MotionEvent e) {

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    context);

            alertDialogBuilder.setTitle("Your Title");

            alertDialogBuilder
            .setMessage("click yes to set wallpaper!")
            .setCancelable(false)
            .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                    //setting wallpaper
                }
            })
            .setNegativeButton("No",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                    dialog.cancel();
                }
            });

            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();
        }
    });
}
ejin
  • 68
  • 5