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:com.baidu.android.voicedemo.ActivityTouch.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sdk2_api);//  w w  w  . j a va 2 s. co m
    txtResult = (TextView) findViewById(R.id.txtResult);
    txtLog = (TextView) findViewById(R.id.txtLog);
    btn = (Button) findViewById(R.id.btn);
    setting = (Button) findViewById(R.id.setting);
    setting.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent("com.baidu.speech.asr.demo.setting");
            startActivity(intent);
        }
    });
    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this,
            new ComponentName(this, VoiceRecognitionService.class));
    speechRecognizer.setRecognitionListener(this);

    speechTips = View.inflate(this, R.layout.bd_asr_popup_speech, null);
    speechWave = speechTips.findViewById(R.id.wave);
    speechTips.setVisibility(View.GONE);
    addContentView(speechTips, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    btn.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                speechTips.setVisibility(View.VISIBLE);
                speechRecognizer.cancel();
                Intent intent = new Intent();
                bindParams(intent);
                intent.putExtra("vad", "touch");
                txtResult.setText("");
                txtLog.setText("");
                speechRecognizer.startListening(intent);
                return true;
            case MotionEvent.ACTION_UP:
                speechRecognizer.stopListening();
                speechTips.setVisibility(View.GONE);
                break;
            }
            return false;
        }
    });
}

From source file:android.hawkencompanionapp.fragments.MechGuideFragment.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    final float xPos = event.getX();

    if (xPos > mSwipeXPxOffset) { //Prevent the nav drawer from registering the event
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            mPrevXdp = xPos;/*w w  w.  jav  a  2  s. c  om*/
        } else if (event.getAction() == MotionEvent.ACTION_UP) {
            if (mPrevXdp < xPos) { //Right swipe
                switchTab("Right");
            } else { //Left swipe
                switchTab("Left");
            }
        }
        return true;
    }
    return false;
}

From source file:com.aashreys.walls.application.adapters.CollectionsAdapter.java

@Override
public void onBindViewHolder(final CollectionViewHolder holder, int position) {
    holder.bind(adapterModel.getCollection(position), new View.OnTouchListener() {
        @Override/*from w  ww.j ava 2s .  c  o  m*/
        public boolean onTouch(View v, MotionEvent event) {
            if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                onDragStarted(holder);
            }
            return true;
        }
    }, onCollectionClickListener);
}

From source file:app.webelement.com.employeetracker.rd.RecyclerListAdapter.java

@Override
public void onBindViewHolder(final ItemViewHolder holder, int position) {
    holder.textView.setText(mItems.get(position));

    // Start a drag whenever the handle view it touched
    holder.handleView.setOnTouchListener(new View.OnTouchListener() {
        @Override//  w w w.  j a  v  a  2  s  .c  om
        public boolean onTouch(View v, MotionEvent event) {
            if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                mDragStartListener.onStartDrag(holder);
            }
            return false;
        }
    });
}

From source file:de.madvertise.android.sdk.MadvertiseImageView.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        mImageAd.handleClick();/*  w  w  w.  ja  va2s .  co  m*/
        return true;
    }
    return super.dispatchTouchEvent(event);
}

From source file:ca.uqac.florentinth.speakerauthentication.CreateActivity.java

private void initGUI() {
    view = findViewById(R.id.create_layout);
    usernameInput = (EditText) findViewById(R.id.username_input);
    passwordInput = (EditText) findViewById(R.id.password_input);
    visibilityImage = (ImageView) findViewById(R.id.visibility);
    femaleRadio = (RadioButton) findViewById(R.id.radio_female);
    maleRadio = (RadioButton) findViewById(R.id.radio_male);
    createBtn = (Button) findViewById(R.id.btn_create);

    usernameInput.setText("user" + StringUtils.getCurrentDateTime());

    visibilityImage.setOnTouchListener(new View.OnTouchListener() {
        @Override/*  w w  w .ja va 2s .c  om*/
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                passwordInput.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
            } else {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    passwordInput
                            .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }
            }
            return true;
        }
    });

    createBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            submit();
        }
    });
}

