Example usage for android.view MotionEvent getActionMasked

List of usage examples for android.view MotionEvent getActionMasked

Introduction

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

Prototype

public final int getActionMasked() 

Source Link

Document

Return the masked action being performed, without pointer index information.

Usage

From source file:com.adguard.android.commons.BrowserUtils.java

public static void showBrowserInstallDialog(final Context context) {
    // Touch listener for changing colors of CardViews
    View.OnTouchListener touchListener = new View.OnTouchListener() {
        @Override/* www. ja  v a  2 s  .  c  o  m*/
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getActionMasked();
            if (action == MotionEvent.ACTION_DOWN) {
                ((CardView) v).setCardBackgroundColor(R.color.card_view_background_pressed);
            } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
                    || action == MotionEvent.ACTION_OUTSIDE) {
                ((CardView) v).setCardBackgroundColor(R.color.white);
            }
            return false;
        }
    };

    final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View dialogLayout = inflater.inflate(R.layout.select_browser_dialog, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AlertDialog);
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.setView(dialogLayout);
    final AlertDialog dialog = builder.create();

    View cardView = dialogLayout.findViewById(R.id.browser_yandex);
    cardView.setOnTouchListener(touchListener);
    cardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ActivityUtils.startMarket(context, YANDEX_BROWSER_PACKAGE, REFERRER);
            dialog.dismiss();
        }
    });

    cardView = dialogLayout.findViewById(R.id.browser_samsung);
    cardView.setOnTouchListener(touchListener);
    cardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ActivityUtils.startMarket(context, SAMSUNG_BROWSER_PACKAGE, null);
            dialog.dismiss();
        }
    });

    dialog.show();
}

From source file:com.google.fpl.voltair.VoltAirActivity.java

private static boolean isGamepadEvent(MotionEvent event) {
    return (isFromSource(event, InputDevice.SOURCE_JOYSTICK) || isFromSource(event, InputDevice.SOURCE_GAMEPAD))
            && event.getActionMasked() == MotionEvent.ACTION_MOVE;
}

From source file:com.noprom.Material_Shadows.ElevationBasicFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.elevation_basic, container, false);

    View shape2 = rootView.findViewById(R.id.floating_shape_2);

    /**/*from w ww  .  j av a 2  s  . co  m*/
     * Sets a {@Link View.OnTouchListener} that responds to a touch event on shape2.
     */
    shape2.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            int action = motionEvent.getActionMasked();
            /* Raise view on ACTION_DOWN and lower it on ACTION_UP. */
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                view.setTranslationZ(120);
                break;
            case MotionEvent.ACTION_UP:
                view.setTranslationZ(0);
                break;
            default:
                return false;
            }
            return true;
        }
    });
    return rootView;
}

From source file:com.malmstein.materialanimations.elevation.ElevationBasicFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    /**//from   ww  w .  j a  v  a  2s. c o m
     * Inflates an XML containing two shapes: the first has a fixed elevation
     * and the second ones raises when tapped.
     */
    View rootView = inflater.inflate(R.layout.elevation_basic, container, false);

    View shape2 = rootView.findViewById(R.id.floating_shape_2);

    /**
     * Sets a {@Link View.OnTouchListener} that responds to a touch event on shape2.
     */
    shape2.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            int action = motionEvent.getActionMasked();
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                view.animate().setDuration(100).scaleX(1.2f).scaleY(1.3f).translationZ(120);
                break;
            case MotionEvent.ACTION_UP:
                view.animate().setDuration(100).scaleX(1).scaleY(1).translationZ(0);
                break;
            default:
                return false;
            }
            return true;
        }
    });
    return rootView;
}

From source file:com.example.android.elevationbasic.ElevationBasicFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    /**/*ww w  . java  2s .  c om*/
     * Inflates an XML containing two shapes: the first has a fixed elevation
     * and the second ones raises when tapped.
     */
    View rootView = inflater.inflate(R.layout.elevation_basic, container, false);

    View shape2 = rootView.findViewById(R.id.floating_shape_2);

    /**
     * Sets a {@Link View.OnTouchListener} that responds to a touch event on shape2.
     */
    shape2.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            int action = motionEvent.getActionMasked();
            /* Raise view on ACTION_DOWN and lower it on ACTION_UP. */
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                Log.d(TAG, "ACTION_DOWN on view.");
                view.setTranslationZ(120);
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "ACTION_UP on view.");
                view.setTranslationZ(0);
                break;
            default:
                return false;
            }
            return true;
        }
    });
    return rootView;
}

