Example usage for android.view MotionEvent getRawX

List of usage examples for android.view MotionEvent getRawX

Introduction

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

Prototype

public final float getRawX() 

Source Link

Document

Returns the original raw X coordinate of this event.

Usage

From source file:org.rm3l.ddwrt.tiles.syslog.StatusSyslogTile.java

@Override
public void onLoadFinished(@NotNull Loader<NVRAMInfo> loader, @Nullable NVRAMInfo data) {
    //Set tiles//from  w  ww .j a v a  2 s  .c o  m
    Log.d(LOG_TAG, "onLoadFinished: loader=" + loader + " / data=" + data);

    layout.findViewById(R.id.tile_status_router_syslog_header_loading_view).setVisibility(View.GONE);
    layout.findViewById(R.id.tile_status_router_syslog_content_loading_view).setVisibility(View.GONE);
    layout.findViewById(R.id.tile_status_router_syslog_state).setVisibility(View.VISIBLE);
    layout.findViewById(R.id.tile_status_router_syslog_content).setVisibility(View.VISIBLE);

    if (data == null) {
        data = new NVRAMInfo().setException(new DDWRTNoDataException("No Data!"));
    }

    @NotNull
    final TextView errorPlaceHolderView = (TextView) this.layout
            .findViewById(R.id.tile_status_router_syslog_error);

    @Nullable
    final Exception exception = data.getException();

    if (!(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) {

        if (exception == null) {
            errorPlaceHolderView.setVisibility(View.GONE);
        }

        final String syslogdEnabledPropertyValue = data.getProperty(SYSLOGD_ENABLE);
        final boolean isSyslogEnabled = "1".equals(syslogdEnabledPropertyValue);

        final TextView syslogState = (TextView) this.layout.findViewById(R.id.tile_status_router_syslog_state);

        final View syslogContentView = this.layout.findViewById(R.id.tile_status_router_syslog_content);
        final EditText filterEditText = (EditText) this.layout
                .findViewById(R.id.tile_status_router_syslog_filter);

        syslogState.setText(
                syslogdEnabledPropertyValue == null ? "-" : (isSyslogEnabled ? "Enabled" : "Disabled"));

        syslogState.setVisibility(mDisplayStatus ? View.VISIBLE : View.GONE);

        final TextView logTextView = (TextView) syslogContentView;
        if (isSyslogEnabled) {

            //Highlight textToFind for new log lines
            final String newSyslog = data.getProperty(SYSLOG, EMPTY_STRING);

            //Hide container if no data at all (no existing data, and incoming data is empty too)
            final View scrollView = layout.findViewById(R.id.tile_status_router_syslog_content_scrollview);

            //noinspection ConstantConditions
            Spanned newSyslogSpan = new SpannableString(newSyslog);

            final SharedPreferences sharedPreferences = this.mParentFragmentPreferences;
            final String existingSearch = sharedPreferences != null
                    ? sharedPreferences.getString(getFormattedPrefKey(LAST_SEARCH), null)
                    : null;

            if (!isNullOrEmpty(existingSearch)) {
                if (isNullOrEmpty(filterEditText.getText().toString())) {
                    filterEditText.setText(existingSearch);
                }
                if (!isNullOrEmpty(newSyslog)) {
                    //noinspection ConstantConditions
                    newSyslogSpan = findAndHighlightOutput(newSyslog, existingSearch);
                }
            }

            //                if (!(isNullOrEmpty(existingSearch) || isNullOrEmpty(newSyslog))) {
            //                    filterEditText.setText(existingSearch);
            //                    //noinspection ConstantConditions
            //                    newSyslogSpan = findAndHighlightOutput(newSyslog, existingSearch);
            //                }

            if (isNullOrEmpty(logTextView.getText().toString()) && isNullOrEmpty(newSyslog)) {
                scrollView.setVisibility(View.INVISIBLE);
            } else {
                scrollView.setVisibility(View.VISIBLE);

                logTextView.setMovementMethod(new ScrollingMovementMethod());

                logTextView.append(
                        new SpannableStringBuilder().append(Html.fromHtml("<br/>")).append(newSyslogSpan));
            }

            filterEditText.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    final int DRAWABLE_LEFT = 0;
                    final int DRAWABLE_TOP = 1;
                    final int DRAWABLE_RIGHT = 2;
                    final int DRAWABLE_BOTTOM = 3;

                    if (event.getAction() == MotionEvent.ACTION_UP) {
                        if (event.getRawX() >= (filterEditText.getRight()
                                - filterEditText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                            //Reset everything
                            filterEditText.setText(EMPTY_STRING); //this will trigger the TextWatcher, thus disabling the "Find" button
                            //Highlight text in textview
                            final String currentText = logTextView.getText().toString();

                            logTextView.setText(currentText.replaceAll(SLASH_FONT_HTML, EMPTY_STRING)
                                    .replaceAll(FONT_COLOR_YELLOW_HTML, EMPTY_STRING));

                            if (sharedPreferences != null) {
                                final SharedPreferences.Editor editor = sharedPreferences.edit();
                                editor.putString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING);
                                editor.apply();
                            }
                            return true;
                        }
                    }
                    return false;
                }
            });

            filterEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                        final String textToFind = filterEditText.getText().toString();
                        if (isNullOrEmpty(textToFind)) {
                            //extra-check, even though we can be pretty sure the button is enabled only if textToFind is present
                            return true;
                        }
                        if (sharedPreferences != null) {
                            if (textToFind.equalsIgnoreCase(existingSearch)) {
                                //No need to go further as this is already the string we are looking for
                                return true;
                            }
                            final SharedPreferences.Editor editor = sharedPreferences.edit();
                            editor.putString(getFormattedPrefKey(LAST_SEARCH), textToFind);
                            editor.apply();
                        }
                        //Highlight text in textview
                        final String currentText = logTextView.getText().toString();

                        logTextView.setText(
                                findAndHighlightOutput(currentText.replaceAll(SLASH_FONT_HTML, EMPTY_STRING)
                                        .replaceAll(FONT_COLOR_YELLOW_HTML, EMPTY_STRING), textToFind));

                        return true;
                    }
                    return false;
                }
            });

        }
    }

    if (exception != null && !(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) {
        //noinspection ThrowableResultOfMethodCallIgnored
        final Throwable rootCause = Throwables.getRootCause(exception);
        errorPlaceHolderView.setText("Error: " + (rootCause != null ? rootCause.getMessage() : "null"));
        final Context parentContext = this.mParentFragmentActivity;
        errorPlaceHolderView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                //noinspection ThrowableResultOfMethodCallIgnored
                if (rootCause != null) {
                    Toast.makeText(parentContext, rootCause.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        });
        errorPlaceHolderView.setVisibility(View.VISIBLE);
    }

    doneWithLoaderInstance(this, loader, R.id.tile_status_router_syslog_togglebutton_title,
            R.id.tile_status_router_syslog_togglebutton);

    Log.d(LOG_TAG, "onLoadFinished(): done loading!");
}

From source file:com.billooms.harppedals.HarpPedalsActivity.java

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

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override/*  w  ww  .  j ava 2s  .  c  om*/
        public void onClick(DialogInterface dialog, int which) {
            // don't do anything except close the dialog
        }
    });

    // This will be either the standard (small) layout or the large layout
    setContentView(R.layout.activity_main);

    // Check that the activity is using the standard (small) layout version with the 'fragment_container' FrameLayout
    if (findViewById(R.id.fragment_container) != null) {
        // Gesture Detector to detect horizontal swipes
        if (gDetector == null) {
            gDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onFling(MotionEvent start, MotionEvent finish, float xVelocity,
                        float yVelocity) {
                    if ((finish == null) || (start == null)) { // not sure why, but the float dx = gives null pointer error sometimes
                        return false;
                    }
                    Fragment swipeFragment = getSupportFragmentManager().findFragmentByTag(NO_SWIPE);
                    if (swipeFragment == null) { // only process swipes in one-pane PedalFragments
                        float dx = finish.getRawX() - start.getRawX();
                        float dy = finish.getRawY() - start.getRawY();
                        if (Math.abs(dy) < Math.abs(dx)) { // horizontal
                            if (dx < 0) { // swipe toward the left for KeySignature
                                launchKeyFragment();
                            } else { // swipe toward the right for Chord
                                launchChordFragment();
                            }
                        }
                        return true; // gesture has been consumed
                    }
                    return false; // don't process swipes if we're not in a one-pane PedalFragment
                }
            });
        }

        // If we're being restored from a previous state,
        // then we don't need to do anything and should return or else
        // we could end up with overlapping fragments.
        if (savedInstanceState != null) {
            return;
        }

        // Create a new PedalFragment to be placed in the activity layout
        PedalFragment pedalFragment = new PedalFragment();
        // Add the fragment to the 'fragment_container' FrameLayout
        getSupportFragmentManager().beginTransaction()
                .add(R.id.fragment_container, pedalFragment, TAG_PEDAL_FRAG).commit();
    }
}

