Android Open Source - mobile-connector-sdk-android Engage Config Fragment






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.demo.engagetest.fragment;
//from  w w  w  .  j  av a2  s .co m
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.silverpop.engage.config.EngageConfig;
import com.silverpop.engage.demo.engagetest.R;
import com.urbanairship.push.PushManager;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Created by jeremydyer on 6/5/14.
 */
public class EngageConfigFragment
        extends ListFragment {

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

    private KeyValueListAdaptor mAdaptor;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onCreate(Bundle savedInstance) {
        super.onCreate(savedInstance);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.engageconfig_view, container, false);
        return v;
    }

    public Map<String, String> updateListData(Context context) {
        Map<String, String> m = new LinkedHashMap<String, String>();
        m.put("Device ID", EngageConfig.deviceId(context));
        m.put("Device Name", EngageConfig.deviceName());
        m.put("Device Version", EngageConfig.deviceVersion());
        m.put("Anonymous User ID", EngageConfig.anonymousUserId(context));
        m.put("Primary User ID", EngageConfig.primaryUserId(context));
        m.put("OS Name", EngageConfig.osName(context));
        m.put("OS Version", EngageConfig.osVersion(context));
        m.put("App Name", EngageConfig.appName(context));
        m.put("App Version", EngageConfig.appVersion(context));
        m.put("Current Campaign", EngageConfig.currentCampaign(context));
        m.put("Expiration Time", EngageConfig.currentCampaignExpirationDate() != null ? EngageConfig.currentCampaignExpirationDate().toString() : "-");
        m.put("Last Campaign", EngageConfig.lastCampaign(context));
        if (EngageConfig.currentLocationCache() != null) {
            m.put("Longitude", new Double(EngageConfig.currentLocationCache().getLongitude()).toString());
            m.put("Latitude", new Double(EngageConfig.currentLocationCache().getLatitude()).toString());
        }
        if (EngageConfig.currentAddressCache() != null) {
            m.put("Location Address", EngageConfig.buildLocationAddress());
        } else {
            m.put("Location Address", "Not yet acquired");
        }
        m.put("UAS App ID", PushManager.shared().getAPID());

        return m;
    }

    @Override
    public void onResume() {
        super.onResume();

        //Hard refresh the view since we want the new EngageConfig values to show.
        Context context = getActivity().getApplicationContext();
        mAdaptor = new KeyValueListAdaptor(getActivity(), updateListData(context));
        setListAdapter(mAdaptor);
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        // do something with the data
        Log.d(TAG, "ListItem was clicked!");
    }


    private class KeyValueListAdaptor
            extends BaseAdapter {

        private Context context = null;
        private Map<String, String> data = null;
        private Map<Integer, String> positionToKeyMap = null;
        private LayoutInflater layoutInflater;

        public KeyValueListAdaptor(Context context, Map<String, String> values) {
            //super();
            this.context = context;
            this.data = values;
            this.layoutInflater = LayoutInflater.from(context);

            positionToKeyMap = new HashMap<Integer, String>();
            Iterator<Map.Entry<String, String>> itr = values.entrySet().iterator();
            Integer position = 0;
            while (itr.hasNext()) {
                Map.Entry<String, String> ent = itr.next();
                positionToKeyMap.put(position, ent.getKey());
                position++;
            }
        }

        @Override
        public int getCount() {
            return this.data.size();
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int position, View view, ViewGroup viewGroup) {
            View v = layoutInflater.inflate(R.layout.key_value_listviewitem, null);

            String key = positionToKeyMap.get(position);

            TextView keyText =(TextView)v.findViewById(R.id.keyValueKey);
            keyText.setText(key);

            TextView value =(TextView)v.findViewById(R.id.keyValueValue);
            value.setText(data.get(key));

            return v;
        }
    }
}




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