2 * Copyright (C) 2010 Felix Bechstein
4 * This file is part of WebSMS.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free Software
8 * Foundation; either version 3 of the License, or (at your option) any later
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License along with
17 * this program; If not, see <http://www.gnu.org/licenses/>.
19 package de
.ub0r
.android
.websms
.connector
.gmx
;
21 import android
.content
.Context
;
22 import android
.content
.Intent
;
23 import android
.content
.SharedPreferences
;
24 import android
.preference
.PreferenceManager
;
25 import android
.util
.Log
;
26 import android
.widget
.Toast
;
27 import de
.ub0r
.android
.andGMXsms
.R
;
28 import de
.ub0r
.android
.websms
.connector
.common
.CommandReceiver
;
29 import de
.ub0r
.android
.websms
.connector
.common
.ConnectorCommand
;
30 import de
.ub0r
.android
.websms
.connector
.common
.ConnectorSpec
;
31 import de
.ub0r
.android
.websms
.connector
.common
.WebSMSException
;
32 import de
.ub0r
.android
.websms
.connector
.common
.ConnectorSpec
.SubConnectorSpec
;
35 * Receives commands coming as broadcast from WebSMS.
39 public class CommandReceiverGMX
extends CommandReceiver
{
40 /** Tag for debug output. */
41 private static final String TAG
= "WebSMS.GMX";
43 /** Preferences intent action. */
44 private static final String PREFS_INTENT_ACTION
= "de.ub0r.android."
45 + "websms.connectors.gmx.PREFS";
51 public final ConnectorSpec
initSpec(final Context context
) {
52 final String name
= context
.getString(R
.string
.connector_gmx_name
);
53 ConnectorSpec c
= new ConnectorSpec(TAG
, name
);
55 context
.getString(R
.string
.connector_gmx_author
));
57 c
.setPrefsIntent(PREFS_INTENT_ACTION
);
58 c
.setPrefsTitle(context
.getString(R
.string
.connector_gmx_preferences
));
59 c
.setCapabilities(ConnectorSpec
.CAPABILITIES_BOOSTRAP
60 | ConnectorSpec
.CAPABILITIES_UPDATE
61 | ConnectorSpec
.CAPABILITIES_SEND
);
62 c
.addSubConnector(TAG
, c
.getName(),
63 SubConnectorSpec
.FEATURE_MULTIRECIPIENTS
64 | SubConnectorSpec
.FEATURE_CUSTOMSENDER
65 | SubConnectorSpec
.FEATURE_SENDLATER
);
73 public final ConnectorSpec
updateSpec(final Context context
,
74 final ConnectorSpec connectorSpec
) {
75 final SharedPreferences p
= PreferenceManager
76 .getDefaultSharedPreferences(context
);
77 if (p
.getBoolean(Preferences
.PREFS_ENABLED
, false)) {
78 if (p
.getString(Preferences
.PREFS_MAIL
, "").length() > 0
79 && p
.getString(Preferences
.PREFS_PASSWORD
, "") // .
81 connectorSpec
.setReady();
83 connectorSpec
.setStatus(ConnectorSpec
.STATUS_ENABLED
);
86 connectorSpec
.setStatus(ConnectorSpec
.STATUS_INACTIVE
);
95 public final void onReceive(final Context context
, final Intent intent
) {
96 final String action
= intent
.getAction();
97 Log
.d(TAG
, "action: " + action
);
101 if (ACTION_CONNECTOR_UPDATE
.equals(action
)) {
102 this.sendInfo(context
, null, null);
103 } else if (ACTION_CONNECTOR_RUN_SEND
.equals(action
)) {
104 final ConnectorCommand command
= new ConnectorCommand(intent
);
105 if (command
.getType() == ConnectorCommand
.TYPE_SEND
) {
106 final ConnectorSpec origSpecs
= new ConnectorSpec(intent
);
107 final ConnectorSpec specs
= this.getSpecs(context
);
108 if (specs
.getID().equals(origSpecs
.getID())
109 && specs
.hasStatus(ConnectorSpec
.STATUS_READY
)) {
110 // check internal status
112 // FIXME: this.send(command);
113 throw new WebSMSException("fixme");
114 } catch (WebSMSException e
) {
116 Toast
.makeText(context
,
117 specs
.getName() + ": " + e
.getMessage(),
118 Toast
.LENGTH_LONG
).show();
119 specs
.setErrorMessage(e
.getMessage());
120 this.sendInfo(context
, specs
, command
);
122 // if nothing went wrong, info was send from inside.