Java Code Examples for android.view.View#getParent()

The following examples show how to use android.view.View#getParent() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Starts the clicked game. This uses the total index position of the clicked view to get the
 * game.
 *
 * @param view The clicked view.
 */
private void startGame(View view) {
    TableRow row = (TableRow) view.getParent();
    TableLayout table = (TableLayout) row.getParent();
    ArrayList<Integer> orderedList = lg.getOrderedGameList();
    int index = indexes.get(table.indexOfChild(row) * menuColumns + row.indexOfChild(view));
    index = orderedList.indexOf(index);

    //avoid loading two games at once when pressing two buttons at once
    if (prefs.getSavedCurrentGame() != DEFAULT_CURRENT_GAME) {
        return;
    }

    prefs.saveCurrentGame(index);
    Intent intent = new Intent(getApplicationContext(), GameManager.class);
    intent.putExtra(GAME, index);
    startActivityForResult(intent, 0);
}
 
Example 2
public void updateTextureViewPosition() {
    View view = videoView.getAspectRatioView();
    view.getLocationInWindow(position);
    position[0] -= getLeftInset();

    if (!videoView.isInline() && !animationInProgress) {
        TextureView textureView = videoView.getTextureView();
        textureView.setTranslationX(position[0]);
        textureView.setTranslationY(position[1]);
        View textureImageView = videoView.getTextureImageView();
        if (textureImageView != null) {
            textureImageView.setTranslationX(position[0]);
            textureImageView.setTranslationY(position[1]);
        }
    }
    View controlsView = videoView.getControlsView();
    if (controlsView.getParent() == container) {
        controlsView.setTranslationY(position[1]);
    } else {
        controlsView.setTranslationY(0);
    }
}
 
Example 3
public static boolean removeViewFromParent(View view) {

        if (null == view) {
            return false;
        }
        final ViewParent parent = view.getParent();
        if (parent == null) {
            return false;
        }
        if (parent instanceof ViewGroup) {
            ((ViewGroup) parent).removeView(view);
        } else {
            return false;
        }
        return true;
    }
 
Example 4
/**
 * Sets the Empty View to be used by the Adapter View.
 * <p/>
 * We need it handle it ourselves so that we can Pull-to-Refresh when the
 * Empty View is shown.
 * <p/>
 * Please note, you do <strong>not</strong> usually need to call this method
 * yourself. Calling setEmptyView on the AdapterView will automatically call
 * this method and set everything up. This includes when the Android
 * Framework automatically sets the Empty View based on it's ID.
 * 
 * @param newEmptyView - Empty View to be used
 */
public final void setEmptyView(View newEmptyView) {
	FrameLayout refreshableViewWrapper = getRefreshableViewWrapper();

	if (null != newEmptyView) {
		// New view needs to be clickable so that Android recognizes it as a
		// target for Touch Events
		newEmptyView.setClickable(true);

		ViewParent newEmptyViewParent = newEmptyView.getParent();
		if (null != newEmptyViewParent && newEmptyViewParent instanceof ViewGroup) {
			((ViewGroup) newEmptyViewParent).removeView(newEmptyView);
		}

		// We need to convert any LayoutParams so that it works in our
		// FrameLayout
		FrameLayout.LayoutParams lp = convertEmptyViewLayoutParams(newEmptyView.getLayoutParams());
		if (null != lp) {
			refreshableViewWrapper.addView(newEmptyView, lp);
		} else {
			refreshableViewWrapper.addView(newEmptyView);
		}
	}

	if (mRefreshableView instanceof EmptyViewMethodAccessor) {
		((EmptyViewMethodAccessor) mRefreshableView).setEmptyViewInternal(newEmptyView);
	} else {
		mRefreshableView.setEmptyView(newEmptyView);
	}
	mEmptyView = newEmptyView;
}
 
Example 5
Source Project: android-animations   File: Slide.java    License: MIT License 5 votes vote down vote up
public static AnimatorSet OutRight(View view){
    AnimatorSet animatorSet = new AnimatorSet();
    ViewGroup parent = (ViewGroup) view.getParent();
    int distance = parent.getWidth() - view.getLeft();

    ObjectAnimator object1 = ObjectAnimator.ofFloat(view,"alpha", 1, 0);
    ObjectAnimator object2 = ObjectAnimator.ofFloat(view,"translationX", 0, distance);

    animatorSet.playTogether(object1, object2);
    return animatorSet;
}
 
