org.appcelerator.kroll.KrollFunction Java Examples

The following examples show how to use org.appcelerator.kroll.KrollFunction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TiGooshModule.java    From ti.goosh with MIT License 6 votes vote down vote up
@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) );
	}
}
 
Example #2
Source File: CaffeinaGCMModule.java    From gcm with MIT License 5 votes vote down vote up
@Kroll.method
@SuppressWarnings("unchecked")
public void registerForPushNotifications(HashMap options) {
	String senderId = (String)options.get("senderId");

	successCallback = (KrollFunction)options.get("success");
	errorCallback = (KrollFunction)options.get("error");
	messageCallback = (KrollFunction)options.get("callback");

	if (senderId != null) {
		GCMRegistrar.register(TiApplication.getInstance(), senderId);
	} else {
		sendError("No GCM senderId specified; get it from the Google Play Developer Console");
	}
}
 
Example #3
Source File: GCMModule.java    From gcmpush with Apache License 2.0 5 votes vote down vote up
@Kroll.method
@SuppressWarnings("unchecked")
public void registerPush(HashMap options) {

    Log.d(LCAT, "registerPush called");

    String senderId = (String) options.get("senderId");
    Map<String, Object> notificationSettings = (Map<String, Object>) options.get("notificationSettings");
    successCallback = (KrollFunction) options.get("success");
    errorCallback = (KrollFunction) options.get("error");
    messageCallback = (KrollFunction) options.get("callback");

    /* Store notification settings in global Ti.App properties */
    JSONObject json = new JSONObject(notificationSettings);
    TiApplication.getInstance().getAppProperties().setString(GCMModule.NOTIFICATION_SETTINGS, json.toString());

    if (senderId != null) {
        GCMRegistrar.register(TiApplication.getInstance(), senderId);

        String registrationId = getRegistrationId();
        if (registrationId != null && registrationId.length() > 0) {
            sendSuccess(registrationId);
        }
    } else {
        sendError(errorCallback, "No GCM senderId specified; get it from the Google Play Developer Console");
    }
}
 
Example #4
Source File: GCMModule.java    From gcmpush with Apache License 2.0 5 votes vote down vote up
@Kroll.method
public void unsubscribe(final HashMap options) {
    // unsubscripe from a topic
    final String senderId = (String) options.get("senderId");
    final String topic  = (String) options.get("topic");
    final KrollFunction callback = (KrollFunction) options.get("callback");

    if (topic == null || !topic.startsWith("/topics/")) {
        Log.e(LCAT, "No or invalid topic specified, should start with /topics/");
    }

    if (senderId != null) {
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                try {
                    String token = getToken(senderId);
                    if (token != null) {
                        GcmPubSub.getInstance(TiApplication.getInstance()).unsubscribe(token, topic);

                        if (callback != null) {
                            // send success callback
                            HashMap<String, Object> data = new HashMap<String, Object>();
                            data.put("success", true);
                            data.put("topic", topic);
                            data.put("token", token);
                            callback.callAsync(getKrollObject(), data);
                        }
                    } else {
                        sendError(callback, "Cannot unsubscribe from topic " + topic);
                    }
                } catch (Exception ex) {
                    sendError(callback, "Cannot unsubscribe from topic " + topic + ": " + ex.getMessage());
                }
                return null;
            }
        }.execute();
    }
}
 
Example #5
Source File: GCMModule.java    From gcmpush with Apache License 2.0 5 votes vote down vote up
public void sendError(KrollFunction callback, String error) {
    Log.e(LCAT, error);
    if (callback != null) {
        HashMap<String, Object> data = new HashMap<String, Object>();
        data.put("success", false);
        data.put("error", error);

        callback.callAsync(getKrollObject(), data);
    }
}
 
Example #6
Source File: GalleryResultHandler.java    From titanium-imagepicker with Apache License 2.0 4 votes vote down vote up
public GalleryResultHandler(KrollFunction callback, KrollObject obj) {
	this.callback = callback;
	this.krollObject = obj;
}
 
Example #7
Source File: GalleryResultHandler.java    From titanium-imagepicker with Apache License 2.0 4 votes vote down vote up
public GalleryResultHandler(KrollFunction callback, KrollObject obj) {
	this.callback = callback;
	this.krollObject = obj;
}