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:android.support.v7.app.AppCompatDelegateImplV7.java

@Override
public void setContentView(View v) {
    ensureSubDecor();//  w  ww  .  ja  v a  2 s.  c o m
    ViewGroup contentParent = (ViewGroup) mSubDecor.findViewById(android.R.id.content);
    contentParent.removeAllViews();
    contentParent.addView(v);
    mOriginalWindowCallback.onContentChanged();
}

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

private void showLabelDialog() {
    if (mAllLabels == null) {
        mProgressDialog = showProgressDialog(getString(R.string.loading_msg), true);
        getSupportLoaderManager().initLoader(0, null, mLabelCallback);
    } else {/*from  w  w  w.ja  v  a 2 s.co  m*/
        LayoutInflater inflater = getLayoutInflater();
        final List<Label> selectedLabels = mEditIssue.getLabels() != null
                ? new ArrayList<>(mEditIssue.getLabels())
                : new ArrayList<Label>();
        View labelContainerView = inflater.inflate(R.layout.generic_linear_container, null);
        ViewGroup container = (ViewGroup) labelContainerView.findViewById(R.id.container);

        View.OnClickListener clickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Label label = (Label) view.getTag();
                if (selectedLabels.contains(label)) {
                    selectedLabels.remove(label);
                    setLabelSelection((TextView) view, false);
                } else {
                    selectedLabels.add(label);
                    setLabelSelection((TextView) view, true);
                }
            }
        };

        for (final Label label : mAllLabels) {
            final View rowView = inflater.inflate(R.layout.row_issue_create_label, container, false);
            View viewColor = rowView.findViewById(R.id.view_color);
            viewColor.setBackgroundColor(ApiHelpers.colorForLabel(label));

            final TextView tvLabel = (TextView) rowView.findViewById(R.id.tv_title);
            tvLabel.setText(label.getName());
            tvLabel.setOnClickListener(clickListener);
            tvLabel.setTag(label);

            setLabelSelection(tvLabel, selectedLabels.contains(label));
            container.addView(rowView);
        }

        new AlertDialog.Builder(this).setCancelable(true).setTitle(R.string.issue_labels)
                .setView(labelContainerView).setNegativeButton(R.string.cancel, null)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mEditIssue.setLabels(selectedLabels);
                        updateLabels();
                    }
                }).show();
    }
}

From source file:com.aretha.slidemenu.SlideMenu.java

/**
 * Resolve the attribute slideMode//from www  .java 2s  .  c om
 */
protected void resolveSlideMode() {
    final ViewGroup decorView = (ViewGroup) getRootView();
    final ViewGroup contentContainer = (ViewGroup) decorView.findViewById(android.R.id.content);
    final View content = mContent;
    if (null == decorView || null == content || 0 == getChildCount()) {
        return;
    }

    TypedValue value = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.windowBackground, value, true);

    switch (mSlideMode) {
    case MODE_SLIDE_WINDOW: {
        // remove this view from parent
        removeViewFromParent(this);
        // copy the layoutparams of content
        LayoutParams contentLayoutParams = new LayoutParams(content.getLayoutParams());
        // remove content view from this view
        removeViewFromParent(content);
        // add content to layout root view
        contentContainer.addView(content);

        // get window with ActionBar
        View decorChild = decorView.getChildAt(0);
        decorChild.setBackgroundResource(0);
        removeViewFromParent(decorChild);
        addView(decorChild, contentLayoutParams);

        // add this view to root view
        decorView.addView(this);
        setBackgroundResource(value.resourceId);
    }
        break;
    case MODE_SLIDE_CONTENT: {
        // remove this view from decor view
        setBackgroundResource(0);
        removeViewFromParent(this);
        // get the origin content view from the content wrapper
        View originContent = contentContainer.getChildAt(0);
        // this is the decor child remove from decor view
        View decorChild = mContent;
        LayoutParams layoutParams = (LayoutParams) decorChild.getLayoutParams();
        // remove the origin content from content wrapper
        removeViewFromParent(originContent);
        // remove decor child from this view
        removeViewFromParent(decorChild);
        // restore the decor child to decor view
        decorChild.setBackgroundResource(value.resourceId);
        decorView.addView(decorChild);
        // add this view to content wrapper
        contentContainer.addView(this);
        // add the origin content to this view
        addView(originContent, layoutParams);
    }
        break;
    }
}

