diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c9f14c62c5..b464ee824a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -65,9 +65,6 @@ android:name=".Services.DataService" android:exported="false" /> - Apps -> Draw over other apps - ActivityCompat.requestPermissions( - this, - new String[]{Manifest.permission.SYSTEM_ALERT_WINDOW}, - REQUEST_CODE_ASK_PERMISSIONS - ); - } - Intent alertServiceIntent = new Intent(getApplicationContext(), AlertService.class); - alertServiceIntent.putExtra("alertText", getString(R.string.nav_test_alert)); - getApplicationContext().startService(alertServiceIntent); - break; +// case R.id.nav_test_alarm: +// final int REQUEST_CODE_ASK_PERMISSIONS = 2355; +// int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.SYSTEM_ALERT_WINDOW); +// if (permission != PackageManager.PERMISSION_GRANTED) { +// // We don't have permission so prompt the user +// // On Android 6 give permission for alarming in Settings -> Apps -> Draw over other apps +// ActivityCompat.requestPermissions( +// this, +// new String[]{Manifest.permission.SYSTEM_ALERT_WINDOW}, +// REQUEST_CODE_ASK_PERMISSIONS +// ); +// } +// Intent alertServiceIntent = new Intent(getApplicationContext(), AlertService.class); +// alertServiceIntent.putExtra("alertText", getString(R.string.nav_test_alert)); +// getApplicationContext().startService(alertServiceIntent); +// break; case R.id.nav_exit: log.debug("Exiting"); keepAliveReceiver.cancelAlarm(this); diff --git a/app/src/main/java/info/nightscout/androidaps/Services/AlertMessage.java b/app/src/main/java/info/nightscout/androidaps/Services/AlertMessage.java deleted file mode 100644 index 33fe6c9637..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/Services/AlertMessage.java +++ /dev/null @@ -1,152 +0,0 @@ -package info.nightscout.androidaps.Services; - -import android.content.Context; -import android.graphics.Color; -import android.graphics.Typeface; -import android.media.AudioManager; -import android.media.SoundPool; -import android.os.PowerManager; -import android.view.Gravity; -import android.view.View; -import android.view.WindowManager; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.TextView; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Calendar; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; - -public class AlertMessage { - private static Logger log = LoggerFactory.getLogger(AlertMessage.class); - - private static boolean displayed = false; - - private WindowManager mWindowManager; - private LinearLayout mLinLayout; - private WindowManager.LayoutParams mLinLayoutParams; - private TextView mFloatingTextView; - private Context mApplicationContext; - private Button mButtonDismis; - - private static SoundPool mSoundPool; - private static int mSoundID; - private static int mPlayingId; - private Runnable mOnDismiss; - private String mAlertText = "Alarm"; - PowerManager.WakeLock mWakeLock; - - static { - mSoundPool = new SoundPool(1, AudioManager.STREAM_ALARM, 0); - mSoundID = mSoundPool.load(MainApp.instance().getApplicationContext(), R.raw.beep_beep, 1); - } - - 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, "AlertMessage"); - } - - public void showMessage() { - log.debug("showMessage() displayed:" + displayed); - if (displayed) { - return; - } - displayed = true; - mWakeLock.acquire(); - - mPlayingId = 0; - int hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); - float volume = (hourOfDay > 11 && hourOfDay < 23) ? 0.03f : 1.0f; - do { - mPlayingId = mSoundPool.play(mSoundID, volume, volume, 0, -1, 1f); - log.debug("mSoundPool.play returned " + mPlayingId); - if (mPlayingId == 0) { - try { - synchronized (this) { - this.wait(100); - } - } catch (InterruptedException e) { - } - } - } while (mPlayingId == 0); - - if (mWindowManager == null) - mWindowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); - if (mLinLayout != null) - mWindowManager.removeViewImmediate(mLinLayout); - - mLinLayout = new LinearLayout(getApplicationContext()); - mLinLayoutParams = new WindowManager.LayoutParams(); - - mLinLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; - mLinLayoutParams.format = 1; - mLinLayoutParams.flags = - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | - WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | - WindowManager.LayoutParams.FLAG_FULLSCREEN; - mLinLayoutParams.width = 500; - mLinLayoutParams.height = 200; - mLinLayoutParams.gravity = Gravity.CENTER; - mLinLayout.setBackgroundColor(Color.argb(220, 255, 0, 0)); - mWindowManager.addView(mLinLayout, mLinLayoutParams); - mLinLayout.setOrientation(LinearLayout.VERTICAL); - mFloatingTextView = new TextView(getApplicationContext()); - mLinLayout.addView(mFloatingTextView); - - mFloatingTextView.setText(mAlertText); - mFloatingTextView.setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL)); - mFloatingTextView.setTextSize(24.0F); - mFloatingTextView.setGravity(Gravity.CENTER); - mFloatingTextView.setTextColor(Color.WHITE); - - mButtonDismis = new Button(getApplicationContext()); - - mButtonDismis.setText(MainApp.sResources.getString(R.string.dismiss)); - mButtonDismis.setTextSize(20.0F); - mButtonDismis.setTextAlignment(Button.TEXT_ALIGNMENT_CENTER); - mButtonDismis.setGravity(Gravity.CENTER); - mButtonDismis.setPadding(30, 20, 30, 20); - - mLinLayout.addView(mButtonDismis); - - mButtonDismis.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - AlertMessage.this.dismis(); - if (mOnDismiss != null) { - mOnDismiss.run(); - } - } - }); - } - - public void dismis() { - mSoundPool.stop(mPlayingId); - - if (mWindowManager == null) - mWindowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); - - if (mLinLayout != null) - mWindowManager.removeViewImmediate(mLinLayout); - displayed = false; - mWakeLock.release(); - log.debug("dismis()"); - } - - private Context getApplicationContext() { - return mApplicationContext; - } - - public void setText(String text) { - mAlertText = text; - } - - public void setOnDismiss(Runnable runnable) { - mOnDismiss = runnable; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/Services/AlertService.java b/app/src/main/java/info/nightscout/androidaps/Services/AlertService.java deleted file mode 100644 index f6729b0d31..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/Services/AlertService.java +++ /dev/null @@ -1,71 +0,0 @@ -package info.nightscout.androidaps.Services; - -import android.app.Service; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.IBinder; -import android.preference.PreferenceManager; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Date; - -import info.nightscout.androidaps.Config; - -public class AlertService extends Service { - private static Logger log = LoggerFactory.getLogger(AlertService.class); - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - if (Config.logFunctionCalls) - log.debug("onStartCommand"); - - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - long lastAlert = preferences.getLong("lastAlert", 0); - long currentTime = new Date().getTime(); - - //if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("masterSwitch", false)) { - // stopSelf(startId); - // log.debug("Alert posponed - master switch disabled"); - //} else - //if ((currentTime - lastAlert) < 15 * 60 * 1000) { - // stopSelf(startId); - // log.debug("Alert posponed"); - //} else - { - - AlertMessage alert = new AlertMessage(getApplicationContext()); - - if (intent != null) { - String alertText = intent.getStringExtra("alertText"); - if (alertText != null) { - alert.setText(alertText); - } - - alert.setOnDismiss(new Runnable() { - - @Override - public void run() { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - SharedPreferences.Editor editor = preferences.edit(); - editor.putLong("lastAlert", new Date().getTime()); - editor.commit(); - AlertService.this.stopSelf(); - } - }); - - alert.showMessage(); - } - } - if (Config.logFunctionCalls) - log.debug("onStartCommand end"); - return START_NOT_STICKY; - } - - @Override - public IBinder onBind(Intent intent) { - return null; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index fb06d98cd8..15af10496a 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -25,8 +25,8 @@ import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; +import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -35,7 +35,6 @@ import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventTreatmentChange; -import info.nightscout.androidaps.Config; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.Objectives.ObjectivesFragment; diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index bd6a58c8e5..ce520c7eb3 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -41,7 +41,7 @@ public class KeepAliveReceiver extends BroadcastReceiver { Thread t = new Thread(new Runnable() { @Override public void run() { - danaRFragment.doConnect("KeepAlive"); + danaRFragment.doConnect("KeepAlive"); // TODO: only if if last conn > 30 min } }); t.start();