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

The following examples show how to use android.view.ViewGroup#getParent() . 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: BaseRootActivity.java    From Awesome-WanAndroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void initEventAndData() {
    mNormalView = (ViewGroup) findViewById(R.id.normal_view);
    if (mNormalView == null) {
        throw new IllegalStateException(
                "The subclass of RootActivity must contain a View named 'mNormalView'.");
    }
    if (!(mNormalView.getParent() instanceof ViewGroup)) {
        throw new IllegalStateException(
                "mNormalView's ParentView should be a ViewGroup.");
    }
    ViewGroup mParent = (ViewGroup) mNormalView.getParent();
    View.inflate(this, R.layout.loading_view, mParent);
    View.inflate(this, R.layout.error_view, mParent);
    mLoadingView = mParent.findViewById(R.id.loading_group);
    mErrorView = mParent.findViewById(R.id.error_group);
    TextView reloadTv = mErrorView.findViewById(R.id.error_reload_tv);
    reloadTv.setOnClickListener(v -> reload());
    mLoadingAnimation = mLoadingView.findViewById(R.id.loading_animation);
    mErrorView.setVisibility(View.GONE);
    mLoadingView.setVisibility(View.GONE);
    mNormalView.setVisibility(View.VISIBLE);
}
 
Example 2
Source File: Toolbar.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    // If the container is a cluster, unmark itself as a cluster to avoid having nested
    // clusters.
    ViewParent parent = getParent();
    while (parent != null && parent instanceof ViewGroup) {
        final ViewGroup vgParent = (ViewGroup) parent;
        if (vgParent.isKeyboardNavigationCluster()) {
            setKeyboardNavigationCluster(false);
            if (vgParent.getTouchscreenBlocksFocus()) {
                setTouchscreenBlocksFocus(false);
            }
            break;
        }
        parent = vgParent.getParent();
    }
}
 
Example 3
Source File: ShareMessageFragment.java    From TestChat with Apache License 2.0 6 votes vote down vote up
@Override
public void onCommentItemClick(View view, String id, int shareMessagePosition, int position, String replyUser) {
        LogUtil.e("位置" + shareMessagePosition);
        currentPosition = shareMessagePosition;
        currentCommentPosition = position;
        ViewParent viewParent = view.getParent();
        if (viewParent != null) {
                ViewGroup parent = (ViewGroup) viewParent;
                commentItemOffset += parent.getHeight() - view.getBottom();
                if (parent.getParent() != null) {
                        ViewGroup rootParent = (ViewGroup) parent.getParent();
                        commentItemOffset += rootParent.getHeight() + parent.getBottom();
                }
        }
        this.replyUid = replyUser;
        dealBottomView(true);
}
 
Example 4
Source File: UserDetailActivity.java    From TestChat with Apache License 2.0 6 votes vote down vote up
@Override
public void onCommentItemClick(View view, String id, int shareMessagePosition, int commentPosition, String replyUid) {
        LogUtil.e("位置" + shareMessagePosition);
        currentPosition = shareMessagePosition;
        currentCommentPosition = commentPosition;
        ViewParent viewParent = view.getParent();
        if (viewParent != null) {
                ViewGroup parent = (ViewGroup) viewParent;
                commentItemOffset += parent.getHeight() - view.getBottom();
                if (parent.getParent() != null) {
                        ViewGroup rootParent = (ViewGroup) parent.getParent();
                        commentItemOffset += rootParent.getHeight() + parent.getBottom();
                }
        }
        this.replyUid = replyUid;
        dealBottomView(true);
}
 
Example 5
Source File: HighLight.java    From Highlight with Apache License 2.0 6 votes vote down vote up
@Override
public HighLight remove() {
    if (getHightLightView() == null) return this;
    ViewGroup parent = (ViewGroup) mHightLightView.getParent();
    if (parent instanceof RelativeLayout || parent instanceof FrameLayout) {
        parent.removeView(mHightLightView);
    } else {
        parent.removeView(mHightLightView);
        View origin = parent.getChildAt(0);
        ViewGroup graParent = (ViewGroup) parent.getParent();
        graParent.removeView(parent);
        graParent.addView(origin, parent.getLayoutParams());
    }
    mHightLightView = null;

    sendRemoveMessage();
    mShowing = false;
    return this;
}
 
