use of com.nyaruka.androidrelay.data.TextMessage in project android-sms-relay by nyaruka.
the class MessageListFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedState) {
super.onActivityCreated(savedState);
//View view = super.onCreateView(inflater, container, savedInstanceState);
List<TextMessage> msgs = AndroidRelay.getHelper(getActivity()).getAllMessages();
m_adapter = new TextMessageAdapter(getActivity(), R.layout.message, msgs);
setListAdapter(m_adapter);
ListView lv = getListView();
lv.setBackgroundColor(Color.WHITE);
lv.setCacheColorHint(Color.WHITE);
}
use of com.nyaruka.androidrelay.data.TextMessage in project android-sms-relay by nyaruka.
the class MessageListFragment method updateMessage.
public void updateMessage(TextMessage textMessage) {
Message msg = new Message();
s_updateMessages.add(textMessage);
m_updateHandler.sendMessage(msg);
}
use of com.nyaruka.androidrelay.data.TextMessage in project android-sms-relay by nyaruka.
the class RelayService method onNewSMS.
public void onNewSMS(String number, String message) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean process_messages = prefs.getBoolean("process_incoming", false);
TextMessageHelper helper = getHelper();
String keyword = prefs.getString("relay_password", "nyaruka").toLowerCase();
// if we aren't supposed to process messages, ignore this message
if (!process_messages) {
return;
}
// if someone sends 'keyword log' then send a log to the server
if (message.equalsIgnoreCase(keyword + " log")) {
RelayService.doSendLog = true;
int unsynced = helper.withStatus(getApplicationContext(), TextMessage.INCOMING, TextMessage.RECEIVED).size();
int erroredOut = helper.withStatus(getApplicationContext(), TextMessage.OUTGOING, TextMessage.ERRORED).size();
int erroredIn = helper.withStatus(getApplicationContext(), TextMessage.INCOMING, TextMessage.ERRORED).size();
modem.sendSms(number, "Log being sent. " + unsynced + " unsynced. " + erroredOut + " out errors. " + erroredIn + " in errors.", "-1");
return;
}
if (message.equalsIgnoreCase(keyword + " reset")) {
// change the label to true
doReset = true;
Log.d(TAG, "The reset process is set to " + Boolean.toString(doReset));
// start the check service for reset changes to take effect
kickService();
modem.sendSms(number, "Reset process has been started. ", "-1");
return;
}
if (message.equalsIgnoreCase(keyword + " clear")) {
Log.d(TAG, "Clearing all messages");
AndroidRelay.clearMessages(RelayService.this);
Toast.makeText(RelayService.this, "Messages cleared", Toast.LENGTH_LONG).show();
modem.sendSms(number, "All messages have been removed.", "-1");
return;
}
{
SharedPreferences.Editor editor = prefs.edit();
// process message with 'keyword data and change the network connection to specified mode
if (message.equalsIgnoreCase(keyword + " data")) {
Log.d(TAG, "Switching to data connection");
editor.putString("pref_net", "1");
editor.commit();
modem.sendSms(number, "Your preferred network is now set to 'MOBILE DATA'", "-1");
return;
}
// process message with 'keyword wifi and change the network connection to specified mode
if (message.equalsIgnoreCase(keyword + " wifi")) {
Log.d(TAG, "Switching to wifi connection");
editor.putString("pref_net", "0");
editor.commit();
modem.sendSms(number, "Your preferred network is now set to 'WIFI'", "-1");
return;
}
}
TextMessage msg = null;
msg = new TextMessage();
msg.number = number;
msg.text = message;
msg.created = new Date();
msg.direction = TextMessage.INCOMING;
msg.status = TextMessage.RECEIVED;
helper.createMessage(msg);
Log.d(TAG, "=== SMS IN:" + msg.number + ": " + msg.text);
MainActivity.updateMessage(msg);
kickService();
}
use of com.nyaruka.androidrelay.data.TextMessage in project android-sms-relay by nyaruka.
the class RelayService method requeueErroredIncoming.
/***
* Goes through all our activations, retriggering syncs for all those that need to be sent.
*/
public void requeueErroredIncoming() {
TextMessageHelper helper = getHelper();
List<TextMessage> msgs = helper.withStatus(this.getApplicationContext(), TextMessage.INCOMING, TextMessage.ERRORED);
int count = 0;
for (TextMessage msg : msgs) {
msg.status = TextMessage.RECEIVED;
helper.updateMessage(msg);
MainActivity.updateMessage(msg);
count++;
if (count >= 5) {
Log.d(TAG, "Reprocessed five messages, skipping rest.");
break;
}
}
}
use of com.nyaruka.androidrelay.data.TextMessage in project android-sms-relay by nyaruka.
the class RelayService method resendErroredSMS.
/***
* Goes through all the messages which have errors and resends them. Note that we only try to send
* five at a time, so it could take a bit to clear out the backlog.
*/
public void resendErroredSMS() {
TextMessageHelper helper = getHelper();
List<TextMessage> msgs = helper.erroredOutgoing(getApplicationContext());
int count = 0;
for (TextMessage msg : msgs) {
try {
Log.d(TAG, "Sending [" + msg.id + "] - " + msg.number + " - " + msg.text);
modem.sendSms(msg.number, msg.text, "" + msg.id);
msg.status = TextMessage.QUEUED;
} catch (Throwable t) {
msg.status = TextMessage.ERRORED;
Log.d(TAG, "Errored [" + msg.id + "] - " + msg.number + " - " + msg.text, t);
}
helper.updateMessage(msg);
MainActivity.updateMessage(msg);
count++;
if (count >= 5) {
Log.d(TAG, "Resent five messages, skipping rest.");
break;
}
}
}
Aggregations