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.cypress.cysmart.BLEServiceFragments.RGBFragment.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        LayoutInflater inflater = (LayoutInflater) getActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rootView = inflater.inflate(R.layout.rgb_view_landscape, null);
        ViewGroup rootViewG = (ViewGroup) getView();
        // Remove all the existing views from the root view.
        rootViewG.removeAllViews();
        rootViewG.addView(rootView);//from  w w w  .  j  a v a  2  s .  c  o m
        setUpControls();
        setDefaultColorPickerPositionColor();

    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
        LayoutInflater inflater = (LayoutInflater) getActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rootView = inflater.inflate(R.layout.rgb_view_portrait, null);
        ViewGroup rootViewG = (ViewGroup) getView();
        // Remove all the existing views from the root view.
        rootViewG.removeAllViews();
        rootViewG.addView(rootView);
        setUpControls();
        setDefaultColorPickerPositionColor();

    }

}

From source file:it.iziozi.iziozi.gui.IOBoardFragment.java

private View buildView(boolean editMode) {

    this.homeRows.clear();
    final List<IOSpeakableImageButton> mButtons = new ArrayList<IOSpeakableImageButton>();
    List<IOSpeakableImageButton> configButtons = this.mBoard.getButtons();

    ViewGroup mainView = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.table_main_layout,
            null);//  w ww . j  a v  a  2  s  .  c o  m

    LinearLayout tableContainer = new LinearLayout(getActivity());
    LinearLayout.LayoutParams mainParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    tableContainer.setLayoutParams(mainParams);
    tableContainer.setOrientation(LinearLayout.VERTICAL);

    for (int i = 0; i < this.mBoard.getRows(); i++) {

        LinearLayout rowLayout = new LinearLayout(getActivity());
        LinearLayout.LayoutParams rowParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.f);
        rowLayout.setLayoutParams(rowParams);
        rowLayout.setOrientation(LinearLayout.HORIZONTAL);
        Random color = new Random();
        rowLayout.setBackgroundColor(Color.WHITE);
        tableContainer.addView(rowLayout);
        this.homeRows.add(rowLayout);
    }

    for (int j = 0; j < this.homeRows.size(); j++) {
        LinearLayout homeRow = this.homeRows.get(j);

        for (int i = 0; i < this.mBoard.getCols(); i++) {
            LinearLayout btnContainer = new LinearLayout(getActivity());
            LinearLayout.LayoutParams btnContainerParams = new LinearLayout.LayoutParams(0,
                    LinearLayout.LayoutParams.MATCH_PARENT, 1.f);
            btnContainer.setLayoutParams(btnContainerParams);
            btnContainer.setOrientation(LinearLayout.VERTICAL);
            btnContainer.setGravity(Gravity.CENTER);

            homeRow.addView(btnContainer);

            final IOSpeakableImageButton imgButton = (configButtons.size() > 0
                    && configButtons.size() > mButtons.size()) ? configButtons.get(mButtons.size())
                            : new IOSpeakableImageButton(getActivity());
            imgButton.setmContext(getActivity());
            imgButton.setShowBorder(IOConfiguration.getShowBorders());
            if (IOGlobalConfiguration.isEditing)
                imgButton.setImageDrawable(getResources().getDrawable(R.drawable.logo_org));
            else
                imgButton.setImageDrawable(null);
            imgButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            imgButton.setBackgroundColor(Color.TRANSPARENT);

            if (imgButton.getmImageFile() != null && imgButton.getmImageFile().length() > 0) {

                if (!new File(imgButton.getmImageFile()).exists()) {
                    if (mAlertDialog == null || !mAlertDialog.isShowing()) {
                        mAlertDialog = new AlertDialog.Builder(getActivity()).setCancelable(true)
                                .setTitle(getString(R.string.image_missing))
                                .setMessage(getString(R.string.image_missing_text))
                                .setNegativeButton(getString(R.string.continue_string), null).create();
                        mAlertDialog.show();
                    }

                    //download image

                    if (isExternalStorageReadable()) {

                        File baseFolder = new File(Environment.getExternalStorageDirectory() + "/"
                                + IOApplication.APPLICATION_FOLDER + "/pictograms");
                        Character pictoChar = imgButton.getmImageFile()
                                .charAt(imgButton.getmImageFile().lastIndexOf("/") + 1);
                        File pictoFolder = new File(baseFolder + "/" + pictoChar + "/");

                        if (isExternalStorageWritable()) {

                            pictoFolder.mkdirs();

                            //download it

                            AsyncHttpClient client = new AsyncHttpClient();
                            client.get(imgButton.getmUrl(),
                                    new FileAsyncHttpResponseHandler(new File(imgButton.getmImageFile())) {
                                        @Override
                                        public void onFailure(int statusCode, Header[] headers,
                                                Throwable throwable, File file) {
                                            Toast.makeText(getActivity(),
                                                    getString(R.string.download_error) + file.toString(),
                                                    Toast.LENGTH_LONG).show();
                                        }

                                        @Override
                                        public void onSuccess(int statusCode, Header[] headers,
                                                File downloadedFile) {

                                            if (new File(imgButton.getmImageFile()).exists()) {
                                                imgButton.setImageBitmap(
                                                        BitmapFactory.decodeFile(imgButton.getmImageFile()));
                                            } else {
                                                Toast.makeText(getActivity(),
                                                        getString(R.string.image_save_error),
                                                        Toast.LENGTH_SHORT).show();
                                            }
                                        }
                                    });
                        } else {

                            Toast.makeText(getActivity(), getString(R.string.image_save_error),
                                    Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Toast.makeText(getActivity(), getString(R.string.image_save_error), Toast.LENGTH_SHORT)
                                .show();
                    }

                } else
                    imgButton.setImageBitmap(BitmapFactory.decodeFile(imgButton.getmImageFile()));
            }

            ViewGroup parent = (ViewGroup) imgButton.getParent();

            if (parent != null)
                parent.removeAllViews();

            btnContainer.addView(imgButton);

            mButtons.add(imgButton);

            imgButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    int index = mButtons.indexOf(v);
                    if (mListener != null)
                        mListener.tapOnSpeakableButton(mButtons.get(index), mBoardLevel);
                }
            });
        }
    }

    this.mBoard.setButtons(mButtons.size() > configButtons.size() ? mButtons : configButtons);

    return tableContainer;
}

