Example usage for android.view View View

List of usage examples for android.view View View

Introduction

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

Prototype

public View(Context context) 

Source Link

Document

Simple constructor to use when creating a view from code.

Usage

From source file:org.zywx.wbpalmstar.plugin.uexPopoverMenu.EUExPopoverMenu.java

private void showPopoverMenu(double x, double y, int direction, String bgColorStr, String dividerColor,
        String textColor, int textSize, JSONArray data) {
    LinearLayout rootView = (LinearLayout) LayoutInflater.from(mContext)
            .inflate(finder.getLayoutId("plugin_uex_popovermenu"), null);

    final PopupWindow popupWindow = new PopupWindow(rootView, LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT, true);

    popupWindow.setContentView(rootView);
    ////from   ww  w  . j av  a2 s  .  co  m
    rootView.setBackgroundColor(Color.parseColor(bgColorStr));
    popupWindow.setContentView(rootView);
    //popupWindow?
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.setOutsideTouchable(true);

    int length = data.length();
    List<ItemData> itemDataList = new ArrayList<ItemData>();
    try {
        for (int i = 0; i < length; i++) {
            ItemData item = new ItemData();
            String icon = data.getJSONObject(i).optString("icon", "");
            if (!hasIcon && !TextUtils.isEmpty(icon)) {
                hasIcon = true;
            }
            if (hasIcon) {
                item.setIcon(data.getJSONObject(i).getString("icon"));
            }
            item.setText(data.getJSONObject(i).getString("text"));
            itemDataList.add(item);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    for (int i = 0; i < length; i++) {
        LinearLayout linearLayout = new LinearLayout(mContext);
        linearLayout.setOrientation(LinearLayout.HORIZONTAL);
        linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        if (hasIcon) {
            ImageView imageView = new ImageView(mContext);
            imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            String imagePath = itemDataList.get(i).getIcon();
            imageView.setImageBitmap(getBitmapFromPath(imagePath));
            imageView.setPadding(DensityUtil.dip2px(mContext, 5), 0, 0, 0);
            linearLayout.addView(imageView);
        }
        TextView tvText = new TextView(mContext);
        LinearLayout.LayoutParams tvLayoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        tvLayoutParams.gravity = Gravity.CENTER_VERTICAL;
        tvText.setLayoutParams(tvLayoutParams);

        tvText.setPadding(DensityUtil.dip2px(mContext, 5), 0, DensityUtil.dip2px(mContext, 8), 0);
        tvText.setText(itemDataList.get(i).getText());
        tvText.setTextColor(Color.parseColor(textColor));
        tvText.setTextSize(textSize);
        linearLayout.addView(tvText);
        linearLayout.setTag(i);
        linearLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                callBackPluginJs(CALLBACK_ITEM_SELECTED, String.valueOf(v.getTag()));
                if (popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });
        rootView.addView(linearLayout);

        //
        View dividerLine = new View(mContext);
        dividerLine.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                DensityUtil.dip2px(mContext, 1)));
        dividerLine.setBackgroundColor(Color.parseColor(dividerColor));
        rootView.addView(dividerLine);
    }
    int gravityParam;
    switch (direction) {
    case 0:
        gravityParam = Gravity.LEFT | Gravity.TOP;
        break;
    case 1:
        gravityParam = Gravity.RIGHT | Gravity.TOP;
        break;
    case 2:
        gravityParam = Gravity.LEFT | Gravity.BOTTOM;
        break;
    case 3:
        gravityParam = Gravity.RIGHT | Gravity.BOTTOM;
        break;
    default:
        gravityParam = Gravity.LEFT | Gravity.TOP;
        break;
    }
    popupWindow.showAtLocation(mBrwView.getRootView(), gravityParam, (int) x, (int) y);
}

From source file:com.example.mapsample.view.ActionSheet.java

