Search in sources :

Example 26 with ViewParent

use of android.view.ViewParent in project android_frameworks_base by ParanoidAndroid.

the class PagedView method getPageForView.

public int getPageForView(View v) {
    int result = -1;
    if (v != null) {
        ViewParent vp = v.getParent();
        int count = getChildCount();
        for (int i = 0; i < count; i++) {
            if (vp == getPageAt(i)) {
                return i;
            }
        }
    }
    return result;
}
Also used : ViewParent(android.view.ViewParent)

Example 27 with ViewParent

use of android.view.ViewParent in project android_frameworks_base by ParanoidAndroid.

the class Bridge method getViewIndex.

@Override
public Result getViewIndex(Object viewObject) {
    if (viewObject instanceof View) {
        View view = (View) viewObject;
        ViewParent parentView = view.getParent();
        if (parentView instanceof ViewGroup) {
            Status.SUCCESS.createResult(((ViewGroup) parentView).indexOfChild(view));
        }
        return Status.SUCCESS.createResult();
    }
    throw new IllegalArgumentException("viewObject is not a View");
}
Also used : ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) View(android.view.View)

Example 28 with ViewParent

use of android.view.ViewParent in project HoloEverywhere by Prototik.

the class ListPopupWindow method removePromptView.

private void removePromptView() {
    if (mPromptView != null) {
        final ViewParent parent = mPromptView.getParent();
        if (parent instanceof ViewGroup) {
            final ViewGroup group = (ViewGroup) parent;
            group.removeView(mPromptView);
        }
    }
}
Also used : ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup)

Example 29 with ViewParent

use of android.view.ViewParent in project meatspace-android by RomainPiel.

the class PreferenceDialogFragment method onDestroyView.

@Override
public void onDestroyView() {
    super.onDestroyView();
    ViewParent p = lv.getParent();
    if (p != null)
        ((ViewGroup) p).removeView(lv);
}
Also used : ViewParent(android.view.ViewParent)

Example 30 with ViewParent

use of android.view.ViewParent in project material-intro-screen by TangoAgency.

the class CustomViewPager method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (mFakeDragging) {
        // (It is likely that the user is multi-touching the screen.)
        return true;
    }
    if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
        // descendants.
        return false;
    }
    if (mAdapter == null || mAdapter.getCount() == 0) {
        // Nothing to present or scroll; nothing to touch.
        return false;
    }
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);
    final int action = ev.getAction();
    boolean needsInvalidate = false;
    switch(action & MotionEventCompat.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            {
                mScroller.abortAnimation();
                mPopulatePending = false;
                populate();
                // Remember where the motion event started
                mLastMotionX = mInitialMotionX = ev.getX();
                mLastMotionY = mInitialMotionY = ev.getY();
                mActivePointerId = ev.getPointerId(0);
                break;
            }
        case MotionEvent.ACTION_MOVE:
            if (!mIsBeingDragged) {
                final int pointerIndex = ev.findPointerIndex(mActivePointerId);
                if (pointerIndex == -1) {
                    // A child has consumed some touch events and put us into an inconsistent
                    // state.
                    needsInvalidate = resetTouch();
                    break;
                }
                final float x = ev.getX(pointerIndex);
                final float xDiff = Math.abs(x - mLastMotionX);
                final float y = ev.getY(pointerIndex);
                final float yDiff = Math.abs(y - mLastMotionY);
                if (DEBUG) {
                    Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
                }
                if (xDiff > mTouchSlop && xDiff > yDiff) {
                    if (DEBUG)
                        Log.v(TAG, "Starting drag!");
                    mIsBeingDragged = true;
                    requestParentDisallowInterceptTouchEvent(true);
                    mLastMotionX = x - mInitialMotionX > 0 ? mInitialMotionX + mTouchSlop : mInitialMotionX - mTouchSlop;
                    mLastMotionY = y;
                    setScrollState(SCROLL_STATE_DRAGGING);
                    setScrollingCacheEnabled(true);
                    // Disallow Parent Intercept, just in case
                    ViewParent parent = getParent();
                    if (parent != null) {
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                }
            }
            // Not else! Note that mIsBeingDragged can be set above.
            if (mIsBeingDragged) {
                // Scroll to follow the motion event
                final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
                final float x = ev.getX(activePointerIndex);
                needsInvalidate |= performDrag(x);
            }
            break;
        case MotionEvent.ACTION_UP:
            if (mIsBeingDragged) {
                final VelocityTracker velocityTracker = mVelocityTracker;
                velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId);
                mPopulatePending = true;
                final int width = getClientWidth();
                final int scrollX = getScrollX();
                final ItemInfo ii = infoForCurrentScrollPosition();
                final float marginOffset = (float) mPageMargin / width;
                final int currentPage = ii.position;
                final float pageOffset = (((float) scrollX / width) - ii.offset) / (ii.widthFactor + marginOffset);
                final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
                final float x = ev.getX(activePointerIndex);
                final int totalDelta = (int) (x - mInitialMotionX);
                int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta);
                setCurrentItemInternal(nextPage, true, true, initialVelocity);
                needsInvalidate = resetTouch();
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            if (mIsBeingDragged) {
                scrollToItem(mCurItem, true, 0, false);
                needsInvalidate = resetTouch();
            }
            break;
        case MotionEventCompat.ACTION_POINTER_DOWN:
            {
                final int index = MotionEventCompat.getActionIndex(ev);
                final float x = ev.getX(index);
                mLastMotionX = x;
                mActivePointerId = ev.getPointerId(index);
                break;
            }
        case MotionEventCompat.ACTION_POINTER_UP:
            onSecondaryPointerUp(ev);
            mLastMotionX = ev.getX(ev.findPointerIndex(mActivePointerId));
            break;
    }
    if (needsInvalidate) {
        ViewCompat.postInvalidateOnAnimation(this);
    }
    return true;
}
Also used : VelocityTracker(android.view.VelocityTracker) ViewParent(android.view.ViewParent)

Aggregations

ViewParent (android.view.ViewParent)401 ViewGroup (android.view.ViewGroup)184 View (android.view.View)153 ImageView (android.widget.ImageView)36 Rect (android.graphics.Rect)32 VelocityTracker (android.view.VelocityTracker)32 TextView (android.widget.TextView)23 SuppressLint (android.annotation.SuppressLint)15 Paint (android.graphics.Paint)15 FrameLayout (android.widget.FrameLayout)15 AdapterView (android.widget.AdapterView)14 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)13 ViewTreeObserver (android.view.ViewTreeObserver)12 LayoutParams (android.view.WindowManager.LayoutParams)11 Description (org.hamcrest.Description)11 ExpandableNotificationRow (com.android.systemui.statusbar.ExpandableNotificationRow)10 SignalClusterView (com.android.systemui.statusbar.SignalClusterView)10 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)10 EditText (android.widget.EditText)9 Context (android.content.Context)8