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.dzt.uberclone.HomeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (v != null) {
        ViewGroup parent = (ViewGroup) v.getParent();
        if (parent != null)
            parent.removeView(v);
    }/* w  w  w . ja v  a2  s .  com*/

    try {
        v = inflater.inflate(R.layout.fragment_home, container, false);
    } catch (InflateException e) {
        e.printStackTrace();
    }

    map = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();
    map.setMyLocationEnabled(true);

    map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    map.setOnMapClickListener(this);
    map.setOnMarkerDragListener(this);

    requestuber = (Button) v.findViewById(R.id.request_uber);
    requestuber.setOnClickListener(this);
    statusText = (TextView) v.findViewById(R.id.status_text);
    statusText.setVisibility(View.INVISIBLE);

    SharedPreferences sp = getActivity().getSharedPreferences("Session", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor;
    editor = sp.edit();
    String location = sp.getString("location", "");

    mGoogleApiClient = new GoogleApiClient.Builder(getActivity()).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).addApi(LocationServices.API).build();

    selectPickup = (TextView) v.findViewById(R.id.select_location);
    selectPickup.setOnClickListener(this);

    if (location.equals("")) {
        selectPickup.setText("Select pick up location");
    } else {
        String latstr = sp.getString("locationlat", "");
        String longstr = sp.getString("locationlong", "");
        latitude = Double.parseDouble(latstr);
        longitude = Double.parseDouble(longstr);
        selectPickup.setText(location);

        editor.putString("location", "");
        editor.putString("locationlat", "");
        editor.putString("locationlong", "");
        editor.commit();
        centerOnCurrent = false;
    }

    mGoogleApiClient.connect();

    return v;
}

From source file:com.bowyoung.enhancelibrary.libs.swipeback.SwipeBackLayout.java

public void attachToActivity(BaseEnhanceActivity activity) {
    mActivity = activity;/*from w  ww.j  a v  a 2s.com*/
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}

From source file:com.github.michalbednarski.intentslab.uihelpers.FragmentTabMergingPagerAdapter.java

@Override
public void destroyItem(ViewGroup container, int page, Object object) {
    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }/*from   w  ww  .j  a  va 2 s  .c  o m*/

    if (DEBUG)
        Log.v(TAG, "Detaching items from page #" + page);

    if (object instanceof AddedPageInfo) {
        for (Fragment fragment : ((AddedPageInfo) object).fragments) {
            mCurTransaction.detach(fragment);
        }
        container.removeView(((AddedPageInfo) object).view);
    } else {
        mCurTransaction.detach((Fragment) object);
    }
}

From source file:org.cowboycoders.cyclismo.fragments.AltitudeProfileFragment.java

@Override
public void onStop() {
    super.onStop();
    ViewGroup layout = (ViewGroup) getActivity().findViewById(R.id.altitude_profile_layout);
    layout.removeView(altitudeProfileView);
}

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

/**
 * Removes the {@link Crouton}'s view after it's display
 * durationInMilliseconds.//from  w  w w. j a v  a 2 s. co  m
 *
 * @param crouton
 *     The {@link Crouton} added to a {@link ViewGroup} and should be
 *     removed.
 */
protected void removeCrouton(Crouton crouton) {
    View croutonView = crouton.getView();
    ViewGroup croutonParentView = (ViewGroup) croutonView.getParent();

    if (null != croutonParentView) {
        croutonView.startAnimation(crouton.getOutAnimation());

        // Remove the Crouton from the queue.
        Crouton removed = croutonQueue.poll();

        // Remove the crouton from the view's parent.
        croutonParentView.removeView(croutonView);
        if (null != removed) {
            removed.detachActivity();
            removed.detachViewGroup();
            if (null != removed.getLifecycleCallback()) {
                removed.getLifecycleCallback().onRemoved();
            }
            removed.detachLifecycleCallback();
        }

        // Send a message to display the next crouton but delay it by the out
        // animation duration to make sure it finishes
        sendMessageDelayed(crouton, Messages.DISPLAY_CROUTON, crouton.getOutAnimation().getDuration());
    }
}

