List of usage examples for android.widget TextView getPaddingLeft
public int getPaddingLeft()
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 www . j a va 2 s.c o 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;/*from w w w . j av a2 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: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 {//from ww w.j av a 2 s.c o m return TextUtils.ellipsize(text, view.getPaint(), view.getWidth() - view.getPaddingRight() - view.getPaddingLeft(), TruncateAt.END); } }
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 . jav a 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 .jav a 2 s . c om*/ // 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:angeloid.dreamnarae.SwipeyTabs.java
/** * Calculate the position of the tabs.//from w ww . j a va 2 s . co m * * @param position * the position of the fronted tab * @param tabPositions * the array in which to store the result */ private void calculateTabPosition(int position, int[] tabPositions) { if (mAdapter == null) { return; } final int count = mAdapter.getCount(); if (position >= 0 && position < count) { final int width = getMeasuredWidth(); final View centerTab = getChildAt(position); tabPositions[position] = width / 2 - centerTab.getMeasuredWidth() / 2; for (int i = position - 1; i >= 0; i--) { final TextView tab = (TextView) getChildAt(i); if (i == position - 1) { tabPositions[i] = 0 - tab.getPaddingLeft(); } else { tabPositions[i] = 0 - tab.getMeasuredWidth() - width; } tabPositions[i] = Math.min(tabPositions[i], tabPositions[i + 1] - tab.getMeasuredWidth()); } for (int i = position + 1; i < count; i++) { final TextView tab = (TextView) getChildAt(i); if (i == position + 1) { tabPositions[i] = width - tab.getMeasuredWidth() + tab.getPaddingRight(); } else { tabPositions[i] = width * 2; } final TextView prevTab = (TextView) getChildAt(i - 1); tabPositions[i] = Math.max(tabPositions[i], tabPositions[i - 1] + prevTab.getMeasuredWidth()); } } else { for (int i = 0; i < tabPositions.length; i++) { tabPositions[i] = -1; } } }
From source file:com.ezmeal.swipeytabs.SwipeyTabs.java
/** * Calculate the position of the tabs.//from ww w.j a va 2 s . c o m * * @param position * the position of the fronted tab * @param tabPositions * the array in which to store the result */ private void calculateTabPosition(int position, int[] tabPositions) { if (mAdapter == null) { return; } final int count = mAdapter.getCount(); if (position >= 0 && position < count) { final int width = getMeasuredWidth(); final View centerTab = getChildAt(position); tabPositions[position] = width / 2 - centerTab.getMeasuredWidth() / 2; for (int i = position - 1; i >= 0; i--) { final TextView tab = (TextView) getChildAt(i); if (i == position - 1) { tabPositions[i] = 5 - tab.getPaddingLeft(); } else if (i != 0 && i != count - 1) { tabPositions[i] = 0 - tab.getMeasuredWidth() - width; } tabPositions[i] = Math.min(tabPositions[i], tabPositions[i + 1] - tab.getMeasuredWidth()); } for (int i = position + 1; i < count; i++) { final TextView tab = (TextView) getChildAt(i); if (i == position + 1) { tabPositions[i] = width - tab.getMeasuredWidth() + tab.getPaddingRight() - 5; } else if (i != 0 && i != count - 1) { tabPositions[i] = width * 2; } final TextView prevTab = (TextView) getChildAt(i - 1); tabPositions[i] = Math.max(tabPositions[i], tabPositions[i - 1] + prevTab.getMeasuredWidth()); } /* // make it a circle! if (position == 0) { final TextView tab = (TextView) getChildAt(count - 1); tabPositions[count - 1] = 5 - tab.getPaddingLeft(); } if (position == count - 1) { final TextView tab = (TextView) getChildAt(0); tabPositions[0] = width - tab.getMeasuredWidth() + tab.getPaddingRight() - 5; } */ } else { for (int i = 0; i < tabPositions.length; i++) { tabPositions[i] = -1; } } }
From source file:ecust.news.myWidgetTabPageIndicator.java
public void setCurrentItem(int position) { ////w ww . j a v a 2 s .c o 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// w w w . j a v a2s . c om * @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: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 w w .j av a 2 s . 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); } }