Search in sources :

Example 1 with TextMessage

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);
}
Also used : ListView(android.widget.ListView) TextMessage(com.nyaruka.androidrelay.data.TextMessage)

Example 2 with TextMessage

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);
}
Also used : TextMessage(com.nyaruka.androidrelay.data.TextMessage) Message(android.os.Message)

Example 3 with TextMessage

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();
}
Also used : SharedPreferences(android.content.SharedPreferences) TextMessage(com.nyaruka.androidrelay.data.TextMessage) Date(java.util.Date) TextMessageHelper(com.nyaruka.androidrelay.data.TextMessageHelper)

Example 4 with TextMessage

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;
        }
    }
}
Also used : TextMessage(com.nyaruka.androidrelay.data.TextMessage) TextMessageHelper(com.nyaruka.androidrelay.data.TextMessageHelper)

Example 5 with TextMessage

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;
        }
    }
}
Also used : TextMessage(com.nyaruka.androidrelay.data.TextMessage) TextMessageHelper(com.nyaruka.androidrelay.data.TextMessageHelper)

Aggregations

TextMessage (com.nyaruka.androidrelay.data.TextMessage)13 TextMessageHelper (com.nyaruka.androidrelay.data.TextMessageHelper)11 SharedPreferences (android.content.SharedPreferences)5 IOException (java.io.IOException)2 HttpResponseException (org.apache.http.client.HttpResponseException)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 Message (android.os.Message)1 ListView (android.widget.ListView)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 NameValuePair (org.apache.http.NameValuePair)1 HttpClient (org.apache.http.client.HttpClient)1 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)1 HttpPost (org.apache.http.client.methods.HttpPost)1 BasicResponseHandler (org.apache.http.impl.client.BasicResponseHandler)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1