Merge branch 'dev' into batteryopt

This commit is contained in:
Milos Kozak 2019-08-03 23:17:02 +02:00
commit 4831eb9193
15 changed files with 179 additions and 185 deletions

View file

@ -11,13 +11,13 @@ import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.utils.SP;
public class AgreementActivity extends Activity {
public class AgreementActivity extends NoSplashActivity {
boolean IUnderstand;
CheckBox agreeCheckBox;
Button saveButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_agreement);
IUnderstand = SP.getBoolean(R.string.key_i_understand, false);

View file

@ -45,7 +45,7 @@ import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.T;
public class HistoryBrowseActivity extends AppCompatActivity {
public class HistoryBrowseActivity extends NoSplashActivity {
private static Logger log = LoggerFactory.getLogger(HistoryBrowseActivity.class);
@ -82,7 +82,7 @@ public class HistoryBrowseActivity extends AppCompatActivity {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_historybrowse);

View file

@ -0,0 +1,13 @@
package info.nightscout.androidaps.activities
import android.app.Activity
import android.os.Bundle
import info.nightscout.androidaps.R
open class NoSplashActivity : Activity() {
public override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.AppTheme_NoActionBar)
super.onCreate(savedInstanceState)
}
}

View file

@ -56,6 +56,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme_NoActionBar);
super.onCreate(savedInstanceState);
myPreferenceFragment = new MyPreferenceFragment();
Bundle args = new Bundle();

View file

@ -52,7 +52,7 @@ import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.SafeParse;
public class TDDStatsActivity extends Activity {
public class TDDStatsActivity extends NoSplashActivity {
private static Logger log = LoggerFactory.getLogger(TDDStatsActivity.class);
TextView statusView, statsMessage, totalBaseBasal2;
@ -99,7 +99,7 @@ public class TDDStatsActivity extends Activity {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.danar_statsactivity);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.aps.openAPSAMA;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -97,7 +98,7 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
currentTempView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getCurrentTempParam()));
try {
JSONArray iobArray = new JSONArray(determineBasalAdapterAMAJS.getIobDataParam());
iobDataView.setText(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0)));
iobDataView.setText(TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))));
} catch (JSONException e) {
log.error("Unhandled exception", e);
iobDataView.setText("JSONException");

View file

@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMB;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -94,26 +96,26 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
}
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = plugin.lastDetermineBasalAdapterSMBJS;
if (determineBasalAdapterSMBJS != null) {
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam()).toString().trim());
currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam()).toString().trim());
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam()));
currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam()));
try {
JSONArray iobArray = new JSONArray(determineBasalAdapterSMBJS.getIobDataParam());
iobDataView.setText((String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0))).trim());
iobDataView.setText(TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))));
} catch (JSONException e) {
log.error("Unhandled exception", e);
iobDataView.setText("JSONException see log for details");
}
profileView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getProfileParam()).toString().trim());
mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam()).toString().trim());
scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug().trim());
profileView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getProfileParam()));
mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam()));
scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug());
if (lastAPSResult != null && lastAPSResult.inputConstraints != null)
constraintsView.setText(lastAPSResult.inputConstraints.getReasons().trim());
constraintsView.setText(lastAPSResult.inputConstraints.getReasons());
}
if (plugin.lastAPSRun != 0) {
lastRunView.setText(DateUtil.dateAndTimeFullString(plugin.lastAPSRun));
}
if (plugin.lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()).toString().trim());
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()));
}
}
});

View file

@ -1,112 +0,0 @@
package info.nightscout.androidaps.plugins.general.overview.dialogs;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import androidx.fragment.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.services.AlarmSoundService;
public class ErrorDialog extends DialogFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(ErrorDialog.class);
Button muteButton;
Button okButton;
TextView statusView;
ErrorHelperActivity helperActivity;
static String status;
static String title;
static int soundId;
public ErrorDialog() {
super();
}
public void setStatus(String status) {
this.status = status;
}
public void setTitle(String title) {
this.title = title;
}
public void setSound(int soundId) {
this.soundId = soundId;
}
public void setHelperActivity(ErrorHelperActivity activity) {
this.helperActivity = activity;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getDialog().setTitle(title);
View view = inflater.inflate(R.layout.overview_error_dialog, container, false);
muteButton = (Button) view.findViewById(R.id.overview_error_mute);
okButton = (Button) view.findViewById(R.id.overview_error_ok);
statusView = (TextView) view.findViewById(R.id.overview_error_status);
muteButton.setOnClickListener(this);
okButton.setOnClickListener(this);
setCancelable(false);
startAlarm();
return view;
}
@Override
public void onResume() {
super.onResume();
if (getDialog() != null)
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
statusView.setText(status);
}
@Override
public void dismiss() {
super.dismissAllowingStateLoss();
if (helperActivity != null) {
helperActivity.finish();
}
stopAlarm();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.overview_error_mute:
log.debug("Error dialog mute button pressed");
stopAlarm();
break;
case R.id.overview_error_ok:
log.debug("Error dialog ok button pressed");
dismiss();
break;
}
}
private void startAlarm() {
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
alarm.putExtra("soundid", soundId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
MainApp.instance().startForegroundService(alarm);
else
MainApp.instance().startService(alarm);
}
private void stopAlarm() {
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
MainApp.instance().stopService(alarm);
}
}

