Two OnTouchListener Conflicting
<p>I am creating an image viewer with zoom. i am using flipper for when i flip it by finger horizontal it go to next /previous image. and also include the code for zoom the picture. 
                Problem: I am using two setOnTouchListener  one for zoom and one for flip. so at a time only one is working . how i solve it my code is given below:</p>

<p>=>   mZoomView.setOnTouchListener(mZoomListener); and another is for gesture.</p>

<p><strong>MyXml for ImageZoom</strong></p>

<pre><code>    &lt;cloudOptix.Storage.zoom.ImageZoomView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/imgToShow"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:scaleType="fitXY"
        android:src="@drawable/musicc" /&gt;      
</code></pre>

<p><strong>ImageViewer.class</strong></p>

<pre><code>        private ImageZoomView mZoomView;
        private ImageZoomView mZoomViewTemp;
        private SimpleZoomListener mZoomListener;

        public class ImageViewer extends Activity {
                    /** Called when the activity is first created. */
                    /** Constant used as menu item id for setting zoom control type */
                    private static final int MENU_ID_ZOOM = 0;

                    /** Constant used as menu item id for setting pan control type */
                    private static final int MENU_ID_PAN = 1;

                    /** Constant used as menu item id for resetting zoom state */
                    private static final int MENU_ID_RESET = 2;

                    /** Image zoom view */
                    private ImageZoomView mZoomView;
                    private ImageZoomView mZoomViewTemp;
                    /** Zoom state */
                    private ZoomState mZoomState;

                    /** On touch listener for zoom view */
                    private SimpleZoomListener mZoomListener;

                    /** Decoded bitmap image */
                    private Bitmap mBitmap;

                    String[] mFiles=null; 
                    String value;
                    ImageAdapter adpt;
                    Bitmap[] mUrls;     
                    static List&lt;ObjectVM&gt; data;
                    int pos=0;
                    //  ImageView img;
                    boolean flag=false,is_slideShow_running=false;
                    ProgressDialog dialog ;
                    File[] imagelist;
                    String path="";
                    TextView trackName;
                    LinearLayout layout_for_buttons;

                    ImageView music;
                    //fliper
                    private static final int SWIPE_MIN_DISTANCE = 120;
                    private static final int SWIPE_MAX_OFF_PATH = 250;
                    private static final int SWIPE_THRESHOLD_VELOCITY = 200;
                    private GestureDetector gestureDetector;
                    View.OnTouchListener gestureListener;
                    private Animation slideLeftIn;
                    private Animation slideLeftOut;
                    private Animation slideRightIn;
                    private Animation slideRightOut;
                    private ViewFlipper viewFlipper;
                    View viewImagZoom;
                    int count;


                    @Override
                    protected void onResume()
                    {
                        super.onResume();
                        showMusicIcon();
                    }

                    private void showMusicIcon()
                    {
                        music.setOnClickListener(new OnClickListener() 
                        {           
                            @Override
                            public void onClick(View v) 
                            {       
                                Bundle b=new Bundle();
                                b.putString("key", "");
                                b.putString("path", "");
                                Intent intent=new Intent(ImageViewer.this,AudioViewer.class);
                                intent.putExtras(b);
                                startActivityForResult(intent, 0);
                            }
                        });

                        if(AudioViewer.mediaPlayer==null)       
                            music.setVisibility(View.GONE);     
                        else
                            music.setVisibility(View.VISIBLE);
                    }

                    private void setInitials(Intent intent)
                    {
                        Bundle b = intent.getExtras();      
                        value = b.getString("key");
                        path=b.getString("path");
                        try
                        {
                            setImage();
                            try
                            {
                                mZoomView.setflag(true);
                                if(mUrls[pos]!=null)
                                    mZoomView.setImage(mUrls[pos]);
                            }
                            catch(Exception e)
                            {
                            }
                        }
                        catch(Exception e)
                        {
                            trackName.setText("Player do not support this kind of file.");
                        }
                    }

                    private void setParameters()
                    {
                        Display display = getWindowManager().getDefaultDisplay(); 
                        int w = display.getWidth();
                        int h = display.getHeight();        
                        RelativeLayout.LayoutParams adaptLayout = new RelativeLayout.LayoutParams(w,h-180);
                        mZoomView.setflag(true);
                        mZoomView.setLayoutParams(adaptLayout);
                    }

                    private void setParameters1()
                    {
                        Display display = getWindowManager().getDefaultDisplay(); 
                        int w = display.getWidth();
                        int h = display.getHeight();        
                        RelativeLayout.LayoutParams adaptLayout = new RelativeLayout.LayoutParams(w,h);
                        mZoomView.setflag(true);
                        mZoomView.setLayoutParams(adaptLayout);
                    }

                    @Override
                    public void onConfigurationChanged(Configuration newConfig) {
                        super.onConfigurationChanged(newConfig);
                        if(layout_for_buttons.getVisibility()==View.GONE)
                        {
                            setParameters1();
                        }
                        else
                        {
                            setParameters();
                        }

                    }

                    private void setImage()
                    {
                        Display display = getWindowManager().getDefaultDisplay(); 
                        int w = display.getWidth();
                        int h = display.getHeight();
                        File images =  new File(path);//"/sdcard/Downloads/"); 

                        imagelist=images.listFiles(new FilenameFilter() 
                        {
                            @Override
                            public boolean accept(File dir, String filename) 
                            {
                                String ext=filename.substring(filename.lastIndexOf(".")+1,filename.length()).toLowerCase();
                                if(Launcher.image_extension.contains(ext))
                                    return true;
                                return false;
                            }
                        });
                        mFiles = new String[imagelist.length];  

                        for(int i= 0 ; i&lt; imagelist.length; i++)  
                        {  
                            if(value.contains(imagelist[i].getName()))
                            {
                                mFiles[i] = imagelist[i].getAbsolutePath();
                            }
                        }  
                        mUrls = new Bitmap[mFiles.length];  

                        for(int i=0; i &lt; mFiles.length; i++)  
                        {  
                            if(mFiles[i]!=null)
                            {
                                try
                                {

                                    BitmapFactory.Options o = new BitmapFactory.Options();
                                    o.inJustDecodeBounds = true;

                                    FileInputStream fis = new FileInputStream(mFiles[i]);
                                    BitmapFactory.decodeStream(fis, null, o);
                                    fis.close();
                                    final int REQUIRED_SIZE=h/6;
                                    int width_tmp=o.outWidth, height_tmp=o.outHeight;
                                    int scale=1;
                                    while(true){
                                        if(width_tmp/2&lt;REQUIRED_SIZE || height_tmp/2&lt;REQUIRED_SIZE)
                                            break;
                                        width_tmp/=2;
                                        height_tmp/=2;
                                        scale*=2;
                                    }
                                    BitmapFactory.Options o2 = new BitmapFactory.Options();
                                    o2.inSampleSize = scale;
                                    fis = new FileInputStream(mFiles[i]);
                                    mUrls[pos] = BitmapFactory.decodeStream(fis, null, o2);
                                    fis.close();
                                }
                                catch(Exception e)
                                {                   
                                }
                            }
                        }    
                    }

                    public static void setCollection(List&lt;ObjectVM&gt; listChild)
                    {
                        data=listChild;
                    }

                    private boolean ifFileExist()
                    {
                        value=data.get(pos).GetKey().substring(data.get(pos).GetKey().lastIndexOf("/")+1, data.get(pos).GetKey().length());
                        for(int i= 0 ; i&lt; imagelist.length; i++)  
                        {  
                            if(value.equals(imagelist[i].getName()))
                            {
                                return true;
                            }
                        }       
                        return false;
                    }

                    @Override
                    public void onCreate(Bundle savedInstanceState) 
                    {
                        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.image_viewer);
                        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
                        TextView mytitletext = (TextView) findViewById(R.id.myTitle);
                        ImageView img=(ImageView)findViewById(R.id.i);
                        music=(ImageView)findViewById(R.id.music);  
                        layout_for_buttons=(LinearLayout)findViewById(R.id.layout_for_buttons);
                        mytitletext.setText("");
                        img.setBackgroundDrawable(null);
                        showMusicIcon();
                        try
                        {
                            //      img=(ImageView)findViewById(R.id.imgToShow);
                            Button btn_next=(Button)findViewById(R.id.btnBack);
                            Button btn_prev=(Button)findViewById(R.id.btnNext);
                            final Button btn_play=(Button)findViewById(R.id.btnPlay);
                            btn_play.setBackgroundResource(R.drawable.play);
                            Intent intent = getIntent();

                            trackName=(TextView)findViewById(R.id.Message);

                            //flipper
                            viewFlipper = (ViewFlipper)findViewById(R.id.flipper);
                            slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
                            slideLeftOut = AnimationUtils.loadAnimation(this, R.anim.slide_left_out);
                            slideRightIn = AnimationUtils.loadAnimation(this, R.anim.slide_right_in);
                            slideRightOut = AnimationUtils.loadAnimation(this, R.anim.slide_right_out);
                            mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.musicc);

                            gestureDetector = new GestureDetector(new MyGestureDetector());

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

                            mZoomState = new ZoomState();       

                            mZoomListener = new SimpleZoomListener();
                            mZoomListener.setZoomState(mZoomState);
                            LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                            viewImagZoom=(View)inflater.inflate(R.layout.zoomview ,null);

                            mZoomView = (ImageZoomView)viewImagZoom.findViewById(R.id.imgToShow);
                            setInitials(intent);
                            setImage();
                            mZoomView.setZoomState(mZoomState);             
                          **mZoomView.setOnTouchListener(mZoomListener);**


                            resetZoomState();
                                pos--;
                            NextImg();
                            viewFlipper.showNext();
                            trackName.setText(value);
                            pos=getCurrentPosOfFile();
                        }
                        catch(Exception e)
                        {
                        }
                    }

                    public void PreImg()
                    {

                        pos--;
                        Toast.makeText(this, "Pre "+pos, 20).show();
                        if(pos&lt;data.size() &amp;&amp; pos&gt;=0)
                        {       
                            if(!ifFileExist())
                                downloadFile(); 
                            else
                            {
                                value=data.get(pos).GetKey().substring(data.get(pos).GetKey().lastIndexOf("/")+1, data.get(pos).GetKey().length());
                                if(mUrls[pos]==null)
                                setImage();
                                try
                                {   
                                    mZoomView.setflag(true);
                                    mZoomView.setImage(mUrls[pos]);
                                    viewFlipper.removeAllViews();
                                    viewFlipper.addView(mZoomView);
                                    trackName.setText(value);
                                }
                                catch(Exception e)
                                {
                                    trackName.setText("Player do not support this kind of file.");
                                }
                            }
                        }
                        else
                        {
                            pos++;              
                            Toast.makeText(ImageViewer.this, "No More Images........", Toast.LENGTH_SHORT).show();
                        }
                    }

                    public void NextImg()
                    {
                        pos++;
                        Toast.makeText(this, "Next "+pos, 20).show();
                        if(pos&lt;data.size() &amp;&amp; pos&gt;=0)
                        {

                            if(!ifFileExist())
                                downloadFile(); 
                            else
                            {
                                value=data.get(pos).GetKey().substring(data.get(pos).GetKey().lastIndexOf("/")+1, data.get(pos).GetKey().length());
                                if(mUrls[pos]==null)
                                    setImage();
                                try
                                {   
                                    mZoomView.setflag(true);

                                    mZoomView.setImage(mUrls[pos]);
                                   viewFlipper.removeAllViews();
                                    viewFlipper.addView(mZoomView);
                                    trackName.setText(value);
                                }
                                catch(Exception e)
                                {
                                    trackName.setText("Player do not support this kind of file.");
                                }
                            }
                        }
                        else
                        {
                            pos--;
                            Toast.makeText(ImageViewer.this, "No More Images........", Toast.LENGTH_SHORT).show();
                        }
                    }


                    class MyGestureDetector extends SimpleOnGestureListener {
                        @Override
                        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                            try {
                                if (Math.abs(e1.getY() - e2.getY()) &gt; SWIPE_MAX_OFF_PATH)
                                    return false;
                                // right to left swipe
                                if(e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
                                    viewFlipper.setInAnimation(slideLeftIn);
                                    viewFlipper.setOutAnimation(slideLeftOut);
                                    NextImg();
                                    viewFlipper.showNext();
                                }  else if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
                                    viewFlipper.setInAnimation(slideRightIn);
                                    viewFlipper.setOutAnimation(slideRightOut);
                                    PreImg();
                                    viewFlipper.showPrevious();                 
                                }
                            } catch (Exception e) {
                                // nothing
                            }
                            return false;
                        }
                    }

                    @Override
                    public boolean onTouchEvent(MotionEvent event) {
                        if (gestureDetector.onTouchEvent(event))
                            return true;
                        else
                            return false;
                    }


                    Handler handlerForSlideShow = new Handler() 
                    {
                        public void handleMessage(Message msg) 
                        {   

                            startPlayProgressUpdater();     
                        }
                    };

                    public void startPlayProgressUpdater() 
                    {
                        if (is_slideShow_running) 
                        {
                            pos++;
                            if(!(pos&lt;data.size() &amp;&amp; pos&gt;=0))
                            {
                                pos=0;          
                            }
                            if(!ifFileExist())
                                downloadFile(); 
                            else
                            {
                                value=data.get(pos).GetKey().substring(data.get(pos).GetKey().lastIndexOf("/")+1, data.get(pos).GetKey().length());
                                setImage();
                                trackName.setText(value);
                                mZoomView.setImage(mUrls[pos]);
                                Runnable notification = new Runnable() 
                                {
                                    public void run() 
                                    {
                                        //                  
                                        startPlayProgressUpdater();
                                    }
                                };
                                handlerForSlideShow.postDelayed(notification,5000);
                            }
                        }       
                    } 

                    private int getCurrentPosOfFile()
                    {
                        for(int i= 0 ; i&lt; data.size(); i++)  
                        {  
                            if(value.contains(data.get(i).GetName()))
                            {
                                return i;
                            }
                        }       
                        return -1;
                    }


                    @Override   
                    protected void onDestroy() {
                        super.onDestroy();

                        mBitmap.recycle();
                        mZoomView.setOnTouchListener(null);
                        mZoomState.deleteObservers();
                    }

                    @Override
                    public boolean onCreateOptionsMenu(Menu menu) {
                        menu.add(Menu.NONE, MENU_ID_ZOOM, 0, "Zoom");
                        menu.add(Menu.NONE, MENU_ID_PAN, 1,"Pan");
                        menu.add(Menu.NONE, MENU_ID_RESET, 2,"Reset");
                        return super.onCreateOptionsMenu(menu);
                    }

                    @Override
                    public boolean onOptionsItemSelected(MenuItem item) {
                        switch (item.getItemId()) {
                        case MENU_ID_ZOOM:
                            mZoomListener.setControlType(ControlType.ZOOM);
                            break;

                        case MENU_ID_PAN:
                            mZoomListener.setControlType(ControlType.PAN);
                            break;

                        case MENU_ID_RESET:
                            resetZoomState();
                            break;
                        }

                        return super.onOptionsItemSelected(item);
                    }

                    /**
                     * Reset zoom state and notify observers
                     */
                    private void resetZoomState() 
                    {
                        mZoomView.setflag(true);
                        mZoomState.setPanX(0.5f);
                        mZoomState.setPanY(0.5f);
                        mZoomState.setZoom(1f);
                        mZoomState.notifyObservers();
                    }
                }
