Example usage for android.widget LinearLayout addView

List of usage examples for android.widget LinearLayout addView

Introduction

In this page you can find the example usage for android.widget LinearLayout addView.

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.i2max.i2smartwork.common.conference.ConferenceDetailViewFragment.java

public void setFilesLayout(String title, LinearLayout targetLayout, Object object) {

    final List<LinkedTreeMap<String, String>> filesList = (List<LinkedTreeMap<String, String>>) object;
    if (filesList == null || (filesList != null && filesList.size() <= 0)) {
        targetLayout.setVisibility(View.GONE);
    } else {//w  w  w . j  av  a  2  s .c  om
        Log.e(TAG, "fileList size =" + filesList.size());
        targetLayout.setVisibility(View.VISIBLE);
        targetLayout.removeAllViews();
        //addTitleView
        LinearLayout.LayoutParams tvParam = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        tvParam.setMargins(0, DisplayUtil.dip2px(getActivity(), 12), 0, DisplayUtil.dip2px(getActivity(), 10));

        TextView tvTitle = new TextView(getActivity());
        tvTitle.setLayoutParams(tvParam);
        if (Build.VERSION.SDK_INT < 23) {
            tvTitle.setTextAppearance(getActivity(), android.R.style.TextAppearance_Material_Medium);
        } else {
            tvTitle.setTextAppearance(android.R.style.TextAppearance_Material_Medium);
        }
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
        tvTitle.setTextColor(getResources().getColor(R.color.text_color_black));
        tvTitle.setText(title);

        targetLayout.addView(tvTitle);

        //addFilesView
        for (int i = 0; i < filesList.size(); i++) {
            final LinkedTreeMap<String, String> fileMap = filesList.get(i);
            LayoutInflater inflater = (LayoutInflater) getActivity()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View fileView = inflater.inflate(R.layout.view_item_file, null);

            ImageView ivIcFileExt = (ImageView) fileView.findViewById(R.id.iv_ic_file_ext);
            TextView tvFileNm = (TextView) fileView.findViewById(R.id.tv_file_nm);

            //??  ? 
            ivIcFileExt.setImageResource(R.drawable.ic_file_doc);
            String fileNm = FormatUtil.getStringValidate(fileMap.get("file_nm"));
            tvFileNm.setText(fileNm);
            FileUtil.setFileExtIcon(ivIcFileExt, fileNm);
            final String fileExt = FileUtil.getFileExtsion(fileNm);
            final String downloadURL = I2UrlHelper.File
                    .getDownloadFile(FormatUtil.getStringValidate(fileMap.get("file_id")));

            fileView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    try {
                        Intent intent = null;
                        if ("Y".equals(FormatUtil.getStringValidate(fileMap.get("conv_yn")))) {
                            //i2viewer ? ( conv_yn='Y')
                            intent = IntentUtil.getI2ViewerIntent(
                                    FormatUtil.getStringValidate(fileMap.get("file_id")),
                                    FormatUtil.getStringValidate(fileMap.get("file_nm")));
                            getActivity().startActivity(intent);
                        } else if ("mp4".equalsIgnoreCase(fileExt) || "fla".equalsIgnoreCase(fileExt)
                                || "wmv".equalsIgnoreCase(fileExt) || "avi".equalsIgnoreCase(fileExt)) { //video
                            intent = IntentUtil.getVideoPlayIntent(downloadURL);
                        } else {
                            //? ??
                            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadURL));
                            Bundle bundle = new Bundle();
                            bundle.putString("Authorization", I2UrlHelper.getTokenAuthorization());
                            intent.putExtra(Browser.EXTRA_HEADERS, bundle);
                            Log.d(TAG, "intent:" + intent.toString());
                        }
                        getActivity().startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        Toast.makeText(getActivity(),
                                "I2Viewer? ?  .\n  ? ?.",
                                Toast.LENGTH_LONG).show();
                        //TODO ? ? ?   URL
                    }
                }
            });

            targetLayout.addView(fileView);
        }

    }
}

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();/*ww w.j av a 2  s. co  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.fowlcorp.homebank4android.gui.AccountRecyclerAdapter.java

@Override
public void onBindViewHolder(final OperationViewHolder holder, final int position) {
    final Operation operation = listOperation.get(position);

    final Calendar myDate = Calendar.getInstance();
    myDate.clear();//from  w ww .  j  a  va2  s  . c o m
    myDate.setTime(operation.getDate().getTime());
    final SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy", Locale.FRANCE);
    holder.getRootLayout().setOnClickListener(new OnClickListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(activity.getApplicationContext(), DetailedCardActivity.class);
            Bundle bdl = new Bundle();
            try {

                bdl.putString("Date", df.format(myDate.getTime()));
            } catch (Exception e) {
            }
            try {
                bdl.putString("Category",
                        (operation.getCategory().getParent() == null ? ""
                                : operation.getCategory().getParent().getName() + ": ")
                                + operation.getCategory().getName());
            } catch (Exception e) {
            }
            try {
                bdl.putString("Payee", operation.getPayee().getName());
            } catch (Exception e) {
            }
            try {
                bdl.putString("Wording", operation.getWording());
            } catch (Exception e) {
            }
            try {
                bdl.putString("Amount", String.valueOf(Round.roundAmount(operation.getAmount())));
            } catch (Exception e) {
            }
            try {
                bdl.putInt("Type", operation.getPayMode());
            } catch (Exception e) {
            }
            //                try {
            //                    intent.putExtra("Info", operation.getInfo());
            //                } catch (Exception e) {
            //                }
            try {
                bdl.putBoolean("Reconciled", operation.isReconciled());
            } catch (Exception e) {
            }
            try {
                bdl.putBoolean("Remind", operation.isRemind());
            } catch (Exception e) {
            }
            try {
                Log.d("Debug", String.valueOf(operation.isSplit()));
                bdl.putBoolean("Split", operation.isSplit());
            } catch (Exception e) {
            }
            try {
                bdl.putSerializable("Couple", operation.getSplits());
            } catch (Exception e) {
                e.printStackTrace();
            }

            intent.putExtras(bdl);

            //            Pair datePair = Pair.create(holder.getDate(), "date");
            //            Pair categoryPair = Pair.create(holder.getCategory(), "category");
            //            Pair wordingPair = Pair.create(holder.getWording(), "wording");
            //            Pair payeePair = Pair.create(holder.getPayee(), "payee");
            //            Pair amountPair = Pair.create(holder.getAmount(), "amount");
            Pair<View, String> cardPair = Pair.create((View) holder.getCard(), "card");
            //            Pair iconPair = Pair.create(holder.getMode(), "icon");
            ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
                    cardPair);
            ActivityCompat.startActivity(activity, intent, options.toBundle());
            //activity.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(activity).toBundle());
            //activity.startActivity(intent);
        }

    });

    try {
        holder.getDate().setText(activity.getString(R.string.Date) + " : " + df.format(myDate.getTime()));
    } catch (Exception e) {
    }
    try {
        holder.getPayee().setText(activity.getString(R.string.Payee) + " : " + operation.getPayee().getName());
    } catch (Exception e) {
    }
    try {
        holder.getWording().setText(activity.getString(R.string.Wording) + " : " + operation.getWording());
    } catch (Exception e) {
    }
    if (!operation.isSplit()) {
        holder.getSplitLinear().removeAllViews();
        holder.getUnSplitLinear().setVisibility(LinearLayout.VISIBLE);
        try {
            holder.getCategory()
                    .setText(activity.getString(R.string.Wording) + " : "
                            + (operation.getCategory().getParent() == null ? ""
                                    : operation.getCategory().getParent().getName() + ": ")
                            + operation.getCategory().getName());
        } catch (Exception e) {
        }

    } else {
        holder.getUnSplitLinear().setVisibility(LinearLayout.GONE);

        LinearLayout splitLayout = holder.getSplitLinear();
        splitLayout.removeAllViews();
        LayoutInflater inflater = activity.getLayoutInflater();
        for (Triplet subOp : operation.getSplits()) {
            View view = inflater.inflate(R.layout.split_layout, null);

            TextView category = (TextView) view.findViewById(R.id.splitLayout_category);
            TextView memo = (TextView) view.findViewById(R.id.splitLayout_memo);
            TextView amount = (TextView) view.findViewById(R.id.splitLayout_amount);
            //System.out.println(activity.getString(R.string.cardLayout_category) + " " + (subOp.getCategory().getParent() == null ? "" :subOp.getCategory().getParent().getName() + ": ") + subOp.getCategory().getName());
            category.setText(activity.getString(R.string.Category) + " : "
                    + (subOp.getCategory().getParent() == null ? ""
                            : subOp.getCategory().getParent().getName() + ": ")
                    + subOp.getCategory().getName());
            amount.setText(colorText(activity.getString(R.string.Amount) + " : ",
                    "" + Round.roundAmount(subOp.getAmount())));
            memo.setText(activity.getString(R.string.Category) + " : " + operation.getWording());
            splitLayout.addView(view);
        }
    }
    try {
        holder.getAmount().setText(colorText(activity.getString(R.string.Amount) + " : ",
                String.valueOf(Round.roundAmount(operation.getAmount()))));
    } catch (Exception e) {
    }
    try {
        holder.getBalance().setText(colorText(activity.getString(R.string.Balance) + " : ",
                String.valueOf(Round.roundAmount(operation.getBalanceAccount()))));
    } catch (Exception e) {
    }

    if (operation.isSplit()) {
        holder.getOption().setImageResource(R.drawable.split);
    } else if (operation.isRemind()) {
        holder.getOption().setImageResource(R.drawable.remind);
        holder.getCard().setCardBackgroundColor(Color.parseColor("#ffebee"));
    } else {
        holder.getOption().setImageDrawable(null);
    }

    if (!operation.isReconciled() && !operation.isRemind()) {
        holder.getCard().setCardBackgroundColor(Color.parseColor("#fff3e0"));
    } else if (operation.isReconciled()) {
        holder.getCard().setCardBackgroundColor(Color.parseColor("#ffffff"));
    }

    try {
        switch (operation.getPayMode()) {
        case PayMode.CREDIT_CARD:
            holder.getMode().setImageResource(R.drawable.mastercard);
            break;
        case PayMode.DEBIT_CARD:
            holder.getMode().setImageResource(R.drawable.card);
            break;
        case PayMode.CASH:
            holder.getMode().setImageResource(R.drawable.cash);
            break;
        case PayMode.TRANSFERT:
            holder.getMode().setImageResource(R.drawable.transfert);
            break;
        case PayMode.ELECTRONIC_PAYMENT:
            holder.getMode().setImageResource(R.drawable.nfc);
            break;
        case PayMode.CHEQUE:
            holder.getMode().setImageResource(R.drawable.cheque);
            break;
        default:
            holder.getMode().setImageDrawable(null);
            break;
        }
    } catch (Exception e) {
    }

}

From source file:com.activiti.android.ui.fragments.task.TaskDetailsFoundationFragment.java

private void displayPeopleSection(List<LightUserRepresentation> people) {
    show(R.id.task_details_people_card);
    if (people.isEmpty() || isEnded) {
        hide(R.id.task_details_people_card);
        return;/*from w w  w  .  j a v  a2  s. c o m*/
    }

    // USER INVOLVED
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout userContainer = (LinearLayout) viewById(R.id.task_details_people_container);
    userContainer.removeAllViews();
    View v;
    if (people == null || people.isEmpty()) {
        v = inflater.inflate(R.layout.row_single_line, userContainer, false);
        ((TextView) v.findViewById(R.id.toptext)).setText(R.string.task_message_no_people_involved);
        v.findViewById(R.id.icon).setVisibility(View.GONE);
        userContainer.addView(v);
    } else {
        TwoLinesViewHolder vh;
        for (LightUserRepresentation user : people) {
            v = inflater.inflate(R.layout.row_two_lines_swipe, userContainer, false);
            v.setTag(user.getId());
            String fullName = user.getFullname();
            vh = HolderUtils.configure(v, fullName != null && !fullName.isEmpty() ? fullName : user.getEmail(),
                    null, R.drawable.ic_account_circle_grey);
            if (picasso != null) {
                picasso.cancelRequest(vh.icon);
                picasso.load(getAPI().getUserGroupService().getPicture(user.getId()))
                        .placeholder(R.drawable.ic_account_circle_grey).fit().transform(roundedTransformation)
                        .into(vh.icon);
            }
            SwipeLayout swipeLayout = (SwipeLayout) v.findViewById(R.id.swipe_layout);
            swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
            swipeLayout.setDragEdge(SwipeLayout.DragEdge.Right);

            LinearLayout actions = (LinearLayout) swipeLayout.findViewById(R.id.bottom_wrapper);
            ImageButton action = (ImageButton) inflater.inflate(R.layout.form_swipe_action_,
                    (LinearLayout) swipeLayout.findViewById(R.id.bottom_wrapper), false);
            action.setImageResource(R.drawable.ic_remove_circle_outline_white);
            action.setTag(user);
            action.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    removeInvolved(((LightUserRepresentation) v.getTag()),
                            new InvolveTaskRepresentation(((LightUserRepresentation) v.getTag()).getId()));
                }
            });
            actions.addView(action);

            userContainer.addView(v);
        }
    }

    if (!isEnded) {
        v = inflater.inflate(R.layout.footer_two_buttons_borderless, userContainer, false);
        Button b = (Button) v.findViewById(R.id.button_action_left);
        b.setVisibility(View.GONE);
        b = (Button) v.findViewById(R.id.button_action_right);
        b.setText(R.string.task_action_involve);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startInvolveAction();
            }
        });
        userContainer.addView(v);
    }
}

