Example usage for android.app Application getApplicationContext

List of usage examples for android.app Application getApplicationContext

Introduction

In this page you can find the example usage for android.app Application getApplicationContext.

Prototype

@Override
    public Context getApplicationContext() 

Source Link

Usage

From source file:Main.java

public static void initialize(Application app) {
    mApplicationContent = app.getApplicationContext();
}

From source file:Main.java

public static void setContext(Application app) {
    context = app.getApplicationContext();
}

From source file:com.linkedin.android.shaky.Shaky.java

/**
 * Entry point into this API./*from w  w  w .j av a 2s.  com*/
 *
 * Registers shaky to the current application.
 */
@NonNull
public static Shaky with(@NonNull Application application, @NonNull ShakeDelegate delegate) {
    Shaky shaky = new Shaky(application.getApplicationContext(), delegate);
    LifecycleCallbacks lifecycleCallbacks = new LifecycleCallbacks(shaky);
    application.registerActivityLifecycleCallbacks(lifecycleCallbacks);
    return shaky;
}

From source file:org.onepf.opfiab.OPFIab.java

/**
 * Initialize OPFIab library with supplied configuration.
 * <p>/*from   w w w.j av a  2  s  .c o m*/
 * It's strongly recommended to call this method from {@link Application#onCreate()}.
 * <p>
 * Subsequent calls are supported but will reset any previous setup state.
 *
 * @param application   Application object to add {@link Application.ActivityLifecycleCallbacks}
 *                      to and to use as {@link Context}.
 * @param configuration Configuration object to use.
 */
@SuppressFBWarnings({ "LI_LAZY_INIT_UPDATE_STATIC", "LI_LAZY_INIT_STATIC" })
public static void init(@NonNull final Application application, @NonNull final Configuration configuration) {
    OPFLog.logMethod(configuration);
    OPFChecks.checkThread(true);
    OPFIab.context = application.getApplicationContext();

    final BillingBase billingBase = BillingBase.getInstance();
    final BillingRequestScheduler scheduler = BillingRequestScheduler.getInstance();
    final Set<BillingProvider> providers = configuration.getProviders();
    if (OPFIab.configuration == null) {
        // first init
        final ActivityMonitor activityMonitor = ActivityMonitor.getInstance(context);
        application.registerActivityLifecycleCallbacks(activityMonitor);
        register(billingBase, Integer.MAX_VALUE);
        register(SetupManager.getInstance(application));
        register(scheduler);
        register(activityMonitor);
        register(BillingEventDispatcher.getInstance());
    } else {
        for (final BillingProvider provider : OPFIab.configuration.getProviders()) {
            unregister(provider);
        }
    }
    OPFIab.configuration = configuration;

    for (final BillingProvider provider : providers) {
        provider.checkManifest();
        register(provider);
    }

    scheduler.dropQueue();
    billingBase.setConfiguration(configuration);
}

From source file:com.popdeem.sdk.core.PopdeemSDK.java

/**
 * Initialize Popdeem SDK/* w w w.j  a  v  a2 s.  co  m*/
 *
 * @param application Application context
 * @param enviroment Popdeem enviroment PD_PROD_API_ENDPOINT, PD_STAGING_API_ENDPOINT
 *
 */
