protected internal override void onMeasure(int widthMeasureSpec, int heightMeasureSpec ) { base.onMeasure(widthMeasureSpec, heightMeasureSpec); android.text.Layout layout_1 = getLayout(); if (layout_1 != null) { int lineCount = layout_1.getLineCount(); if (lineCount > 0) { int ellipsisCount = layout_1.getEllipsisCount(lineCount - 1); if (ellipsisCount > 0) { setSingleLine(false); setMaxLines(2); android.content.res.TypedArray a = mContext.obtainStyledAttributes(null, android.R .styleable.TextAppearance, android.R.attr.textAppearanceMedium, android.R.style. TextAppearance_Medium); int textSize = a.getDimensionPixelSize(android.R.styleable.TextAppearance_textSize , 0); if (textSize != 0) { // textSize is already expressed in pixels setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, textSize); } a.recycle(); base.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } }
public static bool moveToRightEdge(android.text.Spannable text, android.text.Layout layout) { int where = findEdge(text, layout, 1); setSelection(text, where); return(true); }
protected internal override bool pageDown(android.widget.TextView widget, android.text.Spannable buffer) { android.text.Layout layout = widget.getLayout(); bool selecting = isSelecting(buffer); int targetY = getCurrentLineTop(buffer, layout) + getPageHeight(widget); bool handled = false; for (; ;) { int previousSelectionEnd = android.text.Selection.getSelectionEnd(buffer); if (selecting) { android.text.Selection.extendDown(buffer, layout); } else { android.text.Selection.moveDown(buffer, layout); } if (android.text.Selection.getSelectionEnd(buffer) == previousSelectionEnd) { break; } handled = true; if (getCurrentLineTop(buffer, layout) >= targetY) { break; } } return(handled); }
public static bool extendToLeftEdge(android.text.Spannable text, android.text.Layout layout) { int where = findEdge(text, layout, -1); extendSelection(text, where); return(true); }
/// <summary> /// Move the selection end to the buffer offset physically below /// the current selection end. /// </summary> /// <remarks> /// Move the selection end to the buffer offset physically below /// the current selection end. /// </remarks> public static bool extendDown(android.text.Spannable text, android.text.Layout layout ) { int end = getSelectionEnd(text); int line = layout.getLineForOffset(end); if (line < layout.getLineCount() - 1) { int move; if (layout.getParagraphDirection(line) == layout.getParagraphDirection(line + 1)) { float h = layout.getPrimaryHorizontal(end); move = layout.getOffsetForHorizontal(line + 1, h); } else { move = layout.getLineStart(line + 1); } extendSelection(text, move); return(true); } else { if (end != text.Length) { extendSelection(text, text.Length); return(true); } } return(true); }
private static int chooseHorizontal(android.text.Layout layout, int direction, int off1, int off2) { int line1 = layout.getLineForOffset(off1); int line2 = layout.getLineForOffset(off2); if (line1 == line2) { // same line, so it goes by pure physical direction float h1 = layout.getPrimaryHorizontal(off1); float h2 = layout.getPrimaryHorizontal(off2); if (direction < 0) { // to left if (h1 < h2) { return(off1); } else { return(off2); } } else { // to right if (h1 > h2) { return(off1); } else { return(off2); } } } else { // different line, so which line is "left" and which is "right" // depends upon the directionality of the text // This only checks at one end, but it's not clear what the // right thing to do is if the ends don't agree. Even if it // is wrong it should still not be too bad. int line = layout.getLineForOffset(off1); int textdir = layout.getParagraphDirection(line); if (textdir == direction) { return(System.Math.Max(off1, off2)); } else { return(System.Math.Min(off1, off2)); } } }
/// <summary>Performs a scroll to top action.</summary> /// <remarks> /// Performs a scroll to top action. /// Scrolls to the top of the document. /// </remarks> /// <param name="widget">The text view.</param> /// <param name="buffer">The text buffer.</param> /// <returns>True if the event was handled.</returns> /// <hide></hide> protected internal virtual bool scrollTop(android.widget.TextView widget, android.text.Spannable buffer) { android.text.Layout layout = widget.getLayout(); if (getTopLine(widget) >= 0) { android.text.method.Touch.scrollTo(widget, layout, widget.getScrollX(), layout.getLineTop (0)); return true; } return false; }
/// <summary> /// Scrolls the specified widget to the specified coordinates, except /// constrains the X scrolling position to the horizontal regions of /// the text that will be visible after scrolling to the specified /// Y position. /// </summary> /// <remarks> /// Scrolls the specified widget to the specified coordinates, except /// constrains the X scrolling position to the horizontal regions of /// the text that will be visible after scrolling to the specified /// Y position. /// </remarks> public static void scrollTo(android.widget.TextView widget, android.text.Layout layout , int x, int y) { int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom( ); int top = layout.getLineForVertical(y); int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding); int left = int.MaxValue; int right = 0; android.text.Layout.Alignment?a = layout.getParagraphAlignment(top); bool ltr = layout.getParagraphDirection(top) > 0; { for (int i = top; i <= bottom; i++) { left = (int)System.Math.Min(left, layout.getLineLeft(i)); right = (int)System.Math.Max(right, layout.getLineRight(i)); } } int hoizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight (); int availableWidth = widget.getWidth() - hoizontalPadding; int actualWidth = right - left; if (actualWidth < availableWidth) { if (a == android.text.Layout.Alignment.ALIGN_CENTER) { x = left - ((availableWidth - actualWidth) / 2); } else { if ((ltr && (a == android.text.Layout.Alignment.ALIGN_OPPOSITE)) || (a == android.text.Layout.Alignment .ALIGN_RIGHT)) { // align_opposite does NOT mean align_right, we need the paragraph // direction to resolve it to left or right x = left - (availableWidth - actualWidth); } else { x = left; } } } else { x = System.Math.Min(x, right - availableWidth); x = System.Math.Max(x, left); } widget.scrollTo(x, y); }
/// <summary> /// Move the selection end to the buffer offset physically to the right of /// the current selection end. /// </summary> /// <remarks> /// Move the selection end to the buffer offset physically to the right of /// the current selection end. /// </remarks> public static bool extendRight(android.text.Spannable text, android.text.Layout layout ) { int end = getSelectionEnd(text); int to = layout.getOffsetToRightOf(end); if (to != end) { extendSelection(text, to); return(true); } return(true); }
/// <summary>Performs a scroll to bottom action.</summary> /// <remarks> /// Performs a scroll to bottom action. /// Scrolls to the bottom of the document. /// </remarks> /// <param name="widget">The text view.</param> /// <param name="buffer">The text buffer.</param> /// <returns>True if the event was handled.</returns> /// <hide></hide> protected internal virtual bool scrollBottom(android.widget.TextView widget, android.text.Spannable buffer) { android.text.Layout layout = widget.getLayout(); int lineCount = layout.getLineCount(); if (getBottomLine(widget) <= lineCount - 1) { android.text.method.Touch.scrollTo(widget, layout, widget.getScrollX(), layout.getLineTop (lineCount) - getInnerHeight(widget)); return true; } return false; }
protected internal override bool up(android.widget.TextView widget, android.text.Spannable buffer) { android.text.Layout layout = widget.getLayout(); if (isSelecting(buffer)) { return(android.text.Selection.extendUp(buffer, layout)); } else { return(android.text.Selection.moveUp(buffer, layout)); } }
/// <summary>Performs a scroll page up action.</summary> /// <remarks> /// Performs a scroll page up action. /// Scrolls up by one page. /// </remarks> /// <param name="widget">The text view.</param> /// <param name="buffer">The text buffer.</param> /// <returns>True if the event was handled.</returns> /// <hide></hide> protected internal virtual bool scrollPageUp(android.widget.TextView widget, android.text.Spannable buffer) { android.text.Layout layout = widget.getLayout(); int top_1 = widget.getScrollY() - getInnerHeight(widget); int topLine = layout.getLineForVertical(top_1); if (topLine >= 0) { android.text.method.Touch.scrollTo(widget, layout, widget.getScrollX(), layout.getLineTop (topLine)); return true; } return false; }
private void scroll() { Layout layout = deviceMessagesTextView.Layout; if (layout != null) { int y = layout.getLineTop(deviceMessagesTextView.LineCount) - deviceMessagesTextView.Height; if (y > 0) { deviceMessagesTextView.scrollTo(0, y); deviceMessagesTextView.invalidate(); } } }
/// <summary>Performs a scroll page up action.</summary> /// <remarks> /// Performs a scroll page up action. /// Scrolls down by one page. /// </remarks> /// <param name="widget">The text view.</param> /// <param name="buffer">The text buffer.</param> /// <returns>True if the event was handled.</returns> /// <hide></hide> protected internal virtual bool scrollPageDown(android.widget.TextView widget, android.text.Spannable buffer) { android.text.Layout layout = widget.getLayout(); int innerHeight = getInnerHeight(widget); int bottom_1 = widget.getScrollY() + innerHeight + innerHeight; int bottomLine = layout.getLineForVertical(bottom_1); if (bottomLine <= layout.getLineCount() - 1) { android.text.method.Touch.scrollTo(widget, layout, widget.getScrollX(), layout.getLineTop (bottomLine + 1) - innerHeight); return true; } return false; }
private bool deleteLine(android.view.View view, android.text.Editable content) { if (view is android.widget.TextView) { android.text.Layout layout = ((android.widget.TextView)view).getLayout(); if (layout != null) { int line = layout.getLineForOffset(android.text.Selection.getSelectionStart(content )); int start = layout.getLineStart(line); int end = layout.getLineEnd(line); if (end != start) { content.delete(start, end); return(true); } } } return(false); }
/// <summary>Performs a scroll up action.</summary> /// <remarks> /// Performs a scroll up action. /// Scrolls up by the specified number of lines. /// </remarks> /// <param name="widget">The text view.</param> /// <param name="buffer">The text buffer.</param> /// <param name="amount">The number of lines to scroll by. Must be at least 1.</param> /// <returns>True if the event was handled.</returns> /// <hide></hide> protected internal virtual bool scrollUp(android.widget.TextView widget, android.text.Spannable buffer, int amount) { android.text.Layout layout = widget.getLayout(); int top_1 = widget.getScrollY(); int topLine = layout.getLineForVertical(top_1); if (layout.getLineTop(topLine) == top_1) { // If the top line is partially visible, bring it all the way // into view; otherwise, bring the previous line into view. topLine -= 1; } if (topLine >= 0) { topLine = System.Math.Max(topLine - amount + 1, 0); android.text.method.Touch.scrollTo(widget, layout, widget.getScrollX(), layout.getLineTop (topLine)); return true; } return false; }
private int getScrollBoundsLeft(android.widget.TextView widget) { android.text.Layout layout = widget.getLayout(); int topLine = getTopLine(widget); int bottomLine = getBottomLine(widget); if (topLine > bottomLine) { return 0; } int left_1 = int.MaxValue; { for (int line = topLine; line <= bottomLine; line++) { int lineLeft = (int)Sharpen.Util.Floor(layout.getLineLeft(line)); if (lineLeft < left_1) { left_1 = lineLeft; } } } return left_1; }
private int getScrollBoundsRight(android.widget.TextView widget) { android.text.Layout layout = widget.getLayout(); int topLine = getTopLine(widget); int bottomLine = getBottomLine(widget); if (topLine > bottomLine) { return 0; } int right_1 = int.MinValue; { for (int line = topLine; line <= bottomLine; line++) { int lineRight = (int)System.Math.Ceiling(layout.getLineRight(line)); if (lineRight > right_1) { right_1 = lineRight; } } } return right_1; }
/// <summary> /// Move the cursor to the buffer offset physically to the right of /// the current offset, or return false if the cursor is already at /// at the right edge of the line and there is not another line /// to move it to. /// </summary> /// <remarks> /// Move the cursor to the buffer offset physically to the right of /// the current offset, or return false if the cursor is already at /// at the right edge of the line and there is not another line /// to move it to. /// </remarks> public static bool moveRight(android.text.Spannable text, android.text.Layout layout ) { int start = getSelectionStart(text); int end = getSelectionEnd(text); if (start != end) { setSelection(text, chooseHorizontal(layout, 1, start, end)); return(true); } else { int to = layout.getOffsetToRightOf(end); if (to != end) { setSelection(text, to); return(true); } } return(false); }
protected internal override void onDraw(android.graphics.Canvas canvas) { base.onDraw(canvas); // Draw the switch int switchLeft = mSwitchLeft; int switchTop = mSwitchTop; int switchRight = mSwitchRight; int switchBottom = mSwitchBottom; mTrackDrawable.setBounds(switchLeft, switchTop, switchRight, switchBottom); mTrackDrawable.draw(canvas); canvas.save(); mTrackDrawable.getPadding(mTempRect); int switchInnerLeft = switchLeft + mTempRect.left; int switchInnerTop = switchTop + mTempRect.top; int switchInnerRight = switchRight - mTempRect.right; int switchInnerBottom = switchBottom - mTempRect.bottom; canvas.clipRect(switchInnerLeft, switchTop, switchInnerRight, switchBottom); mThumbDrawable.getPadding(mTempRect); int thumbPos = (int)(mThumbPosition + 0.5f); int thumbLeft = switchInnerLeft - mTempRect.left + thumbPos; int thumbRight = switchInnerLeft + thumbPos + mThumbWidth + mTempRect.right; mThumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom); mThumbDrawable.draw(canvas); // mTextColors should not be null, but just in case if (mTextColors != null) { mTextPaint.setColor(mTextColors.getColorForState(getDrawableState(), mTextColors. getDefaultColor())); } mTextPaint.drawableState = getDrawableState(); android.text.Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; canvas.translate((thumbLeft + thumbRight) / 2 - switchText.getWidth() / 2, (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2); switchText.draw(canvas); canvas.restore(); }
/// <summary> /// Move the cursor to the buffer offset physically below the current /// offset, or return false if the cursor is already on the bottom line. /// </summary> /// <remarks> /// Move the cursor to the buffer offset physically below the current /// offset, or return false if the cursor is already on the bottom line. /// </remarks> public static bool moveDown(android.text.Spannable text, android.text.Layout layout ) { int start = getSelectionStart(text); int end = getSelectionEnd(text); if (start != end) { int min = System.Math.Min(start, end); int max = System.Math.Max(start, end); setSelection(text, max); if (min == 0 && max == text.Length) { return(false); } return(true); } else { int line = layout.getLineForOffset(end); if (line < layout.getLineCount() - 1) { int move; if (layout.getParagraphDirection(line) == layout.getParagraphDirection(line + 1)) { float h = layout.getPrimaryHorizontal(end); move = layout.getOffsetForHorizontal(line + 1, h); } else { move = layout.getLineStart(line + 1); } setSelection(text, move); return(true); } } return(false); }
/// <summary>Performs a scroll down action.</summary> /// <remarks> /// Performs a scroll down action. /// Scrolls down by the specified number of lines. /// </remarks> /// <param name="widget">The text view.</param> /// <param name="buffer">The text buffer.</param> /// <param name="amount">The number of lines to scroll by. Must be at least 1.</param> /// <returns>True if the event was handled.</returns> /// <hide></hide> protected internal virtual bool scrollDown(android.widget.TextView widget, android.text.Spannable buffer, int amount) { android.text.Layout layout = widget.getLayout(); int innerHeight = getInnerHeight(widget); int bottom_1 = widget.getScrollY() + innerHeight; int bottomLine = layout.getLineForVertical(bottom_1); if (layout.getLineTop(bottomLine + 1) < bottom_1 + 1) { // Less than a pixel of this line is out of view, // so we must have tried to make it entirely in view // and now want the next line to be in view instead. bottomLine += 1; } int limit = layout.getLineCount() - 1; if (bottomLine <= limit) { bottomLine = System.Math.Min(bottomLine + amount - 1, limit); android.text.method.Touch.scrollTo(widget, layout, widget.getScrollX(), layout.getLineTop (bottomLine + 1) - innerHeight); return true; } return false; }
private static int findEdge(android.text.Spannable text, android.text.Layout layout , int dir) { int pt = getSelectionEnd(text); int line = layout.getLineForOffset(pt); int pdir = layout.getParagraphDirection(line); if (dir * pdir < 0) { return(layout.getLineStart(line)); } else { int end = layout.getLineEnd(line); if (line == layout.getLineCount() - 1) { return(end); } else { return(end - 1); } } }
protected internal override void onMeasure(int widthMeasureSpec, int heightMeasureSpec ) { int widthMode = android.view.View.MeasureSpec.getMode(widthMeasureSpec); int heightMode = android.view.View.MeasureSpec.getMode(heightMeasureSpec); int widthSize = android.view.View.MeasureSpec.getSize(widthMeasureSpec); int heightSize = android.view.View.MeasureSpec.getSize(heightMeasureSpec); if (mOnLayout == null) { mOnLayout = makeLayout(mTextOn); } if (mOffLayout == null) { mOffLayout = makeLayout(mTextOff); } mTrackDrawable.getPadding(mTempRect); int maxTextWidth = System.Math.Max(mOnLayout.getWidth(), mOffLayout.getWidth()); int switchWidth = System.Math.Max(mSwitchMinWidth, maxTextWidth * 2 + mThumbTextPadding * 4 + mTempRect.left + mTempRect.right); int switchHeight = mTrackDrawable.getIntrinsicHeight(); mThumbWidth = maxTextWidth + mThumbTextPadding * 2; switch (widthMode) { case android.view.View.MeasureSpec.AT_MOST: { widthSize = System.Math.Min(widthSize, switchWidth); break; } case android.view.View.MeasureSpec.UNSPECIFIED: { widthSize = switchWidth; break; } case android.view.View.MeasureSpec.EXACTLY: { // Just use what we were given break; } } switch (heightMode) { case android.view.View.MeasureSpec.AT_MOST: { heightSize = System.Math.Min(heightSize, switchHeight); break; } case android.view.View.MeasureSpec.UNSPECIFIED: { heightSize = switchHeight; break; } case android.view.View.MeasureSpec.EXACTLY: { // Just use what we were given break; } } mSwitchWidth = switchWidth; mSwitchHeight = switchHeight; base.onMeasure(widthMeasureSpec, heightMeasureSpec); int measuredHeight = getMeasuredHeight(); if (measuredHeight < switchHeight) { setMeasuredDimension(getMeasuredWidthAndState(), switchHeight); } }
private static int getCurrentLineTop(android.text.Spannable buffer, android.text.Layout layout) { return(layout.getLineTop(layout.getLineForOffset(android.text.Selection.getSelectionEnd (buffer)))); }
public void drawLeadingMargin(android.graphics.Canvas arg0, android.graphics.Paint arg1, int arg2, int arg3, int arg4, int arg5, int arg6, string arg7, int arg8, int arg9, bool arg10, android.text.Layout arg11) { drawLeadingMargin(arg0, arg1, arg2, arg3, arg4, arg5, arg6, (global::java.lang.CharSequence)(global::java.lang.String) arg7, arg8, arg9, arg10, arg11); }
public virtual void drawLeadingMargin(android.graphics.Canvas arg0, android.graphics.Paint arg1, int arg2, int arg3, int arg4, int arg5, int arg6, java.lang.CharSequence arg7, int arg8, int arg9, bool arg10, android.text.Layout arg11) { global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv; if (!IsClrObject) { @__env.CallVoidMethod(this.JvmHandle, global::android.text.style.QuoteSpan._drawLeadingMargin8310, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg3), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg4), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg5), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg6), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg7), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg8), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg9), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg10), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg11)); } else { @__env.CallNonVirtualVoidMethod(this.JvmHandle, global::android.text.style.QuoteSpan.staticClass, global::android.text.style.QuoteSpan._drawLeadingMargin8310, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg3), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg4), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg5), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg6), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg7), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg8), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg9), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg10), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg11)); } }
public virtual void drawLeadingMargin(android.graphics.Canvas c, android.graphics.Paint p, int x, int dir, int top, int baseline, int bottom, java.lang.CharSequence text , int start, int end, bool first, android.text.Layout layout) { throw new System.NotImplementedException(); }
public static bool extendUp(android.text.Spannable arg0, android.text.Layout arg1) { global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv; return(@__env.CallStaticBooleanMethod(android.text.Selection.staticClass, global::android.text.Selection._extendUp7790, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1))); }
public static void scrollTo(android.widget.TextView arg0, android.text.Layout arg1, int arg2, int arg3) { global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv; @__env.CallStaticVoidMethod(android.text.method.Touch.staticClass, global::android.text.method.Touch._scrollTo8195, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg3)); }