Example usage for android.widget TextView setLayoutParams

List of usage examples for android.widget TextView setLayoutParams

Introduction

In this page you can find the example usage for android.widget TextView setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.google.reviewit.AddReviewerFragment.java

private void displayCCs(Change change) {
    TableLayout tl = (TableLayout) v(R.id.reviewerTable);
    Collection<AccountInfo> ccs = change.ccs();
    if (!ccs.isEmpty()) {
        TableRow tr = new TableRow(getContext());
        tr.setLayoutParams(matchAndWrapTableRowLayout());
        TextView ccsTitle = new TextView(getContext());
        TableRow.LayoutParams params = wrapTableRowLayout(2);
        params.bottomMargin = widgetUtil.dpToPx(3);
        ccsTitle.setLayoutParams(params);
        ccsTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
        ccsTitle.setText(getString(R.string.ccs));
        tr.addView(ccsTitle);//from  www  .  java  2  s. c  o m
        tl.addView(tr, matchAndWrapTableLayout());
        for (AccountInfo cc : ccs) {
            addReviewerRow(tl, cc);
        }
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LinkObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/* ww  w.jav  a  2 s .  com*/
    TextView valueTV = new TextView(context);
    String title;
    if (content.has(TITLE)) {
        title = "Link: " + content.optString(TITLE);
    } else {
        title = content.optString(URI);
    }
    valueTV.setText(title);
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
    if (Linkify.addLinks(valueTV, Linkify.ALL)) {
        if (!allowInteractions)
            valueTV.setMovementMethod(null);
    }

    frame.addView(valueTV);
}

From source file:com.investallign.controls.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from  w w w.j av a  2 s. c o m
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
protected TextView createDefaultTabView(Context context) {
    //        FuturaTextView textView = new FuturaTextView(context);
    LayoutInflater inflater = null;
    if (inflater == null)
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    TextView textView = (TextView) inflater.inflate(R.layout.sliding_textview, null);

    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:mobisocial.musubi.objects.FileObj.java

@Override
public View createView(Context context, ViewGroup frame) {
    LinearLayout container = new LinearLayout(context);
    container.setLayoutParams(CommonLayouts.FULL_WIDTH);
    container.setOrientation(LinearLayout.HORIZONTAL);
    container.setGravity(Gravity.CENTER);

    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    TextView valueTV = new TextView(context);

    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.BOTTOM | Gravity.LEFT);
    valueTV.setPadding(4, 0, 0, 0);/* w w w.  j ava2  s  . c o  m*/

    container.addView(imageView);
    container.addView(valueTV);
    return container;
}

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 {/*from   w  w w .  j  av a2  s  .  c  o m*/
        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:com.secbro.qark.customintent.CreateCustomIntentActivity.java

private void createExtrasView() {
    LinearLayout topLayout = (LinearLayout) findViewById(R.id.extras_key_value_container);

    LinearLayout.LayoutParams llpTextView = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    llpTextView.setMargins(10, 20, 10, 10); // llp.setMargins(left, top, right, bottom);

    LinearLayout.LayoutParams llpEditText = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    llpEditText.setMargins(10, 20, 10, 10); // llp.setMargins(left, top, right, bottom);

    //key/*from w  w w.  j a v  a 2s.  c o  m*/
    LinearLayout keyLinearLayout = new LinearLayout(this);
    keyLinearLayout.setOrientation(LinearLayout.HORIZONTAL);

    TextView keyTextView = new TextView(this);
    keyTextView.setText(getResources().getString(R.string.intent_extras_key));
    keyTextView.setLayoutParams(llpTextView);

    AutoCompleteTextView keyEditText = new AutoCompleteTextView(this);
    keyEditText.setLayoutParams(llpEditText);
    ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,
            getResources().getStringArray(R.array.intent_extras_array));
    keyEditText.setAdapter(adapter3);
    keyEditText.setSelection(keyEditText.getText().length());
    keyEditText.setTag("key_field");

    keyLinearLayout.addView(keyTextView);
    keyLinearLayout.addView(keyEditText);

    //value
    LinearLayout valueLinearLayout = new LinearLayout(this);
    valueLinearLayout.setOrientation(LinearLayout.HORIZONTAL);

    TextView valueTextView = new TextView(this);
    valueTextView.setText(getResources().getString(R.string.intent_extras_value));
    valueTextView.setLayoutParams(llpTextView);

    EditText valueEditText = new EditText(this);
    valueEditText.setTag("value_field");
    valueEditText.setLayoutParams(llpEditText);

    valueLinearLayout.addView(valueTextView);
    valueLinearLayout.addView(valueEditText);

    topLayout.addView(keyLinearLayout);
    topLayout.addView(valueLinearLayout);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LocationObj.java

@Override
public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/*from   ww w  . ja va2s  .c  o m*/
    TextView valueTV = new TextView(context);
    NumberFormat df = DecimalFormat.getNumberInstance();
    df.setMaximumFractionDigits(5);
    df.setMinimumFractionDigits(5);

    String msg = "I'm at " + df.format(content.optDouble(COORD_LAT)) + ", "
            + df.format(content.optDouble(COORD_LONG));

    valueTV.setText(msg);
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
    frame.addView(valueTV);
}

From source file:com.truman.showtime.showtime.ui.view.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from   w w  w  . j  a va 2 s .c o  m
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setTextColor(Color.WHITE);
    textView.setGravity(Gravity.CENTER);
    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppObj.java

@Override
public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) {
    PackageManager pm = context.getPackageManager();
    Drawable icon = null;/*from   ww  w  . jav  a2s  .  c o  m*/
    String appName;
    if (obj.getJson() != null && obj.getJson().has(ANDROID_PACKAGE_NAME)) {
        appName = obj.getJson().optString(ANDROID_PACKAGE_NAME);
    } else {
        appName = "Unknown";
    }
    if (!(obj instanceof DbObj)) {
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
        String text = "Preparing application " + appName + "...";
        // TODO: Show Market icon or app icon.
        TextView valueTV = new TextView(context);
        valueTV.setText(text);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
        return;
    }

    DbObj dbParentObj = (DbObj) obj;
    boolean rendered = false;

    Intent launch = getLaunchIntent(context, dbParentObj);
    List<ResolveInfo> infos = pm.queryIntentActivities(launch, 0);
    if (infos.size() > 0) {
        ResolveInfo info = infos.get(0);
        if (info.activityInfo.labelRes != 0) {
            appName = info.activityInfo.loadLabel(pm).toString();
            icon = info.loadIcon(pm);
        } else {
            appName = info.activityInfo.name;
        }
    } else {
        appName = obj.getJson().optString(ANDROID_PACKAGE_NAME);
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
    }
    // TODO: Safer reference to containing view
    if (icon != null) {
        View parentView = (View) frame.getParent().getParent();
        ImageView avatar = (ImageView) parentView.findViewById(R.id.icon);
        avatar.setImageDrawable(icon);

        TextView label = (TextView) parentView.findViewById(R.id.name_text);
        label.setText(appName);
    }

    // TODO: obj.getLatestChild().render();
    String selection = getRenderableClause();
    String[] selectionArgs = null;
    Cursor cursor = dbParentObj.getSubfeed().query(selection, selectionArgs);
    if (cursor.moveToFirst()) {
        DbObj dbObj = App.instance().getMusubi().objForCursor(cursor);
        DbObjects.getFeedRenderer(dbObj.getType()).render(context, frame, dbObj, allowInteractions);
        rendered = true;
    }

    if (!rendered) {
        String text;
        if (icon != null) {
            ImageView iv = new ImageView(context);
            iv.setImageDrawable(icon);
            iv.setAdjustViewBounds(true);
            iv.setMaxWidth(60);
            iv.setMaxHeight(60);
            iv.setLayoutParams(CommonLayouts.WRAPPED);
            frame.addView(iv);
            text = appName;
        } else {
            text = "New application: " + appName + ".";
        }
        // TODO: Show Market icon or app icon.
        TextView valueTV = new TextView(context);
        valueTV.setText(text);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
    }
}

