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.LocationActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {
        if (messageObject != null) {
            fragmentView = inflater.inflate(R.layout.location_view_layout, container, false);
        } else {/*from   ww  w  . ja  va2 s.  c  o  m*/
            fragmentView = inflater.inflate(R.layout.location_attach_layout, container, false);
        }

        avatarImageView = (BackupImageView) fragmentView.findViewById(R.id.location_avatar_view);
        nameTextView = (TextView) fragmentView.findViewById(R.id.location_name_label);
        distanceTextView = (TextView) fragmentView.findViewById(R.id.location_distance_label);
        bottomView = fragmentView.findViewById(R.id.location_bottom_view);
        sendButton = (TextView) fragmentView.findViewById(R.id.location_send_button);
        if (sendButton != null) {
            sendButton.setText(LocaleController.getString("SendLocation", R.string.SendLocation));
        }

        getChildFragmentManager().beginTransaction().replace(R.id.map_view, mapFragment).commit();
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:it.geosolutions.geocollect.android.core.form.FormPageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(TAG, "onCreateView(): container = " + container + "savedInstanceState = " + savedInstanceState);

    if (mScrollView == null) {
        // normally inflate the view hierarchy
        mScrollView = (ScrollView) inflater.inflate(R.layout.form_page_fragment, container, false);
        mFormView = (LinearLayout) mScrollView.findViewById(R.id.formcontent);
        mProgressView = (ProgressBar) mScrollView.findViewById(R.id.loading);
    } else {/*from  w  w  w. ja  va2  s .  c  o m*/
        // mScrollView is still attached to the previous view hierarchy
        // we need to remove it and re-attach it to the current one
        ViewGroup parent = (ViewGroup) mScrollView.getParent();
        parent.removeView(mScrollView);
    }
    return mScrollView;
}

From source file:com.tsoliveira.android.listeners.DragDropTouchListener.java

private void reset() {
    //Animate mobile view back to original position
    final View originalView = getViewByPosition(mobileViewCurrentPos);
    if (originalView != null && mobileView != null) {
        float y = getViewRawCoords(originalView)[1];
        mobileView.animate().y(y).setDuration(MOVE_DURATION).setListener(new AnimatorListenerAdapter() {
            @Override//from w w w.java  2s .  co  m
            public void onAnimationEnd(Animator animation) {

                if (mobileView != null) {
                    ViewCompat.animate(mobileView).z(ViewCompat.getZ(originalView)).setDuration(MOVE_DURATION)
                            .setListener(new ViewPropertyAnimatorListener() {
                                @Override
                                public void onAnimationStart(View view) {
                                }

                                @Override
                                public void onAnimationEnd(View view) {
                                    originalView.setVisibility(View.VISIBLE);
                                    ViewGroup parent = (ViewGroup) mobileView.getParent();
                                    parent.removeView(mobileView);
                                    mobileView = null;
                                }

                                @Override
                                public void onAnimationCancel(View view) {
                                }
                            }).start();
                }
            }
        });

    }

    dragging = false;
    mobileViewStartY = -1;
    mobileViewCurrentPos = -1;

}

From source file:com.csumax.maxgithubclient.fragment.ProgressFragment.java

