Search in sources :

Example 31 with MotionEvent

use of android.view.MotionEvent in project UltimateAndroid by cymcsg.

the class SwipeDismissListViewTouchListener method handleMoveEvent.

private boolean handleMoveEvent(final MotionEvent motionEvent) {
    if (mVelocityTracker == null) {
        return false;
    }
    mVelocityTracker.addMovement(motionEvent);
    float deltaX = motionEvent.getRawX() - mDownX;
    float deltaY = motionEvent.getRawY() - mDownY;
    if (mTouchChildTouched && !mDisallowSwipe && Math.abs(deltaX) > mSlop && Math.abs(deltaX) > Math.abs(deltaY)) {
        mSwiping = true;
        mListView.requestDisallowInterceptTouchEvent(true);
        // Cancel ListView's touch (un-highlighting the item)
        MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
        cancelEvent.setAction(MotionEvent.ACTION_CANCEL | motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT);
        mListView.onTouchEvent(cancelEvent);
    }
    if (mSwiping) {
        ViewHelper.setTranslationX(mCurrentDismissData.view, deltaX);
        //noinspection MagicNumber
        ViewHelper.setAlpha(mCurrentDismissData.view, Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
        return true;
    }
    return false;
}
Also used : MotionEvent(android.view.MotionEvent)

Example 32 with MotionEvent

use of android.view.MotionEvent in project UltimateAndroid by cymcsg.

the class ViewPager method fakeDragBy.

/**
     * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first.
     *
     * @param xOffset Offset in pixels to drag by.
     * @see #beginFakeDrag()
     * @see #endFakeDrag()
     */
public void fakeDragBy(float xOffset) {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }
    mLastMotionX += xOffset;
    float oldScrollX = getScrollX();
    float scrollX = oldScrollX - xOffset;
    final int width = getClientWidth();
    float leftBound = width * mFirstOffset;
    float rightBound = width * mLastOffset;
    final ItemInfo firstItem = mItems.get(0);
    final ItemInfo lastItem = mItems.get(mItems.size() - 1);
    if (firstItem.position != 0) {
        leftBound = firstItem.offset * width;
    }
    if (lastItem.position != mAdapter.getCount() - 1) {
        rightBound = lastItem.offset * width;
    }
    if (scrollX < leftBound) {
        scrollX = leftBound;
    } else if (scrollX > rightBound) {
        scrollX = rightBound;
    }
    // Don't lose the rounded component
    mLastMotionX += scrollX - (int) scrollX;
    scrollTo((int) scrollX, getScrollY());
    pageScrolled((int) scrollX);
    // Synthesize an event for the VelocityTracker.
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
}
Also used : MotionEvent(android.view.MotionEvent)

Example 33 with MotionEvent

use of android.view.MotionEvent in project UltimateAndroid by cymcsg.

the class ViewPager method beginFakeDrag.

/**
     * Start a fake drag of the pager.
     *
     * <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
     * with the touch scrolling of another view, while still letting the ViewPager
     * control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
     * Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
     * {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
     *
     * <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
     * is already in progress, this method will return false.
     *
     * @return true if the fake drag began successfully, false if it could not be started.
     *
     * @see #fakeDragBy(float)
     * @see #endFakeDrag()
     */
public boolean beginFakeDrag() {
    if (mIsBeingDragged) {
        return false;
    }
    mFakeDragging = true;
    setScrollState(SCROLL_STATE_DRAGGING);
    mInitialMotionX = mLastMotionX = 0;
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    } else {
        mVelocityTracker.clear();
    }
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
    mFakeDragBeginTime = time;
    return true;
}
Also used : MotionEvent(android.view.MotionEvent)

Example 34 with MotionEvent

use of android.view.MotionEvent in project plaid by nickbutcher.

the class PlayerActivity method bindPlayer.

