SMS logging and resource refactor
This commit is contained in:
parent
666874c6c4
commit
87ad140eb5
4 changed files with 31 additions and 25 deletions
|
@ -140,7 +140,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
.setMessage(R.string.reset_db_confirm)
|
.setMessage(R.string.reset_db_confirm)
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
@Override public void onClick(DialogInterface dialog, int which) {
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
MainApp.getDbHelper().resetDatabases();
|
MainApp.getDbHelper().resetDatabases();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -208,31 +209,31 @@ public class MainActivity extends AppCompatActivity {
|
||||||
//check for sms permission if enable in prefernces
|
//check for sms permission if enable in prefernces
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||||
|
if (ev.isChanged(R.string.key_smscommunicator_remotecommandsallowed)) {
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
SharedPreferences smssettings = PreferenceManager.getDefaultSharedPreferences(this);
|
synchronized (this) {
|
||||||
synchronized (this){
|
if (SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)) {
|
||||||
if (smssettings.getBoolean("smscommunicator_remotecommandsallowed", false)) {
|
|
||||||
setAskForSMS();
|
setAskForSMS();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized void setAskForSMS() {
|
private synchronized void setAskForSMS() {
|
||||||
askForSMS = true;
|
askForSMS = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume(){
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
askForSMSPermissions();
|
askForSMSPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void askForSMSPermissions(){
|
private synchronized void askForSMSPermissions() {
|
||||||
if (askForSMS) { //only when settings were changed an MainActivity resumes.
|
if (askForSMS) { //only when settings were changed an MainActivity resumes.
|
||||||
askForSMS = false;
|
askForSMS = false;
|
||||||
SharedPreferences smssettings = PreferenceManager.getDefaultSharedPreferences(this);
|
if (SP.getBoolean(R.string.smscommunicator_remotecommandsallowed, false)) {
|
||||||
if (smssettings.getBoolean("smscommunicator_remotecommandsallowed", false)) {
|
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
askForPermission(new String[]{Manifest.permission.RECEIVE_SMS,
|
askForPermission(new String[]{Manifest.permission.RECEIVE_SMS,
|
||||||
Manifest.permission.SEND_SMS,
|
Manifest.permission.SEND_SMS,
|
||||||
|
@ -244,7 +245,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private void askForPermission(String[] permission, Integer requestCode) {
|
private void askForPermission(String[] permission, Integer requestCode) {
|
||||||
boolean test = false;
|
boolean test = false;
|
||||||
for (int i=0; i < permission.length; i++) {
|
for (int i = 0; i < permission.length; i++) {
|
||||||
test = test || (ContextCompat.checkSelfPermission(this, permission[i]) != PackageManager.PERMISSION_GRANTED);
|
test = test || (ContextCompat.checkSelfPermission(this, permission[i]) != PackageManager.PERMISSION_GRANTED);
|
||||||
}
|
}
|
||||||
if (test) {
|
if (test) {
|
||||||
|
@ -276,10 +277,10 @@ public class MainActivity extends AppCompatActivity {
|
||||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
View v = getCurrentFocus();
|
View v = getCurrentFocus();
|
||||||
if ( v instanceof EditText) {
|
if (v instanceof EditText) {
|
||||||
Rect outRect = new Rect();
|
Rect outRect = new Rect();
|
||||||
v.getGlobalVisibleRect(outRect);
|
v.getGlobalVisibleRect(outRect);
|
||||||
if (!outRect.contains((int)event.getRawX(), (int)event.getRawY())) {
|
if (!outRect.contains((int) event.getRawX(), (int) event.getRawY())) {
|
||||||
v.clearFocus();
|
v.clearFocus();
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||||
|
|
|
@ -160,7 +160,8 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void processSettings(final EventPreferenceChange ev) {
|
public void processSettings(final EventPreferenceChange ev) {
|
||||||
String settings = SP.getString("smscommunicator_allowednumbers", "");
|
if (ev.isChanged(R.string.key_smscommunicator_allowednumbers)) {
|
||||||
|
String settings = SP.getString(R.string.key_smscommunicator_allowednumbers, "");
|
||||||
|
|
||||||
String pattern = ";";
|
String pattern = ";";
|
||||||
|
|
||||||
|
@ -171,6 +172,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
log.debug("Found allowed number: " + cleaned);
|
log.debug("Found allowed number: " + cleaned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean isAllowedNumber(String number) {
|
boolean isAllowedNumber(String number) {
|
||||||
for (String num : allowedNumbers) {
|
for (String num : allowedNumbers) {
|
||||||
|
@ -317,7 +319,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
break;
|
break;
|
||||||
case "BASAL":
|
case "BASAL":
|
||||||
if (splited.length > 1) {
|
if (splited.length > 1) {
|
||||||
boolean remoteCommandsAllowed = SP.getBoolean("smscommunicator_remotecommandsallowed", false);
|
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
|
||||||
if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) {
|
if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) {
|
||||||
if (remoteCommandsAllowed) {
|
if (remoteCommandsAllowed) {
|
||||||
passCode = generatePasscode();
|
passCode = generatePasscode();
|
||||||
|
@ -353,7 +355,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
} else if (splited.length > 1) {
|
} else if (splited.length > 1) {
|
||||||
amount = SafeParse.stringToDouble(splited[1]);
|
amount = SafeParse.stringToDouble(splited[1]);
|
||||||
amount = MainApp.getConfigBuilder().applyBolusConstraints(amount);
|
amount = MainApp.getConfigBuilder().applyBolusConstraints(amount);
|
||||||
boolean remoteCommandsAllowed = SP.getBoolean("smscommunicator_remotecommandsallowed", false);
|
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
|
||||||
if (amount > 0d && remoteCommandsAllowed) {
|
if (amount > 0d && remoteCommandsAllowed) {
|
||||||
passCode = generatePasscode();
|
passCode = generatePasscode();
|
||||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusreplywithcode), amount, passCode);
|
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusreplywithcode), amount, passCode);
|
||||||
|
@ -370,7 +372,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
case "CAL":
|
case "CAL":
|
||||||
if (splited.length > 1) {
|
if (splited.length > 1) {
|
||||||
amount = SafeParse.stringToDouble(splited[1]);
|
amount = SafeParse.stringToDouble(splited[1]);
|
||||||
boolean remoteCommandsAllowed = SP.getBoolean("smscommunicator_remotecommandsallowed", false);
|
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
|
||||||
if (amount > 0d && remoteCommandsAllowed) {
|
if (amount > 0d && remoteCommandsAllowed) {
|
||||||
passCode = generatePasscode();
|
passCode = generatePasscode();
|
||||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_calibrationreplywithcode), amount, passCode);
|
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_calibrationreplywithcode), amount, passCode);
|
||||||
|
@ -478,6 +480,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
sms.text = stripAccents(sms.text);
|
sms.text = stripAccents(sms.text);
|
||||||
if (sms.text.length() > 140) sms.text = sms.text.substring(0, 139);
|
if (sms.text.length() > 140) sms.text = sms.text.substring(0, 139);
|
||||||
try {
|
try {
|
||||||
|
log.debug("Sending SMS to " + sms.phoneNumber + ": " + sms.text);
|
||||||
smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null);
|
smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null);
|
||||||
messages.add(sms);
|
messages.add(sms);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|
|
@ -542,4 +542,6 @@
|
||||||
<string name="wear_detailedIOB_summary">Break down IOB into bolus and basal IOB on the watchface</string>
|
<string name="wear_detailedIOB_summary">Break down IOB into bolus and basal IOB on the watchface</string>
|
||||||
<string name="nosuccess">not successful - please check phone</string>
|
<string name="nosuccess">not successful - please check phone</string>
|
||||||
<string name="notavailable">Not available</string>
|
<string name="notavailable">Not available</string>
|
||||||
|
<string name="key_smscommunicator_allowednumbers" translatable="false">smscommunicator_allowednumbers</string>
|
||||||
|
<string name="key_smscommunicator_remotecommandsallowed" translatable="false">smscommunicator_remotecommandsallowed</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:title="@string/smscommunicator_allowednumbers"
|
android:title="@string/smscommunicator_allowednumbers"
|
||||||
android:summary="@string/smscommunicator_allowednumbers_summary"
|
android:summary="@string/smscommunicator_allowednumbers_summary"
|
||||||
android:key="smscommunicator_allowednumbers"
|
android:key="@string/smscommunicator_allowednumbers"
|
||||||
android:defaultValue="">
|
android:defaultValue="">
|
||||||
</EditTextPreference>
|
</EditTextPreference>
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="smscommunicator_remotecommandsallowed"
|
android:key="@string/key_smscommunicator_remotecommandsallowed"
|
||||||
android:title="@string/smscommunicator_remotecommandsallowed" />
|
android:title="@string/smscommunicator_remotecommandsallowed" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
Loading…
Reference in a new issue