Example usage for android.view MotionEvent getAction

List of usage examples for android.view MotionEvent getAction

Introduction

In this page you can find the example usage for android.view MotionEvent getAction.

Prototype

public final int getAction() 

Source Link

Document

Return the kind of action being performed.

Usage

From source file:com.quarterfull.newsAndroid.NewsDetailFragment.java

@SuppressLint("SetJavaScriptEnabled")
private void init_webView() {
    int backgroundColor = ColorHelper.getColorFromAttribute(getContext(), R.attr.news_detail_background_color);
    mWebView.setBackgroundColor(backgroundColor);

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(false);
    webSettings.setSupportMultipleWindows(false);
    webSettings.setSupportZoom(false);//w w  w.j a  va2 s.  co  m
    webSettings.setAppCacheEnabled(true);

    registerForContextMenu(mWebView);

    mWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.v(TAG, cm.message() + " at " + cm.sourceId() + ":" + cm.lineNumber());
            return true;
        }

        @Override
        public void onProgressChanged(WebView view, int progress) {
            if (progress < 100 && mProgressbarWebView.getVisibility() == ProgressBar.GONE) {
                mProgressbarWebView.setVisibility(ProgressBar.VISIBLE);
            }
            mProgressbarWebView.setProgress(progress);
            if (progress == 100) {
                mProgressbarWebView.setVisibility(ProgressBar.GONE);

                //The following three lines are a workaround for websites which don't use a background color
                int bgColor = ContextCompat.getColor(getContext(),
                        R.color.slider_listview_text_color_dark_theme);
                NewsDetailActivity ndActivity = ((NewsDetailActivity) getActivity());
                mWebView.setBackgroundColor(bgColor);
                ndActivity.mViewPager.setBackgroundColor(bgColor);

                if (ThemeChooser.isDarkTheme(getActivity())) {
                    mWebView.setBackgroundColor(
                            ContextCompat.getColor(getContext(), android.R.color.transparent));
                }
            }
        }
    });

    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if (changedUrl) {
                changedUrl = false;

                if (!url.equals("file:///android_asset/") && (urls.isEmpty() || !urls.get(0).equals(url))) {
                    urls.add(0, url);

                    Log.v(TAG, "Page finished (added): " + url);
                }
            }

            super.onPageStarted(view, url, favicon);
        }
    });

    mWebView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (v.getId() == R.id.webview && event.getAction() == MotionEvent.ACTION_DOWN) {
                changedUrl = true;
            }

            return false;
        }
    });
}

From source file:com.android.yijiang.kzx.widget.betterpickers.widget.UnderlinePageIndicatorPicker.java

