From dea00e1e6ca7eb53e02f2bec3cb3757d5498372b Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Sun, 18 Sep 2016 10:21:17 +0200 Subject: [PATCH 01/21] JobScheduler en place, un toast toutes les 3 secondes --- app/src/main/AndroidManifest.xml | 3 +- .../pilldroid/MedicamentListActivity.java | 50 +++++++++++++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3bd318d..0def754 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,7 +4,6 @@ - + \ 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 41d216c..1962b49 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -4,6 +4,10 @@ import android.app.AlarmManager; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; +import android.app.job.JobInfo; +import android.app.job.JobParameters; +import android.app.job.JobScheduler; +import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -11,6 +15,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; +import android.os.Message; import android.os.SystemClock; import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; @@ -41,6 +46,7 @@ import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Random; +import java.util.logging.Handler; import static net.foucry.pilldroid.UtilDate.date2String; import static net.foucry.pilldroid.Utils.doubleRandomInclusive; @@ -62,6 +68,9 @@ public class MedicamentListActivity extends AppCompatActivity { private boolean mTwoPane; final static Boolean DEMO = true; final static Random random = new Random(); + + private JobScheduler mJobScheduler; + /** * ATTENTION: This was auto-generated to implement the App Indexing API. * See https://g.co/AppIndexing/AndroidStudio for more information. @@ -73,8 +82,16 @@ public class MedicamentListActivity extends AppCompatActivity { super.onStart(); Log.d(TAG, "Remove old notification"); - NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - nm.cancelAll(); + cancelAllJobs(mRecyclerView); + //NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + //nm.cancelAll(); + + + try { + mJobScheduler.cancelAll(); + } catch (Exception e) { + Log.d(TAG, "no old job to remove"); + } // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. @@ -96,7 +113,7 @@ public class MedicamentListActivity extends AppCompatActivity { public void onStop() { super.onStop(); - Calendar calendar = Calendar.getInstance(); + /*Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); long dateSchedule; @@ -115,8 +132,28 @@ public class MedicamentListActivity extends AppCompatActivity { // int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime()); scheduleNotification(getNotification("Vous devez passer à la pharmacie."), dateSchedule); - Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(now.getTime() + dateSchedule)); +/* Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(now.getTime() + dateSchedule));*//* + ComponentName mServiceCoponent = new ComponentName(this, PillDroidJobService.class); + JobInfo.Builder builder = new JobInfo.Builder(kJobId++, mServiceCoponent); + builder.setMinimumLatency(5 * 1000); + builder.setOverrideDeadline(50 * 1000); + builder.setRequiresDeviceIdle(true); + builder.setRequiresCharging(false); + JobScheduler jobScheduler = (JobScheduler) getApplication().getSystemService(Context.JOB_SCHEDULER_SERVICE); + jobScheduler.schedule(builder.build());*/ + + + + mJobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); + + JobInfo.Builder builder = new JobInfo.Builder(1, + new ComponentName( getPackageName(), PillDroidJobService.class.getName())); + builder.setPeriodic(3000); + + if (mJobScheduler.schedule(builder.build()) <= 0) { + Log.d(TAG, "Something goes wrong at job schedule"); + } // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. Action viewAction = Action.newAction( @@ -133,6 +170,11 @@ public class MedicamentListActivity extends AppCompatActivity { client.disconnect(); } + public void cancelAllJobs(View v) { + JobScheduler tm = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); + tm.cancelAll(); + } + private static final String TAG = MedicamentListActivity.class.getName(); private static DBHelper dbHelper; From 57877b39f8cf020eac4ff6bde07b3d81736cc8dd Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 20 Sep 2016 15:10:58 +0200 Subject: [PATCH 02/21] =?UTF-8?q?Ajout=20d=C3=A9finition=20du=20JobService?= =?UTF-8?q?=20PillDroidJobService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/gradle.xml | 7 +------ build.gradle | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index cd2ead8..0e23f8e 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -12,12 +12,7 @@ - + diff --git a/build.gradle b/build.gradle index 77ce66e..a3330d4 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.3' + classpath 'com.android.tools.build:gradle:2.2.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From 805ec3a3b8424dffe7409e7d90e64c3b16edeba3 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 18 Oct 2016 16:27:47 +0200 Subject: [PATCH 03/21] =?UTF-8?q?Mise=20=C3=A0=20jour=20du=20graddle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a3330d4..53f4fad 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.0' + classpath 'com.android.tools.build:gradle:2.2.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From 42efe6f9adfaa190929c5d7dcda5dcaf5b3b2d5f Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 18 Oct 2016 16:28:33 +0200 Subject: [PATCH 04/21] =?UTF-8?q?Ajout=20m=C3=A9thode=20calcul=20d=20nouve?= =?UTF-8?q?au=20stock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pilldroid/MedicamentListActivity.java | 73 ++++++------------- 1 file changed, 22 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 1962b49..de902f0 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -113,47 +113,16 @@ public class MedicamentListActivity extends AppCompatActivity { public void onStop() { super.onStop(); - /*Calendar calendar = Calendar.getInstance(); - Date now = calendar.getTime(); - - long dateSchedule; - - Medicament firstMedicament = medicaments.get(0); - - Date dateAlerte = UtilDate.removeDaysToDate(firstMedicament.getAlertThreshold(), firstMedicament.getDateEndOfStock()); - - if (dateAlerte.getTime() < now.getTime()) - { - dateSchedule = 120000; - } else { - dateSchedule = dateAlerte.getTime() - now.getTime(); - } - - // int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime()); - scheduleNotification(getNotification("Vous devez passer à la pharmacie."), dateSchedule); - -/* Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(now.getTime() + dateSchedule));*//* - - ComponentName mServiceCoponent = new ComponentName(this, PillDroidJobService.class); - JobInfo.Builder builder = new JobInfo.Builder(kJobId++, mServiceCoponent); - builder.setMinimumLatency(5 * 1000); - builder.setOverrideDeadline(50 * 1000); - builder.setRequiresDeviceIdle(true); - builder.setRequiresCharging(false); - JobScheduler jobScheduler = (JobScheduler) getApplication().getSystemService(Context.JOB_SCHEDULER_SERVICE); - jobScheduler.schedule(builder.build());*/ - - - mJobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); JobInfo.Builder builder = new JobInfo.Builder(1, new ComponentName( getPackageName(), PillDroidJobService.class.getName())); - builder.setPeriodic(3000); + builder.setPeriodic(300000); // Dans 5 minutes, en millisecondes if (mJobScheduler.schedule(builder.build()) <= 0) { Log.d(TAG, "Something goes wrong at job schedule"); } + // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. Action viewAction = Action.newAction( @@ -186,6 +155,14 @@ public class MedicamentListActivity extends AppCompatActivity { private View mRecyclerView; private SimpleItemRecyclerViewAdapter mAdapter; + public int getCount() { + return medicaments.size(); + } + + public Medicament getItem(int position) { + return medicaments.get(position); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -201,24 +178,7 @@ public class MedicamentListActivity extends AppCompatActivity { toolbar.setTitle(getTitle()); } - startService(new Intent(this, TimeService.class)); - - /*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - *//* Snackbar.make(view, "Will be used to add a drug to the list", Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); *//* - Intent intent = new Intent("com.google.zxing.client.android.SCAN"); - intent.putExtra("SCAN_MODE", "CODE_128"); - //intent.putExtra("SCAN_FORMATS", "EAN_13,DATA_MATRIX"); - startActivityForResult(intent, 0); - } - });*/ - -// Log.d(TAG, "Remove old notification"); -// NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); -// nm.cancelAll(); +// startService(new Intent(this, TimeService.class)); if (DEMO) { if (dbHelper.getCount() == 0) { @@ -338,6 +298,17 @@ public class MedicamentListActivity extends AppCompatActivity { startActivityForResult(intent, 0); } + public void newStockCalculation() { + Medicament currentMedicament; + for (int position = 0 ; position < getCount() ; position++ ) { + currentMedicament = getItem(position); + currentMedicament.newStock(currentMedicament.getStock()); + } + + Toast.makeText( getApplicationContext(), "PillDroid - Calcul nouveau stocks", Toast.LENGTH_SHORT).show(); + // TODO: si un des médicaments est en rouge, on déclanche une notification visuelle pour dans 5 secondes + } + public void onActivityResult(int requestCode, int resultCode, Intent intent) { Context context = getApplicationContext(); String cip13; From 0e4e3ec9ff2e963a10e6bcc2160e476817b4dc17 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 18 Oct 2016 16:29:07 +0200 Subject: [PATCH 05/21] Ajout jobService --- .../foucry/pilldroid/PillDroidJobService.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java diff --git a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java new file mode 100644 index 0000000..f24c498 --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java @@ -0,0 +1,43 @@ +package net.foucry.pilldroid; + +import android.app.job.JobParameters; +import android.app.job.JobService; +import android.os.Message; +import android.os.Handler; +import android.util.Log; +import android.widget.Toast; + + +/** + * Created by jacques on 17/09/16. + */ +public class PillDroidJobService extends JobService { + private static final String TAG = "JobService"; + + private Handler mJobHandler = new Handler(new Handler.Callback() { + @Override + public boolean handleMessage(Message msg) { +// Toast.makeText( getApplicationContext(), "PillDroid - Calcul nouveau stocks", Toast.LENGTH_SHORT).show(); +// MedicamentListActivity.newStockCalculation(); + + jobFinished( (JobParameters) msg.obj,false); + return true; + } + }); + + @Override + public boolean onStartJob (JobParameters params) { + Log.i(TAG, "on Start Job: " + params.getJobId()); + mJobHandler.sendMessage(Message.obtain(mJobHandler, 1,params)); + return false; + } + + @Override + public boolean onStopJob(JobParameters params) { + mJobHandler.removeMessages(1); + return false; + } + + +} + From 8fbc2cb4277d03d47891a5ae8ec7ef03e587ff2d Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Wed, 19 Oct 2016 17:41:10 +0200 Subject: [PATCH 06/21] Ajout de final pour certaines variables --- app/src/main/java/net/foucry/pilldroid/Medicament.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/foucry/pilldroid/Medicament.java b/app/src/main/java/net/foucry/pilldroid/Medicament.java index bc55a10..6d65f09 100644 --- a/app/src/main/java/net/foucry/pilldroid/Medicament.java +++ b/app/src/main/java/net/foucry/pilldroid/Medicament.java @@ -1,5 +1,7 @@ package net.foucry.pilldroid; +import android.view.FocusFinder; + import java.io.Serializable; import java.lang.String; import java.text.SimpleDateFormat; @@ -34,7 +36,7 @@ public class Medicament implements Serializable { public Medicament() {} - public Medicament(String cis, String cip13, String nom, String mode_administration, String presentation, + public Medicament(final String cis, final String cip13, final String nom, final String mode_administration, final String presentation, double stock, double prise, int warn, int alert) { super(); From b056c44661d7a422a106ea1535d10b7596053e52 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Wed, 19 Oct 2016 17:41:51 +0200 Subject: [PATCH 07/21] =?UTF-8?q?correction=20appel=20=C3=A0=20newstockcal?= =?UTF-8?q?culation=20depuis=20PillDroidJobService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../foucry/pilldroid/MedicamentListActivity.java | 16 ++++++++-------- .../foucry/pilldroid/PillDroidJobService.java | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index de902f0..438e5e8 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -150,16 +150,16 @@ public class MedicamentListActivity extends AppCompatActivity { private static DBMedoc dbMedoc; // private SimpleCursorAdapter drugAdapter; - private List medicaments; + private static List medicaments; private View mRecyclerView; private SimpleItemRecyclerViewAdapter mAdapter; - public int getCount() { + public static int getCount() { return medicaments.size(); } - public Medicament getItem(int position) { + public static Medicament getItem(int position) { return medicaments.get(position); } @@ -219,10 +219,10 @@ public class MedicamentListActivity extends AppCompatActivity { } } - if (this.medicaments == null) { - this.medicaments = dbHelper.getAllDrugs(); + if (medicaments == null) { + medicaments = dbHelper.getAllDrugs(); - Collections.sort(this.medicaments, new Comparator() { + Collections.sort(medicaments, new Comparator() { @Override public int compare(Medicament lhs, Medicament rhs) { return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); @@ -298,14 +298,14 @@ public class MedicamentListActivity extends AppCompatActivity { startActivityForResult(intent, 0); } - public void newStockCalculation() { + public static void newStockCalculation(Context context) { Medicament currentMedicament; for (int position = 0 ; position < getCount() ; position++ ) { currentMedicament = getItem(position); currentMedicament.newStock(currentMedicament.getStock()); } - Toast.makeText( getApplicationContext(), "PillDroid - Calcul nouveau stocks", Toast.LENGTH_SHORT).show(); + Toast.makeText(context, "PillDroid - Calcul nouveau stocks", Toast.LENGTH_SHORT).show(); // TODO: si un des médicaments est en rouge, on déclanche une notification visuelle pour dans 5 secondes } diff --git a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java index f24c498..dd57fbe 100644 --- a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java +++ b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java @@ -18,7 +18,7 @@ public class PillDroidJobService extends JobService { @Override public boolean handleMessage(Message msg) { // Toast.makeText( getApplicationContext(), "PillDroid - Calcul nouveau stocks", Toast.LENGTH_SHORT).show(); -// MedicamentListActivity.newStockCalculation(); + MedicamentListActivity.newStockCalculation(getApplicationContext()); jobFinished( (JobParameters) msg.obj,false); return true; From e2ca1a2390ad69d102f2510344345c5fd52aad1d Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Wed, 19 Oct 2016 19:38:13 +0200 Subject: [PATCH 08/21] Changement du format de l'heure --- app/src/main/java/net/foucry/pilldroid/UtilDate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/net/foucry/pilldroid/UtilDate.java b/app/src/main/java/net/foucry/pilldroid/UtilDate.java index 6fd503c..baa68c9 100644 --- a/app/src/main/java/net/foucry/pilldroid/UtilDate.java +++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java @@ -109,7 +109,7 @@ public class UtilDate { } public static String convertDate(long dateInMilliseconds) { - DateFormat formatter = new SimpleDateFormat("dd/MM/yy hh:mm:ss"); + DateFormat formatter = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(dateInMilliseconds); return formatter.format(calendar.getTime()); From 4cd5ca478cfb65b26eca17739af4aff5f7f802ac Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Sat, 29 Oct 2016 21:18:13 +0200 Subject: [PATCH 09/21] =?UTF-8?q?Mise=20=C3=A0=20jour=20graddle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 53f4fad..c20bca1 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.1' + classpath 'com.android.tools.build:gradle:2.2.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From 6a731f9a6b3641237d559503220d79bf4bfd45c8 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 1 Nov 2016 23:17:06 +0100 Subject: [PATCH 10/21] Update graddle version --- app/build.gradle | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 156466e..07d1a53 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,12 +2,11 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 - buildToolsVersion "23.0.2" - + buildToolsVersion '24.0.2' defaultConfig { applicationId "net.foucry.pilldroid" - minSdkVersion 21 - targetSdkVersion 21 + minSdkVersion 23 + targetSdkVersion 23 versionCode 1 versionName "1.0" } @@ -17,6 +16,8 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + productFlavors { + } } repositories { From 24f78e0cdf2c23244bd8bec1f6f1ac16bf9eaf4a Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 1 Nov 2016 23:17:31 +0100 Subject: [PATCH 11/21] Add notification text --- app/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f38692b..fd9f3dc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -129,4 +129,5 @@ trouvé dans la base de données À propos Aide + Vous devez passer à la pharmarcie -POUET From cd1ca18e3200e8b6ae5fe1a556349e789385f684 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 1 Nov 2016 23:21:49 +0100 Subject: [PATCH 12/21] Use NotificationPublisher --- .../pilldroid/MedicamentListActivity.java | 95 +++++++++++++------ 1 file changed, 64 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 438e5e8..21357b9 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -69,8 +69,6 @@ public class MedicamentListActivity extends AppCompatActivity { final static Boolean DEMO = true; final static Random random = new Random(); - private JobScheduler mJobScheduler; - /** * ATTENTION: This was auto-generated to implement the App Indexing API. * See https://g.co/AppIndexing/AndroidStudio for more information. @@ -82,16 +80,16 @@ public class MedicamentListActivity extends AppCompatActivity { super.onStart(); Log.d(TAG, "Remove old notification"); - cancelAllJobs(mRecyclerView); - //NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - //nm.cancelAll(); +// cancelAllJobs(mRecyclerView); + NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + nm.cancelAll(); - try { + /*try { mJobScheduler.cancelAll(); } catch (Exception e) { Log.d(TAG, "no old job to remove"); - } + }*/ // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. @@ -113,15 +111,15 @@ public class MedicamentListActivity extends AppCompatActivity { public void onStop() { super.onStop(); - mJobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); - - JobInfo.Builder builder = new JobInfo.Builder(1, - new ComponentName( getPackageName(), PillDroidJobService.class.getName())); - builder.setPeriodic(300000); // Dans 5 minutes, en millisecondes - - if (mJobScheduler.schedule(builder.build()) <= 0) { - Log.d(TAG, "Something goes wrong at job schedule"); - } +// mJobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); +// +// JobInfo.Builder builder = new JobInfo.Builder(1, +// new ComponentName( getPackageName(), PillDroidJobService.class.getName())); +// builder.setPeriodic(30000); // Dans 30 secondes, en millisecondes +// +// if (mJobScheduler.schedule(builder.build()) <= 0) { +// Log.d(TAG, "Something goes wrong at job schedule"); +// } // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. @@ -139,27 +137,27 @@ public class MedicamentListActivity extends AppCompatActivity { client.disconnect(); } - public void cancelAllJobs(View v) { +/* public void cancelAllJobs(View v) { JobScheduler tm = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); tm.cancelAll(); - } + }*/ private static final String TAG = MedicamentListActivity.class.getName(); - private static DBHelper dbHelper; - private static DBMedoc dbMedoc; + private DBHelper dbHelper; + private DBMedoc dbMedoc; // private SimpleCursorAdapter drugAdapter; - private static List medicaments; + private List medicaments; private View mRecyclerView; private SimpleItemRecyclerViewAdapter mAdapter; - public static int getCount() { + public int getCount() { return medicaments.size(); } - public static Medicament getItem(int position) { + public Medicament getItem(int position) { return medicaments.get(position); } @@ -269,7 +267,8 @@ public class MedicamentListActivity extends AppCompatActivity { public void onPause() { super.onPause(); - Calendar calendar = Calendar.getInstance(); + newStockCalculation(); + /* Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); long dateSchedule; @@ -286,11 +285,16 @@ public class MedicamentListActivity extends AppCompatActivity { } // int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime()); - scheduleNotification(getNotification("It's today + 10s"), dateSchedule); + scheduleNotification(getNotification(getString(R.string.notification_text)), 10000); - Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule)); + Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule));*/ } + /** scanNow + * + * @param view + * call ZXing Library to scan a new QR/EAN code + */ public void scanNow(View view) { Intent intent = new Intent("com.google.zxing.client.android.SCAN"); //intent.putExtra("SCAN_MODE", "CODE_128"); @@ -298,15 +302,40 @@ public class MedicamentListActivity extends AppCompatActivity { startActivityForResult(intent, 0); } - public static void newStockCalculation(Context context) { + /** + * Calculation of newStock + */ + public void newStockCalculation() { Medicament currentMedicament; - for (int position = 0 ; position < getCount() ; position++ ) { - currentMedicament = getItem(position); + for (int position = 0 ; position < this. getCount() ; position++ ) { + currentMedicament = this.getItem(position); currentMedicament.newStock(currentMedicament.getStock()); } - Toast.makeText(context, "PillDroid - Calcul nouveau stocks", Toast.LENGTH_SHORT).show(); - // TODO: si un des médicaments est en rouge, on déclanche une notification visuelle pour dans 5 secondes + // Must record new stock in DB +// Toast.makeText(getApplicationContext(), "PillDroid - Calcul nouveau stocks", Toast.LENGTH_SHORT).show(); +// TODO: si un des médicaments est en rouge, on déclanche une notification visuelle pour dans 5 secondes + + Calendar calendar = Calendar.getInstance(); + Date now = calendar.getTime(); + + long dateSchedule; + + Medicament firstMedicament = medicaments.get(0); + + Date dateAlerte = UtilDate.removeDaysToDate(firstMedicament.getAlertThreshold(), firstMedicament.getDateEndOfStock()); + + if (dateAlerte.getTime() < now.getTime()) + { + dateSchedule = now.getTime() + 10000; // If dateAlerte < now we schedule an alert for now + 5 seconds + } else { + dateSchedule = dateAlerte.getTime(); // If dateAlerte > now we use dateAlerte as scheduleDate + } + + // int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime()); + scheduleNotification(getNotification(getString(R.string.notification_text)), dateSchedule); + + Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule)); } public void onActivityResult(int requestCode, int resultCode, Intent intent) { @@ -377,6 +406,8 @@ public class MedicamentListActivity extends AppCompatActivity { } private void scheduleNotification(Notification notification, long delay) { + Log.i(TAG, "scheduleNotification delay == " + delay); + Intent notificationIntent = new Intent(this, NotificationPublisher.class); notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID, 1); notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification); @@ -388,6 +419,8 @@ public class MedicamentListActivity extends AppCompatActivity { } private Notification getNotification(String content) { + Log.i(TAG, "getNotification"); + Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle(getAppName()); builder.setContentText(content); From 158c28a719800b86d8e3f7810be163bcc5545c51 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 1 Nov 2016 23:27:50 +0100 Subject: [PATCH 13/21] Cleanning code --- app/src/main/java/net/foucry/pilldroid/UtilDate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/net/foucry/pilldroid/UtilDate.java b/app/src/main/java/net/foucry/pilldroid/UtilDate.java index baa68c9..10de68a 100644 --- a/app/src/main/java/net/foucry/pilldroid/UtilDate.java +++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java @@ -22,7 +22,7 @@ public class UtilDate { */ public static Date dateAtNoon(Date aDate) { - Log.d(TAG, "dateAtNoon " + aDate); +// Log.d(TAG, "dateAtNoon " + aDate); Calendar calendar = Calendar.getInstance(); calendar.setTime(aDate); From 3faec26a70b90a3f50f2a79d4aa53bd7bcb80dcc Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 1 Nov 2016 23:35:00 +0100 Subject: [PATCH 14/21] Add Log facility --- .../main/java/net/foucry/pilldroid/NotificationPublisher.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java b/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java index a908fb0..86a4ffb 100644 --- a/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java +++ b/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java @@ -6,6 +6,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Vibrator; +import android.util.Log; /** * Created by jfoucry on 6/23/16. @@ -16,6 +17,8 @@ public class NotificationPublisher extends BroadcastReceiver { public static String NOTIFICATION = "notification"; public void onReceive(Context context, Intent intent) { + Log.i(TAG, "onReceive"); + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = intent.getParcelableExtra(NOTIFICATION); From 0b1da8a65e9f9b8eed7fd0d0343c3496911b848f Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Thu, 3 Nov 2016 13:57:19 +0100 Subject: [PATCH 15/21] =?UTF-8?q?Tentative=20avec=201=20heure=20de=20d?= =?UTF-8?q?=C3=A9calage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pilldroid/MedicamentListActivity.java | 28 ++++--------------- .../pilldroid/NotificationPublisher.java | 5 +++- .../foucry/pilldroid/PillDroidJobService.java | 2 +- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 21357b9..1ba64dc 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -48,6 +48,7 @@ import java.util.Locale; import java.util.Random; import java.util.logging.Handler; +import static net.foucry.pilldroid.NotificationPublisher.NOTIFICATION_ID; import static net.foucry.pilldroid.UtilDate.date2String; import static net.foucry.pilldroid.Utils.doubleRandomInclusive; @@ -268,26 +269,6 @@ public class MedicamentListActivity extends AppCompatActivity { super.onPause(); newStockCalculation(); - /* Calendar calendar = Calendar.getInstance(); - Date now = calendar.getTime(); - - long dateSchedule; - - Medicament firstMedicament = medicaments.get(0); - - Date dateAlerte = UtilDate.removeDaysToDate(firstMedicament.getAlertThreshold(), firstMedicament.getDateEndOfStock()); - - if (dateAlerte.getTime() < now.getTime()) - { - dateSchedule = now.getTime() + 10000; - } else { - dateSchedule = dateAlerte.getTime(); - } - - // int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime()); - scheduleNotification(getNotification(getString(R.string.notification_text)), 10000); - - Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule));*/ } /** scanNow @@ -306,6 +287,7 @@ public class MedicamentListActivity extends AppCompatActivity { * Calculation of newStock */ public void newStockCalculation() { + Medicament currentMedicament; for (int position = 0 ; position < this. getCount() ; position++ ) { currentMedicament = this.getItem(position); @@ -327,13 +309,13 @@ public class MedicamentListActivity extends AppCompatActivity { if (dateAlerte.getTime() < now.getTime()) { - dateSchedule = now.getTime() + 10000; // If dateAlerte < now we schedule an alert for now + 5 seconds + dateSchedule = now.getTime() + 3600000; // If dateAlerte < now we schedule an alert for now + 5 seconds (3600000 pour 1 heure) } else { dateSchedule = dateAlerte.getTime(); // If dateAlerte > now we use dateAlerte as scheduleDate } // int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime()); - scheduleNotification(getNotification(getString(R.string.notification_text)), dateSchedule); + scheduleNotification(getNotification(getString(R.string.notification_text)),3600000); Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule)); } @@ -409,7 +391,7 @@ public class MedicamentListActivity extends AppCompatActivity { Log.i(TAG, "scheduleNotification delay == " + delay); Intent notificationIntent = new Intent(this, NotificationPublisher.class); - notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID, 1); + notificationIntent.putExtra(NOTIFICATION_ID, 1); notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); diff --git a/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java b/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java index 86a4ffb..1fc42b9 100644 --- a/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java +++ b/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java @@ -8,16 +8,19 @@ import android.content.Intent; import android.os.Vibrator; import android.util.Log; +import static android.support.v7.widget.StaggeredGridLayoutManager.TAG; + /** * Created by jfoucry on 6/23/16. */ public class NotificationPublisher extends BroadcastReceiver { + private static String TAG = Thread.currentThread().getStackTrace()[1].getMethodName(); public static String NOTIFICATION_ID = "notification-id"; public static String NOTIFICATION = "notification"; public void onReceive(Context context, Intent intent) { - Log.i(TAG, "onReceive"); + Log.i(TAG, ""); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); diff --git a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java index dd57fbe..c913ac6 100644 --- a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java +++ b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java @@ -18,7 +18,7 @@ public class PillDroidJobService extends JobService { @Override public boolean handleMessage(Message msg) { // Toast.makeText( getApplicationContext(), "PillDroid - Calcul nouveau stocks", Toast.LENGTH_SHORT).show(); - MedicamentListActivity.newStockCalculation(getApplicationContext()); +// MedicamentListActivity.newStockCalculation(getApplicationContext()); jobFinished( (JobParameters) msg.obj,false); return true; From 74d861b1e46ce28a109f271873c5d255930201bc Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Sun, 6 Nov 2016 22:25:13 +0100 Subject: [PATCH 16/21] Try to launch notification in one hour --- .../java/net/foucry/pilldroid/MedicamentListActivity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 1ba64dc..2d694fa 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -50,6 +50,7 @@ import java.util.logging.Handler; import static net.foucry.pilldroid.NotificationPublisher.NOTIFICATION_ID; import static net.foucry.pilldroid.UtilDate.date2String; +import static net.foucry.pilldroid.UtilDate.tomorrowAtNoonInMillis; import static net.foucry.pilldroid.Utils.doubleRandomInclusive; /** @@ -314,8 +315,8 @@ public class MedicamentListActivity extends AppCompatActivity { dateSchedule = dateAlerte.getTime(); // If dateAlerte > now we use dateAlerte as scheduleDate } - // int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime()); - scheduleNotification(getNotification(getString(R.string.notification_text)),3600000); + long delay = (long) (dateSchedule - now.getTime()); + scheduleNotification(getNotification(getString(R.string.notification_text)),delay); Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule)); } From 88322fe1bc121234e604e6e6f11defb7e2b6a4da Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 8 Nov 2016 12:09:47 +0100 Subject: [PATCH 17/21] Change random generator Add variable for random values --- .../pilldroid/MedicamentListActivity.java | 67 ++++++++++--------- .../main/java/net/foucry/pilldroid/Utils.java | 15 +++-- 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 2d694fa..c2b1e65 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -4,10 +4,6 @@ import android.app.AlarmManager; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; -import android.app.job.JobInfo; -import android.app.job.JobParameters; -import android.app.job.JobScheduler; -import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -15,7 +11,6 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; -import android.os.Message; import android.os.SystemClock; import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; @@ -30,7 +25,6 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.SimpleCursorAdapter; import android.widget.TextView; import android.widget.Toast; @@ -46,12 +40,10 @@ import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Random; -import java.util.logging.Handler; import static net.foucry.pilldroid.NotificationPublisher.NOTIFICATION_ID; import static net.foucry.pilldroid.UtilDate.date2String; -import static net.foucry.pilldroid.UtilDate.tomorrowAtNoonInMillis; -import static net.foucry.pilldroid.Utils.doubleRandomInclusive; +import static net.foucry.pilldroid.Utils.intRandomExclusive; /** * An activity representing a list of Medicaments. This activity @@ -69,6 +61,7 @@ public class MedicamentListActivity extends AppCompatActivity { */ private boolean mTwoPane; final static Boolean DEMO = true; + final static Boolean DBDEMO = true; final static Random random = new Random(); /** @@ -181,41 +174,51 @@ public class MedicamentListActivity extends AppCompatActivity { // startService(new Intent(this, TimeService.class)); if (DEMO) { + // Added to drop database each the app is launch. + if (DBDEMO) { + dbHelper.dropDrug(); + } if (dbHelper.getCount() == 0) { // String cis, String cip13, String nom, String mode_administration, // String presentation,double stock, double prise, int warn, int alert + // Limit for randmon generator + final int min_stock=5; + final int max_stock=50; + final int min_prise=0; + final int max_prise=3; + dbHelper.addDrug(new Medicament("60000011", "3400930000011", "Médicament test 01", "orale", "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7)); + intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7)); dbHelper.addDrug(new Medicament("60000012", "3400930000012", "Médicament test 02", "orale", "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7)); + intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7)); dbHelper.addDrug(new Medicament("60000013", "3400930000013", "Médicament test 03", "orale", "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7)); + intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7)); dbHelper.addDrug(new Medicament("60000014", "3400930000014", "Médicament test 04", "orale", "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7)); + intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7)); dbHelper.addDrug(new Medicament("60000015", "3400930000015", "Médicament test 05", "orale", "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7)); + intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7)); dbHelper.addDrug(new Medicament("60000016", "3400930000016", "Médicament test 06", "orale", "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7)); + intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7)); dbHelper.addDrug(new Medicament("60000017", "3400930000017", "Médicament test 07", "orale", "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7)); + intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7)); dbHelper.addDrug(new Medicament("60000018", "3400930000018", "Médicament test 08", "orale", "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7)); + intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7)); dbHelper.addDrug(new Medicament("60000019", "3400930000019", "Médicament test 09", "orale", "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7)); + intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7)); dbHelper.addDrug(new Medicament("60000010", "3400930000010", "Médicament test 10", "orale", "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7)); + intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7)); } } @@ -310,12 +313,12 @@ public class MedicamentListActivity extends AppCompatActivity { if (dateAlerte.getTime() < now.getTime()) { - dateSchedule = now.getTime() + 3600000; // If dateAlerte < now we schedule an alert for now + 5 seconds (3600000 pour 1 heure) + dateSchedule = now.getTime() + 50000; // If dateAlerte < now we schedule an alert for now + 5 seconds (3600000 pour 1 heure) } else { dateSchedule = dateAlerte.getTime(); // If dateAlerte > now we use dateAlerte as scheduleDate } - long delay = (long) (dateSchedule - now.getTime()); + long delay = dateSchedule - now.getTime(); scheduleNotification(getNotification(getString(R.string.notification_text)),delay); Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule)); @@ -416,7 +419,7 @@ public class MedicamentListActivity extends AppCompatActivity { ApplicationInfo applicationInfo = null; try { applicationInfo = packageManager.getApplicationInfo(this.getPackageName(), 0); - } catch (final PackageManager.NameNotFoundException e) {} + } catch (final PackageManager.NameNotFoundException ignored) {} return (String)((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???"); } @@ -428,11 +431,11 @@ public class MedicamentListActivity extends AppCompatActivity { private final List mValues; - public SimpleItemRecyclerViewAdapter(List items) { + SimpleItemRecyclerViewAdapter(List items) { mValues = items; } - public void addItem(Medicament scannedMedoc) { + void addItem(Medicament scannedMedoc) { mValues.add(scannedMedoc); notifyDataSetChanged(); dbHelper.addDrug(scannedMedoc); @@ -507,16 +510,16 @@ public class MedicamentListActivity extends AppCompatActivity { return mValues.size(); } - public class ViewHolder extends RecyclerView.ViewHolder { - public final View mView; - public final TextView mIDView; - public final TextView mContentView; - public final TextView mEndOfStock; - public final ImageView mIconView; + class ViewHolder extends RecyclerView.ViewHolder { + final View mView; + final TextView mIDView; + final TextView mContentView; + final TextView mEndOfStock; + final ImageView mIconView; - public Medicament mItem; + Medicament mItem; - public ViewHolder(View view) { + ViewHolder(View view) { super(view); mView = view; mIDView = (TextView) view.findViewById(R.id.cip13); diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java index 6b79c60..11a5d19 100644 --- a/app/src/main/java/net/foucry/pilldroid/Utils.java +++ b/app/src/main/java/net/foucry/pilldroid/Utils.java @@ -22,12 +22,17 @@ public class Utils { os.write(bytes, 0, count); } } - catch(Exception ex){} + catch(Exception ignored){} } - public static final double doubleRandomInclusive(int min, int max) { - double value = Math.floor(min + (max - min) * MedicamentListActivity.random.nextDouble() *4)/4; - - return value; + /** + * Return a random number between twovalues - use to gənerat a false demo DB + * @param min minimal value accepted + * @param max maximum value accepted + * @return + */ + static final int intRandomExclusive(int min, int max) { + Random r = new Random(); + return r.nextInt(max - min) +max; } } \ No newline at end of file From f88a7157b8b3a71293cef9441a606dceeb60fb03 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 8 Nov 2016 12:10:27 +0100 Subject: [PATCH 18/21] Cleanning code, remove almost warning --- .../java/net/foucry/pilldroid/DBHelper.java | 98 ++++++++++++------- .../java/net/foucry/pilldroid/DBMedoc.java | 19 ++-- .../java/net/foucry/pilldroid/Medicament.java | 56 +++++------ .../pilldroid/NotificationPublisher.java | 2 +- .../java/net/foucry/pilldroid/UtilDate.java | 42 ++++---- 5 files changed, 121 insertions(+), 96 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DBHelper.java b/app/src/main/java/net/foucry/pilldroid/DBHelper.java index 12f13ca..ac2b070 100644 --- a/app/src/main/java/net/foucry/pilldroid/DBHelper.java +++ b/app/src/main/java/net/foucry/pilldroid/DBHelper.java @@ -46,7 +46,7 @@ public class DBHelper extends SQLiteOpenHelper { return sInstance; } - public DBHelper(Context context) { + DBHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @@ -76,7 +76,7 @@ public class DBHelper extends SQLiteOpenHelper { this.onCreate(db); } - public void dropDrug() { + void dropDrug() { SQLiteDatabase db = this.getWritableDatabase(); Log.d(TAG, "Drop drug table"); db.execSQL("DROP TABLE IF EXISTS drug"); @@ -84,7 +84,7 @@ public class DBHelper extends SQLiteOpenHelper { this.onCreate(db); } - public void addDrug(Medicament medicament) { + void addDrug(Medicament medicament) { // Logging Log.d(TAG, medicament.toString()); @@ -129,30 +129,36 @@ public class DBHelper extends SQLiteOpenHelper { null); // limits // if case we got result, go to the first one - if (cursor != null) + Medicament medicament = new Medicament(); + if (cursor != null) { cursor.moveToFirst(); - // Build medicament object - Medicament medicament = new Medicament(); - medicament.setId(Integer.parseInt(cursor.getString(0))); - medicament.setCis(cursor.getString(1)); - medicament.setCip13(cursor.getString(2)); - medicament.setNom(cursor.getString(3)); - medicament.setMode_administration(cursor.getString(4)); - medicament.setPresentation(cursor.getString(5)); - medicament.setStock(Double.parseDouble(cursor.getString(6))); - medicament.setPrise(Double.parseDouble(cursor.getString(7))); - medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8))); - medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9))); - + // Build medicament object + medicament.setId(Integer.parseInt(cursor.getString(0))); + medicament.setCis(cursor.getString(1)); + medicament.setCip13(cursor.getString(2)); + medicament.setNom(cursor.getString(3)); + medicament.setMode_administration(cursor.getString(4)); + medicament.setPresentation(cursor.getString(5)); + medicament.setStock(Double.parseDouble(cursor.getString(6))); + medicament.setPrise(Double.parseDouble(cursor.getString(7))); + medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8))); + medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9))); + } // Log Log.d(TAG, "getDrug("+id+")" + medicament.toString()); + if (null != cursor) cursor.close(); // Return medicament return medicament; } + /** + * + * @param cip13 drug id in French nomemclature + * @return the medicament object found in DB or null + */ public Medicament getDrugByCIP13(String cip13) { // Get reference to readable DB SQLiteDatabase db = this.getReadableDatabase(); @@ -161,37 +167,43 @@ public class DBHelper extends SQLiteOpenHelper { Cursor cursor = db.query(TABLE_DRUG, // Which table COLUMS, // column names " cip13 = ?", // selections - new String[] { String.valueOf(cip13) }, // selections args + new String[]{String.valueOf(cip13)}, // selections args null, // group by null, // having null, // order by null); // limits // if case we got result, go to the first one - if (cursor != null) + Medicament medicament = new Medicament(); + if (cursor != null) { cursor.moveToFirst(); - // Build medicament object - Medicament medicament = new Medicament(); - medicament.setId(Integer.parseInt(cursor.getString(0))); - medicament.setCis(cursor.getString(1)); - medicament.setCip13(cursor.getString(2)); - medicament.setNom(cursor.getString(3)); - medicament.setMode_administration(cursor.getString(4)); - medicament.setPresentation(cursor.getString(5)); - medicament.setStock(Double.parseDouble(cursor.getString(6))); - medicament.setPrise(Double.parseDouble(cursor.getString(7))); - medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8))); - medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9))); + // Build medicament object + medicament.setId(Integer.parseInt(cursor.getString(0))); + medicament.setCis(cursor.getString(1)); + medicament.setCip13(cursor.getString(2)); + medicament.setNom(cursor.getString(3)); + medicament.setMode_administration(cursor.getString(4)); + medicament.setPresentation(cursor.getString(5)); + medicament.setStock(Double.parseDouble(cursor.getString(6))); + medicament.setPrise(Double.parseDouble(cursor.getString(7))); + medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8))); + medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9))); + } - // Log - Log.d(TAG, "getDrug("+cip13+")" + medicament.toString()); + if (null != cursor) cursor.close(); - // Return medicament + Log.d(TAG, "getDrug(" + cip13 + ")" + medicament.toString()); return medicament; } - public List getAllDrugs() { + + /** + * + * @return a List of All medicaments presents in database + */ + + List getAllDrugs() { List medicaments = new LinkedList(); // Build the query @@ -202,7 +214,7 @@ public class DBHelper extends SQLiteOpenHelper { Cursor cursor = db.rawQuery(query, null); // For Each row, build a medicament and add it to the list - Medicament medicament = null; + Medicament medicament; if (cursor.moveToFirst()) { do { medicament = new Medicament(); @@ -229,10 +241,14 @@ public class DBHelper extends SQLiteOpenHelper { cursor.close(); Log.d(TAG, "getAllDrugs " + medicaments.toString()); - // return return medicaments; } + /** + * + * @param medicament object to be updated in DB + * @return code of update operation (should be 0) + */ public int updateDrug(Medicament medicament) { // Get reference to writable DB SQLiteDatabase db = this.getWritableDatabase(); @@ -258,6 +274,10 @@ public class DBHelper extends SQLiteOpenHelper { return i; } + /** + * Delete a medicament object in datebase + * @param medicament object to be delete in the DB + */ public void deleteDrug(Medicament medicament) { // Get writable database SQLiteDatabase db = this.getWritableDatabase(); @@ -274,6 +294,10 @@ public class DBHelper extends SQLiteOpenHelper { Log.d(TAG, "delete drug "+medicament.toString()); } + /** + * Get count of all medicament present in database + * @return number of medicament in DB + */ public int getCount() { String query = "SELECT count (*) FROM " + TABLE_DRUG; diff --git a/app/src/main/java/net/foucry/pilldroid/DBMedoc.java b/app/src/main/java/net/foucry/pilldroid/DBMedoc.java index b5fd309..a62123f 100644 --- a/app/src/main/java/net/foucry/pilldroid/DBMedoc.java +++ b/app/src/main/java/net/foucry/pilldroid/DBMedoc.java @@ -16,7 +16,7 @@ import java.io.OutputStream; /** * Created by jfoucry on 5/25/16. */ -public class DBMedoc extends SQLiteOpenHelper{ +class DBMedoc extends SQLiteOpenHelper{ private static final int DATABASE_VERSION = 1; @@ -37,7 +37,7 @@ public class DBMedoc extends SQLiteOpenHelper{ private static final String TAG = DBMedoc.class.getName(); - public DBMedoc(Context context) { + DBMedoc(Context context) { super(context, dbName, null, DATABASE_VERSION); this.myContext = context; } @@ -86,7 +86,7 @@ public class DBMedoc extends SQLiteOpenHelper{ } } - public void openDatabase() throws SQLiteException { + void openDatabase() throws SQLiteException { Log.e(TAG, "openDatabase called"); String myPath = DATABASE_PATH + dbName; @@ -100,9 +100,12 @@ public class DBMedoc extends SQLiteOpenHelper{ } } - private DBMedoc dbMedoc; - - public Medicament getMedocByCIP13(String cip13) { + /** + * Lookup in the DB for a record corresponding to cpi1 + * @param cip13 string representing the object we're looking for + * @return return a medicament objet + */ + Medicament getMedocByCIP13(String cip13) { Log.e(TAG, "getNedocByCIP13 - " + cip13); SQLiteDatabase db = this.getReadableDatabase(); @@ -110,8 +113,8 @@ public class DBMedoc extends SQLiteOpenHelper{ // Build query Cursor cursor = db.query(TABLE_NAME, // Which table COLUMNS_NAMES, // column names - " cip13 =?", // selections - new String[]{cip13}, // selections args + " cip13 =?", // selections + new String[]{cip13}, // selections args null, // group by null, // having null, // order by diff --git a/app/src/main/java/net/foucry/pilldroid/Medicament.java b/app/src/main/java/net/foucry/pilldroid/Medicament.java index 6d65f09..0f3cc63 100644 --- a/app/src/main/java/net/foucry/pilldroid/Medicament.java +++ b/app/src/main/java/net/foucry/pilldroid/Medicament.java @@ -7,6 +7,7 @@ import java.lang.String; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; +import java.util.Locale; import static net.foucry.pilldroid.UtilDate.*; @@ -31,12 +32,9 @@ public class Medicament implements Serializable { /* calculate part */ private Date dateEndOfStock; - private static final String[] COLUMN_LIST = {"id","cis", "cip13", "nom", "mode_administration", "presentation", "stock", "prise", - "seuil_warn", "seuil_alert", "dateLastUpdate"}; + Medicament() {} - public Medicament() {} - - public Medicament(final String cis, final String cip13, final String nom, final String mode_administration, final String presentation, + Medicament(final String cis, final String cip13, final String nom, final String mode_administration, final String presentation, double stock, double prise, int warn, int alert) { super(); @@ -56,39 +54,37 @@ public class Medicament implements Serializable { return id; } - public String getNom() { + String getNom() { return nom; } - public String getCip13() { + String getCip13() { return cip13; } - public String getCis() { + String getCis() { return cis; } - public String getMode_administration() { + String getMode_administration() { return mode_administration; } - public String getPresentation() { + String getPresentation() { return presentation; } - public double getStock() { - return stock; - } + double getStock() { return stock; } - public double getPrise() { + double getPrise() { return prise; } - public int getAlertThreshold() { + int getAlertThreshold() { return alertThreshold; } - public int getWarnThreshold() { + int getWarnThreshold() { return warnThreshold; } @@ -96,7 +92,7 @@ public class Medicament implements Serializable { return dateLastUpdate; } - public Date getDateEndOfStock() { + Date getDateEndOfStock() { return dateEndOfStock; } @@ -104,51 +100,51 @@ public class Medicament implements Serializable { this.id = id; } - public void setNom(String nom) { + void setNom(String nom) { this.nom = nom; } - public void setCip13(String cip13) { + void setCip13(String cip13) { this.cip13 = cip13; } - public void setCis(String cis) { + void setCis(String cis) { this.cis = cis; } - public void setMode_administration(String mode_administration) { + void setMode_administration(String mode_administration) { this.mode_administration = mode_administration; } - public void setPresentation(String presentation) { + void setPresentation(String presentation) { this.presentation = presentation; } - public void setStock(double stock) { + void setStock(double stock) { this.stock = stock; } - public void setPrise(double prise) { + void setPrise(double prise) { this.prise = prise; } - public void setWarnThreshold(int warn) { + void setWarnThreshold(int warn) { if (warn == 0) warn = 14; this.warnThreshold = warn; } - public void setAlertThreshold(int alert) { + void setAlertThreshold(int alert) { if (alert == 0) alert = 7; this.alertThreshold = alert; } - public void setDateLastUpdate() { - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + void setDateLastUpdate() { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.FRANCE); this.dateLastUpdate = date2String(dateAtNoon(new Date()), dateFormat); } - public void setDateEndOfStock() { + void setDateEndOfStock() { int numberDayOfPrise; if (this.prise > 0) { numberDayOfPrise = (int) Math.floor(this.stock / this.prise); @@ -164,7 +160,7 @@ public class Medicament implements Serializable { this.dateEndOfStock = calendar.getTime(); } - public double newStock(double currentStock) { + double newStock(double currentStock) { Date lastUpdate = string2Date(this.dateLastUpdate); int numberOfDays = nbOfDaysBetweenDateAndToday(lastUpdate); double takeDuringPeriod = this.prise * numberOfDays; diff --git a/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java b/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java index 1fc42b9..770c6e4 100644 --- a/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java +++ b/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java @@ -27,7 +27,7 @@ public class NotificationPublisher extends BroadcastReceiver { 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 vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(400); } diff --git a/app/src/main/java/net/foucry/pilldroid/UtilDate.java b/app/src/main/java/net/foucry/pilldroid/UtilDate.java index 10de68a..e513ae8 100644 --- a/app/src/main/java/net/foucry/pilldroid/UtilDate.java +++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java @@ -7,20 +7,22 @@ import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; +import java.util.Locale; + /** * Created by jacques on 05/05/16. */ -public class UtilDate { +class UtilDate { private static final String TAG = UtilDate.class.getName(); /** * - * @param aDate - * @return date + * @param aDate anydate + * @return date the same date as input but at noon (12:00:00) * * set date time at Noon */ - public static Date dateAtNoon(Date aDate) { + static Date dateAtNoon(Date aDate) { // Log.d(TAG, "dateAtNoon " + aDate); @@ -34,13 +36,13 @@ public class UtilDate { } /** * - * @param days - * @param date + * @param days number of days to remove to the ate + * @param date date before day removing * @return date * * Substract days to date and return a new date */ - public static Date removeDaysToDate(int days, Date date) { + static Date removeDaysToDate(int days, Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DAY_OF_YEAR, -days); @@ -50,12 +52,12 @@ public class UtilDate { /** * - * @param date - * @return String + * @param date Date to be converted + * @return String of the converted date * * Convert a date to a String using a SimpleDateFormat */ - public static String date2String(Date date, DateFormat dateFormat) { + static String date2String(Date date, DateFormat dateFormat) { Log.d(TAG, "date == " + date); @@ -67,25 +69,25 @@ public class UtilDate { /** * - * @param dateString - * @return date + * @param dateString string representing a Date to be conveted + * @return date Date after convertion * * Convert String date into Date */ - public static Date string2Date(String dateString) { - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + static Date string2Date(String dateString) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.FRANCE); ParsePosition pos = new ParsePosition(0); return dateFormat.parse(dateString,pos); } /** * - * @param date - * @return int + * @param date start date + * @return int numbers of days between date and today * * Number of days between date (older than today) and today */ - public static int nbOfDaysBetweenDateAndToday(Date date) { + static int nbOfDaysBetweenDateAndToday(Date date) { Date oldDate = dateAtNoon(date); // Be sure that the old date is at Noon Date todayDate = dateAtNoon(new Date()); // Be sure that we use today at Noon @@ -97,7 +99,7 @@ public class UtilDate { * return int */ - public static long tomorrowAtNoonInMillis() { + static long tomorrowAtNoonInMillis() { Date now = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(now); @@ -108,8 +110,8 @@ public class UtilDate { return (tomorrowAtNoon.getTime() - now.getTime()); } - public static String convertDate(long dateInMilliseconds) { - DateFormat formatter = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); + static String convertDate(long dateInMilliseconds) { + DateFormat formatter = new SimpleDateFormat("dd/MM/yy HH:mm:ss", Locale.FRANCE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(dateInMilliseconds); return formatter.format(calendar.getTime()); From d2b17bf6372d247c317ebe248369ff0bc53279c3 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 8 Nov 2016 12:17:49 +0100 Subject: [PATCH 19/21] Remove unecessary commended code --- app/src/main/AndroidManifest.xml | 1 - .../pilldroid/MedicamentListActivity.java | 29 +--------- .../net/foucry/pilldroid/TimeService.java | 56 ------------------- 3 files changed, 1 insertion(+), 85 deletions(-) delete mode 100644 app/src/main/java/net/foucry/pilldroid/TimeService.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0def754..929ec10 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,7 +53,6 @@ - diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index c2b1e65..0037437 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -75,17 +75,9 @@ public class MedicamentListActivity extends AppCompatActivity { super.onStart(); Log.d(TAG, "Remove old notification"); -// cancelAllJobs(mRecyclerView); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.cancelAll(); - - /*try { - mJobScheduler.cancelAll(); - } catch (Exception e) { - Log.d(TAG, "no old job to remove"); - }*/ - // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. client.connect(); @@ -106,16 +98,6 @@ public class MedicamentListActivity extends AppCompatActivity { public void onStop() { super.onStop(); -// mJobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); -// -// JobInfo.Builder builder = new JobInfo.Builder(1, -// new ComponentName( getPackageName(), PillDroidJobService.class.getName())); -// builder.setPeriodic(30000); // Dans 30 secondes, en millisecondes -// -// if (mJobScheduler.schedule(builder.build()) <= 0) { -// Log.d(TAG, "Something goes wrong at job schedule"); -// } - // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. Action viewAction = Action.newAction( @@ -132,17 +114,11 @@ public class MedicamentListActivity extends AppCompatActivity { client.disconnect(); } -/* public void cancelAllJobs(View v) { - JobScheduler tm = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); - tm.cancelAll(); - }*/ - private static final String TAG = MedicamentListActivity.class.getName(); private DBHelper dbHelper; private DBMedoc dbMedoc; - // private SimpleCursorAdapter drugAdapter; private List medicaments; private View mRecyclerView; @@ -171,8 +147,6 @@ public class MedicamentListActivity extends AppCompatActivity { toolbar.setTitle(getTitle()); } -// startService(new Intent(this, TimeService.class)); - if (DEMO) { // Added to drop database each the app is launch. if (DBDEMO) { @@ -298,8 +272,7 @@ public class MedicamentListActivity extends AppCompatActivity { currentMedicament.newStock(currentMedicament.getStock()); } - // Must record new stock in DB -// Toast.makeText(getApplicationContext(), "PillDroid - Calcul nouveau stocks", Toast.LENGTH_SHORT).show(); +// TODO: Must record new stock in DB // TODO: si un des médicaments est en rouge, on déclanche une notification visuelle pour dans 5 secondes Calendar calendar = Calendar.getInstance(); diff --git a/app/src/main/java/net/foucry/pilldroid/TimeService.java b/app/src/main/java/net/foucry/pilldroid/TimeService.java deleted file mode 100644 index 2aed6e6..0000000 --- a/app/src/main/java/net/foucry/pilldroid/TimeService.java +++ /dev/null @@ -1,56 +0,0 @@ -package net.foucry.pilldroid; - -import android.app.Service; -import android.content.Intent; -import android.os.Handler; -import android.os.IBinder; -import android.widget.Toast; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Timer; -import java.util.TimerTask; - -/** - * Created by jacques on 22/08/16. - */ -public class TimeService extends Service { - //public static final long NOTIFY_INTERVAL = 10 *1000; - - private Handler mHandler = new Handler(); - private Timer mTimer = null; - - @Override - public IBinder onBind(Intent intent) { - return null; - } - - @Override - public void onCreate() { - if(mTimer != null) { - mTimer.cancel(); - } else { - mTimer = new Timer(); - } - - mTimer.scheduleAtFixedRate(new TimeDisplayTimerTask(),0, UtilDate.tomorrowAtNoonInMillis()); - } - - class TimeDisplayTimerTask extends TimerTask { - @Override - public void run() { - mHandler.post(new Runnable() { - - @Override - public void run() { - Toast.makeText(getApplicationContext(),getDateTime(), Toast.LENGTH_SHORT).show(); - } - }); - } - - private String getDateTime() { - SimpleDateFormat sdf = new SimpleDateFormat("[yyyy/MM/dd - HH:mm:ss]"); - return sdf.format(new Date()); - } - } -} From 77f0ea6d0aa73ce9020ed00d932b1ca73d4f9a02 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 8 Nov 2016 12:23:32 +0100 Subject: [PATCH 20/21] Remove references to unnecessary DummyContent Class (was used for template) --- .../java/net/foucry/pilldroid/MedicamentDetailFragment.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java index cceaf80..f84ce2d 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java @@ -4,14 +4,11 @@ import android.app.Activity; import android.support.design.widget.CollapsingToolbarLayout; import android.os.Bundle; import android.support.v4.app.Fragment; -import android.support.v7.app.ActionBarActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -import net.foucry.pilldroid.dummy.DummyContent; - /** * A fragment representing a single Medicament detail screen. * This fragment is either contained in a {@link MedicamentListActivity} From b266cfedd108d18c54ffe35a0d977cba79ab1ab8 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 8 Nov 2016 12:24:02 +0100 Subject: [PATCH 21/21] Remove DummyContent class which came with template --- .../foucry/pilldroid/dummy/DummyContent.java | 72 ------------------- 1 file changed, 72 deletions(-) delete mode 100644 app/src/main/java/net/foucry/pilldroid/dummy/DummyContent.java diff --git a/app/src/main/java/net/foucry/pilldroid/dummy/DummyContent.java b/app/src/main/java/net/foucry/pilldroid/dummy/DummyContent.java deleted file mode 100644 index 8a110fc..0000000 --- a/app/src/main/java/net/foucry/pilldroid/dummy/DummyContent.java +++ /dev/null @@ -1,72 +0,0 @@ -package net.foucry.pilldroid.dummy; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Helper class for providing sample content for user interfaces created by - * Android template wizards. - *

- * TODO: Replace all uses of this class before publishing your app. - */ -public class DummyContent { - - /** - * An array of sample (dummy) items. - */ - public static final List ITEMS = new ArrayList(); - - /** - * A map of sample (dummy) items, by ID. - */ - public static final Map ITEM_MAP = new HashMap(); - - private static final int COUNT = 25; - - static { - // Add some sample items. - for (int i = 1; i <= COUNT; i++) { - addItem(createDummyItem(i)); - } - } - - private static void addItem(DummyItem item) { - ITEMS.add(item); - ITEM_MAP.put(item.id, item); - } - - private static DummyItem createDummyItem(int position) { - return new DummyItem(String.valueOf(position), "Item " + position, makeDetails(position)); - } - - private static String makeDetails(int position) { - StringBuilder builder = new StringBuilder(); - builder.append("Details about Item: ").append(position); - for (int i = 0; i < position; i++) { - builder.append("\nMore details information here."); - } - return builder.toString(); - } - - /** - * A dummy item representing a piece of content. - */ - public static class DummyItem { - public final String id; - public final String content; - public final String details; - - public DummyItem(String id, String content, String details) { - this.id = id; - this.content = content; - this.details = details; - } - - @Override - public String toString() { - return content; - } - } -}