]> iEval git - fonbot.git/commitdiff
Clean up sendMessage calls
authorMarius Gavrilescu <marius@ieval.ro>
Mon, 1 Sep 2014 21:28:50 +0000 (00:28 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Mon, 1 Sep 2014 21:28:50 +0000 (00:28 +0300)
res/values/strings.xml
src/ro/ieval/fonbot/DialogActivity.java
src/ro/ieval/fonbot/FonBotAdminReceiver.java
src/ro/ieval/fonbot/FonBotPhoneStateListener.java
src/ro/ieval/fonbot/Heavy.java
src/ro/ieval/fonbot/ProtectedBroadcastReceiver.java
src/ro/ieval/fonbot/SmsStatusReceiver.java

index 241682271371033f1a32fab005f7c524208ab194..602040c1a76730ab541271cb6165cf4f5c25aa79 100644 (file)
@@ -26,6 +26,7 @@ The help command can be used to get a list of commands and help for them. Exampl
     <string name="user_tapped_fmt">User tapped \'%s\'</string>
     <string name="user_navigated_away_from_dialog">User navigated away from dialog</string>
     <string name="user_canceled_dialog">User canceled dialog</string>
+    <string name="admin_disabled">Admin disabled</string>
     <string name="admin_disable_requested">Admin disable requested</string>
     <string name="admin_enabled">Admin enabled</string>
     <string name="device_password_changed">Device password changed</string>
@@ -33,7 +34,7 @@ The help command can be used to get a list of commands and help for them. Exampl
     <string name="device_login_succeeded">Device login succeeded</string>
     <string name="logging_in">Logging in…</string>
     <string name="phone_status_idle">Phone is now idle</string>
-    <string name="phone_status_ringing">"Phone is ringing. Incoming number: "</string>
+    <string name="phone_status_ringing">"Phone is ringing. Incoming number: %s"</string>
     <string name="phone_status_offhook">Phone is offhook</string>
     <string name="location">Location</string>
     <string name="latitude">Latitude</string>
@@ -487,4 +488,11 @@ The help command can be used to get a list of commands and help for them. Exampl
          Example: rootsh stop;sleep 3;start
        </string>
        <string name="command_not_documented">This command is not documented (yet).</string>
+       <string name="sms_sent">SMS sent (%s)</string>
+       <string name="sms_not_sent_generic_failure">SMS not sent: Generic failure (%s)</string>
+       <string name="sms_not_sent_no_service">SMS not sent: No service (%s)</string>
+       <string name="sms_not_sent_null_pdu">SMS not sent: Null PDU (%s)</string>
+       <string name="sms_not_sent_radio_off">SMS not sent: Radio off (%s)</string>
+       <string name="sms_delivered">SMS delivered (%s)</string>
+       <string name="sms_not_delivered">SMS not delivered (%s)</string>
 </resources>
index 89ae59c055121e0a286fca02ca22785f1c23379f..b24c25d3fed2b3b1a258272efdb235c3d806d222 100644 (file)
@@ -72,7 +72,7 @@ public final class DialogActivity extends Activity {
                                        return;
 
                                Utils.sendMessage(DialogActivity.this, toNonNull(address), 
-                                               toNonNull(getString(user_tapped_fmt, ((Button)v).getText())));
+                                               user_tapped_fmt, ((Button)v).getText());
                                gotAnswer=true;
                                finish();
                        }
@@ -91,7 +91,7 @@ public final class DialogActivity extends Activity {
                super.onStop();
                if(!gotAnswer){
                        Utils.sendMessage(this, toNonNull(address),
-                                       toNonNull(getString(user_navigated_away_from_dialog)));
+                                       user_navigated_away_from_dialog);
                        gotAnswer=true;
                }
                finish();