public boolean onTouchEvent(MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*ww  w  . ja  v  a 2 s. c om*/
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;

            if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage - 1);
                }
                return true;
            } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage + 1);
                }
                return true;
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging()) {
            mViewPager.endFakeDrag();
        }
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent me) {
    if (mGestureDetector.onTouchEvent(me)) {
        return true;
    }//from w w  w .j  av a  2 s .  com

    int action = me.getAction();
    final int x = (int) me.getX();
    final int y = (int) me.getY();
    mTouchX = x;

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        invalidate();
        break;
    case MotionEvent.ACTION_MOVE:
        if (y <= 0) {
            // Fling up!?
            //Fling up should be a hacker's way to delete words (user dictionary words)
            if (mSelectedString != null) {
                Logger.d(TAG, "Fling up from candidates view. Deleting word at index %d, which is %s",
                        mSelectedIndex, mSelectedString);
                mService.removeFromUserDictionary(mSelectedString.toString());
                clear();
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        if (!mScrolled) {
            if (mSelectedString != null) {
                if (mShowingAddToDictionary) {
                    final CharSequence word = mSuggestions.get(0);
                    if (word.length() >= 2 && !mNoticing) {
                        Logger.d(TAG, "User wants to add the word '%s' to the user-dictionary.", word);
                        boolean added = mService.addWordToDictionary(word.toString());
                        if (!added) {
                            Logger.w(TAG, "Failed to add word to user-dictionary!");
                        }
                    }
                } else if (!mNoticing) {
                    mService.pickSuggestionManually(mSelectedIndex, mSelectedString);
                } else if (mSelectedIndex == 1 && !TextUtils.isEmpty(mJustAddedWord)) {
                    // 1 is the index of "Remove?"
                    Logger.d(TAG, "User wants to remove an added word '%s'", mJustAddedWord);
                    mService.removeFromUserDictionary(mJustAddedWord.toString());
                }
            }
        }

        invalidate();
        break;
    }
    return true;
}

From source file:com.tarun.smartwomen.WebViewDemoActivity.java

@SuppressLint({ "JavascriptInterface", "SetJavaScriptEnabled" })
@Override/*from w  w w .j a va2  s . c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.mainn);

    Intent intent = getIntent();
    reg = intent.getBooleanExtra("reg", false);

    i = (ImageView) findViewById(R.id.hj);

    try {

        big = new GifAnimationDrawable(getResources().openRawResource(R.raw.anim2));
        // big.setOneShot(true);
        android.util.Log.v("GifAnimationDrawable", "===>Four");
    } catch (IOException ioe) {

    }

    i.setImageDrawable(big);
    big.setVisible(true, true);

    sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
    // historyStack = new LinkedList<Link>();
    webview = (WebView) findViewById(R.id.webkit);

    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);

    webSettings.setDomStorageEnabled(true);
    // webview.addJavascriptInterface(new WebViewDemoActivity(), "Android");
    // webview.getSettings().setJavaScriptEnabled(true);

    webview.getSettings().setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        // webview.getSettings().setPluginState(PluginState.ON);
        // webview.getSettings().setJavaScriptEnabled(true);
    } else {
        // IMPORTANT!! this method is no longer available since Android 4.3
        // so the code doesn't compile anymore
        // webview.getSettings().setPluginsEnabled(true);
    }

    // Internet

    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    connected = false;
    if ((null != connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) && connectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED)
            || (null != connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI) && connectivityManager
                    .getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED)) {
        // we are connected to a network
        connected = true;
    }

    if (connected == false) {
        /*
         * Toast.makeText(Rss.this,
         * "Connect to internet and Restart Application",
         * Toast.LENGTH_SHORT).show();
         */
        webview.setVisibility(View.INVISIBLE);

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(WebViewDemoActivity.this);

        // alertDialogBuilder.setTitle("Please connect to Internet");
        alertDialogBuilder.setMessage(
                "In order to provide the freshest recipes and juicing information this app must be connected to the internet, please check your internet settings");
        // set positive button: Yes message

        alertDialogBuilder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // cancel the alert box and put a Toast to the user

                startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
            }
        });
        AlertDialog alertDialog = alertDialogBuilder.create();
        // show alert
        alertDialog.show();

    }

    // downloads
    // webview.setDownloadListener(new CustomDownloadListener());

    webview.setWebViewClient(new CustomWebViewClient());

    webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {

        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
        }

        @Override
        public void onReceivedIcon(WebView view, Bitmap icon) {

        }

    });

    // http://stackoverflow.com/questions/2083909/android-webview-refusing-user-input
    webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                    v.requestFocus();
                }
                break;
            }
            return false;
        }

    });

    if (reg == true) {
        if (Locale.getDefault().getLanguage().equals("es")) {

            webview.loadUrl("http://om-msmartwoman.com/member/register");
            // webview.loadUrl("http://live-juice-guru.gotpantheon.com/user/login");
        } else {
            webview.loadUrl("http://om-msmartwoman.com/member/register");
        }

        webview.requestFocus();
    } else {
        uhdj = sp.getString("your_int_key", "0");

        Log.e("Url is here ..............................", uhdj);
        // Welcome page loaded from assets directory
        if (Locale.getDefault().getLanguage().equals("es")) {

            webview.loadUrl(uhdj);
            // webview.loadUrl("http://live-juice-guru.gotpantheon.com/user/login");
        } else {
            webview.loadUrl(uhdj);
        }

        webview.requestFocus();
    }

}