public void setContentView(View view) {
    ensureContent();/*from   ww w  .j ava  2  s  . c o  m*/
    if (view == null) {
        throw new IllegalArgumentException("Content view can't be null");
    }
    if (mContentContainer instanceof ViewGroup) {
        ViewGroup contentContainer = (ViewGroup) mContentContainer;
        if (mContentView == null) {
            contentContainer.addView(view);
        } else {
            int index = contentContainer.indexOfChild(mContentView);
            // replace content view
            contentContainer.removeView(mContentView);
            contentContainer.addView(view, index);
        }
        mContentView = view;
    } else {
        throw new IllegalStateException("Can't be used with a custom content view");
    }
}

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

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

    String[] appsNames = getResources().getStringArray(R.array.apps_titles);
    String[] appsDescriptions = getResources().getStringArray(R.array.apps_descriptions);
    String[] appsIcons = getResources().getStringArray(R.array.apps_icons);
    String[] appsPackages = getResources().getStringArray(R.array.apps_packages);

    int names = appsNames.length, descs = appsDescriptions.length, icons = appsIcons.length,
            packs = appsPackages.length;

    if (names > 0 && names == descs && names == icons && names == packs) {
        hasAppsList = true;/* w  ww  . ja  va 2 s  .c  om*/
    }

    context = getActivity();

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

    fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);

    themeMode = getResources().getBoolean(R.bool.theme_mode);
    RecyclerView mRecyclerView = (RecyclerView) layout.findViewById(R.id.home_rv);

    if (!themeMode) {
        setupAndAnimateIcons(true, true, 600);

        GridLayout iconsRow = (GridLayout) getActivity().findViewById(R.id.iconsRow);

        iconsRow.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                ShowcaseActivity.SHUFFLE = true;
                setupAndAnimateIcons(true, true, 0);
            }
        });

    }

    if (hasAppsList) {
        for (int i = 0; i < appsNames.length; i++) {
            try {
                if (appsPackages[i].indexOf("http") != -1) { //checks if package is a site
                    homeCards.add(new HomeCard.Builder().context(getActivity()).title(appsNames[i])
                            .description(appsDescriptions[i])
                            .icon(ContextCompat.getDrawable(context,
                                    Utils.getIconResId(context, getResources(), context.getPackageName(),
                                            appsIcons[i], null)))
                            .onClickLink(appsPackages[i], false, false, null).build());
                    continue;
                }
                Intent intent;
                boolean isInstalled = Utils.isAppInstalled(context, appsPackages[i]);
                if (isInstalled) {
                    PackageManager pm = context.getPackageManager();
                    intent = pm.getLaunchIntentForPackage(appsPackages[i]);
                    if (intent != null) {
                        try {
                            homeCards.add(new HomeCard.Builder().context(getActivity()).title(appsNames[i])
                                    .description(appsDescriptions[i])
                                    .icon(ContextCompat.getDrawable(context,
                                            Utils.getIconResId(context, getResources(),
                                                    context.getPackageName(), appsIcons[i], null)))
                                    .onClickLink(appsPackages[i], true, true, intent).build());
                        } catch (Resources.NotFoundException e) {
                            if (ShowcaseActivity.DEBUGGING)
                                Utils.showLog(context, "There's no icon that matches name: " + appsIcons[i]);
                            homeCards.add(new HomeCard.Builder().context(getActivity()).title(appsNames[i])
                                    .description(appsDescriptions[i])
                                    .icon(ContextCompat.getDrawable(context,
                                            Utils.getIconResId(context, getResources(),
                                                    context.getPackageName(), "ic_na_launcher", null)))
                                    .onClickLink(appsPackages[i], true, true, intent).build());
                        }
                    }
                } else {
                    try {
                        homeCards.add(new HomeCard.Builder().context(getActivity()).title(appsNames[i])
                                .description(appsDescriptions[i])
                                .icon(ContextCompat.getDrawable(context,
                                        Utils.getIconResId(context, getResources(), context.getPackageName(),
                                                appsIcons[i], null)))
                                .onClickLink(appsPackages[i], true, false, null).build());
                    } catch (Resources.NotFoundException e) {
                        if (ShowcaseActivity.DEBUGGING)
                            Utils.showLog(context, "There's no icon that matches name: " + appsIcons[i]);
                        homeCards.add(new HomeCard.Builder().context(getActivity()).title(appsNames[i])
                                .description(appsDescriptions[i])
                                .icon(ContextCompat.getDrawable(context,
                                        Utils.getIconResId(context, getResources(), context.getPackageName(),
                                                "ic_na_launcher", null)))
                                .onClickLink(appsPackages[i], true, false, null).build());
                    }
                }
            } catch (IndexOutOfBoundsException e) {
                hasAppsList = false;
                if (ShowcaseActivity.DEBUGGING)
                    Utils.showLog(context, "Apps Cards arrays are inconsistent. Fix them.");
            }
        }
    }

    setupFAB();

    LinearLayoutManager layoutManager = new LinearLayoutManager(context);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), null,
            getResources().getDimensionPixelSize(R.dimen.dividers_height), false, true));
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.setHasFixedSize(true);

    HomeListAdapter mAdapter = new HomeListAdapter(homeCards, context, hasAppsList);
    mRecyclerView.setAdapter(mAdapter);

    return layout;
}

From source file:ir.besteveryeverapp.ui.ActionBar.BaseFragment.java

protected void setParentLayout(ActionBarLayout layout) {
    if (parentLayout != layout) {
        parentLayout = layout;//from   www.j  a va  2s  .c o m
        if (fragmentView != null) {
            ViewGroup parent = (ViewGroup) fragmentView.getParent();
            if (parent != null) {
                try {
                    parent.removeView(fragmentView);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
            if (parentLayout != null && parentLayout.getContext() != fragmentView.getContext()) {
                fragmentView = null;
            }
        }
        if (actionBar != null) {
            ViewGroup parent = (ViewGroup) actionBar.getParent();
            if (parent != null) {
                try {
                    parent.removeView(actionBar);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
            if (parentLayout != null && parentLayout.getContext() != actionBar.getContext()) {
                actionBar = null;
            }
        }
        if (parentLayout != null && actionBar == null) {
            actionBar = new ActionBar(parentLayout.getContext());
            actionBar.parentFragment = this;

            int pic = SkinMan.currentSkin.actionSmallPicture();
            // :ramin
            if (pic == 0)
                actionBar.setBackgroundColor(SkinMan.currentSkin.actionbarColor()//ColorUtils.getColor(R.color.primary)
                );
            else {
                Drawable d = ContextCompat.getDrawable(actionBar.getContext(), pic);
                Utils.setBackground(actionBar, d);
            }
            //actionBar.setBackgroundColor(0xff54759e);
            actionBar.setItemsBackgroundColor(//R.drawable.bar_selector_f
                    SkinMan.barSelector(parentLayout.getContext()));
        }
    }
}

From source file:nirwan.cordova.plugin.printer.Printer.java

private void loadContentAsBitmapIntoPrintController(String content, final Intent intent) {
    Activity ctx = cordova.getActivity();
    final WebView page = new WebView(ctx);
    final Printer self = this;

    page.setVisibility(View.INVISIBLE);
    page.getSettings().setJavaScriptEnabled(false);

    page.setWebViewClient(new WebViewClient() {
        @Override//from   w  w w  .j  a  v a2s  .  c  om
        public void onPageFinished(final WebView page, String url) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Bitmap screenshot = self.takeScreenshot(page);
                    File tmpFile = self.saveScreenshotToTmpFile(screenshot);
                    ViewGroup vg = (ViewGroup) (page.getParent());

                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tmpFile));

                    vg.removeView(page);
                }
            }, 1000);
        }
    });

    //Set base URI to the assets/www folder
    String baseURL = webView.getUrl();
    baseURL = baseURL.substring(0, baseURL.lastIndexOf('/') + 1);

    ctx.addContentView(page, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    page.loadDataWithBaseURL(baseURL, content, "text/html", "UTF-8", null);
}