From source file:org.artoolkit.ar.unity.UnityARPlayerActivity.java

@Override
protected void onResume() {
    Log.i(TAG, "onResume()");

    super.onResume();

    ///*from   w  ww. j  a  va2 s  .co  m*/
    // Wrap the Unity application's view and the camera preview in a FrameLayout;
    //

    //View focusView = getCurrentFocus(); // Save the focus, in case we inadvertently change it.
    //Log.i(TAG, "Focus view is " + focusView.toString() + ".");

    ViewGroup decorView = (ViewGroup) getWindow().getDecorView();
    unityView = (ViewGroup) decorView.getChildAt(0);
    if (unityView == null) {
        Log.e(TAG, "Error: Could not find top view.");
        return;
    }
    //Log.i(TAG, "Top view is " + unityView.toString() + ".");

    // Create a placeholder for us to insert the camera preview capture object to the
    // view hierarchy.
    previewInserter = new FrameLayout(this);
    decorView.removeView(unityView); // We must remove the root view from its parent before we can add it somewhere else.
    decorView.addView(previewInserter);

    //focusView.requestFocus(); // Restore focus.

    // Create the camera preview.
    previewView = new CameraSurface(this);
    previewInserter.addView(previewView, new LayoutParams(128, 128));

    // Now add Unity view back in.
    // In order to ensure that Unity's view covers the camera preview each time onResume
    // is called, find the SurfaceView inside the Unity view hierachy, and
    // set the media overlay mode on it. Add the Unity view AFTER adding the previewView.
    SurfaceView sv = findSurfaceView(unityView);
    if (sv == null) {
        Log.w(TAG, "No SurfaceView found in Unity view hierarchy.");
    } else {
        Log.i(TAG, "Found SurfaceView " + sv.toString() + ".");
        sv.setZOrderMediaOverlay(true);
    }
    previewInserter.addView(unityView);
}

From source file:com.hxqc.mall.auto.fragment.MaintainEditAutoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (rootView == null) {
        rootView = inflater.inflate(R.layout.fragment_maintain_add_auto_info, container, false);
    }/*from w w w.j a  va2s  . co  m*/
    ViewGroup parent = (ViewGroup) rootView.getParent();
    if (parent != null) {
        parent.removeView(rootView);
    }

    return rootView;
}

From source file:com.andybotting.tubechaser.activity.Home.java

/**
 * Make a status window//from   ww w  . jav  a2s. co  m
 */
public void setInfoWindow(View infoView) {

    if (mInfoLoadingView == null) // Landscape orientation
        return;

    ViewGroup homeRoot = (ViewGroup) findViewById(R.id.home_root);

    mInfoWindowView = findViewById(R.id.info_window);
    if (mInfoWindowView != null) {
        homeRoot.removeView(mInfoWindowView);
        mInfoWindowView = null;
    }

    mInfoWindowView = infoView;

    homeRoot.addView(infoView, new LayoutParams(LayoutParams.FILL_PARENT,
            (int) getResources().getDimension(R.dimen.info_window_height)));

    mInfoLoadingView.setVisibility(View.GONE);
    mInfoWindowView.setVisibility(View.VISIBLE);
}

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

