Example usage for android.view ViewGroup removeView

List of usage examples for android.view ViewGroup removeView

Introduction

In this page you can find the example usage for android.view ViewGroup removeView.

Prototype

@Override
public void removeView(View view) 

Source Link

Document

Note: do not invoke this method from #draw(android.graphics.Canvas) , #onDraw(android.graphics.Canvas) , #dispatchDraw(android.graphics.Canvas) or any related method.

Usage

From source file:org.telegram.ui.GroupCreateFinalActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {
        fragmentView = inflater.inflate(R.layout.group_create_final_layout, container, false);

        final ImageButton button2 = (ImageButton) fragmentView.findViewById(R.id.settings_change_avatar_button);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override/*  w  ww  .ja v  a  2 s  . co m*/
            public void onClick(View view) {

                AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);

                CharSequence[] items;

                if (avatar != null) {
                    items = new CharSequence[] { getStringEntry(R.string.FromCamera),
                            getStringEntry(R.string.FromGalley), getStringEntry(R.string.DeletePhoto) };
                } else {
                    items = new CharSequence[] { getStringEntry(R.string.FromCamera),
                            getStringEntry(R.string.FromGalley) };
                }

                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        if (i == 0) {
                            avatarUpdater.openCamera();
                        } else if (i == 1) {
                            avatarUpdater.openGallery();
                        } else if (i == 2) {
                            avatar = null;
                            uploadedAvatar = null;
                            avatarImage.setImage(avatar, "50_50", R.drawable.group_blue);
                        }
                    }
                });
                builder.show().setCanceledOnTouchOutside(true);
            }
        });

        avatarImage = (BackupImageView) fragmentView.findViewById(R.id.settings_avatar_image);

        nameTextView = (EditText) fragmentView.findViewById(R.id.bubble_input_text);
        listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView);
        listView.setAdapter(new ListAdapter(parentActivity));
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:com.taobao.weex.ui.component.list.template.TemplateStickyHelper.java

/**
 * dispatch scroll event, sticky  header
 * *//*from   ww w  . j a va  2s. com*/
