Example usage for android.widget TextView getPaddingRight

List of usage examples for android.widget TextView getPaddingRight

Introduction

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

Prototype

public int getPaddingRight() 

Source Link

Document

Returns the right padding of this view.

Usage

From source file:org.smssecure.smssecure.util.ViewUtil.java

public static CharSequence ellipsize(@Nullable CharSequence text, @NonNull TextView view) {
    if (TextUtils.isEmpty(text) || view.getWidth() == 0 || view.getEllipsize() != TruncateAt.END) {
        return text;
    } else {/*  ww  w. ja v a 2 s  . co  m*/
        return TextUtils.ellipsize(text, view.getPaint(),
                view.getWidth() - view.getPaddingRight() - view.getPaddingLeft(), TruncateAt.END);
    }
}

From source file:Main.java

private static void onCenterDraw(TextView view, Canvas canvas, Drawable drawable, int gravity) {
    int drawablePadding = view.getCompoundDrawablePadding();
    int ratio = 1;
    float total;/*  w  w w .  ja v a 2 s. com*/

    switch (gravity) {
    case Gravity.END:
        ratio = -1;
    case Gravity.START:
        total = view.getPaint().measureText(view.getText().toString()) + drawable.getIntrinsicWidth()
                + drawablePadding + view.getPaddingLeft() + view.getPaddingRight();
        canvas.translate(ratio * (view.getWidth() - total) / 2, 0);
        break;
    case Gravity.BOTTOM:
        ratio = -1;
    case Gravity.TOP:
        Paint.FontMetrics fontMetrics = view.getPaint().getFontMetrics();
        total = fontMetrics.descent - fontMetrics.ascent + drawable.getIntrinsicHeight() + drawablePadding
                + view.getPaddingTop() + view.getPaddingBottom();
        canvas.translate(0, ratio * (view.getHeight() - total) / 2);
        break;
    }
}

From source file:Main.java

private static void onCenterDraw(TextView view, Canvas canvas, Drawable drawable, int gravity) {
    int drawablePadding = view.getCompoundDrawablePadding();
    int ratio = 1;
    float total;/*w  w  w . j a va2  s .c  om*/

    switch (gravity) {
    case Gravity.RIGHT:
        ratio = -1;
    case Gravity.LEFT:
        total = view.getPaint().measureText(view.getText().toString()) + drawable.getIntrinsicWidth()
                + drawablePadding + view.getPaddingLeft() + view.getPaddingRight();
        canvas.translate(ratio * (view.getWidth() - total) / 2, 0);
        break;
    case Gravity.BOTTOM:
        ratio = -1;
    case Gravity.TOP:
        Paint.FontMetrics fontMetrics0 = view.getPaint().getFontMetrics();
        total = fontMetrics0.descent - fontMetrics0.ascent + drawable.getIntrinsicHeight() + drawablePadding
                + view.getPaddingTop() + view.getPaddingBottom();
        canvas.translate(0, ratio * (view.getHeight() - total) / 2);
        break;
    }
}

From source file:com.coreform.open.android.formidablevalidation.SetErrorHandler.java

private void chooseSize(PopupWindow pop, CharSequence text, TextView tv) {
    int wid = tv.getPaddingLeft() + tv.getPaddingRight();
    int ht = tv.getPaddingTop() + tv.getPaddingBottom();

    //com.android.internal.R.dimen.textview_error_popup_default_width introduced after Gingerbread, only has one variant (240dip)
    int defaultWidthInPixels = mContext.getResources()
            .getDimensionPixelSize(R.dimen.textview_error_popup_default_width);
    Layout l = new StaticLayout(text, tv.getPaint(), defaultWidthInPixels, Layout.Alignment.ALIGN_NORMAL, 1, 0,
            true);//w  w  w  . j a va  2 s.  c o m

    float max = 0;
    for (int i = 0; i < l.getLineCount(); i++) {
        max = Math.max(max, l.getLineWidth(i));
    }

    if (DEBUG)
        Log.d(TAG, "max: " + max + ", height: " + l.getHeight());

    /*
     * Now set the popup size to be big enough for the text plus the border.
     */
    pop.setWidth(wid + (int) Math.ceil(max));
    pop.setHeight(ht + l.getHeight()); //TODO: buggy (the 2 shouldnt need to be there)
}

