List of usage examples for android.widget TextView setPadding
@Override public void setPadding(int left, int top, int right, int bottom)
From source file:de.janrenz.app.mediathek.MediathekActivity.java
protected AlertDialog getInfoDialog() { TextView tv = new TextView(this); //tv.setBackgroundColor(getResources().getColor(R.color.abs__bright_foreground_holo_dark)); tv.setPadding(15, 15, 15, 15); tv.setMovementMethod(new ScrollingMovementMethod()); tv.setScrollBarStyle(1);/*from w w w.j a va 2s . com*/ tv.setText(Html.fromHtml(getString(R.string.infotext))); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Mediathek 1").setView(tv).setInverseBackgroundForced(true)//needed for old android version .setCancelable(false) // OK button .setPositiveButton(this.getResources().getString(R.string.changelog_ok_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); // Show "More" button if we're only displaying a partial change log. builder.setNegativeButton(R.string.info_popup_changelog, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (cl != null) cl.getFullLogDialog().show(); } }); return builder.create(); }
From source file:com.eyekabob.EventInfo.java
protected void loadEvent(JSONObject response) { try {//from w w w .j a va 2 s .co m JSONObject jsonEvent = response.getJSONObject("event"); artists = new ArrayList<String>(); title = jsonEvent.getString("title"); JSONObject jsonAllArtists = jsonEvent.getJSONObject("artists"); headliner = jsonAllArtists.getString("headliner"); Object artistObj = jsonAllArtists.get("artist"); JSONArray jsonOpeners = new JSONArray(); if (artistObj instanceof JSONArray) { jsonOpeners = (JSONArray) artistObj; } for (int i = 0; i < jsonOpeners.length(); i++) { String artistName = jsonOpeners.getString(i); if (!headliner.equals(artistName)) { artists.add(artistName); } } JSONObject jsonVenue = jsonEvent.getJSONObject("venue"); venue = jsonVenue.optString("name"); venueCity = jsonVenue.optString("city"); venueStreet = jsonVenue.optString("street"); venueUrl = jsonVenue.optString("url"); startDate = EyekabobHelper.LastFM.toReadableDate(jsonEvent.getString("startDate")); JSONObject image = EyekabobHelper.LastFM.getLargestJSONImage(jsonEvent.getJSONArray("image")); imageUrl = image.getString("#text"); } catch (JSONException e) { Log.e(getClass().getName(), "", e); } try { new EventImageTask().execute(new URL(imageUrl)); } catch (MalformedURLException e) { Log.e(getClass().getName(), "Bad image URL [" + imageUrl + "]", e); } TextView titleView = (TextView) findViewById(R.id.infoMainHeader); titleView.setText(title); TextView headlinerView = (TextView) findViewById(R.id.infoSubHeaderOne); // TODO: I18N headlinerView.setText("Headlining: " + headliner); TextView dateTimeView = (TextView) findViewById(R.id.infoSubHeaderTwo); dateTimeView.setText(startDate); if (!startDate.equals("")) { Button tixButton = (Button) findViewById(R.id.infoTicketsButton); tixButton.setVisibility(View.VISIBLE); } LinearLayout artistsView = (LinearLayout) findViewById(R.id.infoFutureEventsContent); TextView alsoPerformingView = (TextView) findViewById(R.id.infoFutureEventsHeader); if (!artists.isEmpty()) { // TODO: I18N alsoPerformingView.setText("Also Performing:"); for (String artist : artists) { TextView row = new TextView(this); row.setTextColor(Color.WHITE); row.setText(artist); row.setPadding(20, 0, 0, 20); // Left and bottom padding artistsView.addView(row); } } String venueDesc = ""; TextView venueView = (TextView) findViewById(R.id.infoEventVenue); // TODO: Padding instead of whitespace venueDesc += " " + venue; if (!venueCity.equals("") && !venueStreet.equals("")) { // TODO: I18N venueDesc += "\n Address: " + venueStreet + "\n" + venueCity; } // TODO: Padding instead of whitespace venueDesc += "\n " + startDate; TextView venueTitleView = (TextView) findViewById(R.id.infoBioHeader); if (!venue.equals("") || !venueCity.equals("") || !venueStreet.equals("")) { // TODO: I18N venueTitleView.setText("Venue Details:"); View vView = findViewById(R.id.infoVenueDetails); vView.setVisibility(View.VISIBLE); } else { // TODO: I18N venueTitleView.setText("No Venue Details Available"); } venueView.setVisibility(View.VISIBLE); venueView.setText(venueDesc); TextView websiteView = (TextView) findViewById(R.id.infoVenueWebsite); if (!venueUrl.equals("")) { // TODO: I18N websiteView.setVisibility(View.VISIBLE); websiteView.setText(Html.fromHtml("<a href=\"" + venueUrl + "\">More Information</a>")); websiteView.setMovementMethod(LinkMovementMethod.getInstance()); } }
From source file:com.doomonafireball.hackerswiperfree.android.activity.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.get_hacker_swiper_pro: Intent hsProIntent = new Intent(Intent.ACTION_VIEW); hsProIntent.setData(Uri.parse(// w w w .ja v a2s. c o m "http://play.google.com/store/apps/details?id=com.doomonafireball.hackerswiperpro.android")); startActivity(hsProIntent); return true; case R.id.about: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.about_hacker_swiper); final TextView aboutText = new TextView(this); int padding = getResources().getDimensionPixelSize(R.dimen.default_padding); aboutText.setPadding(padding, padding, padding, padding); String appVersionName = "x.x"; int appVersionCode = 0; try { appVersionName = getApplication().getPackageManager() .getPackageInfo(getApplication().getPackageName(), 0).versionName; appVersionCode = getApplication().getPackageManager() .getPackageInfo(getApplication().getPackageName(), 0).versionCode; } catch (PackageManager.NameNotFoundException e) { //Failed } aboutText.setText(Html.fromHtml(getString(R.string.about_hacker_swiper_text))); aboutText.append( String.format(getString(R.string.version_dynamic), appVersionName + " b" + appVersionCode)); aboutText.append("\n"); SpannableString openSourceLink = makeLinkSpan(getString(R.string.open_source_licenses), new View.OnClickListener() { @Override public void onClick(View v) { showOpenSourceDialog(); } }); aboutText.append(openSourceLink); aboutText.append("\n"); aboutText.setFocusable(false); makeLinksFocusable(aboutText); builder.setView(aboutText); builder.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }); builder.show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:gov.sfmta.sfpark.DetailViewActivity.java
public TextView normalText(String val) { TextView ntv = new TextView(this); ntv.setPadding(8, 7, 5, 7); ntv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); ntv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); ntv.setTextColor(Color.BLACK); ntv.setText(val); return ntv;/* w ww . j a va2 s. c om*/ }
From source file:com.todoroo.astrid.ui.HideUntilControlSet.java
@Nullable @Override//from ww w .j ava 2 s . com public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); adapter = new HiddenTopArrayAdapter<HideUntilValue>(context, android.R.layout.simple_spinner_item, spinnerItems) { @NonNull @Override public View getView(int position, View convertView, @NonNull ViewGroup parent) { int selectedItemPosition = position; if (parent instanceof AdapterView) { selectedItemPosition = ((AdapterView) parent).getSelectedItemPosition(); } TextView tv = (TextView) inflater.inflate(android.R.layout.simple_spinner_item, parent, false); tv.setPadding(0, 0, 0, 0); HideUntilValue value = getItem(selectedItemPosition); if (value.setting == Task.HIDE_UNTIL_NONE) { clearButton.setVisibility(View.GONE); tv.setText(value.label); tv.setTextColor(getColor(context, R.color.text_tertiary)); } else { String display = value.label; if (value.setting != Task.HIDE_UNTIL_SPECIFIC_DAY && value.setting != Task.HIDE_UNTIL_SPECIFIC_DAY_TIME) { display = display.toLowerCase(); } tv.setText(getString(R.string.TEA_hideUntil_display, display)); tv.setTextColor(getColor(context, R.color.text_primary)); } return tv; } }; if (savedInstanceState == null) { updateSpinnerOptions(initialHideUntil); } else { updateSpinnerOptions(savedInstanceState.getLong(EXTRA_CUSTOM)); selection = savedInstanceState.getInt(EXTRA_SELECTION); } spinner.setAdapter(adapter); spinner.setSelection(selection); spinner.setOnItemSelectedListener(this); refreshDisplayView(); return view; }
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 w w . j a v a 2 s . c om 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:fm.krui.kruifm.ScheduleFragment.java
/** * Adds a show to the schedule./*from ww w. j a v a 2 s . c om*/ * @param title Title of show to display * @param description Description of show to display * @param startTime Start time of show in minutes from midnight * @param endTime End time of show in minutes from midnight * @param category Format of this show, required to correctly color the event. * * Valid settings for category include: * 1 - Regular Rotation * 2 - Music Speciality * 3 - Sports * 4 - News/Talk * 5 - Specials */ private void addShow(String title, String description, int startTime, int endTime, int category) { /* Build the LinearLayout to function as the container for this show. Since the size of the container is to represent the length of the show, its height must be proportional (1dp = 1 minute) to the length. Determine length by finding the difference between the start and end times. */ // Fix for corner case of shows ending at midnight. if (endTime == 0) { endTime = 1440; } int difference = endTime - startTime; /* Define the margins of this show. All shows must not overlap the displayed times, which are 50dp in width. Add 5 more (to the right and left) to see the schedule lines for clarity. Push the show down to align with the appropriate time marker using the top margin value set to the difference (in minutes) between midnight and the start of the show. */ Log.v(TAG, "Configuring " + title); //Log.v(TAG, "Start time: " + startTime + " End time: " + endTime); //Log.v(TAG, "Setting parameters for " + title); RelativeLayout.LayoutParams rrLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, dpToPixels(difference)); rrLayoutParams.leftMargin = dpToPixels(55); //Log.v(TAG, "Left margin: " + rrLayoutParams.leftMargin); rrLayoutParams.topMargin = dpToPixels(startTime); //Log.v(TAG, "Top margin: " + rrLayoutParams.topMargin); rrLayoutParams.rightMargin = dpToPixels(5); //Log.v(TAG, "Right margin: " + rrLayoutParams.rightMargin); /* Build LinearLayout and apply parameters */ LinearLayout eventLL = new LinearLayout(getActivity()); eventLL.setOrientation(LinearLayout.VERTICAL); eventLL.setPadding(dpToPixels(5), dpToPixels(2), dpToPixels(5), dpToPixels(5)); // Get background for this event eventLL.setBackgroundResource(getEventBackground(category)); /* Add title of event to LinearLayout */ TextView titleTV = new TextView(getActivity()); // Title of a show should be bolded titleTV.setText(title); titleTV.setTypeface(null, Typeface.BOLD); titleTV.setPadding(dpToPixels(5), 0, dpToPixels(5), 0); eventLL.addView(titleTV); /* Determine length of event to see if we have room to attach a description (if one was passed) */ int length = endTime - startTime; /* Attach a description with a size that depends on the event length (longer events can hold more description text). */ if (description != null) { TextView descriptionTV = new TextView(getActivity()); descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5)); descriptionTV.setText(description); // ~hour long shows can display 1 line of description if (difference >= 30 && difference <= 60) { descriptionTV.setMaxLines(1); } // 1:30 long shows can display 2 lines of description else if (difference >= 60 && difference <= 90) { descriptionTV.setMaxLines(2); } // 2:00 long shows can display 4 lines of description else if (difference >= 120) { descriptionTV.setMaxLines(4); } descriptionTV.setEllipsize(TextUtils.TruncateAt.END); descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5)); eventLL.addView(descriptionTV); } /* Add this view to the schedule UI */ RelativeLayout rl = (RelativeLayout) rootView.findViewById(R.id.schedule_container_relativelayout); rl.addView(eventLL, rrLayoutParams); }
From source file:com.github.chilinh.android.form.Form.java
public AlertDialog buildDialog(Context context, final Callback.Submit<DialogInterface> submitCb, final Callback.Dismiss<DialogInterface> dismissCb) { mModel = new FormModelDialog(); if (TextUtils.isEmpty(mSubmitBtn)) { mSubmitBtn = "Summit"; }//from w w w. j av a2s .c o m TextView title = new TextView(context); title.setText(mTitle); title.setPadding(10, 10, 10, 15); title.setGravity(Gravity.CENTER); title.setTextSize(22); View view = LayoutInflater.from(context).inflate(R.layout.base_form, null, false); ViewGroup group = (ViewGroup) view.findViewById(R.id.form_elements_container); makeFormView(group); AlertDialog.Builder builder = new AlertDialog.Builder(context).setCustomTitle(title).setView(view) .setPositiveButton(mSubmitBtn, null).setNegativeButton(mCancelBtn, null); final AlertDialog alertDialog = builder.create(); applyWindow(alertDialog.getWindow()); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(final DialogInterface dialog) { Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); if (positive != null) { positive.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (validate(mContext)) { if (submitCb != null) { if (submitCb.validate(dialog, Form.this)) { submitCb.onSubmit(dialog, Form.this); } return; } dialog.dismiss(); } } }); } } }); alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (dismissCb != null) { dismissCb.onDismiss(dialog, Form.this); } } }); alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (dismissCb != null) { dismissCb.onCancel(dialog, Form.this); } } }); return alertDialog; }
From source file:com.mikecorrigan.trainscorekeeper.FragmentSummary.java
@SuppressLint("NewApi") @Override/*from w ww . ja va 2 s . c om*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.vc(VERBOSE, TAG, "onCreateView: inflater=" + inflater + ", container=" + container + ", savedInstanceState=" + Utils.bundleToString(savedInstanceState)); View rootView = inflater.inflate(R.layout.fragment_summary, container, false); final MainActivity activity = (MainActivity) getActivity(); final Context context = activity; final Resources resources = context.getResources(); // Get the model and attach a listener. game = activity.getGame(); if (game != null) { game.addListener(mGameListener); } players = activity.getPlayers(); // Get resources. String[] playerNames = resources.getStringArray(R.array.playerNames); TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables); TypedArray playerTextColorsArray = resources.obtainTypedArray(R.array.playerTextColors); int[] playerTextColorsIds = new int[playerTextColorsArray.length()]; for (int i = 0; i < playerTextColorsArray.length(); i++) { playerTextColorsIds[i] = playerTextColorsArray.getResourceId(i, -1); } // Get root view. ScrollView scrollView = (ScrollView) rootView.findViewById(R.id.scroll_view); // Create table. tableLayout = new TableLayout(context); TableLayout.LayoutParams tableLayoutParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); tableLayout.setLayoutParams(tableLayoutParams); scrollView.addView(tableLayout); // Add header. { TableRow row = new TableRow(context); row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); tableLayout.addView(row); TextView tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.player)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.trains)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.contracts)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.bonuses)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); } // Add rows. for (int i = 0; i < players.getNum(); i++) { TableRow row = new TableRow(context); row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); tableLayout.addView(row); ToggleButton toggleButton = new ToggleButton(context); toggleButton.setGravity(Gravity.CENTER); toggleButton.setPadding(10, 10, 10, 10); toggleButton.setText(playerNames[i]); toggleButton.setClickable(false); Drawable drawable = drawablesArray.getDrawable(i); int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { toggleButton.setBackgroundDrawable(drawable); } else { toggleButton.setBackground(drawable); } toggleButton.setTextColor(resources.getColor(playerTextColorsIds[i])); row.addView(toggleButton); TextView tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); row.addView(tv); } Bundle args = getArguments(); if (args == null) { Log.e(TAG, "onCreateView: missing arguments"); return rootView; } drawablesArray.recycle(); playerTextColorsArray.recycle(); // final int index = args.getInt(ARG_INDEX); // final String tabSpec = args.getString(ARG_TAB_SPEC); return rootView; }
From source file:com.meetingninja.csse.tasks.TasksFragment.java
@Override public View getDropDownView(int position, View convertView, ViewGroup parent) { TextView rowView = (TextView) getView(position, convertView, parent); rowView.setPadding((int) this.context.getResources().getDimension(R.dimen.activity_horizontal_margin), (int) this.context.getResources().getDimension(R.dimen.activity_vertical_margin), (int) this.context.getResources().getDimension(R.dimen.activity_horizontal_margin), (int) this.context.getResources().getDimension(R.dimen.activity_vertical_margin)); return rowView; }