~ubuntuone-client-engineering/ubuntuone-android-files/trunk-2011

« back to all changes in this revision

Viewing changes to src/com/ubuntuone/android/files/receiver/BatteryStatusReceiver.java

  • Committer: Michał Karnicki
  • Date: 2013-11-22 15:14:35 UTC
  • mfrom: (468.1.3 handling-expired-tokens)
  • Revision ID: michal.karnicki@canonical.com-20131122151435-x0ma09gu7u9ivy2l
Robust UX for reauthentication. Minor UI and logging fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
{
36
36
        private final static String TAG = BatteryStatusReceiver.class.getSimpleName();
37
37
 
 
38
        boolean lastIsPlugged = false;
38
39
        boolean isPlugged = false;
 
40
        
 
41
        boolean lastIsCharging = false;
39
42
        boolean isCharging = false;
40
43
 
41
44
        private OnAutoUploadEventListener stateListener;
50
53
        public void onReceive(Context context, Intent intent) {
51
54
                String action = intent.getAction();
52
55
                if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
53
 
                        Log.i(TAG, action);
 
56
                        Log.d(TAG, action);
54
57
                        onActionBatteryChanged(context);
55
58
                } else {
56
59
                        Log.w(TAG, "Unhandled broadcast: " + action);
64
67
 
65
68
        public void onActionBatteryChanged(Context context) {
66
69
                updateBatteryState(context);
67
 
                stateListener.onAutoUploadEventReceived();
 
70
                if (lastIsPlugged != isPlugged || lastIsCharging != isCharging) {
 
71
                        lastIsPlugged = isPlugged;
 
72
                        lastIsCharging = isCharging;
 
73
                        stateListener.onAutoUploadEventReceived();
 
74
                }
68
75
        }
69
76
 
70
77
        public void updateBatteryState(Context context) {
79
86
                isCharging = (statusFlag != -1) &&
80
87
                                (statusFlag == BatteryManager.BATTERY_STATUS_CHARGING ||
81
88
                                statusFlag == BatteryManager.BATTERY_STATUS_FULL);
82
 
                Log.i(TAG, String.format(Locale.US,
 
89
                Log.d(TAG, String.format(Locale.US,
83
90
                                "Battery state: isPlugged %b, isCharging %b",
84
91
                                isPlugged, isCharging));
85
92
        }