-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(browser): implement close() method for android
- Loading branch information
Showing
4 changed files
with
94 additions
and
3 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
52 changes: 52 additions & 0 deletions
52
browser/android/src/main/java/com/capacitorjs/plugins/browser/BrowserControllerActivity.java
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,52 @@ | ||
package com.capacitorjs.plugins.browser; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import androidx.annotation.Nullable; | ||
|
||
public class BrowserControllerActivity extends Activity { | ||
|
||
private boolean isCustomTabsOpen = false; | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
isCustomTabsOpen = false; | ||
|
||
if (BrowserPlugin.browserControllerListener != null) { | ||
BrowserPlugin.browserControllerListener.onControllerReady(this); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onNewIntent(Intent intent) { | ||
super.onNewIntent(intent); | ||
if (intent.hasExtra("close")) { | ||
finish(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
if (isCustomTabsOpen) { | ||
isCustomTabsOpen = false; | ||
finish(); | ||
} else { | ||
isCustomTabsOpen = true; | ||
} | ||
} | ||
|
||
public void open(Browser implementation, Uri url, Integer toolbarColor) { | ||
implementation.open(url, toolbarColor); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
isCustomTabsOpen = false; | ||
BrowserPlugin.setBrowserControllerListener(null); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
browser/android/src/main/java/com/capacitorjs/plugins/browser/BrowserControllerListener.java
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,5 @@ | ||
package com.capacitorjs.plugins.browser; | ||
|
||
public interface BrowserControllerListener { | ||
void onControllerReady(BrowserControllerActivity activity); | ||
} |
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