Example 6
Source File: PagedView.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Hook up the page indicator
    ViewGroup parent = (ViewGroup) getParent();
    ViewGroup grandParent = (ViewGroup) parent.getParent();
    if (mPageIndicator == null && mPageIndicatorViewId > -1) {
        mPageIndicator = (PageIndicator) grandParent.findViewById(mPageIndicatorViewId);
        mPageIndicator.removeAllMarkers(mAllowPagedViewAnimations);

        ArrayList<PageIndicator.PageMarkerResources> markers =
                new ArrayList<PageIndicator.PageMarkerResources>();
        for (int i = 0; i < getChildCount(); ++i) {
            markers.add(getPageIndicatorMarker(i));
        }

        mPageIndicator.addMarkers(markers, mAllowPagedViewAnimations);

        OnClickListener listener = getPageIndicatorClickListener();
        if (listener != null) {
            mPageIndicator.setOnClickListener(listener);
        }
        mPageIndicator.setContentDescription(getPageIndicatorDescription());
    }
}
 
Example 7
Source File: Controller.java    From NewbieGuide with Apache License 2.0 6 votes vote down vote up
/**
 * 中断引导层的显示,后续未显示的page将不再显示
 */
public void remove() {
    if (currentLayout != null && currentLayout.getParent() != null) {
        ViewGroup parent = (ViewGroup) currentLayout.getParent();
        parent.removeView(currentLayout);
        //移除anchor添加的frameLayout
        if (!(parent instanceof FrameLayout)) {
            ViewGroup original = (ViewGroup) parent.getParent();
            View anchor = parent.getChildAt(0);
            parent.removeAllViews();
            if (anchor != null) {
                if (indexOfChild > 0) {
                    original.addView(anchor, indexOfChild, parent.getLayoutParams());
                } else {
                    original.addView(anchor, parent.getLayoutParams());
                }
            }
        }
        if (onGuideChangedListener != null) {
            onGuideChangedListener.onRemoved(this);
        }
        currentLayout = null;
    }
    isShowing = false;
}
 
Example 8
Source File: BoardView.java    From BoardView with Apache License 2.0 6 votes vote down vote up
public void notifyDataSetChanged(){
    for(int column_pos = 0; column_pos < boardAdapter.columns.size(); column_pos++) {
        if(boardAdapter.columns.get(column_pos).header != null) {
            ViewGroup parent_header = removeParent(boardAdapter.columns.get(column_pos).header);
            boardAdapter.columns.get(column_pos).header = boardAdapter.createHeaderView(getContext(), boardAdapter.columns.get(column_pos).header_object, column_pos);
            parent_header.addView(boardAdapter.columns.get(column_pos).header);
            ViewGroup layout = (ViewGroup)parent_header.getParent();
            boardAdapter.columns.get(column_pos).header.setOnClickListener(createHeaderOnClickListener(layout));
            boardAdapter.columns.get(column_pos).header.setOnLongClickListener(createHeaderOnLongClickListener(parent_header,layout));

        }
        if(boardAdapter.columns.get(column_pos).footer != null) {
            ViewGroup parent_footer = removeParent(boardAdapter.columns.get(column_pos).footer);
            boardAdapter.columns.get(column_pos).footer = boardAdapter.createFooterView(getContext(), boardAdapter.columns.get(column_pos).footer_object, column_pos);
            parent_footer.addView(boardAdapter.columns.get(column_pos).footer);
        }
    }
}
 
Example 9
Source File: MadgeModule.java    From debugdrawer with Apache License 2.0 6 votes vote down vote up
public void attach(Activity activity, ViewGroup content){
    madgeFrameLayout = new MadgeFrameLayout(activity);

    ViewGroup parent = (ViewGroup) content.getParent();
    parent.removeView(content);
    parent.addView(madgeFrameLayout,0);
    madgeFrameLayout.addView(content);

    boolean gridEnabled = pixelGridEnabled.get();
    madgeFrameLayout.setOverlayEnabled(gridEnabled);
    uiPixelGridElement.setChecked(gridEnabled);
    uiPixelRatioElement.setEnabled(gridEnabled);

    boolean ratioEnabled = pixelRatioEnabled.get();
    madgeFrameLayout.setOverlayRatioEnabled(ratioEnabled);
    uiPixelRatioElement.setChecked(ratioEnabled);
}
 
