android.view.ViewParent Java Examples

The following examples show how to use android.view.ViewParent. 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 check out the related API usage on the sidebar.
Example #1
Source File: CardStreamLinearLayout.java    From android-BatchStepSensor with Apache License 2.0 6 votes vote down vote up
@Override
public void onChildViewAdded(final View parent, final View child) {

    Log.d(TAG, "child is added: " + child);

    ViewParent scrollView = parent.getParent();
    if (scrollView != null && scrollView instanceof ScrollView) {
        ((ScrollView) scrollView).fullScroll(FOCUS_DOWN);
    }

    if (getLayoutTransition() != null) {
        View view = child.findViewById(R.id.card_actionarea);
        if (view != null)
            view.setAlpha(0.f);
    }
}
 
Example #2
Source File: TestUtilsMatchers.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a matcher that matches {@link View}s based on the given parent type.
 *
 * @param parentMatcher the type of the parent to match on
 */
public static Matcher<View> isChildOfA(final Matcher<View> parentMatcher) {
  return new TypeSafeMatcher<View>() {
    @Override
    public void describeTo(Description description) {
      description.appendText("is child of a: ");
      parentMatcher.describeTo(description);
    }

    @Override
    public boolean matchesSafely(View view) {
      final ViewParent viewParent = view.getParent();
      if (!(viewParent instanceof View)) {
        return false;
      }
      if (parentMatcher.matches(viewParent)) {
        return true;
      }
      return false;
    }
  };
}
 
Example #3
Source File: StatusProvider.java    From StatusUI with Apache License 2.0 6 votes vote down vote up
public StatusProvider(Context context, String status, View contentView, OnStatusViewCreateCallback callback){

        this.mContext = context;
        this.status = status;
        this.contentView = contentView;
        this.callback = callback;
        if(contentView == null){
            throw new RuntimeException("contentView不能为null");
        }
        ViewParent p = this.contentView.getParent();
        if(p instanceof FrameLayout){
            this.container = (FrameLayout) p;
        }else{
            throw new RuntimeException(contentView.getClass().getName() + "必须作为FrameLayout的子元素");
        }
    }
 
Example #4
Source File: WebViewActivity.java    From ans-android-sdk with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onDestroy() {
    if (mWebView != null) {
        // 如果先调用destroy()方法,则会命中if (isDestroyed()) return;这一行代码,需要先onDetachedFromWindow(),再
        // destory()
        ViewParent parent = mWebView.getParent();
        if (parent != null) {
            ((ViewGroup) parent).removeView(mWebView);
        }
        mWebView.stopLoading();
        // 退出时调用此方法,移除绑定的服务,否则某些特定系统会报错
        mWebView.getSettings().setJavaScriptEnabled(false);
        mWebView.clearHistory();
        mWebView.clearView();
        mWebView.removeAllViews();
        mWebView.destroy();

    }
    super.onDestroy();
    AnalysysAgent.resetHybridModel(mContext, mWebView);
}
 
Example #5
Source File: PendIntentCompat.java    From container with GNU General Public License v3.0 6 votes vote down vote up
private Rect getRect(View view) {
	Rect rect = new Rect();
	rect.top = view.getTop();
	rect.left = view.getLeft();
	rect.right = view.getRight();
	rect.bottom = view.getBottom();

	ViewParent viewParent = view.getParent();
	if (viewParent != null) {
		if (viewParent instanceof ViewGroup) {
			Rect prect = getRect((ViewGroup) viewParent);
			rect.top += prect.top;
			rect.left += prect.left;
			rect.right += prect.left;
			rect.bottom += prect.top;
		}
	}
	return rect;
}
 
Example #6
Source File: CollapsingToolbarLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onAttachedToWindow() {
  super.onAttachedToWindow();

  // Add an OnOffsetChangedListener if possible
  final ViewParent parent = getParent();
  if (parent instanceof AppBarLayout) {
    // Copy over from the ABL whether we should fit system windows
    ViewCompat.setFitsSystemWindows(this, ViewCompat.getFitsSystemWindows((View) parent));

    if (onOffsetChangedListener == null) {
      onOffsetChangedListener = new OffsetUpdateListener();
    }
    ((AppBarLayout) parent).addOnOffsetChangedListener(onOffsetChangedListener);

    // We're attached, so lets request an inset dispatch
    ViewCompat.requestApplyInsets(this);
  }
}
 
Example #7
Source File: ExploreByTouchHelper.java    From letv with Apache License 2.0 6 votes vote down vote up
private boolean intersectVisibleToUser(Rect localRect) {
    if (localRect == null || localRect.isEmpty() || this.mView.getWindowVisibility() != 0) {
        return false;
    }
    ViewParent viewParent = this.mView.getParent();
    while (viewParent instanceof View) {
        View view = (View) viewParent;
        if (ViewCompat.getAlpha(view) <= 0.0f || view.getVisibility() != 0) {
            return false;
        }
        viewParent = view.getParent();
    }
    if (viewParent == null || !this.mView.getLocalVisibleRect(this.mTempVisibleRect)) {
        return false;
    }
    return localRect.intersect(this.mTempVisibleRect);
}
 
