Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method addDefaultShareMenuItem for Android #16

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions AUTHORS

This file was deleted.

28 changes: 0 additions & 28 deletions CONTRIBUTING.md

This file was deleted.

12 changes: 0 additions & 12 deletions CONTRIBUTORS

This file was deleted.

1 change: 0 additions & 1 deletion README.md

This file was deleted.

79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# cordova-plugin-browsertab-themeable

Note: This is not an official Google product.

## Supported Platforms

- __Android__
- __iOS__

## Installation

Execute from the projects root folder:
```
$ cordova plugin add cordova-plugin-browsertab-themeable
```

Or install a specific version:
```
$ cordova plugin add cordova-plugin-browsertab-themeable@VERSION
```

Or install the latest head version:
```
$ cordova plugin add https://github.com/gabfiocchi/cordova-plugin-browsertab.git
```

## About

This plugin provides an interface to in-app browser tabs that exist on some
mobile platforms, specifically
[Custom Tabs](http://developer.android.com/tools/support-library/features.html#custom-tabs)
on Android (including the
[Chrome Custom Tabs](https://developer.chrome.com/multidevice/android/customtabs)
implementation), and
[SFSafariViewController](https://developer.apple.com/library/ios/documentation/SafariServices/Reference/SFSafariViewController_Ref/)
on iOS.

## Usage

To open a URL in an in-app browser tab on a compatible platform with Default theme:

cordova.plugins.browsertab.themeable.openUrl('https://www.google.com');

To open a URL in an in-app browser tab on a compatible platform with Custom theme:

cordova.plugins.browsertab.themeable.openUrl('https://www.google.com', {toolbarColor:"#000000"});

toolbarColor: works only with Hexa.

This plugin is designed to complement cordova-plugin-inappbrowser. No fallback
is triggered automatically, you need to test whether it will succeed, and then
perform your own fallback logic like opening the link in the system browser
instead using cordova-plugin-inappbrowser.

cordova.InAppBrowser.open('https://www.google.com/', '_system');

Complete example with fallback handling:

var testURL = 'https://www.google.com';

document.querySelector("#tabwithfallback").addEventListener('click', function(ev) {
cordova.plugins.browsertab.isAvailable(function(result) {
if (!result) {
cordova.InAppBrowser.open(testURL, '_system');
} else {
cordova.plugins.browsertab.openUrl(
testURL,
function(successResp) {},
function(failureResp) {
error.textContent = "failed to launch browser tab";
error.style.display = '';
});
}
},
function(isAvailableError) {
error.textContent = "failed to query availability of in-app browser tab";
error.style.display = '';
});
});
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "cordova-plugin-browsertab-themeable",
"version": "0.2.1",
"description": "In-app browser tabs for Android and iOS it's a forke modify of cordova-plugin-browsertab",
"cordova": {
"id": "cordova-plugin-browsertab-themeable",
"platforms": [
"android",
"ios"
]
},
"keywords": [
"sfsafariviewcontroller",
"custom-tabs",
"browser-tabs",
"browser",
"browsertab",
"in-app-browser",
"inappbrowser"
],
"author": "Gabriel Fiocchi",
"license": "Apache-2.0"
}
16 changes: 7 additions & 9 deletions plugin/plugin.xml → plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@
<plugin
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-browsertab"
version="0.2.0">
<name>cordova-plugin-browsertab</name>
id="cordova-plugin-browsertab-themeable"
version="0.2.1">
<name>cordova-plugin-browsertab-themeable</name>
<description>
This plugin provides an interface to in-app browser tabs that exist on
some mobile platforms, specifically Custom Tabs on Android and
SFSafariViewController on iOS.
This plugin provides an interface to in-app browser tabs that exist on some mobile platforms, specifically Custom Tabs on Android and SFSafariViewController on iOS it's a forke modify of cordova-plugin-browsertab.
</description>
<dependency id="cordova-plugin-compat" version="^1.0.0" />

<js-module name="BrowserTab" src="www/browsertab.js">
<clobbers target="cordova.plugins.browsertab" />
<clobbers target="cordova.plugins.browsertab.themeable" />
</js-module>

<platform name="android">
<config-file parent="/*" target="res/xml/config.xml">
<feature name="BrowserTab">
<param name="android-package"
value="com.google.cordova.plugin.browsertab.BrowserTab" />
value="com.gabfiocchi.cordova.plugin.browsertab.BrowserTab" />
</feature>
</config-file>
<source-file src="src/android/BrowserTab.java"
target-dir="src/com/google/cordova/plugin" />
target-dir="src/com/gabfiocchi/cordova/plugin" />
<framework src="com.android.support:customtabs:23.3.0"/>
<framework src="src/android/BrowserTab.gradle" custom="true" type="gradleReference"/>
</platform>
Expand Down
83 changes: 0 additions & 83 deletions plugin/README.md

This file was deleted.

19 changes: 0 additions & 19 deletions plugin/package.json

This file was deleted.

File renamed without changes.
20 changes: 18 additions & 2 deletions plugin/src/android/BrowserTab.java → src/android/BrowserTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
* limitations under the License.
*/

package com.google.cordova.plugin.browsertab;
package com.gabfiocchi.cordova.plugin.browsertab;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Color;
import android.net.Uri;
import android.support.customtabs.CustomTabsIntent;
import android.util.Log;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class BrowserTab extends CordovaPlugin {

private boolean mFindCalled = false;
private String mCustomTabsBrowser;
private String toolbarColor = "#ffffff";

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
Expand Down Expand Up @@ -95,13 +97,27 @@ private void openUrl(JSONArray args, CallbackContext callbackContext) {
return;
}

JSONObject themeableArgs;
try {
themeableArgs = new JSONObject(args.optString(1));
if (themeableArgs.getString("toolbarColor") != null) {
Log.d( LOG_TAG, "soy arg " + args.optString(1) );
toolbarColor = themeableArgs.getString("toolbarColor");
}
} catch (JSONException e) {
Log.d(LOG_TAG, "openUrl themeableArgs: failed to parse theme parameters" + args);
}

String customTabsBrowser = findCustomTabBrowser();
if (customTabsBrowser == null) {
Log.d(LOG_TAG, "openUrl: no in app browser tab available");
callbackContext.error("no in app browser tab implementation available");
}

Intent customTabsIntent = new CustomTabsIntent.Builder().build().intent;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor( Color.parseColor(toolbarColor));
builder.addDefaultShareMenuItem();
Intent customTabsIntent = builder.build().intent;
customTabsIntent.setData(Uri.parse(urlStr));
customTabsIntent.setPackage(mCustomTabsBrowser);
cordova.getActivity().startActivity(customTabsIntent);
Expand Down
File renamed without changes.
Loading