Example usage for android.view ViewGroup removeAllViews

List of usage examples for android.view ViewGroup removeAllViews

Introduction

In this page you can find the example usage for android.view ViewGroup removeAllViews.

Prototype

public void removeAllViews() 

Source Link

Document

Call this method to remove all child views from the ViewGroup.

Usage

From source file:com.digi.android.wva.fragments.ChartFragment.java

/**
 * Repaints the chart view onto the screen. This is done by
 * removing the chart view from the layout, calling repaint(),
 * and putting the view back into the layout.
  */*  ww w . j av a  2 s. c  o m*/
  * <p>This method is protected, rather than private, due to a bug between JaCoCo and
  * the Android build tools which causes the instrumented bytecode to be invalid when this
  * method is private:
  * http://stackoverflow.com/questions/17603192/dalvik-transformation-using-wrong-invoke-opcode
  * </p>
 */
protected void redrawChart() {
    // super.getView() should return NoSaveStateFrameLayout, which
    // extends FrameLayout, which extends ViewGroup
    ViewGroup l = (ViewGroup) super.getView();
    if (mChart == null) {
        mChart = ChartFactory.getCombinedXYChartView(getActivity(), mDataset, mRenderer,
                new String[] { LineChart.TYPE, LineChart.TYPE });
        mChart.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                SeriesSelection sel = mChart.getCurrentSeriesAndPoint();

                if (sel == null)
                    return;

                String series = "SERIES";
                switch (sel.getSeriesIndex()) {
                case 0:
                    series = "Vehicle Speed";
                    break;
                case 1:
                    series = "Engine RPM";
                    break;
                }

                String time = ISODateTimeFormat.dateTimeNoMillis().print((long) sel.getXValue());

                Toast.makeText(getActivity(), series + " (" + time + "): " + sel.getValue(), Toast.LENGTH_SHORT)
                        .show();
            }
        });
    }
    if (l != null) {
        // Ensure that the chart is removed from all views.
        try {
            if (mChart.getParent() != null) {
                //noinspection ConstantConditions
                ((ViewGroup) mChart.getParent()).removeAllViews();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        l.removeAllViews();
        mChart.repaint();
        l.addView(mChart);
    } else {
        // If the getView() result is null, something's up, like
        // the activity has been backgrounded.
        Log.d(TAG, "redrawChart -- l is null");
    }
}

From source file:de.mrapp.android.bottomsheet.BottomSheet.java

/**
 * Initializes the bottom sheet's root view.
 *///from   w w  w . ja v  a 2 s. c  o  m
private void inflateRootView() {
    ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content);
    contentView.removeAllViews();
    LayoutInflater layoutInflater = LayoutInflater.from(getContext());
    rootView = (DraggableView) layoutInflater.inflate(R.layout.bottom_sheet, contentView, false);
    rootView.setCallback(this);
    contentView.addView(rootView, createRootViewLayoutParams());
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

private void initBookmarkDropdown() {
    if (mBookmarksList == null)
        mBookmarksList = new ExpandableListView(this);
    if (findViewById(R.id.list_frag) != null) {
        ViewGroup leftNav = ((ViewGroup) findViewById(R.id.list_frag));
        leftNav.removeAllViews();
        leftNav.addView(mBookmarksList);
    } else {/* ww  w.j  a  v  a 2 s. c o  m*/
        View anchor = null;
        if (anchor == null)
            anchor = findViewById(R.id.title_icon);
        if (anchor == null)
            anchor = findViewById(android.R.id.home);
        if (anchor == null && USE_ACTION_BAR && !BEFORE_HONEYCOMB && getActionBar() != null
                && getActionBar().getCustomView() != null)
            anchor = getActionBar().getCustomView();
        if (anchor == null)
            anchor = findViewById(R.id.title_bar);
        if (anchor == null)
            anchor = findViewById(R.id.base_bar);
        if (anchor == null)
            anchor = findViewById(R.id.base_row);
        mBookmarksPopup = new BetterPopupWindow(this, anchor);
        mBookmarksPopup.setContentView(mBookmarksList);
    }
    mBookmarks = new OpenBookmarks(this, mBookmarksList);
    for (int i = 0; i < mBookmarksList.getCount(); i++)
        mBookmarksList.expandGroup(i);
}

From source file:com.blueverdi.rosietheriveter.SitesFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    thisFragment = this;
    setRetainInstance(false);/*  www . java2 s .  c  o m*/
    myTour = new MySqliteHelperMyTour(getActivity());
    networkAvailable = Utils.isNetworkAvailable(getActivity());
    buildSitesList();
    view = inflater.inflate(R.layout.sites_fragment, container, false);
    viewContainer = (LinearLayout) view.findViewById(R.id.view_container);
    RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radioGroup1);
    // implementation without nested fragments
    // first initialize the gallery view
    // ---------------------------------
    listLayout = (LinearLayout) inflater.inflate(R.layout.site_gallery_view, viewContainer, false);
    Display display = ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    int rotation = display.getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180:
        portrait = true;
        arrayLayout = R.layout.site_portrait;
        break;
    case Surface.ROTATION_90:
    case Surface.ROTATION_270:
        portrait = false;
        arrayLayout = R.layout.site_landscape;
        break;
    }

    // now initialize the map view 
    // --------------------------
    mapLayout = (LinearLayout) inflater.inflate(R.layout.site_map_view, viewContainer, false);
    try {
        MapsInitializer.initialize(this.getActivity());
    } catch (Exception e) {
        e.printStackTrace();

    }
    mapView = (MapView) mapLayout.findViewById(R.id.siteMap);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {
            map = googleMap;
            map.getUiSettings().setMyLocationButtonEnabled(false);
            if (!networkAvailable) {
                Toast.makeText(thisFragment.getActivity(),
                        thisFragment.getActivity().getString(R.string.internet_required), Toast.LENGTH_LONG)
                        .show();
            }

            //      map.setMyLocationEnabled(true);
            //                 CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(SITES, 0);
            //                 map.animateCamera(cameraUpdate);

            CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(SITES, 0);
            if (networkAvailable) {
                map.animateCamera(cameraUpdate);
            } else {
                map.moveCamera(cameraUpdate);

            }
            markers = new HashMap<String, Site>();
            for (Site s : sites) {
                LatLng ll = new LatLng(Double.parseDouble(s.getString(Site.LATITUDE)),
                        Double.parseDouble(s.getString(Site.LONGITUDE)));
                Marker marker = map.addMarker(new MarkerOptions().position(ll).title(s.getString(Site.NAME)));
                markers.put(marker.getId(), s);
            }
            map.setOnMarkerClickListener(new OnMarkerClickListener() {
                @Override
                public boolean onMarkerClick(Marker marker) {
                    Site s = markers.get(marker.getId());
                    Intent i = new Intent(getActivity(), SiteActivity.class);
                    i.putExtra(Site.PARCEL_NAME, s);
                    SiteDetails sd = s.getDetails();
                    if (sd != null) {
                        i.putExtra(SiteDetails.PARCEL_NAME, sd);
                    }
                    startActivity(i);
                    getActivity().overridePendingTransition(R.anim.zoom_in, 0);
                    return true;
                }
            });
        }
    });
    try {
        container.removeAllViews();
    } catch (Exception e) {
        MyLog.d(TAG, "container evaporated inside onCreateView");
        return view;
    }
    if (startInMapView) {
        RadioButton rb = (RadioButton) view.findViewById(R.id.radioMapView);
        rb.setChecked(true);
        setMap();
    } else {
        setGallery();
    }
    radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.radioListView) {
                setGallery();
            } else {
                Toast.makeText(getActivity(), getString(R.string.getting_map), Toast.LENGTH_LONG).show();
                setMap();
            }
        }
    });
    return view;
}