Example #8
Source File: ZSwipeItem.java    From AutoLoadListView with Apache License 2.0 6 votes vote down vote up
private void performAdapterViewItemClick(MotionEvent e) {
	ViewParent t = getParent();

	Log.d(TAG, "performAdapterViewItemClick()");

	while (t != null) {
		if (t instanceof AdapterView) {
			@SuppressWarnings("rawtypes")
			AdapterView view = (AdapterView) t;
			int p = view.getPositionForView(ZSwipeItem.this);
			if (p != AdapterView.INVALID_POSITION
					&& view.performItemClick(
					view.getChildAt(p
							- view.getFirstVisiblePosition()), p,
					view.getAdapter().getItemId(p)))
				return;
		} else {
			if (t instanceof View && ((View) t).performClick())
				return;
		}

		t = t.getParent();
	}
}
 
Example #9
Source File: Matcher.java    From marvel with MIT License 6 votes vote down vote up
public static org.hamcrest.Matcher<View> childAtPosition(
        final org.hamcrest.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 #10
Source File: WebviewActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onFragmentDestroy() {
    super.onFragmentDestroy();
    AndroidUtilities.cancelRunOnUIThread(typingRunnable);
    webView.setLayerType(View.LAYER_TYPE_NONE, null);
    typingRunnable = null;
    try {
        ViewParent parent = webView.getParent();
        if (parent != null) {
            ((FrameLayout) parent).removeView(webView);
        }
        webView.stopLoading();
        webView.loadUrl("about:blank");
        webView.destroy();
        webView = null;
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example #11
Source File: SkinCompatDelegate.java    From AndroidSkinAnimator with MIT License 6 votes vote down vote up
private boolean shouldInheritContext(ViewParent parent) {
    if (parent == null) {
        // The initial parent is null so just return false
        return false;
    }
    final View windowDecor = mAppCompatActivity.getWindow().getDecorView();
    while (true) {
        if (parent == null) {
            // Bingo. We've hit a view which has a null parent before being terminated from
            // the loop. This is (most probably) because it's the root view in an inflation
            // call, therefore we should inherit. This works as the inflated layout is only
            // added to the hierarchy at the end of the inflate() call.
            return true;
        } else if (parent == windowDecor || !(parent instanceof View)
                || ViewCompat.isAttachedToWindow((View) parent)) {
            // We have either hit the window's decor view, a parent which isn't a View
            // (i.e. ViewRootImpl), or an attached view, so we know that the original parent
            // is currently added to the view hierarchy. This means that it has not be
            // inflated in the current inflate() call and we should not inherit the context.
            return false;
        }
        parent = parent.getParent();
    }
}
 
Example #12
Source File: AndroidWrapperUIBridge.java    From CrossMobile with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
    public void setAttached(final View view, final boolean isAttached) {
        Native.system().runOnEventThread(() -> {
            ViewParent parent = view.getParent();
            boolean isAttachedNow = parent != null;
            if (isAttached == isAttachedNow)
                return;
            ActivityLifecycleListener listener = ((AndroidNativeWidget) view).getLifecycleListener();
            if (isAttachedNow) {
                MainView.current.removeView(view);
                if (listener != null) {
                    MainActivity.current.getStateListener().unregister(listener);
                    listener.onPause();
                    listener.onDestroy();
                }
            } else {
                MainView.current.addView(view);
                if (listener != null) {
                    MainActivity.current.getStateListener().register(listener);
                    listener.onCreate(MainActivity.current.getInstanceState());
                    listener.onResume();
                }
            }
//                AndroidGraphicsBridge.mainview.bringToFront();
        });
    }
 
Example #13
Source File: BottomSheetBehavior.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void settleToStatePendingLayout(@State int state) {
    final V child = viewRef.get();
    if (child == null) {
        return;
    }
    // Start the animation; wait until a pending layout if there is one.
    ViewParent parent = child.getParent();
    if (parent != null && parent.isLayoutRequested() && ViewCompat.isAttachedToWindow(child)) {
        final int finalState = state;
        child.post(
                new Runnable() {
                    @Override
                    public void run() {
                        settleToState(child, finalState);
                    }
                });
    } else {
        settleToState(child, state);
    }
}
 
Example #14
Source File: PullToRefreshAdapterViewBase.java    From Alibaba-Android-Certification with MIT License 5 votes vote down vote up
/**
 * 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 #15
Source File: SwipeBack.java    From SwipeBack with Apache License 2.0 5 votes vote down vote up
protected boolean isViewDescendant(View v) {
	ViewParent parent = v.getParent();
	while (parent != null) {
		if (parent == this) {
			return true;
		}

		parent = parent.getParent();
	}

	return false;
}
 
Example #16
Source File: SeekBarCompatDontCrash.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public static boolean isInScrollingContainer(ViewParent p) {
    while (p != null && p instanceof ViewGroup) {
        if (((ViewGroup) p).shouldDelayChildPressedState()) {
            return true;
        }
        p = p.getParent();
    }
    return false;
}
 
Example #17
Source File: BottomSheetBehaviorV2.java    From paper-launcher with MIT License 5 votes vote down vote up
/**
 * Sets the state of the bottom sheet. The bottom sheet will transition to that state with
 * animation.
 *
 * @param state One of {@link #STATE_COLLAPSED}, {@link #STATE_EXPANDED}, or
 *              {@link #STATE_HIDDEN}.
 */
public final void setState(final @State int state) {
    if (state == mState) {
        return;
    }
    if (mViewRef == null) {
        // The view is not laid out yet; modify mState and let onLayoutChild handle it later
        if (state == STATE_COLLAPSED || state == STATE_EXPANDED ||
                (mHideable && state == STATE_HIDDEN)) {
            mState = state;
        }
        return;
    }
    final V child = mViewRef.get();
    if (child == null) {
        return;
    }
    // Start the animation; wait until a pending layout if there is one.
    ViewParent parent = child.getParent();
    if (parent != null && parent.isLayoutRequested() && ViewCompat.isAttachedToWindow(child)) {
        child.post(new Runnable() {
            @Override
            public void run() {
                startSettlingAnimation(child, state);
            }
        });
    } else {
        startSettlingAnimation(child, state);
    }
}
 
Example #18
Source File: ZrcAbsListView.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void scrollIfNeeded(int x, int y) {
    final int rawDeltaY = y - mMotionY;
    final int deltaY = rawDeltaY - mMotionCorrection;
    int incrementalDeltaY = mLastY != Integer.MIN_VALUE ? y - mLastY : deltaY;
    if (mTouchMode == TOUCH_MODE_SCROLL) {
        if (y != mLastY) {
            if (Math.abs(rawDeltaY) > mTouchSlop) {
                final ViewParent parent = getParent();
                if (parent != null) {
                    parent.requestDisallowInterceptTouchEvent(true);
                }
            }
            boolean atEdge = false;
            if (incrementalDeltaY != 0) {
                atEdge = trackMotionScroll(deltaY, incrementalDeltaY);
            }
            if (atEdge) {
                if (mVelocityTracker != null) {
                    mVelocityTracker.clear();
                }
            }
            mMotionX = x;
            mMotionY = y;
            mLastY = y;
        }
    }
}
 
Example #19
Source File: SwipeLayout.java    From AndroidSwipeLayout with MIT License 5 votes vote down vote up
private AdapterView getAdapterView() {
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        return (AdapterView) t;
    }
    return null;
}
 
Example #20
Source File: NestedScrollView.java    From letv with Apache License 2.0 5 votes vote down vote up
private static boolean isViewDescendantOf(View child, View parent) {
    if (child == parent) {
        return true;
    }
    ViewParent theParent = child.getParent();
    if ((theParent instanceof ViewGroup) && isViewDescendantOf((View) theParent, parent)) {
        return true;
    }
    return false;
}
 
Example #21
Source File: NoteAdapter.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (listener != null) {
        ViewParent parent = v.getParent();
        if(parent instanceof RecyclerView){
            RecyclerView recyclerView = (RecyclerView)parent;
            for(int i=0; i < recyclerView.getChildCount(); i++){
                Utils.setElevation(recyclerView.getChildAt(i),5);
            }
        }

        return listener.onItemLongClicked(getAdapterPosition(), notes.get(getAdapterPosition()));
    }
    return false;
}
 
Example #22
Source File: EditTexts.java    From convalida with Apache License 2.0 5 votes vote down vote up
private static TextInputLayout getTextInputLayout(EditText editText) {
    ViewParent parent = editText.getParent();

    while (parent instanceof View) {
        if (parent instanceof TextInputLayout) {
            return (TextInputLayout) parent;
        }
        parent = parent.getParent();
    }

    return null;
}
 
Example #23
Source File: MxVideoPlayer.java    From MxVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
    Log.i(TAG, "onStartTrackingTouch: bottomProgress [" + this.hashCode() + "] ");
    cancelProgressTimer();
    ViewParent parent = getParent();
    while (parent != null) {
        parent.requestDisallowInterceptTouchEvent(true);
        parent = parent.getParent();
    }
}
 