Example 6
private void getOffset(View current, View decorView, int[] array) {
    if (current != decorView) {
        getOffset(current, array);
        if (current.getParent() != null) {
            View view = (View) current.getParent();
            getOffset(view, decorView, array);
        }
    }
}
 
Example 7
/**
 * Return true if child is a descendant of parent, (or equal to the parent).
 */
private static boolean isViewDescendantOf(View child, View parent) {
    if (child == parent) {
        return true;
    }

    final ViewParent theParent = child.getParent();
    return (theParent instanceof ViewGroup) && isViewDescendantOf((View) theParent, parent);
}
 
Example 8
Source Project: Nimingban   File: ViewDragHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Capture a specific child view for dragging within the parent. The callback will be notified
 * but {@link Callback#tryCaptureView(android.view.View, int)} will not be asked permission to
 * capture this view.
 *
 * @param childView Child view to capture
 * @param activePointerId ID of the pointer that is dragging the captured child view
 */
public void captureChildView(View childView, int activePointerId) {
    if (childView.getParent() != mParentView) {
        throw new IllegalArgumentException("captureChildView: parameter must be a descendant " +
                "of the ViewDragHelper's tracked parent view (" + mParentView + ")");
    }

    mCapturedView = childView;
    mActivePointerId = activePointerId;
    mCallback.onViewCaptured(childView, activePointerId);
    setDragState(STATE_DRAGGING);
}
 
Example 9
Source Project: BoardView   File: BoardView.java    License: Apache License 2.0 5 votes vote down vote up
private ViewGroup removeParent(View view){
    if(view == null){
        return null;
    }
    ViewGroup viewGroup = ((ViewGroup)view.getParent());
    if(viewGroup != null){
        viewGroup.removeView(view);
    }
    return viewGroup;
}
 
Example 10
Source Project: TabPager   File: ViewUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 从View的Parent中移除该View
 *
 * @param view 要移除的View对象
 */
public static void removeFromParent(View view) {
    if (null != view) {
        ViewParent parent = view.getParent();
        if (null != parent && parent instanceof ViewGroup) {
            ((ViewGroup) parent).removeView(view);
        }
    }
}
 
Example 11
Source Project: Mover   File: ViewAnimationUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns an Animator which can animate a clipping circle.
 * <p>
 * Any shadow cast by the View will respect the circular clip from this animator.
 * <p>
 * Only a single non-rectangular clip can be applied on a View at any time.
 * Views clipped by a circular reveal animation take priority over
 * {@link android.view.View#setClipToOutline(boolean) View Outline clipping}.
 * <p>
 * Note that the animation returned here is a one-shot animation. It cannot
 * be re-used, and once started it cannot be paused or resumed.
 *
 * @param view The View will be clipped to the animating circle.
 * @param centerX The x coordinate of the center of the animating circle.
 * @param centerY The y coordinate of the center of the animating circle.
 * @param startRadius The starting radius of the animating circle.
 * @param endRadius The ending radius of the animating circle.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static codetail.animation.Animator createCircularReveal(View view,
                                            int centerX,  int centerY,
                                            float startRadius, float endRadius) {

    if(codetail.animation.Animator.LOLLIPOP){
        return new codetail.animation.Animator(android.view.ViewAnimationUtils
                .createCircularReveal(view, centerX, centerY, startRadius, endRadius));
    }

    if(!(view.getParent() instanceof RevealAnimator)){
        throw new IllegalArgumentException("View must be inside dreamers.widget.RevealLayout.");
    }

    RevealAnimator revealLayout = (RevealAnimator) view.getParent();
    revealLayout.setTarget(view);
    revealLayout.setCenter(centerX, centerY);

    Rect bounds = new Rect();
    view.getHitRect(bounds);

    ObjectAnimator reveal = ObjectAnimator.ofFloat(revealLayout, "revealRadius", startRadius, endRadius);
    reveal.addListener(new RevealAnimator.RevealFinished(revealLayout, bounds));

    return new codetail.animation.Animator(reveal);
}
 
Example 12
@Override
public void onRemoteUserLeft(String userId, RongCallCommon.CallDisconnectedReason reason) {
    //incoming状态,localViewUserId为空
    if (localViewUserId == null)
        return;
    if (localViewUserId.equals(userId)) {
        localViewContainer.removeAllViews();
        String currentUserId = RongIMClient.getInstance().getCurrentUserId();
        FrameLayout remoteVideoView = (FrameLayout) remoteViewContainer.findViewWithTag(currentUserId);
        localView = (SurfaceView) remoteVideoView.getChildAt(0);
        remoteVideoView.removeAllViews();
        localViewContainer.addView(localView);
        TextView topUserNameView = (TextView) topContainer.findViewById(R.id.rc_voip_user_name);
        UserInfo userInfo = RongContext.getInstance().getUserInfoFromCache(currentUserId);
        if (userInfo != null) {
            topUserNameView.setText(userInfo.getName());
        } else {
            topUserNameView.setText(currentUserId);
        }
        localViewUserId = currentUserId;
    }

    View singleRemoteView = remoteViewContainer.findViewWithTag(userId + "view");

    if (singleRemoteView == null)
        return;

    LinearLayout container = (LinearLayout) singleRemoteView.getParent();
    container.removeView(singleRemoteView);
    if (container.equals(remoteViewContainer2)) {
        if (remoteViewContainer1.getChildCount() > 0) {
            View childView = remoteViewContainer1.getChildAt(0);
            remoteViewContainer1.removeView(childView);
            remoteViewContainer2.addView(childView);
        }
    }
}
 
Example 13
Source Project: litho   File: TransitionManager.java    License: Apache License 2.0 5 votes vote down vote up
private void recursivelySetChildClippingForView(View view, boolean clipChildren) {
  if (view instanceof ComponentHost) {
    if (clipChildren) {
      ((ComponentHost) view).restoreChildClipping();
    } else {
      ((ComponentHost) view).temporaryDisableChildClipping();
    }
  }

  final ViewParent parent = view.getParent();
  if (parent instanceof ComponentHost) {
    recursivelySetChildClippingForView((View) parent, clipChildren);
  }
}
 
Example 14
Source Project: MaterialQQLite   File: ViewDragHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Capture a specific child view for dragging within the parent. The
 * callback will be notified but
 * {@link me.imid.swipebacklayout.lib.ViewDragHelper.Callback#tryCaptureView(android.view.View, int)}
 * will not be asked permission to capture this view.
 *
 * @param childView       Child view to capture
 * @param activePointerId ID of the pointer that is dragging the captured
 *                        child view
 */
public void captureChildView(View childView, int activePointerId) {
    if (childView.getParent() != mParentView) {
        throw new IllegalArgumentException("captureChildView: parameter must be a descendant "
                + "of the ViewDragHelper's tracked parent view (" + mParentView + ")");
    }

    mCapturedView = childView;
    mActivePointerId = activePointerId;
    mCallback.onViewCaptured(childView, activePointerId);
    setDragState(STATE_DRAGGING);
}
 
Example 15
Source Project: licodeAndroidClient   File: VideoGridLayout.java    License: MIT License 5 votes vote down vote up
/**
 * signals that the given view was just tapped. This indicates the view
 * should switch from normal to enlarged display, or back to normal?
 * Implicitly calls requestLayout!
 * 
 * @param v
 *            The tapped view.
 * @return true if the element is now zoomed, false if it was returned to
 *         normal size
 */
public boolean onTapped(View v) {
	if (v == null || v.getParent() != this) {
		return false;
	}

	if (mZoomedChild != v) {
		setZoomedChild(v);
	} else {
		setZoomedChild(null);
	}
	requestLayout();
	return v == mZoomedChild;
}
 
Example 16
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    if (child == null) return;
    int gravity = Gravity.NO_GRAVITY;
    try {
        gravity = (Integer) params.getClass().getField("gravity").get(params);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (gravity > 0) {
        gravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));

        if ((gravity & Gravity.LEFT) == Gravity.LEFT) {
            mDragEdges.put(DragEdge.Left, child);
        }
        if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) {
            mDragEdges.put(DragEdge.Right, child);
        }
        if ((gravity & Gravity.TOP) == Gravity.TOP) {
            mDragEdges.put(DragEdge.Top, child);
        }
        if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
            mDragEdges.put(DragEdge.Bottom, child);
        }
    } else {
        for (Map.Entry<DragEdge, View> entry : mDragEdges.entrySet()) {
            if (entry.getValue() == null) {
                //means used the drag_edge attr, the no gravity child should be use set
                mDragEdges.put(entry.getKey(), child);
                break;
            }
        }
    }
    if (child.getParent() == this) {
        return;
    }
    super.addView(child, index, params);
}
 