From source file:com.scoreflex.ScoreflexView.java

protected View openNewView(String resource, Scoreflex.RequestParams params, boolean forceFullScreen) {
    int gravity = getLayoutGravity();
    int anim = (Gravity.TOP == (gravity & Gravity.VERTICAL_GRAVITY_MASK)) ? R.anim.scoreflex_enter_slide_down
            : R.anim.scoreflex_enter_slide_up;
    Animation animation = AnimationUtils.loadAnimation(mParentActivity, anim);

    ScoreflexView webview = new ScoreflexView(mParentActivity);
    webview.setResource(resource, params, forceFullScreen);
    ViewGroup contentView = (ViewGroup) mParentActivity.getWindow().getDecorView()
            .findViewById(android.R.id.content);
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, gravity);
    webview.setLayoutParams(layoutParams);
    contentView.addView(webview);
    webview.startAnimation(animation);/*from w  ww  .  ja va2s .co m*/
    Scoreflex.setCurrentScoreflexView(this);
    return webview;
}

From source file:cm.aptoide.ptdev.adapters.ViewPagerAdapterScreenshots.java

@Override
public Object instantiateItem(ViewGroup container, final int position) {

    final View v = LayoutInflater.from(context).inflate(R.layout.row_item_screenshots_big, null);
    final ProgressBar pb = (ProgressBar) v.findViewById(R.id.screenshots_loading_big);

    String icon;//  w  w  w  .  j a va 2  s  .  c  o  m
    if (hd) {
        Log.d("Aptoide-Screenshots", "Icon is hd: " + url.get(position));

        if (url.get(position).contains("_screen")) {
            icon = url.get(position).split("\\|")[1];
            Log.d("Aptoide-Screenshots", "Icon is : " + icon);
        } else {
            icon = url.get(position);
        }

    } else {
        icon = screenshotToThumb(url.get(position));
    }

    imageLoader.displayImage(icon, (ImageView) v.findViewById(R.id.screenshot_image_big), options,
            new ImageLoadingListener() {

                @Override
                public void onLoadingStarted(String uri, View view) {
                    pb.setVisibility(View.VISIBLE);
                }

                @Override
                public void onLoadingFailed(String uri, View v, FailReason failReason) {
                    ((ImageView) v.findViewById(R.id.screenshot_image_big))
                            .setImageResource(android.R.drawable.ic_delete);
                    pb.setVisibility(View.GONE);
                }

                @Override
                public void onLoadingComplete(String uri, View v, Bitmap loadedImage) {
                    pb.setVisibility(View.GONE);
                }

                @Override
                public void onLoadingCancelled(String uri, View v) {
                }
            });
    container.addView(v);
    if (!hd) {
        v.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                Intent i = new Intent(context, ScreenshotsViewer.class);
                i.putStringArrayListExtra("url", url);
                i.putExtra("position", position);
                i.putExtra("hashCode", hashCode + ".hd");
                context.startActivity(i);
            }
        });
    }
    return v;

}

From source file:com.tmall.ultraviewpager.UltraViewPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int realPosition = position;
    //TODO//w  ww  . j  a v  a2  s  .  c  o m
    if (enableLoop && adapter.getCount() != 0) {
        realPosition = position % adapter.getCount();
    }

    Object item = adapter.instantiateItem(container, realPosition);
    //TODO
    View childView = null;
    if (item instanceof View)
        childView = (View) item;
    if (item instanceof RecyclerView.ViewHolder)
        childView = ((RecyclerView.ViewHolder) item).itemView;

    ViewPager viewPager = (ViewPager) container;
    int childCount = viewPager.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = viewPager.getChildAt(i);
        if (isViewFromObject(child, item)) {
            viewArray.put(realPosition, child);
            break;
        }
    }

    if (isEnableMultiScr()) {
        if (scrWidth == 0) {
            scrWidth = container.getResources().getDisplayMetrics().widthPixels;
        }
        RelativeLayout relativeLayout = new RelativeLayout(container.getContext());

        if (childView.getLayoutParams() != null) {
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                    (int) (scrWidth * multiScrRatio), ViewGroup.LayoutParams.MATCH_PARENT);

            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
            childView.setLayoutParams(layoutParams);
        }

        container.removeView(childView);
        relativeLayout.addView(childView);

        container.addView(relativeLayout);
        return relativeLayout;
    }

    return item;
}