Example #24
Source File: SlideFrameLayout.java    From AccountBook with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);
    copyNodeInfoNoChildren(info, superNode);
    superNode.recycle();

    info.setClassName(SlideFrameLayout.class.getName());
    info.setSource(host);

    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }

    // This is a best-approximation of addChildrenForAccessibility()
    // that accounts for filtering.
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (!filter(child) && (child.getVisibility() == View.VISIBLE)) {
            // Force importance to "yes" since we can't read the value.
            ViewCompat.setImportantForAccessibility(
                child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
            info.addChild(child);
        }
    }
}
 
Example #25
Source File: BookShelfSearchView.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private void initView(Context context) {
    LayoutInflater.from(context).inflate(R.layout.view_search_bookshelf, this, true);
    ButterKnife.bind(this);
    AppCompat.setToolbarNavIconTint(toolbar, getResources().getColor(R.color.colorBarText));
    toolbar.inflateMenu(R.menu.menu_search_view);
    MenuItem search = toolbar.getMenu().findItem(R.id.action_search);
    searchView = (SearchView) search.getActionView();
    AppCompat.useCustomIconForSearchView(searchView, getResources().getString(R.string.searchShelfBook));
    searchAutoComplete = searchView.findViewById(R.id.search_src_text);
    searchView.setMaxWidth(getResources().getDisplayMetrics().widthPixels);
    searchView.onActionViewExpanded();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            queryBooks(newText);
            return false;
        }
    });
    rvList.setLayoutManager(new LinearLayoutManager(context));
    adapter = new BookShelfListAdapter(context, -1, 1);
    rvList.setAdapter(adapter);

    toolbar.setNavigationOnClickListener(v -> {
        ViewParent parent = BookShelfSearchView.this.getParent();
        if (parent instanceof DrawerLayout) {
            ((DrawerLayout) parent).closeDrawers();
        }
    });
}
 
