0

I have implemented ontouchlistener in my service class and trying to get the touch event which is working well with gingerbread but it is not working with higher than icreamsandwich. I am trying a lot to solve this but I am not getting any solution even after reading a lot of documents in stackoverflow,

Here is the code ..please help me solve this problem. In onCreate method I have defined ImageButton

ImageButton imageButton=new ImageButton(this);
imageButton.setBackgroundColor(Color.TRANSPARENT);
imageButton.setOnTouchListener(this);
WindowManager.LayoutParams layoutParams=new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, 
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, 
            PixelFormat.TRANSLUCENT);
WindowManager windowManager=(WindowManager)getSystemService(WINDOW_SERVICE);
windowManager.addView(imageButton, layoutParams);`

@Override 
public boolean onTouch(View arg0, MotionEvent arg1) {
     Toast.makeText(getApplicationContext(), "Double touched "+DoubleTouch, 1000).show();
     return true;
}
Sujeet Kumar Mehta
  • 2,761
  • 2
  • 20
  • 28

3 Answers3

0

You would have to return true on the onTouch to indicate that a touch event has occurred and you want to return the result.

Refer to this : Android: How to detect double-tap? and Android multi touch and double tap working together for an imageview

Community
  • 1
  • 1
lokoko
  • 5,785
  • 5
  • 35
  • 68
  • You are not to use a double tab. Instead you could use a longclick. you could refer to these however : https://github.com/NikolaDespotoski/DoubleTapListView or https://github.com/NikolaDespotoski/DoubleTapListViewHandler – lokoko Feb 07 '13 at 11:13
0

why you are returning false ? you should return true on touch listener !! sorry but can you tell me what you want to do with the touch listener ? as i can see on your code you only showing Toast. if you want to perform on click . just use OnClickListener instead of touch listener !

Kosh
  • 6,140
  • 3
  • 36
  • 67
  • i did return true also but it is not working , i want to capture double touch event that is why i implementing ontouchlistner , plz give any solution for this – Sujeet Kumar Mehta Feb 07 '13 at 10:27
0

response to your Comment. well you can use OnClickListener instead for double clicks or more!

here is an example : first you create a Boolean variable and assign it to true

boolean lightit = true;

second create the method for the button clicks. in my example here when first time i click the button image will change to another one. and when the button clicked again it change it back to the old image. follow my example here and hope it helps you in anyway.

        private void showHide1() {
    if (lightit) {
        if (null != bmp) {
            rotator = null;
            styleId = StyleKosh.bright;
            change = StyleKosh.changeStyle(bmp, styleId);
            view.setImageBitmap(change);
            fix.setImageResource(R.drawable.lighton);
        } else if (null == bmp) {
            final Toast tst = Toast.makeText(getApplication(),
                    "Please Select An Image First", Toast.LENGTH_SHORT);
            tst.setGravity(Gravity.CENTER, 0, 0);
            tst.show();
        }
    } else {
        rotator = null;
        change = null;
        fix.setImageResource(R.drawable.light);
        view.setImageBitmap(bmp);
    }
    lightit = !lightit;
}

and then on your button Click Listener add this showHide(); this is how i handle clicks on a button or imageview. for multiple clicks you just need to add if else . Please see i'm using the same method to show and hid the statusBar in fullScreen but i'm using Gesture instead of OnTouchListener . tell me if you like to know how i use the Gesture is easier to use.

Kosh
  • 6,140
  • 3
  • 36
  • 67
  • thanks for your answer , actually i want to listen the double touch event in service by implementing overlay widget, will u please suggest me for this problem – Sujeet Kumar Mehta Feb 07 '13 at 10:49