From source file:com.conferenceengineer.android.iosched.ui.TracksAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (isAllTracksItem(position)) {
        if (convertView == null) {
            convertView = mActivity.getLayoutInflater().inflate(R.layout.list_item_track, parent, false);
        }// w w w.  j  ava  2s  . co  m

        // Custom binding for the first item
        ((TextView) convertView.findViewById(android.R.id.text1))
                .setText("(" + mActivity.getResources().getString(R.string.all_tracks) + ")");
        convertView.findViewById(android.R.id.icon1).setVisibility(View.INVISIBLE);

        return convertView;

    } else if (isLevel2Header(position)) {
        TextView view = (TextView) convertView;
        if (view == null) {
            view = (TextView) mActivity.getLayoutInflater().inflate(R.layout.list_item_track_header, parent,
                    false);
            if (mIsDropDown) {
                Rect r = new Rect(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(),
                        view.getPaddingBottom());
                view.setBackgroundResource(R.drawable.track_header_bottom_border);
                view.setPadding(r.left, r.top, r.right, r.bottom);
            }
        }
        view.setText(R.string.other_tracks);
        return view;
    }
    return super.getView(adapterPositionToCursorPosition(position), convertView, parent);
}

From source file:ecust.news.myWidgetTabPageIndicator.java

public void setCurrentItem(int position) {
    ///*from   w  w  w  .  jav  a  2s  .co m*/
    for (int i = 0; i < linearLayout.getChildCount(); i++) {
        TextView textView = (TextView) linearLayout.getChildAt(i);
        if (i != position) {
            textView.setTextColor(textViewUnfocusedColor);
            textView.setCompoundDrawables(null, null, null, null);
        } else {
            textView.setTextColor(textViewFocusedColor);

            //drawable
            textView.measure(0, 0);
            int w = textView.getMeasuredWidth() - textView.getPaddingLeft() - textView.getPaddingRight();
            int h = Global.dimenConvert.dip2px(dp_FocusedLineHeight);
            Drawable drawable = new ColorDrawable(Color.WHITE);
            drawable.setBounds(0, 0, w, h);
            textView.setCompoundDrawables(null, null, null, drawable);
        }

    }

    //?textView??
    int sum_width = 0;
    for (int i = 0; i < position; i++) {
        sum_width += linearLayout.getChildAt(i).getWidth();
    }

    //?
    sum_width -= this.getWidth() / 2 - linearLayout.getChildAt(position).getWidth() / 2;

    //
    this.smoothScrollTo(sum_width, 0);
}

From source file:com.munger.passwordkeeper.view.ViewDetailFragment.java

/**
 * Select the textView by changing the background
 * An interesting feature of android is changing the background on a textview will cause the padding to get reset.
 * @param v the view to be selected// www . j a v  a2s.  c o  m
 * @param selected are we selecting or deselecting the view?
 */
private void selectText(TextView v, boolean selected) {
    int left = v.getPaddingLeft();
    int right = v.getPaddingRight();
    int top = v.getPaddingTop();
    int bott = v.getPaddingBottom();

    int resid = 0;
    if (selected)
        resid = R.drawable.abc_list_selector_background_transition_holo_dark;

    v.setBackgroundResource(resid);
    v.setPadding(left, top, right, bott);
}

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

public void layoutImportantNotice(final View importantNoticeStrip, final String importantNoticeTitle) {
    final TextView titleView = (TextView) importantNoticeStrip.findViewById(R.id.important_notice_title);
    final int width = titleView.getWidth() - titleView.getPaddingLeft() - titleView.getPaddingRight();
    titleView.setTextColor(mColorAutoCorrect);
    titleView.setText(importantNoticeTitle);
    titleView.setTextScaleX(1.0f); // Reset textScaleX.
    final float titleScaleX = getTextScaleX(importantNoticeTitle, width, titleView.getPaint());
    titleView.setTextScaleX(titleScaleX);
}

From source file:com.github.vseguip.sweet.contacts.SweetConflictResolveActivity.java

/**
 * @param fieldTable//from w  ww  . j a v  a2 s .c om
 * @param nameOfField
 * @param field
 */