public void onBeforeScroll(int dx, int dy) {
    if (stickyPositions == null || stickyPositions.size() == 0) {
        return;
    }
    BounceRecyclerView bounceRecyclerView = recyclerTemplateList.getHostView();
    RecyclerView recyclerView = recyclerTemplateList.getHostView().getInnerView();
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int firstVisiblePosition = -1;
    int lastVisiblePosition = -1;
    if (layoutManager instanceof LinearLayoutManager) {
        firstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
        lastVisiblePosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int[] firstVisibleItemPositions = new int[3];//max 3 column
        firstVisiblePosition = ((StaggeredGridLayoutManager) layoutManager)
                .findFirstVisibleItemPositions(firstVisibleItemPositions)[0];
        lastVisiblePosition = ((StaggeredGridLayoutManager) layoutManager)
                .findLastVisibleItemPositions(firstVisibleItemPositions)[0];
    }
    if (firstVisiblePosition < 0) {
        return;
    }

    TemplateViewHolder firstVisibleItemHolder = (TemplateViewHolder) recyclerView
            .findViewHolderForAdapterPosition(firstVisiblePosition);
    if (firstVisibleItemHolder == null) {
        return;
    }

    //find match sticky position
    int matchStickyPosition = -1;
    for (Integer headerPosition : stickyPositions) {
        if (headerPosition == null) {
            continue;
        }
        if (headerPosition <= firstVisiblePosition) {
            matchStickyPosition = Math.max(matchStickyPosition, headerPosition);
        } else {
            break;
        }
    }
    if (matchStickyPosition < 0) {
        //remove holder for match position not found
        View stickyFakeView = bounceRecyclerView.getChildAt(bounceRecyclerView.getChildCount() - 1);
        if (stickyFakeView.getTag() instanceof TemplateViewHolder) {
            TemplateViewHolder stickyFakeViewHolder = (TemplateViewHolder) stickyFakeView.getTag();
            bounceRecyclerView.removeView(stickyFakeViewHolder.itemView);
            stickyFakeViewHolder.itemView.setTranslationY(0);
            if (stickyFakeViewHolder.getComponent() != null
                    && stickyFakeViewHolder.getComponent().getDomObject() != null && stickyFakeViewHolder
                            .getComponent().getDomObject().getEvents().contains(Constants.Event.UNSTICKY)) {
                stickyFakeViewHolder.getComponent().fireEvent(Constants.Event.UNSTICKY);
            }
        }

        /**check has sticky cell not visible */
        for (int i = 0; i < recyclerView.getChildCount(); i++) {
            View itemView = recyclerView.getChildAt(i);
            TemplateViewHolder itemHolder = (TemplateViewHolder) recyclerView.getChildViewHolder(itemView);
            if (itemHolder == null) {
                continue;
            }
            int adapterPosition = itemHolder.getAdapterPosition();
            if (!stickyPositions.contains(adapterPosition)) {
                continue;
            }
            if (itemView.getVisibility() != View.VISIBLE) {
                itemView.setVisibility(View.VISIBLE);
            }
        }
        return;
    }

    //onCreate holder for match position if not exist
    View stickyFakeView = bounceRecyclerView.getChildAt(bounceRecyclerView.getChildCount() - 1);
    if (!(stickyFakeView.getTag() instanceof TemplateViewHolder)
            || ((TemplateViewHolder) stickyFakeView.getTag()).getHolderPosition() != matchStickyPosition) {

        //remove previous sticky header
        if (stickyFakeView.getTag() instanceof TemplateViewHolder
                && ((TemplateViewHolder) stickyFakeView.getTag()).getHolderPosition() != matchStickyPosition) {
            TemplateViewHolder stickyFakeViewHolder = (TemplateViewHolder) stickyFakeView.getTag();
            bounceRecyclerView.removeView(stickyFakeViewHolder.itemView);
            stickyFakeViewHolder.itemView.setTranslationY(0);
            if (stickyFakeViewHolder.getComponent() != null
                    && stickyFakeViewHolder.getComponent().getDomObject() != null && stickyFakeViewHolder
                            .getComponent().getDomObject().getEvents().contains(Constants.Event.UNSTICKY)) {
                stickyFakeViewHolder.getComponent().fireEvent(Constants.Event.UNSTICKY);
            }
        }

        //onCreate new sticky
        int stickyHolderType = recyclerTemplateList.getItemViewType(matchStickyPosition);
        TemplateViewHolder fakeStickyHolder = stickyHolderCache.get(stickyHolderType);
        if (fakeStickyHolder == null) {
            fakeStickyHolder = recyclerTemplateList.onCreateViewHolder(recyclerView, stickyHolderType);
            stickyHolderCache.put(stickyHolderType, fakeStickyHolder);
        }
        recyclerTemplateList.onBindViewHolder(fakeStickyHolder, matchStickyPosition);
        fakeStickyHolder.itemView.setTranslationY(0);
        fakeStickyHolder.itemView.setTag(fakeStickyHolder);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        fakeStickyHolder.getComponent().clearPreLayout();
        if (fakeStickyHolder.itemView.getParent() != null) {
            ViewGroup parent = (ViewGroup) fakeStickyHolder.itemView.getParent();
            parent.removeView(fakeStickyHolder.itemView);
        }
        bounceRecyclerView.addView(fakeStickyHolder.itemView, params);
        fakeStickyHolder.getComponent().setLayout(fakeStickyHolder.getComponent().getDomObject());
        stickyFakeView = fakeStickyHolder.itemView;
        if (fakeStickyHolder.getComponent() != null && fakeStickyHolder.getComponent().getDomObject() != null
                && fakeStickyHolder.getComponent().getDomObject().getEvents()
                        .contains(Constants.Event.STICKY)) {
            fakeStickyHolder.getComponent().fireEvent(Constants.Event.STICKY);
        }
    }
    TemplateViewHolder stickyFakeViewHolder = (TemplateViewHolder) stickyFakeView.getTag();
    for (int i = 0; i < recyclerView.getChildCount(); i++) {
        View itemView = recyclerView.getChildAt(i);
        TemplateViewHolder itemHolder = (TemplateViewHolder) recyclerView.getChildViewHolder(itemView);
        if (itemHolder == null) {
            continue;
        }
        int adapterPosition = itemHolder.getAdapterPosition();
        if (!stickyPositions.contains(adapterPosition)) {
            continue;
        }
        if (adapterPosition == stickyFakeViewHolder.getHolderPosition()) {
            if (itemView.getVisibility() != View.INVISIBLE) {
                itemView.setVisibility(View.INVISIBLE);
            }
        } else {
            if (itemView.getVisibility() != View.VISIBLE) {
                itemView.setVisibility(View.VISIBLE);
            }
        }
    }

    if (firstVisibleItemHolder.getComponent().isSticky()) {
        if (firstVisibleItemHolder.itemView.getY() < 0) {
            if (firstVisibleItemHolder.itemView.getVisibility() != View.INVISIBLE) {
                firstVisibleItemHolder.itemView.setVisibility(View.INVISIBLE);
            }
            if (stickyFakeView.getVisibility() != View.VISIBLE) {
                stickyFakeView.setVisibility(View.VISIBLE);
            }
            stickyFakeView.bringToFront();
        } else {
            if (firstVisibleItemHolder.itemView.getVisibility() != View.VISIBLE) {
                firstVisibleItemHolder.itemView.setVisibility(View.VISIBLE);
            }
            if (stickyFakeView.getVisibility() != View.GONE) {
                stickyFakeView.setVisibility(View.GONE);
            }
        }
    } else {
        if (stickyFakeView.getVisibility() != View.VISIBLE) {
            stickyFakeView.setVisibility(View.VISIBLE);
        }
    }

    //handle sticky is related, find next sticky position on screen
    int nextVisiblePostion = firstVisiblePosition + 1;
    if (lastVisiblePosition > 0) {
        for (int i = nextVisiblePostion; i <= lastVisiblePosition; i++) {
            if (stickyPositions.contains(i)) {
                nextVisiblePostion = i;
                break;
            }
        }
    }
    if (!stickyPositions.contains(nextVisiblePostion)) {
        if (stickyFakeViewHolder.itemView.getTranslationY() < 0) {
            stickyFakeViewHolder.itemView.setTranslationY(0);
        }
        return;
    }
    TemplateViewHolder nextStickyHolder = (TemplateViewHolder) recyclerView
            .findViewHolderForAdapterPosition(nextVisiblePostion);
    if (nextStickyHolder == null || nextStickyHolder.getComponent() == null) {
        return;
    }
    int translationY = (int) (nextStickyHolder.itemView.getY()
            - stickyFakeViewHolder.itemView.getMeasuredHeight());
    if (translationY <= 0) {
        stickyFakeViewHolder.itemView.setTranslationY(translationY);
    } else {
        stickyFakeViewHolder.itemView.setTranslationY(0);
    }
}

