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:mobi.cangol.mobile.navigation.DrawerMenuLayout.java

public void attachToActivity(Activity activity, boolean isFloatActionBarEnabled) {
    // get the window background
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();//  w w w  .ja  va  2 s  . c o m

    this.isFloatActionBarEnabled = isFloatActionBarEnabled;

    if (isFloatActionBarEnabled) {
        ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
        ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
        if (decorChild.getBackground() != null) {
            this.setBackgroundDrawable(decorChild.getBackground());
            decorChild.setBackgroundDrawable(null);
        } else {
            if (this.getBackground() == null)
                this.setBackgroundResource(background);
        }
        decor.removeView(decorChild);
        decor.addView(this, 0);
        getContentView().addView(decorChild);
    } else {
        ViewGroup contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
        ViewGroup content = (ViewGroup) contentParent.getChildAt(0);
        contentParent.removeView(content);
        contentParent.addView(this, 0);
        getContentView().addView(content);
    }
}

From source file:com.way.betterdeal.view.LoopPagerAdapterWrapper.java

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    int realFirst = getRealFirstPosition();
    int realLast = getRealLastPosition();
    int realPosition = (mAdapter instanceof FragmentPagerAdapter
            || mAdapter instanceof FragmentStatePagerAdapter) ? position : toRealPosition(position);

    if (mBoundaryCaching && (position == realFirst || position == realLast)) {
        mToDestroy.put(position, new ToDestroy(container, realPosition, object));
    } else {/*  w w w  . j a v a  2s.  c om*/
        //   mAdapter.destroyItem(container, realPosition, object);
    }

    container.removeView(this.mViewPager.findViewFromObject(position));
}

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

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

    this.quiz = new Quiz();
    this.quiz.load(quizContent,
            prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage()));
    this.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);/*from ww  w  . j a  va2  s .co m*/

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

From source file:org.mozilla.focus.fragment.BrowserFragment.java

private void initialiseCustomTabUi(final @NonNull View view) {
    final CustomTabConfig customTabConfig = BrowsingSession.getInstance().getCustomTabConfig();
    if (customTabConfig == null) {
        throw new IllegalStateException("Can't initialise custom tab UI for non custom-tab session");
    }/* w  w  w . java 2s  .  c  o m*/

    // Unfortunately there's no simpler way to have the FAB only in normal-browser mode.
    // - ViewStub: requires splitting attributes for the FAB between the ViewStub, and actual FAB layout file.
    //             Moreover, the layout behaviour just doesn't work unless you set it programatically.
    // - View.GONE: doesn't work because the layout-behaviour makes the FAB visible again when scrolling.
    // - Adding at runtime: works, but then we need to use a separate layout file (and you need
    //   to set some attributes programatically, same as ViewStub).
    final View erase = view.findViewById(R.id.erase);
    final ViewGroup eraseContainer = (ViewGroup) erase.getParent();
    eraseContainer.removeView(erase);

    final View toolbar = view.findViewById(R.id.urlbar);
    if (customTabConfig.toolbarColor != null) {
        toolbar.setBackgroundColor(customTabConfig.toolbarColor);
    }

    final ImageView closeButton = (ImageView) view.findViewById(R.id.customtab_close);

    closeButton.setVisibility(View.VISIBLE);
    closeButton.setOnClickListener(this);

    if (customTabConfig.closeButtonIcon != null) {
        closeButton.setImageBitmap(customTabConfig.closeButtonIcon);
    } else {
        // Always set the icon in case it's been overridden by a previous CT invocation
        closeButton.setImageResource(R.drawable.ic_close);
    }

    if (customTabConfig.disableUrlbarHiding) {
        AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
        params.setScrollFlags(0);
    }

    if (customTabConfig.actionButtonConfig != null) {
        final ImageButton actionButton = (ImageButton) view.findViewById(R.id.customtab_actionbutton);
        actionButton.setVisibility(View.VISIBLE);

        actionButton.setImageBitmap(customTabConfig.actionButtonConfig.icon);
        actionButton.setContentDescription(customTabConfig.actionButtonConfig.description);

        final PendingIntent pendingIntent = customTabConfig.actionButtonConfig.pendingIntent;

        actionButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    pendingIntent.send();
                } catch (PendingIntent.CanceledException e) {
                    // There's really nothing we can do here...
                }
            }
        });
    }
}

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

