-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e54d825
commit 184ff71
Showing
18 changed files
with
201 additions
and
165 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
metadata.json | ||
*.zip | ||
*.xcworkspace/ | ||
*.xcuserstate | ||
xcuserdata/ | ||
build/ | ||
/android/dist |
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,10 @@ | ||
"/Users/hknoechel/Documents/appcelerator_modules/titanium-web-dialog/android/src/ti/webdialog/Params.java" | ||
"/Users/hknoechel/Documents/appcelerator_modules/titanium-web-dialog/android/src/ti/webdialog/TitaniumWebDialogModule.java" | ||
"/Users/hknoechel/Documents/appcelerator_modules/titanium-web-dialog/android/src/ti/webdialog/Utils.java" | ||
"/Users/hknoechel/Documents/appcelerator_modules/titanium-web-dialog/android/build/generated/java/ti/webdialog/TitaniumWebDialogBootstrap.java" | ||
"/Users/hknoechel/Documents/appcelerator_modules/titanium-web-dialog/android/build/generated/r/android/support/compat/R.java" | ||
"/Users/hknoechel/Documents/appcelerator_modules/titanium-web-dialog/android/build/generated/r/android/support/design/R.java" | ||
"/Users/hknoechel/Documents/appcelerator_modules/titanium-web-dialog/android/build/generated/r/android/support/v7/appcompat/R.java" | ||
"/Users/hknoechel/Documents/appcelerator_modules/titanium-web-dialog/android/build/generated/r/android/support/v7/cardview/R.java" | ||
"/Users/hknoechel/Documents/appcelerator_modules/titanium-web-dialog/android/build/generated/r/ti/modules/titanium/ui/R.java" | ||
"/Users/hknoechel/Documents/appcelerator_modules/titanium-web-dialog/android/build/generated/r/ti/webdialog/R.java" |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 was deleted.
Oops, something went wrong.
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,9 @@ | ||
package ti.webdialog; | ||
|
||
public class Params { | ||
public static final String LCAT = "TiChromeDialog"; | ||
public static final String SHOW_TITLE = "showTitle"; | ||
public static final String URL = "url"; | ||
public static final String BAR_COLOR = "barColor"; | ||
public static final String FADE_TRANSITION = "fadeTransition"; | ||
} |
143 changes: 98 additions & 45 deletions
143
android/src/ti/webdialog/TitaniumWebDialogModule.java
100644 → 100755
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 |
---|---|---|
@@ -1,65 +1,118 @@ | ||
/** | ||
* This file was auto-generated by the Titanium Module SDK helper for Android | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-2017 by Appcelerator, Inc. All Rights Reserved. | ||
* Copyright (c) 2009-present by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
* | ||
*/ | ||
package ti.webdialog; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.appcelerator.kroll.KrollDict; | ||
import org.appcelerator.kroll.KrollModule; | ||
import org.appcelerator.kroll.annotations.Kroll; | ||
|
||
import org.appcelerator.titanium.TiApplication; | ||
import org.appcelerator.kroll.common.Log; | ||
import org.appcelerator.kroll.common.TiConfig; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.ResolveInfo; | ||
import android.net.Uri; | ||
import android.support.customtabs.CustomTabsIntent; | ||
import android.support.customtabs.CustomTabsService; | ||
|
||
|
||
@Kroll.module(name="TitaniumWebDialog", id="ti.webdialog") | ||
public class TitaniumWebDialogModule extends KrollModule | ||
{ | ||
// Standard Debugging variables | ||
private static final String LCAT = "TiWebDialog"; | ||
|
||
private List<String> getCustomTabBrowsers(Context context, List<ResolveInfo> browsersList) { | ||
List<String> customTabBrowsers = new ArrayList<String>(); | ||
|
||
for (ResolveInfo info : browsersList) { | ||
String packageName = info.activityInfo.packageName; | ||
|
||
Intent intent = new Intent(); | ||
intent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION); | ||
intent.setPackage(packageName); | ||
|
||
if (context.getPackageManager().resolveService(intent, 0) != null) { | ||
customTabBrowsers.add(packageName); | ||
} | ||
} | ||
|
||
return customTabBrowsers; | ||
} | ||
|
||
private void openCustomTab(Context context, List<String> customTabBrowsers, KrollDict options) { | ||
String URL = options.getString(Params.URL); | ||
URL = URL.toLowerCase(); | ||
|
||
if (!URL.startsWith("http")) { | ||
URL = "http://" + URL; | ||
} | ||
|
||
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); | ||
builder.setShowTitle(Utils.getBool(options, Params.SHOW_TITLE)); | ||
|
||
int barColor = Utils.getColor(options, Params.BAR_COLOR); | ||
if (barColor != -1) { | ||
builder.setToolbarColor(barColor); | ||
} | ||
|
||
// set start and exit animations | ||
if (Utils.getBool(options, Params.FADE_TRANSITION)) { | ||
builder.setStartAnimations(context, android.R.anim.fade_in, android.R.anim.fade_out); | ||
builder.setExitAnimations(context, android.R.anim.fade_in, android.R.anim.fade_out); | ||
} | ||
|
||
CustomTabsIntent tabIntent = builder.build(); | ||
|
||
for(String s:customTabBrowsers) { | ||
tabIntent.intent.setPackage(s); | ||
} | ||
|
||
tabIntent.launchUrl(context, Uri.parse(URL)); | ||
} | ||
|
||
@Kroll.method | ||
public void open(KrollDict options) { | ||
if ((options != null) && options.containsKeyAndNotNull(Params.URL)) { | ||
Context context = TiApplication.getAppCurrentActivity(); | ||
List<ResolveInfo> browsersList = Utils.allBrowsers(context); | ||
|
||
if (!browsersList.isEmpty()) { | ||
List<String> customTabBrowsers = getCustomTabBrowsers(context, browsersList); | ||
|
||
// show supported browsers list or open directly if only 1 supported browser is available | ||
openCustomTab(context, customTabBrowsers, options); | ||
} else { | ||
Log.i(Params.LCAT, "No browsers available in this device."); | ||
} | ||
} | ||
} | ||
|
||
// Standard Debugging variables | ||
private static final String LCAT = "TitaniumWebDialogModule"; | ||
private static final boolean DBG = TiConfig.LOGD; | ||
|
||
// You can define constants with @Kroll.constant, for example: | ||
// @Kroll.constant public static final String EXTERNAL_NAME = value; | ||
|
||
public TitaniumWebDialogModule() | ||
{ | ||
super(); | ||
} | ||
|
||
@Kroll.onAppCreate | ||
public static void onAppCreate(TiApplication app) | ||
{ | ||
Log.d(LCAT, "inside onAppCreate"); | ||
// put module init code that needs to run when the application is created | ||
} | ||
|
||
// Methods | ||
@Kroll.method | ||
public String example() | ||
{ | ||
Log.d(LCAT, "example called"); | ||
return "hello world"; | ||
} | ||
|
||
// Properties | ||
@Kroll.getProperty | ||
public String getExampleProp() | ||
{ | ||
Log.d(LCAT, "get example property"); | ||
return "hello world"; | ||
} | ||
|
||
|
||
@Kroll.setProperty | ||
public void setExampleProp(String value) { | ||
Log.d(LCAT, "set example property: " + value); | ||
} | ||
|
||
@Kroll.method | ||
public boolean isSupported() { | ||
Context context = TiApplication.getAppCurrentActivity(); | ||
List<ResolveInfo> browsersList = Utils.allBrowsers(context); | ||
|
||
return !browsersList.isEmpty(); | ||
} | ||
|
||
@Kroll.method | ||
public void close(KrollDict options) { | ||
Log.e(Params.LCAT, "The \"close\" method is not implemented, yet!"); | ||
} | ||
|
||
@Kroll.method | ||
public boolean isOpen(KrollDict options) { | ||
Log.e(Params.LCAT, "The \"isOpen\" method is not implemented, yet!"); | ||
return false; | ||
} | ||
} | ||
|
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,63 @@ | ||
package ti.webdialog; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.List; | ||
|
||
import org.appcelerator.kroll.KrollDict; | ||
import org.appcelerator.titanium.util.TiRHelper; | ||
import org.appcelerator.titanium.util.TiConvert; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.ResolveInfo; | ||
import android.net.Uri; | ||
|
||
public class Utils { | ||
public static int getR(String path) { | ||
try { | ||
return TiRHelper.getResource(path); | ||
|
||
} catch (Exception exc) { | ||
return -1; | ||
} | ||
} | ||
|
||
public static int[] getStyleableIntArray(String packageName, String name) { | ||
try { | ||
Field[] fields2 = Class.forName(packageName + ".R$styleable" ).getFields(); | ||
|
||
for (Field f : fields2) { | ||
if ( f.getName().equals( name ) ) { | ||
int[] ret = (int[])f.get( null ); | ||
return ret; | ||
} | ||
} | ||
} catch ( Throwable t ) {} | ||
|
||
return null; | ||
} | ||
|
||
// return the list of all available & enabled browsers in device | ||
public static List<ResolveInfo> allBrowsers(Context context) { | ||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.testingurl.com")); | ||
return context.getPackageManager().queryIntentActivities(intent, 0); | ||
} | ||
|
||
public static String getString(KrollDict options, String key) { | ||
String value = "" + (options.containsKeyAndNotNull(key) ? options.get(key) : ""); | ||
return value.trim(); | ||
} | ||
|
||
public static boolean getBool(KrollDict options, String key) { | ||
return (Boolean) (options.containsKeyAndNotNull(key) ? options.get(key) : false); | ||
} | ||
|
||
public static int getColor(KrollDict options, String key) { | ||
if (options.containsKeyAndNotNull(key)) { | ||
return TiConvert.toColor( (String) options.get(key)); | ||
|
||
} else { | ||
return getR("color.colorPrimary"); | ||
} | ||
} | ||
} |
Oops, something went wrong.