From source file:galilei.kelimekavanozu.activity.PoemBuilderActivity.java

private void moveView(ViewGroup from, ViewGroup to, View object) {
    from.removeView(object);
    to.addView(object);/* w  ww . j ava 2s  .c o  m*/
    object.setVisibility(View.VISIBLE);
    onWordMoved();
}

From source file:istat.android.freedev.pagers.adapters.abs.AbsPagerStateAdapter.java

private void LooperInstantiateItem(ViewGroup container, int position, Fragment fragment) {
    // TODO Auto-generated method stub
    if (fragment.getView() != null) {
        if (container == ((ViewGroup) fragment.getView().getParent()))
            container.removeView(fragment.getView());
        container.addView(fragment.getView());
    }//from  w  w  w .  j a v a 2s .  co  m
    Log.d("ADD", "is on :" + fragment.getTag());
}

From source file:galilei.kelimekavanozu.activity.PoemBuilderActivity.java

private void moveView(ViewGroup from, ViewGroup to, View object, int position) {
    from.removeView(object);
    to.addView(object, position);/*ww  w  .ja  va2 s.c o m*/
    object.setVisibility(View.VISIBLE);
    onWordMoved();
}

From source file:net.soulwolf.widget.parallaxrefresh.ParallaxScrollLayout.java

private void ensurePlaceholderView() {
    if (mParallaxTarget != null && mPlaceholderView == null) {
        // To avoid repetition and add PlaceholderView
        ViewGroup targetView = (ViewGroup) mParallaxTarget;
        View view = targetView.findViewById(R.id.psvPlaceholderView);
        if (view != null) {
            targetView.removeView(view);
        }//  w w  w.  ja v a2s  .  c o m
        int width = mParallaxHolder.getRealWidth();
        int height = getOriginalHeight();
        ViewGroup.LayoutParams params = generatePlaceholderLayoutParams(mParallaxTarget, width, height);
        // Due to system {@link android.widget.Space} minimum compatible to API 14,
        // the library minimum support API 9, so rewrite the View
        mPlaceholderView = new PlaceholderView(getContext());
        mPlaceholderView.setLayoutParams(params);
        mPlaceholderView.setId(R.id.psvPlaceholderView);
        ParallaxScrollObserver observer = (ParallaxScrollObserver) mParallaxTarget;
        observer.setPlaceholder(mPlaceholderView);
        observer.setScrollCallback(this);
    }
}

From source file:com.oprisnik.navdrawer.widget.NavDrawerLayout.java

public void setHeader(View header) {
    if (mNavdrawer != null) {
        ViewGroup contentHolder = (ViewGroup) mNavdrawer.findViewById(R.id.navdrawer_content_holder);
        if (mHeader != null) {
            // replace the header
            contentHolder.removeView(mHeader);
        }/*from   w ww. j  a  v a2 s . com*/
        mHeader = header;
        if (mHeader != null) {
            mHasHeader = true;
            contentHolder.addView(mHeader, 0);
        } else {
            mHasHeader = false;
        }
    }
}

From source file:org.huxizhijian.hhcomicviewer.adapter.GalleryViewPagerAdapter.java

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    ZoomImageView imageView = (ZoomImageView) object;
    //// w  w w . ja  v  a2s  .  com
    //            imageView.setImageInCenter();
    //
    imageView.setImageDrawable(null);
    imageView.setImageBitmap(null);
    releaseImageViewResource(imageView);
    //?
    container.removeView(imageView);
    //?
    mRecyclerImageViews.addLast(imageView);
}

From source file:com.arta.lib.widget.crouton.Manager.java

private void removeCroutonFromViewParent(Crouton crouton) {
    if (crouton.isShowing()) {
        ViewGroup parent = (ViewGroup) crouton.getView().getParent();
        if (null != parent) {
            parent.removeView(crouton.getView());
        }/*  w w w.ja v a  2  s .  c om*/
    }
}

From source file:co.edu.uniajc.vtf.content.MapSitesFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (coView != null) {
        ViewGroup parent = (ViewGroup) coView.getParent();
        if (parent != null)
            parent.removeView(coView);
    }/*from  w  w  w  .ja v  a 2s.  c om*/
    try {
        coView = inflater.inflate(R.layout.fragment_sites_map, container, false);
    } catch (InflateException e) {
        /* map is already there, just return view as it is */
    }
    return coView;
}