2424
2525import androidx .annotation .NonNull ;
2626import androidx .annotation .Nullable ;
27+ import androidx .appcompat .app .AppCompatActivity ;
2728import androidx .browser .customtabs .CustomTabsIntent ;
2829
2930/**
3334 * @author https://github.com/TimScriptov
3435 */
3536@ SuppressWarnings ("JavaJniMissingFunction" )
36- public class BrowserLaunchActivity extends Activity {
37+ public class BrowserLaunchActivity extends AppCompatActivity {
3738 public static final String END_URL = "END_URL" ;
3839 public static final String IN_PROC_BROWSER = "IN_PROC_BROWSER" ;
3940 public static final String OPERATION_ID = "OPERATION_ID" ;
@@ -63,16 +64,16 @@ public class BrowserLaunchActivity extends Activity {
6364
6465 public static void showUrl (long operationId , Context context , @ NonNull String startUrl , String endUrl , int showTypeInt , String [] requestHeaderKeys , String [] requestHeaderValues , boolean useInProcBrowser ) {
6566 if (!startUrl .isEmpty () && !endUrl .isEmpty ()) {
66- ShowUrlType fromInt = ShowUrlType .fromInt (showTypeInt );
67+ final ShowUrlType fromInt = ShowUrlType .fromInt (showTypeInt );
6768 if (fromInt == null ) {
6869 urlOperationFailed (operationId , false , null );
6970 return ;
7071 } else if (requestHeaderKeys .length != requestHeaderValues .length ) {
7172 urlOperationFailed (operationId , false , null );
7273 return ;
7374 } else {
74- Intent intent = new Intent (context , BrowserLaunchActivity .class );
75- Bundle bundle = new Bundle ();
75+ final Intent intent = new Intent (context , BrowserLaunchActivity .class );
76+ final Bundle bundle = new Bundle ();
7677 bundle .putLong (OPERATION_ID , operationId );
7778 bundle .putString (START_URL , startUrl );
7879 bundle .putString (END_URL , endUrl );
@@ -92,7 +93,7 @@ public static void showUrl(long operationId, Context context, @NonNull String st
9293 @ Override
9394 public void onCreate (Bundle bundle ) {
9495 super .onCreate (bundle );
95- Bundle extras = getIntent ().getExtras ();
96+ final Bundle extras = getIntent ().getExtras ();
9697 if (!checkNativeCodeLoaded ()) {
9798 startActivity (getApplicationContext ().getPackageManager ().getLaunchIntentForPackage (getApplicationContext ().getPackageName ()));
9899 finish ();
@@ -103,7 +104,7 @@ public void onCreate(Bundle bundle) {
103104 m_browserInfo = bundle .getString (BROWSER_INFO_STATE_KEY );
104105 } else if (extras != null ) {
105106 m_operationId = extras .getLong (OPERATION_ID , 0L );
106- BrowserLaunchParameters FromArgs = BrowserLaunchParameters .FromArgs (extras );
107+ final BrowserLaunchParameters FromArgs = BrowserLaunchParameters .FromArgs (extras );
107108 m_launchParameters = FromArgs ;
108109 if (FromArgs != null && m_operationId != 0 ) {
109110 return ;
@@ -121,14 +122,14 @@ public void onCreate(Bundle bundle) {
121122 @ Override
122123 protected void onResume () {
123124 super .onResume ();
124- boolean z = m_customTabsInProgress ;
125+ final boolean z = m_customTabsInProgress ;
125126 if (!z && m_launchParameters != null ) {
126- BrowserLaunchParameters browserLaunchParameters = m_launchParameters ;
127+ final BrowserLaunchParameters browserLaunchParameters = m_launchParameters ;
127128 m_launchParameters = null ;
128129 startAuthSession (browserLaunchParameters );
129130 } else if (z ) {
130131 m_customTabsInProgress = false ;
131- Uri data = getIntent ().getData ();
132+ final Uri data = getIntent ().getData ();
132133 if (data != null ) {
133134 finishOperation (WebResult .SUCCESS , data .toString ());
134135 return ;
@@ -154,14 +155,15 @@ public void onNewIntent(Intent intent) {
154155
155156 @ Override
156157 public void onActivityResult (int requestCode , int resultCode , Intent intent ) {
158+ super .onActivityResult (requestCode , resultCode , intent );
157159 if (requestCode == WEB_KIT_WEB_VIEW_REQUEST ) {
158- if (resultCode == - 1 ) {
159- String string = intent .getExtras ().getString (WebKitWebViewController .RESPONSE_KEY , "" );
160+ if (resultCode == RESULT_OK ) {
161+ final String string = intent .getExtras ().getString (WebKitWebViewController .RESPONSE_KEY , "" );
160162 if (!string .isEmpty ()) {
161163 finishOperation (WebResult .SUCCESS , string );
162164 return ;
163165 }
164- } else if (resultCode == 0 ) {
166+ } else if (resultCode == RESULT_CANCELED ) {
165167 finishOperation (WebResult .CANCEL , null );
166168 return ;
167169 }
@@ -179,9 +181,9 @@ protected void onDestroy() {
179181 }
180182
181183 private void startAuthSession (@ NonNull BrowserLaunchParameters browserLaunchParameters ) {
182- BrowserSelectionResult selectBrowser = BrowserSelector .selectBrowser (getApplicationContext (), browserLaunchParameters .UseInProcBrowser );
184+ final BrowserSelectionResult selectBrowser = BrowserSelector .selectBrowser (getApplicationContext (), browserLaunchParameters .UseInProcBrowser );
183185 m_browserInfo = selectBrowser .toString ();
184- String packageName = selectBrowser .packageName ();
186+ final String packageName = selectBrowser .packageName ();
185187 if (packageName == null ) {
186188 startWebView (browserLaunchParameters .StartUrl , browserLaunchParameters .EndUrl , browserLaunchParameters .ShowType , browserLaunchParameters .RequestHeaderKeys , browserLaunchParameters .RequestHeaderValues );
187189 return ;
@@ -196,18 +198,18 @@ private void startCustomTabsInBrowser(String packageName, String startUrl, Strin
196198 }
197199 m_customTabsInProgress = true ;
198200 m_sharedBrowserUsed = true ;
199- CustomTabsIntent .Builder builder = new CustomTabsIntent .Builder ();
201+ final CustomTabsIntent .Builder builder = new CustomTabsIntent .Builder ();
200202 builder .setShowTitle (true );
201- CustomTabsIntent build = builder .build ();
203+ final CustomTabsIntent build = builder .build ();
202204 build .intent .setData (Uri .parse (startUrl ));
203205 build .intent .setPackage (packageName );
204206 startActivity (build .intent );
205207 }
206208
207209 private void startWebView (String startUrl , String endUrl , ShowUrlType showUrlType , String [] requestHeaderKeys , String [] requestHeaderValues ) {
208210 m_sharedBrowserUsed = false ;
209- Intent intent = new Intent (getApplicationContext (), WebKitWebViewController .class );
210- Bundle bundle = new Bundle ();
211+ final Intent intent = new Intent (getApplicationContext (), WebKitWebViewController .class );
212+ final Bundle bundle = new Bundle ();
211213 bundle .putString (START_URL , startUrl );
212214 bundle .putString (END_URL , endUrl );
213215 bundle .putSerializable (SHOW_TYPE , showUrlType );
@@ -218,13 +220,13 @@ private void startWebView(String startUrl, String endUrl, ShowUrlType showUrlTyp
218220 }
219221
220222 private void finishOperation (WebResult webResult , String finalUrl ) {
221- long j = m_operationId ;
223+ final long j = m_operationId ;
222224 m_operationId = 0L ;
223225 finish ();
224226 if (j == 0 ) {
225227 return ;
226228 }
227- int result = XalWebResult .mWebResult [webResult .ordinal ()];
229+ final int result = XalWebResult .mWebResult [webResult .ordinal ()];
228230 if (result == 1 ) {
229231 urlOperationSucceeded (j , finalUrl , m_sharedBrowserUsed , m_browserInfo );
230232 } else if (result == 2 ) {
@@ -269,12 +271,12 @@ private BrowserLaunchParameters(String startUrl, String endUrl, String[] request
269271
270272 @ Nullable
271273 public static BrowserLaunchParameters FromArgs (@ NonNull Bundle bundle ) {
272- String startUrl = bundle .getString (START_URL );
273- String endUrl = bundle .getString (END_URL );
274- String [] headerKeys = bundle .getStringArray (REQUEST_HEADER_KEYS );
275- String [] headerValues = bundle .getStringArray (REQUEST_HEADER_VALUES );
276- ShowUrlType showUrlType = (ShowUrlType ) bundle .get (SHOW_TYPE );
277- boolean z = bundle .getBoolean (BrowserLaunchActivity .IN_PROC_BROWSER );
274+ final String startUrl = bundle .getString (START_URL );
275+ final String endUrl = bundle .getString (END_URL );
276+ final String [] headerKeys = bundle .getStringArray (REQUEST_HEADER_KEYS );
277+ final String [] headerValues = bundle .getStringArray (REQUEST_HEADER_VALUES );
278+ final ShowUrlType showUrlType = (ShowUrlType ) bundle .get (SHOW_TYPE );
279+ final boolean z = bundle .getBoolean (BrowserLaunchActivity .IN_PROC_BROWSER );
278280 if (startUrl == null || endUrl == null || headerKeys == null || headerValues == null || headerKeys .length != headerValues .length ) {
279281 return null ;
280282 }
0 commit comments