Java Code Examples for android.widget.TextView#getLineCount()
The following examples show how to use
android.widget.TextView#getLineCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewSwitcherWrapper.java From Android-Notification with Apache License 2.0 | 6 votes |
private void adjustTextViewHeight() { View view = getView(); if (view == null) { return; } TextSwitcher textSwitcher = (TextSwitcher) view; TextView curr = (TextView) textSwitcher.getCurrentView(); TextView next = (TextView) textSwitcher.getNextView(); int currH = curr.getLineCount() * curr.getLineHeight(); int nextH = next.getLineCount() * next.getLineHeight(); if (currH != nextH) { curr.setHeight(currH); next.setHeight(currH); } }
Example 2
Source File: OverlayServiceCommon.java From heads-up with GNU General Public License v3.0 | 6 votes |
private boolean expand() { if (!isCompact) return false; else { TextView subtitle = (TextView) layout.findViewById(R.id.notification_subtitle); if ( (subtitle.getLineCount() <= MIN_LINES && subtitle.length() < 80) && !isActionButtons) { return false; } isCompact = false; subtitle.setMaxLines(MAX_LINES); if (isActionButtons) themeClass.showActionButtons(layout, -1); if (displayTime < MAX_DISPLAY_TIME) { handler.removeCallbacks(closeTimer); handler.postDelayed(closeTimer, displayTime); } return true; } }
Example 3
Source File: LineUtils.java From CodeEditor with Apache License 2.0 | 5 votes |
public int getTopVisibleLine(TextView editor) { int lineHeight = editor.getLineHeight(); if (lineHeight == 0) { return 0; } int line = editor.getScrollY() / lineHeight; if (line < 0) { return 0; } if (line >= editor.getLineCount()) { return editor.getLineCount() - 1; } return line; }
Example 4
Source File: LineUtils.java From CodeEditor with Apache License 2.0 | 5 votes |
public int getBottomVisibleLine(TextView editor) { int lineHeight = editor.getLineHeight(); if (lineHeight == 0) { return 0; } int line = Math.abs((editor.getScrollY() + editor.getHeight()) / lineHeight) + 1; if (line < 0) { return 0; } if (line >= editor.getLineCount()) { return editor.getLineCount() - 1; } return line; }
Example 5
Source File: PushListAdapter.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void configureViewForPosition(View itemView, int position) { TextView dateText = (TextView) itemView.findViewById(R.id.push_date); TextView titleText = (TextView) itemView.findViewById(R.id.push_title); TextView descriptionText = (TextView) itemView.findViewById(R.id.push_description); ImageView iconImage = (ImageView) itemView.findViewById(R.id.push_icon_image); String title = entries.get(position).getTitle(); if (title.equals("")) title = entries.get(position).getService().getName(); String description = entries.get(position).getMessage(); Date pushDate = entries.get(position).getLocalTimestamp(); Bitmap icon = entries.get(position).getService().getIconBitmapOrDefault(context); dateText.setText(this.dateFormat.format(pushDate)); titleText.setText(title); descriptionText.setText(description); iconImage.setImageBitmap(icon); TypedValue value = new TypedValue(); DisplayMetrics metrics = new DisplayMetrics(); context.getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, value, true); ((WindowManager) (context.getSystemService(Context.WINDOW_SERVICE))).getDefaultDisplay().getMetrics(metrics); int lineCount = selectedIndex == position ? descriptionText.getLineCount() : 0; int minHeight = (int) TypedValue.complexToDimension(value.data, metrics); int prefHeight = (lineCount + 2) * descriptionText.getLineHeight(); itemView.getLayoutParams().height = prefHeight > minHeight ? prefHeight : minHeight; }
Example 6
Source File: AligningTextView.java From YCCustomText with Apache License 2.0 | 5 votes |
/** * 获取文本实际所占高度,辅助用于计算行高,行数 * * @param text 文本 * @param textSize 字体大小 * @param deviceWidth 屏幕宽度 */ private void measureTextViewHeight(String text, float textSize, int deviceWidth) { TextView textView = new TextView(getContext()); textView.setText(text); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); int widthMeasureSpec = MeasureSpec.makeMeasureSpec(deviceWidth, MeasureSpec.EXACTLY); int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); textView.measure(widthMeasureSpec, heightMeasureSpec); originalLineCount = textView.getLineCount(); originalHeight = textView.getMeasuredHeight(); }
Example 7
Source File: CharacteristicOperationFragment.java From FastBle with Apache License 2.0 | 5 votes |
private void addText(TextView textView, String content) { textView.append(content); textView.append("\n"); int offset = textView.getLineCount() * textView.getLineHeight(); if (offset > textView.getHeight()) { textView.scrollTo(0, offset - textView.getHeight()); } }
Example 8
Source File: UIUtils.java From Kore with Apache License 2.0 | 5 votes |
/** * Returns a {@link Runnable} that sets up toggleable scrolling behavior on a {@link TextView} * if the number of lines to be displayed exceeds the maximum lines limit supported by the TextView. * Can be applied by using {@link View#post(Runnable)}. * * @param textView TextView that the Runnable should apply against * @return Runnable */ public static Runnable getMarqueeToggleableAction(final TextView textView) { return new Runnable() { @Override public void run() { int lines = textView.getLineCount(); int maxLines = TextViewCompat.getMaxLines(textView); if (lines > maxLines) { textView.setEllipsize(TextUtils.TruncateAt.END); textView.setClickable(true); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { v.setSelected(!v.isSelected()); TextUtils.TruncateAt ellipsize; if (v.isSelected()) { ellipsize = TextUtils.TruncateAt.MARQUEE; } else { ellipsize = TextUtils.TruncateAt.END; } textView.setEllipsize(ellipsize); textView.setHorizontallyScrolling(v.isSelected()); } }); } } }; }
Example 9
Source File: AlignTextView.java From AlignTextView with Apache License 2.0 | 5 votes |
/** * 获取文本实际所占高度,辅助用于计算行高,行数 * * @param text 文本 * @param textSize 字体大小 * @param deviceWidth 屏幕宽度 */ private void measureTextViewHeight(String text, float textSize, int deviceWidth) { TextView textView = new TextView(getContext()); textView.setText(text); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); int widthMeasureSpec = MeasureSpec.makeMeasureSpec(deviceWidth, MeasureSpec.EXACTLY); int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); textView.measure(widthMeasureSpec, heightMeasureSpec); originalLineCount = textView.getLineCount(); originalHeight = textView.getMeasuredHeight(); }
Example 10
Source File: VerticalMarqueeTextView.java From Android-Lib-VerticalMarqueeTextView with Apache License 2.0 | 2 votes |
/** * Returns the standard height (i.e. without text effects such as shadow) of all the text of * the given {@link TextView}. * @param textView The {@link TextView} to determine the height of all its text content. * @return The standard height of all the text content of the given {@link TextView}. */ private int heightOf(final TextView textView) { return textView.getLineCount() > 0 ? textView.getLineHeight() * textView.getLineCount() : 0; }