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

The following are Jave code examples for showing how to use getParent() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: privacyidea-authenticator   File: MainActivityTest.java   View Source Code Vote up 8 votes
private static Matcher<View> childAtPosition(
        final Matcher<View> parentMatcher, final int position) {

    return new TypeSafeMatcher<View>() {
        @Override
        public void describeTo(Description description) {
            description.appendText("Child at position " + position + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent)
                    && view.equals(((ViewGroup) parent).getChildAt(position));
        }
    };
}
 
Example 2
Project: FlickLauncher   File: UserEventDispatcher.java   View Source Code Vote up 7 votes
/**
 * Recursively finds the parent of the given child which implements IconLogInfoProvider
 */
public static LaunchSourceProvider getLaunchProviderRecursive(View v) {
    ViewParent parent = null;

    if (v != null) {
        parent = v.getParent();
    } else {
        return null;
    }

    // Optimization to only check up to 5 parents.
    int count = MAXIMUM_VIEW_HIERARCHY_LEVEL;
    while (parent != null && count-- > 0) {
        if (parent instanceof LaunchSourceProvider) {
            return (LaunchSourceProvider) parent;
        } else {
            parent = parent.getParent();
        }
    }
    return null;
}
 
Example 3
Project: TextReader   File: DefaultEventDelegate.java   View Source Code Vote up 7 votes
public void refreshStatus(){
    if (container!=null){
        if (flag == Hide){
            container.setVisibility(View.GONE);
            return;
        }
        if (container.getVisibility() != View.VISIBLE)container.setVisibility(View.VISIBLE);
        View view = null;
        switch (flag){
            case ShowMore:view = moreView;break;
            case ShowError:view = errorView;break;
            case ShowNoMore:view = noMoreView;break;
        }
        if (view == null){
            hide();
            return;
        }
        if (view.getParent()==null)container.addView(view);
        for (int i = 0; i < container.getChildCount(); i++) {
            if (container.getChildAt(i) == view)view.setVisibility(View.VISIBLE);
            else container.getChildAt(i).setVisibility(View.GONE);
        }
    }
}
 
Example 4
Project: RNLearn_Project1   File: ReactClippingViewGroupHelper.java   View Source Code Vote up 7 votes
/**
 * Can be used by view that support {@code removeClippedSubviews} property to calculate area that
 * given {@param view} should be clipped to based on the clipping rectangle of it's parent in
 * case when parent is also set to clip it's children.
 *
 * @param view view that we want to calculate clipping rect for
 * @param outputRect where the calculated rectangle will be written
 */
public static void calculateClippingRect(View view, Rect outputRect) {
  ViewParent parent = view.getParent();
  if (parent == null) {
    outputRect.setEmpty();
    return;
  } else if (parent instanceof ReactClippingViewGroup) {
    ReactClippingViewGroup clippingViewGroup = (ReactClippingViewGroup) parent;
    if (clippingViewGroup.getRemoveClippedSubviews()) {
      clippingViewGroup.getClippingRect(sHelperRect);
      // Intersect the view with the parent's rectangle
      // This will result in the overlap with coordinates in the parent space
      if (!sHelperRect.intersect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())) {
        outputRect.setEmpty();
        return;
      }
      // Now we move the coordinates to the View's coordinate space
      sHelperRect.offset(-view.getLeft(), -view.getTop());
      sHelperRect.offset(view.getScrollX(), view.getScrollY());
      outputRect.set(sHelperRect);
      return;
    }
  }
  view.getDrawingRect(outputRect);
}
 
Example 5
Project: duo-navigation-drawer   File: DuoDrawerLayout.java   View Source Code Vote up 7 votes
/**
 * Sets the menu view.
 *
 * @param menuView View that becomes the menu view.
 */
public void setMenuView(View menuView) {
    if (menuView.getParent() != null) {
        throw new IllegalStateException("Your menu view already has a parent. Please make sure your menu view does not have a parent.");
    }

    mMenuView = this.findViewWithTag(TAG_MENU);
    if (mMenuView != null) {
        this.removeView(mMenuView);
    }
    mMenuView = menuView;
    mMenuView.setTag(TAG_MENU);
    addView(mMenuView);
    invalidate();
    requestLayout();
}
 
Example 6
Project: ProgressManager   File: a.java   View Source Code Vote up 6 votes
public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
    // Update window manager if: we have a view, that view is
    // attached to its parent (which will be a RootView), and
    // this activity is not embedded.
    if (mParent == null) {
        View decor = mDecor;
        if (decor != null && decor.getParent() != null) {
            getWindowManager().updateViewLayout(decor, params);
        }
    }
}
 
Example 7
Project: Tribe   File: ViewConverter.java   View Source Code Vote up 6 votes
public static View replaceView(View srcView, int destId) {
    Context context = srcView.getContext();
    ViewGroup viewParent = (ViewGroup) srcView.getParent();
    View destView = LayoutInflater.from(context).inflate(destId, viewParent, false);
    if (destView.getParent() != null) {
        destView.setVisibility(VISIBLE);
    } else {
        viewParent.addView(destView);
    }
    srcView.setVisibility(GONE);
    return destView;
}
 
Example 8
Project: brickkit-android   File: StickyViewBehavior.java   View Source Code Vote up 6 votes
/**
 * Remove the given view from its parent.
 *
 * @param view view to remove from its parent
 */
