summaryrefslogtreecommitdiff
path: root/core/java/android/view/Gravity.java
diff options
context:
space:
mode:
authorQing Xia <xiaqing@google.com>2017-11-16 10:12:53 -0800
committerQing Xia <xiaqing@google.com>2017-11-16 18:26:55 +0000
commited800704525971755471ba5c17faaf42dcd8395d (patch)
tree2608bc34fcc1fde12f8f02a885e99080f45cc311 /core/java/android/view/Gravity.java
parent62462871b50480acc19ada846787ec7c3ee462bb (diff)
Fix Gravity toString wrong message issue
1. Bit calculation was not correct before as there are multiple bits that can be set. 2. Changed a duplicate CLIP message as well. 3. And add an empty check. Test: In 'dumpsys window' the gravity of the window should be correct. Change-Id: I4b699e5d6d5d7c2beb8ac12cbd78cf2f81e70b3f
Diffstat (limited to 'core/java/android/view/Gravity.java')
-rw-r--r--core/java/android/view/Gravity.java33
1 files changed, 18 insertions, 15 deletions
diff --git a/core/java/android/view/Gravity.java b/core/java/android/view/Gravity.java
index 232ff2551433..defa58e10e6e 100644
--- a/core/java/android/view/Gravity.java
+++ b/core/java/android/view/Gravity.java
@@ -446,50 +446,53 @@ public class Gravity
*/
public static String toString(int gravity) {
final StringBuilder result = new StringBuilder();
- if ((gravity & FILL) != 0) {
+ if ((gravity & FILL) == FILL) {
result.append("FILL").append(' ');
} else {
- if ((gravity & FILL_VERTICAL) != 0) {
+ if ((gravity & FILL_VERTICAL) == FILL_VERTICAL) {
result.append("FILL_VERTICAL").append(' ');
} else {
- if ((gravity & TOP) != 0) {
+ if ((gravity & TOP) == TOP) {
result.append("TOP").append(' ');
}
- if ((gravity & BOTTOM) != 0) {
+ if ((gravity & BOTTOM) == BOTTOM) {
result.append("BOTTOM").append(' ');
}
}
- if ((gravity & FILL_HORIZONTAL) != 0) {
+ if ((gravity & FILL_HORIZONTAL) == FILL_HORIZONTAL) {
result.append("FILL_HORIZONTAL").append(' ');
} else {
- if ((gravity & START) != 0) {
+ if ((gravity & START) == START) {
result.append("START").append(' ');
- } else if ((gravity & LEFT) != 0) {
+ } else if ((gravity & LEFT) == LEFT) {
result.append("LEFT").append(' ');
}
- if ((gravity & END) != 0) {
+ if ((gravity & END) == END) {
result.append("END").append(' ');
- } else if ((gravity & RIGHT) != 0) {
+ } else if ((gravity & RIGHT) == RIGHT) {
result.append("RIGHT").append(' ');
}
}
}
- if ((gravity & CENTER) != 0) {
+ if ((gravity & CENTER) == CENTER) {
result.append("CENTER").append(' ');
} else {
- if ((gravity & CENTER_VERTICAL) != 0) {
+ if ((gravity & CENTER_VERTICAL) == CENTER_VERTICAL) {
result.append("CENTER_VERTICAL").append(' ');
}
- if ((gravity & CENTER_HORIZONTAL) != 0) {
+ if ((gravity & CENTER_HORIZONTAL) == CENTER_HORIZONTAL) {
result.append("CENTER_HORIZONTAL").append(' ');
}
}
- if ((gravity & DISPLAY_CLIP_VERTICAL) != 0) {
- result.append("DISPLAY_CLIP_VERTICAL").append(' ');
+ if (result.length() == 0) {
+ result.append("NO GRAVITY").append(' ');
}
- if ((gravity & DISPLAY_CLIP_VERTICAL) != 0) {
+ if ((gravity & DISPLAY_CLIP_VERTICAL) == DISPLAY_CLIP_VERTICAL) {
result.append("DISPLAY_CLIP_VERTICAL").append(' ');
}
+ if ((gravity & DISPLAY_CLIP_HORIZONTAL) == DISPLAY_CLIP_HORIZONTAL) {
+ result.append("DISPLAY_CLIP_HORIZONTAL").append(' ');
+ }
result.deleteCharAt(result.length() - 1);
return result.toString();
}