public static void initializeSDK(@NonNull final Application application, String enviroment) {

    application.registerReceiver(mLoggedInBroadcastReceiver, new IntentFilter(PD_LOGGED_IN_RECEIVER_FILTER));

    PDAPIConfig.PD_API_ENDPOINT = enviroment;
    sApplication = application;

    // Register Activity Lifecycle Callbacks
    application.registerActivityLifecycleCallbacks(PD_ACTIVITY_LIFECYCLE_CALLBACKS);

    // Init Realm
    PDRealmUtils.initRealmDB(application);

    TwitterAuthConfig authConfig = PDSocialUtils.getTwitterAuthConfig(application.getApplicationContext());

    TwitterConfig config = new TwitterConfig.Builder(application).logger(new DefaultLogger(Log.DEBUG))
            .twitterAuthConfig(authConfig).debug(true).build();
    Twitter.initialize(config);

    // Get Popdeem API Key
    getPopdeemAPIKey();
    FacebookSdk.sdkInitialize(application, new FacebookSdk.InitializeCallback() {
        @Override
        public void onInitialized() {
            Log.i("Facebook", "onInitialized: Facebook initialized");
        }
    });

    sdkInitialized = true;

    PDAPIClient.instance().getCustomer(new PDAPICallback<JsonObject>() {
        @Override
        public void success(JsonObject jsonObject) {
            Log.i("JsonObject", "success: ");
            if (jsonObject.has("customer")) {
                JsonObject customer = jsonObject.getAsJsonObject("customer");
                PDRealmCustomer realmCustomer = PDRealmCustomer.fromJson(customer);

                Realm realm = Realm.getDefaultInstance();
                realm.beginTransaction();
                RealmResults<PDRealmCustomer> results = realm.where(PDRealmCustomer.class).findAll();
                results.deleteAllFromRealm();
                realm.copyToRealm(realmCustomer);
                realm.commitTransaction();
                realm.close();
                initFromCustomer(application);

            }
        }

        @Override
        public void failure(int statusCode, Exception e) {
            e.printStackTrace();
            initFromCustomer(application);

        }
    });

    // Get UID for Non Social login
    if (PDUniqueIdentifierUtils.getUID() == null) {
        PDUniqueIdentifierUtils.createUID(application, new PDUniqueIdentifierUtils.PDUIDCallback() {
            @Override
            public void success(String uid) {
                PDRealmNonSocialUID uidReam = new PDRealmNonSocialUID();
                //                    uidReam.setId(0);
                uidReam.setRegistered(false);
                uidReam.setUid(uid);

                Realm realm = Realm.getDefaultInstance();
                realm.beginTransaction();
                realm.copyToRealmOrUpdate(uidReam);
                realm.commitTransaction();
                realm.close();

                registerNonSocialUser();
            }

            @Override
            public void failure(String message) {
                PDLog.d(PDUniqueIdentifierUtils.class, "failed to create uid: " + message);
            }
        });
    }

    // Init GCM
    PDFirebaseMessagingService.initGCM(application, new PDGCMUtils.PDGCMRegistrationCallback() {
        @Override
        public void success(String registrationToken) {
            PDLog.d(PDGCMUtils.class, "Init GCM success. Registration token: " + registrationToken);
            registerNonSocialUser();
        }

        @Override
        public void failure(String message) {
            PDLog.d(PDGCMUtils.class, "Init GCM failure: " + message);
        }
    });

}

From source file:com.localytics.LocalyticsModule.java

/*******************
 * Automatic Integration//from  ww  w.  j a  v a2 s . c o  m
 ******************/

@Kroll.method
public void autoIntegrate() {
    Application app = TiApplication.getInstance();
    app.registerActivityLifecycleCallbacks(
            new LocalyticsActivityLifecycleCallbacks(app.getApplicationContext()));
}

From source file:io.mapsquare.osmcontributor.ui.utils.BitmapHandler.java

@Inject
public BitmapHandler(Application osmTemplateApplication) {
    context = osmTemplateApplication.getApplicationContext();

    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    // Use 1/5th of the available memory for this memory cache.
    final int cacheSize = maxMemory / 5;

    cache = new LruCache<String, Bitmap>(cacheSize) {
        @Override//www. ja  va2s . co m
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in kilobytes rather than items count
            return bitmap.getByteCount() / 1024;
        }
    };

    icons.put("administrative", R.drawable.administrative);
    icons.put("animal_shelter", R.drawable.pet2);
    icons.put("antique", R.drawable.archaeological);
    icons.put("gallery", R.drawable.art_gallery2);
    icons.put("boat_sharing", R.drawable.sailing);
    icons.put("books", R.drawable.library);
    icons.put("boutique", R.drawable.convenience);
    icons.put("brothel", R.drawable.hotel2);
    icons.put("bureau_de_change", R.drawable.currency_exchange);
    icons.put("camp_site", R.drawable.camping);
    icons.put("car_wash", R.drawable.ford);
    icons.put("car_sharing", R.drawable.car_share);
    icons.put("clinic", R.drawable.doctors2);
    icons.put("arts_centre", R.drawable.art_gallery2);
    icons.put("dry_cleaning", R.drawable.laundrette);
    icons.put("archaeological_site", R.drawable.archaeological2);
    icons.put("farm", R.drawable.marketplace);
    icons.put("variety_store", R.drawable.convenience);
    icons.put("food_court", R.drawable.marketplace);
    icons.put("fort", R.drawable.castle2);
    icons.put("general", R.drawable.department_store);
    icons.put("hardware", R.drawable.mine);
    icons.put("doityourself", R.drawable.diy);
    icons.put("organic", R.drawable.greengrocer);
    icons.put("laundry", R.drawable.laundrette);
    icons.put("kindergarten", R.drawable.nursery3);
    icons.put("manor", R.drawable.house);
    icons.put("alpine_hut", R.drawable.alpinehut);
    icons.put("wilderness_hut", R.drawable.alpinehut);
    icons.put("ship", R.drawable.sailing);
    icons.put("music_venue", R.drawable.music);
    icons.put("music_venue", R.drawable.music);
    icons.put("nursing_home", R.drawable.hotel2);
    icons.put("optician", R.drawable.opticians);
    icons.put("viewpoint", R.drawable.photo);
    icons.put("crossing", R.drawable.zebra_crossing);
    icons.put("guest_house", R.drawable.bed_and_breakfast2);
    icons.put("photo_booth", R.drawable.photo);
    icons.put("picnic_site", R.drawable.picnic);
    icons.put("services", R.drawable.picnic);
    icons.put("public_bookcase", R.drawable.library);
    icons.put("register_office", R.drawable.administrative);
    icons.put("mini_roundabout", R.drawable.roundabout_anticlockwise);
    icons.put("ruins", R.drawable.ruin);
    icons.put("caravan_site", R.drawable.caravan_park);
    icons.put("tailor", R.drawable.clothes);
    icons.put("taxi", R.drawable.taxi_rank);
    icons.put("tomb", R.drawable.memorial);
    icons.put("travel_agency", R.drawable.aerodrome);
    icons.put("video", R.drawable.video_rental);
    icons.put("waste_basket", R.drawable.waste_bin);
    icons.put("waste_basket", R.drawable.waste_bin);
    icons.put("artwork", R.drawable.art_gallery);
    icons.put("aerodrome", R.drawable.aerodrome);
    icons.put("aircraft", R.drawable.aerodrome);
    icons.put("alcohol", R.drawable.bar);
    icons.put("atm", R.drawable.atm);
    icons.put("attraction", R.drawable.attraction);
    icons.put("bank", R.drawable.bank);
    icons.put("bar", R.drawable.bar);
    icons.put("bus_stop", R.drawable.bus_stop);
    icons.put("bicycle_parking", R.drawable.bicycle_parking);
    icons.put("bicycle_rental", R.drawable.bicycle_rental);
    icons.put("biergarten", R.drawable.biergarten);
    icons.put("cafe", R.drawable.cafe);
    icons.put("car_rental", R.drawable.car_rental);
    icons.put("church", R.drawable.place_of_worship);
    icons.put("cinema", R.drawable.cinema);
    icons.put("city", R.drawable.town);
    icons.put("commercial", R.drawable.mall);
    icons.put("courthouse", R.drawable.courthouse);
    icons.put("dentist", R.drawable.dentist);
    icons.put("doctors", R.drawable.doctors);
    icons.put("drinking_water", R.drawable.drinking_water);
    icons.put("embassy", R.drawable.embassy);
    icons.put("entrance", R.drawable.entrance);
    icons.put("fast_food", R.drawable.fast_food);
    icons.put("fire_station", R.drawable.fire_station);
    icons.put("fuel", R.drawable.fuel);
    icons.put("hamlet", R.drawable.town);
    icons.put("hospital", R.drawable.hospital);
    icons.put("hotel", R.drawable.hotel);
    icons.put("house", R.drawable.house);
    icons.put("housenumber", R.drawable.house);
    icons.put("hunting_stand", R.drawable.hunting_stand);
    icons.put("locality", R.drawable.town);
    icons.put("mall", R.drawable.mall);
    icons.put("nightclub", R.drawable.nightclub);
    icons.put("neighbourhood", R.drawable.house);
    icons.put("parking", R.drawable.parking);
    icons.put("pharmacy", R.drawable.pharmacy);
    icons.put("place_of_worship", R.drawable.place_of_worship);
    icons.put("police", R.drawable.police);
    icons.put("political", R.drawable.administrative);
    icons.put("primary", R.drawable.street);
    icons.put("prison", R.drawable.prison);
    icons.put("pub", R.drawable.pub);
    icons.put("recycling", R.drawable.recycling);
    icons.put("religious_administrative", R.drawable.place_of_worship);
    icons.put("residential", R.drawable.house);
    icons.put("restaurant", R.drawable.restaurant);
    icons.put("retail", R.drawable.mall);
    icons.put("road", R.drawable.street);
    icons.put("secondary", R.drawable.street);
    icons.put("stadium", R.drawable.stadium);
    icons.put("station", R.drawable.bus_stop);
    icons.put("street", R.drawable.street);
    icons.put("suburb", R.drawable.town);
    icons.put("subway_entrance", R.drawable.bus_stop);
    icons.put("supermarket", R.drawable.mall);
    icons.put("terminal", R.drawable.aerodrome);
    icons.put("tertiary", R.drawable.street);
    icons.put("theatre", R.drawable.theatre);
    icons.put("toilets", R.drawable.toilets);
    icons.put("town", R.drawable.town);
    icons.put("townhall", R.drawable.townhall);
    icons.put("track", R.drawable.street);
    icons.put("village", R.drawable.town);
    icons.put("phone", R.drawable.sos);
}

From source file:com.iternox.piggate.sdk.Piggate.java

public Piggate(Application app) {
    _app = app;
    internal_constructor(_context = app.getApplicationContext(), new PiggateEstimoteBridge(this));
}

From source file:io.jawg.osmcontributor.ui.utils.BitmapHandler.java

@Inject
public BitmapHandler(Application osmTemplateApplication) {
    context = osmTemplateApplication.getApplicationContext();

    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    // Use 1/5th of the available memory for this memory cache.
    final int cacheSize = maxMemory / 5;

    cache = new LruCache<String, Bitmap>(cacheSize) {
        @Override//from w  w w  .java 2  s  .c o  m
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in kilobytes rather than items count
            return bitmap.getByteCount() / 1024;
        }
    };

    icons.put("administrative", R.drawable.administrative);
    icons.put("animal_shelter", R.drawable.pet2);
    icons.put("antique", R.drawable.archaeological);
    icons.put("gallery", R.drawable.art_gallery2);
    icons.put("boat_sharing", R.drawable.sailing);
    icons.put("books", R.drawable.library);
    icons.put("boutique", R.drawable.convenience);
    icons.put("brothel", R.drawable.hotel2);
    icons.put("bureau_de_change", R.drawable.currency_exchange);
    icons.put("camp_site", R.drawable.camping);
    icons.put("car_wash", R.drawable.ford);
    icons.put("car_sharing", R.drawable.car_share);
    icons.put("clinic", R.drawable.doctors2);
    icons.put("arts_centre", R.drawable.art_gallery2);
    icons.put("dry_cleaning", R.drawable.laundrette);
    icons.put("archaeological_site", R.drawable.archaeological2);
    icons.put("farm", R.drawable.marketplace);
    icons.put("variety_store", R.drawable.convenience);
    icons.put("food_court", R.drawable.marketplace);
    icons.put("fort", R.drawable.castle2);
    icons.put("general", R.drawable.department_store);
    icons.put("hardware", R.drawable.mine);
    icons.put("doityourself", R.drawable.diy);
    icons.put("organic", R.drawable.greengrocer);
    icons.put("laundry", R.drawable.laundrette);
    icons.put("kindergarten", R.drawable.nursery3);
    icons.put("manor", R.drawable.house);
    icons.put("alpine_hut", R.drawable.alpinehut);
    icons.put("wilderness_hut", R.drawable.alpinehut);
    icons.put("ship", R.drawable.sailing);
    icons.put("music_venue", R.drawable.music);
    icons.put("music_venue", R.drawable.music);
    icons.put("nursing_home", R.drawable.hotel2);
    icons.put("optician", R.drawable.opticians);
    icons.put("viewpoint", R.drawable.photo);
    icons.put("crossing", R.drawable.zebra_crossing);
    icons.put("guest_house", R.drawable.bed_and_breakfast2);
    icons.put("photo_booth", R.drawable.photo);
    icons.put("picnic_site", R.drawable.picnic);
    icons.put("services", R.drawable.picnic);
    icons.put("public_bookcase", R.drawable.library);
    icons.put("register_office", R.drawable.administrative);
    icons.put("mini_roundabout", R.drawable.roundabout_anticlockwise);
    icons.put("ruins", R.drawable.ruin);
    icons.put("caravan_site", R.drawable.caravan_park);
    icons.put("tailor", R.drawable.clothes);
    icons.put("taxi", R.drawable.taxi_rank);
    icons.put("tomb", R.drawable.memorial);
    icons.put("travel_agency", R.drawable.aerodrome);
    icons.put("video", R.drawable.video_rental);
    icons.put("waste_basket", R.drawable.waste_bin);
    icons.put("waste_basket", R.drawable.waste_bin);
    icons.put("artwork", R.drawable.art_gallery);
    icons.put("aerodrome", R.drawable.aerodrome);
    icons.put("aircraft", R.drawable.aerodrome);
    icons.put("alcohol", R.drawable.bar);
    icons.put("atm", R.drawable.atm);
    icons.put("attraction", R.drawable.attraction);
    icons.put("bank", R.drawable.bank);
    icons.put("bar", R.drawable.bar);
    icons.put("bus_stop", R.drawable.bus_stop);
    icons.put("bicycle_parking", R.drawable.bicycle_parking);
    icons.put("bicycle_rental", R.drawable.bicycle_rental);
    icons.put("biergarten", R.drawable.biergarten);
    icons.put("cafe", R.drawable.cafe);
    icons.put("car_rental", R.drawable.car_rental);
    icons.put("church", R.drawable.place_of_worship);
    icons.put("cinema", R.drawable.cinema);
    icons.put("city", R.drawable.town);
    icons.put("commercial", R.drawable.mall);
    icons.put("courthouse", R.drawable.courthouse);
    icons.put("dentist", R.drawable.dentist);
    icons.put("doctors", R.drawable.doctors);
    icons.put("drinking_water", R.drawable.drinking_water);
    icons.put("embassy", R.drawable.embassy);
    icons.put("entrance", R.drawable.entrance);
    icons.put("fast_food", R.drawable.fast_food);
    icons.put("fire_station", R.drawable.fire_station);
    icons.put("fuel", R.drawable.fuel);
    icons.put("hamlet", R.drawable.town);
    icons.put("hospital", R.drawable.hospital);
    icons.put("hotel", R.drawable.hotel);
    icons.put("house", R.drawable.house);
    icons.put("housenumber", R.drawable.house);
    icons.put("hunting_stand", R.drawable.hunting_stand);
    icons.put("locality", R.drawable.town);
    icons.put("mall", R.drawable.mall);
    icons.put("nightclub", R.drawable.nightclub);
    icons.put("neighbourhood", R.drawable.house);
    icons.put("parking", R.drawable.parking);
    icons.put("pharmacy", R.drawable.pharmacy);
    icons.put("place_of_worship", R.drawable.place_of_worship);
    icons.put("police", R.drawable.police);
    icons.put("political", R.drawable.administrative);
    icons.put("primary", R.drawable.street);
    icons.put("prison", R.drawable.prison);
    icons.put("pub", R.drawable.pub);
    icons.put("recycling", R.drawable.recycling);
    icons.put("religious_administrative", R.drawable.place_of_worship);
    icons.put("residential", R.drawable.house);
    icons.put("restaurant", R.drawable.restaurant);
    icons.put("retail", R.drawable.mall);
    icons.put("road", R.drawable.street);
    icons.put("secondary", R.drawable.street);
    icons.put("stadium", R.drawable.stadium);
    icons.put("station", R.drawable.bus_stop);
    icons.put("street", R.drawable.street);
    icons.put("suburb", R.drawable.town);
    icons.put("subway_entrance", R.drawable.bus_stop);
    icons.put("platform", R.drawable.bus_stop);
    icons.put("supermarket", R.drawable.mall);
    icons.put("terminal", R.drawable.aerodrome);
    icons.put("tertiary", R.drawable.street);
    icons.put("theatre", R.drawable.theatre);
    icons.put("toilets", R.drawable.toilets);
    icons.put("town", R.drawable.town);
    icons.put("townhall", R.drawable.townhall);
    icons.put("track", R.drawable.street);
    icons.put("village", R.drawable.town);
    icons.put("phone", R.drawable.sos);
}