From source file:com.alex.smartwomanmiddleeastfem.WebViewDemoActivity.java

@SuppressLint({ "JavascriptInterface", "SetJavaScriptEnabled" })
@Override/*from   w  w w  .j a  v  a  2 s .c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.mainn);

    Intent intent = getIntent();
    reg = intent.getBooleanExtra("reg", false);

    i = (ImageView) findViewById(R.id.hj);

    try {

        big = new GifAnimationDrawable(getResources().openRawResource(R.raw.anim2));
        // big.setOneShot(true);
        android.util.Log.v("GifAnimationDrawable", "===>Four");
    } catch (IOException ioe) {

    }

    i.setImageDrawable(big);
    big.setVisible(true, true);

    sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
    // historyStack = new LinkedList<Link>();
    webview = (WebView) findViewById(R.id.webkit);

    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);

    webSettings.setDomStorageEnabled(true);
    // webview.addJavascriptInterface(new WebViewDemoActivity(), "Android");
    // webview.getSettings().setJavaScriptEnabled(true);

    webview.getSettings().setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        // webview.getSettings().setPluginState(PluginState.ON);
        // webview.getSettings().setJavaScriptEnabled(true);
    } else {
        // IMPORTANT!! this method is no longer available since Android 4.3
        // so the code doesn't compile anymore
        // webview.getSettings().setPluginsEnabled(true);
    }

    // Internet

    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    connected = false;
    if ((null != connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) && connectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED)
            || (null != connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI) && connectivityManager
                    .getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED)) {
        // we are connected to a network
        connected = true;
    }

    if (connected == false) {
        /*
         * Toast.makeText(Rss.this,
         * "Connect to internet and Restart Application",
         * Toast.LENGTH_SHORT).show();
         */
        webview.setVisibility(View.INVISIBLE);

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(WebViewDemoActivity.this);

        // alertDialogBuilder.setTitle("Please connect to Internet");
        alertDialogBuilder.setMessage(
                "Through our app offers some offline features, in order to stay actively connected to the SmartWoman community in realtime, you need an internet connection, tap here to check your settings or wait until you have connection.");
        // set positive button: Yes message

        alertDialogBuilder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // cancel the alert box and put a Toast to the user

                startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
            }
        });
        AlertDialog alertDialog = alertDialogBuilder.create();
        // show alert
        alertDialog.show();

    }

    // downloads
    // webview.setDownloadListener(new CustomDownloadListener());

    webview.setWebViewClient(new CustomWebViewClient());

    webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {

        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
        }

        @Override
        public void onReceivedIcon(WebView view, Bitmap icon) {

        }

    });

    // http://stackoverflow.com/questions/2083909/android-webview-refusing-user-input
    webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                    v.requestFocus();
                }
                break;
            }
            return false;
        }

    });

    if (reg == true) {
        if (Locale.getDefault().getLanguage().equals("es")) {

            webview.loadUrl("http://www.qa-msmartwoman.com/member/register");
            // webview.loadUrl("http://live-juice-guru.gotpantheon.com/user/login");
        } else {
            webview.loadUrl("http://www.qa-msmartwoman.com/member/register");
        }

        webview.requestFocus();
    } else {
        uhdj = sp.getString("your_int_key", "0");

        //   Log.e("Url is here ..............................", uhdj);
        // Welcome page loaded from assets directory
        if (Locale.getDefault().getLanguage().equals("es")) {

            webview.loadUrl(uhdj);
            // webview.loadUrl("http://live-juice-guru.gotpantheon.com/user/login");
        } else {
            webview.loadUrl(uhdj);
        }

        webview.requestFocus();
    }

}

From source file:br.com.bioscada.apps.biotracks.TrackDetailActivity.java

@Override
public boolean onTrackballEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        if (trackId == recordingTrackId && !recordingTrackPaused) {
            TrackRecordingServiceConnectionUtils.addMarker(this, trackRecordingServiceConnection,
                    WaypointCreationRequest.DEFAULT_WAYPOINT);
            return true;
        }//ww  w.  ja  v a 2  s .  co  m
    }
    return super.onTrackballEvent(event);
}