From source file:terse.a1.TerseActivity.java

private void viewPath9display(String path, LayoutParams widgetParams) {
    String explain;// w w w.  ja  va  2 s .  com
    if (terp_error != null) {
        explain = "terp_error = " + terp_error;
    } else {
        try {
            terp.say("Sending to terp: %s", path);
            final Dict d = terp.handleUrl(path, taQuery);
            explain = "DEFAULT EXPLANATION:\n\n" + d.toString();

            Str TYPE = d.cls.terp.newStr("type");
            Str VALUE = d.cls.terp.newStr("value");
            Str TITLE = d.cls.terp.newStr("title");
            Str type = (Str) d.dict.get(TYPE);
            Ur value = d.dict.get(VALUE);
            Ur title = d.dict.get(TITLE);

            // {
            // double ticks = Static.floatAt(d, "ticks", -1);
            // double nanos = Static.floatAt(d, "nanos", -1);
            // Toast.makeText(
            // getApplicationContext(),
            // Static.fmt("%d ticks, %.3f secs", (long) ticks,
            // (double) nanos / 1e9), Toast.LENGTH_SHORT)
            // .show();
            // }

            if (type.str.equals("list") && value instanceof Vec) {
                final ArrayList<Ur> v = ((Vec) value).vec;
                final ArrayList<String> labels = new ArrayList<String>();
                final ArrayList<String> links = new ArrayList<String>();
                for (int i = 0; i < v.size(); i++) {
                    Ur item = v.get(i);
                    String label = item instanceof Str ? ((Str) item).str : item.toString();
                    if (item instanceof Vec && ((Vec) item).vec.size() == 2) {
                        // OLD STYLE
                        label = ((Vec) item).vec.get(0).toString();
                        Matcher m = LINK_P.matcher(label);
                        if (m.lookingAt()) {
                            label = m.group(2) + " " + m.group(3);
                        }
                        label += "    [" + ((Vec) item).vec.get(1).toString().length() + "]";
                        links.add(null); // Use old style, not links.
                    } else {
                        // NEW STYLE
                        label = item.toString();
                        if (label.charAt(0) == '/') {
                            String link = Terp.WHITE_PLUS.split(label, 2)[0];
                            links.add(link);
                        } else {
                            links.add("");
                        }
                    }
                    labels.add(label);
                }
                if (labels.size() != links.size())
                    terp.toss("lables#%d links#%d", labels.size(), links.size());

                ListView listv = new ListView(this);
                listv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, labels));
                listv.setLayoutParams(widgetParams);
                listv.setTextFilterEnabled(true);

                listv.setOnItemClickListener(new OnItemClickListener() {
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        // When clicked, show a toast with the TextView text
                        // Toast.makeText(getApplicationContext(),
                        // ((TextView) view).getText(),
                        // Toast.LENGTH_SHORT).show();
                        String toast_text = ((TextView) view).getText().toString();
                        // if (v.get(position) instanceof Vec) {
                        if (links.get(position) == null) {
                            // OLD STYLE
                            Vec pair = (Vec) v.get(position);
                            if (pair.vec.size() == 2) {
                                if (pair.vec.get(0) instanceof Str) {
                                    String[] words = ((Str) pair.vec.get(0)).str.split("\\|");
                                    Log.i("TT-WORDS", terp.arrayToString(words));
                                    toast_text += "\n\n" + Static.arrayToString(words);
                                    if (words[1].equals("link")) {
                                        Uri uri = new Uri.Builder().scheme("terse").path(words[2]).build();
                                        Intent intent = new Intent("android.intent.action.MAIN", uri);
                                        intent.setClass(getApplicationContext(), TerseActivity.class);

                                        startActivity(intent);
                                    }
                                }
                            }
                        } else {
                            // NEW STYLE
                            terp.say("NEW STYLE LIST SELECT #%d link=<%s> label=<%s>", position,
                                    links.get(position), labels.get(position));
                            if (links.get(position).length() > 0) {
                                Uri uri = new Uri.Builder().scheme("terse").path(links.get(position)).build();
                                Intent intent = new Intent("android.intent.action.MAIN", uri);
                                intent.setClass(getApplicationContext(), TerseActivity.class);

                                startActivity(intent);
                            }
                        }
                        // }
                        // Toast.makeText(getApplicationContext(),
                        // ((TextView) view).getText(),
                        // Toast.LENGTH_SHORT).show();
                    }
                });
                setContentView(listv);
                return;
            } else if (type.str.equals("edit") && value instanceof Str) {
                final EditText ed = new EditText(this);

                ed.setText(taSaveMe == null ? value.toString() : taSaveMe);

                ed.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE
                        | InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
                ed.setLayoutParams(widgetParams);
                // ed.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
                ed.setTextAppearance(this, R.style.teletype);
                ed.setBackgroundColor(Color.BLACK);
                ed.setGravity(Gravity.TOP);
                ed.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET);
                ed.setVerticalFadingEdgeEnabled(true);
                ed.setVerticalScrollBarEnabled(true);
                ed.setOnKeyListener(new OnKeyListener() {
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        // If the event is a key-down event on the "enter"
                        // button
                        // if ((event.getAction() == KeyEvent.ACTION_DOWN)
                        // &&
                        // (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        // // Perform action on key press
                        // Toast.makeText(TerseActivity.this, ed.getText(),
                        // Toast.LENGTH_SHORT).show();
                        // return true;
                        // }
                        return false;
                    }
                });

                Button btn = new Button(this);
                btn.setText("Save");
                btn.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                        // Perform action on clicks
                        String text = ed.getText().toString();
                        text = Parser.charSubsts(text);
                        Toast.makeText(TerseActivity.this, text, Toast.LENGTH_SHORT).show();
                        String action = stringAt(d, "action");
                        String query = "";

                        String f1 = stringAt(d, "field1");
                        String v1 = stringAt(d, "value1");
                        String f2 = stringAt(d, "field2");
                        String v2 = stringAt(d, "value2");
                        f1 = (f1 == null) ? "f1null" : f1;
                        v1 = (v1 == null) ? "v1null" : v1;
                        f2 = (f2 == null) ? "f2null" : f2;
                        v2 = (v2 == null) ? "v2null" : v2;

                        startTerseActivity(action, query, stringAt(d, "field1"), stringAt(d, "value1"),
                                stringAt(d, "field2"), stringAt(d, "value2"), "text", text);
                    }
                });

                LinearLayout linear = new LinearLayout(this);
                linear.setOrientation(LinearLayout.VERTICAL);
                linear.addView(btn);
                linear.addView(ed);
                setContentView(linear);
                return;

            } else if (type.str.equals("draw") && value instanceof Vec) {
                Vec v = ((Vec) value);
                DrawView dv = new DrawView(this, v.vec, d);
                dv.setLayoutParams(widgetParams);
                setContentView(dv);
                return;
            } else if (type.str.equals("live")) {
                Blk blk = value.mustBlk();
                Blk event = Static.urAt(d, "event").asBlk();
                TerseSurfView tsv = new TerseSurfView(this, blk, event);
                setContentView(tsv);
                return;
            } else if (type.str.equals("fnord")) {
                Blk blk = value.mustBlk();
                Blk event = Static.urAt(d, "event").asBlk();
                FnordView fnord = new FnordView(this, blk, event);
                setContentView(fnord);
                return;
            } else if (type.str.equals("world") && value instanceof Str) {
                String newWorld = value.toString();
                if (Terp.WORLD_P.matcher(newWorld).matches()) {
                    world = newWorld;
                    resetTerp();
                    explain = Static.fmt("Switching to world <%s>\nUse menu to go Home.", world);
                    Toast.makeText(getApplicationContext(), explain, Toast.LENGTH_LONG).show();
                } else {
                    terp.toss("Bad world syntax (must be 3 letters then 0 to 3 digits: <%s>", newWorld);
                }
                // Fall thru for explainv.setText(explain).
            } else if (type.str.equals("text")) {
                explain = "<<< " + title + " >>>\n\n" + value.toString();
                // Fall thru for explainv.setText(explain).
            } else if (type.str.equals("html")) {
                final WebView webview = new WebView(this);
                // webview.loadData(value.toString(), "text/html", null);
                webview.loadDataWithBaseURL("terse://terse", value.toString(), "text/html", "UTF-8", null);
                webview.setWebViewClient(new WebViewClient() {
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        // terp.say("WebView UrlLoading: url=%s", url);
                        URI uri = URI.create("" + url);
                        // terp.say("WebView UrlLoading: URI=%s", uri);
                        terp.say("WebView UrlLoading: getPath=%s", uri.getPath());
                        terp.say("WebView UrlLoading: getQuery=%s", uri.getQuery());

                        // Toast.makeText(getApplicationContext(),
                        // uri.toASCIIString(), Toast.LENGTH_SHORT)
                        // .show();
                        // webview.invalidate();
                        //
                        // TextView quick = new
                        // TextView(TerseActivity.this);
                        // quick.setText(uri.toASCIIString());
                        // quick.setBackgroundColor(Color.BLACK);
                        // quick.setTextColor(Color.WHITE);
                        // setContentView(quick);

                        startTerseActivity(uri.getPath(), uri.getQuery());

                        return true;
                    }
                });

                // webview.setWebChromeClient(new WebChromeClient());
                webview.getSettings().setBuiltInZoomControls(true);
                // webview.getSettings().setJavaScriptEnabled(true);
                webview.getSettings().setDefaultFontSize(18);
                webview.getSettings().setNeedInitialFocus(true);
                webview.getSettings().setSupportZoom(true);
                webview.getSettings().setSaveFormData(true);
                setContentView(webview);

                // ScrollView scrollv = new ScrollView(this);
                // scrollv.addView(webview);
                // setContentView(scrollv);
                return;
            } else {
                explain = "Unknown page type: " + type.str + " with vaule type: " + value.cls
                        + "\n\n##############\n\n";
                explain += value.toString();
                // Fall thru for explainv.setText(explain).
            }

        } catch (Exception ex) {
            ex.printStackTrace();
            explain = Static.describe(ex);
        }
    }

    TextView explainv = new TextView(this);
    explainv.setText(explain);
    explainv.setBackgroundColor(Color.BLACK);
    explainv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
    explainv.setTextColor(Color.YELLOW);

    SetContentViewWithHomeButtonAndScroll(explainv);
}

