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:com.momock.outlet.tab.PagerTabOutlet.java

public void attach(TabHolder target) {
    Logger.check(target != null, "Parameter target cannot be null!");
    Logger.check(target.getTabContent() instanceof ViewPager,
            "The PagerTabOutlet must contains a ViewPager content!");
    this.target = target;
    final TabHost tabHost = target.getTabHost();
    final ViewPager tabContent = (ViewPager) target.getTabContent();
    plugs = getPlugs();//  ww  w  .j  ava 2 s .  c o  m

    ViewPager pager = (ViewPager) target.getTabContent();
    for (int i = 0; i < plugs.getItemCount(); i++) {
        ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof ViewHolder,
                "The plug of PagerTabOutlet must include a ViewHolder!");
        ((ViewHolder) plug.getContent()).reset();
    }
    pager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return plugs.getItemCount();
        }

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

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ITabPlug plug = (ITabPlug) plugs.getItem(position);
            View view = ((ViewHolder) plug.getContent()).getView();
            container.addView(view);
            return view;
        }

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

    tabContent.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            TabWidget widget = tabHost.getTabWidget();
            int oldFocusability = widget.getDescendantFocusability();
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            tabHost.setCurrentTab(position);
            widget.setDescendantFocusability(oldFocusability);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    tabHost.setup();
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            int index = tabHost.getCurrentTab();
            ITabPlug plug = (ITabPlug) plugs.getItem(index);
            setActivePlug(plug);
            tabContent.setCurrentItem(index, true);
        }
    });
    for (int i = 0; i < plugs.getItemCount(); i++) {
        final ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof ViewHolder,
                "Plug in PagerTabOutlet must contains a ViewHolder content!");

        TabHost.TabSpec spec = tabHost.newTabSpec("" + i);
        target.setTabIndicator(spec, plug);
        spec.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                View v = new View(tabHost.getContext());
                v.setMinimumWidth(0);
                v.setMinimumHeight(0);
                return v;
            }

        });
        tabHost.addTab(spec);
        if (getActivePlug() == plug)
            tabHost.setCurrentTab(i);
    }
}

From source file:jahirfiquitiva.iconshowcase.fragments.WallpapersFragment.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    setHasOptionsMenu(true);//w w w .  j a  v a2  s . co m
    context = getActivity();

    if (layout != null) {
        ViewGroup parent = (ViewGroup) layout.getParent();
        if (parent != null) {
            parent.removeView(layout);
        }
    }
    try {
        layout = (ViewGroup) inflater.inflate(R.layout.wallpapers_section, container, false);
    } catch (InflateException e) {
        // Do nothing
    }

    int light = ContextCompat.getColor(context, R.color.drawable_tint_dark);
    int dark = ContextCompat.getColor(context, R.color.drawable_tint_light);

    noConnection = (ImageView) layout.findViewById(R.id.no_connected_icon);
    mProgress = (ProgressBar) layout.findViewById(R.id.progress);
    mRecyclerView = (RecyclerView) layout.findViewById(R.id.wallsGrid);
    fastScroller = (RecyclerFastScroller) layout.findViewById(R.id.rvFastScroller);
    mSwipeRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.swipeRefreshLayout);

    if (!ShowcaseActivity.wallsPicker) {
        showWallsAdviceDialog(getActivity());
    }

    noConnection.setImageDrawable(new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_cloud_off)
            .color(ThemeUtils.darkTheme ? light : dark).sizeDp(144));
    noConnection.setVisibility(View.GONE);

    showProgressBar();

    setupRecyclerView(false, 0);

    mRecyclerView.setVisibility(View.GONE);

    mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(ThemeUtils.darkTheme ? dark : light);

    mSwipeRefreshLayout.setColorSchemeResources(
            ThemeUtils.darkTheme ? R.color.dark_theme_accent : R.color.light_theme_accent,
            ThemeUtils.darkTheme ? R.color.dark_theme_accent : R.color.light_theme_accent,
            ThemeUtils.darkTheme ? R.color.dark_theme_accent : R.color.light_theme_accent);

    mSwipeRefreshLayout.setEnabled(false);

    setupLayout(false, getActivity(), noConnection);

    return layout;

}

