Merge branch 'feature/jobScheduler' into develop

This commit is contained in:
Jacques Foucry 2016-11-08 13:40:14 +01:00
commit 7eb5b2e954
16 changed files with 279 additions and 327 deletions

View file

@ -12,12 +12,7 @@
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="myModules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>

View file

@ -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 {

View file

@ -4,7 +4,6 @@
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
@ -54,7 +53,8 @@
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<service android:name=".TimeService"/>
<service android:name=".PillDroidJobService"
android:permission="android.permission.BIND_JOB_SERVICE"/>
</application>
</manifest>

View file

@ -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,11 +129,11 @@ 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));
@ -144,15 +144,21 @@ public class DBHelper extends SQLiteOpenHelper {
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();
@ -168,11 +174,11 @@ 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));
@ -183,15 +189,21 @@ public class DBHelper extends SQLiteOpenHelper {
medicament.setPrise(Double.parseDouble(cursor.getString(7)));
medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
}
if (null != cursor) cursor.close();
// Log
Log.d(TAG, "getDrug(" + cip13 + ")" + medicament.toString());
// Return medicament
return medicament;
}
public List<Medicament> getAllDrugs() {
/**
*
* @return a List of All medicaments presents in database
*/
List<Medicament> getAllDrugs() {
List<Medicament> medicaments = new LinkedList<Medicament>();
// 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;

View file

@ -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();

View file

@ -1,10 +1,13 @@
package net.foucry.pilldroid;
import android.view.FocusFinder;
import java.io.Serializable;
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.*;
@ -29,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(String cis, String cip13, String nom, String mode_administration, 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();
@ -54,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;
}
@ -94,7 +92,7 @@ public class Medicament implements Serializable {
return dateLastUpdate;
}
public Date getDateEndOfStock() {
Date getDateEndOfStock() {
return dateEndOfStock;
}
@ -102,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);
@ -162,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;

View file

@ -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}

View file

@ -25,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;
@ -42,8 +41,9 @@ import java.util.List;
import java.util.Locale;
import java.util.Random;
import static net.foucry.pilldroid.NotificationPublisher.NOTIFICATION_ID;
import static net.foucry.pilldroid.UtilDate.date2String;
import static net.foucry.pilldroid.Utils.doubleRandomInclusive;
import static net.foucry.pilldroid.Utils.intRandomExclusive;
/**
* An activity representing a list of Medicaments. This activity
@ -61,7 +61,9 @@ public class MedicamentListActivity extends AppCompatActivity {
*/
private boolean mTwoPane;
final static Boolean DEMO = true;
final static Boolean DBDEMO = true;
final static Random random = new Random();
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
@ -96,27 +98,6 @@ 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));
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
@ -135,15 +116,22 @@ public class MedicamentListActivity extends AppCompatActivity {
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 List<Medicament> medicaments;
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);
@ -159,68 +147,59 @@ 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();
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));
}
}
if (this.medicaments == null) {
this.medicaments = dbHelper.getAllDrugs();
if (medicaments == null) {
medicaments = dbHelper.getAllDrugs();
Collections.sort(this.medicaments, new Comparator<Medicament>() {
Collections.sort(medicaments, new Comparator<Medicament>() {
@Override
public int compare(Medicament lhs, Medicament rhs) {
return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock());
@ -267,6 +246,35 @@ public class MedicamentListActivity extends AppCompatActivity {
public void onPause() {
super.onPause();
newStockCalculation();
}
/** 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");
intent.putExtra("SCAN_FORMATS", "CODE_18,DATA_MATRIX");
startActivityForResult(intent, 0);
}
/**
* Calculation of newStock
*/
public void newStockCalculation() {
Medicament currentMedicament;
for (int position = 0 ; position < this. getCount() ; position++ ) {
currentMedicament = this.getItem(position);
currentMedicament.newStock(currentMedicament.getStock());
}
// 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();
Date now = calendar.getTime();
@ -278,24 +286,17 @@ public class MedicamentListActivity extends AppCompatActivity {
if (dateAlerte.getTime() < now.getTime())
{
dateSchedule = now.getTime() + 10000;
dateSchedule = now.getTime() + 50000; // If dateAlerte < now we schedule an alert for now + 5 seconds (3600000 pour 1 heure)
} else {
dateSchedule = dateAlerte.getTime();
dateSchedule = dateAlerte.getTime(); // If dateAlerte > now we use dateAlerte as scheduleDate
}
// int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime());
scheduleNotification(getNotification("It's today + 10s"), dateSchedule);
long delay = dateSchedule - now.getTime();
scheduleNotification(getNotification(getString(R.string.notification_text)),delay);
Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule));
}
public void scanNow(View view) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
//intent.putExtra("SCAN_MODE", "CODE_128");
intent.putExtra("SCAN_FORMATS", "CODE_18,DATA_MATRIX");
startActivityForResult(intent, 0);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
Context context = getApplicationContext();
String cip13;
@ -364,8 +365,10 @@ 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(NOTIFICATION_ID, 1);
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
@ -375,6 +378,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);
@ -387,7 +392,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) : "???");
}
@ -399,11 +404,11 @@ public class MedicamentListActivity extends AppCompatActivity {
private final List<Medicament> mValues;
public SimpleItemRecyclerViewAdapter(List<Medicament> items) {
SimpleItemRecyclerViewAdapter(List<Medicament> items) {
mValues = items;
}
public void addItem(Medicament scannedMedoc) {
void addItem(Medicament scannedMedoc) {
mValues.add(scannedMedoc);
notifyDataSetChanged();
dbHelper.addDrug(scannedMedoc);
@ -478,16 +483,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);

View file

@ -6,22 +6,28 @@ import android.content.BroadcastReceiver;
import android.content.Context;
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, "");
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 vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(400);
}

View file

@ -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(getApplicationContext());
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;
}
}

View file

@ -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());
}
}
}

View file

@ -7,22 +7,24 @@ 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);
// Log.d(TAG, "dateAtNoon " + aDate);
Calendar calendar = Calendar.getInstance();
calendar.setTime(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());

View file

@ -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;
}
}

View file

@ -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.
* <p>
* TODO: Replace all uses of this class before publishing your app.
*/
public class DummyContent {
/**
* An array of sample (dummy) items.
*/
public static final List<DummyItem> ITEMS = new ArrayList<DummyItem>();
/**
* A map of sample (dummy) items, by ID.
*/
public static final Map<String, DummyItem> ITEM_MAP = new HashMap<String, DummyItem>();
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;
}
}
}

View file

@ -129,4 +129,5 @@
<string name="msgFound">trouvé dans la base de données</string>
<string name="about">À propos</string>
<string name="help">Aide</string>
<string name="notification_text">Vous devez passer à la pharmarcie -POUET</string>
</resources>

View file

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
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