-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix orientation change bug that causes stat bar and nav bar height to wrong values * removed comment
- Loading branch information
Showing
5 changed files
with
194 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.percy.appium.lib; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import io.percy.appium.AppPercy; | ||
|
||
public class Utils { | ||
public static Integer extractStatusBarHeight(String input) { | ||
try { | ||
Pattern pattern = Pattern.compile("ITYPE_STATUS_BAR frame=\\[\\d+,\\d+\\]\\[\\d+,([\\d]+)\\]"); | ||
Matcher matcher = pattern.matcher(input); | ||
if (matcher.find()) { | ||
return Integer.parseInt(matcher.group(1)); | ||
} | ||
return null; // Return null if no match found | ||
} catch (Exception ex) { | ||
AppPercy.log(ex.toString(), "debug"); | ||
return null; // Return null if any error | ||
} | ||
} | ||
|
||
public static Integer extractNavigationBarHeight(String input) { | ||
try { | ||
Pattern pattern = Pattern.compile("ITYPE_NAVIGATION_BAR frame=\\[\\d+,([\\d]+)\\]\\[\\d+,([\\d]+)\\]"); | ||
Matcher matcher = pattern.matcher(input); | ||
|
||
if (matcher.find()) { | ||
int bottomCoordinate = Integer.parseInt(matcher.group(1)); | ||
int topCoordinate = Integer.parseInt(matcher.group(2)); | ||
return topCoordinate - bottomCoordinate; | ||
} | ||
return null; // Return null if no match found | ||
} catch (Exception ex) { | ||
AppPercy.log(ex.toString(), "debug"); | ||
return null; // Return null if any error | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.percy.appium.lib; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
public class UtilsTest { | ||
@Test | ||
public void testExtractStatusBarHeighWhenPatternIsPresent() { | ||
String input = "InsetsSource type=ITYPE_STATUS_BAR frame=[0,0][2400,74] visible=true\n" + | ||
"InsetsSource type=ITYPE_NAVIGATION_BAR frame=[0,2358][1080,2400] visible=true"; | ||
|
||
int expectedStatBarHeight = 74; | ||
int actualStatBarHeight = Utils.extractStatusBarHeight(input); | ||
|
||
assertEquals(expectedStatBarHeight, actualStatBarHeight); | ||
} | ||
|
||
@Test | ||
public void testExtractNavigationBarHeightWhenPatternIsPresent() { | ||
String input = "InsetsSource type=ITYPE_STATUS_BAR frame=[0,0][2400,74] visible=true\n" + | ||
"InsetsSource type=ITYPE_NAVIGATION_BAR frame=[0,2358][1080,2400] visible=true"; | ||
|
||
int expectedNavBarHeight = 42; | ||
int actualNavBarHeight = Utils.extractNavigationBarHeight(input); | ||
|
||
assertEquals(expectedNavBarHeight, actualNavBarHeight); | ||
} | ||
|
||
@Test | ||
public void testExtractStatusBarHeighWhenPatternIsNotPresent() { | ||
String input = "RANDOM frame=[0,0][2400,74] visible=true\n" + | ||
"RANDOM frame=[0,2358][1080,2400] visible=true"; | ||
|
||
Integer actualStatBarHeight = Utils.extractStatusBarHeight(input); | ||
|
||
assertEquals(null, actualStatBarHeight); | ||
} | ||
|
||
@Test | ||
public void testExtractNavigationBarHeightWhenPatternIsNotPresent() { | ||
String input = "RANDOM [0,0][2400,74] visible=true\n" + | ||
"RANDOM [0,2358][1080,2400] visible=true"; | ||
|
||
Integer actualNavBarHeight = Utils.extractNavigationBarHeight(input); | ||
|
||
assertEquals(null, actualNavBarHeight); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters