use of android.text.Layout.Alignment in project android_frameworks_base by DirtyUnicorns.
the class Touch method scrollTo.
/**
* 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.
*/
public static void scrollTo(TextView widget, Layout layout, int x, int y) {
final int horizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
final int availableWidth = widget.getWidth() - horizontalPadding;
final int top = layout.getLineForVertical(y);
Alignment a = layout.getParagraphAlignment(top);
boolean ltr = layout.getParagraphDirection(top) > 0;
int left, right;
if (widget.getHorizontallyScrolling()) {
final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding);
left = Integer.MAX_VALUE;
right = 0;
for (int i = top; i <= bottom; i++) {
left = (int) Math.min(left, layout.getLineLeft(i));
right = (int) Math.max(right, layout.getLineRight(i));
}
} else {
left = 0;
right = availableWidth;
}
final int actualWidth = right - left;
if (actualWidth < availableWidth) {
if (a == Alignment.ALIGN_CENTER) {
x = left - ((availableWidth - actualWidth) / 2);
} else if ((ltr && (a == Alignment.ALIGN_OPPOSITE)) || (!ltr && (a == Alignment.ALIGN_NORMAL)) || (a == 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 = Math.min(x, right - availableWidth);
x = Math.max(x, left);
}
widget.scrollTo(x, y);
}
use of android.text.Layout.Alignment in project android_frameworks_base by AOSPA.
the class Touch method scrollTo.
/**
* 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.
*/
public static void scrollTo(TextView widget, Layout layout, int x, int y) {
final int horizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
final int availableWidth = widget.getWidth() - horizontalPadding;
final int top = layout.getLineForVertical(y);
Alignment a = layout.getParagraphAlignment(top);
boolean ltr = layout.getParagraphDirection(top) > 0;
int left, right;
if (widget.getHorizontallyScrolling()) {
final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding);
left = Integer.MAX_VALUE;
right = 0;
for (int i = top; i <= bottom; i++) {
left = (int) Math.min(left, layout.getLineLeft(i));
right = (int) Math.max(right, layout.getLineRight(i));
}
} else {
left = 0;
right = availableWidth;
}
final int actualWidth = right - left;
if (actualWidth < availableWidth) {
if (a == Alignment.ALIGN_CENTER) {
x = left - ((availableWidth - actualWidth) / 2);
} else if ((ltr && (a == Alignment.ALIGN_OPPOSITE)) || (!ltr && (a == Alignment.ALIGN_NORMAL)) || (a == 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 = Math.min(x, right - availableWidth);
x = Math.max(x, left);
}
widget.scrollTo(x, y);
}
use of android.text.Layout.Alignment in project XobotOS by xamarin.
the class Touch method scrollTo.
/**
* 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.
*/
public static void scrollTo(TextView widget, Layout layout, int x, int y) {
final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
final int top = layout.getLineForVertical(y);
final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding);
int left = Integer.MAX_VALUE;
int right = 0;
Alignment a = layout.getParagraphAlignment(top);
boolean ltr = layout.getParagraphDirection(top) > 0;
for (int i = top; i <= bottom; i++) {
left = (int) Math.min(left, layout.getLineLeft(i));
right = (int) Math.max(right, layout.getLineRight(i));
}
final int hoizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
final int availableWidth = widget.getWidth() - hoizontalPadding;
final int actualWidth = right - left;
if (actualWidth < availableWidth) {
if (a == Alignment.ALIGN_CENTER) {
x = left - ((availableWidth - actualWidth) / 2);
} else if ((ltr && (a == Alignment.ALIGN_OPPOSITE)) || (a == 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 = Math.min(x, right - availableWidth);
x = Math.max(x, left);
}
widget.scrollTo(x, y);
}
Aggregations