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:android.support.v7.internal.view.menu.ActionMenuPresenter.java

@Override
public void updateMenuView(boolean cleared) {
    super.updateMenuView(cleared);

    if (mMenuView == null) {
        return;// w  ww  .j  av a2  s  . com
    }

    if (mMenu != null) {
        final ArrayList<MenuItemImpl> actionItems = mMenu.getActionItems();
        final int count = actionItems.size();
        for (int i = 0; i < count; i++) {
            final ActionProvider provider = actionItems.get(i).getSupportActionProvider();
            if (provider != null) {
                provider.setSubUiVisibilityListener(this);
            }
        }
    }

    final ArrayList<MenuItemImpl> nonActionItems = mMenu != null ? mMenu.getNonActionItems() : null;

    boolean hasOverflow = false;
    if (mReserveOverflow && nonActionItems != null) {
        final int count = nonActionItems.size();
        if (count == 1) {
            hasOverflow = !nonActionItems.get(0).isActionViewExpanded();
        } else {
            hasOverflow = count > 0;
        }
    }

    if (hasOverflow) {
        if (mOverflowButton == null) {
            mOverflowButton = new OverflowMenuButton(mSystemContext);
        }
        ViewGroup parent = (ViewGroup) mOverflowButton.getParent();
        if (parent != mMenuView) {
            if (parent != null) {
                parent.removeView(mOverflowButton);
            }
            ActionMenuView menuView = (ActionMenuView) mMenuView;
            menuView.addView(mOverflowButton, menuView.generateOverflowButtonLayoutParams());
        }
    } else if (mOverflowButton != null && mOverflowButton.getParent() == mMenuView) {
        ((ViewGroup) mMenuView).removeView(mOverflowButton);
    }

    ((ActionMenuView) mMenuView).setOverflowReserved(mReserveOverflow);
}

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

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

        epmtyTextView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
        userSelectEditText = (EditText) fragmentView.findViewById(R.id.bubble_input_text);
        countTextView = (TextView) fragmentView.findViewById(R.id.bubble_counter_text);
        if (Build.VERSION.SDK_INT >= 11) {
            userSelectEditText.setTextIsSelectable(false);
        }/*from www  .j  a  v  a 2 s . c  o  m*/
        userSelectEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
                if (!ignoreChange) {
                    beforeChangeIndex = userSelectEditText.getSelectionStart();
                    changeString = new SpannableString(charSequence);
                }
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!ignoreChange) {
                    boolean search = false;
                    int afterChangeIndex = userSelectEditText.getSelectionEnd();
                    if (editable.toString().length() < changeString.toString().length()) {
                        String deletedString = "";
                        try {
                            deletedString = changeString.toString().substring(afterChangeIndex,
                                    beforeChangeIndex);
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                        if (deletedString.length() > 0) {
                            if (searching && searchWas) {
                                search = true;
                            }
                            Spannable span = userSelectEditText.getText();
                            for (int a = 0; a < allSpans.size(); a++) {
                                Emoji.XImageSpan sp = allSpans.get(a);
                                if (span.getSpanStart(sp) == -1) {
                                    allSpans.remove(sp);
                                    selectedContacts.remove(sp.uid);
                                }
                            }
                            if (selectedContacts.isEmpty()) {
                                doneTextView.setText(getStringEntry(R.string.Done));
                            } else {
                                doneTextView.setText(
                                        getStringEntry(R.string.Done) + " (" + selectedContacts.size() + ")");
                            }
                            countTextView.setText(selectedContacts.size() + "/200");
                            listView.invalidateViews();
                        } else {
                            search = true;
                        }
                    } else {
                        search = true;
                    }
                    if (search) {
                        String text = userSelectEditText.getText().toString().replace("<", "");
                        if (text.length() != 0) {
                            searchDialogs(text);
                            searching = true;
                            searchWas = true;
                            epmtyTextView.setText(getStringEntry(R.string.NoResult));
                            listViewAdapter.notifyDataSetChanged();
                        } else {
                            searchResult = null;
                            searchResultNames = null;
                            searching = false;
                            searchWas = false;
                            epmtyTextView.setText(getStringEntry(R.string.NoContacts));
                            listViewAdapter.notifyDataSetChanged();
                        }
                    }
                }
            }
        });

        listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView);
        listView.setEmptyView(epmtyTextView);
        listView.setVerticalScrollBarEnabled(false);

        listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                TLRPC.User user;
                int section = listViewAdapter.getSectionForPosition(i);
                int row = listViewAdapter.getPositionInSectionForPosition(i);
                if (searching && searchWas) {
                    user = searchResult.get(row);
                } else {
                    ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict
                            .get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
                    user = MessagesController.Instance.users.get(arr.get(row).user_id);
                    listView.invalidateViews();
                }
                if (selectedContacts.containsKey(user.id)) {
                    Emoji.XImageSpan span = selectedContacts.get(user.id);
                    selectedContacts.remove(user.id);
                    SpannableStringBuilder text = new SpannableStringBuilder(userSelectEditText.getText());
                    text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                    allSpans.remove(span);
                    ignoreChange = true;
                    userSelectEditText.setText(text);
                    userSelectEditText.setSelection(text.length());
                    ignoreChange = false;
                } else {
                    if (selectedContacts.size() == 200) {
                        return;
                    }
                    ignoreChange = true;
                    Emoji.XImageSpan span = createAndPutChipForUser(user);
                    span.uid = user.id;
                    ignoreChange = false;
                }
                if (selectedContacts.isEmpty()) {
                    doneTextView.setText(getStringEntry(R.string.Done));
                } else {
                    doneTextView.setText(getStringEntry(R.string.Done) + " (" + selectedContacts.size() + ")");
                }
                countTextView.setText(selectedContacts.size() + "/200");
                if (searching || searchWas) {
                    searching = false;
                    searchWas = false;
                    epmtyTextView.setText(getStringEntry(R.string.NoContacts));

                    ignoreChange = true;
                    SpannableStringBuilder ssb = new SpannableStringBuilder("");
                    for (ImageSpan sp : allSpans) {
                        ssb.append("<<");
                        ssb.setSpan(sp, ssb.length() - 2, ssb.length(),
                                SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    userSelectEditText.setText(ssb);
                    userSelectEditText.setSelection(ssb.length());
                    ignoreChange = false;

                    listViewAdapter.notifyDataSetChanged();
                } else {
                    listView.invalidateViews();
                }
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:com.mk4droid.IMC_Activities.Fragment_Map.java

/**
 *            OnCreateView /*  w w  w  .j  ava2  s  .c o  m*/
 * 
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // ----- Inflate the view ---------
    if (vframelayout_main != null) {
        ViewGroup parent = (ViewGroup) vframelayout_main.getParent();
        parent.removeView(vframelayout_main);
    } else {
        vframelayout_main = inflater.inflate(R.layout.framelayout_map, container, false);
    }

    ctx = vframelayout_main.getContext();

    //------- Add fragment_map ----
    if (fmap_main == null) {
        fmap_main = SupportMapFragment.newInstance();
        FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
        fragmentTransaction.add(R.id.flmain, fmap_main);
        fragmentTransaction.commit();
    }

    getFragmentManager().addOnBackStackChangedListener(new OnBackStackChangedListener() {
        public void onBackStackChanged() {
            if (fmap_main == null && !Fragment_Issue_Details.isVisible && FActivity_TabHost.IndexGroup == 0) {
                onResume();
            }
        }
    });

    //-----------------------------
    pbgeneral = (ProgressBar) vframelayout_main.findViewById(R.id.pbgeneral);
    pbgeneral.bringToFront();

    //---- Bind Location Service --------------
    IntLocServ = new Intent(ctx, Service_Location.class);

    if (!isLocServBound && FActivity_TabHost.IndexGroup == 0)
        ctx.bindService(IntLocServ, mLocConnection, Context.BIND_AUTO_CREATE);

    FActivity_TabHost.IndexGroup = 0;

    //-----Start Data Service ------------
    IntDataServ = new Intent(ctx, Service_Data.class);
    ctx.startService(IntDataServ);

    return vframelayout_main;
}

From source file:at.alladin.rmbt.android.adapter.result.RMBTResultPagerAdapter.java

/**
* 
*//*from  w w w. ja v a 2 s . c om*/
@Override
public void destroyItem(final ViewGroup vg, final int i, final Object obj) {
    final View view = (View) obj;
    vg.removeView(view);
}

From source file:com.cranberrygame.cordova.plugin.ad.admob.Util.java

private void _preloadBannerAd_split() {
    if (bannerView != null) {
        //if banner is showing
        ViewGroup parentView = (ViewGroup) bannerView.getParent();
        if (parentView != null) {
            parentView.removeView(bannerView);
            bannerView.destroy();//from  ww  w.j  a  v a  2 s. co  m
            bannerView = null;
        }
    }
}

From source file:com.cranberrygame.cordova.plugin.ad.admob.Util.java

private void _hideBannerAd_split() {
    if (bannerView != null) {
        //if banner is showing
        ViewGroup parentView = (ViewGroup) bannerView.getParent();
        if (parentView != null) {
            parentView.removeView(bannerView);
            bannerView.destroy();/*w w  w. j a va 2  s .c  o m*/
            bannerView = null;
        }
    }
}

From source file:net.evecom.androidecssp.activity.EmergencyNotification.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.emergency_info_activity);

    //1/*from   w w  w.ja  v  a  2  s  . co m*/
    viewpager = (ViewPager) findViewById(R.id.my_viewpager_id);
    //4DepthPageTransformer
    //      viewpager.setPageTransformer(true, new DepthPageTransformer());
    viewpager.setPageTransformer(true, new RotateDownTransformer());
    //2
    viewpager.setAdapter(new PagerAdapter() {
        @Override //item   page
        public Object instantiateItem(ViewGroup container, int position) {
            //    switchpage
            ImageView imageView = new ImageView(EmergencyNotification.this);
            imageView.setImageResource(imagesId[position]);
            //
            imageView.setScaleType(ScaleType.CENTER_CROP);

            //imageViewcontainer  page
            container.addView(imageView);
            //imageViewlist
            imageViews.add(imageView);
            //imageView
            return imageView;
        }

        @Override //destroyItem
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(imageViews.get(position));
        }

        @Override //  adapter
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override //
        public int getCount() {
            return imagesId.length;
        }
    });

}

