Example usage for android.widget TextView setPadding

List of usage examples for android.widget TextView setPadding

Introduction

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

Prototype

@Override
public void setPadding(int left, int top, int right, int bottom) 

Source Link

Usage

From source file:br.org.funcate.dynamicforms.views.GDateView.java

/**
 * @param fragment   the fragment to use.
 * @param attrs attributes./*  w  w  w  .j a  v  a  2s.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);
}

From source file:de.gebatzens.sia.fragment.RemoteDataFragment.java

public TextView createPrimaryTextView(String text, int size, LayoutInflater inflater, ViewGroup group) {
    TextView t = (TextView) inflater.inflate(R.layout.basic_textview_primary, group, false);
    t.setText(text);//from   www  .  j a v a 2 s  .co m
    t.setPadding(0, 0, toPixels(20), 0);
    t.setTextSize(size);
    group.addView(t);
    return t;
}

From source file:de.gebatzens.sia.fragment.RemoteDataFragment.java

public TextView createSecondaryTextView(String text, int size, LayoutInflater inflater, ViewGroup group) {
    TextView t = (TextView) inflater.inflate(R.layout.basic_textview_secondary, group, false);
    t.setText(text);//from w  w  w. j  a v a  2s .c  om
    t.setPadding(0, 0, toPixels(20), 0);
    t.setTextSize(size);
    group.addView(t);
    return t;
}

From source file:com.itime.team.itime.fragments.InputDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    // Get the layout inflater
    final LayoutInflater inflater = getActivity().getLayoutInflater();

    TextView title = new TextView(getActivity());
    // You Can Customise your Title here
    String titleText = getArguments().getString(INPUT_DIALOG_TITLE);
    title.setText(titleText);/* w  ww.  ja v  a  2 s.  c  om*/
    title.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
    title.setPadding(10, 10, 10, 10);
    title.setGravity(Gravity.CENTER);
    title.setTextColor(Color.WHITE);
    title.setTextSize(20);

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(inflater.inflate(R.layout.fragment_input_dialog, null)).setCustomTitle(title)
            // Add action buttons
            .setPositiveButton(R.string.Save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    TextView inputArea = (TextView) getDialog().findViewById(R.id.input_area);
                    mListener.onDialogPositiveClick(inputArea.getText().toString());

                }
            }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    mListener.onDialogNegativeClick(InputDialogFragment.this);
                }
            });
    return builder.create();
}

From source file:com.pseudosudostudios.jdd.fragments.ScoreFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    View view = inflater.inflate(R.layout.score_display, container, false);
    // Find the user's profile picture custom view
    // Find the user's name view
    userNameView = (TextView) view.findViewById(R.id.selection_user_name);
    scoreDisplay = (TextView) view.findViewById(R.id.scoreDisplay);
    movesDisplay = (TextView) view.findViewById(R.id.movesDisplay);
    timeDisplay = (TextView) view.findViewById(R.id.timeDisplay);
    playAgain = (Button) view.findViewById(R.id.playAgainButton);
    highScores = (ListView) view.findViewById(R.id.high_score_list_view);

    signIn = view.findViewById(R.id.sign_in_button_google_play_services);
    signOut = view.findViewById(R.id.sign_out_button);

    TextView tv = new TextView(getActivity());
    tv.setText(getActivity().getString(R.string.high_scores));
    tv.setTextSize(20);//  w  w  w .j  a v  a 2 s  .  c  om
    tv.setGravity(Gravity.CENTER_HORIZONTAL);
    tv.setPadding(0, 6, 0, 6);
    highScores.addHeaderView(tv);

    shareSocial = (Button) view.findViewById(R.id.social_share);
    shareSocial.setVisibility(View.INVISIBLE);

    // onClickListeners
    shareSocial.setOnClickListener(this);

    signIn.setOnClickListener(this);
    signOut.setOnClickListener(this);

    return view;
}

From source file:com.connectsdk.smarthomesampler.dialog.AcknowledgementsFragmentDialog.java

@NonNull
@Override/*  w ww  .  j  a  v  a 2s . com*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context context = getActivity();
    final TextView message = new TextView(context);
    message.setText(Html.fromHtml(context.getString(R.string.info_message)));
    message.setMovementMethod(LinkMovementMethod.getInstance());
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25,
            context.getResources().getDisplayMetrics());
    message.setPadding(padding, 0, padding, 0);
    ScrollView scrollView = new ScrollView(context);
    scrollView.addView(message);

    return new AlertDialog.Builder(context).setTitle(R.string.info_title).setView(scrollView)
            .setCancelable(true).create();
}

From source file:com.github.wakhub.monodict.activity.bean.ActivityHelper.java

public AlertDialog.Builder buildNoticeDialog(CharSequence text) {
    TextView textView = new TextView(activity);
    textView.setAutoLinkMask(Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
    textView.setPadding((int) spaceSuperRelax, (int) spaceSuperRelax, (int) spaceSuperRelax,
            (int) spaceSuperRelax);
    textView.setText(text);/*from  w  w  w. java 2  s . c om*/
    ScrollView scrollView = new ScrollView(activity);
    scrollView.addView(textView);
    return new AlertDialog.Builder(activity).setView(scrollView).setPositiveButton(android.R.string.ok, null);
}