From source file:fr.cph.chicago.activity.StationActivity.java

@SuppressWarnings("unchecked")
@Override//from  w  ww  . ja va 2  s .  co m
protected final void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ChicagoTracker.checkTrainData(this);
    if (!this.isFinishing()) {
        // Load data
        DataHolder dataHolder = DataHolder.getInstance();
        this.mTrainData = dataHolder.getTrainData();

        mIds = new HashMap<String, Integer>();

        // Load right xml
        setContentView(R.layout.activity_station);

        // Get station id from bundle extra
        if (mStationId == null) {
            mStationId = getIntent().getExtras().getInt("stationId");
        }

        // Get station from station id
        mStation = mTrainData.getStation(mStationId);

        MultiMap<String, String> reqParams = new MultiValueMap<String, String>();
        reqParams.put("mapid", String.valueOf(mStation.getId()));
        new LoadData().execute(reqParams);

        // Call google street api to load image
        new DisplayGoogleStreetPicture().execute(mStation.getStops().get(0).getPosition());

        this.mIsFavorite = isFavorite();

        TextView textView = (TextView) findViewById(R.id.activity_bike_station_station_name);
        textView.setText(mStation.getName().toString());

        mStreetViewImage = (ImageView) findViewById(R.id.activity_bike_station_streetview_image);

        mStreetViewText = (TextView) findViewById(R.id.activity_bike_station_steetview_text);

        mMapImage = (ImageView) findViewById(R.id.activity_bike_station_map_image);

        mDirectionImage = (ImageView) findViewById(R.id.activity_bike_station_map_direction);

        mFavoritesImage = (ImageView) findViewById(R.id.activity_bike_station_favorite_star);
        if (mIsFavorite) {
            mFavoritesImage.setImageDrawable(getResources().getDrawable(R.drawable.ic_save_active));
        }
        mFavoritesImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StationActivity.this.switchFavorite();
            }
        });

        LinearLayout stopsView = (LinearLayout) findViewById(R.id.activity_bike_station_details);

        this.mParamsStop = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

        Map<TrainLine, List<Stop>> stops = mStation.getStopByLines();
        CheckBox checkBox = null;
        for (Entry<TrainLine, List<Stop>> e : stops.entrySet()) {
            final TrainLine line = e.getKey();
            List<Stop> stopss = e.getValue();
            Collections.sort(stopss);
            LayoutInflater layoutInflater = (LayoutInflater) ChicagoTracker.getAppContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = layoutInflater.inflate(R.layout.activity_station_line_title, null);

            TextView lineTextView = (TextView) view.findViewById(R.id.activity_bus_station_value);
            lineTextView.setText(line.toStringWithLine());

            TextView lineColorTextView = (TextView) view.findViewById(R.id.activity_bus_color);
            lineColorTextView.setBackgroundColor(line.getColor());
            stopsView.addView(view);

            for (final Stop stop : stopss) {
                LinearLayout line2 = new LinearLayout(this);
                line2.setOrientation(LinearLayout.HORIZONTAL);
                line2.setLayoutParams(mParamsStop);

                checkBox = new CheckBox(this);
                checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        Preferences.saveTrainFilter(mStationId, line, stop.getDirection(), isChecked);
                    }
                });
                checkBox.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // Update timing
                        MultiMap<String, String> reqParams = new MultiValueMap<String, String>();
                        reqParams.put("mapid", String.valueOf(mStation.getId()));
                        new LoadData().execute(reqParams);
                    }
                });
                checkBox.setChecked(Preferences.getTrainFilter(mStationId, line, stop.getDirection()));
                checkBox.setText(stop.getDirection().toString());
                checkBox.setTextColor(getResources().getColor(R.color.grey));

                line2.addView(checkBox);
                stopsView.addView(line2);

                LinearLayout line3 = new LinearLayout(this);
                line3.setOrientation(LinearLayout.VERTICAL);
                line3.setLayoutParams(mParamsStop);
                int id3 = Util.generateViewId();
                line3.setId(id3);
                mIds.put(line.toString() + "_" + stop.getDirection().toString(), id3);

                stopsView.addView(line3);
            }

        }
        getActionBar().setDisplayHomeAsUpEnabled(true);

        Util.trackScreen(this, R.string.analytics_train_details);
    }
}