Example 17
Source Project: BigApp_Discuz_Android   File: BadgeView.java    License: Apache License 2.0 5 votes vote down vote up
private void applyTo(View target) {

		LayoutParams lp = target.getLayoutParams();
		ViewParent parent = target.getParent();
		FrameLayout container = new FrameLayout(context);

		if (target instanceof TabWidget) {
			// set target to the relevant tab child container
			target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
			this.target = target;
			((ViewGroup) target).addView(container, new LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

			this.setVisibility(View.GONE);
			container.addView(this);
		} else {
			// verify that parent is indeed a ViewGroup
			ViewGroup group = (ViewGroup) parent;
			int index = group.indexOfChild(target);
			group.removeView(target);
			group.addView(container, index, lp);
			container.addView(target);
			this.setVisibility(View.GONE);
			container.addView(this);
			group.invalidate();
		}
	}
 
Example 18
Source Project: V.FlyoutTest   File: ViewCompat.java    License: MIT License 4 votes vote down vote up
@Override
public ViewParent getParentForAccessibility(View view) {
    return view.getParent();
}
 
Example 19
Source Project: Tweetin   File: PhotoViewAttacher.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
        ViewParent parent = v.getParent();
        switch (ev.getAction()) {
            case ACTION_DOWN:
                // First, disable the Parent from intercepting the touch
                // event
                if (null != parent)
                    parent.requestDisallowInterceptTouchEvent(true);
                else
                    Log.i(LOG_TAG, "onTouch getParent() returned null");

                // If we're flinging, and the user presses down, cancel
                // fling
                cancelFling();
                break;

            case ACTION_CANCEL:
            case ACTION_UP:
                // If the user has zoomed less than min scale, zoom back
                // to min scale
                if (getScale() < mMinScale) {
                    RectF rect = getDisplayRect();
                    if (null != rect) {
                        v.post(new AnimatedZoomRunnable(getScale(), mMinScale,
                                rect.centerX(), rect.centerY()));
                        handled = true;
                    }
                }
                break;
        }

        // Try the Scale/Drag detector
        if (null != mScaleDragDetector
                && mScaleDragDetector.onTouchEvent(ev)) {
            handled = true;
        }

        // Check to see if the user double tapped
        if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }
    }

    return handled;
}
 