public void showResults() {

    // log the activity as complete
    isOnResultsPage = true;/*from w  w w.  j av  a2  s  .  c  o m*/
    quiz.mark(prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage()));
    // save results ready to send back to the quiz server
    String data = quiz.getResultObject().toString();
    Log.d(TAG, data);

    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(quiz.getUserscore());
    qa.setMaxscore(quiz.getMaxscore());
    qa.setPassed(this.getActivityCompleted());
    qa.setSent(false);
    db.insertQuizAttempt(qa);
    DatabaseManager.getInstance().closeDatabase();

    //Check if quiz results layout is already loaded
    View quizResultsLayout = getView().findViewById(R.id.widget_quiz_results);
    if (quizResultsLayout == null) {
        // load new layout
        View C = getView().findViewById(R.id.quiz_progress);
        ViewGroup parent = (ViewGroup) C.getParent();
        int index = parent.indexOfChild(C);
        parent.removeView(C);
        C = super.getActivity().getLayoutInflater().inflate(R.layout.widget_quiz_results, parent, false);
        parent.addView(C, index);
    }

    TextView title = (TextView) getView().findViewById(R.id.quiz_results_score);
    title.setText(super.getActivity().getString(R.string.widget_quiz_results_score, this.getPercent()));

    if (this.isBaseline) {
        TextView baselineExtro = (TextView) getView().findViewById(R.id.quiz_results_baseline);
        baselineExtro.setVisibility(View.VISIBLE);
        baselineExtro.setText(super.getActivity().getString(R.string.widget_quiz_baseline_completed));
    }

    // TODO add TextView here to give overall feedback if it's in the quiz

    // Show the detail of which questions were right/wrong
    if (quiz.getShowFeedback() == Quiz.SHOW_FEEDBACK_ALWAYS
            || quiz.getShowFeedback() == Quiz.SHOW_FEEDBACK_ATEND) {
        ListView questionFeedbackLV = (ListView) getView().findViewById(R.id.quiz_results_feedback);
        ArrayList<QuizFeedback> quizFeedback = new ArrayList<QuizFeedback>();
        List<QuizQuestion> questions = this.quiz.getQuestions();
        for (QuizQuestion q : questions) {
            if (!(q instanceof Description)) {
                QuizFeedback qf = new QuizFeedback();
                qf.setScore(q.getScoreAsPercent());
                qf.setQuestionText(q.getTitle(
                        prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage())));
                qf.setUserResponse(q.getUserResponses());
                qf.setFeedbackText(q.getFeedback(
                        prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage())));
                quizFeedback.add(qf);
            }
        }
        QuizFeedbackAdapter qfa = new QuizFeedbackAdapter(super.getActivity(), quizFeedback);
        questionFeedbackLV.setAdapter(qfa);
    }

    // Show restart or continue button
    Button restartBtn = (Button) getView().findViewById(R.id.quiz_results_button);

    if (this.isBaseline) {
        restartBtn.setText(super.getActivity().getString(R.string.widget_quiz_baseline_goto_course));
        restartBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                QuizWidget.this.getActivity().finish();
            }
        });
    } else {
        restartBtn.setText(super.getActivity().getString(R.string.widget_quiz_results_restart));
        restartBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                QuizWidget.this.restart();
            }
        });
    }
}

From source file:com.l4digital.fastscroll.FastScrollRecyclerView.java

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    mFastScroller.attachRecyclerView(this);

    final ViewParent parent = getParent();

    if (parent instanceof ViewGroup) {
        final ViewGroup viewGroup = (ViewGroup) parent;
        if ((viewGroup instanceof CoordinatorLayout) || (viewGroup instanceof FrameLayout)
                || (viewGroup instanceof RelativeLayout)) {
            if (mFastScroller.getParent() == null) {
                viewGroup.addView(mFastScroller);
                mFastScroller.setLayoutParams(viewGroup);
            }/*from  w  w  w . j av a 2 s . co  m*/
        } else {
            if (viewGroup instanceof SwipeRefreshLayout) {
                mFastScroller.swipeRefreshLayout = (SwipeRefreshLayout) viewGroup;
            }
            final int index = viewGroup.indexOfChild(this);
            viewGroup.removeView(this);
            final FrameLayout fr = new FrameLayout(getContext());
            fr.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.MATCH_PARENT));
            fr.addView(this);
            fr.addView(mFastScroller);
            mFastScroller.setLayoutParams(fr);
            viewGroup.addView(fr, index);
        }
    }
}