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.vuze.android.remote.dialog.DialogFragmentMoveData.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    boolean checked = cbRememberLocation.isChecked();
    String location = etLocation.getText().toString();

    // This mess is an attempt to rebuild the layout within the dialog
    // when the orientation changes.  Seems to work, but diesn't make sense
    ViewGroup viewGroup = (ViewGroup) alertDialogBuilder.view;
    //ViewGroup parent = (ViewGroup) viewGroup.getParent();
    viewGroup.removeAllViews();
    View view = View.inflate(dialog.getContext(), R.layout.dialog_move_data, viewGroup);
    dialog.setView(view);/*from  w w  w  .j a va  2  s  .co m*/
    alertDialogBuilder.view = view;
    setupVars(view);

    cbRememberLocation.setChecked(checked);
    etLocation.setText(location);

    resize();
}

From source file:com.android.settings.PreviewSeekBarPreferenceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View root = super.onCreateView(inflater, container, savedInstanceState);
    final ViewGroup listContainer = (ViewGroup) root.findViewById(android.R.id.list_container);
    listContainer.removeAllViews();

    final View content = inflater.inflate(mActivityLayoutResId, listContainer, false);
    listContainer.addView(content);/*from   www .ja  va  2 s.  c  o  m*/

    mLabel = (TextView) content.findViewById(R.id.current_label);

    // The maximum SeekBar value always needs to be non-zero. If there's
    // only one available value, we'll handle this by disabling the
    // seek bar.
    final int max = Math.max(1, mEntries.length - 1);

    final LabeledSeekBar seekBar = (LabeledSeekBar) content.findViewById(R.id.seek_bar);
    seekBar.setLabels(mEntries);
    seekBar.setMax(max);
    seekBar.setProgress(mInitialIndex);
    seekBar.setOnSeekBarChangeListener(new onPreviewSeekBarChangeListener());

    mSmaller = content.findViewById(R.id.smaller);
    mSmaller.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            final int progress = seekBar.getProgress();
            if (progress > 0) {
                seekBar.setProgress(progress - 1, true);
            }
        }
    });

    mLarger = content.findViewById(R.id.larger);
    mLarger.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            final int progress = seekBar.getProgress();
            if (progress < seekBar.getMax()) {
                seekBar.setProgress(progress + 1, true);
            }
        }
    });

    if (mEntries.length == 1) {
        // The larger and smaller buttons will be disabled when we call
        // setPreviewLayer() later in this method.
        seekBar.setEnabled(false);
    }

    final Context context = getContext();
    final Configuration origConfig = context.getResources().getConfiguration();
    final boolean isLayoutRtl = origConfig.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    Configuration[] configurations = new Configuration[mEntries.length];
    for (int i = 0; i < mEntries.length; ++i) {
        configurations[i] = createConfig(origConfig, i);
    }

    mPreviewPager = (ViewPager) content.findViewById(R.id.preview_pager);
    mPreviewPagerAdapter = new PreviewPagerAdapter(context, isLayoutRtl, mPreviewSampleResIds, configurations);
    mPreviewPager.setAdapter(mPreviewPagerAdapter);
    mPreviewPager.setCurrentItem(isLayoutRtl ? mPreviewSampleResIds.length - 1 : 0);
    mPreviewPager.addOnPageChangeListener(mPreviewPageChangeListener);

    mPageIndicator = (DotsPageIndicator) content.findViewById(R.id.page_indicator);
    if (mPreviewSampleResIds.length > 1) {
        mPageIndicator.setViewPager(mPreviewPager);
        mPageIndicator.setVisibility(View.VISIBLE);
        mPageIndicator.setOnPageChangeListener(mPageIndicatorPageChangeListener);
    } else {
        mPageIndicator.setVisibility(View.GONE);
    }

    setPreviewLayer(mInitialIndex, false);
    return root;
}

From source file:com.hyperaware.conference.android.fragment.HomeFragment.java

private void updateUpNextCard() {
    ViewGroup time_groups = (ViewGroup) cardUpNext.findViewById(R.id.vg_time_groups);
    time_groups.removeAllViews();

    final SortedMap<DateRange, List<AgendaItem>> up_next = AgendaItems.upNext(agenda.getItems().values(),
            timeAtUpdate, TimeUnit.DAYS.toMillis(1), TimeUnit.HOURS.toMillis(1));

    if (up_next.size() > 0) {
        populateTimeGroups(up_next, time_groups);
        cardUpNext.setVisibility(View.VISIBLE);
        upNextStartTime = up_next.firstKey().start;
    } else {//from  w  w w.ja va 2s  .  com
        cardUpNext.setVisibility(View.GONE);
    }
}