@Override
public View createView(LayoutInflater inflater) {
    if (fragmentView == null) {
        actionBar.setBackButtonImage(R.drawable.ic_ab_back);
        actionBar.setAllowOverlayTitle(true);
        actionBar.setTitle("My Places");
        actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
            @Override/* w w w  .j  ava2s .  c o m*/
            public void onItemClick(int id) {
                if (id == -1) {
                    finishFragment();
                }
            }
        });

        listAdapter = new ListAdapter(getParentActivity());

        fragmentView = new FrameLayout(getParentActivity());
        FrameLayout frameLayout = (FrameLayout) fragmentView;
        frameLayout.setBackgroundColor(0xfff0f0f0);

        ListView listView = new ListView(getParentActivity());
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
        layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == homeRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Home");
                    final ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(50, 30);
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    input.setLayoutParams(lparams);
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationHome = new getCoordinates().execute(city).get();
                                    String latHome = locationHome.getString("lat");
                                    String lonHome = locationHome.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latHome", latHome);
                                    editor.putString("longHome", lonHome);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + lonHome);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                } else if (i == workRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Work");
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationWork = new getCoordinates().execute(city).get();
                                    String latWork = locationWork.getString("lat");
                                    String lonWork = locationWork.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latWork", latWork);
                                    editor.putString("longWork", lonWork);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + latWork);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                } else if (i == entertainmentRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Entertainment");
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationEntertainment = new getCoordinates().execute(city).get();
                                    String latEntertainment = locationEntertainment.getString("lat");
                                    String lonEntertainment = locationEntertainment.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latEntertainment", latEntertainment);
                                    editor.putString("longEntertainment", lonEntertainment);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + latEntertainment);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                }
                //TODO find a solution for commuteRow as well!!
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:com.alivenet.dmvtaxi.fragment.FragmentArriveDriver.java

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

        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null)
            parent.removeView(view);

    }/*from ww  w  . j a v a 2s .  c  om*/
    try {
        view = inflater.inflate(R.layout.fragment_time_estemet, container, false);
    } catch (InflateException e) {
    }
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }
    mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE);
    mUserId = mPref.getString("userId", null);

    gps = new GPSTracker(getActivity());
    MyApplication.arrivedrivermarker = true;
    progressDialog = new ProgressDialog(getActivity());
    progressDialog.setMessage("Please wait...");
    progressDialog.setCancelable(false);

    mlinerlayoutbottom = (LinearLayout) view.findViewById(R.id.ll_bottom);
    mphone = (ImageView) view.findViewById(R.id.iv_phone);
    mphonenumber = (TextView) view.findViewById(R.id.tv_phonenumber);
    marrivaltime = (TextView) view.findViewById(R.id.tv_textarrival);
    mname = (TextView) view.findViewById(R.id.tv_name);
    mlicence = (TextView) view.findViewById(R.id.tv_licence);
    mtaximodel = (TextView) view.findViewById(R.id.tv_model);
    muserImage = (ImageView) view.findViewById(R.id.imageView_close);
    getLatLong();
    btnSplite = (Button) view.findViewById(R.id.btn_splite_rides);

    btnSplite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent in = new Intent(getActivity(), SplitAddFrnd.class);
            startActivity(in);
        }
    });

    mphone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String uri = "tel:" + mphonenumber.getText().toString().trim();
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse(uri));
            startActivity(intent);
        }
    });

    System.out.println("userId>>>>>>>>>>>>>>>>>>>>>" + mUserId);

    mname.setText(MyApplication.driverName);
    mlicence.setText(MyApplication.licenseId);
    mtaximodel.setText(MyApplication.vehicle);
    mphonenumber.setText(MyApplication.mobileNO);

    Picasso.with(getActivity()).load(MyApplication.imageUrl).error(R.mipmap.avtar).placeholder(R.mipmap.avtar)
            .into(muserImage);

    System.out.println("driverImageurl" + "chceck=" + MyApplication.imageUrl);

    mphonenumber.setText("Call To" + " " + MyApplication.driverName);

    final SinchClient sinchClient = Sinch.getSinchClientBuilder().context(getActivity()).userId(mUserId)
            .applicationKey("3b013f09-db1f-422e-ac7b-c6498e119612")
            .applicationSecret("LMhelEFYtUqms55VX1C7MQ==").environmentHost("sandbox.sinch.com").build();

    sinchClient.setSupportCalling(true);
    sinchClient.start();
    mphone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (call == null) {
                if (MyApplication.mobileNO != null && !MyApplication.mobileNO.equals("")) {
                    call = sinchClient.getCallClient().callPhoneNumber("+" + MyApplication.mobileNO);
                    System.out.println("mobile_number" + MyApplication.mobileNO);
                    //call = sinchClient.getCallClient().callPhoneNumber("+918510834641");
                    try {
                        call.addCallListener(new SinchCallListener());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    mphonenumber.setText("Hang Up");
                }
            } else {
                call.hangup();
            }
        }
    });

    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                // handle back button's click listener

                if (keyCode == KeyEvent.KEYCODE_BACK) {

                    Fragment homeFragment = new FragmentMainScreen();
                    FragmentManager frgManager;
                    frgManager = getFragmentManager();
                    frgManager.beginTransaction().replace(R.id.fragment_switch, homeFragment).commit();

                    return true;
                }

                return true;
            }
            return false;
        }
    });

    return view;
}