From source file:com.android.cts.uiautomator.Test5DetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    View rootView = inflater.inflate(R.layout.test5_detail_fragment, container, false);

    // Set the content description for the following
    Spinner spinner = (Spinner) rootView.findViewById(R.id.test_5_spinner);
    spinner.setContentDescription("Spinner");
    ImageButton imageButton = (ImageButton) rootView.findViewById(R.id.test_5_imageButton);
    imageButton.setContentDescription("Image button");

    // Each time this view is displayed, reset the following states
    SeekBar seekBar = (SeekBar) rootView.findViewById(R.id.test_5_seekBar);
    seekBar.setProgress(50);//w w w .  j a  v a  2 s  . c o m
    seekBar.setContentDescription("Progress is 50 %");
    CheckBox checkbox = (CheckBox) rootView.findViewById(R.id.test_5_checkBox);
    checkbox.setChecked(false);

    // Register click event handlers for the following
    Button button = (Button) rootView.findViewById(R.id.test_5_button1);
    button.setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            // we want an artificial crash
            throw new RuntimeException("Artificial crash to test UiWatcher");
        }
    });

    imageButton.setOnTouchListener(new ImageButton.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                resetTouchResults();
                collectStartAction(event, v);
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                collectEndAction(event, v);
                displayTouchResults();
            }
            return false;
        }
    });

    return rootView;
}

From source file:com.android.deskclock.VerticalViewPager.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    try {//  w w w.j av  a 2 s  .c om
        initializeParent();
        final float x = ev.getX();
        final float y = ev.getY();
        switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN: {
            mLastMotionX = x;
            mLastMotionY = y;
            if (!mParentViewPager.onTouchEvent(ev))
                return false;
            return verticalDrag(ev);
        }
        case MotionEvent.ACTION_MOVE: {
            final float xDiff = Math.abs(x - mLastMotionX);
            final float yDiff = Math.abs(y - mLastMotionY);
            if (!mHorizontalDrag && !mVerticalDrag) {
                if (xDiff > mTouchSlop && xDiff > yDiff) { // Swiping left and right
                    mHorizontalDrag = true;
                } else if (yDiff > mTouchSlop && yDiff > xDiff) { //Swiping up and down
                    mVerticalDrag = true;
                }
            }
            if (mHorizontalDrag) {
                return mParentViewPager.onTouchEvent(ev);
            } else if (mVerticalDrag) {
                return verticalDrag(ev);
            }
        }
        case MotionEvent.ACTION_UP: {
            if (mHorizontalDrag) {
                mHorizontalDrag = false;
                return mParentViewPager.onTouchEvent(ev);
            }
            if (mVerticalDrag) {
                mVerticalDrag = false;
                return verticalDrag(ev);
            }
        }
        }
        // Set both flags to false in case user lifted finger in the parent view pager
        mHorizontalDrag = false;
        mVerticalDrag = false;
    } catch (Exception e) {
        // The mParentViewPager shouldn't be null, but just in case. If this happens,
        // app should not crash, instead just ignore the user swipe input
        // TODO: handle the exception gracefully
    }
    return false;
}

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

@Override
public boolean onTouchEvent(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 w w .  j a  v a2  s  .com
            //launchFullPhotoActivity(imageUrls);// WE HAVE A CLICK!!
        } else {
            super.onTouchEvent(event);
        }
    }

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

    /*if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP)
    {
    super.onTouchEvent(event);
    }*/

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        return super.onTouchEvent(event);
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onTouchEvent(event);
        }
    }

    return false;
}

From source file:cn.nekocode.camerafilter.MainActivity.java

void setupCameraPreviewView() {
    renderer = new CameraRenderer(this);
    textureView = (TextureView) findViewById(R.id.textureView);
    assert textureView != null;
    textureView.setSurfaceTextureListener(renderer);

    // Show original frame when touch the view
    textureView.setOnTouchListener(new View.OnTouchListener() {
        @Override// w w  w.  j a  v  a2  s  .c  om
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                renderer.setSelectedFilter(R.id.filter0);
                break;

            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                renderer.setSelectedFilter(filterId);
                break;
            }
            return true;
        }
    });

    textureView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            renderer.onSurfaceTextureSizeChanged(null, v.getWidth(), v.getHeight());
        }
    });
}