From source file:com.photon.phresco.nativeapp.eshop.activity.ProductDetailActivity.java

/**
 * Create the details sections at the bottom of the screen dynamically
 *
 * @param details//from www. j  a va 2 s. c  o  m
 * @throws NumberFormatException
 */
private void renderProdcutDetails(Map<String, String> details) {

    try {
        LinearLayout tl = (LinearLayout) findViewById(R.id.product_details_layout);
        int totalDetails = details.size();
        int cnt = 1;
        PhrescoLogger.info(TAG + "renderProdcutDetails() - totalDetails : " + totalDetails);
        TextView lblDetailLabel = null;
        for (Entry<String, String> entry : details.entrySet()) {

            // Create a TextView to hold the label for product detail
            lblDetailLabel = new TextView(this);
            if (cnt == 1) {
                lblDetailLabel.setBackgroundResource(R.drawable.view_cart_item_top);
            } else if (cnt == totalDetails) {
                lblDetailLabel.setBackgroundResource(R.drawable.view_cart_item_bottom);
            } else {
                lblDetailLabel.setBackgroundResource(R.drawable.view_cart_item_middle);
            }
            lblDetailLabel.setText(entry.getKey() + ": " + entry.getValue());
            lblDetailLabel.setGravity(Gravity.CENTER);
            lblDetailLabel.setTypeface(Typeface.DEFAULT, style.TextViewStyle);
            lblDetailLabel.setTextColor(Color.WHITE);
            lblDetailLabel.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f));
            tl.addView(lblDetailLabel);
            cnt++;
        }
    } catch (Exception ex) {
        PhrescoLogger.info(TAG + "renderProdcutDetails - Exception : " + ex.toString());
        PhrescoLogger.warning(ex);
    }
}