From source file:com.momock.outlet.card.PagerCardOutlet.java

public void attach(ViewPager target) {
    refTarget = new WeakReference<ViewPager>(target);
    ViewPager pager = target;/*from   ww  w  .  j  av a  2s  . c  o m*/
    pager.setAdapter(new PagerAdapter() {

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

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

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

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });
    IDataList<IPlug> plugs = getPlugs();
    for (int i = 0; i < plugs.getItemCount(); i++) {
        ICardPlug plug = (ICardPlug) plugs.getItem(i);
        Logger.check(plug.getComponent() instanceof ViewHolder,
                "The plug of PagerCardOutlet must include a ViewHolder!");
        ((ViewHolder) plug.getComponent()).reset();
        if (plug == this.getActivePlug()) {
            onActivate(plug);
        }
    }
}

From source file:org.digitalcampus.oppia.widgets.FeedbackWidget.java

public void showResults() {

    if (!isOnResultsPage) {
        // log the activity as complete
        isOnResultsPage = true;/*  w  ww.j av  a 2s  .com*/
        this.saveTracker();

        // save results ready to send back to the quiz server
        String data = feedback.getResultObject().toString();
        DbHelper db = new DbHelper(super.getActivity());
        long userId = db.getUserId(prefs.getString(PrefsActivity.PREF_USER_NAME, ""));

        QuizAttempt qa = new QuizAttempt();
        qa.setCourseId(course.getCourseId());
        qa.setUserId(userId);
        qa.setData(data);
        qa.setActivityDigest(activity.getDigest());
        qa.setScore(feedback.getUserscore());
        qa.setMaxscore(feedback.getMaxscore());
        qa.setPassed(this.getActivityCompleted());

        db.insertQuizAttempt(qa);
        DatabaseManager.getInstance().closeDatabase();
    }

    //Check if feedback results layout is already loaded
    View feedbackResultsLayout = getView().findViewById(R.id.widget_feedback_results);
    if (feedbackResultsLayout == null) {
        View view = getView().findViewById(R.id.quiz_progress);
        ViewGroup parent = (ViewGroup) view.getParent();
        int index = parent.indexOfChild(view);
        parent.removeView(view);
        view = super.getActivity().getLayoutInflater().inflate(R.layout.widget_feedback_results, parent, false);
        parent.addView(view, index);
    }
}

From source file:org.telegram.ui.ActionBar.BaseFragment.java

protected void setParentLayout(ActionBarLayout layout) {
    if (parentLayout != layout) {
        parentLayout = layout;// w  ww . ja va  2s  . c o  m
        if (fragmentView != null) {
            ViewGroup parent = (ViewGroup) fragmentView.getParent();
            if (parent != null) {
                try {
                    parent.removeView(fragmentView);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
            if (parentLayout != null && parentLayout.getContext() != fragmentView.getContext()) {
                fragmentView = null;
            }
        }
        if (actionBar != null) {
            ViewGroup parent = (ViewGroup) actionBar.getParent();
            if (parent != null) {
                try {
                    parent.removeView(actionBar);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
            if (parentLayout != null && parentLayout.getContext() != actionBar.getContext()) {
                actionBar = null;
            }
        }
        if (parentLayout != null && actionBar == null) {
            actionBar = new ActionBar(parentLayout.getContext());
            actionBar.parentFragment = this;

            int pic = SkinMan.currentSkin.actionSmallPicture();
            // :ramin
            if (pic == 0)
                actionBar.setBackgroundColor(SkinMan.currentSkin.actionbarColor()//ColorUtils.getColor(R.color.primary)
                );
            else {
                Drawable d = ContextCompat.getDrawable(actionBar.getContext(), pic);
                Utils.setBackground(actionBar, d);
            }
            //actionBar.setBackgroundColor(0xff54759e);
            actionBar.setItemsBackground(//R.drawable.bar_selector_f
                    SkinMan.barSelector(parentLayout.getContext()));
        }
    }
}