private void addConflictRow(TableLayout fieldTable, final String nameOfField, final String fieldLocal,
        final String fieldRemote) {
    if (mCurrentLocal == null || mCurrentSugar == null)
        return;
    // String fieldLocal = mCurrentLocal.get(nameOfField);
    // String fieldRemote = mCurrentSugar.get(nameOfField);
    TableRow row = new TableRow(this);
    final Spinner sourceSelect = new Spinner(this);
    sourceSelect.setBackgroundResource(R.drawable.black_underline);
    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, this.getResources().getStringArray(R.array.conflict_sources));
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sourceSelect.setAdapter(spinnerArrayAdapter);
    // Open the spinner when pressing any of the text fields
    OnClickListener spinnerOpener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            sourceSelect.performClick();
        }
    };
    row.addView(sourceSelect);
    fieldTable.addView(row);
    row = new TableRow(this);
    TextView fieldName = new TextView(this);
    int stringId = this.getResources().getIdentifier(nameOfField, "string", this.getPackageName());
    fieldName.setText(this.getString(stringId));
    fieldName.setTextSize(16);
    fieldName.setPadding(fieldName.getPaddingLeft(), fieldName.getPaddingTop(),
            fieldName.getPaddingRight() + 10, fieldName.getPaddingBottom());
    fieldName.setOnClickListener(spinnerOpener);
    row.addView(fieldName);
    final TextView fieldValueLocal = new TextView(this);
    fieldValueLocal.setText(fieldLocal);
    fieldValueLocal.setTextSize(16);
    row.addView(fieldValueLocal);
    fieldValueLocal.setOnClickListener(spinnerOpener);

    fieldTable.addView(row);
    row = new TableRow(this);
    row.addView(new TextView(this));// add dummy control
    final TextView fieldValueRemote = new TextView(this);
    fieldValueRemote.setText(fieldRemote);
    fieldValueRemote.setTextSize(16);

    fieldValueRemote.setOnClickListener(spinnerOpener);
    row.addView(fieldValueRemote);
    sourceSelect.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected);
                fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected);
                resolvedContacts[mPosResolved].set(nameOfField, fieldLocal);
            } else {
                fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected);
                fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected);
                resolvedContacts[mPosResolved].set(nameOfField, fieldRemote);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> view) {
        }
    });
    row.setPadding(row.getLeft(), row.getTop() + 5, row.getRight(), row.getBottom() + 10);
    // Restore appropiate selections according to resolved contact
    if (resolvedContacts[mPosResolved].get(nameOfField).equals(fieldLocal)) {
        sourceSelect.setSelection(0);
    } else {
        sourceSelect.setSelection(1);
    }
    fieldTable.addView(row);
}

From source file:dcheungaa.procal.MainActivity.java

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    TextView cursor = (TextView) MainActivity.views.get("cursor");
    TextView matrixDisplay = (TextView) MainActivity.views.get("matrixDisplay");
    super.onWindowFocusChanged(hasFocus);
    if (call_load) {
        call_load = false;//from  w ww  .  ja  v  a  2s  .c  o m
        fontWidth = cursor.getWidth();
        fontHeight = cursor.getHeight();
        cursor.setText(Character.toString((char) 0x258E));
        //cursor.setTop(matrixDisplay.getTop());
        cursor.setPadding(matrixDisplay.getPaddingLeft(), cursor.getPaddingTop(), cursor.getPaddingRight(),
                cursor.getPaddingBottom());
        cursor.setLeft(matrixDisplay.getLeft());
        //CursorHandler.hideCursor();
        RelativeLayout cm = (RelativeLayout) findViewById(R.id.content_main);
        LinearLayout rows = (LinearLayout) findViewById(R.id.llKeyPad);
        keyPad.KeyPad_resize(cm, rows);
        int fnBtnHeight = keyPad.btn_rows.get(0).get(0).get_mheight();
        System.out.print(Integer.toString(fnBtnHeight));
        varPad.resize(fnBtnHeight, fnBtnHeight * 3, svVar);
        cmdPad.resize(fnBtnHeight, fnBtnHeight * 3, svCmd);
        constPad.resize(fnBtnHeight, fnBtnHeight * 3, svConst);
    }
}