From source file:com.antew.redditinpictures.library.ui.ImageViewerFragment.java

/**
 * This handles receiving the touch events in the WebView so that we can
 * toggle between fullscreen and windowed mode.
 * <p/>/*ww  w.ja v a2  s.  co m*/
 * The first time the user touches the screen we save the X and Y coordinates.
 * If we receive a {@link MotionEvent#ACTION_DOWN} event we compare the previous
 * X and Y coordinates to the saved coordinates, if they are greater than {@link
 * #MOVE_THRESHOLD}
 * we prevent the toggle from windowed mode to fullscreen mode or vice versa, the idea
 * being that the user is either dragging the image or using pinch-to-zoom.
 * <p/>
 * TODO: Implement handling for double tap to zoom.
 *
 * @return The {@link OnTouchListener} for the {@link WebView} to use.
 */
public OnTouchListener getWebViewOnTouchListener() {
    return new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mCancelClick = false;
                mDownXPos = event.getX();
                mDownYPos = event.getY();
                break;
            case MotionEvent.ACTION_UP:
                if (!mCancelClick) {
                    Intent intent = new Intent(Constants.Broadcast.BROADCAST_TOGGLE_FULLSCREEN);
                    intent.putExtra(Constants.Extra.EXTRA_IS_SYSTEM_UI_VISIBLE,
                            mSystemUiStateProvider.isSystemUiVisible());
                    LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent);
                }
                break;
            case MotionEvent.ACTION_MOVE:
                if (Math.abs(event.getX() - mDownXPos) > MOVE_THRESHOLD
                        || Math.abs(event.getY() - mDownYPos) > MOVE_THRESHOLD) {
                    mCancelClick = true;
                }
                break;
            }

            // Return false so that we still let the WebView consume the event
            return false;
        }
    };
}

From source file:am.widget.tabstrip.TabStripHelper.java

boolean onTouchEvent(MotionEvent event) {
    if (mClickable) {
        final float x = event.getX();
        final float y = event.getY();
        final int action = event.getAction();
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            mClickPosition = PagerAdapter.POSITION_NONE;
            mDownX = x;/* ww  w .  j a  v  a  2s. c o  m*/
            mDownY = y;
            break;
        case MotionEvent.ACTION_UP:
            mClickPosition = PagerAdapter.POSITION_NONE;
            if (mPager != null && getPageCount() > 0) {
                if (mView instanceof TabStripView)
                    mClickPosition = ((TabStripView) mView).getClickedPosition(mDownX, mDownY, x, y);
                else if (mView instanceof TabStripViewGroup)
                    mClickPosition = ((TabStripViewGroup) mView).getClickedPosition(mDownX, mDownY, x, y);
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            mClickPosition = PagerAdapter.POSITION_NONE;
            break;
        }
    }
    if (mDoubleClickable) {
        final float x = event.getX();
        final float y = event.getY();
        final int action = event.getAction();
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            mFirstDownX = mSecondDownX;
            mFirstDownY = mSecondDownY;
            mSecondDownX = x;
            mSecondDownY = y;
            break;
        case MotionEvent.ACTION_UP:
            final long downTime = event.getDownTime();
            if (mLastUpTime != 0 && downTime - mLastUpTime < DOUBLE_TAP_TIMEOUT) {
                mDoubleClicked = true;
                if (mView instanceof TabStripView)
                    mFirstPosition = ((TabStripView) mView).getClickedPosition(mFirstDownX, mFirstDownY,
                            mFirstUpX, mFirstUpY);
                else if (mView instanceof TabStripViewGroup)
                    mFirstPosition = ((TabStripViewGroup) mView).getClickedPosition(mFirstDownX, mFirstDownY,
                            mFirstUpX, mFirstUpY);
                if (mView instanceof TabStripView)
                    mSecondPosition = ((TabStripView) mView).getClickedPosition(mSecondDownX, mSecondDownY, x,
                            y);
                else if (mView instanceof TabStripViewGroup)
                    mSecondPosition = ((TabStripViewGroup) mView).getClickedPosition(mSecondDownX, mSecondDownY,
                            x, y);
                mLastUpTime = 0;
            } else {
                mDoubleClicked = false;
                mFirstPosition = PagerAdapter.POSITION_NONE;
                mSecondPosition = PagerAdapter.POSITION_NONE;
                mFirstUpX = x;
                mFirstUpY = y;
                mLastUpTime = event.getEventTime();
            }
            break;
        case MotionEvent.ACTION_CANCEL:

            break;
        }
    }

    return false;
}

