/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 2 0 ĠThe ĠAndroid ĠOpen ĠSource ĠProject Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġcom . android . tools . idea . emulator Ċ Ċ import Ġcom . android . emulator . control . Rotation . Skin Rotation Ċ import Ġcom . android . io . read Image Ċ import Ġcom . android . test utils . Image Diff Util Ċ import Ġcom . android . test utils . TestUtils . resolve Workspace Path Ċ import Ġcom . android . tools . adt ui . Image Utils Ċ import Ġcom . android . tools . adt ui . webp . Web p Metadata Ċ import Ġcom . android . tools . idea . av d manager . Skin Layout Definition Ċ import Ġcom . android . tools . idea . emulator . Fake Em ulator . Companion . get Skin Folder Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġorg . junit . Assert . fail Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġjava . awt . Dimension Ċ import Ġjava . awt . Rectangle Ċ import Ġjava . awt . image . Buffered Image Ċ import Ġjava . awt . image . Buffered Image . TYPE _ INT _ ARGB Ċ import Ġjava . nio . charset . StandardCharsets Ċ import Ġjava . nio . file . Files Ċ import Ġjava . nio . file . NoSuch File Exception Ċ import Ġjava . nio . file . Path Ċ import Ġjava . util . function . Consumer Ċ import Ġjava . util . function . Predicate Ċ Ċ /** Ċ Ġ* ĠTests Ġfor Ġ[ Skin Definition ] Ġand Ġrelated Ġclasses . Ċ Ġ*/ Ċ class ĠSk in Definition Test Ġ{ ĊĊĠ Ġ@ Before ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ ĠWeb p Metadata . ensure Web p Registered () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Pixel _ 2 _ XL () Ġ{ ĊĠĠĠ Ġval Ġfolder Ġ= Ġget Skin Folder (" pixel _ 2 _ xl ") ĊĠĠĠ Ġval Ġskin Ġ= ĠSk in Definition . create ( folder ) Ġ?: Ġthrow ĠAssertionError (" Expected Ġnon - null ĠSk in Definition ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġget Rot ated Frame Size Ġmethod . ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . POR TRA IT )). isEqualTo ( Dimension ( 1 6 2 3 , Ġ 3 3 2 2 )) ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . LAND SC APE )). isEqualTo ( Dimension ( 3 3 2 2 , Ġ 1 6 2 3 )) ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . RE VERSE _ POR TRA IT )). isEqualTo ( Dimension ( 1 6 2 3 , Ġ 3 3 2 2 )) ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . RE VERSE _ LAND SC APE )). isEqualTo ( Dimension ( 3 3 2 2 , Ġ 1 6 2 3 )) ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġcreate Scaled Layout Ġmethod Ġwithout Ġrotation Ġor Ġscaling . ĊĠĠĠ Ġvar Ġlayout Ġ= Ġskin . layout ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 1 4 4 0 , Ġ 2 8 8 0 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle ). isEqualTo ( Rectangle (- 8 6 , Ġ- 2 4 2 , Ġ 1 6 2 3 , Ġ 3 3 2 2 )) ĊĠĠĠ ĠassertThat ( layout . frame Images ). has Size ( 8 ) ĊĠĠĠ ĠassertThat ( layout . mask Images ). has Size ( 4 ) Ġ// ĠFour Ġround Ġcorners . ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġcreate Scaled Layout Ġmethod Ġwith Ġscaling . ĊĠĠĠ Ġlayout Ġ= Ġskin . create Scaled Layout ( 3 2 5 , Ġ 6 5 0 , ĠSk in Rotation . POR TRA IT ) ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 3 2 5 , Ġ 6 5 0 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle ). isEqualTo ( Rectangle (- 1 9 , Ġ- 5 5 , Ġ 3 6 6 , Ġ 7 5 0 )) ĊĠĠĠ Ġassert Skin Appearance ( layout , Ġ" pixel _ 2 _ xl ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġcreate Scaled Layout Ġmethod Ġwith Ġ 9 0 Ġdegree Ġrotation Ġand Ġscaling . ĊĠĠĠ Ġlayout Ġ= Ġskin . create Scaled Layout ( 6 5 0 , Ġ 3 2 5 , ĠSk in Rotation . LAND SC APE ) ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 6 5 0 , Ġ 3 2 5 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle ). isEqualTo ( Rectangle (- 5 5 , Ġ- 2 2 , Ġ 7 5 0 , Ġ 3 6 6 )) ĊĠĠĠ Ġassert Skin Appearance ( layout , Ġ" pixel _ 2 _ xl _ 9 0 ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġcreate Scaled Layout Ġmethod Ġwith Ġ 1 8 0 Ġdegree Ġrotation Ġand Ġscaling . ĊĠĠĠ Ġlayout Ġ= Ġskin . create Scaled Layout ( 3 2 5 , Ġ 6 5 0 , ĠSk in Rotation . RE VERSE _ POR TRA IT ) ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 3 2 5 , Ġ 6 5 0 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle ). isEqualTo ( Rectangle (- 2 2 , Ġ- 4 5 , Ġ 3 6 6 , Ġ 7 5 0 )) ĊĠĠĠ Ġassert Skin Appearance ( layout , Ġ" pixel _ 2 _ xl _ 1 8 0 ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġcreate Scaled Layout Ġmethod Ġwith Ġ 2 7 0 Ġdegree Ġrotation Ġand Ġscaling . ĊĠĠĠ Ġlayout Ġ= Ġskin . create Scaled Layout ( 6 5 0 , Ġ 3 2 5 , ĠSk in Rotation . RE VERSE _ LAND SC APE ) ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 6 5 0 , Ġ 3 2 5 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle ). isEqualTo ( Rectangle (- 4 5 , Ġ- 1 9 , Ġ 7 5 0 , Ġ 3 6 6 )) ĊĠĠĠ Ġassert Skin Appearance ( layout , Ġ" pixel _ 2 _ xl _ 2 7 0 ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Pixel _ 3 _ XL () Ġ{ ĊĠĠĠ Ġval Ġfolder Ġ= Ġget Skin Folder (" pixel _ 3 _ xl ") ĊĠĠĠ Ġval Ġskin Ġ= ĠSk in Definition . create ( folder ) Ġ?: Ġthrow ĠAssertionError (" Expected Ġnon - null ĠSk in Definition ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġget Rot ated Frame Size Ġmethod Ġwithout Ġscaling . ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . POR TRA IT )). isEqualTo ( Dimension ( 1 5 8 4 , Ġ 3 2 4 5 )) ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . LAND SC APE )). isEqualTo ( Dimension ( 3 2 4 5 , Ġ 1 5 8 4 )) ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . RE VERSE _ POR TRA IT )). isEqualTo ( Dimension ( 1 5 8 4 , Ġ 3 2 4 5 )) ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . RE VERSE _ LAND SC APE )). isEqualTo ( Dimension ( 3 2 4 5 , Ġ 1 5 8 4 )) ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġget Rot ated Frame Size Ġmethod Ġwith Ġscaling . ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . POR TRA IT , ĠDimension ( 1 4 5 2 , Ġ 2 9 8 4 ))). isEqualTo ( Dimension ( 1 5 9 8 , Ġ 3 2 7 2 )) ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . LAND SC APE , ĠDimension ( 1 4 5 2 , Ġ 2 9 8 4 ))). isEqualTo ( Dimension ( 3 2 7 2 , Ġ 1 5 9 8 )) ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . RE VERSE _ POR TRA IT , ĠDimension ( 1 4 5 2 , Ġ 2 9 8 4 ))). isEqualTo ( Dimension ( 1 5 9 8 , Ġ 3 2 7 2 )) ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . RE VERSE _ LAND SC APE , ĠDimension ( 1 4 5 2 , Ġ 2 9 8 4 ))). isEqualTo ( Dimension ( 3 2 7 2 , Ġ 1 5 9 8 )) ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġcreate Scaled Layout Ġmethod Ġwithout Ġrotation Ġor Ġscaling . ĊĠĠĠ Ġvar Ġlayout Ġ= Ġskin . layout ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 1 4 4 0 , Ġ 2 9 6 0 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle ). isEqualTo ( Rectangle (- 6 5 , Ġ- 7 2 , Ġ 1 5 8 4 , Ġ 3 2 4 5 )) ĊĠĠĠ ĠassertThat ( layout . frame Images ). has Size ( 8 ) ĊĠĠĠ ĠassertThat ( layout . mask Images ). has Size ( 5 ) Ġ// ĠFour Ġround Ġcorners Ġand Ġthe Ġcut out . ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġcreate Scaled Layout Ġmethod Ġwith Ġscaling . ĊĠĠĠ Ġlayout Ġ= Ġskin . create Scaled Layout ( 3 4 1 , Ġ 7 0 0 , ĠSk in Rotation . POR TRA IT ) ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 3 4 1 , Ġ 7 0 0 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle ). isEqualTo ( Rectangle (- 1 5 , Ġ- 1 7 , Ġ 3 7 5 , Ġ 7 6 7 )) ĊĠĠĠ Ġassert Skin Appearance ( layout , Ġ" pixel _ 3 _ xl ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġcreate Scaled Layout Ġmethod Ġwith Ġ 9 0 Ġdegree Ġrotation Ġand Ġscaling . ĊĠĠĠ Ġlayout Ġ= Ġskin . create Scaled Layout ( 7 0 0 , Ġ 3 4 1 , ĠSk in Rotation . LAND SC APE ) ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 7 0 0 , Ġ 3 4 1 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle ). isEqualTo ( Rectangle (- 1 7 , Ġ- 1 9 , Ġ 7 6 7 , Ġ 3 7 5 )) ĊĠĠĠ Ġassert Skin Appearance ( layout , Ġ" pixel _ 3 _ xl _ 9 0 ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġcreate Scaled Layout Ġmethod Ġwith Ġ 1 8 0 Ġdegree Ġrotation Ġand Ġscaling . ĊĠĠĠ Ġlayout Ġ= Ġskin . create Scaled Layout ( 3 4 1 , Ġ 7 0 0 , ĠSk in Rotation . RE VERSE _ POR TRA IT ) ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 3 4 1 , Ġ 7 0 0 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle ). isEqualTo ( Rectangle (- 1 9 , Ġ- 5 0 , Ġ 3 7 5 , Ġ 7 6 7 )) ĊĠĠĠ Ġassert Skin Appearance ( layout , Ġ" pixel _ 3 _ xl _ 1 8 0 ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġcreate Scaled Layout Ġmethod Ġwith Ġ 2 7 0 Ġdegree Ġrotation Ġand Ġscaling . ĊĠĠĠ Ġlayout Ġ= Ġskin . create Scaled Layout ( 7 0 0 , Ġ 3 4 1 , ĠSk in Rotation . RE VERSE _ LAND SC APE ) ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 7 0 0 , Ġ 3 4 1 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle ). isEqualTo ( Rectangle (- 5 0 , Ġ- 1 5 , Ġ 7 6 7 , Ġ 3 7 5 )) ĊĠĠĠ Ġassert Skin Appearance ( layout , Ġ" pixel _ 3 _ xl _ 2 7 0 ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Very Tiny Scale () Ġ{ ĊĠĠĠ Ġval Ġfolder Ġ= Ġget Skin Folder (" pixel _ 4 _ xl ") ĊĠĠĠ Ġval Ġskin Ġ= ĠSk in Definition . create ( folder ) Ġ?: Ġthrow ĠAssertionError (" Expected Ġnon - null ĠSk in Definition ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġcreate Scaled Layout Ġmethod Ġwith Ġscaling . ĊĠĠĠ Ġval Ġlayout Ġ= Ġskin . create Scaled Layout ( 8 , Ġ 1 6 , ĠSk in Rotation . POR TRA IT ) ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 8 , Ġ 1 6 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle ). isEqualTo ( Rectangle (- 0 , Ġ- 1 , Ġ 8 , Ġ 1 8 )) ĊĠĠĠ Ġassert Skin Appearance ( layout , Ġ" tiny _ pixel _ 4 _ xl ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Pixel _ 4 () Ġ{ ĊĠĠĠ Ġval Ġfolder Ġ= Ġget Skin Folder (" pixel _ 4 ") ĊĠĠĠ Ġval Ġskin Ġ= ĠSk in Definition . create ( folder ) Ġ?: Ġthrow ĠAssertionError (" Expected Ġnon - null ĠSk in Definition ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġskin Ġlayout Ġand Ġconsistency Ġof Ġits Ġimages . ĊĠĠĠ Ġval Ġlayout Ġ= Ġskin . layout ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 1 0 8 0 , Ġ 2 2 8 0 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle . size ). isEqualTo ( Dimension ( 1 1 7 8 , Ġ 2 4 9 8 )) ĊĠĠĠ ĠassertThat ( layout . frame Images ). has Size ( 8 ) ĊĠĠĠ ĠassertThat ( layout . mask Images ). has Size ( 4 ) Ġ// ĠFour Ġround Ġcorners . ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Pixel _ 4 _ xl () Ġ{ ĊĠĠĠ Ġval Ġfolder Ġ= Ġget Skin Folder (" pixel _ 4 _ xl ") ĊĠĠĠ Ġval Ġskin Ġ= ĠSk in Definition . create ( folder ) Ġ?: Ġthrow ĠAssertionError (" Expected Ġnon - null ĠSk in Definition ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġskin Ġlayout Ġand Ġconsistency Ġof Ġits Ġimages . ĊĠĠĠ Ġval Ġlayout Ġ= Ġskin . layout ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 1 4 4 0 , Ġ 3 0 4 0 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle . size ). isEqualTo ( Dimension ( 1 5 7 1 , Ġ 3 3 3 2 )) ĊĠĠĠ ĠassertThat ( layout . frame Images ). has Size ( 8 ) ĊĠĠĠ ĠassertThat ( layout . mask Images ). has Size ( 4 ) Ġ// ĠFour Ġround Ġcorners . ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Pixel _ 4 a _ 5 g () Ġ{ ĊĠĠĠ Ġval Ġfolder Ġ= Ġget Skin Folder (" pixel _ 4 a _ 5 g ") ĊĠĠĠ Ġval Ġskin Ġ= ĠSk in Definition . create ( folder ) Ġ?: Ġthrow ĠAssertionError (" Expected Ġnon - null ĠSk in Definition ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġskin Ġlayout Ġand Ġconsistency Ġof Ġits Ġimages . ĊĠĠĠ Ġval Ġlayout Ġ= Ġskin . layout ĊĠĠĠ Ġvalidate Layout Consistency ( layout , Ġfolder ) ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 1 0 8 0 , Ġ 2 3 4 0 )) ĊĠĠĠ ĠassertThat ( layout . frame Images ). has Size ( 8 ) ĊĠĠĠ ĠassertThat ( layout . mask Images ). has Size ( 4 ) Ġ// ĠFour Ġround Ġcorners , Ġone Ġwith Ġa Ġcamera Ġhole . ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Pixel _ 5 () Ġ{ ĊĠĠĠ Ġval Ġfolder Ġ= Ġget Skin Folder (" pixel _ 5 ") ĊĠĠĠ Ġval Ġskin Ġ= ĠSk in Definition . create ( folder ) Ġ?: Ġthrow ĠAssertionError (" Expected Ġnon - null ĠSk in Definition ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġskin Ġlayout Ġand Ġconsistency Ġof Ġits Ġimages . ĊĠĠĠ Ġval Ġlayout Ġ= Ġskin . layout ĊĠĠĠ Ġvalidate Layout Consistency ( layout , Ġfolder ) ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 1 0 8 0 , Ġ 2 3 4 0 )) ĊĠĠĠ ĠassertThat ( layout . frame Images ). has Size ( 8 ) ĊĠĠĠ ĠassertThat ( layout . mask Images ). has Size ( 4 ) Ġ// ĠFour Ġround Ġcorners , Ġone Ġwith Ġa Ġcamera Ġhole . ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest W ear Round () Ġ{ ĊĠĠĠ Ġval Ġfolder Ġ= Ġget Skin Folder (" we ar _ round ") ĊĠĠĠ Ġval Ġskin Ġ= ĠSk in Definition . create ( folder ) Ġ?: Ġthrow ĠAssertionError (" Expected Ġnon - null ĠSk in Definition ") ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġget Rot ated Frame Size Ġmethod . ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . POR TRA IT )). isEqualTo ( Dimension ( 3 8 0 , Ġ 3 8 0 )) ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . LAND SC APE )). isEqualTo ( Dimension ( 3 8 0 , Ġ 3 8 0 )) ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . RE VERSE _ POR TRA IT )). isEqualTo ( Dimension ( 3 8 0 , Ġ 3 8 0 )) ĊĠĠĠ ĠassertThat ( skin . get Rot ated Frame Size ( Skin Rotation . RE VERSE _ LAND SC APE )). isEqualTo ( Dimension ( 3 8 0 , Ġ 3 8 0 )) ĊĊĠĠĠ Ġ// ĠCheck Ġthe Ġcreate Scaled Layout Ġmethod Ġwithout Ġrotation Ġor Ġscaling . ĊĠĠĠ Ġval Ġlayout Ġ= Ġskin . layout ĊĠĠĠ ĠassertThat ( layout . display Size ). isEqualTo ( Dimension ( 3 2 0 , Ġ 3 2 0 )) ĊĠĠĠ ĠassertThat ( layout . frame Rectangle ). isEqualTo ( Rectangle (- 3 0 , Ġ- 3 0 , Ġ 3 8 0 , Ġ 3 8 0 )) ĊĠĠĠ ĠassertThat ( layout . frame Images ). has Size ( 8 ) ĊĠĠĠ ĠassertThat ( layout . mask Images ). has Size ( 1 ) ĊĠĠĠ Ġassert Skin Appearance ( layout , Ġ" we ar _ round ") ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġvalidate Layout Consistency ( skin Layout : ĠSk in Layout , Ġskin Folder : ĠPath ) Ġ{ ĊĠĠĠ Ġval Ġimage Ġ= Ġskin Layout . draw () ĊĠĠĠ Ġval Ġbackground Image Ġ= Ġread Background Image ( skin Folder ) ĊĠĠĠ Ġval Ġproblems Ġ= Ġmutable ListOf < String >() ĊĠĠĠ Ġif Ġ( background Image Ġ!= Ġnull Ġ&& Ġ( background Image . width Ġ!= Ġimage . width Ġ|| Ġbackground Image . height Ġ!= Ġimage . height )) Ġ{ ĊĠĠĠĠĠ Ġproblems . add (" The Ġbackground Ġimage Ġcan Ġbe Ġc ropped Ġwithout Ġlo osing Ġany Ġinformation ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġstart Ġ= ĠPoint ( skin Layout . display Size . width Ġ/ Ġ 2 Ġ- Ġskin Layout . frame Rectangle . x , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġskin Layout . display Size . height Ġ/ Ġ 2 Ġ- Ġskin Layout . frame Rectangle . y ) ĊĠĠĠ Ġif Ġ(! image . is Transparent ( start )) Ġ{ ĊĠĠĠĠĠ Ġfail (" The Ġskin Ġimage Ġis Ġnot Ġtransparent Ġnear Ġthe Ġcenter Ġof Ġthe Ġdisplay ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġtransparent Area Bounds Ġ= Ġfind Bounds Of Cont iguous Area ( image , Ġstart , Ġimage :: is Transparent ) ĊĠĠĠ Ġif Ġ( transparent Area Bounds . width Ġ!= Ġskin Layout . display Size . width ) Ġ{ ĊĠĠĠĠĠ Ġproblems . add (" The Ġwidth Ġof Ġthe Ġdisplay Ġarea Ġin Ġthe Ġskin Ġimage Ġ(${ transparent Area Bounds . width })" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġdoesn 't Ġmatch Ġthe Ġlayout Ġfile Ġ(${ skin Layout . display Size . width }) ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġif Ġ( transparent Area Bounds . height Ġ!= Ġskin Layout . display Size . height ) Ġ{ ĊĠĠĠĠĠ Ġproblems . add (" The Ġheight Ġof Ġthe Ġdisplay Ġarea Ġin Ġthe Ġskin Ġimage Ġ(${ transparent Area Bounds . height })" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġdoesn 't Ġmatch Ġthe Ġlayout Ġfile Ġ(${ skin Layout . display Size . height }) ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġnon Opaque Area Bounds Ġ= Ġfind Bounds Of Cont iguous Area ( image , Ġstart , Ġimage :: isNot Opaque ) ĊĠĠĠ Ġif Ġ( non Opaque Area Bounds . x Ġ!= Ġtransparent Area Bounds . x ) Ġ{ ĊĠĠĠĠĠ Ġproblems . add (" Part ially Ġtransparent Ġpixels Ġnear Ġthe Ġleft Ġedge Ġof Ġthe Ġdisplay Ġarea ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġif Ġ( non Opaque Area Bounds . x Ġ+ Ġnon Opaque Area Bounds . width Ġ!= Ġtransparent Area Bounds . x Ġ+ Ġ Ġ+ Ġtransparent Area Bounds . width ) Ġ{ ĊĠĠĠĠĠ Ġproblems . add (" Part ially Ġtransparent Ġpixels Ġnear Ġthe Ġright Ġedge Ġof Ġthe Ġdisplay Ġarea ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġif Ġ( non Opaque Area Bounds . y Ġ!= Ġtransparent Area Bounds . y ) Ġ{ ĊĠĠĠĠĠ Ġproblems . add (" Part ially Ġtransparent Ġpixels Ġnear Ġthe Ġtop Ġedge Ġof Ġthe Ġdisplay Ġarea ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġif Ġ( non Opaque Area Bounds . y Ġ+ Ġnon Opaque Area Bounds . height Ġ!= Ġtransparent Area Bounds . y Ġ+ Ġ Ġ+ Ġtransparent Area Bounds . height ) Ġ{ ĊĠĠĠĠĠ Ġproblems . add (" Part ially Ġtransparent Ġpixels Ġnear Ġthe Ġbottom Ġedge Ġof Ġthe Ġdisplay Ġarea ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġif Ġ( transparent Area Bounds . x Ġ!= Ġ- skin Layout . frame Rectangle . x Ġ|| Ġtransparent Area Bounds . y Ġ!= Ġ- skin Layout . frame Rectangle . y ) Ġ{ ĊĠĠĠĠĠ Ġproblems . add (" Display Ġoffset Ġin Ġthe Ġlayout Ġfile Ġ(${ - skin Layout . frame Rectangle . x }, Ġ${ - skin Layout . frame Rectangle . y })" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġdoesn 't Ġmatch Ġthe Ġskin Ġimage Ġ(${ transparent Area Bounds . x }, Ġ${ transparent Area Bounds . y }) ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġif Ġ( problems . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠ Ġfail ( problems . join ToString ("\ n ")) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġread Background Image ( skin Folder : ĠPath ): ĠBufferedImage ? Ġ{ ĊĠĠĠ Ġval Ġlayout File Ġ= Ġskin Folder . resolve (" layout ") ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġval Ġcontents Ġ= ĠFiles . read All Bytes ( layout File ). toString ( StandardCharsets . UTF _ 8 ) ĊĠĠĠĠĠ Ġval Ġlayout Definition Ġ= ĠSk in Layout Definition . parse String ( contents ) ĊĠĠĠĠĠ Ġval Ġback round FileName Ġ= Ġlayout Definition . getValue (" parts . portrait . background . image ") Ġ?: Ġreturn Ġnull ĊĠĠĠĠĠ Ġval Ġbackground File Ġ= Ġskin Folder . resolve ( back round FileName ) ĊĠĠĠĠĠ Ġreturn Ġbackground File . read Image () ĊĠĠĠ Ġ} ĊĠĠĠ Ġcatch Ġ( e : ĠNoSuch File Exception ) Ġ{ ĊĠĠĠĠĠ Ġreturn Ġnull ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġfind Bounds Of Cont iguous Area ( image : ĠBufferedImage , Ġstart : ĠPoint , Ġpredicate : ĠPredicate < Point >): ĠRectangle Ġ{ ĊĠĠĠ Ġvar Ġmin X Ġ= Ġstart . x ĊĠĠĠ Ġvar Ġmax X Ġ= Ġstart . x ĊĠĠĠ Ġvar Ġmin Y Ġ= Ġstart . y ĊĠĠĠ Ġvar Ġmax Y Ġ= Ġstart . y ĊĊĠĠĠ Ġvisit Cont iguous Area ( image , Ġstart , Ġpredicate ) Ġ{ Ġpoint Ġ-> ĊĠĠĠĠĠ Ġmin X Ġ= Ġmin X . coerce At Most ( point . x ) ĊĠĠĠĠĠ Ġmax X Ġ= Ġmax X . coerce At Least ( point . x ) ĊĠĠĠĠĠ Ġmin Y Ġ= Ġmin Y . coerce At Most ( point . y ) ĊĠĠĠĠĠ Ġmax Y Ġ= Ġmax Y . coerce At Least ( point . y ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn ĠRectangle ( min X , Ġmin Y , Ġmax X Ġ+ Ġ 1 Ġ- Ġmin X , Ġmax Y Ġ+ Ġ 1 Ġ- Ġmin Y ) ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠCalls Ġ[ visitor ] Ġfor Ġevery Ġpoint Ġof Ġthe Ġcontiguous Ġarea Ġof Ġthe Ġ[ image ] Ġwhere Ġevery Ġpixel Ġsatisfies ĊĠĠ Ġ* Ġthe Ġ[ predicate ] Ġand Ġcontaining Ġthe Ġ[ start ] Ġpoint . ĊĠĠ Ġ*/ ĊĠ Ġprivate Ġfun Ġvisit Cont iguous Area ( image : ĠBufferedImage , Ġstart : ĠPoint , Ġpredicate : ĠPredicate < Point >, Ġvisitor : ĠConsumer < Point >) Ġ{ ĊĠĠĠ Ġif Ġ(! predicate . test ( start )) Ġ{ ĊĠĠĠĠĠ Ġreturn ĊĠĠĠ Ġ} ĊĠĠĠ Ġvisitor . accept ( start ) ĊĠĠĠ Ġval Ġwidth Ġ= Ġimage . width ĊĠĠĠ Ġval Ġheight Ġ= Ġimage . height ĊĠĠĠ Ġ// ĠUse Ġthe Ġf lood Ġfill Ġalgorithm Ġto Ġexplore Ġthe Ġcontiguous Ġarea . ĊĠĠĠ Ġvar Ġfront Ġ= Ġmutable Set Of ( start ) ĊĠĠĠ Ġvar Ġprevious Front Ġ= Ġmutable Set Of < Point >() ĊĠĠĠ Ġwhile Ġ( front . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠ Ġvar Ġnew Front Ġ= Ġmutable Set Of < Point >() ĊĠĠĠĠĠ Ġfor Ġ( p 1 Ġin Ġfront ) Ġ{ ĊĠĠĠĠĠĠĠ Ġfor Ġ( neighbor Ġin ĠNE IGH B ORS ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġp 2 Ġ= ĠPoint ( p 1 . x Ġ+ Ġneighbor . x , Ġp 1 . y Ġ+ Ġneighbor . y ) ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ( p 2 . x Ġin Ġ 0 Ġuntil Ġwidth Ġ&& Ġp 2 . y Ġin Ġ 0 Ġuntil Ġheight Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ! new Front . contains ( p 2 ) Ġ&& Ġ! front . contains ( p 2 ) Ġ&& Ġ! previous Front . contains ( p 2 ) Ġ&& Ġpredicate . test ( p 2 )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvisitor . accept ( p 2 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnew Front . add ( p 2 ) ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġval Ġtemp Ġ= Ġprevious Front ĊĠĠĠĠĠ Ġprevious Front Ġ= Ġfront ĊĠĠĠĠĠ Ġfront Ġ= Ġnew Front ĊĠĠĠĠĠ Ġnew Front Ġ= Ġtemp ĊĠĠĠĠĠ Ġnew Front . clear () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassert Skin Appearance ( skin Layout : ĠSk in Layout , Ġgold en Image Name : ĠString ) Ġ{ ĊĠĠĠ Ġval Ġimage Ġ= Ġskin Layout . draw () ĊĠĠĠ ĠImage Diff Util . assert Image Similar ( get Gold en File ( golden Image Name ), Ġimage , Ġ 0 . 0 ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠSk in Layout . draw (): ĠBufferedImage Ġ{ ĊĠĠĠ Ġval Ġimage Ġ= ĠImage Utils . create Dip Image ( frame Rectangle . width , Ġframe Rectangle . height , ĠTYPE _ INT _ ARGB ) ĊĠĠĠ Ġval Ġg Ġ= Ġimage . create Graphics () ĊĠĠĠ Ġdraw Frame And Mask ( g , ĠRectangle (- frame Rectangle . x , Ġ- frame Rectangle . y , Ġdisplay Size . width , Ġdisplay Size . height )) ĊĠĠĠ Ġg . dispose () ĊĠĠĠ Ġreturn Ġimage ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġget Gold en File ( name : ĠString ): ĠPath Ġ{ ĊĠĠĠ Ġreturn Ġresolve Workspace Path ("${ G OLD EN _ FILE _ PATH }/${ name }. png ") ĊĠ Ġ} Ċ } Ċ Ċ private Ġfun ĠBufferedImage . is Transparent ( point : ĠPoint ): ĠBoolean Ġ{ ĊĠ Ġreturn Ġget RGB ( point . x , Ġpoint . y ) Ġand ĠAL PH A _ MASK Ġ== Ġ 0 Ċ } Ċ Ċ private Ġfun ĠBufferedImage . is Opaque ( point : ĠPoint ): ĠBoolean Ġ{ ĊĠ Ġreturn Ġget RGB ( point . x , Ġpoint . y ) Ġand ĠAL PH A _ MASK Ġ== ĠAL PH A _ MASK Ċ } Ċ Ċ private Ġfun ĠBufferedImage . isNot Opaque ( point : ĠPoint ): ĠBoolean Ġ{ ĊĠ Ġreturn Ġ! is Opaque ( point ) Ċ } Ċ Ċ data Ġclass ĠPoint ( val Ġx : ĠInt , Ġval Ġy : ĠInt ) Ġ// ĠUn like Ġjava . awt . Point Ġthis Ġclass Ġhas Ġan Ġefficient ĠhashCode Ġmethod . Ċ Ċ private Ġval ĠNE IGH B ORS Ġ= ĠlistOf ( Point (- 1 , Ġ- 1 ), ĠPoint (- 1 , Ġ 0 ), ĠPoint (- 1 , Ġ 1 ), ĠPoint ( 0 , Ġ 1 ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠPoint ( 1 , Ġ 1 ), ĠPoint ( 1 , Ġ 0 ), ĠPoint ( 1 , Ġ- 1 ), ĠPoint ( 0 , Ġ- 1 )) Ċ Ċ private Ġconst Ġval ĠAL PH A _ MASK Ġ= Ġ 0 xFF Ġshl Ġ 2 4 Ċ Ċ private Ġconst Ġval ĠG OLD EN _ FILE _ PATH Ġ= Ġ" tools / adt / idea / emulator / testData / Skin Definition Test / golden " Ċ