aboutsummaryrefslogtreecommitdiffstats
path: root/common/src
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-10-15 13:03:40 -0700
committerTor Norbye <tnorbye@google.com>2012-10-15 17:46:37 -0700
commita1e7aa7cc973adaba4f31673c897724eb8d9f399 (patch)
treea882deff58ea4fd638421369053660fbc8d21d44 /common/src
parent1e6c45d826478a9621f433c28cce38786b890f52 (diff)
downloadsdk-a1e7aa7cc973adaba4f31673c897724eb8d9f399.zip
sdk-a1e7aa7cc973adaba4f31673c897724eb8d9f399.tar.gz
sdk-a1e7aa7cc973adaba4f31673c897724eb8d9f399.tar.bz2
Misc improvements to the multi-configuration editing
* Fix bug in switching to preview configurations * Don't draw drop shadows for thumbnails in Dialog themes * Move the preview title labels to sit above each preview thumbnail * Make error thumbnails include rendering error messages (and wrap if necessary), plus tweak appearance * Make switch animation show rectangles animating in both directions Change-Id: I0995617fa277b48419a88c5203abf5b1d49af711
Diffstat (limited to 'common/src')
-rw-r--r--common/src/com/android/utils/SdkUtils.java71
1 files changed, 70 insertions, 1 deletions
diff --git a/common/src/com/android/utils/SdkUtils.java b/common/src/com/android/utils/SdkUtils.java
index 18d3ccd..160f95d 100644
--- a/common/src/com/android/utils/SdkUtils.java
+++ b/common/src/com/android/utils/SdkUtils.java
@@ -17,7 +17,9 @@
package com.android.utils;
import com.android.annotations.NonNull;
+import com.android.annotations.Nullable;
+/** Miscellaneous utilities used by the Android SDK tools */
public class SdkUtils {
/**
* Returns true if the given string ends with the given suffix, using a
@@ -111,7 +113,12 @@ public class SdkUtils {
return sb.toString();
}
- /** Returns true if the given string has an upper case character. */
+ /**
+ * Returns true if the given string has an upper case character.
+ *
+ * @param s the string to check
+ * @return true if it contains uppercase characters
+ */
public static boolean hasUpperCaseCharacter(String s) {
for (int i = 0; i < s.length(); i++) {
if (Character.isUpperCase(s.charAt(i))) {
@@ -144,4 +151,66 @@ public class SdkUtils {
return sLineSeparator;
}
+
+ /**
+ * Wraps the given text at the given line width, with an optional hanging
+ * indent.
+ *
+ * @param text the text to be wrapped
+ * @param lineWidth the number of characters to wrap the text to
+ * @param hangingIndent the hanging indent (to be used for the second and
+ * subsequent lines in each paragraph, or null if not known
+ * @return the string, wrapped
+ */
+ @NonNull
+ public static String wrap(
+ @NonNull String text,
+ int lineWidth,
+ @Nullable String hangingIndent) {
+ if (hangingIndent == null) {
+ hangingIndent = "";
+ }
+ int explanationLength = text.length();
+ StringBuilder sb = new StringBuilder(explanationLength * 2);
+ int index = 0;
+
+ while (index < explanationLength) {
+ int lineEnd = text.indexOf('\n', index);
+ int next;
+
+ if (lineEnd != -1 && (lineEnd - index) < lineWidth) {
+ next = lineEnd + 1;
+ } else {
+ // Line is longer than available width; grab as much as we can
+ lineEnd = Math.min(index + lineWidth, explanationLength);
+ if (lineEnd - index < lineWidth) {
+ next = explanationLength;
+ } else {
+ // then back up to the last space
+ int lastSpace = text.lastIndexOf(' ', lineEnd);
+ if (lastSpace > index) {
+ lineEnd = lastSpace;
+ next = lastSpace + 1;
+ } else {
+ // No space anywhere on the line: it contains something wider than
+ // can fit (like a long URL) so just hard break it
+ next = lineEnd + 1;
+ }
+ }
+ }
+
+ if (sb.length() > 0) {
+ sb.append(hangingIndent);
+ } else {
+ lineWidth -= hangingIndent.length();
+ }
+
+ sb.append(text.substring(index, lineEnd));
+ sb.append('\n');
+ index = next;
+ }
+
+ return sb.toString();
+ }
+
}