void bindPlayer() {
    if (player == null)
        return;
    final Resources res = getResources();
    final NumberFormat nf = NumberFormat.getInstance();
    Glide.with(this).load(player.getHighQualityAvatarUrl()).placeholder(R.drawable.avatar_placeholder).transform(circleTransform).into(avatar);
    playerName.setText(player.name.toLowerCase());
    if (!TextUtils.isEmpty(player.bio)) {
        DribbbleUtils.parseAndSetText(bio, player.bio);
    } else {
        bio.setVisibility(View.GONE);
    }
    shotCount.setText(res.getQuantityString(R.plurals.shots, player.shots_count, nf.format(player.shots_count)));
    if (player.shots_count == 0) {
        shotCount.setCompoundDrawablesRelativeWithIntrinsicBounds(null, getDrawable(R.drawable.avd_no_shots), null, null);
    }
    setFollowerCount(player.followers_count);
    likesCount.setText(res.getQuantityString(R.plurals.likes, player.likes_count, nf.format(player.likes_count)));
    // load the users shots
    dataManager = new PlayerShotsDataManager(this, player) {

        @Override
        public void onDataLoaded(List<Shot> data) {
            if (data != null && data.size() > 0) {
                if (adapter.getDataItemCount() == 0) {
                    loading.setVisibility(View.GONE);
                    ViewUtils.setPaddingTop(shots, likesCount.getBottom());
                }
                adapter.addAndResort(data);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    shots.setAdapter(adapter);
    shots.setItemAnimator(new SlideInItemAnimator());
    shots.setVisibility(View.VISIBLE);
    layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            return adapter.getItemColumnSpan(position);
        }
    });
    shots.setLayoutManager(layoutManager);
    shots.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {

        @Override
        public void onLoadMore() {
            dataManager.loadData();
        }
    });
    shots.setHasFixedSize(true);
    // forward on any clicks above the first item in the grid (i.e. in the paddingTop)
    // to 'pass through' to the view behind
    shots.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int firstVisible = layoutManager.findFirstVisibleItemPosition();
            if (firstVisible > 0)
                return false;
            // if no data loaded then pass through
            if (adapter.getDataItemCount() == 0) {
                return container.dispatchTouchEvent(event);
            }
            final RecyclerView.ViewHolder vh = shots.findViewHolderForAdapterPosition(0);
            if (vh == null)
                return false;
            final int firstTop = vh.itemView.getTop();
            if (event.getY() < firstTop) {
                return container.dispatchTouchEvent(event);
            }
            return false;
        }
    });
    // check if following
    if (dataManager.getDribbblePrefs().isLoggedIn()) {
        if (player.id == dataManager.getDribbblePrefs().getUserId()) {
            TransitionManager.beginDelayedTransition(container);
            follow.setVisibility(View.GONE);
            ViewUtils.setPaddingTop(shots, container.getHeight() - follow.getHeight() - ((ViewGroup.MarginLayoutParams) follow.getLayoutParams()).bottomMargin);
        } else {
            final Call<Void> followingCall = dataManager.getDribbbleApi().following(player.id);
            followingCall.enqueue(new Callback<Void>() {

                @Override
                public void onResponse(Call<Void> call, Response<Void> response) {
                    following = response.isSuccessful();
                    if (!following)
                        return;
                    TransitionManager.beginDelayedTransition(container);
                    follow.setText(R.string.following);
                    follow.setActivated(true);
                }

                @Override
                public void onFailure(Call<Void> call, Throwable t) {
                }
            });
        }
    }
    if (player.shots_count > 0) {
        // kick off initial load
        dataManager.loadData();
    } else {
        loading.setVisibility(View.GONE);
    }
}
Also used : PlayerShotsDataManager(io.plaidapp.data.api.dribbble.PlayerShotsDataManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) GridLayoutManager(android.support.v7.widget.GridLayoutManager) SlideInItemAnimator(io.plaidapp.ui.recyclerview.SlideInItemAnimator) Resources(android.content.res.Resources) Shot(io.plaidapp.data.api.dribbble.model.Shot) InfiniteScrollListener(io.plaidapp.ui.recyclerview.InfiniteScrollListener) NumberFormat(java.text.NumberFormat)

Example 35 with MotionEvent

use of android.view.MotionEvent in project Android-Switch-Demo-pre-4.0 by pellucide.

the class MySwitch method cancelSuperTouch.

private void cancelSuperTouch(MotionEvent ev) {
    MotionEvent cancel = MotionEvent.obtain(ev);
    cancel.setAction(MotionEvent.ACTION_CANCEL);
    super.onTouchEvent(cancel);
    cancel.recycle();
}
Also used : MotionEvent(android.view.MotionEvent)

Aggregations

MotionEvent (android.view.MotionEvent)1088 View (android.view.View)497 TextView (android.widget.TextView)264 ImageView (android.widget.ImageView)190 GestureDetector (android.view.GestureDetector)95 Point (android.graphics.Point)81 AdapterView (android.widget.AdapterView)80 ViewGroup (android.view.ViewGroup)75 Paint (android.graphics.Paint)72 ListView (android.widget.ListView)70 SuppressLint (android.annotation.SuppressLint)69 OnTouchListener (android.view.View.OnTouchListener)69 Intent (android.content.Intent)68 RecyclerView (android.support.v7.widget.RecyclerView)53 Test (org.junit.Test)47 ScrollView (android.widget.ScrollView)46 Handler (android.os.Handler)43 AbsListView (android.widget.AbsListView)42 WindowManager (android.view.WindowManager)41 LinearLayout (android.widget.LinearLayout)40