Bug 1380811 - Add telemetry to collect boolean state for toggle preference. r=francois,mcomella
authorChenxia Liu <liuche@mozilla.com>
Mon, 11 Sep 2017 18:42:29 -0700
changeset 429950 9fbfe01ae6f1e578f29f7fb6ae583d2a16d8699a
parent 429949 be5cbdf6f42084a2399e0a85458a37f617aed597
child 429951 afaf910a6acade9fb6e86d1793faf1b91de9ce32
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrancois, mcomella
bugs1380811
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1380811 - Add telemetry to collect boolean state for toggle preference. r=francois,mcomella MozReview-Commit-ID: DQUkuWQUouM
mobile/android/base/java/org/mozilla/gecko/widget/SwitchPreferenceView.java
--- a/mobile/android/base/java/org/mozilla/gecko/widget/SwitchPreferenceView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/SwitchPreferenceView.java
@@ -9,18 +9,21 @@ import android.content.SharedPreferences
 import android.content.res.TypedArray;
 import android.support.annotation.Nullable;
 import android.support.v7.widget.SwitchCompat;
 import android.util.AttributeSet;
 import android.widget.CompoundButton;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+import org.json.JSONArray;
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.Telemetry;
+import org.mozilla.gecko.TelemetryContract;
 
 /**
  * A toggle that controls a SharedPreference preference, and can be added outside of PreferenceScreen.
  *
  * The attribute 'androidPreferenceKey' must be defined when using this layout.
  */
 public class SwitchPreferenceView extends SwitchCompat {
 
@@ -52,13 +55,18 @@ public class SwitchPreferenceView extend
         final SharedPreferences sharedPreferences = GeckoSharedPrefs.forProfile(context);
         final boolean isChecked = sharedPreferences.getBoolean(preferenceKey, defaultValue);
 
         setChecked(isChecked);
         setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
             @Override
             public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                 sharedPreferences.edit().putBoolean(preferenceKey, b).apply();
+
+                final JSONArray extras = new JSONArray();
+                extras.put(preferenceKey);
+                extras.put(b ? "1" : "0");
+                Telemetry.sendUIEvent(TelemetryContract.Event.EDIT, TelemetryContract.Method.SETTINGS, extras.toString());
             }
         });
 
     }
 }