Example usage for android.view ViewGroup addView

List of usage examples for android.view ViewGroup addView

Introduction

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

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:de.stkl.gbgvertretungsplan.fragments.MainFragment.java

private void fillTable(View view, SubstitutionTable.Table day) {
    NavigationDrawerFragment ndf = mCallback.getNavigationDrawerFragment();
    NavigationListAdapter.SubItem o = (NavigationListAdapter.SubItem) ndf.getItemByCId(CId);

    TextView textPlaceholder = (TextView) view.findViewById(R.id.placeholder);

    TableFixHeaders tableFixHeaders = (TableFixHeaders) view.findViewById(R.id.table2);
    TextView updateTime = (TextView) view.findViewById(R.id.updateTime);

    // init values
    SubstitutionTable.Table newDay;//  w  w w. j a  v a2  s  .c o  m

    // filter, if a particular class is selected
    if (o != null)
        newDay = Storage.filter(day, Storage.FilterType.FILTER_CLASS_TEACHER, o.text);
    else
        newDay = Storage.filter(day, Storage.FilterType.FILTER_NONE, null);

    // display substitution info only if display width is greater than treshold
    int width;
    int threshold = getResources().getDimensionPixelSize(R.dimen.table_substitutioninfo_threshold);
    // LayoutMeasureView.w is ALWAYS the width in portrait mode!
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
        width = LayoutMeasureView.screenH;
    else
        width = LayoutMeasureView.screenW;

    if (width < threshold)
        newDay.generalData.flags.add(SubstitutionTable.GeneralData.Flags.HIDE_SUBSTITUTIONINFO);

    int columnWidth[] = new int[day.getHeaderCount()];

    if (newDay.getEntryCount() > 0) {
        SubstitutionPlanAdapter adapter = new SubstitutionPlanAdapter(getActivity(), newDay, columnWidth);

        // initial calculation of column width
        for (int i = 0; i < day.getHeaderCount(); i++) {
            columnWidth[i] = calculateTableColWidth(newDay, adapter, i, tableFixHeaders);
        }

        // assign adapter
        tableFixHeaders.setAdapter(adapter);
        tableFixHeaders.setVisibility(View.VISIBLE);
        textPlaceholder.setVisibility(View.GONE);
    } else {
        tableFixHeaders.setVisibility(View.GONE);
        textPlaceholder.setVisibility(View.VISIBLE);
    }

    // set update time
    updateTime.setText(newDay.generalData.updateTime);

    ViewGroup container = (ViewGroup) view.findViewById(R.id.dailyInfos);
    container.removeAllViews();

    // set daily infos
    int i = 0;
    int c = newDay.generalData.dailyInfos.size();
    View v = null;
    for (SubstitutionTable.GeneralData.DailyInfo info : newDay.generalData.dailyInfos) {
        v = getActivity().getLayoutInflater().inflate(R.layout.table_dailyinfo, container, false);
        TextView tvTitle = (TextView) v.findViewById(R.id.title);
        TextView tvDescription = (TextView) v.findViewById(R.id.description);
        tvTitle.setText(info.title);

        if (info.description.equals("")) {
            ((ViewGroup) v).removeViewInLayout(tvDescription);
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tvTitle.getLayoutParams();
            params.weight = 1f;
        } else
            tvDescription.setText(info.description);

        container.addView(v);
        i++;
    }
}

From source file:com.rubengees.introduction.IntroductionFragment.java

@NonNull
private View initDefaultViews(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.introduction_fragment_default_content, container,
            false);/*w  w  w . ja v a2s  .c  o  m*/
    TextView title = (TextView) root.findViewById(R.id.introduction_fragment_default_content_title);
    ImageView image = (ImageView) root.findViewById(R.id.introduction_fragment_default_content_image);
    ViewGroup descriptionContainer = (ViewGroup) root
            .findViewById(R.id.introduction_fragment_default_content_description_container);
    TextView description;

    if (slide.getTitle() != null) {
        title.setText(slide.getTitle());
        title.setMaxLines(getLineCountForTitle());
        title.setTypeface(IntroductionConfiguration.getInstance().getTitleTypeface());

        if (slide.getTitleSize() != null) {
            title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, slide.getTitleSize());
        }
    }

    if (slide.getDescription() == null && slide.getOption() != null) {
        AppCompatCheckBox option = (AppCompatCheckBox) inflater.inflate(R.layout.introduction_fragment_option,
                descriptionContainer, false);

        option.setText(slide.getOption().getTitle());
        option.setChecked(slide.getOption().isActivated());
        option.setMaxLines(getLineCountForDescription());
        option.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                slide.getOption().setActivated(isChecked);
            }
        });

        CompoundButtonCompat.setButtonTintList(option,
                ContextCompat.getColorStateList(getContext(), android.R.color.white));

        descriptionContainer.addView(option);
        description = option;
    } else {
        description = (TextView) inflater.inflate(R.layout.introduction_fragment_description,
                descriptionContainer, false);

        if (slide.getDescription() != null) {
            description.setText(slide.getDescription());
        }

        description.setMaxLines(getLineCountForDescription());
        descriptionContainer.addView(description);
    }

    description.setTypeface(IntroductionConfiguration.getInstance().getDescriptionTypeface());

    if (slide.getDescriptionSize() != null) {
        description.setTextSize(TypedValue.COMPLEX_UNIT_DIP, slide.getDescriptionSize());
    }

    if (slide.getImageResource() != null) {
        image.setImageResource(slide.getImageResource());
    }

    IntroductionConfiguration.getInstance().callOnSlideInit(slide.getPosition(), title, image, description);

    return root;
}

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