From source file:com.yahala.ui.GroupCreateActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {

        searching = false;//  www. ja va2s . c  o m
        searchWas = false;

        fragmentView = inflater.inflate(R.layout.group_create_layout, container, false);

        emptyTextView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
        emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
        userSelectEditText = (EditText) fragmentView.findViewById(R.id.bubble_input_text);
        userSelectEditText.setHint(LocaleController.getString("SendMessageTo", R.string.SendMessageTo));
        if (Build.VERSION.SDK_INT >= 11) {
            userSelectEditText.setTextIsSelectable(false);
        }
        userSelectEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
                if (!ignoreChange) {
                    beforeChangeIndex = userSelectEditText.getSelectionStart();
                    changeString = new SpannableString(charSequence);
                }
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!ignoreChange) {
                    boolean search = false;
                    int afterChangeIndex = userSelectEditText.getSelectionEnd();
                    if (editable.toString().length() < changeString.toString().length()) {
                        String deletedString = "";
                        try {
                            deletedString = changeString.toString().substring(afterChangeIndex,
                                    beforeChangeIndex);
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                        if (deletedString.length() > 0) {
                            if (searching && searchWas) {
                                search = true;
                            }
                            Spannable span = userSelectEditText.getText();
                            for (int a = 0; a < allSpans.size(); a++) {
                                XImageSpan sp = allSpans.get(a);
                                if (span.getSpanStart(sp) == -1) {
                                    allSpans.remove(sp);
                                    selectedContacts.remove(sp.jid);
                                }
                            }
                            if (parentActivity != null) {
                                ActionBar actionBar = parentActivity.getSupportActionBar();
                                actionBar.setSubtitle(String.format("%d/200 %s", selectedContacts.size(),
                                        LocaleController.getString("Members", R.string.Members)));
                            }
                            listView.invalidateViews();
                        } else {
                            search = true;
                        }
                    } else {
                        search = true;
                    }
                    if (search) {
                        String text = userSelectEditText.getText().toString().replace("<", "");
                        if (text.length() != 0) {
                            searchDialogs(text);
                            searching = true;
                            searchWas = true;
                            emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
                            listViewAdapter.notifyDataSetChanged();
                        } else {
                            searchResult = null;
                            searchResultNames = null;
                            searching = false;
                            searchWas = false;
                            emptyTextView
                                    .setText(LocaleController.getString("NoContacts", R.string.NoContacts));
                            listViewAdapter.notifyDataSetChanged();
                        }
                    }
                }
            }
        });

        listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView);
        listView.setEmptyView(emptyTextView);
        listView.setVerticalScrollBarEnabled(false);

        listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                TLRPC.User user;
                int section = listViewAdapter.getSectionForPosition(i);
                int row = listViewAdapter.getPositionInSectionForPosition(i);
                if (searching && searchWas) {
                    user = searchResult.get(row);
                } else {
                    ArrayList<TLRPC.User> arr = com.yahala.xmpp.ContactsController
                            .getInstance().usersSectionsDict.get(
                                    com.yahala.xmpp.ContactsController.getInstance().sortedUsersSectionsArray
                                            .get(section));
                    user = com.yahala.xmpp.ContactsController.getInstance().friendsDict.get(arr.get(row).jid);
                    listView.invalidateViews();
                }
                if (selectedContacts.containsKey(user.jid)) {
                    XImageSpan span = selectedContacts.get(user.jid);
                    selectedContacts.remove(user.jid);
                    SpannableStringBuilder text = new SpannableStringBuilder(userSelectEditText.getText());
                    text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                    allSpans.remove(span);
                    ignoreChange = true;
                    userSelectEditText.setText(text);
                    userSelectEditText.setSelection(text.length());
                    ignoreChange = false;
                } else {
                    if (selectedContacts.size() == 200) {
                        return;
                    }
                    ignoreChange = true;
                    XImageSpan span = createAndPutChipForUser(user);
                    span.jid = user.jid;
                    ignoreChange = false;
                }
                if (parentActivity != null) {
                    ActionBar actionBar = parentActivity.getSupportActionBar();
                    actionBar.setSubtitle(String.format("%d/200 %s", selectedContacts.size(),
                            LocaleController.getString("Members", R.string.Members)));
                }
                if (searching || searchWas) {
                    searching = false;
                    searchWas = false;
                    emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));

                    ignoreChange = true;
                    SpannableStringBuilder ssb = new SpannableStringBuilder("");
                    for (ImageSpan sp : allSpans) {
                        ssb.append("<<");
                        ssb.setSpan(sp, ssb.length() - 2, ssb.length(),
                                SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    userSelectEditText.setText(ssb);
                    userSelectEditText.setSelection(ssb.length());
                    ignoreChange = false;

                    listViewAdapter.notifyDataSetChanged();
                } else {
                    listView.invalidateViews();
                }
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static void removeViewFromSuperView(final View view) {
    if (view == null)
        return;//from w w w .ja  v  a2s .  c  om
    ViewGroup parentViewGroup = (ViewGroup) view.getParent();
    if (parentViewGroup != null) {
        parentViewGroup.removeView(view);
    }
}

From source file:ru.tinkoff.acquiring.sdk.EnterCardFragment.java

private void removeSpace(ViewGroup container, View space) {
    if (space != null) {
        container.removeView(space);
    }
}