diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 79a7284..5c26f84 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,6 +3,7 @@
package="net.foucry.pilldroid">
+
+
\ No newline at end of file
diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java
index 37e3637..2f481ed 100644
--- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java
+++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java
@@ -1,9 +1,15 @@
package net.foucry.pilldroid;
+import android.app.AlarmManager;
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.IntentFilter;
import android.os.Bundle;
+import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
@@ -62,11 +68,20 @@ public class MedicamentListActivity extends AppCompatActivity {
private View mRecyclerView;
private SimpleItemRecyclerViewAdapter mAdapter;
+ // For the notifications
+ PendingIntent pendingIntent;
+ AlarmManager alarmManager;
+ BroadcastReceiver mReceiver;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_medicament_list);
+ // Register for alarm
+
+// RegisterAlarmBroadcast();
+
dbHelper = new DBHelper(this);
dbMedoc = new DBMedoc(this);
@@ -158,7 +173,20 @@ public class MedicamentListActivity extends AppCompatActivity {
}
return super.onOptionsItemSelected(item);
}
-
+
+
+ public void onPause() {
+ super.onPause();
+
+// alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, pendingIntent);
+ scheduleNotification(getNotification("10 second delay"), 10000);
+ }
+
+/* protected void onDestroy() {
+ unregisterReceiver(mReceiver);
+ super.onDestroy();
+ }*/
+
public void scanNow(View view) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
//intent.putExtra("SCAN_MODE", "CODE_128");
@@ -233,6 +261,41 @@ public class MedicamentListActivity extends AppCompatActivity {
recyclerView.setAdapter(mAdapter);
}
+ private void scheduleNotification(Notification notification, int delay) {
+ Intent notificationIntent = new Intent(this, NotificationPublisher.class);
+ notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID,1);
+ notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification);
+ PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+
+ long futureInMillis = SystemClock.elapsedRealtime() + delay;
+ AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
+ alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);
+ }
+
+ private Notification getNotification(String content) {
+ Notification.Builder builder = new Notification.Builder(this);
+ builder.setContentTitle("Scheduled Notification");
+ builder.setContentText(content);
+ builder.setSmallIcon(R.mipmap.ic_launcher);
+ return builder.build();
+ }
+ // Received Alarm, display a toast
+/* private void RegisterAlarmBroadcast() {
+ mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Toast.makeText(context, "Vous devez passer à la pharmacie", Toast.LENGTH_LONG).show();
+ }
+ };
+ registerReceiver(mReceiver, new IntentFilter("net.foucry.pilldroid"));
+ pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("net.foucry.pilldroid"),0);
+ alarmManager = (AlarmManager)(this.getSystemService(Context.ALARM_SERVICE));
+ }
+
+ private void UnregisterAlarmBroadcast(){
+ alarmManager.cancel(pendingIntent);
+ getBaseContext().unregisterReceiver(mReceiver);
+ }*/
/**
* SimpleItemRecyclerViewAdapter
*/
diff --git a/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java b/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java
new file mode 100644
index 0000000..a908fb0
--- /dev/null
+++ b/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java
@@ -0,0 +1,28 @@
+package net.foucry.pilldroid;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Vibrator;
+
+/**
+ * Created by jfoucry on 6/23/16.
+ */
+public class NotificationPublisher extends BroadcastReceiver {
+
+ public static String NOTIFICATION_ID = "notification-id";
+ public static String NOTIFICATION = "notification";
+
+ public void onReceive(Context context, Intent intent) {
+ NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+
+ Notification notification = intent.getParcelableExtra(NOTIFICATION);
+ int id = intent.getIntExtra(NOTIFICATION_ID,0);
+ notificationManager.notify(id, notification);
+ Vibrator vibrator = (Vibrator) context.getSystemService(context.VIBRATOR_SERVICE);
+ vibrator.vibrate(400);
+
+ }
+}
diff --git a/app/src/main/res/drawable/gradient_bg_alert.xml b/app/src/main/res/drawable/gradient_bg_alert.xml
index 7d58d72..6bce62a 100644
--- a/app/src/main/res/drawable/gradient_bg_alert.xml
+++ b/app/src/main/res/drawable/gradient_bg_alert.xml
@@ -2,8 +2,7 @@
\ No newline at end of file
diff --git a/app/src/main/res/drawable/gradient_bg_ok.xml b/app/src/main/res/drawable/gradient_bg_ok.xml
index e2ea5eb..7155d22 100644
--- a/app/src/main/res/drawable/gradient_bg_ok.xml
+++ b/app/src/main/res/drawable/gradient_bg_ok.xml
@@ -2,8 +2,7 @@
+ android:startColor="#FF048F01"
+ android:endColor="#FF5CB65A"
+ android:angle="90" />
\ No newline at end of file
diff --git a/app/src/main/res/drawable/gradient_bg_warning.xml b/app/src/main/res/drawable/gradient_bg_warning.xml
index 59190ce..e07f789 100644
--- a/app/src/main/res/drawable/gradient_bg_warning.xml
+++ b/app/src/main/res/drawable/gradient_bg_warning.xml
@@ -2,8 +2,7 @@
+ android:startColor="#FFF8A253"
+ android:endColor="#FFF7C01E"
+ android:angle="90" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/medicament_list_content.xml b/app/src/main/res/layout/medicament_list_content.xml
index 0f038f7..f5be3b6 100644
--- a/app/src/main/res/layout/medicament_list_content.xml
+++ b/app/src/main/res/layout/medicament_list_content.xml
@@ -1,63 +1,67 @@
-
+
+
-
-
-
+ android:src="@drawable/stock_ok"
+ android:contentDescription="Icone de stock"
+ android:layout_centerVertical="true"
+ android:layout_alignParentStart="true" />
+
+
+
+
+
+
+
-
-
+
\ No newline at end of file