void setContentView() {
    setContentView(R.layout.request);/*from  ww w. j a va  2s  . c om*/

    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:at.alladin.rmbt.android.adapter.result.RMBTResultPagerAdapter.java

@Override
public Object instantiateItem(final ViewGroup vg, final int i) {
    final Context context = vg.getContext();
    final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    System.out.println("instantiateItem: " + i);

    View view = null;/*  www. j a  v a 2 s. c o  m*/

    switch (i) {
    case RESULT_PAGE_QOS:
        view = instantiateQoSDetailView(vg, inflater);
        break;
    case RESULT_PAGE_TEST:
        view = instantiateDetailView(vg, inflater);
        break;
    case RESULT_PAGE_MAIN_MENU:
        view = instantiateResultPage(vg, inflater);
        break;
    case RESULT_PAGE_MAP:
        view = instantiateMapView(vg, inflater);
        break;
    case RESULT_PAGE_GRAPH:
        view = instantiateGraphView(vg, inflater);
        break;
    }

    if (view != null)
        vg.addView(view);
    return view;
}

From source file:com.google.android.apps.iosched.ui.SessionDetailActivity.java

private void onSpeakersQueryComplete(Cursor cursor) {
    try {/*from   w  ww  .java2  s. co m*/
        mSpeakersCursor = true;

        // TODO: remove any existing speakers from layout, since this cursor
        // might be from a data change notification.
        final ViewGroup speakersGroup = (ViewGroup) findViewById(R.id.session_speakers_block);
        final LayoutInflater inflater = getLayoutInflater();

        boolean hasSpeakers = false;

        while (cursor.moveToNext()) {
            final String speakerName = cursor.getString(SpeakersQuery.SPEAKER_NAME);
            final String speakerCompany = cursor.getString(SpeakersQuery.SPEAKER_COMPANY);
            if (TextUtils.isEmpty(speakerName))
                continue;

            final View speakerView = inflater.inflate(R.layout.speaker_detail, speakersGroup, false);

            final String speaker = getString(R.string.speaker_template, speakerName, speakerCompany);
            ((TextView) speakerView.findViewById(R.id.speaker_header)).setText(speaker);

            final String speakerAbstract = cursor.getString(SpeakersQuery.SPEAKER_ABSTRACT);
            final TextView abstractView = (TextView) speakerView.findViewById(R.id.speaker_abstract);
            UIUtils.setTextMaybeHtml(abstractView, speakerAbstract);

            speakersGroup.addView(speakerView);
            hasSpeakers = true;
            mHasSummaryContent = true;
        }

        speakersGroup.setVisibility(hasSpeakers ? View.VISIBLE : View.GONE);

        // Show empty message when all data is loaded, and nothing to show
        if (mSessionCursor && !mHasSummaryContent) {
            findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
        }

    } finally {
        cursor.close();
    }
}

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

private int layoutPunctuationsAndReturnStartIndexOfMoreSuggestions(
        final PunctuationSuggestions punctuationSuggestions, final ViewGroup stripView) {
    final int countInStrip = Math.min(punctuationSuggestions.size(), PUNCTUATIONS_IN_STRIP);
    for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
        if (positionInStrip != 0) {
            // Add divider if this isn't the left most suggestion in suggestions strip.
            addDivider(stripView, mDividerViews.get(positionInStrip));
        }//ww w  .j a  v  a 2  s .c  o  m

        final TextView wordView = mWordViews.get(positionInStrip);
        final String punctuation = punctuationSuggestions.getLabel(positionInStrip);
        // {@link TextView#getTag()} is used to get the index in suggestedWords at
        // {@link SuggestionStripView#onClick(View)}.
        wordView.setTag(positionInStrip);
        wordView.setText(punctuation);
        wordView.setContentDescription(punctuation);
        wordView.setTextScaleX(1.0f);
        wordView.setCompoundDrawables(null, null, null, null);
        wordView.setTextColor(mColorAutoCorrect);
        stripView.addView(wordView);
        setLayoutWeight(wordView, 1.0f, mSuggestionsStripHeight);
    }
    mMoreSuggestionsAvailable = (punctuationSuggestions.size() > countInStrip);
    return countInStrip;
}