From source file:at.wada811.android.dialogfragments.sample.alertdialogfragment.AlertDialogFragmentExamplesFragment.java

@Override
public DialogFragmentCallback getDialogFragmentCallback() {
    return new SimpleDialogFragmentCallback() {
        @Override//from www .ja  v a 2s  .c om
        public void onShow(DialogFragmentInterface dialog) {
            String text = "onShow";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel(DialogFragmentInterface dialog) {
            String text = "onCancel";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onDismiss(DialogFragmentInterface dialog) {
            String text = "onDismiss";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onClickPositive(DialogFragmentInterface dialog) {
            String text = "onClickPositive";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onClickNeutral(DialogFragmentInterface dialog) {
            String text = "onClickNeutral";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onClickNegative(DialogFragmentInterface dialog) {
            String text = "onClickNegative";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public boolean onKey(DialogFragmentInterface dialog, int keyCode, KeyEvent event) {
            String text = "onKey[keyCode: " + keyCode + ", KeyEvent: " + event + "]";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
            return false;
        }

        @Override
        public void onItemClick(DialogFragmentInterface dialog, int position) {
            Bundle extra = dialog.getExtra();
            String[] items = extra.getStringArray("items");
            String text = "onItemClick[position: " + position + ", item: " + items[position] + "]";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public ListAdapter getAdapter(DialogFragmentInterface dialog) {
            String[] items = new String[] { AlertDialog.class.getSimpleName(),
                    CharacterPickerDialog.class.getSimpleName(), ProgressDialog.class.getSimpleName(),
                    DatePickerDialog.class.getSimpleName(), TimePickerDialog.class.getSimpleName(), };
            Bundle extra = new Bundle();
            extra.putStringArray("items", items);
            dialog.setExtra(extra);
            return new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, items);
        }

        @Override
        public void onSingleChoiceClick(DialogFragmentInterface dialog, int position) {
            Bundle extra = dialog.getExtra();
            String[] items = extra.getStringArray("items");
            String text = "onItemClick[position: " + position + ", item: " + items[position] + "]";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onMultiChoiceClick(DialogFragmentInterface dialog, int position, boolean isChecked) {
            Bundle extra = dialog.getExtra();
            String[] items = extra.getStringArray("items");
            String text = "onItemClick[position: " + position + ", item: " + items[position] + ", isChecked: "
                    + isChecked + "]";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public View getCustomTitle(DialogFragmentInterface dialog) {
            TextView titleView = new TextView(getActivity());
            titleView.setText(dialog.getTag());
            titleView.setPadding(0, 24, 0, 24);
            titleView.setGravity(Gravity.CENTER);
            titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
            return titleView;
        }

        @Override
        public View getView(DialogFragmentInterface dialog) {
            ImageView imageView = new ImageView(getActivity());
            imageView.setImageResource(R.drawable.ic_launcher);
            imageView.setPadding(0, 24, 0, 24);
            return imageView;
        }
    };
}

From source file:com.nineducks.hereader.HackfulReaderActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog result = null;/*  w  ww  .ja  v a2s.c  o  m*/
    AlertDialog.Builder builder = null;
    switch (id) {
    case R.id.open_dialog:
        builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.open_dialog_title);
        builder.setItems(R.array.open_dialog_options, (OnClickListener) itemsController);
        builder.setCancelable(true);
        result = builder.create();
        break;
    case R.id.about_dialog:
        builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.about_dialog_title);
        ScrollView scroll = new ScrollView(this);
        TextView msg = new TextView(this);
        SpannableString s = new SpannableString(getString(R.string.about_dialog_text));
        Linkify.addLinks(s, Linkify.WEB_URLS);
        msg.setText(s);
        msg.setMovementMethod(LinkMovementMethod.getInstance());
        msg.setTextSize(16);
        msg.setPadding(15, 15, 15, 15);
        scroll.addView(msg);
        builder.setView(scroll);
        builder.setInverseBackgroundForced(true);
        result = builder.create();
        break;
    }
    return result;
}

From source file:com.zhongsou.souyue.ui.indicator.CheckTabPageIndicator.java

private void doSetTextStyle(TextView tv, int background) {
    tv.setGravity(Gravity.CENTER);/*from ww w.ja  v  a2 s  . c o m*/
    tv.setBackgroundResource(background);
    tv.setPadding(10, 12, 10, 12);
    tv.setTextSize(16);
    tv.setMaxLines(1);
    tv.setWidth(dip2px(this.getContext(), 110));
    tv.setTextColor(0xff696969);
}