From source file:com.richtodd.android.quiltdesign.app.QuiltEditActivity.java

private void populateLayoutBlocks() {
    List<BlockContainerEntry> entries;
    try {/*from w w  w .j  a  v  a2  s . co m*/
        Repository repository = Repository.getDefaultRepository(this);
        BlockContainer blocks = repository.getBlocks();
        entries = blocks.getEntries(true);
    } catch (RepositoryException ex) {
        return;
    }

    LinearLayout layoutRow = null;

    for (BlockContainerEntry entry : entries) {
        View view = QuiltEditActivity.this.getLayoutInflater().inflate(R.layout.listentry_block_selector, null);

        ImageView image_thumbnail = (ImageView) view.findViewById(R.id.image_thumbnail);
        image_thumbnail.setImageBitmap(entry.getThumbnail());

        view.setTag(entry.getBlockName());
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String blockName = (String) v.getTag();
                try {
                    getQuiltEditFragment().setBlock(blockName);
                } catch (Exception e) {
                    Handle.asRuntimeError(e);
                }
            }
        });

        if (m_layout_blocks.getOrientation() == LinearLayout.HORIZONTAL) {
            m_layout_blocks.addView(view);
        } else {
            if (layoutRow != null && layoutRow.getChildCount() == m_layout_blocks.getNumColumns()) {
                layoutRow = null;
            }
            if (layoutRow == null) {
                layoutRow = new LinearLayout(this);
                layoutRow.setOrientation(LinearLayout.HORIZONTAL);
                m_layout_blocks.addView(layoutRow);
            }
            layoutRow.addView(view);
        }
    }
}