From source file:com.android.settingslib.drawer.SettingsDrawerActivity.java

@Override
public void setContentView(@LayoutRes int layoutResID) {
    final ViewGroup parent = (ViewGroup) findViewById(R.id.content_frame);
    if (parent != null) {
        parent.removeAllViews();
    }//from  ww  w.j a v  a  2 s  . com
    /**
     * xinsi
     *
     * layoutInflater.inflate(resourceId, root);  resourceIdid root:
     * ?View, LayoutInflater
     *
     * http://blog.csdn.net/guolin_blog/article/details/12921889
     */
    LayoutInflater.from(this).inflate(layoutResID, parent);
}

From source file:org.addhen.smssync.presentation.view.ui.activity.BasePreferenceActivity.java

private void setupActionBar() {
    Toolbar toolbar;/*  w w w  .j  a v  a 2s. c  om*/

    if (Build.VERSION.SDK_INT >= 14) {
        ViewGroup root = (ViewGroup) findViewById(android.R.id.list).getParent().getParent().getParent();
        toolbar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar_actionbar, root, false);
        root.addView(toolbar, 0);
    } else {
        ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
        ListView content = (ListView) root.getChildAt(0);
        root.removeAllViews();
        toolbar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar_actionbar, root, false);
        int height;
        TypedValue tv = new TypedValue();
        if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
            height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        } else {
            height = toolbar.getHeight();
        }
        content.setPadding(0, height, 0, 0);
        root.addView(content);
        root.addView(toolbar);
    }
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    toolbar.setNavigationOnClickListener(v -> navigateUp());
}

From source file:fr.shywim.antoinedaniel.ui.fragment.VideoDetailsFragment.java

private void displayMusics(ViewGroup layout, Cursor cursor) {
    if (layout != null) {
        layout.removeAllViews();
    }/*from w ww.  ja va  2 s . c o  m*/
    if (cursor.getCount() <= 0 || layout == null) {
        return;
    }

    for (int i = 0; i < cursor.getCount(); i++) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_music_item, layout, false);
        cursor.moveToPosition(i);
        bindMusic(view, cursor);
        layout.addView(view);
    }
}

From source file:com.koushikdutta.superuser.MultitaskSuRequestActivity.java

