本文整理汇总了Java中org.appcelerator.kroll.annotations.Kroll类的典型用法代码示例。如果您正苦于以下问题:Java Kroll类的具体用法?Java Kroll怎么用?Java Kroll使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Kroll类属于org.appcelerator.kroll.annotations包,在下文中一共展示了Kroll类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
@Kroll.method
public void start()
{
setState(STATE_RUNNING);
// App opens analytics
ParseAnalytics.trackAppOpenedInBackground(TiApplication.getAppRootOrCurrentActivity().getIntent());
ParseInstallation.getCurrentInstallation().put("androidId", getAndroidId());
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e != null) {
Log.e(TAG, "Installation initialization failed: " + e.getMessage());
}
// fire event
try {
JSONObject pnData = new JSONObject();
pnData.put("objectId", getObjectId());
pnData.put("installationId", getCurrentInstallationId());
KrollDict data = new KrollDict(pnData);
module.fireEvent("installationId", data);
} catch (JSONException e1) {
Log.e(TAG, "InstallationId event failed: " + e1.getMessage());
}
}
});
}
示例2: openURL
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
@Kroll.method
public boolean openURL(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);
return true;
} else {
Log.i(Params.LCAT, "No browsers available in this device.");
return false;
}
}
Log.i(Params.LCAT, "Check your paramters. URL parameter is mandatory.");
return false;
}
示例3: setHtml
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
@Kroll.method
public void setHtml(String html, @Kroll.argument(optional = true) KrollDict d)
{
setProperty(TiC.PROPERTY_HTML, html);
setProperty(OPTIONS_IN_SETHTML, d);
// If the web view has not been created yet, don't set html here. It will be set in processProperties() when the
// view is created.
TiUIView v = peekView();
if (v != null) {
if (TiApplication.isUIThread()) {
((TiUIWebView) v).setHtml(html, d);
} else {
getMainHandler().sendEmptyMessage(MSG_SET_HTML);
}
}
}
示例4: clearSchedule
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
@Kroll.method
public void clearSchedule() {
TiApplication app = TiApplication.getInstance();
int ntfCount = app.getAppProperties().getInt(PROPERTY_NOTIFICATION_COUNTER, 0);
Log.d(TAG, "Clearing " + ntfCount + " notifications");
if(ntfCount > 0) {
Intent intent = new Intent(app.getApplicationContext(), NotificationPublisher.class);
for(int i = 0; i < ntfCount; i++) {
PendingIntent pendingIntent = PendingIntent.getBroadcast(app.getApplicationContext(), i, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager)app.getApplicationContext().getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
pendingIntent.cancel();
}
app.getAppProperties().setInt(PROPERTY_NOTIFICATION_COUNTER, 0);
}
}
示例5: schedule
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
@Kroll.method
public void schedule(long time, HashMap data) {
TiApplication app = TiApplication.getInstance();
int ntfId = app.getAppProperties().getInt(PROPERTY_NOTIFICATION_COUNTER, 0);
Log.d(TAG, "Scheduling notification " + ntfId + " at " + time);
Intent intent = new Intent(app.getApplicationContext(), NotificationPublisher.class);
intent.putExtra(PROPERTY_NOTIFICATION_DATA, data);
PendingIntent pendingIntent = PendingIntent.getBroadcast(app.getApplicationContext(), ntfId, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager)app.getApplicationContext().getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
app.getAppProperties().setInt(PROPERTY_NOTIFICATION_COUNTER, ntfId+1);
}
示例6: hasPermission
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
/**
* check, if given permission is currently granted
*
* @param requestedPermission - permission as defined in Manifest
* @return
*/
@Kroll.method
public boolean hasPermission(@Kroll.argument() String requestedPermission) {
Log.d(LCAT, "check for granted permission: " + requestedPermission);
// TODO really depends on Build or Platform???
if (Build.VERSION.SDK_INT < 23) {
return true;
}
Context ctx = TiApplication.getInstance().getApplicationContext();
if (ContextCompat.checkSelfPermission(ctx,
requestedPermission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
return true;
}
示例7: requestPermission
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
/**
* Request a permission and optionally register a callback for the current activity
*
* @param requestedPermission permission as defined in Manifest
* @param permissionCallback function called with result of permission prompt
* @param requestCode - 8 Bit value to associate callback with request - if none is provided a system generated will used
* @return true in case of valid request, false if requested permission is not a valid one
*/
@Kroll.method
public boolean requestPermission(String requestedPermission,
@Kroll.argument(optional = true) KrollFunction permissionCallback,
@Kroll.argument(optional = true) Integer requestCode) {
Log.d(LCAT, "Requesting permission: " + requestedPermission);
if (!isValidPermissionString(requestedPermission)) {
Log.e(LCAT, "Requested permission is not supported :"
+ requestedPermission);
return false;
}
return handleRequest(new String[]{requestedPermission}, requestCode, permissionCallback);
}
示例8: requestPermissions
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
/**
* Request a permission and optionally register a callback for the current activity
*
* @param requestedPermissions Array of permissions as defined in Manifest
* @param permissionCallback function called with result of permission prompt
* @param requestCode - 8 Bit value to associate callback with request - if none is provided, a system generated one is used
* @return true in case of valid request, false if requested permission is not a valid one
*/
@Kroll.method
public boolean requestPermissions(@Kroll.argument String[] requestedPerms,
@Kroll.argument(optional = true) KrollFunction permissionCallback,
@Kroll.argument(optional = true) Integer requestCode)
{
// String[] requestedPermissions = new String[]{requestedPerms};//(String[])requestedPerms;
for(String permission:requestedPerms) {
Log.d(LCAT, "Requesting permission: " + permission);
if (!isValidPermissionString(permission)) {
Log.e(LCAT, "Requested permission is not supported :"
+ permission);
return false;
}
}
return handleRequest(requestedPerms, requestCode, permissionCallback);
}
示例9: registerForPushNotifications
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
@Kroll.method
public void registerForPushNotifications(HashMap options) {
Activity activity = TiApplication.getAppRootOrCurrentActivity();
if (false == options.containsKey("callback")) {
Log.e(LCAT, "You have to specify a callback attribute when calling registerForPushNotifications");
return;
}
messageCallback = (KrollFunction)options.get("callback");
successCallback = options.containsKey("success") ? (KrollFunction)options.get("success") : null;
errorCallback = options.containsKey("error") ? (KrollFunction)options.get("error") : null;
parseBootIntent();
if (checkPlayServices()) {
activity.startService( new Intent(activity, RegistrationIntentService.class) );
}
}
示例10: unregisterForPushNotifications
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
@Kroll.method
public void unregisterForPushNotifications() {
final String senderId = getSenderId();
final Context context = TiApplication.getInstance().getApplicationContext();
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
InstanceID.getInstance(context).deleteToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE);
Log.d(LCAT, "delete instanceid succeeded");
} catch (final IOException e) {
Log.e(LCAT, "remove token failed - error: " + e.getMessage());
}
return null;
}
}.execute();
}
示例11: onAppCreate
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
@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
// Store a reference to the parse singleton now that the app is ready
parseSingleton = ParseSingleton.Instance();
// Obtain the application and client keys from the tiapp.xml file.
// It must be stored there because of the way Android applications work,
// we can't initialize the module during runtime because the application is
// started when a push notification is received
String propertyAppId = app.getAppProperties().getString(ParseSingleton.PROPERTY_APP_ID, "");
String propertyClientKey = app.getAppProperties().getString(ParseSingleton.PROPERTY_CLIENT_KEY, "");
String propertyServerUrl = app.getAppProperties().getString(ParseSingleton.PROPERTY_SERVER_URL, "");
// Invoke the Parse SDK Initialize method
//parseSingleton.InitializeParse(propertyAppId, propertyClientKey, app);
parseSingleton.InitializeParseWithConfig(propertyAppId, propertyClientKey, propertyServerUrl, app);
}
示例12: updateObject
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
@Kroll.method
public void updateObject(final HashMap data, final KrollFunction applicationCallback) {
final ParseObject convertedObject = (ParseObject)ParseDataConversions.ConvertToParseObjectIfNecessary(data);
SaveCallback parseCallback = new SaveCallback() {
public void done(ParseException e) {
HashMap result = new HashMap();
HashMap returnObject = ParseDataConversions.ObjectToHashMap(convertedObject);
if (e == null) {
result.put("object", returnObject);
} else {
// There was an error
result.put("error", e.toString());
}
if (applicationCallback != null) {
applicationCallback.callAsync(getKrollObject(), result);
}
}
};
parseSingleton.UpdateDataObject(convertedObject, parseCallback);
}
示例13: deleteObject
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
@Kroll.method
public void deleteObject(String className, String objectId, final KrollFunction applicationCallback) {
DeleteCallback parseCallback = new DeleteCallback() {
public void done(ParseException e) {
HashMap result = new HashMap();
if (e == null) {
result.put("success", true);
} else {
result.put("error", e.toString());
}
applicationCallback.callAsync(getKrollObject(), result);
}
};
parseSingleton.DeleteDataObject(className, objectId, parseCallback);
}
示例14: registerForMultiplePushChannelString
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
@Kroll.method
public void registerForMultiplePushChannelString(String deviceToken, String channels, KrollFunction applicationCallback) {
Log.d(LCAT, "String String Callback");
Log.d(LCAT, channels);
String[] channelNames = channels.split(",");
for ( String s: channelNames){
Log.d(LCAT, s);
}
registerForMultiplePushChannelArray(deviceToken, channelNames, applicationCallback);
// NOTE: deviceToken is not used, but in order to maintain call
// compatibility with the iOS module, I'm leaving it as a parameter
//parseSingleton.SubscribeToMultiplePushChannel(channelName);
// This is just a fake call back function the saveEventually() function will be used and no need for callback
//HashMap results = new HashMap();
//results.put("success", true);
//applicationCallback.callAsync(getKrollObject(), results);
}
示例15: pushChannelList
import org.appcelerator.kroll.annotations.Kroll; //导入依赖的package包/类
@Kroll.method
public void pushChannelList(KrollFunction applicationCallback) {
HashMap results = new HashMap();
List<String> channelList = parseSingleton.ChannelSubscriptionList();
String[] channels = new String[channelList.size()];
int count = 0;
for (String channelName : channelList) {
channels[count] = channelName;
++count;
}
// Store the resulting string list under the 'channels' field for the Titanium App
results.put("channels", channels);
applicationCallback.callAsync(getKrollObject(), results);
}