From source file:com.augustosalazar.dragdroptest.DragFrameLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = ev.getActionMasked();
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mDragHelper.cancel();/* w  w  w  . jav a2  s.c  o m*/
        return false;
    }
    return mDragHelper.shouldInterceptTouchEvent(ev);
}

From source file:com.google.android.car.kitchensink.input.InputTestFragment.java

private void handleTouchEvent(MotionEvent event, int keyCode) {
    int androidAction = event.getActionMasked();
    Log.i(TAG, "handleTouchEvent, action:" + androidAction + ",keyCode:" + keyCode);

    switch (androidAction) {
    case MotionEvent.ACTION_DOWN:
        mCarEmulator.injectKey(keyCode, VehicleHwKeyInputAction.ACTION_DOWN);
        break;// ww w  .  j av  a2 s .  c om
    case MotionEvent.ACTION_UP:
        mCarEmulator.injectKey(keyCode, VehicleHwKeyInputAction.ACTION_UP);
        break;
    default:
        Log.w(TAG, "Unhandled touch action: " + androidAction);
        break;
    }
}

From source file:fr.free.nrw.commons.upload.SingleUploadFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_single_upload, null);

    titleEdit = (EditText) rootView.findViewById(R.id.titleEdit);
    descEdit = (EditText) rootView.findViewById(R.id.descEdit);
    licenseSummaryView = (TextView) rootView.findViewById(R.id.share_license_summary);

    TextWatcher uploadEnabler = new TextWatcher() {
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }//from w  ww. j  a  v  a2 s  . c o  m

        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        public void afterTextChanged(Editable editable) {
            if (getActivity() != null) {
                getActivity().invalidateOptionsMenu();
            }
        }
    };

    titleEdit.addTextChangedListener(uploadEnabler);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    final String license = prefs.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA);
    licenseSummaryView
            .setText(getString(R.string.share_license_summary, getString(Utils.licenseNameFor(license))));

    // Open license page on touch
    licenseSummaryView.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(Utils.licenseUrlFor(license)));
                startActivity(intent);
                return true;
            } else {
                return false;
            }
        }
    });

    return rootView;
}

From source file:danonino.danonino_the_game.Core.Activities.Menu.java

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

    //set to full screen
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_menu);
    this.continuePlaying = false;
    MusicManager.start(getApplicationContext(), MusicManager.MUSIC_MENU);
    ShardsContainer.load(getBaseContext());

    this.startBtn = (ImageButton) findViewById(R.id.start_btn);
    this.settingsBtn = (Button) findViewById(R.id.settings_btn);
    this.layout = (RelativeLayout) findViewById(R.id.layout);

    Drawable bg = ContextCompat.getDrawable(getApplicationContext(), R.drawable.menubackground);
    this.layout.setBackground(bg);
    Drawable setbg = ContextCompat.getDrawable(getApplicationContext(), R.drawable.settingicon);
    this.settingsBtn.setBackground(setbg);
    Drawable playbg = ContextCompat.getDrawable(getApplicationContext(), R.drawable.woodenlabel);
    this.startBtn.setBackground(playbg);

    this.startBtn.setOnTouchListener(new View.OnTouchListener() {
        @Override/*from   www .  j  a  v a2  s . c  o m*/
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN: {
                ImageButton view = (ImageButton) v;
                view.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                v.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP:
                Intent i = new Intent(getBaseContext(), Game.class);
                startActivity(i);

            case MotionEvent.ACTION_CANCEL: {
                ImageButton view = (ImageButton) v;
                view.getBackground().clearColorFilter();
                view.invalidate();
                break;
            }
            }
            return true;
        }
    });

    this.settingsBtn.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN: {
                Button view = (Button) v;
                view.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                v.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP:
                continuePlaying = true;
                Intent i = new Intent(getBaseContext(), Settings.class);
                startActivity(i);

            case MotionEvent.ACTION_CANCEL: {
                Button view = (Button) v;
                view.getBackground().clearColorFilter();
                view.invalidate();
                break;
            }
            }
            return true;
        }
    });

}

From source file:com.github.nisrulz.sensey.TouchTypeDetector.java

/**
 * On touch event boolean.//  ww w .  j  ava 2  s.  co  m
 *
 * @param event
 *     the event
 * @return the boolean
 */
boolean onTouchEvent(MotionEvent event) {

    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_POINTER_DOWN:
        if (event.getPointerCount() == 3) {
            touchTypListener.onThreeFingerSingleTap();
        } else if (event.getPointerCount() == 2) {
            touchTypListener.onTwoFingerSingleTap();
        }
    }
    return gDetect.onTouchEvent(event);
}