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:com.gh4a.fragment.PullRequestFragment.java

private void fillStatus(List<CommitStatus> statuses) {
    Map<String, CommitStatus> statusByContext = new HashMap<>();
    for (CommitStatus status : statuses) {
        if (!statusByContext.containsKey(status.getContext())) {
            statusByContext.put(status.getContext(), status);
        }/*from  w w  w  .  j a va2  s  .  co m*/
    }

    final int statusIconDrawableAttrId, statusLabelResId;
    if (PullRequest.MERGEABLE_STATE_CLEAN.equals(mPullRequest.getMergeableState())) {
        statusIconDrawableAttrId = R.attr.pullRequestMergeOkIcon;
        statusLabelResId = R.string.pull_merge_status_clean;
    } else if (PullRequest.MERGEABLE_STATE_UNSTABLE.equals(mPullRequest.getMergeableState())) {
        statusIconDrawableAttrId = R.attr.pullRequestMergeUnstableIcon;
        statusLabelResId = R.string.pull_merge_status_unstable;
    } else if (PullRequest.MERGEABLE_STATE_DIRTY.equals(mPullRequest.getMergeableState())) {
        statusIconDrawableAttrId = R.attr.pullRequestMergeDirtyIcon;
        statusLabelResId = R.string.pull_merge_status_dirty;
    } else if (statusByContext.isEmpty()) {
        // unknwon status, no commit statuses -> nothing to display
        return;
    } else {
        statusIconDrawableAttrId = R.attr.pullRequestMergeUnknownIcon;
        statusLabelResId = R.string.pull_merge_status_unknown;
    }

    ImageView statusIcon = (ImageView) mListHeaderView.findViewById(R.id.iv_merge_status_icon);
    statusIcon.setImageResource(UiUtils.resolveDrawable(getActivity(), statusIconDrawableAttrId));

    TextView statusLabel = (TextView) mListHeaderView.findViewById(R.id.merge_status_label);
    statusLabel.setText(statusLabelResId);

    ViewGroup statusContainer = (ViewGroup) mListHeaderView.findViewById(R.id.merge_commit_status_container);
    LayoutInflater inflater = getLayoutInflater(null);
    statusContainer.removeAllViews();
    for (CommitStatus status : statusByContext.values()) {
        View statusRow = inflater.inflate(R.layout.row_commit_status, statusContainer, false);

        String state = status.getState();
        final int iconDrawableAttrId;
        if (CommitStatus.STATE_ERROR.equals(state) || CommitStatus.STATE_FAILURE.equals(state)) {
            iconDrawableAttrId = R.attr.commitStatusFailIcon;
        } else if (CommitStatus.STATE_SUCCESS.equals(state)) {
            iconDrawableAttrId = R.attr.commitStatusOkIcon;
        } else {
            iconDrawableAttrId = R.attr.commitStatusUnknownIcon;
        }
        ImageView icon = (ImageView) statusRow.findViewById(R.id.iv_status_icon);
        icon.setImageResource(UiUtils.resolveDrawable(getActivity(), iconDrawableAttrId));

        TextView context = (TextView) statusRow.findViewById(R.id.tv_context);
        context.setText(status.getContext());

        TextView description = (TextView) statusRow.findViewById(R.id.tv_desc);
        description.setText(status.getDescription());

        statusContainer.addView(statusRow);
    }
    mListHeaderView.findViewById(R.id.merge_commit_no_status)
            .setVisibility(statusByContext.isEmpty() ? View.VISIBLE : View.GONE);

    mListHeaderView.findViewById(R.id.merge_status_container).setVisibility(View.VISIBLE);
}

From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java

/**
 *  Activity /*from w  w  w. j  av  a2s. c  om*/
 *
 * @param activity
 */