private View createView() {
    FrameLayout parent = new FrameLayout(getActivity());
    parent.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT));
    mBg = new View(getActivity());
    mBg.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT));
    mBg.setBackgroundColor(Color.argb(136, 0, 0, 0));
    mBg.setId(ActionSheet.BG_VIEW_ID);//from   w ww .  ja  v a  2  s.  c om
    mBg.setOnClickListener(this);

    mPanel = new LinearLayout(getActivity());
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.BOTTOM;
    mPanel.setLayoutParams(params);
    mPanel.setOrientation(LinearLayout.VERTICAL);
    parent.setPadding(0, 0, 0, getNavBarHeight(getActivity()));
    parent.addView(mBg);
    parent.addView(mPanel);
    return parent;
}

From source file:org.odk.collect.android.views.ODKView.java

public ODKView(Context context, final FormEntryPrompt[] questionPrompts, FormEntryCaption[] groups,
        boolean advancingPage) {
    super(context);

    inflate(getContext(), R.layout.nested_scroll_view, this); // keep in an xml file to enable the vertical scrollbar

    widgets = new ArrayList<>();

    view = new LinearLayout(getContext());
    view.setOrientation(LinearLayout.VERTICAL);
    view.setGravity(Gravity.TOP);/*from   ww w . j a v a 2  s. c  om*/
    view.setPadding(0, 7, 0, 0);

    layout = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    layout.setMargins(10, 0, 10, 0);

    // display which group you are in as well as the question

    addGroupText(groups);

    // when the grouped fields are populated by an external app, this will get true.
    boolean readOnlyOverride = false;

    // get the group we are showing -- it will be the last of the groups in the groups list
    if (groups != null && groups.length > 0) {
        final FormEntryCaption c = groups[groups.length - 1];
        final String intentString = c.getFormElement().getAdditionalAttribute(null, "intent");
        if (intentString != null && intentString.length() != 0) {

            readOnlyOverride = true;

            final String buttonText;
            final String errorString;
            String v = c.getSpecialFormQuestionText("buttonText");
            buttonText = (v != null) ? v : context.getString(R.string.launch_app);
            v = c.getSpecialFormQuestionText("noAppErrorString");
            errorString = (v != null) ? v : context.getString(R.string.no_app);

            TableLayout.LayoutParams params = new TableLayout.LayoutParams();
            params.setMargins(7, 5, 7, 5);

            // set button formatting
            Button launchIntentButton = new Button(getContext());
            launchIntentButton.setId(ViewIds.generateViewId());
            launchIntentButton.setText(buttonText);
            launchIntentButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, Collect.getQuestionFontsize() + 2);
            launchIntentButton.setPadding(20, 20, 20, 20);
            launchIntentButton.setLayoutParams(params);

            launchIntentButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String intentName = ExternalAppsUtils.extractIntentName(intentString);
                    Map<String, String> parameters = ExternalAppsUtils.extractParameters(intentString);

                    Intent i = new Intent(intentName);
                    try {
                        ExternalAppsUtils.populateParameters(i, parameters, c.getIndex().getReference());

                        for (FormEntryPrompt p : questionPrompts) {
                            IFormElement formElement = p.getFormElement();
                            if (formElement instanceof QuestionDef) {
                                TreeReference reference = (TreeReference) formElement.getBind().getReference();
                                IAnswerData answerValue = p.getAnswerValue();
                                Object value = answerValue == null ? null : answerValue.getValue();
                                switch (p.getDataType()) {
                                case Constants.DATATYPE_TEXT:
                                case Constants.DATATYPE_INTEGER:
                                case Constants.DATATYPE_DECIMAL:
                                    i.putExtra(reference.getNameLast(), (Serializable) value);
                                    break;
                                }
                            }
                        }

                        ((Activity) getContext()).startActivityForResult(i, RequestCodes.EX_GROUP_CAPTURE);
                    } catch (ExternalParamsException e) {
                        Timber.e(e, "ExternalParamsException");

                        ToastUtils.showShortToast(e.getMessage());
                    } catch (ActivityNotFoundException e) {
                        Timber.d(e, "ActivityNotFoundExcept");

                        ToastUtils.showShortToast(errorString);
                    }
                }
            });

            View divider = new View(getContext());
            divider.setBackgroundResource(new ThemeUtils(getContext()).getDivider());
            divider.setMinimumHeight(3);
            view.addView(divider);

            view.addView(launchIntentButton, layout);
        }
    }

    boolean first = true;
    for (FormEntryPrompt p : questionPrompts) {
        if (!first) {
            View divider = new View(getContext());
            divider.setBackgroundResource(new ThemeUtils(getContext()).getDivider());
            divider.setMinimumHeight(3);
            view.addView(divider);
        } else {
            first = false;
        }

        // if question or answer type is not supported, use text widget
        QuestionWidget qw = WidgetFactory.createWidgetFromPrompt(p, getContext(), readOnlyOverride);
        qw.setLongClickable(true);
        qw.setOnLongClickListener(this);
        qw.setId(ViewIds.generateViewId());

        widgets.add(qw);
        view.addView(qw, layout);
    }

    ((NestedScrollView) findViewById(R.id.odk_view_container)).addView(view);

    // see if there is an autoplay option.
    // Only execute it during forward swipes through the form
    if (advancingPage && widgets.size() == 1) {
        final String playOption = widgets.get(0).getFormEntryPrompt().getFormElement()
                .getAdditionalAttribute(null, "autoplay");
        if (playOption != null) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (playOption.equalsIgnoreCase("audio")) {
                        widgets.get(0).playAudio();
                    } else if (playOption.equalsIgnoreCase("video")) {
                        widgets.get(0).playVideo();
                    }
                }
            }, 150);
        }
    }
}

