Search in sources :

Example 1 with LogWithProperties

use of com.microsoft.azure.mobile.ingestion.models.LogWithProperties in project mobile-center-sdk-android by Microsoft.

the class MainActivity method getAnalyticsListener.

private AnalyticsListener getAnalyticsListener() {
    return new AnalyticsListener() {

        @Override
        public void onBeforeSending(com.microsoft.azure.mobile.ingestion.models.Log log) {
            if (log instanceof EventLog) {
                Toast.makeText(MainActivity.this, R.string.event_before_sending, Toast.LENGTH_SHORT).show();
            } else if (log instanceof PageLog) {
                Toast.makeText(MainActivity.this, R.string.page_before_sending, Toast.LENGTH_SHORT).show();
            }
            analyticsIdlingResource.increment();
        }

        @Override
        public void onSendingFailed(com.microsoft.azure.mobile.ingestion.models.Log log, Exception e) {
            String message = null;
            if (log instanceof EventLog) {
                message = getString(R.string.event_sent_failed);
            } else if (log instanceof PageLog) {
                message = getString(R.string.page_sent_failed);
            }
            if (message != null) {
                message = String.format("%s\nException: %s", message, e.toString());
                Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
            }
            analyticsIdlingResource.decrement();
        }

        @Override
        public void onSendingSucceeded(com.microsoft.azure.mobile.ingestion.models.Log log) {
            String message = null;
            if (log instanceof EventLog) {
                message = String.format("%s\nName: %s", getString(R.string.event_sent_succeeded), ((EventLog) log).getName());
            } else if (log instanceof PageLog) {
                message = String.format("%s\nName: %s", getString(R.string.page_sent_succeeded), ((PageLog) log).getName());
            }
            if (message != null) {
                if (((LogWithProperties) log).getProperties() != null) {
                    message += String.format("\nProperties: %s", new JSONObject(((LogWithProperties) log).getProperties()).toString());
                }
                Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
            }
            analyticsIdlingResource.decrement();
        }
    };
}
Also used : AnalyticsListener(com.microsoft.azure.mobile.analytics.channel.AnalyticsListener) JSONObject(org.json.JSONObject) LogWithProperties(com.microsoft.azure.mobile.ingestion.models.LogWithProperties) PageLog(com.microsoft.azure.mobile.analytics.ingestion.models.PageLog) Log(android.util.Log) MobileCenterLog(com.microsoft.azure.mobile.utils.MobileCenterLog) EventLog(com.microsoft.azure.mobile.analytics.ingestion.models.EventLog) PageLog(com.microsoft.azure.mobile.analytics.ingestion.models.PageLog) EventLog(com.microsoft.azure.mobile.analytics.ingestion.models.EventLog)

Aggregations

Log (android.util.Log)1 AnalyticsListener (com.microsoft.azure.mobile.analytics.channel.AnalyticsListener)1 EventLog (com.microsoft.azure.mobile.analytics.ingestion.models.EventLog)1 PageLog (com.microsoft.azure.mobile.analytics.ingestion.models.PageLog)1 LogWithProperties (com.microsoft.azure.mobile.ingestion.models.LogWithProperties)1 MobileCenterLog (com.microsoft.azure.mobile.utils.MobileCenterLog)1 JSONObject (org.json.JSONObject)1