package org.projectbuendia.client.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;

import org.joda.time.Duration;
import org.joda.time.Instant;
import org.projectbuendia.client.utils.Logger;

import javax.annotation.Nonnull;

public class BatteryWatcher extends BroadcastReceiver {
    private static final Logger LOG = Logger.create();
    private Instant dockTime = null;

    @Override public void onReceive(Context context, Intent intent) {
        int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        // NOTE(ping): The charging docks we are using don't seem to trigger
        // DOCK_EVENT actions, so we watch for AC charging instead.
        if ((plugged & BatteryManager.BATTERY_PLUGGED_AC) > 0) {
            LOG.i("AC charging started");
            dockTime = Instant.now();
        } else {
            LOG.i("AC charging stopped");
            dockTime = null;
        }
    }

    public @Nonnull Duration getDockedDuration() {
        return dockTime != null
            ? new Duration(dockTime, Instant.now())
            : new Duration(0);
    }
}

@@ -469,16 +469,55 @@
  = null;
+%0A    private boolean acPlugged = false;
 %0A%0A    @O
@@ -813,12 +813,31 @@
     
-if (
+boolean newAcPlugged = 
 (plu
@@ -881,16 +881,56 @@
 _AC) %3E 0
+;%0A        if (newAcPlugged && !acPlugged
 ) %7B%0A    
@@ -1018,13 +1018,48 @@
    %7D
- else
+%0A        if (acPlugged && !newAcPlugged)
  %7B%0A 
@@ -1124,24 +1124,24 @@
 ime = null;%0A
-
         %7D%0A  
@@ -1134,24 +1134,58 @@
 ;%0A        %7D%0A
+        acPlugged = newAcPlugged;%0A
     %7D%0A%0A    p

Make BatteryWatcher ignore events with no change to the AC plugged state.