void setContentView() {
    setContentView(R.layout.request);//from w  w  w  .  ja  va2 s  . com

    mSpinner = (Spinner) findViewById(R.id.remember_choices);
    mSpinner.setAdapter(mSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.request_spinner_choice,
            R.id.request_spinner_choice));
    for (int id : mSpinnerIds) {
        mSpinnerAdapter.add(getString(id, getGracePeriod()));
    }

    mRemember = (RadioGroup) findViewById(R.id.remember);
    RadioButton rememberFor = (RadioButton) findViewById(R.id.remember_for);
    rememberFor.setText(getString(R.string.remember_for, getGracePeriod()));

    mAllow = (Button) findViewById(R.id.allow);
    mDeny = (Button) findViewById(R.id.deny);

    mAllow.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!Settings.isPinProtected(MultitaskSuRequestActivity.this)) {
                approve();
                return;
            }

            ViewGroup ready = (ViewGroup) findViewById(R.id.root);
            final int until = getUntil();
            ready.removeAllViews();

            PinViewHelper pin = new PinViewHelper(getLayoutInflater(),
                    (ViewGroup) findViewById(android.R.id.content), null) {
                @Override
                public void onEnter(String password) {
                    super.onEnter(password);
                    if (Settings.checkPin(MultitaskSuRequestActivity.this, password)) {
                        mAllow.setEnabled(false);
                        mDeny.setEnabled(false);
                        handleAction(true, until);
                    } else {
                        Toast.makeText(MultitaskSuRequestActivity.this, getString(R.string.incorrect_pin),
                                Toast.LENGTH_SHORT).show();
                    }
                }

                @Override
                public void onCancel() {
                    super.onCancel();
                    deny();
                }
            };

            ready.addView(pin.getView());
        }
    });
    mDeny.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            deny();
        }
    });

    if (mRequestReady)
        requestReady();
}

From source file:fr.shywim.antoinedaniel.ui.fragment.VideoDetailsFragment.java

private void displayRandomSounds(ViewGroup layout, Cursor cursor) {
    if (layout != null) {
        layout.removeAllViews();
    }/*from   w w  w .  j  a  v a  2s .co  m*/
    if (cursor.getCount() <= 0 || layout == null) {
        return;
    }

    Random rdm = new Random();

    for (int i = 0; i < getColumnNumber(); i++) {
        int pos;

        if (cursor.getCount() > getColumnNumber()) {
            pos = rdm.nextInt(cursor.getCount());
        } else {
            pos = i;
        }

        View view = LayoutInflater.from(mContext).inflate(R.layout.grid_single, layout, false);
        cursor.moveToPosition(pos);
        if (i >= cursor.getCount()) {
            view.setVisibility(View.INVISIBLE);
        } else {
            bindSound(view, cursor);
        }
        layout.addView(view);
    }
}

From source file:fm.krui.kruifm.PlaylistFragment.java

public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Initialize track list and play count. For now this is arbitrary, this would be a cool user setting.
    showLoadingScreen(true);/* w  w  w .ja  v a 2  s .co  m*/
    int playCount = 100;

    // Prepare for network operations
    ViewGroup rootContainer = (RelativeLayout) getActivity()
            .findViewById(R.id.playlist_fragment_container_relativelayout);
    NetworkListener networkListener = new NetworkListener(getActivity(), rootContainer);
    NetworkManager networkManager = new NetworkManager(getActivity(), networkListener);

    // Check for an internet connection
    boolean isConnected = networkManager.checkForNetworkConnection();
    if (!isConnected) {
        // If no connection is detected, show a connection alert.
        rootContainer.removeAllViews();
        networkManager.showConnectionAlert();
    } else {
        // When we hit this point, we can finally grab playlist tracks.
        PlaylistFetcher fetcher = new PlaylistFetcher(getActivity(), this);
        fetcher.execute(playCount);
    }
}

From source file:ti.modules.titanium.ui.widget.TiUIDrawerLayout.java

private View getNativeView(TiViewProxy viewProxy) {
    View nativeView = viewProxy.getOrCreateView().getOuterView();
    ViewGroup parentViewGroup = (ViewGroup) nativeView.getParent();
    if (parentViewGroup != null) {
        parentViewGroup.removeAllViews();
    }//  w w w  . ja  v  a2 s.c  o  m
    return nativeView;
}

From source file:com.xengar.android.stocktracker.ui.SettingsActivity.java

/**
 * Set up the {@link android.support.v7.widget.Toolbar}, if the API is available.
 *//*from w ww. java  2 s  .c  o  m*/
private void setupToolBar() {
    Toolbar toolbar;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        ViewGroup root = (ViewGroup) findViewById(android.R.id.list).getParent().getParent().getParent();
        toolbar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.view_toolbar, root, false);
        root.addView(toolbar, 0);
    } else {
        ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
        ListView content = (ListView) root.getChildAt(0);
        root.removeAllViews();
        toolbar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.view_toolbar, root, false);
        int height;
        TypedValue tv = new TypedValue();
        if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
            height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        } else {
            height = toolbar.getHeight();
        }
        content.setPadding(0, height, 0, 0);
        root.addView(content);
        root.addView(toolbar);
    }
    toolbar.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}