</code></pre>

<p><strong>SimpleZoomListener.class</strong></p>

<pre><code>        public class SimpleZoomListener implements View.OnTouchListener {

            /**
             * Which type of control is used
             */
            public enum ControlType {
                PAN, ZOOM
            }

            /** State being controlled by touch events */
            private ZoomState mState;

            /** Current control type being used */
            private ControlType mControlType = ControlType.ZOOM;

            /** X-coordinate of previously handled touch event */
            private float mX;

            /** Y-coordinate of previously handled touch event */
            private float mY;
            public static boolean istouch=false;
            /**
             * Sets the zoom state that should be controlled
             * 
             * @param state Zoom state
             */
            public void setZoomState(ZoomState state) {
                mState = state;
            }



            /**
             * Sets the control type to use
             * 
             * @param controlType Control type
             */
            public void setControlType(ControlType controlType) {
                mControlType = controlType;
            }

            // implements View.OnTouchListener
            public boolean onTouch(View v, MotionEvent event) {
                final int action = event.getAction();
                final float x = event.getX();
                final float y = event.getY();

                //if (Math.abs(e1.getY() - e2.getY()) &gt; SWIPE_MAX_OFF_PATH)
                switch (action) {
                    case MotionEvent.ACTION_DOWN:
                        mX = x;
                        mY = y;
                        istouch=false;
                        break;


                    case MotionEvent.ACTION_MOVE: {
                        final float dx = (x - mX) / v.getWidth();
                        final float dy = (y - mY) / v.getHeight();

                        if (mControlType == ControlType.ZOOM) 
                        {
                            mState.setZoom(mState.getZoom() * (float)Math.pow(20, -dy));
                            mState.notifyObservers();
                        } 
                        else 
                        {
                            mState.setPanX(mState.getPanX() - dx);
                            mState.setPanY(mState.getPanY() - dy);
                            mState.notifyObservers();
                        }

                        mX = x;
                        mY = y;
                        istouch=true;
                        break;
                    }
                }

                return false;

            }

        }
</code></pre>

<p>When i zoom Touch for zoom must be work and when i flip flip must work how i done it?
plz help.</p>