From source file:org.telegram.ui.ActionBar.ActionBar.java

public ActionBarMenu createActionMode() {
    if (actionMode != null) {
        return actionMode;
    }//  www.  j a  v  a  2 s  . co m
    actionMode = new ActionBarMenu(getContext(), this);
    actionMode.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.background));
    addView(actionMode, indexOfChild(backButtonImageView));
    actionMode.setPadding(0, occupyStatusBar ? AndroidUtilities.statusBarHeight : 0, 0, 0);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) actionMode.getLayoutParams();
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.RIGHT;
    actionMode.setLayoutParams(layoutParams);
    actionMode.setVisibility(INVISIBLE);

    if (occupyStatusBar && actionModeTop == null) {
        actionModeTop = new View(getContext());
        actionModeTop.setBackgroundColor(0x99000000);
        addView(actionModeTop);
        layoutParams = (FrameLayout.LayoutParams) actionModeTop.getLayoutParams();
        layoutParams.height = AndroidUtilities.statusBarHeight;
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        actionModeTop.setLayoutParams(layoutParams);
        actionModeTop.setVisibility(INVISIBLE);
    }

    return actionMode;
}

From source file:com.alburivan.slickform.tooltip.SimpleTooltip.java

private void createOverlay() {
    mOverlay = mTransparentOverlay ? new View(mContext) : new OverlayView(mContext, mAnchorView);
    mOverlay.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    mOverlay.setOnTouchListener(mOverlayTouchListener);
    mRootView.addView(mOverlay);//  www  .  jav a  2  s  .c o m
}

From source file:com.hzx.luoyechat.activity.SettingsFragment.java

private void initSwitchColor() {
    dialog = new android.support.v7.app.AlertDialog.Builder(getActivity()).setAdapter(new BaseAdapter() {
        @Override//  www.  j  av  a 2 s.c  o  m
        public int getCount() {
            return colors.length;
        }

        @Override
        public Object getItem(int position) {
            return colors[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = new View(getActivity());
                convertView.setLayoutParams(new AbsListView.LayoutParams(-1, 70));
            }

            convertView.setBackgroundColor(getResources().getColor((Integer) getItem(position)));
            return convertView;
        }
    }, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            //                  Snackbar.make(theme_color, i + ": ", 0).show();
            HXPreferenceUtils.getInstance().setThemeColor(i);
            HXPreferenceUtils.getInstance().setTabIndex(2);
            theme_color.setBackgroundResource(colors[i]);
            getActivity().finish();
            startActivity(new Intent(getActivity(), MainActivity.class));
        }
    });/**/
    rl_switch_theme_color.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.show();
        }
    });
    int colorindex = HXPreferenceUtils.getInstance().getThemeColor();
    theme_color.setBackgroundResource(colors[colorindex]);
}

