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.librelio.activity.StartupActivity.java

private void setOnAdvertisingImageClickListener(final String link) {
    if (advertisingImage != null) {
        advertisingImage.setOnTouchListener(new OnTouchListener() {
            //            @Override
            //            public void onClick(View v) {
            //               advertisingClickPerformed = true;
            ///*  www.jav  a 2s.c  o  m*/
            //               startAdsActivity(link);
            //            }

            @Override
            public boolean onTouch(View pView, MotionEvent pEvent) {
                if (pEvent.getAction() == MotionEvent.ACTION_DOWN) {
                    // check the Y coordinates of the touch event
                    float pY = pEvent.getY();
                    int pHeight = pView.getHeight();
                    if (Math.round(pY / 0.2) <= pHeight) {
                        // Skip ads
                        if (mStartupAdsTimer != null)
                            mStartupAdsTimer.cancel();
                        startMainMagazineActivity();
                    } else {
                        // Show ads
                        if (mStartupAdsTimer != null)
                            mStartupAdsTimer.cancel();
                        startAdsActivity(link);
                    }
                }
                return false;
            }
        });
    }
}

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();/*from  ww w .  j  a  va 2  s .  c om*/
        break;
    case MotionEvent.ACTION_UP:
        start();
        break;
    }
    return false;
}

From source file:com.app.blockydemo.content.bricks.SetVariableBrick.java

@Override
public View getView(final Context context, int brickId, BaseAdapter baseAdapter) {
    if (animationState) {
        return view;
    }/*from w w  w  . ja  va  2s . com*/
    if (view == null) {
        alphaValue = 255;
    }

    view = View.inflate(context, R.layout.brick_set_variable, null);
    view = getViewWithAlpha(alphaValue);
    setCheckboxView(R.id.brick_set_variable_checkbox);

    final Brick brickInstance = this;
    checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            checked = isChecked;
            adapter.handleCheck(brickInstance, isChecked);
        }
    });

    TextView prototypeText = (TextView) view.findViewById(R.id.brick_set_variable_prototype_view);
    TextView textField = (TextView) view.findViewById(R.id.brick_set_variable_edit_text);
    prototypeText.setVisibility(View.GONE);
    variableFormula.setTextFieldId(R.id.brick_set_variable_edit_text);
    variableFormula.refreshTextField(view);
    textField.setVisibility(View.VISIBLE);
    textField.setOnClickListener(this);

    Spinner variableSpinner = (Spinner) view.findViewById(R.id.set_variable_spinner);
    UserVariableAdapter userVariableAdapter = ProjectManager.getInstance().getCurrentProject()
            .getUserVariables().createUserVariableAdapter(context, sprite);
    UserVariableAdapterWrapper userVariableAdapterWrapper = new UserVariableAdapterWrapper(context,
            userVariableAdapter);
    userVariableAdapterWrapper.setItemLayout(android.R.layout.simple_spinner_item, android.R.id.text1);

    variableSpinner.setAdapter(userVariableAdapterWrapper);

    if (!(checkbox.getVisibility() == View.VISIBLE)) {
        variableSpinner.setClickable(true);
        variableSpinner.setEnabled(true);
    } else {
        variableSpinner.setClickable(false);
        variableSpinner.setFocusable(false);
    }

    setSpinnerSelection(variableSpinner, null);

    variableSpinner.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (((Spinner) view).getSelectedItemPosition() == 0
                        && ((Spinner) view).getAdapter().getCount() == 1) {
                    NewVariableDialog dialog = new NewVariableDialog((Spinner) view);
                    dialog.addVariableDialogListener(SetVariableBrick.this);
                    dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                            NewVariableDialog.DIALOG_FRAGMENT_TAG);
                    return true;
                }
            }
            return false;
        }
    });
    variableSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0 && ((UserVariableAdapterWrapper) parent.getAdapter()).isTouchInDropDownView()) {
                NewVariableDialog dialog = new NewVariableDialog((Spinner) parent);
                dialog.addVariableDialogListener(SetVariableBrick.this);
                dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                        NewVariableDialog.DIALOG_FRAGMENT_TAG);
            }
            ((UserVariableAdapterWrapper) parent.getAdapter()).resetIsTouchInDropDownView();
            userVariable = (UserVariable) parent.getItemAtPosition(position);
            adapterView = parent;
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            userVariable = null;
        }
    });

    return view;
}

From source file:com.app.blockydemo.content.bricks.ChangeVariableBrick.java