View file

@ -0,0 +1,85 @@
package info.nightscout.androidaps.plugins.general.overview.dialogs
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.services.AlarmSoundService
import kotlinx.android.synthetic.main.overview_error_dialog.*
import org.slf4j.LoggerFactory
class ErrorDialog : DialogFragment() {
private val log = LoggerFactory.getLogger(ErrorDialog::class.java)
var helperActivity: ErrorHelperActivity? = null
var status: String = ""
var title: String = ""
var sound: Int = 0
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
dialog.setTitle(title)
isCancelable = false
savedInstanceState?.let { bundle ->
bundle.getString("status")?.let { status = it }
bundle.getString("title")?.let { title = it }
sound = bundle.getInt("sound", R.raw.error)
}
return inflater.inflate(R.layout.overview_error_dialog, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
overview_error_ok.setOnClickListener {
log.debug("Error dialog ok button pressed")
dismiss()
}
overview_error_mute.setOnClickListener {
log.debug("Error dialog mute button pressed")
stopAlarm()
}
startAlarm()
}
override fun onSaveInstanceState(bundle: Bundle) {
super.onSaveInstanceState(bundle)
bundle.putString("status", status)
bundle.putString("title", title)
bundle.putInt("sound", sound)
}
override fun onResume() {
super.onResume()
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
overview_error_status.text = status
}
override fun dismiss() {
super.dismissAllowingStateLoss()
helperActivity?.finish()
stopAlarm()
}
private fun startAlarm() {
if (sound != 0) {
val alarm = Intent(MainApp.instance().applicationContext, AlarmSoundService::class.java)
alarm.putExtra("soundid", sound)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
MainApp.instance().startForegroundService(alarm)
} else {
MainApp.instance().startService(alarm)
}
}
}
private fun stopAlarm() =
MainApp.instance().stopService(Intent(MainApp.instance().applicationContext, AlarmSoundService::class.java))
}

View file

@ -1,29 +0,0 @@
package info.nightscout.androidaps.plugins.general.overview.dialogs;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
public class ErrorHelperActivity extends AppCompatActivity {
public ErrorHelperActivity() {
super();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ErrorDialog errorDialog = new ErrorDialog();
errorDialog.setHelperActivity(this);
errorDialog.setStatus(getIntent().getStringExtra("status"));
errorDialog.setSound(getIntent().getIntExtra("soundid", 0));
errorDialog.setTitle(getIntent().getStringExtra("title"));
errorDialog.show(this.getSupportFragmentManager(), "Error");
if (SP.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) {
NSUpload.uploadError(getIntent().getStringExtra("status"));
}
}
}

View file

@ -0,0 +1,25 @@
package info.nightscout.androidaps.plugins.general.overview.dialogs
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import info.nightscout.androidaps.R
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
import info.nightscout.androidaps.utils.SP
class ErrorHelperActivity : AppCompatActivity() {
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val errorDialog = ErrorDialog()
errorDialog.helperActivity = this
errorDialog.status = intent.getStringExtra("status")
errorDialog.sound = intent.getIntExtra("soundid", R.raw.error)
errorDialog.title = intent.getStringExtra("title")
errorDialog.show(supportFragmentManager, "Error")
if (SP.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) {
NSUpload.uploadError(intent.getStringExtra("status"))
}
}
}

View file