From source file:com.appeaser.sublimepickerlibrary.datepicker.DayPickerPagerAdapter.java

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    final ViewHolder holder = (ViewHolder) object;
    container.removeView(holder.container);

    mItems.remove(position);/*from   ww  w  .ja  va 2 s  .  c  o  m*/
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {
        fragmentView = inflater.inflate(R.layout.settings_blocked_users_layout, container, false);
        listViewAdapter = new ListAdapter(parentActivity);
        listView = (ListView) fragmentView.findViewById(R.id.listView);
        progressView = fragmentView.findViewById(R.id.progressLayout);
        emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
        emptyView.setText(LocaleController.getString("NoBlocked", R.string.NoBlocked));
        if (loading) {
            progressView.setVisibility(View.VISIBLE);
            emptyView.setVisibility(View.GONE);
            listView.setEmptyView(null);
        } else {//from   w w  w  .  ja va  2 s.  co m
            progressView.setVisibility(View.GONE);
            listView.setEmptyView(emptyView);
        }
        listView.setAdapter(listViewAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (i < blockedContacts.size()) {
                    UserProfileActivity fragment = new UserProfileActivity();
                    Bundle args = new Bundle();
                    args.putInt("user_id", blockedContacts.get(i).user_id);
                    fragment.setArguments(args);
                    ((LaunchActivity) parentActivity).presentFragment(fragment,
                            "user_" + blockedContacts.get(i).user_id, false);
                }
            }
        });

        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (i >= blockedContacts.size()) {
                    return true;
                }
                selectedUserId = blockedContacts.get(i).user_id;

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

                CharSequence[] items = new CharSequence[] {
                        LocaleController.getString("Unblock", R.string.Unblock) };

                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        if (i == 0) {
                            TLRPC.TL_contacts_unblock req = new TLRPC.TL_contacts_unblock();
                            TLRPC.User user = MessagesController.getInstance().users.get(selectedUserId);
                            if (user == null) {
                                return;
                            }
                            req.id = MessagesController.getInputUser(user);
                            TLRPC.TL_contactBlocked blocked = blockedContactsDict.get(selectedUserId);
                            blockedContactsDict.remove(selectedUserId);
                            blockedContacts.remove(blocked);
                            listViewAdapter.notifyDataSetChanged();
                            ConnectionsManager.getInstance().performRpc(req,
                                    new RPCRequest.RPCRequestDelegate() {
                                        @Override
                                        public void run(TLObject response, TLRPC.TL_error error) {

                                        }
                                    }, null, true, RPCRequest.RPCRequestClassGeneric);
                        }
                    }
                });
                builder.show().setCanceledOnTouchOutside(true);

                return true;
            }
        });

        listView.setOnTouchListener(new OnSwipeTouchListener() {
            public void onSwipeRight() {
                finishFragment(true);
            }
        });
        emptyView.setOnTouchListener(new OnSwipeTouchListener() {
            public void onSwipeRight() {
                finishFragment(true);
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:com.android.inputmethod.keyboard.emoji.EmojiPalettesAdapter.java

@Override
public void destroyItem(final ViewGroup container, final int position, final Object object) {
    if (DEBUG_PAGER) {
        Log.d(TAG, "destroy item: " + position + ", " + object.getClass().getSimpleName());
    }/*from w w  w .  j ava2  s .  co m*/
    final EmojiPageKeyboardView keyboardView = mActiveKeyboardViews.get(position);
    if (keyboardView != null) {
        keyboardView.deallocateMemory();
        mActiveKeyboardViews.remove(position);
    }
    if (object instanceof View) {
        container.removeView((View) object);
    } else {
        Log.w(TAG, "Warning!!! Emoji palette may be leaking. " + object);
    }
}

From source file:com.calciumion.widget.BasePagerAdapter.java

@Override
public final void finishUpdate(ViewGroup container) {
    ArrayList<View> recycledViews = new ArrayList<View>();

    // Remove views backing destroyed items from the specified container,
    // and queue them for recycling.
    for (int i = 0; destroyedItems.size() > 0 && i < container.getChildCount(); i++) {
        View v = container.getChildAt(i);
        Iterator<Object> it = destroyedItems.iterator();
        while (it.hasNext()) {
            if (isViewFromObject(v, it.next())) {
                container.removeView(v);
                recycledViews.add(v);//from  ww  w  .  j  a  v  a 2s.  c  o m
                it.remove();
                break;
            }
        }
    }

    // Render views and attach them to the container. Page views are reused
    // whenever possible.
    for (Object instantiatedItem : instantiatedItems) {
        View convertView = null;
        if (recycledViews.size() > 0)
            convertView = recycledViews.remove(0);
        convertView = getView(instantiatedItem, convertView, container);
        convertView.setTag(instantiatedItem);
        container.addView(convertView);
    }

    instantiatedItems.clear();
    recycledViews.clear();
}

From source file:com.pacific.adapter.BasePagerAdapter2.java

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    if (object instanceof View) {
        View view = (View) object;
        T item = get(position);//from  w  w  w .  j a va 2  s .c  o m
        ViewHolder holder = (ViewHolder) view.getTag(R.integer.adapter_holder);
        item.unbind(holder);
        container.removeView(view);
        cacheViews.add(view);
    }
}

From source file:com.google.android.apps.mytracks.fragments.MapFragment.java

@Override
public void onDestroyView() {
    super.onDestroyView();
    ViewGroup parentViewGroup = (ViewGroup) mapViewContainer.getParent();
    if (parentViewGroup != null) {
        parentViewGroup.removeView(mapViewContainer);
    }/*  ww  w.j av  a2s .  co  m*/
}

From source file:widgets.QuizWidget.java

private void restart() {
    this.setStartTime(System.currentTimeMillis() / 1000);

    quiz = new Quiz();
    quiz.load(quizContent);/*w  w  w  . j a  v  a 2  s.  c  om*/
    isOnResultsPage = false;

    // reload quiz layout
    View C = getView().findViewById(R.id.widget_quiz_results);
    ViewGroup parent = (ViewGroup) C.getParent();
    int index = parent.indexOfChild(C);
    parent.removeView(C);
    C = super.getActivity().getLayoutInflater().inflate(R.layout.widget_quiz, parent, false);
    parent.addView(C, index);

    prevBtn = (Button) getView().findViewById(R.id.mquiz_prev_btn);
    nextBtn = (Button) getView().findViewById(R.id.mquiz_next_btn);
    qText = (TextView) getView().findViewById(R.id.question_text);
    questionImage = (LinearLayout) getView().findViewById(R.id.question_image);
    questionImage.setVisibility(View.GONE);
    this.showQuestion();
}

From source file:com.wagos.calendarcard.RecyclePagerAdapter.java

@Override
public final void finishUpdate(ViewGroup container) {
    ArrayList<View> recycledViews = new ArrayList<>();

    // Remove views backing destroyed items from the specified container,
    // and queue them for recycling.
    for (int i = 0; destroyedItems.size() > 0 && i < container.getChildCount(); i++) {
        View v = container.getChildAt(i);
        Iterator<Object> it = destroyedItems.iterator();
        while (it.hasNext()) {
            if (isViewFromObject(v, it.next())) {
                container.removeView(v);
                recycledViews.add(v);/*from ww  w.  j  a va  2s.  c o  m*/
                it.remove();
                break;
            }
        }
    }

    // Render views and attach them to the container. Page views are reused
    // whenever possible.
    for (Object instantiatedItem : instantiatedItems) {
        View convertView = null;
        if (recycledViews.size() > 0)
            convertView = recycledViews.remove(0);

        if (convertView != null) {
            // Re-add existing view before rendering so that we can make change inside getView()
            container.addView(convertView);
            convertView = getView(instantiatedItem, convertView, container);
        } else {
            convertView = getView(instantiatedItem, null, container);
            container.addView(convertView);
        }

        // Set another tag id to not break ViewHolder pattern
        convertView.setTag(R.id.view_data, instantiatedItem);
    }

    instantiatedItems.clear();
    recycledViews.clear();
}