Example usage for android.view MotionEvent ACTION_DOWN

List of usage examples for android.view MotionEvent ACTION_DOWN

Introduction

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

Prototype

int ACTION_DOWN

To view the source code for android.view MotionEvent ACTION_DOWN.

Click Source Link

Document

Constant for #getActionMasked : A pressed gesture has started, the motion contains the initial starting location.

Usage

From source file:co.taqat.call.CallIncomingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getResources().getBoolean(R.bool.orientation_portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }//from w  w w. ja  v a2s.c o m

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.call_incoming);

    name = (TextView) findViewById(R.id.contact_name);
    number = (TextView) findViewById(R.id.contact_number);
    contactPicture = (ImageView) findViewById(R.id.contact_picture);

    // set this flag so this activity will stay in front of the keyguard
    int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
    getWindow().addFlags(flags);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

    final int screenWidth = getResources().getDisplayMetrics().widthPixels;

    acceptUnlock = (LinearLayout) findViewById(R.id.acceptUnlock);
    declineUnlock = (LinearLayout) findViewById(R.id.declineUnlock);

    accept = (ImageView) findViewById(R.id.accept);
    decline = (ImageView) findViewById(R.id.decline);
    accept.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            decline.setVisibility(View.GONE);
            acceptUnlock.setVisibility(View.VISIBLE);

        }
    });

    accept.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            float curX;
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
                acceptUnlock.setVisibility(View.VISIBLE);
                decline.setVisibility(View.GONE);
                answerX = motionEvent.getX();
                break;
            case MotionEvent.ACTION_MOVE:
                curX = motionEvent.getX();
                if ((answerX - curX) >= 0)
                    view.scrollBy((int) (answerX - curX), view.getScrollY());
                answerX = curX;
                if (curX < screenWidth / 4) {
                    answer();
                    return true;
                }
                break;
            case MotionEvent.ACTION_UP:
                view.scrollTo(0, view.getScrollY());
                decline.setVisibility(View.VISIBLE);
                acceptUnlock.setVisibility(View.GONE);
                break;
            }
            return true;
        }
    });

    decline.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            float curX;
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
                declineUnlock.setVisibility(View.VISIBLE);
                accept.setVisibility(View.GONE);
                declineX = motionEvent.getX();
                break;
            case MotionEvent.ACTION_MOVE:
                curX = motionEvent.getX();
                view.scrollBy((int) (declineX - curX), view.getScrollY());
                declineX = curX;
                Log.w(curX);
                if (curX > (screenWidth / 2)) {
                    decline();
                    return true;
                }
                break;
            case MotionEvent.ACTION_UP:
                view.scrollTo(0, view.getScrollY());
                accept.setVisibility(View.VISIBLE);
                declineUnlock.setVisibility(View.GONE);
                break;

            }
            return true;
        }
    });

    decline.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            accept.setVisibility(View.GONE);
            acceptUnlock.setVisibility(View.VISIBLE);
        }
    });

    mListener = new LinphoneCoreListenerBase() {
        @Override
        public void callState(LinphoneCore lc, LinphoneCall call, State state, String message) {
            if (call == mCall && State.CallEnd == state) {
                finish();
            }
            if (state == State.StreamsRunning) {
                // The following should not be needed except some devices need it (e.g. Galaxy S).
                LinphoneManager.getLc().enableSpeaker(LinphoneManager.getLc().isSpeakerEnabled());
            }
        }
    };

    super.onCreate(savedInstanceState);
    instance = this;
}

From source file:com.mimo.service.api.MimoOauth2Client.java

/**
 * Instantiate a webview and allows the user to login to the Api form within
 * the application/* w ww .j  a  v  a  2s .c o m*/
 * 
 * @param p_view
 *            : Calling view
 * 
 * @param p_activity
 *            : Calling Activity reference
 **/