From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditClaimActivity.java

/**
 * Function that is called when you press the add tag
 * /*  w  w  w .j  a v  a2 s  .com*/
 * Creates a alert dialog that gives the user the option 
 * of adding a previously added tag or entering a new tag name
 * 
 * @param view
 */
public void addTagButton(View view) {
    final EditText enterTag = new EditText(this);
    final Spinner tagSpinner = new Spinner(this);
    //Linear layout that holds enterTag and tagSpinner views
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    tagSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View arg1, int position, long id) {
            enterTag.setText(parent.getItemAtPosition(position).toString());
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub      
        }
    });

    enterTag.setHint("Enter tag");
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    //get all the tags currently added to claims in application claimlist
    ArrayList<Tag> tags = ClaimListController.getTagList();
    String t[] = new String[tags.size()];
    for (int i = 0; i < tags.size(); i++) {
        t[i] = tags.get(i).getName();
    }
    //create a arrayadaptor for displaying the tagSpinner view, and set it
    ArrayAdapter<String> tagA = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, t);
    tagSpinner.setAdapter(tagA);
    //add views to linear layout and set the Linear layout view as the alert dialog view 
    ll.addView(tagSpinner);
    ll.addView(enterTag);
    alert.setView(ll);

    alert.setPositiveButton("Add", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Tag tag = new Tag(enterTag.getText().toString());
            if (theClaim.getTagList().getTag(enterTag.getText().toString()) != null) {
                return;
            }
            ClaimListController.addTag(theClaim, tag);
            tagAdaptor.notifyDataSetChanged();
        }
    });
    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    alert.show();
}

From source file:com.freeme.filemanager.view.FileViewFragment.java

private void buildVolumesList() {
    LinearLayout linearyLayout = (LinearLayout) mRootView.findViewById(R.id.dropdown_navigation_list);
    linearyLayout.removeAllViews();//from ww  w  .j ava 2  s.c o m

    ArrayList mountVolumeList = StorageHelper.getInstance(mActivity).getSortedMountVolumeList();
    if (mountVolumeList == null || mountVolumeList.size() == 0) {
        return;
    }

    Iterator iterator = mountVolumeList.iterator();
    while (iterator.hasNext()) {
        storageVolume = (StorageVolume) iterator.next();
        //Log.i("liuhaoran", "storageVolume = " + storageVolume);
        //*/ freeme.liuhaoran , 20160728 , adapter zhanxun M
        if (storageVolume.getStorageId() != 0) {
            linearyLayout.addView(
                    createStorageVolumeItem(storageVolume.getPath(), storageVolume.getDescription(mActivity)));
        }
        //*/
    }
}