From source file:com.app.gongza.libs.view.scrollablelayout.ScrollableLayout.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    float currentX = ev.getX();
    float currentY = ev.getY();
    float deltaY;
    int shiftX = (int) Math.abs(currentX - mDownX);
    int shiftY = (int) Math.abs(currentY - mDownY);
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mDisallowIntercept = false;/*from   w w  w  .j  av  a 2s . c o  m*/
        needCheckUpdown = true;
        updown = true;
        mDownX = currentX;
        mDownY = currentY;
        mLastY = currentY;
        checkIsClickHead((int) currentY, mHeadHeight, getScrollY());
        checkIsClickHeadExpand((int) currentY, mHeadHeight, getScrollY());
        initOrResetVelocityTracker();
        mVelocityTracker.addMovement(ev);
        mScroller.forceFinished(true);
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDisallowIntercept) {
            break;
        }
        initVelocityTrackerIfNotExists();
        mVelocityTracker.addMovement(ev);
        deltaY = mLastY - currentY;
        if (needCheckUpdown) {
            if (shiftX > mTouchSlop && shiftX > shiftY) {
                needCheckUpdown = false;
                updown = false;
            } else if (shiftY > mTouchSlop && shiftY > shiftX) {
                needCheckUpdown = false;
                updown = true;
            }
        }

        if (updown && shiftY > mTouchSlop && shiftY > shiftX
                && (!isSticked() || mHelper.isTop() || isClickHeadExpand)) {

            if (childViewPager != null) {
                childViewPager.requestDisallowInterceptTouchEvent(true);
            }
            scrollBy(0, (int) (deltaY + 0.5));
        }
        mLastY = currentY;
        break;
    case MotionEvent.ACTION_UP:
        if (updown && shiftY > shiftX && shiftY > mTouchSlop) {
            mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            float yVelocity = -mVelocityTracker.getYVelocity();
            boolean dislowChild = false;
            if (Math.abs(yVelocity) > mMinimumVelocity) {
                mDirection = yVelocity > 0 ? DIRECTION.UP : DIRECTION.DOWN;
                if ((mDirection == DIRECTION.UP && isSticked())
                        || (!isSticked() && getScrollY() == 0 && mDirection == DIRECTION.DOWN)) {
                    dislowChild = true;
                } else {
                    mScroller.fling(0, getScrollY(), 0, (int) yVelocity, 0, 0, -Integer.MAX_VALUE,
                            Integer.MAX_VALUE);
                    mScroller.computeScrollOffset();
                    mLastScrollerY = getScrollY();
                    invalidate();
                }
            }
            if (!dislowChild && (isClickHead || !isSticked())) {
                int action = ev.getAction();
                ev.setAction(MotionEvent.ACTION_CANCEL);
                boolean dispathResult = super.dispatchTouchEvent(ev);
                ev.setAction(action);
                return dispathResult;
            }
        }
        break;
    default:
        break;
    }
    super.dispatchTouchEvent(ev);
    return true;
}

From source file:com.z.stproperty.PropertyDetailFragment.java

/**
 * PHOTOS// www  .  j  a  v a  2 s  . c  om
 * 
 * photos are shown in pager and when the user touches the pager 
 * then scroll stops to scroll vertically
 * 
 * DETAILS
 * 
 * Will show all the details related to the property or directory
 * like type,
 * title,
 * subtype,
 * district etc..
 * 
 * FACILITIES
 * 
 * This method will add the facility details by calling both
 * loadLandDisplay() and loadPortraitDisplay(). It will check weather there
 * is any facility or not and if there is no facility, then noFacilites
 * TextView is made visible. Else, the TextView is made gone and
 * directory_facilities_row layout is inflated and is added to
 * facilityParent.
 * 
 */
