-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from proyecto26/96-add-maylaunchurl-and-warmup…
…-methods-in-android Add mayLaunchUrl and warmup methods in Android
- Loading branch information
Showing
14 changed files
with
465 additions
and
53 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
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,98 @@ | ||
import { | ||
Application, | ||
setActivityCallbacks, | ||
AndroidActivityCallbacks, | ||
} from "@nativescript/core"; | ||
import { InAppBrowser } from "nativescript-inappbrowser"; | ||
|
||
@NativeClass() | ||
@JavaProxy("org.nativescript.demo.MainActivity") | ||
export class Activity extends androidx.appcompat.app.AppCompatActivity { | ||
public isNativeScriptActivity; | ||
|
||
private _callbacks: AndroidActivityCallbacks; | ||
|
||
public onCreate(savedInstanceState: android.os.Bundle): void { | ||
Application.android.init(this.getApplication()); | ||
// Set the isNativeScriptActivity in onCreate (as done in the original NativeScript activity code) | ||
// The JS constructor might not be called because the activity is created from Android. | ||
this.isNativeScriptActivity = true; | ||
if (!this._callbacks) { | ||
setActivityCallbacks(this); | ||
} | ||
|
||
this._callbacks.onCreate( | ||
this, | ||
savedInstanceState, | ||
this.getIntent(), | ||
super.onCreate | ||
); | ||
} | ||
|
||
public onNewIntent(intent: android.content.Intent): void { | ||
this._callbacks.onNewIntent( | ||
this, | ||
intent, | ||
super.setIntent, | ||
super.onNewIntent | ||
); | ||
} | ||
|
||
public onSaveInstanceState(outState: android.os.Bundle): void { | ||
this._callbacks.onSaveInstanceState( | ||
this, | ||
outState, | ||
super.onSaveInstanceState | ||
); | ||
} | ||
|
||
public onStart(): void { | ||
this._callbacks.onStart(this, super.onStart); | ||
// InAppBrowser initialization (Connect to the Custom Tabs service) | ||
InAppBrowser.onStart(); | ||
} | ||
|
||
public onStop(): void { | ||
this._callbacks.onStop(this, super.onStop); | ||
} | ||
|
||
public onDestroy(): void { | ||
this._callbacks.onDestroy(this, super.onDestroy); | ||
} | ||
|
||
public onPostResume(): void { | ||
this._callbacks.onPostResume(this, super.onPostResume); | ||
} | ||
|
||
public onBackPressed(): void { | ||
this._callbacks.onBackPressed(this, super.onBackPressed); | ||
} | ||
|
||
public onRequestPermissionsResult( | ||
requestCode: number, | ||
permissions: Array<string>, | ||
grantResults: Array<number> | ||
): void { | ||
this._callbacks.onRequestPermissionsResult( | ||
this, | ||
requestCode, | ||
permissions, | ||
grantResults, | ||
undefined /*TODO: Enable if needed*/ | ||
); | ||
} | ||
|
||
public onActivityResult( | ||
requestCode: number, | ||
resultCode: number, | ||
data: android.content.Intent | ||
): void { | ||
this._callbacks.onActivityResult( | ||
this, | ||
requestCode, | ||
resultCode, | ||
data, | ||
super.onActivityResult | ||
); | ||
} | ||
} |
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
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,37 @@ | ||
import Context = android.content.Context; | ||
import ComponentName = android.content.ComponentName; | ||
import CustomTabsClient = androidx.browser.customtabs.CustomTabsClient; | ||
import Log = android.util.Log; | ||
|
||
import { CustomTabsServiceConnection } from "./utils.android"; | ||
import { log } from "./utils.common"; | ||
|
||
@NativeClass() | ||
class CustomTabsController extends CustomTabsServiceConnection { | ||
private static readonly TAG = "CustomTabsController"; | ||
private readonly context: WeakRef<Context>; | ||
public static customTabsClient: CustomTabsClient; | ||
constructor(context: Context) { | ||
super(); | ||
this.context = new WeakRef(context); | ||
|
||
return global.__native(this); | ||
} | ||
|
||
onCustomTabsServiceConnected(_: ComponentName, client: CustomTabsClient) { | ||
CustomTabsController.customTabsClient = client; | ||
if (!client.warmup(long(0))) { | ||
Log.e(CustomTabsController.TAG, "Couldn't warmup custom tabs client"); | ||
} | ||
const context = this.context.get(); | ||
context.unbindService(this); | ||
log("Custom tabs service connected"); | ||
} | ||
|
||
onServiceDisconnected(_: ComponentName) { | ||
CustomTabsController.customTabsClient = null; | ||
log("Custom tabs service disconnected"); | ||
} | ||
} | ||
|
||
export { CustomTabsController }; |
Oops, something went wrong.