@SuppressLint("SetJavaScriptEnabled")
public void login(View p_view, Activity p_activity) {

    final Activity m_activity;
    m_activity = p_activity;
    String m_url = this.m_api.getAuthUrl();
    WebView m_webview = new WebView(p_view.getContext());
    m_webview.getSettings().setJavaScriptEnabled(true);
    m_webview.setVisibility(View.VISIBLE);
    m_activity.setContentView(m_webview);

    m_webview.requestFocus(View.FOCUS_DOWN);
    /**
     * Open the softkeyboard of the device to input the text in form which
     * loads in webview.
     */
    m_webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View p_v, MotionEvent p_event) {
            switch (p_event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!p_v.hasFocus()) {
                    p_v.requestFocus();
                }
                break;
            }
            return false;
        }
    });

    /**
     * Show the progressbar in the title of the activity untill the page
     * loads the give url.
     */
    m_webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView p_view, int p_newProgress) {
            ((Activity) m_context).setProgress(p_newProgress * 100);
            ((Activity) m_context).setTitle(MimoAPIConstants.DIALOG_TEXT_LOADING);

            if (p_newProgress == 100)
                ((Activity) m_context).setTitle(m_context.getString(R.string.app_name));
        }
    });

    m_webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView p_view, String p_url, Bitmap p_favicon) {
        }

        @Override
        public void onReceivedHttpAuthRequest(WebView p_view, HttpAuthHandler p_handler, String p_url,
                String p_realm) {
            p_handler.proceed(MimoAPIConstants.USERNAME, MimoAPIConstants.PASSWORD);
        }

        public void onPageFinished(WebView p_view, String p_url) {
            if (MimoAPIConstants.DEBUG) {
                Log.d(TAG, "Page Url = " + p_url);
            }
            if (p_url.contains("?code=")) {
                if (p_url.indexOf("code=") != -1) {
                    String[] m_urlSplit = p_url.split("=");

                    String m_tempString1 = m_urlSplit[1];
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "TempString1 = " + m_tempString1);
                    }
                    String[] m_urlSplit1 = m_tempString1.split("&");

                    String m_code = m_urlSplit1[0];
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "code = " + m_code);
                    }
                    MimoOauth2Client.this.m_code = m_code;
                    Thread m_thread = new Thread() {
                        public void run() {
                            String m_token = requesttoken(MimoOauth2Client.this.m_code);

                            Log.d(TAG, "Token = " + m_token);

                            Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class);

                            m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token);

                            m_activity.startActivity(m_navigateIntent);
                        }
                    };
                    m_thread.start();
                } else {
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "going in else");
                    }
                }
            } else if (p_url.contains(MimoAPIConstants.URL_KEY_TOKEN)) {
                if (p_url.indexOf(MimoAPIConstants.URL_KEY_TOKEN) != -1) {
                    String[] m_urlSplit = p_url.split("=");
                    final String m_token = m_urlSplit[1];

                    Thread m_thread = new Thread() {
                        public void run() {
                            Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class);
                            m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token);
                            m_activity.startActivity(m_navigateIntent);
                        }
                    };
                    m_thread.start();
                }
            }
        };
    });

    m_webview.loadUrl(m_url);
}

From source file:am.widget.scalerecyclerview.ScaleRecyclerView.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (!mScaleEnable)
        return super.dispatchTouchEvent(ev);
    final int action = ev.getAction();
    if (action == MotionEvent.ACTION_DOWN) {
        mScaleHelper.stop();// ww  w  . j av a  2s. c o  m
        mShouldReactDoubleTab = true;
        mShouldReactSingleTab = true;
    }
    final boolean superResult = super.dispatchTouchEvent(ev);
    if (!mInterceptTouch) {
        // ??
        // ?????????
        mGestureDetector.onTouchEvent(ev);
    }
    return superResult;
}

From source file:co.dift.ui.SwipeToAction.java