From source file:zuo.biao.library.base.BaseFragmentActivity.java

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

    if (onPageReturnListener != null) {

        float maxDragHeight = getResources().getDimension(R.dimen.page_drag_max_height);
        float distanceY = e2.getRawY() - e1.getRawY();
        if (distanceY < maxDragHeight && distanceY > -maxDragHeight) {

            float minDragWidth = getResources().getDimension(R.dimen.page_drag_min_width);
            float distanceX = e2.getRawX() - e1.getRawX();
            if (distanceX > minDragWidth) {
                onPageReturnListener.onPageReturn();
                return true;
            }//  ww w .jav  a  2s .c  om
        }
    }

    return false;
}

From source file:com.hrs.filltheform.dialog.FillTheFormDialog.java

private void prepareDialogView() {
    windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    dialogParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);

    dialogView = new FrameLayout(context);
    dialogView.setOnTouchListener(new View.OnTouchListener() {
        final Point screenSize = new Point();

        @Override/*from  w w w .  j  a v  a2s . com*/
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                windowManager.getDefaultDisplay().getSize(screenSize);
                model.setScreenDimensions(screenSize.x, screenSize.y);
                model.setInitialDialogPosition(dialogParams.x, dialogParams.y);
                model.setInitialTouchEvent(event.getRawX(), event.getRawY());
                return true;
            case MotionEvent.ACTION_UP:
                model.onActionUp();
                return true;
            case MotionEvent.ACTION_MOVE:
                model.onActionMove(event.getRawX(), event.getRawY());
                return true;
            }
            return false;
        }
    });

    @SuppressLint("InflateParams")
    final View dialogContent = LayoutInflater.from(context).inflate(R.layout.dialog, null);
    dialogMenu = dialogContent.findViewById(R.id.dialog_menu);
    expandIcon = dialogContent.findViewById(R.id.expand_icon);
    expandIconFastMode = dialogContent.findViewById(R.id.expand_icon_fast_mode);

    // Set up dialog content
    ImageButton closeButton = (ImageButton) dialogContent.findViewById(R.id.close_button);
    closeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            model.onCloseButtonClicked();
        }
    });
    ImageButton minimizeButton = (ImageButton) dialogContent.findViewById(R.id.minimize_button);
    minimizeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            model.onMinimizeButtonClicked();
        }
    });
    ImageButton openFillTheFormAppButton = (ImageButton) dialogContent
            .findViewById(R.id.open_fill_the_form_app_button);
    openFillTheFormAppButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            model.onOpenFillTheFormAppButtonClicked();
        }
    });
    fastModeButton = (ImageButton) dialogContent.findViewById(R.id.fast_mode_button);
    fastModeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            model.toggleFastMode();
        }
    });

    // Configuration items list
    configurationItemsView = (RecyclerView) dialogContent.findViewById(R.id.configuration_items_view);
    configurationItemsView.setHasFixedSize(true);
    configurationItemsView.setLayoutManager(new LinearLayoutManager(context));
    // Set adapter
    configurationItemsAdapter = new ConfigurationItemsAdapter(context, model);
    configurationItemsView.setAdapter(configurationItemsAdapter);
    dialogView.addView(dialogContent);
}

