Search in sources :

Example 11 with ViewParent

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

the class ViewPager method arrowScroll.

public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this) {
        currentFocused = null;
    } else if (currentFocused != null) {
        boolean isChild = false;
        for (ViewParent parent = currentFocused.getParent(); parent instanceof ViewGroup; parent = parent.getParent()) {
            if (parent == this) {
                isChild = true;
                break;
            }
        }
        if (!isChild) {
            // This would cause the focus search down below to fail in fun ways.
            final StringBuilder sb = new StringBuilder();
            sb.append(currentFocused.getClass().getSimpleName());
            for (ViewParent parent = currentFocused.getParent(); parent instanceof ViewGroup; parent = parent.getParent()) {
                sb.append(" => ").append(parent.getClass().getSimpleName());
            }
            Log.e(TAG, "arrowScroll tried to find focus based on non-child " + "current focused view " + sb.toString());
            currentFocused = null;
        }
    }
    boolean handled = false;
    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
    if (nextFocused != null && nextFocused != currentFocused) {
        if (direction == View.FOCUS_LEFT) {
            // If there is nothing to the left, or this is causing us to
            // jump to the right, then what we really want to do is page left.
            final int nextLeft = getChildRectInPagerCoordinates(mTempRect, nextFocused).left;
            final int currLeft = getChildRectInPagerCoordinates(mTempRect, currentFocused).left;
            if (currentFocused != null && nextLeft >= currLeft) {
                handled = pageLeft();
            } else {
                handled = nextFocused.requestFocus();
            }
        } else if (direction == View.FOCUS_RIGHT) {
            // If there is nothing to the right, or this is causing us to
            // jump to the left, then what we really want to do is page right.
            final int nextLeft = getChildRectInPagerCoordinates(mTempRect, nextFocused).left;
            final int currLeft = getChildRectInPagerCoordinates(mTempRect, currentFocused).left;
            if (currentFocused != null && nextLeft <= currLeft) {
                handled = pageRight();
            } else {
                handled = nextFocused.requestFocus();
            }
        }
    } else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
        // Trying to move left and nothing there; try to page.
        handled = pageLeft();
    } else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
        // Trying to move right and nothing there; try to page.
        handled = pageRight();
    }
    if (handled) {
        playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
    }
    return handled;
}
Also used : ViewGroup(android.view.ViewGroup) ViewParent(android.view.ViewParent) View(android.view.View)

Example 12 with ViewParent

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

the class SwipeLayout method performAdapterViewItemClick.

private void performAdapterViewItemClick(MotionEvent e) {
    ViewParent t = getParent();
    while (t != null) {
        if (t instanceof AdapterView) {
            AdapterView view = (AdapterView) t;
            int p = view.getPositionForView(SwipeLayout.this);
            if (p != AdapterView.INVALID_POSITION && view.performItemClick(view.getChildAt(p), p, view.getAdapter().getItemId(p)))
                return;
        } else {
            if (t instanceof View && ((View) t).performClick())
                return;
        }
        t = t.getParent();
    }
}
Also used : ViewParent(android.view.ViewParent) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 13 with ViewParent

use of android.view.ViewParent in project Libraries-for-Android-Developers by eoecn.

the class ActionBarView method onFinishInflate.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    addView(mHomeLayout);
    if (mCustomNavView != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
        final ViewParent parent = mCustomNavView.getParent();
        if (parent != this) {
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(mCustomNavView);
            }
            addView(mCustomNavView);
        }
    }
}
Also used : ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup)

Example 14 with ViewParent

use of android.view.ViewParent in project yield-layout by evant.

the class YieldLayout method inflate.

private void inflate() {
    ViewParent viewParent = null;
    View currentView = this;
    if (mLayoutView != null) {
        currentView = mLayoutView;
        viewParent = mLayoutView.getParent();
    }
    if (viewParent == null) {
        viewParent = getParent();
    }
    if (viewParent == null) {
        return;
    }
    if (!(viewParent instanceof ViewGroup)) {
        throw new IllegalStateException("YieldLayout must have a non-null ViewGroup viewParent (Instead parent was: '" + viewParent + "')");
    }
    ViewGroup parent = (ViewGroup) viewParent;
    inflate(currentView, parent, true);
}
Also used : ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) View(android.view.View)

Example 15 with ViewParent

use of android.view.ViewParent in project StickyListHeaders by emilsjolander.

the class WrapperView method update.

void update(View item, View header, Drawable divider, int dividerHeight) {
    //every wrapperview must have a list item
    if (item == null) {
        throw new NullPointerException("List view item must not be null.");
    }
    //only remove the current item if it is not the same as the new item. this can happen if wrapping a recycled view
    if (this.mItem != item) {
        removeView(this.mItem);
        this.mItem = item;
        final ViewParent parent = item.getParent();
        if (parent != null && parent != this) {
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(item);
            }
        }
        addView(item);
    }
    //same logik as above but for the header
    if (this.mHeader != header) {
        if (this.mHeader != null) {
            removeView(this.mHeader);
        }
        this.mHeader = header;
        if (header != null) {
            addView(header);
        }
    }
    if (this.mDivider != divider) {
        this.mDivider = divider;
        this.mDividerHeight = dividerHeight;
        invalidate();
    }
}
Also used : ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup)

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