• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.google.android.setupcompat.logging.internal;
2 
3 import android.os.Bundle;
4 import com.google.android.setupcompat.logging.CustomEvent;
5 import com.google.android.setupcompat.logging.MetricKey;
6 import com.google.android.setupcompat.logging.ScreenKey;
7 import com.google.android.setupcompat.logging.SetupMetric;
8 import com.google.android.setupcompat.logging.internal.SetupMetricsLoggingConstants.MetricBundleKeys;
9 
10 /** Collection of helper methods for reading and writing {@link CustomEvent}, {@link MetricKey}. */
11 public final class MetricBundleConverter {
12 
createBundleForLogging(CustomEvent customEvent)13   public static Bundle createBundleForLogging(CustomEvent customEvent) {
14     Bundle bundle = new Bundle();
15     bundle.putParcelable(MetricBundleKeys.CUSTOM_EVENT_BUNDLE, CustomEvent.toBundle(customEvent));
16     return bundle;
17   }
18 
createBundleForLoggingCounter(MetricKey counterName, int times)19   public static Bundle createBundleForLoggingCounter(MetricKey counterName, int times) {
20     Bundle bundle = new Bundle();
21     bundle.putParcelable(MetricBundleKeys.METRIC_KEY_BUNDLE, MetricKey.fromMetricKey(counterName));
22     bundle.putInt(MetricBundleKeys.COUNTER_INT, times);
23     return bundle;
24   }
25 
createBundleForLoggingTimer(MetricKey timerName, long timeInMillis)26   public static Bundle createBundleForLoggingTimer(MetricKey timerName, long timeInMillis) {
27     Bundle bundle = new Bundle();
28     bundle.putParcelable(MetricBundleKeys.METRIC_KEY_BUNDLE, MetricKey.fromMetricKey(timerName));
29     bundle.putLong(MetricBundleKeys.TIME_MILLIS_LONG, timeInMillis);
30     return bundle;
31   }
32 
createBundleForLoggingSetupMetric(ScreenKey screenKey, SetupMetric metric)33   public static Bundle createBundleForLoggingSetupMetric(ScreenKey screenKey, SetupMetric metric) {
34     Bundle bundle = new Bundle();
35     bundle.putParcelable(MetricBundleKeys.SCREEN_KEY_BUNDLE, ScreenKey.toBundle(screenKey));
36     bundle.putParcelable(MetricBundleKeys.SETUP_METRIC_BUNDLE, SetupMetric.toBundle(metric));
37     return bundle;
38   }
39 
MetricBundleConverter()40   private MetricBundleConverter() {
41     throw new AssertionError("Cannot instantiate MetricBundleConverter");
42   }
43 }
44