From source file:com.appsimobile.appsii.SidebarHotspot.java

private void cancelMotionHandling(MotionEvent e, boolean cancelled) {
    mState = STATE_WAITING;/*from w  ww.jav  a  2 s  .  c  om*/
    if (mSwipeListener != null) {
        if (e == null) {
            mSwipeListener.onSwipeEnd(this, 0, 0, cancelled, mVelocityTracker);
        } else {
            mSwipeListener.onSwipeEnd(this, (int) e.getRawX(), (int) e.getRawY(), cancelled, mVelocityTracker);
        }
    }
    if (mCallback != null) {
        mCallback.cancelVisualHints(this);
    }
    mSwipeInProgress = false;
    mSwipeListener = null;

    // restore the background
    setBackground(mBackground);
    mIsDragOpening = false;

    if (mCallback != null) {
        mCallback.removeIfNeeded(this);
    }
    invalidate();

    mVelocityTracker.addMovement(e);
    mVelocityTracker.recycle();
    mVelocityTracker = null;
}

From source file:com.personal.taskmanager2.utilities.RecyclerViewTouchListener.java

@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    switch (e.getActionMasked()) {
    case MotionEvent.ACTION_CANCEL:
        Log.d(TAG, "Cancel Event");
        break;/*  w  w  w . j a  v a2 s .  c  o  m*/
    case MotionEvent.ACTION_DOWN:
        Log.d(TAG, "Press Event");
        break;
    case MotionEvent.ACTION_UP:
        Log.d(TAG, "Up Event");

        if (mVelocityTracker == null) {
            Log.d(TAG, "velocity tracker is null in action up");
            break;
        }

        Log.d(TAG, "Up Intercept");
        float deltaX = e.getRawX() - mDownX;
        float absDeltaX = Math.abs(deltaX);
        mVelocityTracker.addMovement(e);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = mVelocityTracker.getXVelocity();
        float absVelocityX = Math.abs(velocityX);
        float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;
        if (absDeltaX > mViewWidth / 2) {
            dismiss = true;
            dismissRight = deltaX > 0;
        } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
                && absVelocityY < absVelocityX) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (deltaX < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
        }

        if (dismiss) {
            dismiss(mChildView, mChildPosition, dismissRight);
        } else {
            mChildView.animate().alpha(1).translationX(0).setDuration(mAnimationTime).setListener(null);
        }

        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDeltaX = 0;
        mChildView = null;
        mChildPosition = RecyclerView.NO_POSITION;
        mSwiping = false;
        break;
    case MotionEvent.ACTION_MOVE:
        Log.d(TAG, "Move Event");
        mRecyclerView.requestDisallowInterceptTouchEvent(true);
        mRefreshLayout.requestDisallowInterceptTouchEvent(true);

        // Cancel ListView's touch (un-highlighting the item)
        MotionEvent cancelEvent = MotionEvent.obtain(e);
        cancelEvent.setAction(
                MotionEvent.ACTION_CANCEL | (e.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
        mRecyclerView.onTouchEvent(cancelEvent);
        mRefreshLayout.onTouchEvent(cancelEvent);
        cancelEvent.recycle();

        mChildView.setTranslationX(mDeltaX);
        /*mChildView.setAlpha(Math.max(0.15f, Math.min(1f,
                                                     1f - 2f * Math.abs(mDeltaX) /
                                                          mViewWidth)));*/
        break;
    }
}

