rename Alarm -> Alert

This commit is contained in:
Milos Kozak 2016-07-07 00:20:47 +02:00
parent ca31195b15
commit 725db13776
4 changed files with 26 additions and 28 deletions

View file

@ -63,9 +63,9 @@
<service
android:name=".Services.DataService"
android:exported="false" />
<!-- Service showing alarm on screen -->
<!-- Service showing alert on screen -->
<service
android:name=".Services.AlarmService"
android:name=".Services.AlertService"
android:exported="false" />
<meta-data

View file

@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Iterator;
import info.nightscout.androidaps.Services.AlarmService;
import info.nightscout.androidaps.Services.AlertService;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
@ -163,7 +163,7 @@ public class MainActivity extends AppCompatActivity {
REQUEST_CODE_ASK_PERMISSIONS
);
}
Intent alarmServiceIntent = new Intent(getApplicationContext(), AlarmService.class);
Intent alarmServiceIntent = new Intent(getApplicationContext(), AlertService.class);
alarmServiceIntent.putExtra("alarmText", getString(R.string.nav_test_alarm));
getApplicationContext().startService(alarmServiceIntent);
break;

View file

@ -6,7 +6,6 @@ import android.graphics.Typeface;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.PowerManager;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
@ -19,12 +18,11 @@ import org.slf4j.LoggerFactory;
import java.util.Calendar;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
public class AlarmMessage {
private static Logger log = LoggerFactory.getLogger(AlarmMessage.class);
public class AlertMessage {
private static Logger log = LoggerFactory.getLogger(AlertMessage.class);
private static boolean displayed = false;
@ -39,7 +37,7 @@ public class AlarmMessage {
private static int mSoundID;
private static int mPlayingId;
private Runnable mOnDismiss;
private String mAlarmText = "Alarm";
private String mAlertText = "Alarm";
PowerManager.WakeLock mWakeLock;
static {
@ -47,10 +45,10 @@ public class AlarmMessage {
mSoundID = mSoundPool.load(MainApp.instance().getApplicationContext(), R.raw.beep_beep, 1);
}
public AlarmMessage(Context mApplicationContext) {
public AlertMessage(Context mApplicationContext) {
this.mApplicationContext = mApplicationContext;
PowerManager powerManager = (PowerManager) mApplicationContext.getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "AlarmMessage");
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "AlertMessage");
}
public void showMessage() {
@ -100,7 +98,7 @@ public class AlarmMessage {
mFloatingTextView = new TextView(getApplicationContext());
mLinLayout.addView(mFloatingTextView);
mFloatingTextView.setText(mAlarmText);
mFloatingTextView.setText(mAlertText);
mFloatingTextView.setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL));
mFloatingTextView.setTextSize(24.0F);
mFloatingTextView.setGravity(Gravity.CENTER);
@ -119,7 +117,7 @@ public class AlarmMessage {
mButtonDismis.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlarmMessage.this.dismis();
AlertMessage.this.dismis();
if (mOnDismiss != null) {
mOnDismiss.run();
}
@ -145,7 +143,7 @@ public class AlarmMessage {
}
public void setText(String text) {
mAlarmText = text;
mAlertText = text;
}
public void setOnDismiss(Runnable runnable) {

View file

@ -13,8 +13,8 @@ import java.util.Date;
import info.nightscout.androidaps.Config;
public class AlarmService extends Service {
private static Logger log = LoggerFactory.getLogger(AlarmService.class);
public class AlertService extends Service {
private static Logger log = LoggerFactory.getLogger(AlertService.class);
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
@ -22,40 +22,40 @@ public class AlarmService extends Service {
log.debug("onStartCommand");
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
long lastAlarm = preferences.getLong("lastAlarm", 0);
long lastAlert = preferences.getLong("lastAlert", 0);
long currentTime = new Date().getTime();
//if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("masterSwitch", false)) {
// stopSelf(startId);
// log.debug("Alarm posponed - master switch disabled");
// log.debug("Alert posponed - master switch disabled");
//} else
//if ((currentTime - lastAlarm) < 15 * 60 * 1000) {
//if ((currentTime - lastAlert) < 15 * 60 * 1000) {
// stopSelf(startId);
// log.debug("Alarm posponed");
// log.debug("Alert posponed");
//} else
{
AlarmMessage alarm = new AlarmMessage(getApplicationContext());
AlertMessage alert = new AlertMessage(getApplicationContext());
if (intent != null) {
String alarmText = intent.getStringExtra("alarmText");
if (alarmText != null) {
alarm.setText(alarmText);
String alertText = intent.getStringExtra("alertText");
if (alertText != null) {
alert.setText(alertText);
}
alarm.setOnDismiss(new Runnable() {
alert.setOnDismiss(new Runnable() {
@Override
public void run() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = preferences.edit();
editor.putLong("lastAlarm", new Date().getTime());
editor.putLong("lastAlert", new Date().getTime());
editor.commit();
AlarmService.this.stopSelf();
AlertService.this.stopSelf();
}
});
alarm.showMessage();
alert.showMessage();
}
}
if (Config.logFunctionCalls)