private View addProjectDetail() {
    View view = inflater.inflate(R.layout.property_details, null);
    try {
        projectDetailScrollView = (ScrollView) view.findViewById(R.id.DetailsScroll);
        if (detailsJson == null) {
            SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
            detailsJson = new JSONObject(mPrefs.getString("PropertyDetailJson", null));
        } else {
            SharedPreferences mPrefs = PreferenceManager
                    .getDefaultSharedPreferences(getActivity().getApplicationContext());
            mPrefs.edit().putString("PropertyDetailJson", detailsJson.toString()).commit();
        }
        try {
            ((HelveticaBold) view.findViewById(R.id.propertyTitle))
                    .setText(detailsJson.getString("property_title"));
            ((HelveticaBold) view.findViewById(R.id.projectName))
                    .setText(detailsJson.getString("project_name"));
            ((HelveticaBold) view.findViewById(R.id.Classification))
                    .setText(detailsJson.getString("property_classification"));
            ((HelveticaBold) view.findViewById(R.id.Tenure))
                    .setText(detailsJson.getString("tenure").replace("null", "-"));
            ((HelveticaBold) view.findViewById(R.id.propertyType))
                    .setText(detailsJson.getString("property_type"));
        } catch (Exception e) {
            Toast.makeText(getActivity(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
        }
        String floorArea = "-";
        if (!detailsJson.getString("builtin_area").equals("null")) {
            floorArea = detailsJson.getString("builtin_area") + " sqft";
        }
        ((HelveticaBold) view.findViewById(R.id.FloorArea)).setText(floorArea);

        ((HelveticaBold) view.findViewById(R.id.Address)).setText(detailsJson.getString("address"));
        ((HelveticaBold) view.findViewById(R.id.PostalCode))
                .setText(detailsJson.getString("postal_code").replace("null", "-"));
        String bedRoom = detailsJson.getString("bedrooms");
        String bathRoom = detailsJson.getString("bathroom");
        ((HelveticaBold) view.findViewById(R.id.Bedrooms))
                .setText(bedRoom.equals("null") || bedRoom.equals("0") ? "-" : bedRoom);
        ((HelveticaBold) view.findViewById(R.id.Bathrooms))
                .setText(bathRoom.equals("null") || bathRoom.equals("0") ? "-" : bathRoom);
        String psf = detailsJson.getString("psf");
        psf = psf.equals("null") || psf.equals("0") ? "-" : "SGD " + psf;
        ((HelveticaBold) view.findViewById(R.id.Psf)).setText(psf);
        String district = detailsJson.get("property_district").toString();
        String estate = detailsJson.get("property_estate").toString();
        if (!estate.equals("")) {
            district = estate;
        }
        ((HelveticaBold) view.findViewById(R.id.district)).setText(district);
        price = detailsJson.getString("price").replace("null", "");
        price = price.equals("") || price.equalsIgnoreCase("price on ask") ? price
                : "SGD " + SharedFunction.getPriceWithComma(detailsJson.getString("price"));
        view.findViewById(R.id.PSFDetailLayout).setVisibility(psf.equals("-") ? View.GONE : View.VISIBLE);
        if (price.equals("")) {
            ((LinearLayout) view.findViewById(R.id.PriceLayout)).setVisibility(View.GONE);
            ((LinearLayout) view.findViewById(R.id.PSFDetailLayout)).setVisibility(View.GONE);
        } else {
            ((HelveticaBold) view.findViewById(R.id.Price)).setText(price);
        }
        ((HelveticaBold) view.findViewById(R.id.Psf)).setText(psf);
        title = detailsJson.getString("property_title");
        prurl = detailsJson.getString("url");
        JSONObject sellerJson = detailsJson.getJSONObject("seller_info");
        String registerNoStr = sellerJson.getString("agent_cea_reg_no").replace("null", "-");
        String licenceNoStr = sellerJson.getString("agent_cea_license_no").replace("null", "-");
        String agentImageUrl = sellerJson.getString("agent_image");
        agentEmail = sellerJson.getString("agent_email");
        mobileNoStr = sellerJson.getString("agent_mobile");
        ((HelveticaBold) view.findViewById(R.id.AgentName))
                .setText("Agent Name : " + sellerJson.getString("agent_name"));
        ((HelveticaBold) view.findViewById(R.id.AgentMobile)).setText(sellerJson.getString("agent_mobile"));
        ((HelveticaBold) view.findViewById(R.id.RegisterNo)).setText(registerNoStr);
        ((HelveticaBold) view.findViewById(R.id.LicenceNo)).setText(licenceNoStr);
        ((HelveticaBold) view.findViewById(R.id.agentEmail)).setText(sellerJson.getString("agent_email"));
        ((HelveticaBold) view.findViewById(R.id.Agency)).setText(sellerJson.getString("agency_name"));
        imageLoader.displayImage(agentImageUrl, (ImageView) view.findViewById(R.id.AgentImage));

        if (detailsJson.getString("property_for").equalsIgnoreCase("for sale")
                && !price.equalsIgnoreCase("price on ask") && !price.equalsIgnoreCase("")) {
            ((Button) view.findViewById(R.id.LoanCalculator)).setOnClickListener(onClick);
        } else {
            ((Button) view.findViewById(R.id.LoanCalculator))
                    .setBackgroundResource(R.drawable.green_btn_disables);
            ((Button) view.findViewById(R.id.LoanCalculator)).getBackground().setAlpha(128);
        }
        final TextView imageCount = (TextView) view.findViewById(R.id.imageCount);
        view.findViewById(R.id.AgentMobile).setOnClickListener(onClick);
        view.findViewById(R.id.SendEmailBtn).setOnClickListener(onClick);
        view.findViewById(R.id.SendEnquiryBtn).setOnClickListener(onClick);
        ViewPager pager = (ViewPager) view.findViewById(R.id.pager);

        PhotoGallery gallery = new PhotoGallery();
        pager.setAdapter(gallery);
        JSONArray galery = detailsJson.getJSONArray("photos");
        final String[] photosArray = new String[galery.length()];
        imageCount.setText("1/" + photosArray.length);
        for (int index = 0; index < galery.length(); index++) {
            View imageLoading = inflater.inflate(R.layout.image_with_loading, null);
            ImageView image = (ImageView) imageLoading.findViewById(R.id.galleryPhoto);
            photosArray[index] = galery.getString(index).replace("_S.", "_L.");
            imageLoader.displayImage(galery.getString(index).replace("_S.", "_L."), image);
            final int curIndex = index;
            imageLoading.setOnTouchListener(new OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        projectDetailScrollView.requestDisallowInterceptTouchEvent(true);
                    } else if (event.getAction() == MotionEvent.ACTION_UP) {
                        projectDetailScrollView.requestDisallowInterceptTouchEvent(false);
                    }
                    return false;
                }
            });
            imageLoading.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent galleryIntent = new Intent(getActivity(), Photos.class);
                    galleryIntent.putExtra("photos1", photosArray);
                    galleryIntent.putExtra("selected", curIndex);
                    startActivity(galleryIntent);
                }
            });
            gallery.addView(imageLoading);
        }
        pager.setOnPageChangeListener(new OnPageChangeListener() {
            @Override
            public void onPageSelected(int arg0) {
                imageCount.setText((arg0 + 1) + "/" + photosArray.length);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
                // Auto-generated method stub
            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
                // Auto-generated method stub
            }
        });
        gallery.notifyDataSetChanged();
        view.findViewById(R.id.BedBathLayout).setVisibility(
                Arrays.asList(Constants.RESIDENTIAL_TYPE).contains(detailsJson.getString("property_type"))
                        ? View.VISIBLE
                        : View.GONE);
    } catch (Exception e) {
        Log.e(this.getClass().getSimpleName(), e.getLocalizedMessage(), e);
    }
    return view;
}