From source file:at.alladin.rmbt.android.map.overlay.RMBTBalloonOverlayView.java

public void setBalloonData(final RMBTBalloonOverlayItem item, final ViewGroup parent) {
    // map our custom item data to fields
    //        title.setText(item.getTitle());
    resultItems = item.getResultItems();

    resultListView.removeAllViews();/* www.  j  av  a 2 s  . c  o m*/

    final float scale = getResources().getDisplayMetrics().density;

    final int leftRightItem = Helperfunctions.dpToPx(5, scale);
    final int topBottomItem = Helperfunctions.dpToPx(3, scale);

    final int leftRightDiv = Helperfunctions.dpToPx(0, scale);
    final int topBottomDiv = Helperfunctions.dpToPx(0, scale);
    final int heightDiv = Helperfunctions.dpToPx(1, scale);

    final int topBottomImg = Helperfunctions.dpToPx(1, scale);

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

        for (int i = 0; i < 1; i++)
            // JSONObject resultListItem;
            try {
                final JSONObject result = resultItems.getJSONObject(i);

                final LayoutInflater resultInflater = (LayoutInflater) context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                final View resultView = resultInflater.inflate(R.layout.balloon_overlay_listitem, parent);

                final LinearLayout measurementLayout = (LinearLayout) resultView
                        .findViewById(R.id.resultMeasurementList);
                measurementLayout.setVisibility(View.GONE);

                final LinearLayout netLayout = (LinearLayout) resultView.findViewById(R.id.resultNetList);
                netLayout.setVisibility(View.GONE);

                final TextView measurementHeader = (TextView) resultView.findViewById(R.id.resultMeasurement);
                measurementHeader.setVisibility(View.GONE);

                final TextView netHeader = (TextView) resultView.findViewById(R.id.resultNet);
                netHeader.setVisibility(View.GONE);

                final TextView dateHeader = (TextView) resultView.findViewById(R.id.resultDate);
                dateHeader.setVisibility(View.GONE);

                dateHeader.setText(result.optString("time_string"));

                final JSONArray measurementArray = result.getJSONArray("measurement");

                final JSONArray netArray = result.getJSONArray("net");

                for (int j = 0; j < measurementArray.length(); j++) {

                    final JSONObject singleItem = measurementArray.getJSONObject(j);

                    final LinearLayout measurememtItemLayout = new LinearLayout(context); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item);

                    measurememtItemLayout.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT));

                    measurememtItemLayout.setGravity(Gravity.CENTER_VERTICAL);
                    measurememtItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem,
                            topBottomItem);

                    final TextView itemTitle = new TextView(context, null, R.style.balloonResultItemTitle);
                    itemTitle.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.4f));
                    itemTitle.setTextAppearance(context, R.style.balloonResultItemTitle);
                    itemTitle.setWidth(0);
                    itemTitle.setGravity(Gravity.LEFT);
                    itemTitle.setText(singleItem.getString("title"));

                    measurememtItemLayout.addView(itemTitle);

                    final ImageView itemClassification = new ImageView(context);
                    itemClassification.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0.1f));
                    itemClassification.setPadding(0, topBottomImg, 0, topBottomImg);
                    // itemClassification.set setGravity(Gravity.LEFT);

                    itemClassification.setImageDrawable(getResources().getDrawable(
                            Helperfunctions.getClassificationImage(singleItem.getInt("classification"))));

                    measurememtItemLayout.addView(itemClassification);

                    final TextView itemValue = new TextView(context, null, R.style.balloonResultItemValue);
                    itemValue.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f));
                    itemValue.setTextAppearance(context, R.style.balloonResultItemValue);
                    itemValue.setWidth(0);
                    itemValue.setGravity(Gravity.LEFT);
                    itemValue.setText(singleItem.getString("value"));

                    measurememtItemLayout.addView(itemValue);

                    measurementLayout.addView(measurememtItemLayout);

                    final View divider = new View(context);
                    divider.setLayoutParams(new LinearLayout.LayoutParams(
                            android.view.ViewGroup.LayoutParams.MATCH_PARENT, heightDiv, 1));
                    divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv);

                    divider.setBackgroundResource(R.drawable.bg_trans_light_10);

                    measurementLayout.addView(divider);

                    measurementLayout.invalidate();
                }

                for (int j = 0; j < netArray.length(); j++) {

                    final JSONObject singleItem = netArray.getJSONObject(j);

                    final LinearLayout netItemLayout = new LinearLayout(context); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item);

                    netItemLayout.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
                    netItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem, topBottomItem);

                    netItemLayout.setGravity(Gravity.CENTER_VERTICAL);

                    final TextView itemTitle = new TextView(context, null, R.style.balloonResultItemTitle);
                    itemTitle.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.4f));
                    itemTitle.setTextAppearance(context, R.style.balloonResultItemTitle);
                    itemTitle.setWidth(0);
                    itemTitle.setGravity(Gravity.LEFT);
                    itemTitle.setText(singleItem.getString("title"));

                    netItemLayout.addView(itemTitle);

                    final ImageView itemClassification = new ImageView(context);
                    itemClassification.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0.1f));
                    itemClassification.setPadding(0, topBottomImg, 0, topBottomImg);

                    itemClassification.setImageDrawable(
                            context.getResources().getDrawable(R.drawable.traffic_lights_none));
                    netItemLayout.addView(itemClassification);

                    final TextView itemValue = new TextView(context, null, R.style.balloonResultItemValue);
                    itemValue.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f));
                    itemValue.setTextAppearance(context, R.style.balloonResultItemValue);
                    itemValue.setWidth(0);
                    itemValue.setGravity(Gravity.LEFT);
                    itemValue.setText(singleItem.optString("value", null));

                    netItemLayout.addView(itemValue);

                    netLayout.addView(netItemLayout);

                    final View divider = new View(context);
                    divider.setLayoutParams(new LinearLayout.LayoutParams(
                            android.view.ViewGroup.LayoutParams.MATCH_PARENT, heightDiv, 1));
                    divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv);

                    divider.setBackgroundResource(R.drawable.bg_trans_light_10);

                    netLayout.addView(divider);

                    netLayout.invalidate();
                }

                measurementHeader.setVisibility(View.VISIBLE);
                netHeader.setVisibility(View.VISIBLE);

                measurementLayout.setVisibility(View.VISIBLE);
                netLayout.setVisibility(View.VISIBLE);

                dateHeader.setVisibility(View.VISIBLE);

                resultListView.addView(resultView);

                Log.d(DEBUG_TAG, "View Added");
                // codeText.setText(resultListItem.getString("sync_code"));

            } catch (final JSONException e) {
                e.printStackTrace();
            }

        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.GONE);

        resultListView.setVisibility(View.VISIBLE);

        resultListView.invalidate();
    } else {
        Log.i(DEBUG_TAG, "LEERE LISTE");
        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.VISIBLE);
        emptyView.setText(context.getString(R.string.error_no_data));
        emptyView.invalidate();
    }
}