From source file:com.fastaccess.ui.modules.repos.RepoPagerActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (navType == RepoPagerMvp.ISSUES && filterLayout.isShown()) {
        Rect viewRect = ViewHelper.getLayoutPosition(filterLayout);
        if (!viewRect.contains((int) ev.getRawX(), (int) ev.getRawY())) {
            hideFilterLayout();//from   ww w.  j  a  va  2  s .c  om
        }
    }
    return super.dispatchTouchEvent(ev);
}

From source file:arun.com.chromer.webheads.ui.views.WebHead.java

/**
 * Responsible for moving the web heads around and for locking/unlocking the web head to
 * remove view.//  w  w w .j  a v a 2  s  .  c o m
 *
 * @param event the touch event
 */
private void handleMove(@NonNull MotionEvent event) {
    movementTracker.addMovement(event);

    float offsetX = event.getRawX() - posX;
    float offsetY = event.getRawY() - posY;

    if (Math.hypot(offsetX, offsetY) > touchSlop) {
        dragging = true;
    }

    if (dragging) {
        getTrashy().reveal();

        userManuallyMoved = true;

        int x = (int) (initialDownX + offsetX);
        int y = (int) (initialDownY + offsetY);

        if (isNearRemoveCircle(x, y)) {
            getTrashy().grow();
            touchUp();

            xSpring.setSpringConfig(SpringConfigs.SNAP);
            ySpring.setSpringConfig(SpringConfigs.SNAP);

            xSpring.setEndValue(trashLockCoOrd()[0]);
            ySpring.setEndValue(trashLockCoOrd()[1]);

        } else {
            getTrashy().shrink();

            xSpring.setSpringConfig(SpringConfigs.DRAG);
            ySpring.setSpringConfig(SpringConfigs.DRAG);

            xSpring.setCurrentValue(x);
            ySpring.setCurrentValue(y);

            touchDown();
        }
    }
}

From source file:com.taobao.weex.ui.view.listview.BaseBounceView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    if (action != MotionEvent.ACTION_DOWN && mIsBeingDragged) {
        return true;
    }/*w ww .  j  av  a 2s.  c om*/
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mLastMotionY = ev.getRawY();
        mLastMotionX = ev.getRawX();
        //listview??listview.setPadding()getPaddingTop()scrollValue??
        mScrollValue = -getPaddingTop();
        break;
    }
    case MotionEvent.ACTION_MOVE: {
        float x = ev.getRawX();
        float y = ev.getRawY();
        float deltaX = ev.getRawX() - mLastMotionX;
        float deltaY = ev.getRawY() - mLastMotionY;
        float degree = Math.abs(deltaY) / Math.abs(deltaX);
        //Log.v(getClass().getSimpleName(), "onInterceptTouchEvent move");
        if (Math.abs(deltaY) > mTouchSlop && degree >= 1.7f && mBounceable) {
            if (deltaY > 0 && isReadyForPullFromTop()) {
                mLastMotionX = x;
                mLastMotionY = y;
                mIsBeingDragged = true;
                mMode = Mode.PULL_FROM_TOP;
            } else if (deltaY < 0 && isReadyForPullFromBottom()) {
                mLastMotionX = x;
                mLastMotionY = y;
                mIsBeingDragged = true;
                mMode = Mode.PULL_FROM_BOTTOM;
            }

        }
        break;
    }
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mIsBeingDragged = false;
    }
    }
    return mIsBeingDragged;
}

From source file:com.prevas.redmine.NewIssueActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    View view = getCurrentFocus();
    boolean ret = super.dispatchTouchEvent(event);

    if (view instanceof EditText) {
        View v = getCurrentFocus();
        int scrcoords[] = new int[2];
        v.getLocationOnScreen(scrcoords);
        float x = event.getRawX() + v.getLeft() - scrcoords[0];
        float y = event.getRawY() + v.getTop() - scrcoords[1];

        if (event.getAction() == MotionEvent.ACTION_UP
                && (x < v.getLeft() || x >= v.getRight() || y < v.getTop() || y > v.getBottom())) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
        }/*  w  w w  .j  a va 2  s .c  om*/
    }
    return ret;
}