public void attachToActivity(Activity activity) {
    mActivity = activity;

    setSliderFadeColor(Color.TRANSPARENT);

    mShadowView = new View(activity);
    setIsNeedShowShadow(mIsNeedShowShadow);
    addView(mShadowView, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    mContentView = decorView.getChildAt(0);
    decorView.removeView(mContentView);
    decorView.addView(this);
    addView(mContentView, 1, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}

From source file:com.taobao.weex.ui.component.WXVContainer.java

/********************************
 *  end hook Activity life cycle callback
 ********************************************************/

public @Nullable View getBoxShadowHost(boolean isClear) {
    if (isClear) {
        // Return existed host if want clear shadow
        return mBoxShadowHost;
    }//w  ww.  j a v  a 2 s .  c o m

    ViewGroup hostView = getHostView();
    if (hostView == null) {
        return null;
    }

    try {
        String type = getComponentType();
        if (WXBasicComponentType.DIV.equals(type)) {
            WXLogUtils.d("BoxShadow", "Draw box-shadow with BoxShadowHost on div: " + toString());
            if (mBoxShadowHost == null) {
                mBoxShadowHost = new BoxShadowHost(getContext());
                WXViewUtils.setBackGround(mBoxShadowHost, null, this);

                CSSShorthand padding = this.getPadding();
                CSSShorthand border = this.getBorder();

                int left = (int) (padding.get(CSSShorthand.EDGE.LEFT) + border.get(CSSShorthand.EDGE.LEFT));
                int top = (int) (padding.get(CSSShorthand.EDGE.TOP) + border.get(CSSShorthand.EDGE.TOP));
                int right = (int) (padding.get(CSSShorthand.EDGE.RIGHT) + border.get(CSSShorthand.EDGE.RIGHT));
                int bottom = (int) (padding.get(CSSShorthand.EDGE.BOTTOM)
                        + border.get(CSSShorthand.EDGE.BOTTOM));

                ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(
                        hostView.getLayoutParams());
                layoutParams.setMargins(-left, -top, -right, -bottom);

                mBoxShadowHost.setLayoutParams(layoutParams);

                hostView.addView(mBoxShadowHost);
            }
            hostView.removeView(mBoxShadowHost);
            hostView.addView(mBoxShadowHost);
            return mBoxShadowHost;
        }
    } catch (Throwable t) {
        WXLogUtils.w("BoxShadow", t);
    }
    return hostView;
}

From source file:com.siso.app.adapter.BannerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final View view = viewlist.get(position);
    final ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_img);
    //      final LinearLayout loading = (LinearLayout)view.findViewById(R.id.item_banner_loading);
    Log.i("tag", "imgUrl[position]==" + imgUrl[position]);
    if (imageView.getDrawable() == null) {
        Picasso picasso = Picasso.with(imageView.getContext());
        picasso.load(imgUrl[position]).into(imageView);
        //         Log.i("image", "position=="+position+""+imgUrl[position]);
        //         AsyncHttpClient client=new AsyncHttpClient();
        //         client.get(imgUrl[position], new AsyncHttpResponseHandler() {
        //            
        //            @Override
        //            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
        //               if(statusCode==200){
        //                  BitmapFactory factory=new BitmapFactory();
        //                  Bitmap bitmap=factory.decodeByteArray(responseBody, 0, responseBody.length);
        //                  imageView.setImageBitmap(bitmap);
        //                  loading.setVisibility(View.GONE);
        //               }
        //            }
        //            
        //            @Override
        //            public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
        //               loading.setVisibility(View.GONE);
        //               Toast.makeText(context, context.getResources().getString(R.string.timeoutError), Toast.LENGTH_SHORT);
        //            }
        //         });
    }//from   w  ww  .j  a va 2 s  .  c  o  m

    ViewParent vp = view.getParent();
    if (vp != null) {
        ViewGroup parent = (ViewGroup) vp;
        parent.removeView(view);
    }
    container.addView(view);
    return view;
}

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

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

    LinearLayout l2 = new LinearLayout(getActivity());
    l2.setOrientation(LinearLayout.VERTICAL);
    RelativeLayout.LayoutParams layoutparams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutparams.addRule(RelativeLayout.CENTER_VERTICAL);
    l2.setLayoutParams(layoutparams);// w ww.j av  a 2s . c o  m
    l2.setGravity(Gravity.CENTER_HORIZONTAL);

    TextView tv = new TextView(getActivity());
    LinearLayout.LayoutParams tvparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    tv.setLayoutParams(tvparams);
    tv.setText(text);
    tv.setTextSize(23);
    tv.setPadding(0, 0, 0, toPixels(15));
    l2.addView(tv);

    if (button != null) {
        Button b = new Button(getActivity());
        LinearLayout.LayoutParams bparams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        bparams.setMargins(toPixels(4), toPixels(0), toPixels(4), toPixels(4));
        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);
        l2.addView(b);
    }

    r.addView(l2);
    l.addView(r);
}

From source file:com.waz.zclient.pages.main.conversation.SingleImageFragment.java

