From 4d99698930c6ed51a3d3dc3c87b3fb19f22fc278 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Thu, 23 Jun 2016 06:01:38 +0200 Subject: [PATCH 1/5] =?UTF-8?q?Ajout=20du=20d=C3=A9but=20des=20notificatio?= =?UTF-8?q?ns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pilldroid/MedicamentListActivity.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 37e3637..166bb0f 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -1,8 +1,12 @@ package net.foucry.pilldroid; +import android.app.AlarmManager; +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.support.annotation.NonNull; import android.support.v7.app.AlertDialog; @@ -62,11 +66,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 +171,19 @@ public class MedicamentListActivity extends AppCompatActivity { } return super.onOptionsItemSelected(item); } - + + + public void onPause() { + super.onPause(); + + alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, pendingIntent); + } + + 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 +258,23 @@ public class MedicamentListActivity extends AppCompatActivity { recyclerView.setAdapter(mAdapter); } + // 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 */ From 06cd7a443d3c90804f130a8a1bb5bd04c460ecd0 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Thu, 23 Jun 2016 17:11:57 +0200 Subject: [PATCH 2/5] Ajout utilisation du vibreur dans la notification --- app/src/main/AndroidManifest.xml | 2 ++ 1 file changed, 2 insertions(+) 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 From 9f7e7045e1e002bdc9e0c5e63bf3ac6cb93acd50 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Thu, 23 Jun 2016 17:12:25 +0200 Subject: [PATCH 3/5] Nouvelle technique pour l'alarme avec notification --- .../pilldroid/MedicamentListActivity.java | 33 +++++++++++++++---- .../pilldroid/NotificationPublisher.java | 28 ++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 166bb0f..2f481ed 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -1,6 +1,7 @@ package net.foucry.pilldroid; import android.app.AlarmManager; +import android.app.Notification; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; @@ -8,6 +9,7 @@ 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; @@ -78,7 +80,7 @@ public class MedicamentListActivity extends AppCompatActivity { // Register for alarm - RegisterAlarmBroadcast(); +// RegisterAlarmBroadcast(); dbHelper = new DBHelper(this); dbMedoc = new DBMedoc(this); @@ -176,13 +178,14 @@ public class MedicamentListActivity extends AppCompatActivity { public void onPause() { super.onPause(); - alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, pendingIntent); +// alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, pendingIntent); + scheduleNotification(getNotification("10 second delay"), 10000); } - protected void onDestroy() { +/* protected void onDestroy() { unregisterReceiver(mReceiver); super.onDestroy(); - } + }*/ public void scanNow(View view) { Intent intent = new Intent("com.google.zxing.client.android.SCAN"); @@ -258,8 +261,26 @@ 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() { +/* private void RegisterAlarmBroadcast() { mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -274,7 +295,7 @@ public class MedicamentListActivity extends AppCompatActivity { 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); + + } +} From 837a87f80b3845f57eaa1c9e5235e88ee5b525a3 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Mon, 25 Jul 2016 22:44:32 +0200 Subject: [PATCH 4/5] =?UTF-8?q?Agrandissement=20de=20la=20taille=20de=20la?= =?UTF-8?q?=20cellule=20et=20r=C3=A9ordonnancement=20des=20=C3=A9l=C3=A9me?= =?UTF-8?q?nts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../res/layout/medicament_list_content.xml | 95 ++++++++++--------- 1 file changed, 50 insertions(+), 45 deletions(-) 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 From ca8be0daefe23a483e66b7b865d13e1517b7560e Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 26 Jul 2016 22:56:23 +0200 Subject: [PATCH 5/5] =?UTF-8?q?Changement=20des=20d=C3=A9grad=C3=A9s=20des?= =?UTF-8?q?=20cellules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/drawable/gradient_bg_alert.xml | 5 ++--- app/src/main/res/drawable/gradient_bg_ok.xml | 7 +++---- app/src/main/res/drawable/gradient_bg_warning.xml | 7 +++---- 3 files changed, 8 insertions(+), 11 deletions(-) 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