Example 10
Source File: ViewAndroidDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return An anchor view that can be used to anchor decoration views like Autofill popup.
 */
@CalledByNative
public View acquireView() {
    ViewGroup containerView = getContainerView();
    if (containerView == null || containerView.getParent() == null) return null;
    View anchorView = new View(containerView.getContext());
    containerView.addView(anchorView);
    return anchorView;
}
 
Example 11
Source File: LabelView.java    From labelview with Apache License 2.0 5 votes vote down vote up
public void remove() {
    if (getParent() == null || _labelViewContainerID == -1) {
        return;
    }

    ViewGroup frameContainer = (ViewGroup) getParent();
    assert (frameContainer.getChildCount() == 2);
    View target = frameContainer.getChildAt(0);

    ViewGroup parentContainer = (ViewGroup) frameContainer.getParent();
    int groupIndex = parentContainer.indexOfChild(frameContainer);
    if (frameContainer.getParent() instanceof RelativeLayout) {
        for (int i = 0; i < parentContainer.getChildCount(); i++) {
            if (i == groupIndex) {
                continue;
            }
            View view = parentContainer.getChildAt(i);
            RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams) view.getLayoutParams();
            for (int j = 0; j < para.getRules().length; j++) {
                if (para.getRules()[j] == _labelViewContainerID) {
                    para.getRules()[j] = target.getId();
                }
            }
            view.setLayoutParams(para);
        }
    }

    ViewGroup.LayoutParams frameLayoutParam = frameContainer.getLayoutParams();
    target.setLayoutParams(frameLayoutParam);
    parentContainer.removeViewAt(groupIndex);
    frameContainer.removeView(target);
    frameContainer.removeView(this);
    parentContainer.addView(target,groupIndex);
    _labelViewContainerID = -1;
}
 
Example 12
Source File: TipsUtils.java    From GankGirl with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void removeContainerView(ViewGroup tipsContainerView, View targetView) {
    ViewGroup parent = (ViewGroup) tipsContainerView.getParent();
    ViewGroup.LayoutParams targetParams = tipsContainerView.getLayoutParams();
    int index = parent.indexOfChild(tipsContainerView);
    parent.removeViewAt(index);
    if (targetView.getParent() != null) {
        ((ViewGroup) targetView.getParent()).removeView(targetView);
    }
    parent.addView(targetView, index, targetParams);
}
 
Example 13
Source File: StackController.java    From react-native-navigation with MIT License 5 votes vote down vote up
public void pop(Options mergeOptions, CommandListener listener) {
    if (!canPop()) {
        listener.onError("Nothing to pop");
        return;
    }

    peek().mergeOptions(mergeOptions);
    Options disappearingOptions = resolveCurrentOptions(presenter.getDefaultOptions());

    final ViewController disappearing = stack.pop();
    final ViewController appearing = stack.peek();

    disappearing.onViewWillDisappear();
    appearing.onViewWillAppear();

    ViewGroup appearingView = appearing.getView();
    if (appearingView.getLayoutParams() == null) {
        appearingView.setLayoutParams(matchParentWithBehaviour(new StackBehaviour(this)));
    }
    if (appearingView.getParent() == null) {
        getView().addView(appearingView, 0);
    }
    presenter.onChildWillAppear(this, appearing, disappearing);
    if (disappearingOptions.animations.pop.enabled.isTrueOrUndefined()) {
        animator.pop(disappearing.getView(), disappearingOptions.animations.pop, () -> finishPopping(disappearing, listener));
    } else {
        finishPopping(disappearing, listener);
    }
}
 