private static void removeViewFromParent(final View view) {
    final ViewParent parent = view.getParent();
    if (parent instanceof ViewGroup) {
        ((ViewGroup) parent).removeView(view);
    }
}
 
Example 9
Project: PHEmptyDataSetForAndroid   File: PHEmptyDataSet.java   View Source Code Vote up 6 votes
public PHEmptyDataSet(View fatherView){
    super(fatherView.getContext());
    mcontext = fatherView.getContext();
    this.isFirstCreated = false;
    this.msuperGroup = (ViewGroup) fatherView.getParent();
    this.mfatherView = fatherView;
    ViewGroup.LayoutParams mparam = mfatherView.getLayoutParams();
    this.setLayoutParams(mparam);
    this.imageBTN = new ImageView(mcontext);
    this.imageBTN.setId(9527);
    titleV = new TextView(mcontext);
}
 
Example 10
Project: TabPager   File: ViewUtils.java   View Source Code Vote up 6 votes
/**
 * 从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
Project: switchbutton   File: FTouchHelper.java   View Source Code Vote up 6 votes
/**
 * 是否请求当前view的父view不要拦截事件
 *
 * @param view
 * @param disallowIntercept true-请求父view不要拦截,false-父view可以拦截
 */
public static void requestDisallowInterceptTouchEvent(View view, boolean disallowIntercept)
{
    ViewParent parent = view.getParent();
    if (parent == null)
    {
        return;
    }
    parent.requestDisallowInterceptTouchEvent(disallowIntercept);
}
 
Example 12
Project: HueNotifier   File: RuleAdapter.java   View Source Code Vote up 6 votes
@Override
public void onClick(View view) {
    View editView = (View) view.getParent();
    if (activity.isConnected) {
        View cardView = (View) editView.getParent();
        final int itemPosition = activity.ruleList.getChildLayoutPosition(cardView);
        activity.editRule(activity.rules.get(itemPosition));
    } else {
        Snackbar.make(activity.findViewById(android.R.id.content), R.string.not_connected,
                Snackbar.LENGTH_SHORT).show();
    }
    MainActivity.fadeView(false, editView);
}
 
Example 13
Project: simple-upnp   File: FileBrowserAdapter.java   View Source Code Vote up 6 votes
@Override
public void onClick(View view) {
    if (view.getId() != R.id.file_browser_list_item_button) {
        throw new IllegalStateException("Unhandled view in onClick: " + view.toString());
    }

    RelativeLayout parent = (RelativeLayout) view.getParent();
    ViewHolder holder = (ViewHolder) parent.getTag();
    ListItem listItem = getItem(holder.position);
    if (mListener != null && listItem != null) {
        mListener.playItems(listItem.getMediaItems());
    }
}
 
Example 14
Project: KUtils-master   File: ZoomInUpAnimator.java   View Source Code Vote up 6 votes
@Override
public void prepare(View target) {
    ViewGroup parent = (ViewGroup) target.getParent();
    int distance = parent.getHeight() - target.getTop();
    getAnimatorAgent().playTogether(
            ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1),
            ObjectAnimator.ofFloat(target, "scaleX", 0.1f, 0.475f, 1),
            ObjectAnimator.ofFloat(target, "scaleY", 0.1f, 0.475f, 1),
            ObjectAnimator.ofFloat(target, "translationY", distance, -60, 0)
    );
}
 
Example 15
Project: fragmentnav   File: FragmentTaskManager.java   View Source Code Vote up 6 votes
private void syncFragmentViewState(Fragment fragment) {
    final View view = fragment.getView();
    if(view != null){
        ViewGroup viewGroup = (ViewGroup) view.getParent();
        if (viewGroup != null && viewGroup.getChildAt(viewGroup.getChildCount() - 1) != fragment.getView()) {
            viewGroup.removeView(view);
            viewGroup.addView(view);
        }
    }

}
 
Example 16
Project: Hello-Music-droid   File: ViewDragHelper.java   View Source Code Vote up 6 votes
/**
 * 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 17
Project: JewelryUI   File: ViewUtil.java   View Source Code Vote up 5 votes
public static int getRelativeTop(View view) {
    if (view.getParent() == view.getRootView())
        return view.getTop();
    else
        return view.getTop() + getRelativeTop((View) view.getParent());
}
 
Example 18
Project: DownloadableCalligraphy   File: CalligraphyFactory.java   View Source Code Vote up 5 votes
protected static boolean parentIsToolbarV7(View view) {
    return CalligraphyUtils.canCheckForV7Toolbar() && view.getParent() != null && (view.getParent() instanceof android.support.v7.widget.Toolbar);
}
 
Example 19
Project: Swift-Braille-Soft-keyboard   File: Common.java   View Source Code Vote up 5 votes
public static int getRelativeLeft(View myView) {
    if (myView.getParent() == myView.getRootView())
        return myView.getLeft();
    else
        return myView.getLeft() + getRelativeLeft((View) myView.getParent());
}
 
Example 20
Project: NanoIconPack   File: SimplePageTransformer.java   View Source Code Vote up 5 votes
private void setTranslation(View view) {
    ViewPager viewPager = (ViewPager) view.getParent();
    int scroll = viewPager.getScrollX() - view.getLeft();
    view.setTranslationX(scroll);
}