package Ġcom . nic olas gu ill en . k oint lin . utils Ċ Ċ import Ġandroidx . test . Instrumentation Registry Ċ import Ġtools . fastlane . screen grab .* Ċ import Ġjava . util . regex . Pattern Ċ Ċ object ĠScreen grab Ġ{ ĊĠĠĠ Ġprivate Ġval ĠTAG _ PATTERN Ġ= ĠPattern . compile ("[ a - zA - Z 0 - 9 _- ]+ ") ĊĠĠĠ Ġvar Ġdefault Screenshot Strategy : ĠScreen shot Strategy Ġ= ĠDecor View Screenshot Strategy () ĊĊĠĠĠ Ġ@ Jvm Over loads ĊĠĠĠ Ġfun Ġscreenshot ( screenshot Name : ĠString , Ġstrategy : ĠScreen shot Strategy Ġ= Ġdefault Screenshot Strategy ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġapp Context Ġ= ĠInstrument ation Registry . get Instrumentation (). target Context . application Context ĊĠĠĠĠĠĠĠ Ġscreenshot ( screenshot Name , Ġstrategy , ĠFile Writing Screenshot Callback ( app Context )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġscreenshot ( screenshot Name : ĠString , Ġstrategy : ĠScreen shot Strategy , Ġcallback : ĠScreen shot Callback ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ(! TAG _ PATTERN . matcher ( screenshot Name ). matches ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠIllegalArgumentException (" screenshot Name Ġmay Ġonly Ġcontain Ġthe Ġletters Ġa - z , Ġ ĠA - Z , Ġthe Ġnumbers Ġ 0 - 9 , Ġunders cores , Ġand Ġhy ph ens ") ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstrategy . take Screenshot ( screenshot Name , Ġcallback ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }