Android Open Source - mobile-connector-sdk-android Engage Location Receiver Hardcode Test






From Project

Back to project page mobile-connector-sdk-android.

License

The source code is released under:

Apache License

If you think the Android project mobile-connector-sdk-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.silverpop.engage.location.receiver.plugin;
//w w w  .  j  a  v a  2  s  .  c o m
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.location.Address;
import android.location.Location;
import android.location.LocationManager;
import android.util.Log;

import com.silverpop.engage.R;
import com.silverpop.engage.XMLAPIManager;
import com.silverpop.engage.config.EngageConfig;
import com.silverpop.engage.config.EngageConfigManager;
import com.silverpop.engage.domain.XMLAPI;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * When the Geocode class is not present on certain devices this class
 * can be used in its place to query Google maps to determine the reverse
 * Geocode information.
 *
 * Created by jeremydyer on 6/12/14.
 */
public class EngageLocationReceiverHardcodeTest
    extends EngageLocationReceiverBase {

    private static final String TAG = EngageLocationReceiverHardcodeTest.class.getName();

    @Override
    public void onReceive(Context context, Intent intent) {
        super.onReceive(context, intent);
        Log.d(TAG, "Reverse Geocoding with " + EngageLocationReceiverHardcodeTest.class.getName());
        onLocationReceived(context, (Location)intent.getParcelableExtra(LocationManager.KEY_LOCATION_CHANGED));
    }

    protected void onLocationReceived(Context context, Location loc) {
        if (loc != null && EngageConfig.addressCacheExpired(context)) {

            Resources r = context.getResources();
            Address address = new Address(Locale.US);
            address.setLongitude(loc.getLongitude());
            address.setLatitude(loc.getLatitude());
            address.setLocality(r.getString(R.string.locality));
            address.setAdminArea(r.getString(R.string.adminArea));
            address.setPostalCode(r.getString(R.string.postalCode));
            address.setCountryName(r.getString(R.string.countryName));
            address.setCountryCode(r.getString(R.string.countryCode));
            address.setFeatureName(r.getString(R.string.featureName));

            EngageConfig.storeCurrentAddressCache(address);
            EngageConfig.storeCurrentAddressCacheExpiration(new Date());

            updateUserLastKnownLocation(context);
        } else {
            Log.d(TAG, "Using current Address cache value");
        }
    }

    protected void updateUserLastKnownLocation(Context context) {
        Resources r = context.getResources();
        String lastKnownLocationColumn = EngageConfigManager.get(context).lastKnownLocationColumn();
        String lastKnownLocationTimestampColumn = EngageConfigManager.get(context).lastKnownLocationTimestampColumn();

        String lastKnownLocationTimeFormat = EngageConfigManager.get(context).lastKnownLocationDateFormat();
        SimpleDateFormat sdf = new SimpleDateFormat(lastKnownLocationTimeFormat);

        //Make XMLAPI request to update the last known location.
        Map<String, Object> bodyElements = new HashMap<String, Object>();
        bodyElements.put("LIST_ID", EngageConfigManager.get(context).engageListId());
        bodyElements.put("CREATED_FROM", "1");
        XMLAPI updateLastKnownLocation = new XMLAPI("UpdateRecipient", bodyElements);
        Map<String, Object> syncFields = new HashMap<String, Object>();
        syncFields.put("EMAIL", EngageConfig.primaryUserId(context));
        updateLastKnownLocation.addSyncFields(syncFields);
        Map<String, Object> cols = new HashMap<String, Object>();
        cols.put(lastKnownLocationColumn, sdf.format(new Date()));
        cols.put(lastKnownLocationTimestampColumn, EngageConfig.buildLocationAddress());
        updateLastKnownLocation.addColumns(cols);

        String env = updateLastKnownLocation.envelope();
        Log.d(TAG, env);
        XMLAPIManager.get().postXMLAPI(updateLastKnownLocation, null, null);
    }
}




Java Source Code List

com.silverpop.engage.EngageApplication.java
com.silverpop.engage.UBFManager.java
com.silverpop.engage.XMLAPIManager.java
com.silverpop.engage.augmentation.UBFAugmentationServiceImpl.java
com.silverpop.engage.augmentation.UBFAugmentationService.java
com.silverpop.engage.augmentation.plugin.UBFAddressAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFCoordinatesAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFLocationNameAugmentationPlugin.java
com.silverpop.engage.config.EngageConfigManagerTests.java
com.silverpop.engage.config.EngageConfigManager.java
com.silverpop.engage.config.EngageConfigTest.java
com.silverpop.engage.config.EngageConfig.java
com.silverpop.engage.deeplinking.EngageDeepLinkManager.java
com.silverpop.engage.demo.engagetest.Application.java
com.silverpop.engage.demo.engagetest.EngageNotificationReceiver.java
com.silverpop.engage.demo.engagetest.MainActivity.java
com.silverpop.engage.demo.engagetest.PushReceiver.java
com.silverpop.engage.demo.engagetest.fragment.EngageConfigFragment.java
com.silverpop.engage.demo.engagetest.fragment.UBFAPIFragment.java
com.silverpop.engage.demo.engagetest.fragment.XMLAPIFragment.java
com.silverpop.engage.domain.EngageEvent.java
com.silverpop.engage.domain.JSONable.java
com.silverpop.engage.domain.UBFTests.java
com.silverpop.engage.domain.UBF.java
com.silverpop.engage.domain.XMLAPIEnum.java
com.silverpop.engage.domain.XMLAPITest.java
com.silverpop.engage.domain.XMLAPI.java
com.silverpop.engage.exception.XMLResponseParseException.java
com.silverpop.engage.location.manager.EngageLocationManager.java
com.silverpop.engage.location.manager.plugin.EngageLocationManagerDefault.java
com.silverpop.engage.location.receiver.EngageLocationReceiver.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverBase.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverGeocode.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverHardcodeTest.java
com.silverpop.engage.network.Credential.java
com.silverpop.engage.network.EngageClient.java
com.silverpop.engage.network.RequestCacheWrapper.java
com.silverpop.engage.network.UBFClient.java
com.silverpop.engage.network.XMLAPIClient.java
com.silverpop.engage.response.EngageResponseXMLTests.java
com.silverpop.engage.response.EngageResponseXML.java
com.silverpop.engage.response.XMLAPIResponseNode.java
com.silverpop.engage.store.EngageLocalEventStoreTest.java
com.silverpop.engage.store.EngageLocalEventStore.java
com.silverpop.engage.store.EngageSQLiteHelper.java
com.silverpop.engage.util.EngageExpirationParserTests.java
com.silverpop.engage.util.EngageExpirationParser.java
com.silverpop.engage.util.TimedAsyncTask.java