// Path: src/com/icecondor/nest/Constants.java
// public class Constants {
// 
//     public static final String APP_TAG = "icecondor";
//     public static final int SIGNAL_NEW_ACTIVITY = 1;
//     public static final String ACTION_WAKE_ALARM = "com.icecondor.WAKE_ALARM";
//     public static final String ICECONDOR_API_URL = "wss://api.icecondor.com/v2";
//     public static final String VERSION = "20150402";
// 
//     /* internal app settings */
//     public static final String SETTING_ON_OFF = "on_off";
//     public static final String SETTING_DEVICE_ID = "device_id";
// 
//     /* user preferences */
//     public static final String PREFERENCE_AUTOSTART = "autostart";
//     public static final String PREFERENCE_API_URL = "api_url";
//     public static final String PREFERENCE_RECORDING_FREQUENCY_SECONDS = "recording_frequency";
//     public static final String PREFERENCE_SOURCE_GPS = "source_gps";
//     public static final String PREFERENCE_SOURCE_CELL = "source_cell";
//     public static final String PREFERENCE_SOURCE_WIFI = "source_wifi";
//     public static final String PREFERENCE_VERSION = "version_string";
//     public static final String PREFERENCE_LOGOUT = "logout_pref";
//     public static final String PREFERENCE_PERSISTENT_RECONNECT = "persistent_reconnect";
//     public static final String PREFERENCE_EVENT_CONNECTING = "event_connecting";
//     public static final String PREFERENCE_EVENT_CONNECTED = "event_connected";
//     public static final String PREFERENCE_EVENT_DISCONNECTED = "event_disconnected";
//     public static final String PREFERENCE_EVENT_HEARTBEAT= "event_heartbeat";
// 
// }


import java.util.Date;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
import android.util.Log;
import com.icecondor.nest.Constants;
package com.icecondor.nest.service;




public class BatteryReceiver extends BroadcastReceiver {
    private int last_battery_level;
    private Date last_battery_date;
    private boolean ac_power;

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
            last_battery_level = intent.getIntExtra("level", 0);
            last_battery_date = new Date();
            int ac_int = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
            ac_power = ac_int != 0;
            Log.d(Constants.APP_TAG, "battery changed "+last_battery_level+" charging "+ac_power+" "+ac_int);
        }
        if (action.equals("android.intent.action.ACTION_POWER_CONNECTED")) {
            ac_power = true;
            Log.d(Constants.APP_TAG, "ac power"+ac_power);
        }
        if (action.equals("android.intent.action.ACTION_POWER_DISCONNECTED")) {
            ac_power = false;
            Log.d(Constants.APP_TAG, "ac power"+ac_power);
        }
    }

    public int getLastBatteryLevel() {
        return last_battery_level;
    }

    public boolean isLastBatteryValid() {
        return last_battery_date != null;
    }

// Path: src/com/icecondor/nest/Constants.java
// public class Constants {
// 
//     public static final String APP_TAG = "icecondor";
//     public static final int SIGNAL_NEW_ACTIVITY = 1;
//     public static final String ACTION_WAKE_ALARM = "com.icecondor.WAKE_ALARM";
//     public static final String ICECONDOR_API_URL = "wss://api.icecondor.com/v2";
//     public static final String VERSION = "20150402";
// 
//     /* internal app settings */
//     public static final String SETTING_ON_OFF = "on_off";
//     public static final String SETTING_DEVICE_ID = "device_id";
// 
//     /* user preferences */
//     public static final String PREFERENCE_AUTOSTART = "autostart";
//     public static final String PREFERENCE_API_URL = "api_url";
//     public static final String PREFERENCE_RECORDING_FREQUENCY_SECONDS = "recording_frequency";
//     public static final String PREFERENCE_SOURCE_GPS = "source_gps";
//     public static final String PREFERENCE_SOURCE_CELL = "source_cell";
//     public static final String PREFERENCE_SOURCE_WIFI = "source_wifi";
//     public static final String PREFERENCE_VERSION = "version_string";
//     public static final String PREFERENCE_LOGOUT = "logout_pref";
//     public static final String PREFERENCE_PERSISTENT_RECONNECT = "persistent_reconnect";
//     public static final String PREFERENCE_EVENT_CONNECTING = "event_connecting";
//     public static final String PREFERENCE_EVENT_CONNECTED = "event_connected";
//     public static final String PREFERENCE_EVENT_DISCONNECTED = "event_disconnected";
//     public static final String PREFERENCE_EVENT_HEARTBEAT= "event_heartbeat";
// 
// }


// Path: src/com/icecondor/nest/service/BatteryReceiver.java
import java.util.Date;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
import android.util.Log;
import com.icecondor.nest.Constants;

package com.icecondor.nest.service;




public class BatteryReceiver extends BroadcastReceiver {
    private int last_battery_level;
    private Date last_battery_date;
    private boolean ac_power;

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
            last_battery_level = intent.getIntExtra("level", 0);
            last_battery_date = new Date();
            int ac_int = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
            ac_power = ac_int != 0;
            Log.d(Constants.APP_TAG, "battery changed "+last_battery_level+" charging "+ac_power+" "+ac_int);
        }
        if (action.equals("android.intent.action.ACTION_POWER_CONNECTED")) {
            ac_power = true;
            Log.d(Constants.APP_TAG, "ac power"+ac_power);
        }
        if (action.equals("android.intent.action.ACTION_POWER_DISCONNECTED")) {
            ac_power = false;
            Log.d(Constants.APP_TAG, "ac power"+ac_power);
        }
    }

    public int getLastBatteryLevel() {
        return last_battery_level;
    }

    public boolean isLastBatteryValid() {
        return last_battery_date != null;
    }

    public int getLastBatteryAge() {