/** Private methods **/
private void init() {
    gestureDetector = new GestureDetectorCompat(recyclerView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {
                @Override//  w  ww  .  j  av a 2s .  co m
                public void onLongPress(MotionEvent e) {
                    logger.d("onLongPress called!");
                    if (touchedViewHolder != null) {
                        swipeListener.onLongClick(touchedViewHolder.getItemData());
                    }
                }

                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    logger.d("onSingleTapUp called!");
                    if (touchedViewHolder != null) {
                        swipeListener.onClick(touchedViewHolder.getItemData());
                        return true;
                    }
                    return super.onSingleTapUp(e);
                }
            });

    recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {

        @Override
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent ev) {
            gestureDetector.onTouchEvent(ev);

            switch (ev.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN: {
                // starting point
                downX = ev.getX();
                downY = ev.getY();

                downTime = new Date().getTime();

                // which item are we touching
                resolveItem(downX, downY);

                break;
            }

            case MotionEvent.ACTION_UP: {
                upX = ev.getX();
                upY = ev.getY();
                upTime = new Date().getTime();

                resolveState();
                break;
            }

            case MotionEvent.ACTION_MOVE: {
                final float x = ev.getX();
                final float dx = x - downX;

                if (!shouldMove(dx))
                    break;

                // current position. moving only over x-axis
                frontViewLastX = frontViewX + dx + (dx > 0 ? -getRevealThreshold() : getRevealThreshold());
                //                        logger.d("dx: %f, frontViewLastX: %f", dx, frontViewLastX);
                if (maxSwipeXPosition != null) {
                    if (frontViewLastX > 0 && frontViewLastX > maxSwipeXPosition) {
                        frontViewLastX = maxSwipeXPosition;
                    } else if (frontViewLastX <= -maxSwipeXPosition) {
                        frontViewLastX = -maxSwipeXPosition;
                    }
                }
                frontView.setX(frontViewLastX);

                if (frontViewLastX > 0) {
                    revealRight();
                } else {
                    revealLeft();
                }

                break;
            }

            case MotionEvent.ACTION_CANCEL: {
                resolveState();

                break;
            }
            }

            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView rv, MotionEvent e) {
            logger.d("onTouchEvent called");
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
            logger.d("onRequestDisallowInterceptTouchEvent called");
        }
    });
}

From source file:cn.goodjobs.common.view.photodraweeview.ScaleDragDetector.java

private void onTouchDragEvent(int action, MotionEvent ev) {
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mVelocityTracker = VelocityTracker.obtain();
        if (null != mVelocityTracker) {
            mVelocityTracker.addMovement(ev);
        }//w ww  .j a  va 2s  .c om

        mLastTouchX = getActiveX(ev);
        mLastTouchY = getActiveY(ev);
        mIsDragging = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final float x = getActiveX(ev);
        final float y = getActiveY(ev);
        final float dx = x - mLastTouchX, dy = y - mLastTouchY;

        if (!mIsDragging) {
            mIsDragging = Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop;
        }

        if (mIsDragging) {
            mScaleDragGestureListener.onDrag(dx, dy);
            mLastTouchX = x;
            mLastTouchY = y;

            if (null != mVelocityTracker) {
                mVelocityTracker.addMovement(ev);
            }
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL: {
        if (null != mVelocityTracker) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }

    case MotionEvent.ACTION_UP: {
        if (mIsDragging) {
            if (null != mVelocityTracker) {
                mLastTouchX = getActiveX(ev);
                mLastTouchY = getActiveY(ev);

                mVelocityTracker.addMovement(ev);
                mVelocityTracker.computeCurrentVelocity(1000);

                final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker.getYVelocity();

                if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) {
                    mScaleDragGestureListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY);
                }
            }
        }
        if (null != mVelocityTracker) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }
}