Example 14
Source File: FamiliarRecyclerView.java    From FamiliarRecyclerView with MIT License 4 votes vote down vote up
@Override
public void setAdapter(Adapter adapter) {
    // Only once
    if (mEmptyViewResId != -1) {
        if (null != getParent()) {
            ViewGroup parentView = ((ViewGroup) getParent());
            View tempEmptyView1 = parentView.findViewById(mEmptyViewResId);

            if (null != tempEmptyView1) {
                mEmptyView = tempEmptyView1;

                if (isKeepShowHeadOrFooter) parentView.removeView(tempEmptyView1);
            } else {
                ViewParent pParentView = parentView.getParent();
                if (pParentView instanceof ViewGroup) {
                    View tempEmptyView2 = ((ViewGroup) pParentView).findViewById(mEmptyViewResId);
                    if (null != tempEmptyView2) {
                        mEmptyView = tempEmptyView2;

                        if (isKeepShowHeadOrFooter)
                            ((ViewGroup) pParentView).removeView(tempEmptyView2);
                    }
                }
            }
        }
        mEmptyViewResId = -1;
    } else if (isKeepShowHeadOrFooter && null != mEmptyView) {
        ViewParent emptyViewParent = mEmptyView.getParent();
        if (emptyViewParent instanceof ViewGroup) {
            ((ViewGroup) emptyViewParent).removeView(mEmptyView);
        }
    }

    if (null == adapter) {
        if (null != mReqAdapter) {
            if (!isKeepShowHeadOrFooter) {
                mReqAdapter.unregisterAdapterDataObserver(mReqAdapterDataObserver);
            }
            mReqAdapter = null;
            mWrapFamiliarRecyclerViewAdapter = null;

            processEmptyView();
        }

        return;
    }

    mReqAdapter = adapter;
    mWrapFamiliarRecyclerViewAdapter = new FamiliarWrapRecyclerViewAdapter(this, adapter, mHeaderView, mFooterView, mLayoutManagerType);

    mWrapFamiliarRecyclerViewAdapter.setOnItemClickListener(mTempOnItemClickListener);
    mWrapFamiliarRecyclerViewAdapter.setOnItemLongClickListener(mTempOnItemLongClickListener);
    mWrapFamiliarRecyclerViewAdapter.setOnHeadViewBindViewHolderListener(mTempOnHeadViewBindViewHolderListener);
    mWrapFamiliarRecyclerViewAdapter.setOnFooterViewBindViewHolderListener(mTempOnFooterViewBindViewHolderListener);

    mReqAdapter.registerAdapterDataObserver(mReqAdapterDataObserver);
    super.setAdapter(mWrapFamiliarRecyclerViewAdapter);

    if (needInitAddItemDescration && null != mFamiliarDefaultItemDecoration) {
        needInitAddItemDescration = false;
        super.addItemDecoration(mFamiliarDefaultItemDecoration);
    }

    processEmptyView();
}
 
Example 15
Source File: ActionBarSherlockCompat.java    From android-apps with MIT License 4 votes vote down vote up
private ViewGroup generateLayout() {
    if (DEBUG) Log.d(TAG, "[generateLayout]");

    // Apply data from current theme.

    TypedArray a = mActivity.getTheme().obtainStyledAttributes(R.styleable.SherlockTheme);

    mIsFloating = a.getBoolean(R.styleable.SherlockTheme_android_windowIsFloating, false);

    if (!a.hasValue(R.styleable.SherlockTheme_windowActionBar)) {
        throw new IllegalStateException("You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.");
    }

    if (a.getBoolean(R.styleable.SherlockTheme_windowNoTitle, false)) {
        requestFeature(Window.FEATURE_NO_TITLE);
    } else if (a.getBoolean(R.styleable.SherlockTheme_windowActionBar, false)) {
        // Don't allow an action bar if there is no title.
        requestFeature(Window.FEATURE_ACTION_BAR);
    }

    if (a.getBoolean(R.styleable.SherlockTheme_windowActionBarOverlay, false)) {
        requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    }

    if (a.getBoolean(R.styleable.SherlockTheme_windowActionModeOverlay, false)) {
        requestFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
    }

    a.recycle();

    int layoutResource;
    if (!hasFeature(Window.FEATURE_NO_TITLE)) {
        if (mIsFloating) {
            //Trash original dialog LinearLayout
            mDecor = (ViewGroup)mDecor.getParent();
            mDecor.removeAllViews();

            layoutResource = R.layout.abs__dialog_title_holo;
        } else {
            if (hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY)) {
                layoutResource = R.layout.abs__screen_action_bar_overlay;
            } else {
                layoutResource = R.layout.abs__screen_action_bar;
            }
        }
    } else if (hasFeature(Window.FEATURE_ACTION_MODE_OVERLAY) && !hasFeature(Window.FEATURE_NO_TITLE)) {
        layoutResource = R.layout.abs__screen_simple_overlay_action_mode;
    } else {
        layoutResource = R.layout.abs__screen_simple;
    }

    if (DEBUG) Log.d(TAG, "[generateLayout] using screen XML " + mActivity.getResources().getString(layoutResource));
    View in = mActivity.getLayoutInflater().inflate(layoutResource, null);
    mDecor.addView(in, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));

    ViewGroup contentParent = (ViewGroup)mDecor.findViewById(R.id.abs__content);
    if (contentParent == null) {
        throw new RuntimeException("Couldn't find content container view");
    }

    //Make our new child the true content view (for fragments). VERY VOLATILE!
    mDecor.setId(View.NO_ID);
    contentParent.setId(android.R.id.content);

    if (hasFeature(Window.FEATURE_INDETERMINATE_PROGRESS)) {
        IcsProgressBar progress = getCircularProgressBar(false);
        if (progress != null) {
            progress.setIndeterminate(true);
        }
    }

    return contentParent;
}
 