@@ -101,7 +101,7 @@ public final class DialogActivity extends Activity {
        public void onBackPressed() {
                if(!gotAnswer){
                        Utils.sendMessage(this, toNonNull(address),
-                                       toNonNull(getString(user_canceled_dialog)));
+                                       user_canceled_dialog);
                        gotAnswer=true;
                }
                finish();
index 108b1dab9f4e8ecf73a3e87d0b50c1e46232420e..9f54239e54780684dd99fc14e259b7c5e68a2696 100644 (file)
@@ -42,7 +42,7 @@ public final class FonBotAdminReceiver extends DeviceAdminReceiver {
        public void onDisabled(@Nullable final Context context, @Nullable final Intent intent) {
                if(context==null)
                        return;
-               Utils.sendMessage(context, toNonNull(MessageType.ADMIN), "Admin disabled");
+               Utils.sendMessage(context, toNonNull(MessageType.ADMIN), admin_disabled);
        }
 
        @Override
@@ -51,8 +51,7 @@ public final class FonBotAdminReceiver extends DeviceAdminReceiver {
                        Log.wtf(getClass().getName(), "context is null in onDisableRequested");
                        throw new AssertionError("Log.wtf did not terminate the process");
                }
-               Utils.sendMessage(context, toNonNull(MessageType.ADMIN),
-                               toNonNull(context.getString(admin_disable_requested)));
+               Utils.sendMessage(context, toNonNull(MessageType.ADMIN), admin_disable_requested);
                return null;//TODO: write this
        }
 
@@ -60,16 +59,14 @@ public final class FonBotAdminReceiver extends DeviceAdminReceiver {
        public void onEnabled(@Nullable final Context context, @Nullable final Intent intent) {
                if(context==null)
                        return;
-               Utils.sendMessage(context, toNonNull(MessageType.ADMIN),
-                               toNonNull(context.getString(admin_enabled)));
+               Utils.sendMessage(context, toNonNull(MessageType.ADMIN), admin_enabled);
        }
 
        @Override
        public void onPasswordChanged(@Nullable final Context context, @Nullable final Intent intent) {
                if(context==null)
                        return;
-               Utils.sendMessage(context, toNonNull(MessageType.ADMIN),
-                               toNonNull(context.getString(device_password_changed)));
+               Utils.sendMessage(context, toNonNull(MessageType.ADMIN), device_password_changed);
        }
 
        @SuppressWarnings("boxing")
@@ -78,14 +75,13 @@ public final class FonBotAdminReceiver extends DeviceAdminReceiver {
                if(context==null)
                        return;
                final DevicePolicyManager dpm=(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
-               Utils.sendMessage(context, toNonNull(MessageType.WATCH_LOGIN),
-                               toNonNull(context.getString(device_login_failed_fmt, dpm.getCurrentFailedPasswordAttempts())));
+               Utils.sendMessage(context, toNonNull(MessageType.WATCH_LOGIN), device_login_failed_fmt, dpm.getCurrentFailedPasswordAttempts());
        }
 
        @Override
        public void onPasswordSucceeded(@Nullable final Context context, @Nullable final Intent intent) {
                if(context==null)
                        return;
-               Utils.sendMessage(context, toNonNull(MessageType.WATCH_LOGIN), toNonNull(context.getString(device_login_succeeded)));
+               Utils.sendMessage(context, toNonNull(MessageType.WATCH_LOGIN), device_login_succeeded);
        }
 }
index 88bde8788ed6ccd7531be0c2da965a5678ffa958..9dde5bf81c98844f07e78496b8d9515c4b879988 100644 (file)
@@ -61,23 +61,20 @@ final class FonBotPhoneStateListener extends PhoneStateListener {
 
                switch(state){
                case TelephonyManager.CALL_STATE_IDLE:
-                       Utils.sendMessage(context, toNonNull(MessageType.PHONE_STATE),
-                                       toNonNull(context.getString(phone_status_idle)));
+                       Utils.sendMessage(context, toNonNull(MessageType.PHONE_STATE), phone_status_idle);
                        break;
                case TelephonyManager.CALL_STATE_RINGING:
                        if(incomingNumber==null)
                                return;
                        final String name=Utils.callerId(context, incomingNumber);
                        if(name==null)
-                               Utils.sendMessage(context, toNonNull(MessageType.PHONE_STATE),
-                                               context.getString(phone_status_ringing)+incomingNumber);
+                               Utils.sendMessage(context, toNonNull(MessageType.PHONE_STATE), phone_status_ringing, incomingNumber);
                        else
                                Utils.sendMessage(context, toNonNull(MessageType.PHONE_STATE),
-                                               context.getString(phone_status_ringing)+incomingNumber+" ("+name+")");
+                                               phone_status_ringing, incomingNumber + " ("+name+")");
                        break;
                case TelephonyManager.CALL_STATE_OFFHOOK:
-                       Utils.sendMessage(context, toNonNull(MessageType.PHONE_STATE),
-                                       toNonNull(context.getString(phone_status_offhook)));
+                       Utils.sendMessage(context, toNonNull(MessageType.PHONE_STATE), phone_status_offhook);
                        break;
                }
        }
index fcc5e4d40b9bbb54ab1fea6eeb6fb888864facdb..3eb17a875685c1fe75ac9881bdd6a29b7109883f 100644 (file)
@@ -337,7 +337,7 @@ final class Heavy {
                        try{
                                sock = SocketChannel.open(new InetSocketAddress(hostname, port));
                        } catch (final IOException e){
-                               Utils.sendMessage(context, replyTo, toNonNull(context.getString(cannot_connect_to_host_on_port, hostname, Integer.valueOf(port))));
+                               Utils.sendMessage(context, replyTo, cannot_connect_to_host_on_port, hostname, Integer.valueOf(port));
                                try {
                                        in.close();
                                } catch (IOException ex) {
@@ -349,7 +349,7 @@ final class Heavy {
                        try{
                                in.transferTo(0, in.size(), sock);
                        } catch (final IOException e){
-                               Utils.sendMessage(context, replyTo, toNonNull(context.getString(io_error, e.getMessage())));
+                               Utils.sendMessage(context, replyTo, io_error, e.getMessage());
                        } finally {
                                try{
                                        in.close();
@@ -410,7 +410,7 @@ final class Heavy {
                                sock = new Socket(hostname, port);
                                in = sock.getInputStream();
                        } catch (final IOException e){
-                               Utils.sendMessage(context, replyTo, toNonNull(context.getString(cannot_connect_to_host_on_port, hostname, Integer.valueOf(port))));
+                               Utils.sendMessage(context, replyTo, cannot_connect_to_host_on_port, hostname, Integer.valueOf(port));
                                try {
                                        out.close();
                                } catch (IOException ex) {
@@ -425,7 +425,7 @@ final class Heavy {
                                while((nread = in.read(buffer)) > 0)
                                        out.write(buffer, 0, nread);
                        } catch (final IOException e){
-                               Utils.sendMessage(context, replyTo, toNonNull(context.getString(io_error, e.getMessage())));
+                               Utils.sendMessage(context, replyTo, io_error, e.getMessage());
                        } finally {
                                try{
                                        out.close();
@@ -1005,10 +1005,10 @@ final class Heavy {
                                        CommonDataKinds.Phone.LABEL);
 
                        while(inCursor.moveToNext())
-                               Utils.sendMessage(context, replyTo, toNonNull(context.getString(contact_info,
+                               Utils.sendMessage(context, replyTo, contact_info,
                                                cursor.getString(0),
                                                inCursor.getString(0),
-                                               phoneNumberType(context, inCursor.getInt(1), inCursor.getString(2)))));
+                                               phoneNumberType(context, inCursor.getInt(1), inCursor.getString(2)));
 
                        inCursor.close();
                }
index 7ad1537192d3c679526f2824b4124963833d2784..66256896487b293c8af64a622fc83c4381168678 100644 (file)
@@ -45,16 +45,13 @@ public final class ProtectedBroadcastReceiver extends BroadcastReceiver {
                final String action=intent.getAction();
 
                if(action.equals(Intent.ACTION_BATTERY_LOW)){
-                       Utils.sendMessage(context, toNonNull(MessageType.BATTERY),
-                                       toNonNull(context.getString(battery_low)));
+                       Utils.sendMessage(context, toNonNull(MessageType.BATTERY), battery_low);
                        Heavy.describeBatteryLevel(context, null, toNonNull(MessageType.BATTERY));
                } else if(action.equals(Intent.ACTION_BATTERY_OKAY)){
-                       Utils.sendMessage(context, toNonNull(MessageType.BATTERY),
-                                       toNonNull(context.getString(battery_okay)));
+                       Utils.sendMessage(context, toNonNull(MessageType.BATTERY),battery_okay);
                        Heavy.describeBatteryLevel(context, null, toNonNull(MessageType.BATTERY));
                } else if(action.equals(Intent.ACTION_BOOT_COMPLETED)){
-                       Utils.sendMessage(context, toNonNull(MessageType.BOOT),
-                                                         toNonNull(context.getString(device_booted)));
+                       Utils.sendMessage(context, toNonNull(MessageType.BOOT), device_booted);
                } else if(action.equals(ConnectivityManager.CONNECTIVITY_ACTION))
                        context.startService(new Intent(context, FonBotMainService.class));
        }
index 30809ae3189745c6c93cf8ac9198398f0e85cdb0..59a96a56a54a3247d4ff72f9eaa53a900d95b901 100644 (file)
@@ -1,5 +1,6 @@
 package ro.ieval.fonbot;
 
+import static ro.ieval.fonbot.R.string.*;
 import org.eclipse.jdt.annotation.Nullable;
 
 import android.app.Activity;
@@ -40,8 +41,8 @@ public final class SmsStatusReceiver extends BroadcastReceiver {
         * @return the string representation of the SMS
         */
        private static String describeSMS(final Intent intent){
-               return " ("+"To: "+intent.getStringExtra(EXTRA_DESTINATION)+
-                               ", Part: "+intent.getIntExtra(EXTRA_PART, 1)+" of "+intent.getIntExtra(EXTRA_TOTAL, 1)+")";
+               return "To: "+intent.getStringExtra(EXTRA_DESTINATION)+
+                               ", Part: "+intent.getIntExtra(EXTRA_PART, 1)+" of "+intent.getIntExtra(EXTRA_TOTAL, 1);
        }
 
        /**
@@ -77,28 +78,28 @@ public final class SmsStatusReceiver extends BroadcastReceiver {
                if(intent.getAction().startsWith(SENT_ACTION))
                        switch(getResultCode()){
                        case Activity.RESULT_OK:
-                               Utils.sendMessage(context, replyTo, "SMS sent"+describeSMS(intent));
+                               Utils.sendMessage(context, replyTo, sms_sent, describeSMS(intent));
                                break;
                        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
-                               Utils.sendMessage(context, replyTo, "SMS not sent: Generic failure"+describeSMS(intent));
+                               Utils.sendMessage(context, replyTo, sms_not_sent_generic_failure, describeSMS(intent));
                                break;
                        case SmsManager.RESULT_ERROR_NO_SERVICE:
-                               Utils.sendMessage(context, replyTo, "SMS not sent: No service"+describeSMS(intent));
+                               Utils.sendMessage(context, replyTo, sms_not_sent_no_service, describeSMS(intent));
                                break;
                        case SmsManager.RESULT_ERROR_NULL_PDU:
-                               Utils.sendMessage(context, replyTo, "SMS not sent: Null PDU"+describeSMS(intent));
+                               Utils.sendMessage(context, replyTo, sms_not_sent_null_pdu, describeSMS(intent));
                                break;
                        case SmsManager.RESULT_ERROR_RADIO_OFF:
-                               Utils.sendMessage(context, replyTo, "SMS not sent: Radio off"+describeSMS(intent));
+                               Utils.sendMessage(context, replyTo, sms_not_sent_radio_off, describeSMS(intent));
                                break;
                        }
                else if(intent.getAction().startsWith(DELIVERED_ACTION))
                        switch(getResultCode()){
                        case Activity.RESULT_OK:
-                               Utils.sendMessage(context, replyTo, "SMS delivered"+describeSMS(intent));
+                               Utils.sendMessage(context, replyTo, sms_delivered, describeSMS(intent));
                                break;
                        case Activity.RESULT_CANCELED:
-                               Utils.sendMessage(context, replyTo, "SMS not delivered"+describeSMS(intent));
+                               Utils.sendMessage(context, replyTo, sms_not_delivered, describeSMS(intent));
                                break;
                        }
        }
This page took 0.032853 seconds and 4 git commands to generate.