private void initAnimatingImageView(boolean afterFling) {
    if (getView() == null) {
        return;//from   w w  w  .  ja va  2s . c o  m
    }
    ViewGroup parent = (ViewGroup) animatingImageView.getParent();
    parent.removeView(animatingImageView);

    final int displayHeight = ViewUtils.getOrientationDependentDisplayHeight(getActivity())
            - ViewUtils.getStatusBarHeight(getActivity());
    final int displayWidth = ViewUtils.getOrientationDependentDisplayWidth(getActivity());
    final int finalTop;
    final int finalLeft;
    if (afterFling) {
        finalLeft = (int) flingImageLeft;
        finalTop = (int) flingImageTop;
        animatingImageView.setPivotX(flingImagePivotX);
        animatingImageView.setPivotY(flingImagePivotY);
        animatingImageView.setRotation(flingRotation);
    } else {
        finalTop = (displayHeight - clickedImageHeight) / 2;
        finalLeft = (displayWidth - clickedImageWidth) / 2;
    }
    final float scale = Math.min(displayWidth / (float) clickedImageWidth,
            displayHeight / (float) clickedImageHeight);

    ViewGroup.LayoutParams layoutParams = new FrameLayout.LayoutParams(clickedImageWidth, clickedImageHeight);
    animatingImageView.setLayoutParams(layoutParams);
    animatingImageView.setX(finalLeft);
    animatingImageView.setY(finalTop);
    animatingImageView.setScaleX(scale);
    animatingImageView.setScaleY(scale);

    parent.addView(animatingImageView);
}

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

private void updateLinksTab(Cursor cursor) {
    ViewGroup container = (ViewGroup) mRootView.findViewById(R.id.links_container);

    // Remove all views but the 'empty' view
    int childCount = container.getChildCount();
    if (childCount > 1) {
        container.removeViews(1, childCount - 1);
    }/*from   w  w w .j a v  a2 s  .co  m*/

    LayoutInflater inflater = getLayoutInflater(null);

    boolean hasLinks = false;
    for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) {
        final String url = cursor.getString(SessionsQuery.LINKS_INDICES[i]);
        if (!TextUtils.isEmpty(url)) {
            hasLinks = true;
            ViewGroup linkContainer = (ViewGroup) inflater.inflate(R.layout.list_item_session_link, container,
                    false);
            ((TextView) linkContainer.findViewById(R.id.link_text)).setText(SessionsQuery.LINKS_TITLES[i]);
            final int linkTitleIndex = i;
            linkContainer.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    fireLinkEvent(SessionsQuery.LINKS_TITLES[linkTitleIndex]);
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    startActivity(intent);

                }
            });

            container.addView(linkContainer);

            // Create separator
            View separatorView = new ImageView(getActivity());
            separatorView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            separatorView.setBackgroundResource(android.R.drawable.divider_horizontal_bright);
            container.addView(separatorView);
        }
    }

    container.findViewById(R.id.empty_links).setVisibility(hasLinks ? View.GONE : View.VISIBLE);
}

From source file:com.projectsexception.about.adapters.ColumnsAdapter.java

@Override
public Object instantiateItem(View view, int position) {
    ViewGroup viewGroup = (ViewGroup) view;
    View newView;//from   w  w  w.  j  a va  2s. co m

    String appName = context.getString(R.string.about_app_name);

    if (position == 0) {
        newView = inflater.inflate(R.layout.about_comments, null);
        Button button = (Button) newView.findViewById(R.id.about_like);
        button.setText(context.getString(R.string.about_comments_like, appName));
        String[] lines = context.getResources().getStringArray(R.array.about_comments_pro_features);
        if (lines.length == 0) {
            // No se han especificado caractersticas de la versin PRO
            // Suponemos por tanto que no hay versin PRO
            newView.findViewById(R.id.about_getpro).setVisibility(View.GONE);
            newView.findViewById(R.id.about_comments_pro_title).setVisibility(View.GONE);
            newView.findViewById(R.id.about_comments_pro_features).setVisibility(View.GONE);
        } else {
            TextView textView = (TextView) newView.findViewById(R.id.about_comments_pro_features);
            for (String line : lines) {
                textView.append(line);
                textView.append("\n");
            }
        }
    } else if (position == 1) {
        newView = inflater.inflate(R.layout.about_contact, null);
        TextView textView = (TextView) newView.findViewById(R.id.about_contact_title);
        textView.setText(appName);
        textView = (TextView) newView.findViewById(R.id.about_contact_license_content);
        new LicenseTask(context).execute(textView);
    } else {
        newView = inflater.inflate(R.layout.about_apps, null);
        ListView listView = (ListView) newView.findViewById(android.R.id.list);
        ApplicationsAdapter adapter = new ApplicationsAdapter(context);
        listView.setAdapter(adapter);
        new AppsTask(context).execute(adapter);
    }

    viewGroup.addView(newView);
    return newView;
}

