Beispiel #1
0
		/// <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);
		}
Beispiel #2
0
		/// <summary>Performs a scroll to line end action.</summary>
		/// <remarks>
		/// Performs a scroll to line end action.
		/// Scrolls to the end of the line.
		/// </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 scrollLineEnd(android.widget.TextView widget, android.text.Spannable
			 buffer)
		{
			int maxScrollX = getScrollBoundsRight(widget) - getInnerWidth(widget);
			int scrollX = widget.getScrollX();
			if (scrollX < maxScrollX)
			{
				widget.scrollTo(maxScrollX, widget.getScrollY());
				return true;
			}
			return false;
		}
Beispiel #3
0
		/// <summary>Performs a scroll right action.</summary>
		/// <remarks>
		/// Performs a scroll right action.
		/// Scrolls right by the specified number of characters.
		/// </remarks>
		/// <param name="widget">The text view.</param>
		/// <param name="buffer">The text buffer.</param>
		/// <param name="amount">The number of characters to scroll by.  Must be at least 1.</param>
		/// <returns>True if the event was handled.</returns>
		/// <hide></hide>
		protected internal virtual bool scrollRight(android.widget.TextView widget, android.text.Spannable
			 buffer, int amount)
		{
			int maxScrollX = getScrollBoundsRight(widget) - getInnerWidth(widget);
			int scrollX = widget.getScrollX();
			if (scrollX < maxScrollX)
			{
				scrollX = System.Math.Min(scrollX + getCharacterWidth(widget) * amount, maxScrollX
					);
				widget.scrollTo(scrollX, widget.getScrollY());
				return true;
			}
			return false;
		}
Beispiel #4
0
		/// <summary>Performs a scroll to line start action.</summary>
		/// <remarks>
		/// Performs a scroll to line start action.
		/// Scrolls to the start of the line.
		/// </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 scrollLineStart(android.widget.TextView widget, android.text.Spannable
			 buffer)
		{
			int minScrollX = getScrollBoundsLeft(widget);
			int scrollX = widget.getScrollX();
			if (scrollX > minScrollX)
			{
				widget.scrollTo(minScrollX, widget.getScrollY());
				return true;
			}
			return false;
		}
Beispiel #5
0
		/// <summary>Performs a scroll left action.</summary>
		/// <remarks>
		/// Performs a scroll left action.
		/// Scrolls left by the specified number of characters.
		/// </remarks>
		/// <param name="widget">The text view.</param>
		/// <param name="buffer">The text buffer.</param>
		/// <param name="amount">The number of characters to scroll by.  Must be at least 1.</param>
		/// <returns>True if the event was handled.</returns>
		/// <hide></hide>
		protected internal virtual bool scrollLeft(android.widget.TextView widget, android.text.Spannable
			 buffer, int amount)
		{
			int minScrollX = getScrollBoundsLeft(widget);
			int scrollX = widget.getScrollX();
			if (scrollX > minScrollX)
			{
				scrollX = System.Math.Max(scrollX - getCharacterWidth(widget) * amount, minScrollX
					);
				widget.scrollTo(scrollX, widget.getScrollY());
				return true;
			}
			return false;
		}