Example 16
Source File: LinearBackStack.java    From backstack with Apache License 2.0 4 votes vote down vote up
private void forceRemoveView(BackStackNode backStackNode, ViewGroup viewGroup){
    ViewGroup parent = (ViewGroup) viewGroup.getParent();
    parent.removeView(viewGroup);
}
 
Example 17
Source File: FocusHelper.java    From TurboLauncher with Apache License 2.0 4 votes vote down vote up
/**
 * Handles key events in the workspace hotseat (bottom of the screen).
 */
static boolean handleHotseatButtonKeyEvent(View v, int keyCode, KeyEvent e, int orientation) {
    final ViewGroup parent = (ViewGroup) v.getParent();
    final ViewGroup launcher = (ViewGroup) parent.getParent();
    final Workspace workspace = (Workspace) launcher.findViewById(R.id.workspace);
    final int buttonIndex = parent.indexOfChild(v);
    final int buttonCount = parent.getChildCount();
    final int pageIndex = workspace.getCurrentPage();

    // NOTE: currently we don't special case for the phone UI in different
    // orientations, even though the hotseat is on the side in landscape mode.  This
    // is to ensure that accessibility consistency is maintained across rotations.

    final int action = e.getAction();
    final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
    boolean wasHandled = false;
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (handleKeyEvent) {
                // Select the previous button, otherwise snap to the previous page
                if (buttonIndex > 0) {
                    parent.getChildAt(buttonIndex - 1).requestFocus();
                } else {
                    workspace.snapToPage(pageIndex - 1);
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (handleKeyEvent) {
                // Select the next button, otherwise snap to the next page
                if (buttonIndex < (buttonCount - 1)) {
                    parent.getChildAt(buttonIndex + 1).requestFocus();
                } else {
                    workspace.snapToPage(pageIndex + 1);
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (handleKeyEvent) {
                // Select the first bubble text view in the current page of the workspace
                final CellLayout layout = (CellLayout) workspace.getChildAt(pageIndex);
                final ShortcutAndWidgetContainer children = layout.getShortcutsAndWidgets();
                final View newIcon = getIconInDirection(layout, children, -1, 1);
                if (newIcon != null) {
                    newIcon.requestFocus();
                } else {
                    workspace.requestFocus();
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            // Do nothing
            wasHandled = true;
            break;
        default: break;
    }
    return wasHandled;
}
 
Example 18
Source File: FolderIcon.java    From TurboLauncher with Apache License 2.0 4 votes vote down vote up
public boolean isDropEnabled() {
    final ViewGroup cellLayoutChildren = (ViewGroup) getParent();
    final ViewGroup cellLayout = (ViewGroup) cellLayoutChildren.getParent();
    final Workspace workspace = (Workspace) cellLayout.getParent();
    return !workspace.isSmall();
}
 
Example 19
Source File: LinearBackStack.java    From backstack with Apache License 2.0 4 votes vote down vote up
private void removeView(BackStackNode backStackNode, ViewGroup viewGroup){
    if (!backStackNode.shouldRetain){
        ViewGroup parent = (ViewGroup) viewGroup.getParent();
        parent.removeView(viewGroup);
    }
}
 
Example 20
Source File: FolderIcon.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
public boolean isDropEnabled() {
    final ViewGroup cellLayoutChildren = (ViewGroup) getParent();
    final ViewGroup cellLayout = (ViewGroup) cellLayoutChildren.getParent();
    final Workspace workspace = (Workspace) cellLayout.getParent();
    return !workspace.workspaceInModalState();
}