From source file:com.nttec.everychan.ui.BoardsListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (isFailInstance) {
        Toast.makeText(activity, R.string.error_unknown, Toast.LENGTH_LONG).show();
        return new View(activity);
    }//www  .java 2 s. co  m
    startItem = tabModel.startItemNumber;
    startItemTop = tabModel.startItemTop;
    rootView = inflater.inflate(R.layout.boardslist_fragment, container, false);
    loadingView = rootView.findViewById(R.id.boardslist_loading);
    errorView = rootView.findViewById(R.id.boardslist_error);
    errorTextView = (TextView) errorView.findViewById(R.id.frame_error_text);
    listView = (ListView) rootView.findViewById(android.R.id.list);
    listView.setOnItemClickListener(this);
    registerForContextMenu(listView);
    boardField = (EditText) rootView.findViewById(R.id.boardslist_board_field);
    boardField.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                onClick(v);
                return true;
            }
            return false;
        }
    });
    buttonGo = (Button) rootView.findViewById(R.id.boardslist_btn_go);
    buttonGo.setOnClickListener(this);
    activity.setTitle(chan.getDisplayingName());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        CompatibilityImpl.setActionBarCustomFavicon(activity, chan.getChanFavicon());
    update(false);
    return rootView;
}

From source file:com.gome.haoyuangong.views.MyViewPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;//from   www  . ja va 2  s  . c  o  m
    tabView.setTag("tavView");
    tabView.setId(index);
    //      tabView.setFocusable(true);
    //      tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    //tabView.setPadding(pointSize, 0, pointSize, 0);
    tabView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tabView.setMaxLines(1);
    tabView.setGravity(Gravity.CENTER);
    XmlPullParser xrp = getResources().getXml(R.drawable.tab_button);
    try {
        ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);
        tabView.setTextColor(csl);
    } catch (Exception e) {

    }

    if (iconResId != 0) {
        //tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }

    FrameLayout.LayoutParams tabTvL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabView.setLayoutParams(tabTvL);

    //measureView(tabView);

    LinearLayout layoutWraper1 = new LinearLayout(getContext());
    LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1);
    layoutWraper1.setLayoutParams(lp1);
    layoutWraper1.setGravity(Gravity.CENTER);
    layoutWraper1.setFocusable(true);
    layoutWraper1.setOnClickListener(mTabClickListener);
    layoutWraper1.setPadding(0, 0, 0, 0);
    layoutWraper1.setBackgroundResource(R.drawable.tab_btn_red);

    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setTag("framelayout");
    //      FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(tabView.getMeasuredWidth() + padding, tabView.getMeasuredHeight()+ (int)(padding * 1.5));
    FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    //      frameLayout.setPadding(padding, padding, padding, padding);
    frameLayout.setLayoutParams(fl2);
    //      frameLayout.addView(tabView);

    View hasNew = new View(getContext());
    FrameLayout.LayoutParams hasNewL = new FrameLayout.LayoutParams(pointSize, pointSize);
    hasNew.setLayoutParams(hasNewL);
    hasNewL.gravity = Gravity.TOP | Gravity.RIGHT;
    hasNew.setBackgroundResource(R.drawable.shape_circle);

    FrameLayout tabTvframe = new FrameLayout(getContext());
    FrameLayout.LayoutParams tabTvframeL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabTvframeL.gravity = Gravity.CENTER;
    tabTvframe.setLayoutParams(tabTvframeL);
    tabTvframe.addView(tabView);
    tabTvframe.addView(hasNew);
    hasNew.setVisibility(View.GONE);

    frameLayout.addView(tabTvframe);

    layoutWraper1.addView(frameLayout);

    tabView.setTagView(hasNew);

    mTabLayout.addView(layoutWraper1, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

From source file:ng.kingsley.android.widget.CollectionView.java

private View makeRow(View view, RowComputeResult rowInfo, ViewGroup parent) {
    if (mCallbacks == null) {
        Log.e(TAG, "Call to makeRow without an adapter installed");
        return view != null ? view : new View(getContext());
    }/*from  w ww.  j av  a 2  s.  c  om*/

    // Notice that view types are tied to a specific instance of mInventory by hashcode,
    // so when mInventory is updated, we don't attempt to reuse views that were used for
    // a previous incarnation of mInventory (the views may be incompatible).
    String desiredViewType = mInventory.hashCode() + "." + getRowViewType(rowInfo.row);
    String actualViewType = (view != null && view.getTag() != null) ? view.getTag().toString() : "";
    if (!desiredViewType.equals(actualViewType)) {
        // We can't recycle this view. We have to make a new one.
        view = null;
    }

    if (rowInfo.isHeader) {
        if (view == null) {
            view = mCallbacks.newCollectionHeaderView(getContext(), parent);
        }
        mCallbacks.bindCollectionHeaderView(getContext(), view, rowInfo.groupId, rowInfo.group.mHeaderLabel);
    } else {
        view = makeItemRow(view, rowInfo);
    }

    view.setTag(desiredViewType);
    return view;
}