Example 20
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // We need to handle focus change within the SimpleMonthView because we are simulating
    // multiple Views. The arrow keys will move between days until there is no space (no
    // day to the left, top, right, or bottom). Focus forward and back jumps out of the
    // SimpleMonthView, skipping over other SimpleMonthViews in the parent ViewPager
    // to the next focusable View in the hierarchy.
    boolean focusChanged = false;
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (event.hasNoModifiers()) {
                focusChanged = moveOneDay(isLayoutRtl());
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (event.hasNoModifiers()) {
                focusChanged = moveOneDay(!isLayoutRtl());
            }
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (event.hasNoModifiers()) {
                ensureFocusedDay();
                if (mHighlightedDay > 7) {
                    mHighlightedDay -= 7;
                    focusChanged = true;
                }
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (event.hasNoModifiers()) {
                ensureFocusedDay();
                if (mHighlightedDay <= mDaysInMonth - 7) {
                    mHighlightedDay += 7;
                    focusChanged = true;
                }
            }
            break;
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (mHighlightedDay != -1) {
                onDayClicked(mHighlightedDay);
                return true;
            }
            break;
        case KeyEvent.KEYCODE_TAB: {
            int focusChangeDirection = 0;
            if (event.hasNoModifiers()) {
                focusChangeDirection = View.FOCUS_FORWARD;
            } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                focusChangeDirection = View.FOCUS_BACKWARD;
            }
            if (focusChangeDirection != 0) {
                final ViewParent parent = getParent();
                // move out of the ViewPager next/previous
                View nextFocus = this;
                do {
                    nextFocus = nextFocus.focusSearch(focusChangeDirection);
                } while (nextFocus != null && nextFocus != this &&
                        nextFocus.getParent() == parent);
                if (nextFocus != null) {
                    nextFocus.requestFocus();
                    return true;
                }
            }
            break;
        }
    }
    if (focusChanged) {
        invalidate();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}