From source file:com.achep.base.ui.DialogBuilder.java

/**
 * Builds dialog's view/*from   w  w w .  j  a  v a  2s.c  o m*/
 *
 * @throws IllegalArgumentException when type is not one of defined.
 * @see #LAYOUT_COMMON
 * @see #LAYOUT_SKELETON
 */
public View createView(int type) {
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    ViewGroup rootLayout = (ViewGroup) createSkeleton();
    ViewGroup contentLayout = rootLayout;

    switch (type) {
    case LAYOUT_COMMON:
        final boolean hasMessageOnly = mView == null && mViewRes == 0;
        final int layoutResource = mContentViewRes != 0 ? mContentViewRes
                : hasMessageOnly ? R.layout.dialog_message : R.layout.dialog_content;

        ViewStub viewStub = (ViewStub) inflater.inflate(R.layout.dialog_main_body, rootLayout, true)
                .findViewById(R.id.placeholder);
        viewStub.setLayoutResource(layoutResource);

        contentLayout = (ViewGroup) viewStub.inflate().findViewById(R.id.content);
        if (contentLayout == null)
            contentLayout = rootLayout;
        TextView messageView = (TextView) contentLayout.findViewById(R.id.message);

        if (messageView != null) {
            if (!TextUtils.isEmpty(mMessageText)) {
                messageView.setMovementMethod(new LinkMovementMethod());
                messageView.setText(mMessageText);
            } else {
                ViewGroup vg = (ViewGroup) messageView.getParent();
                vg.removeView(messageView);
            }
        }

        // Fall down.
    case LAYOUT_SKELETON:

        if (mViewRes != 0) {
            inflater.inflate(mViewRes, contentLayout, true);
        } else if (mView != null) {
            contentLayout.addView(mView);
        }

        return rootLayout;
    default:
        throw new IllegalArgumentException();
    }
}

From source file:com.tomeokin.lspush.biz.home.CollectionListAdapter.java

private void setExplorers(ViewGroup container, @Nullable List<User> explorers) {
    final Context context = container.getContext();
    // // TODO: 2016/10/8 performance improve
    //container.removeAllViews();
    //for (User explorer : explorers) {
    //    final ImageView avatar =
    //        (ImageView) LayoutInflater.from(context).inflate(R.layout.layout_item_explorer, container, false);
    //    ImageLoader.loadAvatar(context, avatar, explorer.getImage());
    //    container.addView(avatar);
    //}/*from w w w  .j  a  v a 2s .  com*/

    final int count = container.getChildCount();
    int targetCount = explorers == null ? 0 : explorers.size();
    targetCount = targetCount >= 5 ? 5 : targetCount;
    final LayoutInflater inflater = LayoutInflater.from(context);
    if (count > targetCount) {
        container.removeViews(targetCount, count - targetCount);
    }
    ImageView avatar;
    for (int i = 0; i < targetCount; i++) {
        if (i > count - 1) { // no cache
            avatar = (ImageView) inflater.inflate(R.layout.layout_item_explorer, container, false);
        } else {
            avatar = (ImageView) container.getChildAt(i);
        }
        ImageLoader.loadAvatar(context, avatar, explorers.get(i).getImage());
        if (avatar.getParent() == null) {
            container.addView(avatar);
        }
        avatar.setTag(R.id.avatar_tag_uid, explorers.get(i).getUid());
        avatar.setOnClickListener(mExplorerListener);
    }
}

From source file:de.gebatzens.ggvertretungsplan.fragment.RemoteDataFragment.java

public void createButtonWithText(Activity activity, ViewGroup l, String text, String button,
        View.OnClickListener onclick) {
    RelativeLayout r = new RelativeLayout(activity);
    r.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    TextView tv = new TextView(activity);
    RelativeLayout.LayoutParams tvparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tvparams.addRule(RelativeLayout.ABOVE, R.id.reload_button);
    tvparams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    tv.setLayoutParams(tvparams);//from   w  ww . j a  va 2  s . c o  m
    tv.setText(text);
    tv.setTextSize(23);
    tv.setPadding(0, 0, 0, toPixels(15));
    tv.setGravity(Gravity.CENTER_HORIZONTAL);
    r.addView(tv);

    Button b = new Button(activity);
    RelativeLayout.LayoutParams bparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    bparams.addRule(RelativeLayout.CENTER_VERTICAL);
    bparams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    b.setLayoutParams(bparams);
    b.setId(R.id.reload_button);
    b.setText(button);
    b.setTextSize(23);
    b.setAllCaps(false);
    b.setTypeface(null, Typeface.NORMAL);
    b.setOnClickListener(onclick);
    r.addView(b);

    l.addView(r);
}