From source file:com.cihon.androidrestart_keven.activity.CarNumActivity.java

@Override
public void finish() {
    ViewGroup view = (ViewGroup) getWindow().getDecorView();
    view.removeAllViews();
    super.finish();
}

From source file:com.gh4a.activities.GistActivity.java

private void fillData(final Gist gist) {
    mGist = gist;/*w ww.  j a v  a 2  s . c  o m*/

    if (gist.getOwner() != null) {
        getSupportActionBar().setSubtitle(gist.getOwner().getLogin());
    }

    TextView tvDesc = (TextView) findViewById(R.id.tv_desc);
    tvDesc.setText(TextUtils.isEmpty(gist.getDescription()) ? getString(R.string.gist_no_description)
            : gist.getDescription());

    TextView tvCreatedAt = (TextView) findViewById(R.id.tv_created_at);
    tvCreatedAt.setText(StringUtils.formatRelativeTime(this, gist.getCreatedAt(), true));

    Map<String, GistFile> files = gist.getFiles();
    if (files != null && !files.isEmpty()) {
        ViewGroup container = (ViewGroup) findViewById(R.id.file_container);
        LayoutInflater inflater = getLayoutInflater();

        container.removeAllViews();
        for (GistFile gistFile : files.values()) {
            TextView rowView = (TextView) inflater.inflate(R.layout.selectable_label, container, false);

            rowView.setText(gistFile.getFilename());
            rowView.setTextColor(UiUtils.resolveColor(this, android.R.attr.textColorPrimary));
            rowView.setOnClickListener(this);
            rowView.setTag(gistFile);
            container.addView(rowView);
        }
    } else {
        findViewById(R.id.file_card).setVisibility(View.GONE);
    }

    findViewById(R.id.tv_private).setVisibility(gist.isPublic() ? View.GONE : View.VISIBLE);
}

From source file:cs.umass.edu.prepare.view.custom.CalendarAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;//from  ww  w . j  av  a2 s .c om
    TextView dayView;
    if (convertView == null) { // if it's not recycled, initialize some attributes
        v = View.inflate(context, R.layout.calendar_item, null);
    }

    ViewGroup insertPoint = (ViewGroup) v.findViewById(R.id.layout_calendar_item);
    insertPoint.removeAllViews();

    dayView = (TextView) View.inflate(context, R.layout.textview_date, null);
    insertPoint.addView(dayView);

    // disable empty days from the beginning
    if (dateStrings[position].equals("")) {
        dayView.setClickable(false);
        dayView.setFocusable(false);
    } else {
        v.setBackgroundResource(R.drawable.list_item_background);
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, month.get(Calendar.YEAR));
        cal.set(Calendar.MONTH, month.get(Calendar.MONTH));
        cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateStrings[position]));
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
        if (month.get(Calendar.YEAR) == selectedDate.get(Calendar.YEAR)
                && month.get(Calendar.MONTH) == selectedDate.get(Calendar.MONTH)
                && dateStrings[position].equals("" + selectedDate.get(Calendar.DAY_OF_MONTH))) {
            int selectedColor = ContextCompat.getColor(context,
                    R.color.color_calendar_item_background_selected);
            v.setBackgroundColor(selectedColor);
        } else if (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) {
            dayView.setTextColor(Color.GRAY);
        }
    }
    dayView.setText(dateStrings[position]);

    // create date string for comparison
    String dateStr = dateStrings[position];

    if (displayType == DisplayType.BASIC) {
        v.setMinimumHeight(0);
        return v; // do not populate cells
    }
    v.setMinimumHeight(325); // TODO: not device independent

    if (medications == null || adherenceData == null) {
        Log.w(TAG, "Warning : No adherenceData found.");
        return v; // do not populate cells
    }

    if (dateStr.equals(""))
        return v;

    Calendar dateKey = Utils.getDateKey(month.get(Calendar.YEAR), month.get(Calendar.MONTH),
            Integer.parseInt(dateStr));
    if (adherenceData.containsKey(dateKey)) {
        populateCell(dateKey, insertPoint);
    }

    return v;
}

From source file:com.hyperaware.conference.android.fragment.HomeFragment.java