From source file:cn.dreamtobe.touchgallery.GalleryWidget.GalleryViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        //super.onInterceptTouchEvent(event);

        float endX = event.getX();
        float endY = event.getY();
        if (isAClick(startX, endX, startY, endY)) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem());
            }// w ww  .j  av  a2 s  .c  o m
        } else {
            super.onInterceptTouchEvent(event);
        }
    }

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        startX = event.getX();
        startY = event.getY();
    }

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        return super.onInterceptTouchEvent(event);
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onInterceptTouchEvent(event);
        }
    }
    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;
    }/*from  ww  w .j a  v  a 2 s . com*/
    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.tony.casthelloworld.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));

    //Current Card Text
    currentCard = (TextView) findViewById(R.id.currentCard);

    //Remaining Cards Text
    remainingCards = (TextView) findViewById(R.id.cardsRemaining);

    //Start/Reset Game Button
    startGame = (Button) findViewById(R.id.startGame);
    startGame.setOnClickListener(new View.OnClickListener() {
        @Override// w w w  .  j a v  a2s  .  c o  m
        public void onClick(View v) {
            initializeGame();
            updateCast();
        }
    });

    //Next Card Button
    nextCard = (Button) findViewById(R.id.nextCard);
    nextCard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //pop the card off
            //Update the current card
            getNextCard();
            updateCast();
        }
    });

    //Show Card Button
    showCard = (Button) findViewById(R.id.showCard);
    showCard.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                //Make the card visible
                if (deck.peek() != null) {
                    currentCard.setText(prettyPrintCard(deck.peek()));
                } else {
                    currentCard.setText("No more Cards!");
                }
                return true;
            case MotionEvent.ACTION_UP:
                // No longer down
                if (deck.peek() != null) {
                    currentCard.setText(CARD_HIDDEN_TEXT);
                } else {
                    currentCard.setText("No more Cards!");
                }
                return true;
            }
            return false;
        }
    });

    // Configure Cast device discovery
    mMediaRouter = MediaRouter.getInstance(getApplicationContext());
    mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
            CastMediaControlIntent.categoryForCast(getResources().getString(R.string.app_id))).build();
    mMediaRouterCallback = new MyMediaRouterCallback();
}

From source file:com.echlabsw.android.drawertab.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "onCreate");

    setContentView(R.layout.activity_main);

    createStubTab();/*from   w  ww .j a  va 2  s. c om*/

    mActionBar = getActionBar();

    mHorizontalTabScrollView = (HorizontalScrollView) findViewById(R.id.hscroll_tab_host);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerListView = (ListView) findViewById(R.id.left_drawer);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    mActionBar.setHomeButtonEnabled(true);
    mActionBar.setDisplayHomeAsUpEnabled(true);

    mDrawerToggle = createDrawerToggleListener();

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();

    for (String tag : mTabMap.keySet()) {
        Tab tab = mTabMap.get(tag);
        TabHost.TabSpec spec = mTabHost.newTabSpec(tag);
        spec.setContent(this);
        spec.setIndicator(tab.title);
        mTabHost.addTab(spec);
    }

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager(), mTabMap.size());
    mViewPager.setAdapter(mAdapter);

    mTabHost.setOnTabChangedListener(this);
    mViewPager.setOnPageChangeListener(this);

    if (!TAB_SCROLL_ENABLED) {
        mHorizontalTabScrollView.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    break;
                case MotionEvent.ACTION_UP:
                    v.performClick();
                    break;
                }
                return true;
            }
        });
    }

    mArrayNavigationDrawerAdapter = new ArrayAdapter<Tab>(this, android.R.layout.simple_list_item_1,
            mTabMap.values().toArray(new Tab[0]));
    mDrawerListView.setAdapter(mArrayNavigationDrawerAdapter);
    mDrawerListView.setOnItemClickListener(this);

    /* Create AsyncTaskLoader */
    getSupportLoaderManager().initLoader(0, null, this);
}

From source file:cn.ieclipse.af.view.AutoPlayView.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_SCROLL:
        stop();//w  ww.  j  av a2  s.c  o  m
        break;
    case MotionEvent.ACTION_UP:
        start();
        break;
    }
    return false;
}