@Override
public View getView(final Context context, int brickId, BaseAdapter baseAdapter) {
    if (animationState) {
        return view;
    }/*www . ja  v  a2s .c  om*/

    view = View.inflate(context, R.layout.brick_change_variable_by, null);
    view = getViewWithAlpha(alphaValue);
    setCheckboxView(R.id.brick_change_variable_checkbox);
    final Brick brickInstance = this;

    checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            checked = isChecked;
            adapter.handleCheck(brickInstance, isChecked);
        }
    });

    TextView prototypeText = (TextView) view.findViewById(R.id.brick_change_variable_prototype_view);
    TextView textField = (TextView) view.findViewById(R.id.brick_change_variable_edit_text);
    prototypeText.setVisibility(View.GONE);
    variableFormula.setTextFieldId(R.id.brick_change_variable_edit_text);
    variableFormula.refreshTextField(view);
    textField.setVisibility(View.VISIBLE);
    textField.setOnClickListener(this);

    Spinner variableSpinner = (Spinner) view.findViewById(R.id.change_variable_spinner);
    UserVariableAdapter userVariableAdapter = ProjectManager.getInstance().getCurrentProject()
            .getUserVariables().createUserVariableAdapter(context, sprite);
    UserVariableAdapterWrapper userVariableAdapterWrapper = new UserVariableAdapterWrapper(context,
            userVariableAdapter);
    userVariableAdapterWrapper.setItemLayout(android.R.layout.simple_spinner_item, android.R.id.text1);

    variableSpinner.setAdapter(userVariableAdapterWrapper);

    if (!(checkbox.getVisibility() == View.VISIBLE)) {
        variableSpinner.setClickable(true);
        variableSpinner.setEnabled(true);
    } else {
        variableSpinner.setClickable(false);
        variableSpinner.setFocusable(false);
    }

    setSpinnerSelection(variableSpinner, null);

    variableSpinner.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (((Spinner) view).getSelectedItemPosition() == 0
                        && ((Spinner) view).getAdapter().getCount() == 1) {
                    NewVariableDialog dialog = new NewVariableDialog((Spinner) view);
                    dialog.addVariableDialogListener(ChangeVariableBrick.this);
                    dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                            NewVariableDialog.DIALOG_FRAGMENT_TAG);
                    return true;
                }
            }
            return false;
        }
    });

    variableSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0 && ((UserVariableAdapterWrapper) parent.getAdapter()).isTouchInDropDownView()) {
                NewVariableDialog dialog = new NewVariableDialog((Spinner) parent);
                dialog.addVariableDialogListener(ChangeVariableBrick.this);
                dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                        NewVariableDialog.DIALOG_FRAGMENT_TAG);
            }
            ((UserVariableAdapterWrapper) parent.getAdapter()).resetIsTouchInDropDownView();
            userVariable = (UserVariable) parent.getItemAtPosition(position);
            adapterView = parent;
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            userVariable = null;
        }
    });

    return view;
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingPageView.java

/**
 * View./*w ww.ja  v  a 2s  .co m*/
 *
 * @param view the view
 */
public void addContentView(View view) {
    addView(view, 0, getLayoutParams());
    view.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                showPrevious();
            }

        }
    });

    view.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (MotionEvent.ACTION_DOWN == event.getAction()) {
                showPrevious();
            }
            return false;
        }
    });
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingPageView.java

/**
 * View./*from ww  w .j a va 2s .co m*/
 *
 * @param view the view
 */
public void addNextView(View view) {
    addView(view, 1, getLayoutParams());
    view.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                showNext();
            }

        }
    });

    view.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (MotionEvent.ACTION_DOWN == event.getAction()) {
                showNext();
            }
            return false;
        }
    });
}

From source file:de.struckmeierfliesen.ds.wochenbericht.ClearableAutoCompleteTextView.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (getCompoundDrawables()[2] != null) {
        boolean tappedX = event.getX() > (getWidth() - getPaddingRight()
                - (int) (xD.getIntrinsicWidth() * DRAWABLE_MULTIPLIER));
        if (tappedX) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                setText("");
                if (textClearListener != null) {
                    textClearListener.didClearText();
                }//from  w w w.  j  av  a 2s. c  o  m
            }
            return true;
        }
    }
    if (l != null) {
        return l.onTouch(v, event);
    }
    return false;
}

From source file:co.paulburke.android.textviewpager.TextViewPagerIndicator.java

public void setViewPager(ViewPager viewPager) {
    if (mViewPager == viewPager) {
        return;/*  w ww  . j a  v  a  2s  .c  om*/
    }
    if (mViewPager != null) {
        // Clear us from the old pager.
        mViewPager.setOnPageChangeListener(null);
    }
    if (viewPager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = (DirectionalViewPager) viewPager;
    mViewPager.setOnPageChangeListener(this);
    mViewPager.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                show();
            }
            return false;
        }
    });
    invalidate();
    post(new Runnable() {
        @Override
        public void run() {
            if (mFades) {
                post(mFadeRunnable);
            }
        }
    });
}

From source file:com.alex.vmandroid.display.main.fragments.fragments.LoopAdvertisementFragment.java

@Override
public void setViewPagerData(List<Integer> pictureList) {
    LoopAdvertisementAdapter mBannerPagerAdapter = new LoopAdvertisementAdapter(getActivity(), pictureList);

    mViewPager.setAdapter(mBannerPagerAdapter);

    mViewPager.setOnTouchListener(new View.OnTouchListener() {
        int flage = 0;

        @Override/*from   w ww  .  jav  a  2 s . c om*/
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                flage = 0;
                mIsUserTouched = true;
                break;
            case MotionEvent.ACTION_MOVE:
                mIsUserTouched = true;
                flage = 1;
                break;
            case MotionEvent.ACTION_UP:
                mIsUserTouched = false;
                if (flage == 0) {
                    int item = mViewPager.getCurrentItem();
                    mPresenter.onViewPagerItemClick(item);
                }
                break;
            }
            return false;
        }
    });

    startBannerTimer();
}

From source file:agricultural.nxt.agriculturalsupervision.Activity.company.CompanyActivity.java

@Override
public void onTouch(MotionEvent motionEvent) {
    int action = motionEvent.getAction();
    switch (action) {
    case MotionEvent.ACTION_UP:
        sl.requestDisallowInterceptTouchEvent(false);
        break;/*  w ww. j a  v  a2 s.  c o  m*/
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_MOVE:
        sl.requestDisallowInterceptTouchEvent(true);
        break;
    }
}