Example #26
Source File: TabVPFragActivity.java    From sa-sdk-android with Apache License 2.0 5 votes vote down vote up
private ViewPager findViewGroup(ViewParent parent) {
    if (parent == null) {
        return null;
    }
    if (parent instanceof ViewPager) {
        return (ViewPager) parent;
    }
    return findViewGroup(parent.getParent());
}
 
Example #27
Source File: VScaleLayoutManager.java    From SmoothRefreshLayout with MIT License 5 votes vote down vote up
@Override
public void resetLayout(
        @Nullable IRefreshView<IIndicator> header,
        @Nullable IRefreshView<IIndicator> footer,
        @Nullable View stickyHeader,
        @Nullable View stickyFooter,
        @Nullable View content) {
    View targetView = mLayout.getScrollTargetView();
    if (targetView != null) {
        if (targetView != content) {
            ViewParent parent = targetView.getParent();
            if (parent instanceof View) {
                View parentView = (View) parent;
                if (ViewCatcherUtil.isViewPager(parentView)) {
                    targetView = parentView;
                }
            }
        }
        if (ScrollCompat.canScaleInternal(targetView)) {
            View view = ((ViewGroup) targetView).getChildAt(0);
            view.setPivotY(0);
            view.setScaleY(1);
        } else {
            targetView.setPivotY(0);
            targetView.setScaleY(1);
        }
    }
}
 
Example #28
Source File: ViewControllerTest.java    From react-native-navigation with MIT License 5 votes vote down vote up
@Test
public void onAppear_CalledAtMostOnce() {
    ViewController spy = spy(uut);
    Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
    Assertions.assertThat(spy.getView()).isShown();
    spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
    spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
    spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();

    verify(spy, times(1)).onViewAppeared();
}
 
Example #29
Source File: FlexibleToolbarLayout.java    From AppCompat-Extension-Library with Apache License 2.0 5 votes vote down vote up
/**
 * Expands the {@link FlexibleToolbarLayout}.
 * This will only have an effect if the {@link FlexibleToolbarLayout}
 * is used as a child of {@link AppBarLayout}.
 */
public void expand() {
    // Passes call to AppBarLayout if possible
    ViewParent parent = getParent();
    if (parent instanceof AppBarLayout) {
        ((AppBarLayout) parent).setExpanded(true);
    }
}
 
Example #30
Source File: AdmobExpressAdapterWrapper.java    From admobadapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onAdFailed(int adIdx, int errorCode, Object adPayload) {
    NativeExpressAdView adView = (NativeExpressAdView)adPayload;
    if (adView != null) {
        ViewParent parent = adView.getParent();
        if(parent == null || parent instanceof ListView)
            adView.setVisibility(View.GONE);
        else {
            while (parent.getParent() != null && !(parent.getParent() instanceof ListView))
                parent = parent.getParent();
            ((View) parent).setVisibility(View.GONE);
        }
    }
    notifyDataSetChanged();
}