@ -7,13 +7,14 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.view.View;
import androidx.core.app.NotificationCompat;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -66,7 +67,7 @@ public class NotificationStore {
if (SP.getBoolean(MainApp.gs(R.string.key_raise_notifications_as_android_notifications), false) && !(n instanceof NotificationWithAction)) {
raiseSystemNotification(n);
if (usesChannels && n.soundId != null) {
if (usesChannels && n.soundId != null && n.soundId != 0) {
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
alarm.putExtra("soundid", n.soundId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
@ -76,7 +77,7 @@ public class NotificationStore {
}
} else {
if (n.soundId != null) {
if (n.soundId != null && n.soundId != 0) {
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
alarm.putExtra("soundid", n.soundId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
@ -146,7 +147,7 @@ public class NotificationStore {
if (n.level == Notification.URGENT) {
notificationBuilder.setVibrate(new long[]{1000, 1000, 1000, 1000})
.setContentTitle(MainApp.gs(R.string.urgent_alarm))
.setSound(sound, AudioAttributes.USAGE_ALARM);
.setSound(sound, AudioManager.STREAM_ALARM);
} else {
notificationBuilder.setVibrate(new long[]{0, 100, 50, 100, 50})
.setContentTitle(MainApp.gs(R.string.info))

View file

@ -1529,6 +1529,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
ServiceTaskExecutor.startTask(new WakeAndTuneTask());
} else {
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", MainApp.gs(R.string.medtronic_error_operation_not_possible_no_configuration));
i.putExtra("title", MainApp.gs(R.string.combo_warning));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

View file

@ -38,6 +38,8 @@ public class AlarmSoundService extends Service {
super.onCreate();
if (L.isEnabled(L.CORE))
log.debug("onCreate");
Notification notification = PersistentNotificationPlugin.getPlugin().getLastNotification();
startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, notification);
}
public int onStartCommand(Intent intent, int flags, int startId) {
@ -51,28 +53,22 @@ public class AlarmSoundService extends Service {
resourceId = intent.getIntExtra("soundid", R.raw.error);
player = new MediaPlayer();
try {
AssetFileDescriptor afd = MainApp.sResources.openRawResourceFd(resourceId);
if (afd == null)
return START_STICKY;
try {
player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
} catch (IOException e) {
log.error("Unhandled exception", e);
}
player.setLooping(true); // Set looping
AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
if (manager == null || !manager.isMusicActive()) {
player.setVolume(100, 100);
}
try {
player.prepare();
player.start();
} catch (IOException e) {
} catch (Exception e) {
log.error("Unhandled exception", e);
}
return START_STICKY;
}

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.utils;
import android.os.Build;
import android.text.Html;
import android.text.Spanned;
@ -18,14 +19,23 @@ public class JSONFormatter {
private static Logger log = LoggerFactory.getLogger(JSONFormatter.class);
public static Spanned format(final String jsonString) {
final JsonVisitor visitor = new JsonVisitor(4, ' ');
final JsonVisitor visitor = new JsonVisitor(1, '\t');
try {
if (jsonString.equals("undefined"))
return Html.fromHtml("undefined");
else if (jsonString.getBytes()[0] == '[')
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return Html.fromHtml(visitor.visit(new JSONArray(jsonString), 0), Html.FROM_HTML_MODE_COMPACT);
} else {
return Html.fromHtml(visitor.visit(new JSONArray(jsonString), 0));
else
}
else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return Html.fromHtml(visitor.visit(new JSONObject(jsonString), 0), Html.FROM_HTML_MODE_COMPACT);
} else {
return Html.fromHtml(visitor.visit(new JSONObject(jsonString), 0));
}
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
return Html.fromHtml("");
@ -33,7 +43,7 @@ public class JSONFormatter {
}
public static Spanned format(final JSONObject object) {
final JsonVisitor visitor = new JsonVisitor(4, ' ');
final JsonVisitor visitor = new JsonVisitor(1, '\t');
try {
return Html.fromHtml(visitor.visit(object, 0));
} catch (JSONException e) {
@ -58,7 +68,7 @@ public class JSONFormatter {
} else {
ret += write("[", indent);
for (int i = 0; i < length; i++) {
ret += visit(array.get(i), indent + 1);
ret += visit(array.get(i), indent);
}
ret += write("]", indent);
}
@ -73,8 +83,8 @@ public class JSONFormatter {
final Iterator<String> keys = obj.keys();
while (keys.hasNext()) {
final String key = keys.next();
ret += write("<b>" + key + "</b>: ", indent + 1);
ret += visit(obj.get(key), 0);
ret += write("<b>" + key + "</b>: ", indent);
ret += visit(obj.get(key), indent + 1);
ret += "<br>";
}
}
@ -86,7 +96,7 @@ public class JSONFormatter {
if (object instanceof JSONArray) {
ret += visit((JSONArray) object, indent);
} else if (object instanceof JSONObject) {
ret += visit((JSONObject) object, indent);
ret += "<br>" + visit((JSONObject) object, indent);
} else {
if (object instanceof String) {
ret += write("\"" + ((String) object).replace("<", "&lt;").replace(">", "&gt;") + "\"", indent);