List of usage examples for android.widget TextView setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:com.eric.quora.fragment.SuperAwesomeCardFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); FrameLayout fl = new FrameLayout(getActivity()); fl.setLayoutParams(params);// w w w . ja v a2s. c o m fl.setBackgroundResource(mipmaps[position]); final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()); TextView v = new TextView(getActivity()); params.setMargins(margin, margin, margin, margin); v.setLayoutParams(params); v.setLayoutParams(params); v.setGravity(Gravity.BOTTOM); v.setText("CARD " + (position + 1)); fl.addView(v); return fl; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.JoinNotificationObj.java
@Override public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) { TextView valueTV = new TextView(context); valueTV.setText("I'm here!"); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.TOP | Gravity.LEFT); frame.addView(valueTV);// w w w . ja v a 2 s.co m }
From source file:feipai.qiangdan.my.SuperAwesomeCardFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); FrameLayout fl = new FrameLayout(getActivity()); fl.setLayoutParams(params);/*from w w w .ja v a 2 s. com*/ final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics()); TextView v = new TextView(getActivity()); params.setMargins(margin, margin, margin, margin); v.setLayoutParams(params); v.setGravity(Gravity.CENTER); // v.setBackgroundResource(R.drawable.ic_launcher); // v.setText("CARD " + (position + 1)); v.setText(" "); v.setTextSize(20); v.setTextColor(getActivity().getResources().getColor(R.color.address_title_color)); // Drawable drawable = getActivity().getDrawable(R.drawable.icon_no_order); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_no_order); BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap); //TextViewdrawableleft v.setCompoundDrawablesWithIntrinsicBounds(null, bitmapDrawable, null, null); fl.addView(v); return fl; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.StatusObj.java
public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) { JSONObject content = obj.getJson();//from w w w . j a v a 2s . c o m TextView valueTV = new TextView(context); valueTV.setText(content.optString(TEXT)); 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:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToGroupObj.java
@Override public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) { JSONObject content = obj.getJson();// ww w . j ava2 s. com TextView valueTV = new TextView(context); valueTV.setText("Join me in '" + content.optString(GROUP_NAME) + "'"); 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:eu.geopaparazzi.library.forms.views.GTimeView.java
/** * @param fragment the fragment./*from w w w.j av a 2 s . com*/ * @param attrs attributes. * @param parentView parent * @param key key * @param value value * @param constraintDescription constraints * @param readonly if <code>false</code>, the item is disabled for editing. */ public GTimeView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String key, String value, String constraintDescription, boolean readonly) { super(fragment.getActivity(), attrs); Context context = fragment.getActivity(); LinearLayout textLayout = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(key.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(context.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); button = new Button(context); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); final SimpleDateFormat timeFormatter = TimeUtilities.INSTANCE.TIMEONLY_FORMATTER; if (value == null || value.length() == 0) { String dateStr = timeFormatter.format(new Date()); button.setText(dateStr); } else { button.setText(value); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String dateStr = button.getText().toString(); Date date = null; try { date = timeFormatter.parse(dateStr); } catch (ParseException e) { // fallback on current date date = new Date(); } final Calendar c = Calendar.getInstance(); c.setTime(date); int hourOfDay = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); FormTimePickerFragment newFragment = new FormTimePickerFragment(); newFragment.setAttributes(hourOfDay, minute, true, button); newFragment.show(fragment.getFragmentManager(), "timePicker"); } }); button.setEnabled(!readonly); textLayout.addView(button); }
From source file:eu.geopaparazzi.library.forms.views.GDateView.java
/** * @param fragment the fragment to use. * @param attrs attributes./*from ww w . j a va 2s .com*/ * @param parentView parent * @param key key * @param value value * @param constraintDescription constraints * @param readonly if <code>false</code>, the item is disabled for editing. */ public GDateView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String key, String value, String constraintDescription, boolean readonly) { super(fragment.getActivity(), attrs); Context context = fragment.getActivity(); LinearLayout textLayout = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(key.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(context.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); button = new Button(context); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); final SimpleDateFormat dateFormatter = TimeUtilities.INSTANCE.DATEONLY_FORMATTER; if (value == null || value.length() == 0) { String dateStr = dateFormatter.format(new Date()); button.setText(dateStr); } else { button.setText(value); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String dateStr = button.getText().toString(); Date date = null; try { date = dateFormatter.parse(dateStr); } catch (ParseException e) { // fallback on current date date = new Date(); } final Calendar c = Calendar.getInstance(); c.setTime(date); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); FormDatePickerFragment newFragment = new FormDatePickerFragment(year, month, day, button); newFragment.show(fragment.getFragmentManager(), "datePicker"); } }); button.setEnabled(!readonly); textLayout.addView(button); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.MusicObj.java
public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) { JSONObject content = obj.getJson();/*from w ww. j a v a2 s .com*/ LinearLayout container = new LinearLayout(context); container.setLayoutParams(CommonLayouts.FULL_WIDTH); container.setOrientation(LinearLayout.HORIZONTAL); container.setGravity(Gravity.CENTER); ImageView imageView = new ImageView(context); imageView.setImageResource(R.drawable.play); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); TextView valueTV = new TextView(context); valueTV.setText(asText(content)); 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); container.addView(imageView); container.addView(valueTV); frame.addView(container); }
From source file:br.org.funcate.dynamicforms.views.GTimeView.java
/** * @param fragment the fragment.//from w ww .ja v a 2s . c o m * @param attrs attributes. * @param parentView parent * @param label label * @param value value * @param constraintDescription constraints * @param readonly if <code>false</code>, the item is disabled for editing. */ public GTimeView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String label, String value, String constraintDescription, boolean readonly) { super(fragment.getActivity(), attrs); final Context context = fragment.getActivity(); LinearLayout textLayout = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(context.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); button = new Button(context); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); final SimpleDateFormat timeFormatter = TimeUtilities.INSTANCE.TIMEONLY_FORMATTER; if (value == null || value.length() == 0) { String dateStr = timeFormatter.format(new Date()); button.setText(dateStr); } else { button.setText(value); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String dateStr = button.getText().toString(); Date date = null; try { date = timeFormatter.parse(dateStr); } catch (ParseException e) { //GPLog.error(this, null, e); Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); // fallback on current date date = new Date(); } final Calendar c = Calendar.getInstance(); c.setTime(date); int hourOfDay = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); FormTimePickerFragment newFragment = new FormTimePickerFragment(); newFragment.setAttributes(hourOfDay, minute, true, button); //newFragment.show(fragment.getFragmentManager(), "timePicker"); } }); button.setEnabled(!readonly); textLayout.addView(button); }
From source file:br.org.funcate.dynamicforms.views.GDateView.java
/** * @param fragment the fragment to use. * @param attrs attributes.//from w w w. j a v a 2 s . co m * @param parentView parent * @param label label * @param value value * @param constraintDescription constraints * @param readonly if <code>false</code>, the item is disabled for editing. */ public GDateView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String label, String value, String constraintDescription, boolean readonly) { super(fragment.getActivity(), attrs); final Context context = fragment.getActivity(); LinearLayout textLayout = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(context.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); button = new Button(context); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); final SimpleDateFormat dateFormatter = TimeUtilities.INSTANCE.DATEONLY_FORMATTER; if (value == null || value.length() == 0) { String dateStr = dateFormatter.format(new Date()); button.setText(dateStr); } else { button.setText(value); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String dateStr = button.getText().toString(); Date date = null; try { date = dateFormatter.parse(dateStr); } catch (ParseException e) { //GPLog.error(this, null, e); Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); date = new Date(); } final Calendar c = Calendar.getInstance(); c.setTime(date); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); FormDatePickerFragment newFragment = new FormDatePickerFragment(); newFragment.setAttributes(year, month, day, button); newFragment.show(fragment.getFragmentManager(), "datePicker"); } }); button.setEnabled(!readonly); textLayout.addView(button); }