private void updateHappeningNowCard() {
    ViewGroup time_groups = (ViewGroup) cardHappeningNow.findViewById(R.id.vg_time_groups);
    time_groups.removeAllViews();

    final SortedMap<DateRange, List<AgendaItem>> happening = AgendaItems
            .happeningNow(agenda.getItems().values(), timeAtUpdate);

    if (happening.size() > 0) {
        populateTimeGroups(happening, time_groups);
        cardHappeningNow.setVisibility(View.VISIBLE);
        happeningNowStartTime = happening.firstKey().start;
    } else {//w  w  w. j a  va  2  s  .c  om
        cardHappeningNow.setVisibility(View.GONE);
    }
}

From source file:com.hyperaware.conference.android.fragment.HomeFragment.java

private void populateTimeGroups(SortedMap<DateRange, List<AgendaItem>> groups, ViewGroup time_groups) {
    final LayoutInflater inflater = getActivity().getLayoutInflater();

    for (Map.Entry<DateRange, List<AgendaItem>> entry : groups.entrySet()) {
        final ViewGroup sessions_group = (ViewGroup) inflater.inflate(R.layout.item_time_group_sessions,
                time_groups, false);/*from ww w .  j  av  a2s.  c o  m*/
        time_groups.addView(sessions_group);

        final TextView tv_time = (TextView) sessions_group.findViewById(R.id.tv_time);
        final DateRange range = entry.getKey();
        sb.setLength(0);
        DateUtils.formatDateRange(tv_time.getContext(), formatter, range.start, range.end,
                DateUtils.FORMAT_SHOW_TIME, event.getTimezoneName());
        tv_time.setText(formatter.toString());

        final ViewGroup vg_sessions = (ViewGroup) sessions_group.findViewById(R.id.vg_sessions);
        vg_sessions.removeAllViews();
        for (final AgendaItem item : entry.getValue()) {
            final View session = inflater.inflate(R.layout.item_time_group_session, vg_sessions, false);
            vg_sessions.addView(session);
            final TextView tv_topic = (TextView) session.findViewById(R.id.tv_topic);
            tv_topic.setText(item.getTopic());
        }
    }
}

From source file:com.mikecorrigan.trainscorekeeper.Players.java

@SuppressLint("NewApi")
public Players(final Activity context, ViewGroup viewGroup, final JSONArray jsonPlayers) {
    Log.vc(VERBOSE, TAG,/*from ww w  .j  a v a  2  s.co m*/
            "ctor: context=" + context + ", viewGroup=" + viewGroup + ", jsonPlayers=" + jsonPlayers);

    viewGroup.removeAllViews();

    Resources resources = context.getResources();

    String[] playerNames = resources.getStringArray(R.array.playerNames);

    TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables);

    TypedArray colorIdsArray = resources.obtainTypedArray(R.array.playerTextColors);
    int[] colorIds = new int[colorIdsArray.length()];
    for (int i = 0; i < colorIdsArray.length(); i++) {
        colorIds[i] = colorIdsArray.getResourceId(i, -1);
    }

    listeners = new HashSet<Listener>();
    players = new SparseArray<Player>();

    for (int i = 0; i < playerNames.length; i++) {
        PlayerButton toggleButton = new PlayerButton(context);
        toggleButton.setPlayerId(i);
        LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT, 1f);
        toggleButton.setLayoutParams(layoutParams);
        Drawable drawable = drawablesArray.getDrawable(i);
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            toggleButton.setBackgroundDrawable(drawable);
        } else {
            toggleButton.setBackground(drawable);
        }
        toggleButton.setPadding(10, 10, 10, 10);
        toggleButton.setTextColor(resources.getColor(colorIds[i]));
        toggleButton.setOnClickListener(onSelect);

        viewGroup.addView(toggleButton);

        final String name = playerNames[i];

        boolean enabled = true;

        // If the players configuration is available, determine which players are enabled.
        if (jsonPlayers != null) {
            enabled = false;
            for (int j = 0; j < jsonPlayers.length(); j++) {
                String jsonName = jsonPlayers.optString(j, "");
                if (jsonName.equalsIgnoreCase(name)) {
                    enabled = true;
                    break;
                }
            }
        }

        Player player = new Player(toggleButton, i, name, enabled);
        players.put(i, player);
    }

    setSelection(-1);

    drawablesArray.recycle();
    colorIdsArray.recycle();
}

From source file:org.protocoder.MainActivity.java

/**
 * onDestroy/* w  ww . j av  a  2s  .  c  o m*/
 */
@Override
protected void onDestroy() {
    super.onDestroy();
    ViewGroup vg = (ViewGroup) findViewById(R.layout.activity_forfragments);
    if (vg != null) {
        vg.invalidate();
        vg.removeAllViews();
    }
    mProtocoder.app.killConnections();
}