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;
}
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();
}
}
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);
}
}
}
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);
}
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();
}
}
Aggregations