Example usage for android.widget TextView getPaddingBottom

List of usage examples for android.widget TextView getPaddingBottom

Introduction

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

Prototype

public int getPaddingBottom() 

Source Link

Document

Returns the bottom padding of this view.

Usage

From source file:com.agenthun.readingroutine.utils.ViewUtils.java

public static void setPaddingStart(TextView target, int paddingStart) {
    ViewCompat.setPaddingRelative(target, paddingStart, target.getPaddingTop(),
            ViewCompat.getPaddingEnd(target), target.getPaddingBottom());
}

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;//from w  w  w  .j  a v  a2s .  co m

    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;/*www.  j  a v  a  2s.  c  o m*/

    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);/*from   w w  w.  j a v  a 2s  . 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.ja  va 2 s.c  o  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: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/*from   w  w  w . 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.github.vseguip.sweet.contacts.SweetConflictResolveActivity.java

/**
 * @param fieldTable//from  w  ww  .  j a v a  2 s  . co m
 * @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;//  w ww  .ja  v a2 s .com
        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);
    }
}

From source file:com.example.gaurav.calculator.Calculator.java

@Override
public void onTextSizeChanged(final TextView textView, float oldSize) {
    if (mCurrentState != CalculatorState.INPUT) {
        // Only animate text changes that occur from user input.
        return;//  w w  w  .  j  a va2s. c o  m
    }

    // Calculate the values needed to perform the scale and translation animations,
    // maintaining the same apparent baseline for the displayed text.
    final float textScale = oldSize / textView.getTextSize();
    final float translationX = (1.0f - textScale)
            * (textView.getWidth() / 2.0f - ViewCompat.getPaddingEnd(textView));
    final float translationY = (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(textView, "scaleX", textScale, 1.0f),
            ObjectAnimator.ofFloat(textView, "scaleY", textScale, 1.0f),
            ObjectAnimator.ofFloat(textView, "translationX", translationX, 0.0f),
            ObjectAnimator.ofFloat(textView, "translationY", translationY, 0.0f));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.start();
}

From source file:com.hamzahrmalik.calculator2.Calculator.java

@Override
public void onTextSizeChanged(final TextView textView, float oldSize) {
    if (mCurrentState != CalculatorState.INPUT) {
        // Only animate text changes that occur from user input.
        return;/*  w  w  w.j  av a 2s  .c om*/
    }

    // Calculate the values needed to perform the scale and translation
    // animations,
    // maintaining the same apparent baseline for the displayed text.
    final float textScale = oldSize / textView.getTextSize();
    final float translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingEnd());
    final float translationY = (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(textView, View.SCALE_X, textScale, 1.0f),
            ObjectAnimator.ofFloat(textView, View.SCALE_Y, textScale, 1.0f),
            ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, translationX, 0.0f),
            ObjectAnimator.ofFloat(textView, View.TRANSLATION_Y, translationY, 0.0f));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.start();
}