From source file:com.qs.qswlw.view.Mypager.UltraViewPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int realPosition = position;
    //TODO//  ww  w.  j  ava  2 s  .c  om
    if (enableLoop && adapter.getCount() != 0) {
        realPosition = position % adapter.getCount();
    }

    Object item = adapter.instantiateItem(container, realPosition);
    //TODO
    View childView = null;
    if (item instanceof View)
        childView = (View) item;
    //        if (item instanceof RecyclerView.ViewHolder)
    //            childView = ((RecyclerView.ViewHolder) item).itemView;

    ViewPager viewPager = (ViewPager) container;
    int childCount = viewPager.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = viewPager.getChildAt(i);
        if (isViewFromObject(child, item)) {
            viewArray.put(realPosition, child);
            break;
        }
    }

    if (isEnableMultiScr()) {
        if (scrWidth == 0) {
            scrWidth = container.getResources().getDisplayMetrics().widthPixels;
        }
        RelativeLayout relativeLayout = new RelativeLayout(container.getContext());

        if (childView.getLayoutParams() != null) {
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                    (int) (scrWidth * multiScrRatio), ViewGroup.LayoutParams.MATCH_PARENT);

            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
            childView.setLayoutParams(layoutParams);
        }

        container.removeView(childView);
        relativeLayout.addView(childView);

        container.addView(relativeLayout);
        return relativeLayout;
    }

    return item;
}

From source file:de.mrapp.android.dialog.decorator.WizardDialogDecorator.java

/**
 * Inflates the tab layout, which indicates the currently shown fragment.
 *//*from  w w w.  ja v a  2s . co  m*/
private void inflateTabLayout() {
    if (getDialogRootView() != null) {
        LayoutInflater layoutInflater = LayoutInflater.from(getContext());
        ViewGroup headerContainer = (ViewGroup) getDialogRootView().findViewById(R.id.header);
        ViewGroup contentContainer = (ViewGroup) getDialogRootView().findViewById(R.id.content_container);

        if (tabLayout != null) {
            headerContainer.removeViewInLayout(tabLayout);
            contentContainer.removeView(tabLayout);
            tabLayout = null;
        }

        if (getDialog().isHeaderShown() && getTabPosition() != TabPosition.NO_HEADER
                && ((TextUtils.isEmpty(getDialog().getTitle()) && TextUtils.isEmpty(getDialog().getMessage()))
                        || getTabPosition() == TabPosition.PREFER_HEADER)) {
            tabLayout = (TabLayout) layoutInflater.inflate(R.layout.wizard_dialog_tab_layout, headerContainer,
                    false);
            headerContainer.addView(tabLayout);
        } else {
            tabLayout = (TabLayout) layoutInflater.inflate(R.layout.wizard_dialog_tab_layout, contentContainer,
                    false);
            contentContainer.addView(tabLayout, 0);
        }

        tabLayout.setupWithViewPager(viewPager);
    }
}

From source file:com.dk.view.FolderDrawerLayout.java

private void revertView() {
    if (mLeftCache != null && mLeftCache.getParent() == null) {
        ViewGroup left = (ViewGroup) findDrawerWithGravity(Gravity.LEFT);
        left.removeAllViews();/*w  ww.  j a v  a2 s.c o m*/
        left.addView(mLeftCache);
    }
}

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

@SuppressLint("NewApi")
public Players(final Activity context, ViewGroup viewGroup, final JSONArray jsonPlayers) {
    Log.vc(VERBOSE, TAG,//  w ww. 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();
}