From source file:com.blueverdi.rosietheriveter.MoreFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRetainInstance(false);/*from   w w w  . ja va2  s.c  o  m*/
    thisFragment = this;
    myTour = new MySqliteHelperMyTour(getActivity());
    networkAvailable = Utils.isNetworkAvailable(getActivity());
    buildSitesList();
    view = inflater.inflate(R.layout.more_fragment, container, false);
    viewContainer = (LinearLayout) view.findViewById(R.id.view_container);
    RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radioGroup1);
    // implementation without nested fragments
    // first initialize the gallery view
    // ---------------------------------
    listLayout = (LinearLayout) inflater.inflate(R.layout.site_gallery_view, viewContainer, false);
    Display display = ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    int rotation = display.getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180:
        portrait = true;
        arrayLayout = R.layout.site_portrait;
        break;
    case Surface.ROTATION_90:
    case Surface.ROTATION_270:
        portrait = false;
        arrayLayout = R.layout.site_landscape;
        break;
    }
    ListView listview = (ListView) listLayout.findViewById(R.id.siteListView);

    // now initialize the map view 
    // --------------------------
    mapLayout = (LinearLayout) inflater.inflate(R.layout.site_map_view, viewContainer, false);
    try {
        MapsInitializer.initialize(this.getActivity());
    } catch (Exception e) {
        e.printStackTrace();

    }
    mapView = (MapView) mapLayout.findViewById(R.id.siteMap);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {
            map = googleMap;
            map.getUiSettings().setMyLocationButtonEnabled(false);
            if (!networkAvailable) {
                thisFragment.getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getActivity(), getString(R.string.internet_required), Toast.LENGTH_LONG)
                                .show();

                    }
                });
            }

            map.setOnCameraChangeListener(new OnCameraChangeListener() {

                @Override
                public void onCameraChange(CameraPosition arg0) {
                    map.setOnCameraChangeListener(null);
                    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(SITES, 0);
                    if (networkAvailable) {
                        map.animateCamera(cameraUpdate);
                    } else {
                        map.moveCamera(cameraUpdate);
                    }
                }
            });
            markers = new HashMap<String, Site>();
            for (Site s : sites) {
                LatLng ll = new LatLng(Double.parseDouble(s.getString(Site.LATITUDE)),
                        Double.parseDouble(s.getString(Site.LONGITUDE)));
                Marker marker = map.addMarker(new MarkerOptions().position(ll).title(s.getString(Site.NAME)));
                markers.put(marker.getId(), s);
            }
            map.setOnMarkerClickListener(new OnMarkerClickListener() {
                @Override
                public boolean onMarkerClick(Marker marker) {
                    Site s = markers.get(marker.getId());
                    Intent i = new Intent(getActivity(), SiteActivity.class);
                    i.putExtra(Site.PARCEL_NAME, s);
                    startActivity(i);
                    getActivity().overridePendingTransition(R.anim.zoom_in, 0);
                    return true;
                }
            });
        }
    });
    try {
        container.removeAllViews();
    } catch (Exception e) {
        MyLog.d(TAG, "container evaporated inside onCreateView");
        return view;
    }
    if (startInMapView) {
        RadioButton rb = (RadioButton) view.findViewById(R.id.radioMapView);
        rb.setChecked(true);
        setMap();
    } else {
        setGallery();
    }
    radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.radioListView) {
                setGallery();
            } else {
                Toast.makeText(getActivity(), getString(R.string.getting_map), Toast.LENGTH_LONG).show();
                setMap();
            }
        }
    });
    return view;
}