Skip to content

Commit dfb59b6

Browse files
authored
Merge pull request #3 from appcelerator-modules/parity
Add parity for "barCollapsingEnabled" and "open" event, expose more docs
2 parents 75cb915 + bb431b4 commit dfb59b6

18 files changed

+404
-233
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ xcuserdata/
77
build/
88
/android/dist
99
ios/titanium-web-dialog.xcodeproj/project.xcworkspace/xcuserdata
10+
android/libs

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Titanium Web Dialog
22

3-
Use the SFSafariViewController (iOS) and Chrome Pages (Android) together.
3+
Use the native `SFSafariViewController` (iOS) and `Chrome Pages` (Android) within Axway Titanium.
44

55
<img src="./fixtures/DQM57Q7X4AAF8yR.jpg" width="890" alt="Titanium Web Dialog" />
66

@@ -9,13 +9,10 @@ Use the SFSafariViewController (iOS) and Chrome Pages (Android) together.
99
- Titanium SDK 7.0.0 or later (or use the [SDK-6-compatibility](https://github.com/appcelerator-modules/titanium-web-dialog/tree/SDK-6-compatibility) Titanium SDK 6.x)
1010
- iOS 9+ and Android 4.1+
1111

12-
## Roadmap
12+
## iOS Note
1313

14-
- [x] Find suitable module name
15-
- [x] Create both modules on the same namespace (right now [Ti.SafariDialog](https://github.com/appcelerator-modules/ti.safaridialog) vs [Ti.ChromeTabs](https://github.com/prashantsaini1/ti-chrometabs))
16-
- [x] Adjust existing docs from Ti.SafariDialog to support Android as well
17-
- [x] Write cross-platform example and tests
18-
- [x] Release module
14+
The iOS part of this module is based on Ti.SafariDialog, which has been deprecated for a cross-platform solution. All API's of Ti.SafariDialog
15+
still work here and have been extended by more features over time.
1916

2017
## Android Legacy Support
2118

@@ -33,7 +30,7 @@ If you want to use this module in Titanium SDK 6.x, please use the [this version
3330
* `barColor` (String)
3431
* `animated` (Boolean, iOS only)
3532
* `entersReaderIfAvailable` (Boolean, iOS only)
36-
* `barCollapsingEnabled` (Boolean, iOS only)
33+
* `barCollapsingEnabled` (Boolean)
3734
* `title` (String, iOS only)
3835
* `tintColor` (String, iOS only)
3936
   * `dismissButtonStyle` (`DISMISS_BUTTON_STYLE_*`, iOS only)
@@ -52,6 +49,13 @@ If you want to use this module in Titanium SDK 6.x, please use the [this version
5249
* `DISMISS_BUTTON_STYLE_CLOSE` (iOS only)
5350
* `DISMISS_BUTTON_STYLE_CANCEL` (iOS only)
5451

52+
#### Events
53+
54+
* `open` -> `success` (Boolean), `url` (String)
55+
* `close` -> `success` (Boolean), `url` (String) - iOS only
56+
* `load` -> `success` (Boolean), `url` (String) - iOS only
57+
* `redirect` -> `url` (String) - iOS only
58+
5559
### `AuthenticationSession` (iOS only)
5660

5761
## License

android/.clang-format

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
Language: Java
3+
AccessModifierOffset: -4
4+
AllowShortBlocksOnASingleLine: false
5+
AllowShortFunctionsOnASingleLine: None
6+
AllowShortIfStatementsOnASingleLine: false
7+
AllowShortLoopsOnASingleLine: false
8+
# class, constructor, method should be next line
9+
BreakBeforeBraces: Linux
10+
# Keep '=' at end of line when wrapping, but move things like '&&', '||' to beginning of newline
11+
BreakBeforeBinaryOperators: NonAssignment
12+
# FIXME: break for brace after synchronized block, anonymous class declarations
13+
BreakAfterJavaFieldAnnotations: true
14+
ColumnLimit: 120
15+
IndentCaseLabels: true
16+
IndentWidth: 4
17+
MaxEmptyLinesToKeep: 1
18+
SpaceBeforeAssignmentOperators: true
19+
SpaceBeforeParens: ControlStatements
20+
SpacesInParentheses: false
21+
TabWidth: 4
22+
UseTab: ForContinuationAndIndentation
23+
SpaceAfterCStyleCast: true
24+
# Spaces inside {} for array literals, i.e. "new Object[] { args }"
25+
Cpp11BracedListStyle: false
26+
ReflowComments: false
-33.7 KB
Binary file not shown.
-33.6 KB
Binary file not shown.
-33.4 KB
Binary file not shown.

android/manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# this is your module manifest and used by Titanium
33
# during compilation, packaging, distribution, etc.
44
#
5-
version: 1.0.0
5+
version: 1.1.0
66
apiversion: 4
77
architectures: arm64-v8a armeabi-v7a x86
88
description: titanium-web-dialog

android/src/ti/webdialog/Params.java

100755100644
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package ti.webdialog;
22

3-
public class Params {
3+
public class Params
4+
{
45
public static final String LCAT = "TiChromeDialog";
56
public static final String SHOW_TITLE = "showTitle";
67
public static final String URL = "url";
78
public static final String BAR_COLOR = "barColor";
89
public static final String FADE_TRANSITION = "fadeTransition";
910
public static final String ENABLE_SHARING = "enableSharing";
1011
public static final String CLOSE_ICON = "closeIcon";
12+
public static final String BAR_COLLAPSING_ENABLED = "barCollapsingEnabled";
1113
}

android/src/ti/webdialog/TitaniumWebDialogModule.java

100755100644
Lines changed: 144 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -34,132 +34,150 @@
3434
import android.support.customtabs.CustomTabsService;
3535
import android.util.DisplayMetrics;
3636

37-
38-
@Kroll.module(name="TitaniumWebDialog", id="ti.webdialog")
37+
@Kroll.module(name = "TitaniumWebDialog", id = "ti.webdialog")
3938
public class TitaniumWebDialogModule extends KrollModule
4039
{
41-
// Standard Debugging variables
42-
private static final String LCAT = "TiWebDialog";
43-
44-
private List<String> getCustomTabBrowsers(Context context, List<ResolveInfo> browsersList) {
45-
List<String> customTabBrowsers = new ArrayList<String>();
46-
47-
for (ResolveInfo info : browsersList) {
48-
String packageName = info.activityInfo.packageName;
49-
50-
Intent intent = new Intent();
51-
intent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
52-
intent.setPackage(packageName);
53-
54-
if (context.getPackageManager().resolveService(intent, 0) != null) {
55-
customTabBrowsers.add(packageName);
56-
}
57-
}
58-
59-
return customTabBrowsers;
60-
}
61-
62-
private void openCustomTab(Context context, List<String> customTabBrowsers, KrollDict options) {
63-
String URL = options.getString(Params.URL);
64-
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
65-
builder.setShowTitle(Utils.getBool(options, Params.SHOW_TITLE));
66-
67-
int barColor = Utils.getColor(options, Params.BAR_COLOR);
68-
if (barColor != -1) {
69-
builder.setToolbarColor(barColor);
70-
}
71-
72-
// set start and exit animations
73-
if (Utils.getBool(options, Params.FADE_TRANSITION)) {
74-
builder.setStartAnimations(context, android.R.anim.fade_in, android.R.anim.fade_out);
75-
builder.setExitAnimations(context, android.R.anim.fade_in, android.R.anim.fade_out);
76-
}
77-
78-
//enable Share link option
79-
if (Utils.getBool(options, Params.ENABLE_SHARING)) {
80-
builder.addDefaultShareMenuItem();
81-
}
82-
83-
String closeIcon = Utils.getString(options, Params.CLOSE_ICON);
84-
if (!closeIcon.isEmpty()) {
85-
builder.setCloseButtonIcon( getIcon(closeIcon) );
86-
}
87-
88-
CustomTabsIntent tabIntent = builder.build();
89-
90-
for(String s:customTabBrowsers) {
91-
tabIntent.intent.setPackage(s);
92-
}
93-
94-
tabIntent.launchUrl(context, Uri.parse(URL));
95-
}
96-
97-
98-
private Bitmap getIcon(String path) {
99-
Bitmap resultBitmap = null;
100-
101-
if (path != null && !path.trim().equalsIgnoreCase("")) {
102-
String resourceIcon = path.replaceAll(".png", "");
103-
resourceIcon = "drawable." + resourceIcon;
104-
105-
int resource = Utils.getR(resourceIcon);
106-
107-
if (resource == 0) {
108-
TiUrl imageUrl = new TiUrl(path);
109-
TiFileHelper tfh = new TiFileHelper(TiApplication.getInstance());
110-
Drawable d = tfh.loadDrawable(imageUrl.resolve(), false);
111-
112-
resultBitmap = ((BitmapDrawable) d).getBitmap();
113-
114-
} else {
115-
resultBitmap = BitmapFactory.decodeResource(TiApplication.getAppRootOrCurrentActivity().getResources(), resource);
116-
}
117-
}
118-
119-
// important step to show close icon
120-
// rescale bitmap to 24dp(Height) x 48dp(Width) as mentioned here, otherwise it won't work
121-
// https://developer.chrome.com/multidevice/android/customtabs#choosing-an icon for the action button
122-
if (resultBitmap != null) {
123-
resultBitmap = Utils.rescaleBitmap(TiApplication.getAppRootOrCurrentActivity(), resultBitmap, 24, 48);
124-
}
125-
126-
return resultBitmap;
127-
}
128-
129-
130-
@Kroll.method
131-
public void open(KrollDict options) {
132-
if ((options != null) && options.containsKeyAndNotNull(Params.URL)) {
133-
Context context = TiApplication.getAppCurrentActivity();
134-
List<ResolveInfo> browsersList = Utils.allBrowsers(context);
135-
136-
if (!browsersList.isEmpty()) {
137-
List<String> customTabBrowsers = getCustomTabBrowsers(context, browsersList);
138-
139-
// show supported browsers list or open directly if only 1 supported browser is available
140-
openCustomTab(context, customTabBrowsers, options);
141-
} else {
142-
Log.i(Params.LCAT, "No browsers available in this device.");
143-
}
144-
}
145-
}
146-
147-
@Kroll.method
148-
public boolean isSupported() {
149-
Context context = TiApplication.getAppCurrentActivity();
150-
List<ResolveInfo> browsersList = Utils.allBrowsers(context);
151-
152-
return !browsersList.isEmpty();
153-
}
154-
155-
@Kroll.method
156-
public void close(KrollDict options) {
157-
Log.e(Params.LCAT, "The \"close\" method is not implemented, yet!");
158-
}
159-
160-
@Kroll.method
161-
public boolean isOpen(KrollDict options) {
162-
Log.e(Params.LCAT, "The \"isOpen\" method is not implemented, yet!");
163-
return false;
164-
}
40+
// Standard Debugging variables
41+
private static final String LCAT = "TiWebDialog";
42+
43+
private List<String> getCustomTabBrowsers(Context context, List<ResolveInfo> browsersList)
44+
{
45+
List<String> customTabBrowsers = new ArrayList<String>();
46+
47+
for (ResolveInfo info : browsersList) {
48+
String packageName = info.activityInfo.packageName;
49+
50+
Intent intent = new Intent();
51+
intent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
52+
intent.setPackage(packageName);
53+
54+
if (context.getPackageManager().resolveService(intent, 0) != null) {
55+
customTabBrowsers.add(packageName);
56+
}
57+
}
58+
59+
return customTabBrowsers;
60+
}
61+
62+
private void openCustomTab(Context context, List<String> customTabBrowsers, KrollDict options)
63+
{
64+
String URL = options.getString(Params.URL);
65+
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
66+
builder.setShowTitle(Utils.getBool(options, Params.SHOW_TITLE));
67+
68+
int barColor = Utils.getColor(options, Params.BAR_COLOR);
69+
if (barColor != -1) {
70+
builder.setToolbarColor(barColor);
71+
}
72+
73+
// set start and exit animations
74+
if (Utils.getBool(options, Params.FADE_TRANSITION)) {
75+
builder.setStartAnimations(context, android.R.anim.fade_in, android.R.anim.fade_out);
76+
builder.setExitAnimations(context, android.R.anim.fade_in, android.R.anim.fade_out);
77+
}
78+
79+
// hide navigation bar on scroll
80+
if (Utils.getBool(options, Params.BAR_COLLAPSING_ENABLED)) {
81+
builder.enableUrlBarHiding();
82+
}
83+
84+
//enable Share link option
85+
if (Utils.getBool(options, Params.ENABLE_SHARING)) {
86+
builder.addDefaultShareMenuItem();
87+
}
88+
89+
String closeIcon = Utils.getString(options, Params.CLOSE_ICON);
90+
if (!closeIcon.isEmpty()) {
91+
builder.setCloseButtonIcon(getIcon(closeIcon));
92+
}
93+
94+
CustomTabsIntent tabIntent = builder.build();
95+
96+
for (String s : customTabBrowsers) {
97+
tabIntent.intent.setPackage(s);
98+
}
99+
100+
tabIntent.launchUrl(context, Uri.parse(URL));
101+
}
102+
103+
private Bitmap getIcon(String path)
104+
{
105+
Bitmap resultBitmap = null;
106+
107+
if (path != null && !path.trim().equalsIgnoreCase("")) {
108+
String resourceIcon = path.replaceAll(".png", "");
109+
resourceIcon = "drawable." + resourceIcon;
110+
111+
int resource = Utils.getR(resourceIcon);
112+
113+
if (resource == 0) {
114+
TiUrl imageUrl = new TiUrl(path);
115+
TiFileHelper tfh = new TiFileHelper(TiApplication.getInstance());
116+
Drawable d = tfh.loadDrawable(imageUrl.resolve(), false);
117+
118+
resultBitmap = ((BitmapDrawable) d).getBitmap();
119+
120+
} else {
121+
resultBitmap =
122+
BitmapFactory.decodeResource(TiApplication.getAppRootOrCurrentActivity().getResources(), resource);
123+
}
124+
}
125+
126+
// important step to show close icon
127+
// rescale bitmap to 24dp(Height) x 48dp(Width) as mentioned here, otherwise it won't work
128+
// https://developer.chrome.com/multidevice/android/customtabs#choosing-an icon for the action button
129+
if (resultBitmap != null) {
130+
resultBitmap = Utils.rescaleBitmap(TiApplication.getAppRootOrCurrentActivity(), resultBitmap, 24, 48);
131+
}
132+
133+
return resultBitmap;
134+
}
135+
136+
@Kroll.method
137+
public void open(KrollDict options)
138+
{
139+
if ((options != null) && options.containsKeyAndNotNull(Params.URL)) {
140+
Context context = TiApplication.getAppCurrentActivity();
141+
List<ResolveInfo> browsersList = Utils.allBrowsers(context);
142+
143+
KrollDict event = new KrollDict();
144+
145+
event.put("success", !browsersList.isEmpty());
146+
event.put("url", options.getString(Params.URL));
147+
148+
if (!browsersList.isEmpty()) {
149+
List<String> customTabBrowsers = getCustomTabBrowsers(context, browsersList);
150+
151+
// show supported browsers list or open directly if only 1 supported browser is available
152+
openCustomTab(context, customTabBrowsers, options);
153+
154+
} else {
155+
Log.i(Params.LCAT, "No browsers available in this device.");
156+
}
157+
158+
fireEvent("open", event);
159+
}
160+
}
161+
162+
@Kroll.method
163+
public boolean isSupported()
164+
{
165+
Context context = TiApplication.getAppCurrentActivity();
166+
List<ResolveInfo> browsersList = Utils.allBrowsers(context);
167+
168+
return !browsersList.isEmpty();
169+
}
170+
171+
@Kroll.method
172+
public void close(KrollDict options)
173+
{
174+
Log.e(Params.LCAT, "The \"close\" method is not implemented on Android, yet!");
175+
}
176+
177+
@Kroll.method
178+
public boolean isOpen(KrollDict options)
179+
{
180+
Log.e(Params.LCAT, "The \"isOpen\" method is not implemented on Android, yet!");
181+
return false;
182+
}
165183
}

0 commit comments

Comments
 (0)