From source file:com.simas.vc.editor.player.PlayerFragment.java

void toggleFullscreen() {
    // Disable touch listener (to prevent multiple toggles until done)
    getContainer().setOnTouchListener(null);
    final ViewGroup root = (ViewGroup) getActivity().findViewById(android.R.id.content);
    final View progressOverlay = (getActivity() instanceof MainActivity)
            ? ((MainActivity) getActivity()).getProgressOverlay()
            : null;/*w  w w  .j  av a  2s .  c  o  m*/
    if (progressOverlay != null) {
        progressOverlay.setVisibility(View.VISIBLE);
        ViewGroup progressParent = (ViewGroup) progressOverlay.getParent();
        if (progressParent != null) {
            progressParent.removeView(progressOverlay);
        }
    }

    // Toggle state
    mFullscreen = !isFullscreen();

    if (isFullscreen()) {
        // Add preview to the root view
        if (progressOverlay != null) {
            root.addView(progressOverlay);
        }

        // All APIs can go fullscreen
        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Low profile is only for APIs 14+
        if (Build.VERSION.SDK_INT >= 14) {
            // Enable the low profile mode
            getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
        }

    } else {
        // Add preview to the default parent
        if (mDefaultContainerParent != null && progressOverlay != null) {
            mDefaultContainerParent.addView(progressOverlay);
        }

        // All APIs can go fullscreen
        getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Low profile is only for APIs 14+
        if (Build.VERSION.SDK_INT >= 14) {
            // Remove low profile
            getActivity().getWindow().getDecorView().setSystemUiVisibility(ViewGroup.SYSTEM_UI_FLAG_VISIBLE);
        }
    }

    final Runnable changeContainerParent = new Runnable() {
        @Override
        public void run() {
            // Hide surface view while doing all the work, this is to make sure it's not being re-drawn
            mSurfaceView.setVisibility(View.GONE);

            // Controls should be hidden while working
            final boolean controlsWereShown = getControls().isShown();
            getControls().hide();

            // Video should be paused while working
            boolean playing = false;
            if (getPlayer().getState() == Player.State.STARTED) {
                // Pause if started
                playing = true;
                getPlayer().pause();
            }
            final boolean wasPlaying = playing;

            // Expand or collapse the PlayerView
            if (isFullscreen()) {
                // Save current params
                mDefaultContainerParams = new ViewGroup.LayoutParams(getContainer().getLayoutParams());

                // Remove from current parent
                mDefaultContainerParent = (ViewGroup) getContainer().getParent();
                mDefaultContainerParent.removeView(getContainer());

                // Set new params
                ViewGroup.LayoutParams params = getContainer().getLayoutParams();
                params.width = LinearLayout.LayoutParams.MATCH_PARENT;
                params.height = LinearLayout.LayoutParams.MATCH_PARENT;

                // Re-measure the SurfaceView
                invalidateSurface();

                // Add to the root view before the progressOverlay (if it's added)
                int progressIndex = root.indexOfChild(progressOverlay);
                root.addView(getContainer(), progressIndex);
                getContainer().requestFocus();
            } else {
                if (mDefaultContainerParams != null && mDefaultContainerParent != null) {
                    // Remove from current parent
                    ((ViewGroup) getContainer().getParent()).removeView(getContainer());

                    // Restore params
                    getContainer().setLayoutParams(mDefaultContainerParams);

                    // Re-measure the SurfaceView
                    invalidateSurface();

                    // Add as the first child to the default parent
                    mDefaultContainerParent.addView(getContainer(), 0);
                }
            }

            getContainer().post(new Runnable() {
                @Override
                public void run() {
                    mSurfaceView.setVisibility(View.VISIBLE);
                    // Check if fragment and player data sources match
                    if (getItem() != null
                            && getItem().getFile().getPath().equals(getPlayer().getDataSource())) {
                        switch (getPlayer().getState()) {
                        case PAUSED:
                        case PREPARED:
                        case STARTED:
                            if (wasPlaying) {
                                getPlayer().start();
                            } else {
                                updatePreview();
                            }
                            break;
                        }
                    } else {
                        setPreviewVisible(true);
                    }
                    if (controlsWereShown) {
                        getControls().show();
                    }
                    if (progressOverlay != null) {
                        progressOverlay.setVisibility(View.INVISIBLE);
                    }
                    // Re-enable touch listener
                    getContainer().post(new Runnable() {
                        @Override
                        public void run() {
                            getContainer().setOnTouchListener(PlayerFragment.this);
                        }
                    });
                }
            });
        }
    };

    if (getPlayer().getState() == Player.State.PREPARING) {
        getPlayer().addOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                changeContainerParent.run();
            }
        });
    } else {
        changeContainerParent.run();
    }
}