From source file:mobi.cangol.mobile.navigation.SlidingMenuLayout.java

public void attachToActivity(Activity activity, boolean isFloatActionBarEnabled) {
    // get the window background
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();/*from w  w  w. ja v a  2s  . c  om*/

    this.isFloatActionBarEnabled = isFloatActionBarEnabled;

    if (isFloatActionBarEnabled) {
        ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
        ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
        if (decorChild.getBackground() != null) {
            this.setBackgroundDrawable(decorChild.getBackground());
            decorChild.setBackgroundDrawable(null);
        } else {
            if (this.getBackground() == null)
                this.setBackgroundResource(background);
        }
        decor.removeView(decorChild);
        decor.addView(this.getRootView(), 0);
        getContentView().addView(decorChild);
    } else {
        ViewGroup contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
        ViewGroup content = (ViewGroup) contentParent.getChildAt(0);
        contentParent.removeView(content);
        contentParent.addView(this, 0);
        getContentView().addView(content);
    }
}

From source file:com.android.fastlibrary.ui.activity.swipeback.SwipeBackLayout.java

public void attachToActivity(Activity activity) {
    mActivity = activity;//  w ww .  j a va  2  s. c  o  m
    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.elephant.widget.crouton.Manager.java

/**
 * Removes the {@link Crouton}'s view after it's display
 * durationInMilliseconds./* w w  w.  j av  a 2  s  . c om*/
 * 
 * @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:com.waz.zclient.pages.main.conversation.SingleImageFragment.java

private void initAnimatingImageView(boolean afterFling) {
    if (getView() == null) {
        return;/*from  w w  w . j av a2 s.  c  om*/
    }
    ViewGroup parent = (ViewGroup) animatingImageView.getParent();
    parent.removeView(animatingImageView);

    final int displayHeight = ViewUtils.getOrientationDependentDisplayHeight(getActivity())
            - ViewUtils.getStatusBarHeight(getActivity());
    final int displayWidth = ViewUtils.getOrientationDependentDisplayWidth(getActivity());
    final int finalTop;
    final int finalLeft;
    if (afterFling) {
        finalLeft = (int) flingImageLeft;
        finalTop = (int) flingImageTop;
        animatingImageView.setPivotX(flingImagePivotX);
        animatingImageView.setPivotY(flingImagePivotY);
        animatingImageView.setRotation(flingRotation);
    } else {
        finalTop = (displayHeight - clickedImageHeight) / 2;
        finalLeft = (displayWidth - clickedImageWidth) / 2;
    }
    final float scale = Math.min(displayWidth / (float) clickedImageWidth,
            displayHeight / (float) clickedImageHeight);

    ViewGroup.LayoutParams layoutParams = new FrameLayout.LayoutParams(clickedImageWidth, clickedImageHeight);
    animatingImageView.setLayoutParams(layoutParams);
    animatingImageView.setX(finalLeft);
    animatingImageView.setY(finalTop);
    animatingImageView.setScaleX(scale);
    animatingImageView.setScaleY(scale);

    parent.addView(animatingImageView);
}