From source file:com.localytics.phonegap.LocalyticsPlugin.java

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    if (action.equals("integrate")) {
        String localyticsKey = (args.length() == 1 ? args.getString(0) : null);
        Localytics.integrate(cordova.getActivity().getApplicationContext(), localyticsKey);
        callbackContext.success();//from  w ww .  ja v  a  2  s  . c o m
        return true;
    } else if (action.equals("upload")) {
        Localytics.upload();
        callbackContext.success();
        return true;
    } else if (action.equals("autoIntegrate")) {
        /* App-key is read from meta-data LOCALYTICS_APP_KEY in AndroidManifest */
        Application app = cordova.getActivity().getApplication();
        app.registerActivityLifecycleCallbacks(
                new LocalyticsActivityLifecycleCallbacks(app.getApplicationContext()));
        callbackContext.success();
        return true;
    } else if (action.equals("openSession")) {
        Localytics.openSession();
        callbackContext.success();
        return true;
    } else if (action.equals("closeSession")) {
        Localytics.closeSession();
        callbackContext.success();
        return true;
    } else if (action.equals("tagEvent")) {
        if (args.length() == 3) {
            String name = args.getString(0);
            if (name != null && name.length() > 0) {
                JSONObject attributes = null;
                if (!args.isNull(1)) {
                    attributes = args.getJSONObject(1);
                }
                HashMap<String, String> a = null;
                if (attributes != null && attributes.length() > 0) {
                    a = new HashMap<String, String>();
                    Iterator<?> keys = attributes.keys();
                    while (keys.hasNext()) {
                        String key = (String) keys.next();
                        String value = attributes.getString(key);
                        a.put(key, value);
                    }
                }
                int customerValueIncrease = args.getInt(2);
                Localytics.tagEvent(name, a, customerValueIncrease);
                callbackContext.success();
            } else {
                callbackContext.error("Expected non-empty name argument.");
            }
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("tagScreen")) {
        String name = args.getString(0);
        if (name != null && name.length() > 0) {
            Localytics.tagScreen(name);
            callbackContext.success();
        } else {
            callbackContext.error("Expected non-empty name argument.");
        }
        return true;
    } else if (action.equals("setCustomDimension")) {
        if (args.length() == 2) {
            int index = args.getInt(0);
            String value = null;
            if (!args.isNull(1)) {
                value = args.getString(1);
            }
            Localytics.setCustomDimension(index, value);
            callbackContext.success();
        } else {
            callbackContext.error("Expected two arguments.");
        }
        return true;
    } else if (action.equals("getCustomDimension")) {
        final int index = args.getInt(0);
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                String value = Localytics.getCustomDimension(index);
                callbackContext.success(value);
            }
        });
        return true;
    } else if (action.equals("setOptedOut")) {
        boolean enabled = args.getBoolean(0);
        Localytics.setOptedOut(enabled);
        callbackContext.success();
        return true;
    } else if (action.equals("isOptedOut")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                boolean enabled = Localytics.isOptedOut();
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, enabled));
            }
        });
        return true;
    } else if (action.equals("setProfileAttribute")) {
        if (args.length() == 3) {
            String errorString = null;

            String attributeName = args.getString(0);
            Object attributeValue = args.get(1);
            String scope = args.getString(2);

            if (attributeValue instanceof Integer) {
                Localytics.setProfileAttribute(attributeName, (Integer) attributeValue, getProfileScope(scope));
            } else if (attributeValue instanceof String) {
                Localytics.setProfileAttribute(attributeName, (String) attributeValue, getProfileScope(scope));
            } else if (attributeValue instanceof Date) {
                Localytics.setProfileAttribute(attributeName, (Date) attributeValue, getProfileScope(scope));
            } else if (attributeValue instanceof JSONArray) {
                JSONArray array = (JSONArray) attributeValue;
                Object item = getInitialItem(array);
                if (item instanceof Integer) {
                    long[] longs = buildLongArray(array);
                    if (longs != null) {
                        Localytics.setProfileAttribute(attributeName, longs, getProfileScope(scope));
                    } else {
                        errorString = ERROR_INVALID_ARRAY;
                    }
                } else if (item instanceof String) {
                    if (parseISO8601Date((String) item) != null) {
                        Date[] dates = buildDateArray(array);
                        if (dates != null) {
                            Localytics.addProfileAttributesToSet(attributeName, dates, getProfileScope(scope));
                        } else {
                            errorString = ERROR_INVALID_ARRAY;
                        }
                    } else {
                        String[] strings = buildStringArray(array);
                        if (strings != null) {
                            Localytics.addProfileAttributesToSet(attributeName, strings,
                                    getProfileScope(scope));
                        } else {
                            errorString = ERROR_INVALID_ARRAY;
                        }
                    }
                }
            } else {
                errorString = ERROR_UNSUPPORTED_TYPE;
            }

            if (errorString != null) {
                callbackContext.error(errorString);
            } else {
                callbackContext.success();
            }
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("addProfileAttributesToSet")) {
        if (args.length() == 3) {
            String errorString = null;

            String attributeName = args.getString(0);
            Object attributeValue = args.get(1);
            String scope = args.getString(2);

            if (attributeValue instanceof JSONArray) {
                JSONArray array = (JSONArray) attributeValue;
                Object item = getInitialItem(array);
                if (item instanceof Integer) {
                    long[] longs = buildLongArray(array);
                    if (longs != null) {
                        Localytics.addProfileAttributesToSet(attributeName, longs, getProfileScope(scope));
                    } else {
                        errorString = ERROR_INVALID_ARRAY;
                    }
                } else if (item instanceof String) {
                    // Check if date string first
                    if (parseISO8601Date((String) item) != null) {
                        Date[] dates = buildDateArray(array);
                        if (dates != null) {
                            Localytics.addProfileAttributesToSet(attributeName, dates, getProfileScope(scope));
                        } else {
                            errorString = ERROR_INVALID_ARRAY;
                        }
                    } else {
                        String[] strings = buildStringArray(array);
                        if (strings != null) {
                            Localytics.addProfileAttributesToSet(attributeName, strings,
                                    getProfileScope(scope));
                        } else {
                            errorString = ERROR_INVALID_ARRAY;
                        }
                    }
                }
            } else {
                errorString = ERROR_UNSUPPORTED_TYPE;
            }

            if (errorString != null) {
                callbackContext.error(errorString);
            } else {
                callbackContext.success();
            }
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("removeProfileAttributesFromSet")) {
        if (args.length() == 3) {
            String errorString = null;

            String attributeName = args.getString(0);
            Object attributeValue = args.get(1);
            String scope = args.getString(2);
            if (attributeValue instanceof JSONArray) {
                JSONArray array = (JSONArray) attributeValue;
                Object item = getInitialItem(array);
                if (item instanceof Integer) {
                    long[] longs = buildLongArray(array);
                    if (longs != null) {
                        Localytics.removeProfileAttributesFromSet(attributeName, longs, getProfileScope(scope));
                    } else {
                        errorString = ERROR_INVALID_ARRAY;
                    }
                } else if (item instanceof String) {
                    if (parseISO8601Date((String) item) != null) {
                        Date[] dates = buildDateArray(array);
                        if (dates != null) {
                            Localytics.addProfileAttributesToSet(attributeName, dates, getProfileScope(scope));
                        } else {
                            errorString = ERROR_INVALID_ARRAY;
                        }
                    } else {
                        String[] strings = buildStringArray(array);
                        if (strings != null) {
                            Localytics.addProfileAttributesToSet(attributeName, strings,
                                    getProfileScope(scope));
                        } else {
                            errorString = ERROR_INVALID_ARRAY;
                        }
                    }
                }
            } else {
                errorString = ERROR_UNSUPPORTED_TYPE;
            }

            if (errorString != null) {
                callbackContext.error(errorString);
            } else {
                callbackContext.success();
            }
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("incrementProfileAttribute")) {
        if (args.length() == 3) {
            String attributeName = args.getString(0);
            long incrementValue = args.getLong(1);
            String scope = args.getString(2);

            Localytics.incrementProfileAttribute(attributeName, incrementValue, getProfileScope(scope));
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("decrementProfileAttribute")) {
        if (args.length() == 3) {
            String attributeName = args.getString(0);
            long decrementValue = args.getLong(1);
            String scope = args.getString(2);

            Localytics.decrementProfileAttribute(attributeName, decrementValue, getProfileScope(scope));
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("deleteProfileAttribute")) {
        if (args.length() == 2) {
            String attributeName = args.getString(0);
            String scope = args.getString(1);

            Localytics.deleteProfileAttribute(attributeName, getProfileScope(scope));
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("setIdentifier")) {
        if (args.length() == 2) {
            String key = args.getString(0);
            if (key != null && key.length() > 0) {
                String value = null;
                if (!args.isNull(1)) {
                    value = args.getString(1);
                }
                Localytics.setIdentifier(key, value);
                callbackContext.success();
            } else {
                callbackContext.error("Expected non-empty key argument.");
            }
        } else {
            callbackContext.error("Expected two arguments.");
        }
        return true;
    } else if (action.equals("setCustomerId")) {
        String id = null;
        if (!args.isNull(0)) {
            id = args.getString(0);
        }
        Localytics.setCustomerId(id);
        callbackContext.success();
        return true;
    } else if (action.equals("setCustomerFullName")) {
        String fullName = null;
        if (!args.isNull(0)) {
            fullName = args.getString(0);
        }
        Localytics.setCustomerFullName(fullName);
        callbackContext.success();
        return true;
    } else if (action.equals("setCustomerFirstName")) {
        String firstName = null;
        if (!args.isNull(0)) {
            firstName = args.getString(0);
        }
        Localytics.setCustomerFirstName(firstName);
        callbackContext.success();
        return true;
    } else if (action.equals("setCustomerLastName")) {
        String lastName = null;
        if (!args.isNull(0)) {
            lastName = args.getString(0);
        }
        Localytics.setCustomerLastName(lastName);
        callbackContext.success();
        return true;
    } else if (action.equals("setCustomerEmail")) {
        String email = null;
        if (!args.isNull(0)) {
            email = args.getString(0);
        }
        Localytics.setCustomerEmail(email);
        callbackContext.success();
        return true;
    } else if (action.equals("setLocation")) {
        if (args.length() == 2) {
            Location location = new Location("");
            location.setLatitude(args.getDouble(0));
            location.setLongitude(args.getDouble(1));

            Localytics.setLocation(location);
            callbackContext.success();
        } else {
            callbackContext.error("Expected two arguments.");
        }
        return true;
    } else if (action.equals("registerPush")) {
        String senderId = null;

        try {
            PackageManager pm = cordova.getActivity().getPackageManager();
            ApplicationInfo ai = pm.getApplicationInfo(cordova.getActivity().getPackageName(),
                    PackageManager.GET_META_DATA);
            Bundle metaData = ai.metaData;
            senderId = metaData.getString(PROP_SENDER_ID);
        } catch (PackageManager.NameNotFoundException e) {
            //No-op
        }

        Localytics.registerPush(senderId);
        callbackContext.success();
        return true;
    } else if (action.equals("setPushDisabled")) {
        boolean enabled = args.getBoolean(0);
        Localytics.setPushDisabled(enabled);
        callbackContext.success();
        return true;
    } else if (action.equals("isPushDisabled")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                boolean enabled = Localytics.isPushDisabled();
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, enabled));
            }
        });
        return true;
    } else if (action.equals("setTestModeEnabled")) {
        boolean enabled = args.getBoolean(0);
        Localytics.setTestModeEnabled(enabled);
        callbackContext.success();
        return true;
    } else if (action.equals("isTestModeEnabled")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                boolean enabled = Localytics.isTestModeEnabled();
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, enabled));
            }
        });
        return true;
    } else if (action.equals("setInAppMessageDismissButtonImageWithName")) {
        //No-op
        return true;
    } else if (action.equals("setInAppMessageDismissButtonLocation")) {
        //No-op
        return true;
    } else if (action.equals("getInAppMessageDismissButtonLocation")) {
        //No-op
        return true;
    } else if (action.equals("triggerInAppMessage")) {
        //No-op
        return true;
    } else if (action.equals("dismissCurrentInAppMessage")) {
        //No-op
        return true;
    } else if (action.equals("setLoggingEnabled")) {
        boolean enabled = args.getBoolean(0);
        Localytics.setLoggingEnabled(enabled);
        callbackContext.success();
        return true;
    } else if (action.equals("isLoggingEnabled")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                boolean enabled = Localytics.isLoggingEnabled();
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, enabled));
            }
        });
        return true;
    } else if (action.equals("setSessionTimeoutInterval")) {
        int seconds = args.getInt(0);
        Localytics.setSessionTimeoutInterval(seconds);
        callbackContext.success();
        return true;
    } else if (action.equals("getSessionTimeoutInterval")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                long timeout = Localytics.getSessionTimeoutInterval();
                callbackContext.success(Long.valueOf(timeout).toString());
            }
        });
        return true;
    } else if (action.equals("getInstallId")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                String result = Localytics.getInstallId();
                callbackContext.success(result);
            }
        });
        return true;
    } else if (action.equals("getAppKey")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                String result = Localytics.getAppKey();
                callbackContext.success(result);
            }
        });

        return true;
    } else if (action.equals("getLibraryVersion")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                String result = Localytics.getLibraryVersion();
                callbackContext.success(result);
            }
        });
        return true;
    }
    return false;
}