From source file:itesm.mx.golpedecalor.MonitoringActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_monitoring);

    alerta = false;/*from w ww.  j  a va 2  s.  c om*/

    dbo = new DataBaseOperations(getApplicationContext());
    groupId = getIntent().getLongExtra("id", 0);

    // Referencias a objetos de interfacae
    tablaTL = (TableLayout) findViewById(R.id.tablaTL);
    nombreTV = (TextView) findViewById(R.id.nombreTV);
    causaTV = (TextView) findViewById(R.id.causaTV);
    parametroTV = (TextView) findViewById(R.id.parametroTV);
    switcherVS = (ViewSwitcher) findViewById(R.id.switcherVS);
    mp = MediaPlayer.create(this, R.raw.alert);
    recomendacionesTV = (TextView) findViewById(R.id.recomendacionesTV);

    // Inicializacin
    rc = new ArrayList<TextView>();
    temp = new ArrayList<TextView>();
    rad = new ArrayList<TextView>();

    try {
        dbo.open();
    } catch (SQLException ex) {
        Log.e("", ex.toString());
    }

    grupo = dbo.getGroup(groupId);
    grupo.setIntegrantes(dbo.getAllUsersFromGroup(grupo));
    monitoreoHelper = new Monitoreo(grupo, this);

    for (Usuario u : grupo.getIntegrantes()) {
        TableRow tr = new TableRow(this);
        tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                TableRow.LayoutParams.FILL_PARENT));

        TextView tvAux = new TextView(this);
        tvAux.setText(u.getNombre() + " " + u.getApellidos());
        tvAux.setLayoutParams(new TableRow.LayoutParams(400, TableRow.LayoutParams.WRAP_CONTENT));

        TextView rcAux = new TextView(this);
        rcAux.setText("5");
        rcAux.setLayoutParams(new TableRow.LayoutParams(200, TableRow.LayoutParams.WRAP_CONTENT));

        TextView tempAux = new TextView(this);
        tempAux.setText("9");
        tempAux.setLayoutParams(new TableRow.LayoutParams(200, TableRow.LayoutParams.WRAP_CONTENT));

        TextView radAux = new TextView(this);
        radAux.setText("10");
        radAux.setLayoutParams(new TableRow.LayoutParams(100, TableRow.LayoutParams.WRAP_CONTENT));

        rc.add(rcAux);
        temp.add(tempAux);
        rad.add(radAux);

        tr.addView(tvAux);
        tr.addView(rcAux);
        tr.addView(tempAux);
        tr.addView(radAux);

        tr.setBackgroundResource(R.drawable.tabla); // Asigna recurso de drawable a la row nueva
        tablaTL.addView(tr);
    }
    monitoreoHelper.empezarMonitoreo();

    notificationIntent = new Intent(getApplicationContext(), NotificationActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    dialogClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                monitoreoHelper.terminarAlerta();
                break;

            case DialogInterface.BUTTON_NEGATIVE:
                //No button clicked
                break;
            }
        }
    };

}