From source file:com.tr4android.support.extension.picker.date.DayPickerPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final View itemView = mInflater.inflate(mLayoutResId, container, false);

    final SimpleMonthView v = (SimpleMonthView) itemView.findViewById(mCalendarViewId);
    v.setOnDayClickListener(mOnDayClickListener);
    v.setMonthTextAppearance(mMonthTextAppearance);
    v.setDayOfWeekTextAppearance(mDayOfWeekTextAppearance);
    v.setDayTextAppearance(mDayTextAppearance);

    if (mDaySelectorColor != null) {
        v.setDaySelectorColor(mDaySelectorColor);
    }/*from  w  w w  .  j a  va 2s  .c  o  m*/

    if (mDayHighlightColor != null) {
        v.setDayHighlightColor(mDayHighlightColor);
    }

    final int month = getMonthForPosition(position);
    final int year = getYearForPosition(position);

    final int selectedDay;
    if (mSelectedDay != null && mSelectedDay.get(Calendar.MONTH) == month) {
        selectedDay = mSelectedDay.get(Calendar.DAY_OF_MONTH);
    } else {
        selectedDay = -1;
    }

    final int enabledDayRangeStart;
    if (mMinDate.get(Calendar.MONTH) == month && mMinDate.get(Calendar.YEAR) == year) {
        enabledDayRangeStart = mMinDate.get(Calendar.DAY_OF_MONTH);
    } else {
        enabledDayRangeStart = 1;
    }

    final int enabledDayRangeEnd;
    if (mMaxDate.get(Calendar.MONTH) == month && mMaxDate.get(Calendar.YEAR) == year) {
        enabledDayRangeEnd = mMaxDate.get(Calendar.DAY_OF_MONTH);
    } else {
        enabledDayRangeEnd = 31;
    }

    v.setMonthParams(selectedDay, month, year, mFirstDayOfWeek, enabledDayRangeStart, enabledDayRangeEnd);

    final ViewHolder holder = new ViewHolder(position, itemView, v);
    mItems.put(position, holder);

    container.addView(itemView);

    return holder;
}

From source file:com.tecnojin.timekiller.menuviews.GamePageAdapter.java

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

    GameDescriptor descriptor = GameManager.instance(context).getGameFromIndex(context, position);

    View layout = inflater.inflate(R.layout.game_page, null);

    TextView t = (TextView) layout.findViewById(R.id.game_name);
    ImageView icon = (ImageView) layout.findViewById(R.id.gameIcon);

    ImageView sett = (ImageView) layout.findViewById(R.id.settings);
    ImageView tutorial = (ImageView) layout.findViewById(R.id.tutorial);
    ImageView stat = (ImageView) layout.findViewById(R.id.stat);

    if (descriptor.getName() != 0) {
        t.setText(descriptor.getName());
        ActivityUtil.setFont(t, ActivityUtil.FONTS_BATES_SHOWER);
        if (descriptor.isReady())
            icon.setImageResource(descriptor.getIcon());
        else//from   w w  w. ja v a  2 s  .  co m
            icon.setImageResource(R.drawable.work);

        if (!descriptor.isReady()) {
            tutorial.setEnabled(false);
            icon.setEnabled(false);
        }
        if (!descriptor.isReady() || descriptor.getOptions() == null)
            sett.setEnabled(false);
        if (descriptor.getStatistics() == null)
            stat.setVisibility(View.INVISIBLE);

    }
    icon.setOnClickListener(new myOnclickListener(myOnclickListener.PLAY,
            GameManager.instance(context).getIndexFor(descriptor), context));
    sett.setOnClickListener(new myOnclickListener(myOnclickListener.SETTINGS,
            GameManager.instance(context).getIndexFor(descriptor), context));
    tutorial.setOnClickListener(new myOnclickListener(myOnclickListener.TUTORIAL,
            GameManager.instance(context).getIndexFor(descriptor), context));
    stat.setOnClickListener(new myOnclickListener(myOnclickListener.STATISTICS,
            GameManager.instance(context).getIndexFor(descriptor), context));
    container.addView(layout);

    return layout;
}