2010-01-13 23:33:50 -05:00
|
|
|
|
|
|
|
package com.fsck.k9.service;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import com.fsck.k9.Account;
|
|
|
|
import com.fsck.k9.K9;
|
2010-01-15 00:05:41 -05:00
|
|
|
import com.fsck.k9.remotecontrol.K9RemoteControl;
|
2010-01-13 23:33:50 -05:00
|
|
|
import com.fsck.k9.Preferences;
|
|
|
|
|
2010-01-15 00:05:41 -05:00
|
|
|
import static com.fsck.k9.remotecontrol.K9RemoteControl.*;
|
2010-01-13 23:33:50 -05:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public class RemoteControlReceiver extends CoreReceiver {
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public Integer receive(Context context, Intent intent, Integer tmpWakeLockId) {
|
2010-01-13 23:33:50 -05:00
|
|
|
if (K9.DEBUG)
|
|
|
|
Log.i(K9.LOG_TAG, "RemoteControlReceiver.onReceive" + intent);
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (K9RemoteControl.K9_SET.equals(intent.getAction())) {
|
2010-01-13 23:33:50 -05:00
|
|
|
RemoteControlService.set(context, intent, tmpWakeLockId);
|
|
|
|
tmpWakeLockId = null;
|
2011-02-06 17:09:48 -05:00
|
|
|
} else if (K9RemoteControl.K9_REQUEST_ACCOUNTS.equals(intent.getAction())) {
|
|
|
|
try {
|
2010-01-13 23:33:50 -05:00
|
|
|
Preferences preferences = Preferences.getPreferences(context);
|
|
|
|
Account[] accounts = preferences.getAccounts();
|
|
|
|
String[] uuids = new String[accounts.length];
|
|
|
|
String[] descriptions = new String[accounts.length];
|
2011-02-06 17:09:48 -05:00
|
|
|
for (int i = 0; i < accounts.length; i++) {
|
2010-11-13 16:40:56 -05:00
|
|
|
//warning: account may not be isAvailable()
|
2010-01-13 23:33:50 -05:00
|
|
|
Account account = accounts[i];
|
2010-01-17 19:11:02 -05:00
|
|
|
|
2010-01-13 23:33:50 -05:00
|
|
|
uuids[i] = account.getUuid();
|
|
|
|
descriptions[i] = account.getDescription();
|
|
|
|
}
|
|
|
|
Bundle bundle = getResultExtras(true);
|
|
|
|
bundle.putStringArray(K9_ACCOUNT_UUIDS, uuids);
|
|
|
|
bundle.putStringArray(K9_ACCOUNT_DESCRIPTIONS, descriptions);
|
2011-02-06 17:09:48 -05:00
|
|
|
} catch (Exception e) {
|
2010-01-13 23:33:50 -05:00
|
|
|
Log.e(K9.LOG_TAG, "Could not handle K9_RESPONSE_INTENT", e);
|
|
|
|
}
|
2010-01-17 19:11:02 -05:00
|
|
|
|
2010-01-13 23:33:50 -05:00
|
|
|
}
|
2010-01-17 19:11:02 -05:00
|
|
|
|
2010-01-13 23:33:50 -05:00
|
|
|
return tmpWakeLockId;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|