diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..081feb7
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,25 @@
+The BSD 3-Clause License The following is a BSD 3-Clause ("BSD New" or "BSD Simplified") license template. To generate your own license, change the values of OWNER, ORGANIZATION and YEAR from their original values as given here, and substitute your own.
+
+Note: You may omit clause 3 and still be OSD-conformant. Despite its colloquial name "BSD New", this is not the newest version of the BSD license; it was followed by the even newer BSD-2-Clause version, sometimes known as the "Simplified BSD License". On January 9th, 2008 the OSI Board approved BSD-2-Clause, which is used by FreeBSD and others. It omits the final "no-endorsement" clause and is thus roughly equivalent to the MIT License.
+
+Historical Background: The original license used on BSD Unix had four clauses. The advertising clause (the third of four clauses) required you to acknowledge use of U.C. Berkeley code in your advertising of any product using that code. It was officially rescinded by the Director of the Office of Technology Licensing of the University of California on July 22nd, 1999. He states that clause 3 is "hereby deleted in its entirety." The four clause license has not been approved by OSI. The license below does not contain the advertising clause.
+
+This prelude is not part of the license.
+
+OWNER = Regents of the University of California
+
+ORGANIZATION = University of California, Berkeley
+
+YEAR = 1998
+
+In the original BSD license, both occurrences of the phrase "COPYRIGHT HOLDERS AND CONTRIBUTORS" in the disclaimer read "REGENTS AND CONTRIBUTORS".
+
+Copyright (c) $2022 Jacques Foucry, All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
index 744d411..c56ccb6 100644
--- a/README.md
+++ b/README.md
@@ -3,10 +3,6 @@
Pilldroid est une application de gestion de stock **théorique** de médicament à
destinations des personnes résidant en France.
-[](https://f-droid.org/packages/net.foucry.pilldroid/)
-
## Ce que n'est pas Pilldroid
- Pilldroid n'est pas un pilulier. Pilldroid ne vous rappellera pas de prendre
@@ -31,7 +27,7 @@ lancer son cycle de réveil journalier ;
scanner le code barre des boites de médicaments ;
- Pilldroid a besoin de pouvoir vous envoyer des alarmes ;
- Pilldroid a besoin de faire vibrer le téléphone pour les alarmes ;
-- Pilldroid utilise un accès Internet pour les remontée de crash *via* la bibliothèque [sentry.io](https://sentry.io).
+
## L'application Pilldroid embarque-t-elle des bibliothèques tierce ?
@@ -39,11 +35,6 @@ Oui. Pour la lecture de code barre, Pilldroid utilise le projet
[zxing](https://github.com/journeyapps/zxing-android-embedded) lui-même libre et
ouvert.
-A terme Pilldroid utilisera la bibliothèque
-[sentry.io](https://sentry.io/for/android/) quand j'aurais compris comment cela
-fonctionne. Le but est d'avoir des remontées les crashs de l'application sans
-collecter de données à caractère personnel.
-Déjà embarquée mais non fonctionnelle, `sentry.io` à besoin de l'accès Internet.
## L'application Pilldroid contient-elle des pisteurs ?
diff --git a/app/build.gradle b/app/build.gradle
index 4210b5a..cc3eb2b 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,14 +1,6 @@
//noinspection GradleCompatible
apply plugin: 'com.android.application'
-ext.versionMajor = 0
-ext.versionMinor = 65
-ext.versionPatch = new Date().format("yyyyMMdd")
-ext.versionClassifier = null
-ext.isSnapshot = false
-ext.minimumSdkVersion = defaultMinSdkVersion
-ext.git_version= ("git rev-parse --short HEAD".execute().text.trim())
-
// Try reading secrets from file
def secretsPropertiesFile = rootProject.file("secrets.properties")
def secretProperties = new Properties()
@@ -26,22 +18,26 @@ else {
android {
signingConfigs {
release {
+ storeFile rootProject.file("android-signing-keystore.jks")
+ storePassword secretProperties['signing_keystore_password']
+ keyAlias secretProperties['signing_release_alias_key']
+ keyPassword secretProperties['signing_release_key_password']
}
prerelease {
- storeFile file("../android-signing-keystore.jks")
+ storeFile rootProject.file("android-signing-keystore.jks")
storePassword secretProperties['signing_keystore_password']
- keyAlias secretProperties['signing_key_alias']
- keyPassword secretProperties['signing_key_password']
+ keyAlias secretProperties['signing_pre-release_key_alias']
+ keyPassword secretProperties['signing_pre-release_key_password']
}
}
- compileSdkVersion 29
+ compileSdkVersion 31
defaultConfig {
applicationId "net.foucry.pilldroid"
minSdkVersion defaultMinSdkVersion
targetSdkVersion defaultTargetSdkVersion
- versionCode generateVersionCode() // 190010203
- versionName generateVersionName() // 1.2.3-SNAPSHOT
+ versionCode 100
+ versionName "v0.100-beta"
multiDexEnabled true
}
@@ -55,6 +51,7 @@ android {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
+ signingConfig signingConfigs.release
}
prerelease {
minifyEnabled false
@@ -81,15 +78,11 @@ android {
}
compileOptions {
- coreLibraryDesugaringEnabled true
+ sourceCompatibility JavaVersion.VERSION_11
+ targetCompatibility JavaVersion.VERSION_11
+ }
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
- }
- dexOptions {
- incremental false
- javaMaxHeapSize "4g"
- }
+ buildToolsVersion '32.0.0'
allprojects {
tasks.withType(JavaCompile) {
@@ -112,40 +105,13 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.13.2'
- implementation 'androidx.appcompat:appcompat:1.2.0'
+ implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
- implementation 'com.google.android.material:material:1.4.0'
+ implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
- implementation 'androidx.core:core:1.6.0'
+ implementation 'androidx.core:core:1.7.0'
-// debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
-
- implementation 'io.sentry:sentry-android:5.4.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}
-
-private Integer generateVersionCode() {
- Integer versionCode = ext.minimumSdkVersion * 1000 + ext.versionMajor * 100 + ext.versionMinor
- print "versionCode = " + versionCode +"\n"
- return versionCode
-}
-
-private String generateVersionName() {
- String versionName = "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}"
- if (ext.versionClassifier == null && ext.isSnapshot) {
- ext.versionClassifier = "SNAPSHOT"
- }
-
- if (ext.versionClassifier != null) {
- versionName += "-" + ext.versionClassifier
- }
-
- if (ext.git_version != null) {
- versionName += "-" + ext.git_version
- }
-
- print "versionName = " + versionName
- return versionName
-}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index ebfc2b6..a70a432 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -59,7 +59,5 @@
-
-
-
\ No newline at end of file
+
diff --git a/app/src/main/assets/about.html b/app/src/main/assets/about.html
index 13cb3ab..c20e71c 100644
--- a/app/src/main/assets/about.html
+++ b/app/src/main/assets/about.html
@@ -14,11 +14,11 @@
}
-
+
-PillDroid © 2021 Jacques Foucry
-PillDroid est une gestion théorique de votre stock de médicaments.
-PillDroid n'a aucune connaissance des interactions des médicaments entre eux.
+Pilldroid © 2022 Jacques Foucry
+Pilldroid est une gestion théorique de votre stock de médicaments.
+Pilldroid n'a aucune connaissance des interactions des médicaments entre eux.
EN CAS DE DOUTE, CONSULTEZ VOTRE MÉDECIN OU VOTRE PHARMACIEN.
PillDroid ne vous rappelle pas de prendre vos médicaments.
LA RESPONSABILITÉ DE L'AUTEUR NE SAURAIT ÊTRE ENGAGÉE EN CAS DE SURDOSAGE OU D'OUBLI DE PRISE.
@@ -28,9 +28,9 @@
Les conseils et aides de mob-dev.fr.
Le soutien actif et les conseils du Dr Kauffmann me permettent de faire
- évoluer PillDroid.
+ évoluer Pilldroid.
Vous pouvez me contacter à l'adresse suivante : jacques+pilldroid@foucry.net
.
Le site web de l'application.
diff --git a/app/src/main/assets/icon_pilldroid.png b/app/src/main/assets/icon_pilldroid.png
new file mode 100644
index 0000000..c72814e
Binary files /dev/null and b/app/src/main/assets/icon_pilldroid.png differ
diff --git a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java
index 8883956..c2fe9ca 100644
--- a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java
+++ b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java
@@ -96,26 +96,24 @@ public class AlarmReceiver extends BroadcastReceiver {
String description = context.getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_DEFAULT;
String CHANNEL_ID = "PillDroid";
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
- channel.setDescription(description);
- channel.enableLights(true);
- channel.setLightColor(R.color.led);
- channel.enableVibration(true);
- channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
- // Register the channel with the system; you can't change the importance
- // or other notification behaviors after this
- NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
- try {
- notificationManager.createNotificationChannel(channel);
- } catch (Exception e) {
- // This will catch any exception, because they are all descended from Exception
- Log.e(TAG, e.toString());
- //At the level Exception Class handle the error in Exception Table
- // Exception Create That Error Object and throw it
- //E.g: FileNotFoundException ,etc
- e.printStackTrace();
- }
+ NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
+ channel.setDescription(description);
+ channel.enableLights(true);
+ channel.setLightColor(R.color.led);
+ channel.enableVibration(true);
+ channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
+ // Register the channel with the system; you can't change the importance
+ // or other notification behaviors after this
+ NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
+ try {
+ notificationManager.createNotificationChannel(channel);
+ } catch (Exception e) {
+ // This will catch any exception, because they are all descended from Exception
+ Log.e(TAG, e.toString());
+ //At the level Exception Class handle the error in Exception Table
+ // Exception Create That Error Object and throw it
+ //E.g: FileNotFoundException ,etc
+ e.printStackTrace();
}
}
public static void scheduleAlarm(Context context) {
@@ -150,4 +148,4 @@ public class AlarmReceiver extends BroadcastReceiver {
if (BuildConfig.DEBUG) { Toast.makeText(context, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis()), Toast.LENGTH_SHORT).show(); }
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/net/foucry/pilldroid/BarcodeValues.java b/app/src/main/java/net/foucry/pilldroid/BarcodeValues.java
new file mode 100644
index 0000000..5c19af2
--- /dev/null
+++ b/app/src/main/java/net/foucry/pilldroid/BarcodeValues.java
@@ -0,0 +1,23 @@
+package net.foucry.pilldroid;
+
+public class BarcodeValues {
+ private final String mFormat;
+ private final String mContent;
+
+ public BarcodeValues(String format, String content) {
+ mFormat = format;
+ mContent = content;
+ }
+
+ public String format() {
+ return mFormat;
+ }
+
+ public String content() {
+ return mContent;
+ }
+
+ public boolean isEmpty() {
+ return mFormat == null && mContent == null;
+ }
+}
diff --git a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java
index 0fb949b..b3ff7c1 100644
--- a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java
+++ b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java
@@ -1,15 +1,19 @@
package net.foucry.pilldroid;
import android.app.Activity;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.os.Bundle;
+import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageButton;
import androidx.annotation.NonNull;
+import com.journeyapps.barcodescanner.BarcodeCallback;
+import com.journeyapps.barcodescanner.BarcodeResult;
import com.journeyapps.barcodescanner.CaptureManager;
import com.journeyapps.barcodescanner.DecoratedBarcodeView;
import com.journeyapps.barcodescanner.ViewfinderView;
@@ -19,39 +23,59 @@ import java.util.Random;
/**
* Custom Scanner Activity extending from Activity to display a custom layout form scanner view.
*/
-public class CustomScannerActivity extends Activity implements
- DecoratedBarcodeView.TorchListener {
+public class CustomScannerActivity extends Activity implements DecoratedBarcodeView.TorchListener {
+
+ private static final String TAG = CustomScannerActivity.class.getName();
private CaptureManager capture;
private DecoratedBarcodeView barcodeScannerView;
private ImageButton switchFlashlightButton;
private ViewfinderView viewfinderView;
+ final Bundle captureIntentBundle = new Bundle();
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
setContentView(R.layout.activity_custom_scanner);
- barcodeScannerView = findViewById(R.id.zxing_barcode_scanner);
- barcodeScannerView.setTorchListener(this);
+ //barcodeScannerView.setTorchListener(this);
+ findViewById(R.id.keyboard_button).setOnClickListener(this::onKeyboard);
+ findViewById(R.id.cancel_button).setOnClickListener(this::onCancel);
+ findViewById(R.id.switch_flashlight).setOnClickListener(this::switchFlashlight);
switchFlashlightButton = findViewById(R.id.switch_flashlight);
-
viewfinderView = findViewById(R.id.zxing_viewfinder_view);
+ barcodeScannerView = findViewById(R.id.zxing_barcode_scanner);
+
// if the device does not have flashlight in its camera,
// then remove the switch flashlight button...
if (!hasFlash()) {
- switchFlashlightButton.setVisibility(View.GONE);
+ findViewById(R.id.switch_flashlight).setVisibility(View.GONE);
}
capture = new CaptureManager(this, barcodeScannerView);
capture.initializeFromIntent(getIntent(), savedInstanceState);
capture.setShowMissingCameraPermissionDialog(false);
- capture.decode();
- changeMaskColor(null);
+ //changeMaskColor(null);
changeLaserVisibility(true);
+ barcodeScannerView.decodeSingle(new BarcodeCallback() {
+ @Override
+ public void barcodeResult(BarcodeResult result) {
+ Intent scanResult = new Intent();
+ //Bundle scanResultBundle = new Bundle();
+ scanResult.putExtra("Barcode Content", result.getText());
+ scanResult.putExtra("Barcode Format name", result.getBarcodeFormat().name());
+ scanResult.putExtra("returnCode", captureIntentBundle.getInt("returnCode"));
+ scanResult.putExtra("resultCode", 1);
+ CustomScannerActivity.this.setResult(RESULT_OK, scanResult);
+ Log.d(TAG, "scanResult == " + scanResult);
+ finish();
+ }
+ });
}
@Override
@@ -85,6 +109,7 @@ public class CustomScannerActivity extends Activity implements
/**
* Check if the device's camera has a Flashlight.
+ *
* @return true if there is Flashlight, otherwise false.
*/
private boolean hasFlash() {
@@ -93,10 +118,13 @@ public class CustomScannerActivity extends Activity implements
}
public void switchFlashlight(View view) {
+ Log.d(TAG, "Switch torch");
if (switchFlashlightButton.isActivated()) {
barcodeScannerView.setTorchOff();
+ switchFlashlightButton.setActivated(false);
} else {
barcodeScannerView.setTorchOn();
+ switchFlashlightButton.setActivated(true);
}
}
@@ -110,13 +138,13 @@ public class CustomScannerActivity extends Activity implements
viewfinderView.setLaserVisibility(visible);
}
- @Override
public void onTorchOn() {
+ Log.d(TAG, "TorchON");
switchFlashlightButton.setActivated(true);
}
- @Override
public void onTorchOff() {
+ Log.d(TAG, "TorchOFF");
switchFlashlightButton.setActivated(false);
}
@@ -125,14 +153,20 @@ public class CustomScannerActivity extends Activity implements
capture.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
-
public void onKeyboard(View view) {
- setResult(3);
+ Log.d(TAG, "onkeyboard");
+ Intent resultIntent = new Intent();
+ resultIntent.putExtra("returnCode",3);
+ CustomScannerActivity.this.setResult(RESULT_OK, resultIntent);
finish();
}
public void onCancel(View view) {
- setResult(2);
+ Log.d(TAG, "onCancel");
+ Intent resultIntent = new Intent();
+ resultIntent.putExtra("returnCode", 2);
+ CustomScannerActivity.this.setResult(RESULT_OK, resultIntent);
finish();
}
+
}
diff --git a/app/src/main/java/net/foucry/pilldroid/DBDrugs.java b/app/src/main/java/net/foucry/pilldroid/DBDrugs.java
index 1ff6a2a..912cf42 100644
--- a/app/src/main/java/net/foucry/pilldroid/DBDrugs.java
+++ b/app/src/main/java/net/foucry/pilldroid/DBDrugs.java
@@ -46,9 +46,10 @@ class DBDrugs extends SQLiteOpenHelper {
public boolean isDBFileExist(File database)
{
- try {
+ try {
myContext.getDatabasePath(String.valueOf(database));
- } catch (final Exception exception) {
+ }
+ catch (final Exception e){
return false;
}
return true;
@@ -108,9 +109,8 @@ class DBDrugs extends SQLiteOpenHelper {
@Override
public synchronized void close() {
- if (myDataBase != null) {
- myDataBase.close();
- }
+ assert false;
+ myDataBase.close();
}
/**
@@ -154,7 +154,7 @@ class DBDrugs extends SQLiteOpenHelper {
drug.setAlertThreshold(7);
// Log
- Log.d(TAG, "getDrug(" + cip13 + ")" + drug.toString());
+ Log.d(TAG, "getDrug(" + cip13 + ")" + drug);
// Return drug
@@ -222,7 +222,7 @@ class DBDrugs extends SQLiteOpenHelper {
drug.setAlertThreshold(7);
// Log
- Log.d(TAG, "getDrug(" + cip7 + ")" + drug.toString());
+ Log.d(TAG, "getDrug(" + cip7 + ")" + drug);
// Return drug
diff --git a/app/src/main/java/net/foucry/pilldroid/DBHelper.java b/app/src/main/java/net/foucry/pilldroid/DBHelper.java
index 5d9954e..0fb0784 100644
--- a/app/src/main/java/net/foucry/pilldroid/DBHelper.java
+++ b/app/src/main/java/net/foucry/pilldroid/DBHelper.java
@@ -161,7 +161,7 @@ class DBHelper extends SQLiteOpenHelper {
drug.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
}
// Log
- Log.d(TAG, "getDrug("+id+")" + drug.toString());
+ Log.d(TAG, "getDrug("+id+")" + drug);
assert cursor != null;
cursor.close();
@@ -212,7 +212,7 @@ class DBHelper extends SQLiteOpenHelper {
assert cursor != null;
cursor.close();
- Log.d(TAG, "getDrug(" + cip13 + ")" + drug.toString());
+ Log.d(TAG, "getDrug(" + cip13 + ")" + drug);
return drug;
}
@@ -274,10 +274,7 @@ class DBHelper extends SQLiteOpenHelper {
- Log.d(TAG, "Before sort == " + drugs.toString());
-
- /*drugs.sort(Comparator.comparing(Drug::getDateEndOfStock)
- .thenComparing(Drug::getStock));*/
+ Log.d(TAG, "Before sort == " + drugs);
drugs.sort(new Comparator() {
@Override
@@ -288,7 +285,7 @@ class DBHelper extends SQLiteOpenHelper {
return (int) (lhs.getStock() - rhs.getStock());
}
});
- Log.d(TAG, "After sort " + drugs.toString());
+ Log.d(TAG, "After sort " + drugs);
// Move drug with prise = 0 at the end of the list
// todo: If some drug moved, must redo all the loop
@@ -320,7 +317,7 @@ class DBHelper extends SQLiteOpenHelper {
// Get reference to writable DB
SQLiteDatabase db = this.getWritableDatabase();
- // Create ContentValues to add columnm/value
+ // Create ContentValues to add column/value
ContentValues values = new ContentValues();
values.put(KEY_ID, drug.getId());
values.put(KEY_CIS, drug.getCis());
@@ -336,14 +333,14 @@ class DBHelper extends SQLiteOpenHelper {
String[] selectionArgs = { String.valueOf(drug.getId()) };
- db.update(TABLE_DRUG, // table
- values, // column/value
- KEY_ID + " = ?", // selections
+ db.update(TABLE_DRUG, // table
+ values, // column/value
+ KEY_ID + " = ?", // selections
selectionArgs);
// Close DB
db.close();
- Log.d(TAG, "values == " + values.toString());
+ Log.d(TAG, "values == " + values);
}
/**
diff --git a/app/src/main/java/net/foucry/pilldroid/Drug.java b/app/src/main/java/net/foucry/pilldroid/Drug.java
index 54a1686..5c5b011 100644
--- a/app/src/main/java/net/foucry/pilldroid/Drug.java
+++ b/app/src/main/java/net/foucry/pilldroid/Drug.java
@@ -165,7 +165,7 @@ public class Drug implements Serializable {
}
void newStock() {
- Log.d(TAG, "current drug = " + this.toString());
+ Log.d(TAG, "current drug = " + this);
Date lastUpdate = new Date(getDateLastUpdate());
diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java
index f39b211..21061a6 100644
--- a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java
+++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java
@@ -29,25 +29,25 @@ public class DrugDetailActivity extends AppCompatActivity {
Drug drug;
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- Bundle extras = getIntent().getExtras();
+ Bundle bundle = getIntent().getExtras();
/* fetching the string passed with intent using ‘extras’*/
- assert extras != null;
- drug = (Drug) extras.getSerializable("drug");
+ assert bundle != null;
+ drug = (Drug) bundle.getSerializable("drug");
assert drug != null;
- Log.d(TAG, "drug == " + drug.toString());
+ Log.d(TAG, "drug == " + drug);
+
+ /* fetching the string passed with intent using ‘bundle’*/
setContentView(R.layout.activity_drug_detail);
Toolbar toolbar = findViewById(detail_toolbar);
-
if (toolbar != null) {
setSupportActionBar(toolbar);
}
diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailContract.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailContract.java
new file mode 100644
index 0000000..7059816
--- /dev/null
+++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailContract.java
@@ -0,0 +1,39 @@
+package net.foucry.pilldroid;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+
+import androidx.activity.result.contract.ActivityResultContract;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+public class DrugDetailContract extends ActivityResultContract {
+ /**
+ * Create an intent that can be used for {@link Activity#startActivityForResult}
+ *
+ * @param context Context
+ * @param input Drug
+ */
+ @NonNull
+ @Override
+ public Intent createIntent(@NonNull Context context, Intent input) {
+ Intent intent = new Intent(context, DrugDetailActivity.class);
+
+ intent.putExtra("Drug", input.getExtras());
+ return (intent);
+ }
+
+ /**
+ * Convert result obtained from to O
+ * @param resultCode Integer
+ * @param intent Intent
+ * @return Integer
+ */
+ @Override
+ public Integer parseResult(int resultCode, @Nullable Intent intent) {
+
+ return resultCode;
+ }
+}
diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java
index 9466bb8..04a74e1 100644
--- a/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java
+++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java
@@ -80,13 +80,13 @@ public class DrugDetailFragment extends Fragment {
presentationView = detailView.findViewById(R.id.presentation_cell);
TextView presentationLabel = presentationView.findViewById(R.id.label);
TextView presentationValue = presentationView.findViewById(R.id.value);
- presentationLabel.setText(R.string.drug_presention_labal);
+ presentationLabel.setText(R.string.drug_presentation_label);
presentationValue.setText(drug.getPresentation());
adminModeView = detailView.findViewById(R.id.administration_cell);
TextView adminModeLabel = adminModeView.findViewById(R.id.label);
TextView adminModeValue = adminModeView.findViewById(R.id.value);
- adminModeLabel.setText(R.string.drug_administationMode_label);
+ adminModeLabel.setText(R.string.drug_administrationMode_label);
adminModeValue.setText(drug.getAdministration_mode());
stockView = detailView.findViewById(R.id.stock_cell);
@@ -108,17 +108,17 @@ public class DrugDetailFragment extends Fragment {
warningView = detailView.findViewById(R.id.warning_cell);
TextView warningLibelle = warningView.findViewById(R.id.label);
TextView warningValue = warningView.findViewById(R.id.value);
- warningLibelle.setText(R.string.drug_warningTherehold_label);
+ warningLibelle.setText(R.string.drug_warningThreshold_label);
warningValue.setText(Integer.toString(drug.getWarnThreshold()));
- warningValue.setHint(R.string.drug_warningTherehold_label);
+ warningValue.setHint(R.string.drug_warningThreshold_label);
warningValue.setSelectAllOnFocus(true);
alertView = detailView.findViewById(R.id.alert_cell);
TextView alertLibelle = alertView.findViewById(R.id.label);
TextView alertValue = alertView.findViewById(R.id.value);
- alertLibelle.setText(R.string.drug_alertTherehold_label);
+ alertLibelle.setText(R.string.drug_alertThreshold_label);
alertValue.setText(Integer.toString(drug.getAlertThreshold()));
- alertValue.setHint(R.string.drug_alertTherehold_label);
+ alertValue.setHint(R.string.drug_alertThreshold_label);
alertValue.setSelectAllOnFocus(true);
}
diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java
index 343fa98..c9f724f 100644
--- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java
+++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java
@@ -1,11 +1,14 @@
package net.foucry.pilldroid;
+import static net.foucry.pilldroid.UtilDate.date2String;
+import static net.foucry.pilldroid.Utils.intRandomExclusive;
+
+import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
-import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
@@ -21,6 +24,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
+import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
@@ -28,17 +32,13 @@ import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.RecyclerView;
import com.google.zxing.client.android.Intents;
-import com.google.zxing.integration.android.IntentIntegrator;
-import com.google.zxing.integration.android.IntentResult;
+import com.journeyapps.barcodescanner.ScanOptions;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
-import static net.foucry.pilldroid.UtilDate.date2String;
-import static net.foucry.pilldroid.Utils.intRandomExclusive;
-
/**
* An activity representing a list of Drugs is activity
* has different presentations for handset and tablet-size devices. On
@@ -53,11 +53,16 @@ public class DrugListActivity extends AppCompatActivity {
* device.
*/
- // TODO: Change DEMO/DBDEMO form static to non-static. In order to create fake data at only at launchtime
+ // TODO: Change DEMO/DBDEMO form static to non-static. In order to create fake data at only at launch time
final Boolean DEMO = false;
final Boolean DBDEMO = false;
public final int CUSTOMIZED_REQUEST_CODE = 0x0000ffff;
+ public final String BARCODE_FORMAT_NAME = "Barcode Format name";
+ public final String BARCODE_CONTENT = "Barcode Content";
+
+ private ActivityResultLauncher mBarcodeScannerLauncher;
+
/**
* Start tutorial
@@ -74,8 +79,8 @@ public class DrugListActivity extends AppCompatActivity {
nm.cancelAll();
}
- // tuto
- Log.i(TAG, "Launch tuto");
+ // tutorial
+ Log.i(TAG, "Launch tutorial");
startActivity(new Intent(this, WelcomeActivity.class));
}
@@ -93,8 +98,7 @@ public class DrugListActivity extends AppCompatActivity {
private SimpleItemRecyclerViewAdapter mAdapter;
- public void constructDrugsList()
- {
+ public void constructDrugsList() {
dbHelper = new DBHelper(getApplicationContext());
if (!(drugs == null)) {
@@ -109,15 +113,14 @@ public class DrugListActivity extends AppCompatActivity {
setupRecyclerView((RecyclerView) mRecyclerView);
}
+ @SuppressLint("NotifyDataSetChanged")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drug_list);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- dbHelper = new DBHelper(this);
- }
+ dbHelper = new DBHelper(this);
dbDrug = new DBDrugs(this);
Toolbar toolbar = findViewById(R.id.toolbar);
@@ -139,10 +142,10 @@ public class DrugListActivity extends AppCompatActivity {
// String presentation,double stock, double prise, int warn, int alert
// Limit for randoms generator
- final int min_stock=5;
- final int max_stock=50;
- final int min_prise=0;
- final int max_prise=3;
+ final int min_stock = 5;
+ final int max_stock = 50;
+ final int min_prise = 0;
+ final int max_prise = 3;
dbHelper.addDrug(new Drug("60000011", "3400930000011", "Médicament test 01", "orale",
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
@@ -177,6 +180,68 @@ public class DrugListActivity extends AppCompatActivity {
}
}
+ mBarcodeScannerLauncher = registerForActivityResult(new PilldroidScanContract(),
+ result -> {
+ if (result.getContents() == null) {
+ Intent originalIntent = result.getOriginalIntent();
+ Bundle bundle = originalIntent.getExtras();
+ if (originalIntent.hasExtra(Intents.Scan.MISSING_CAMERA_PERMISSION)) {
+ Log.d(TAG, "Missing camera permission");
+ Toast.makeText(this, R.string.missing_camera_permission, Toast.LENGTH_LONG).show();
+ } else {
+ Log.d(TAG, "bundle == " + bundle.getInt("returnCode"));
+ int returnCode = bundle.getInt("returnCode");
+ int resultCode = bundle.getInt("resultCode");
+
+ if (resultCode != 1) {
+ if (returnCode == 3) {
+ if (BuildConfig.DEBUG) {
+ Toast.makeText(this, "Keyboard input",
+ Toast.LENGTH_SHORT).show();
+ }
+ Log.d(TAG, "Keyboard Input");
+ showInputDialog();
+ } else if (returnCode == 2) {
+ Toast.makeText(this, R.string.cancelled_scan, Toast.LENGTH_LONG).show();
+ }
+ } else {
+ Log.d(TAG, "Scanned");
+ if (BuildConfig.DEBUG) {
+ Toast.makeText(this, "Scanned: " + bundle.getString(BARCODE_FORMAT_NAME),
+ Toast.LENGTH_LONG).show();
+ }
+ String cip13;
+
+ // Handle successful scan
+
+ Log.d(TAG, "formatName = " + bundle.getString(BARCODE_FORMAT_NAME));
+
+ switch (bundle.getString(BARCODE_FORMAT_NAME)) {
+ case "CODE_128":
+ case "EAN_13": //CODE_128 || EAN 13
+ cip13 = bundle.getString(BARCODE_CONTENT);
+ break;
+ case "CODE_39":
+ cip13 = dbDrug.getCIP13FromCIP7(bundle.getString(BARCODE_CONTENT));
+ break;
+ case "DATA_MATRIX":
+ cip13 = bundle.getString(BARCODE_CONTENT).substring(4, 17);
+ break;
+ default:
+ scanNotOK();
+ return;
+ }
+
+ // Get Drug from database
+ final Drug scannedDrug = dbDrug.getDrugByCIP13(cip13);
+
+ // add Drug to prescription database
+ askToAddInDB(scannedDrug);
+ }
+ }
+ }
+ });
+
constructDrugsList();
}
@@ -202,9 +267,27 @@ public class DrugListActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item);
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ /*if (requestCode != CUSTOMIZED_REQUEST_CODE && requestCode != IntentIntegrator.REQUEST_CODE) {
+ // This is important, otherwise the result will not be passed to the fragment
+ super.onActivityResult(requestCode, resultCode, data);
+ return;
+ }*/
+ if (requestCode == CUSTOMIZED_REQUEST_CODE) {
+ if (BuildConfig.DEBUG) {
+ Toast.makeText(this, "REQUEST_CODE = " + requestCode +
+ "RESULT_CODE = " + resultCode, Toast.LENGTH_LONG).show();
+ }
+ Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
+ constructDrugsList();
+ }
+ }
+
public void onPause() {
super.onPause();
- Log.d(TAG, "onPause really!");
+ Log.d(TAG, "onPause");
AlarmReceiver.scheduleAlarm(this);
}
@@ -212,89 +295,24 @@ public class DrugListActivity extends AppCompatActivity {
super.onResume();
}
- /** scanNow
- *
- * @param view
- * call ZXing Library to scan a new QR/EAN code
- */
- public void scanNow(View view) {
- new IntentIntegrator(this).setOrientationLocked(false).setCaptureActivity(CustomScannerActivity.class).initiateScan();
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode != CUSTOMIZED_REQUEST_CODE && requestCode != IntentIntegrator.REQUEST_CODE) {
- // This is important, otherwise the result will not be passed to the fragment
- super.onActivityResult(requestCode, resultCode, data);
- return;
- }
- if (requestCode == CUSTOMIZED_REQUEST_CODE) {
- if (BuildConfig.DEBUG) { Toast.makeText(this, "REQUEST_CODE = " + requestCode +
- "RESULT_CODE = " + resultCode, Toast.LENGTH_LONG).show(); }
- Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
- constructDrugsList();
- } else {
- IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data);
+ // Launch scan
+ public void onButtonClick() {
+ Log.d(TAG, "add medication");
+ ScanOptions options = new ScanOptions();
+ options.setDesiredBarcodeFormats(ScanOptions.DATA_MATRIX, ScanOptions.CODE_39,
+ ScanOptions.CODE_128);
+ options.setCameraId(0); // Use a specific camera of the device
+ options.setBeepEnabled(true);
+ options.setBarcodeImageEnabled(true);
+ //options.setTimeout(3600);
+ options.setCaptureActivity(CustomScannerActivity.class);
+ options.setBeepEnabled(true);
+ options.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.MIXED_SCAN);
+ options.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.INVERTED_SCAN);
- if (BuildConfig.DEBUG) { Toast.makeText(this, "REQUEST_CODE = " + requestCode,
- Toast.LENGTH_LONG).show(); }
-
- Log.d(TAG, "REQUEST_CODE = " + requestCode + "resultCode = " + resultCode);
- if (result.getContents() == null) {
- Intent originalIntent = result.getOriginalIntent();
- if (originalIntent == null) {
- if (resultCode == 3) {
- if(BuildConfig.DEBUG) { Toast.makeText(this, "Keyboard input",
- Toast.LENGTH_SHORT).show(); }
- Log.d(TAG, "Keyboard Input");
- showInputDialog();
- } else {
- Log.d(TAG, "Cancelled scan");
- Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
- }
- if(BuildConfig.DEBUG) { Toast.makeText(this, "Cancelled",
- Toast.LENGTH_LONG).show(); }
- } else if (originalIntent.hasExtra(Intents.Scan.MISSING_CAMERA_PERMISSION)) {
- Log.d(TAG, "Cancelled scan due to missing camera permission");
- Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
- Toast.makeText(this, "Cancelled due to missing camera permission", Toast.LENGTH_LONG).show();
- }
- } else {
- Log.d(TAG, "Scanned");
- Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
- Log.d(TAG, "result.getContents = " + result.getContents());
- Log.d(TAG, "format = " + result.getFormatName());
-
- if (BuildConfig.DEBUG) { Toast.makeText(this, "Scanned: " +
- result.getContents(), Toast.LENGTH_LONG).show(); }
-
- String cip13;
-
- // Handle successful scan
-
- Log.d(TAG, "formatName = " + result.getFormatName());
-
- switch (result.getFormatName()) {
- case "CODE_128":
- case "EAN_13": //CODE_128 || EAN 13
- cip13 = result.getContents();
- break;
- case "CODE_39":
- cip13 = dbDrug.getCIP13FromCIP7(result.getContents());
- break;
- case "DATA_MATRIX":
- cip13 = result.getContents().substring(4, 17);
- break;
- default:
- scanNotOK();
- return;
- }
-
- // Get Drug from database
- final Drug scannedDrug = dbDrug.getDrugByCIP13(cip13);
- askToAddInDB(scannedDrug);
- }
- }
+ Log.d(TAG, "scanOptions == " + options);
+ mBarcodeScannerLauncher.launch(options);
}
/**
@@ -316,7 +334,7 @@ public class DrugListActivity extends AppCompatActivity {
String cip13 = editText.getText().toString();
Drug aDrug = dbDrug.getDrugByCIP13(cip13);
- askToAddInDB(aDrug);
+ askToAddInDB(aDrug);
})
.setNegativeButton("Cancel",
(dialog, id) -> dialog.cancel());
@@ -346,6 +364,7 @@ public class DrugListActivity extends AppCompatActivity {
/**
* Ask if the drug found in the database should be include in the
* user database
+ *
* @param aDrug Drug- drug to be added
*/
private void askToAddInDB(Drug aDrug) {
@@ -375,8 +394,7 @@ public class DrugListActivity extends AppCompatActivity {
/**
* Tell user that the barre code cannot be interpreted
*/
- private void scanNotOK()
- {
+ private void scanNotOK() {
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
dlg.setTitle(getString(R.string.app_name));
@@ -389,10 +407,12 @@ public class DrugListActivity extends AppCompatActivity {
/**
* Add New drug to the user database
+ *
* @param aDrug Drug - drug to be added
*/
- private void addDrugToList(Drug aDrug)
- {
+
+ @SuppressWarnings("deprecation")
+ private void addDrugToList(Drug aDrug) {
aDrug.setDateEndOfStock();
mAdapter.addItem(aDrug);
@@ -400,11 +420,24 @@ public class DrugListActivity extends AppCompatActivity {
Context context = this;
Intent intent = new Intent(context, DrugDetailActivity.class);
intent.putExtra("drug", aDrug);
+
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
}
- /**
- * setupRecyclerView (list of drugs
+
+ private String getAppName() {
+ PackageManager packageManager = getApplicationContext().getPackageManager();
+ ApplicationInfo applicationInfo = null;
+ try {
+ applicationInfo = packageManager.getApplicationInfo(this.getPackageName(), 0);
+ } catch (final PackageManager.NameNotFoundException ignored) {
+ }
+ return (String) ((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???");
+ }
+
+ /**
+ * setupRecyclerView (list of drugs)
+ *
* @param recyclerView RecyclerView
*/
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
@@ -413,21 +446,13 @@ public class DrugListActivity extends AppCompatActivity {
recyclerView.setAdapter(mAdapter);
}
- private String getAppName() {
- PackageManager packageManager = getApplicationContext().getPackageManager();
- ApplicationInfo applicationInfo = null;
- try {
- applicationInfo = packageManager.getApplicationInfo(this.getPackageName(), 0);
- } catch (final PackageManager.NameNotFoundException ignored) {}
- return (String)((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???");
- }
-
/**
* SimpleItemRecyclerViewAdapter
*/
public class SimpleItemRecyclerViewAdapter extends RecyclerView.Adapter {
private final List mValues;
+
SimpleItemRecyclerViewAdapter(List items) {
mValues = items;
}
@@ -452,6 +477,7 @@ public class DrugListActivity extends AppCompatActivity {
}
@Override
+ @SuppressWarnings("deprecation")
public void onBindViewHolder(final ViewHolder holder, int dummy) {
final int position = holder.getBindingAdapterPosition();
SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE d MMMM yyyy", Locale.getDefault());
@@ -473,6 +499,19 @@ public class DrugListActivity extends AppCompatActivity {
if (mValues.get(position).getTake() == 0) {
holder.mView.setBackgroundResource(R.drawable.gradient_bg);
holder.mIconView.setImageResource(R.drawable.ic_suspended_pill);
+
+ holder.mView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Drug drug = mValues.get(position);
+ Context context = v.getContext();
+ Intent intent = new Intent(context, DrugDetailActivity.class);
+ intent.putExtra("drug", drug);
+ startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
+ overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
+
+ }
+ });
} else {
int remainingStock = (int) Math.floor(mValues.get(position).getStock() / mValues.get(position).getTake());
if (remainingStock <= mValues.get(position).getAlertThreshold()) {
@@ -486,19 +525,21 @@ public class DrugListActivity extends AppCompatActivity {
holder.mView.setBackgroundResource(R.drawable.gradient_bg_ok);
holder.mIconView.setImageResource(R.drawable.ok_stock_vect);
}
+
+ holder.mView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Drug drug = mValues.get(position);
+ Context context = v.getContext();
+ Intent intent = new Intent(context, DrugDetailActivity.class);
+ intent.putExtra("drug", drug);
+ startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
+ overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
+
+ }
+ });
}
- holder.mView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Drug drugCourant = mValues.get(position);
- Context context = v.getContext();
- Intent intent = new Intent(context, DrugDetailActivity.class);
- intent.putExtra("drug", drugCourant);
- startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
- overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
- }
- });
}
@Override
@@ -511,8 +552,7 @@ public class DrugListActivity extends AppCompatActivity {
final TextView mContentView;
final TextView mEndOfStock;
final ImageView mIconView;
-
- Drug mItem;
+ public Drug mItem;
ViewHolder(View view) {
super(view);
@@ -529,4 +569,4 @@ public class DrugListActivity extends AppCompatActivity {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java
index 5d37158..3ee2e7b 100644
--- a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java
+++ b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java
@@ -13,7 +13,6 @@ import androidx.core.app.NotificationManagerCompat;
import java.util.List;
-
/**
* Created by jacques on 17/09/16.
*/
@@ -89,7 +88,7 @@ public class PillDroidJobService extends JobService {
Log.d(TAG, "schedule notification");
createNotificationChannel();
Intent intent = new Intent(this, DrugListActivity.class);
- PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,0);
+ PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,PendingIntent.FLAG_MUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "PillDroid")
.setSmallIcon(R.drawable.ic_pill_alarm)
.setContentTitle(getString(R.string.app_name))
@@ -114,23 +113,21 @@ public class PillDroidJobService extends JobService {
int importance = NotificationManager.IMPORTANCE_DEFAULT;
String CHANNEL_ID = "PillDroid";
NotificationChannel channel;
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- channel = new NotificationChannel(CHANNEL_ID, name, importance);
+ channel = new NotificationChannel(CHANNEL_ID, name, importance);
- channel.setDescription(description);
- // Register the channel with the system; you can't change the importance
- // or other notification behaviors after this
- NotificationManager notificationManager = getSystemService(NotificationManager.class);
- try {
- notificationManager.createNotificationChannel(channel);
- } catch (Exception e) {
- // This will catch any exception, because they are all descended from Exception
- Log.e(TAG, e.toString());
- //At the level Exception Class handle the error in Exception Table
- // Exception Create That Error Object and throw it
- //E.g: FileNotFoundException ,etc
- e.printStackTrace();
- }
+ channel.setDescription(description);
+ // Register the channel with the system; you can't change the importance
+ // or other notification behaviors after this
+ NotificationManager notificationManager = getSystemService(NotificationManager.class);
+ try {
+ notificationManager.createNotificationChannel(channel);
+ } catch (Exception e) {
+ // This will catch any exception, because they are all descended from Exception
+ Log.e(TAG, e.toString());
+ //At the level Exception Class handle the error in Exception Table
+ // Exception Create That Error Object and throw it
+ //E.g: FileNotFoundException ,etc
+ e.printStackTrace();
}
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/net/foucry/pilldroid/PilldroidScanContract.java b/app/src/main/java/net/foucry/pilldroid/PilldroidScanContract.java
new file mode 100644
index 0000000..8c8478a
--- /dev/null
+++ b/app/src/main/java/net/foucry/pilldroid/PilldroidScanContract.java
@@ -0,0 +1,35 @@
+package net.foucry.pilldroid;
+
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+import androidx.activity.result.contract.ActivityResultContract;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.google.zxing.client.android.Intents;
+import com.journeyapps.barcodescanner.ScanIntentResult;
+import com.journeyapps.barcodescanner.ScanOptions;
+
+
+public class PilldroidScanContract extends ActivityResultContract{
+ private static final String TAG = PilldroidScanContract.class.getName();
+ @NonNull
+ @Override
+ public Intent createIntent(@NonNull Context context, ScanOptions input) {
+ Log.d(TAG, "create Intent");
+
+ Intent intent = new Intent(context, CustomScannerActivity.class);
+
+ intent.setAction(Intents.Scan.ACTION);
+
+ Log.d(TAG, "intent ==" + intent);
+ return(intent);
+ }
+
+ @Override
+ public ScanIntentResult parseResult(int resultCode, @Nullable Intent intent) {
+ return ScanIntentResult.parseActivityResult(resultCode, intent);
+ }
+}
diff --git a/app/src/main/java/net/foucry/pilldroid/PrefManager.java b/app/src/main/java/net/foucry/pilldroid/PrefManager.java
index cbd6736..352df03 100644
--- a/app/src/main/java/net/foucry/pilldroid/PrefManager.java
+++ b/app/src/main/java/net/foucry/pilldroid/PrefManager.java
@@ -8,11 +8,11 @@ import android.content.SharedPreferences;
* Created by Lincoln on 05/05/16.
*/
public class PrefManager {
- SharedPreferences pref;
+ final SharedPreferences pref;
SharedPreferences.Editor editor;
// shared pref mode
- int PRIVATE_MODE = 0;
+ final int PRIVATE_MODE = 0;
// Shared preferences file name
private static final String PREF_NAME = "Pildroid-Prefs";
diff --git a/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java b/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java
index 86a5bcf..ea424b5 100644
--- a/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java
+++ b/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java
@@ -6,7 +6,6 @@ import android.graphics.drawable.Drawable;
import android.view.View;
import androidx.annotation.NonNull;
-import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
/**
diff --git a/app/src/main/java/net/foucry/pilldroid/UtilDate.java b/app/src/main/java/net/foucry/pilldroid/UtilDate.java
index 1213256..bafb822 100644
--- a/app/src/main/java/net/foucry/pilldroid/UtilDate.java
+++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java
@@ -5,7 +5,6 @@ import android.util.Log;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
-import java.time.LocalTime;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java
index b57bd0c..0db4c80 100644
--- a/app/src/main/java/net/foucry/pilldroid/Utils.java
+++ b/app/src/main/java/net/foucry/pilldroid/Utils.java
@@ -1,11 +1,20 @@
package net.foucry.pilldroid;
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Random;
public class Utils {
- private static final String TAG = UtilDate.class.getName();
+ private static final String TAG = Utils.class.getName();
+
+ public static final int SELECT_BARCODE_REQUEST = 2;
+ public static final int BARCODE_SCAN = 3;
public static void CopyStream(InputStream is, OutputStream os)
{
@@ -20,8 +29,10 @@ public class Utils {
break;
os.write(bytes, 0, count);
}
+ } catch (IOException e) {
+ e.printStackTrace();
}
- catch(Exception ignored){}
+
}
/**
@@ -34,5 +45,4 @@ public class Utils {
Random r = new Random();
return r.nextInt(max - min) +max;
}
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java
index ebb5a8c..fe0946a 100644
--- a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java
+++ b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java
@@ -2,16 +2,20 @@ package net.foucry.pilldroid;
import android.content.Intent;
import android.graphics.Color;
+import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
+import android.view.WindowInsets;
+import android.view.WindowInsetsController;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.viewpager.widget.PagerAdapter;
@@ -41,11 +45,10 @@ public class WelcomeActivity extends AppCompatActivity {
}
prefManager.setFirstTimeLaunch(false);
- // Making notification bar transparent
- getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
-
setContentView(R.layout.activity_welcome);
+ setFullScreen();
+
viewPager = findViewById(R.id.view_pager);
dotsLayout = findViewById(R.id.layoutDots);
btnSkip = findViewById(R.id.btn_skip);
@@ -90,7 +93,7 @@ public class WelcomeActivity extends AppCompatActivity {
public void onClick(View v) {
// checking for last page
// if last page home screen will be launched
- int current = getItem(+1);
+ int current = getItem();
if (current < layouts.length) {
// move to next screen
viewPager.setCurrentItem(current);
@@ -118,8 +121,8 @@ public class WelcomeActivity extends AppCompatActivity {
dots[currentPage].setTextColor(ContextCompat.getColor(this, R.color.dot_light));
}
- private int getItem(int i) {
- return viewPager.getCurrentItem() + i;
+ private int getItem() {
+ return viewPager.getCurrentItem() + 1;
}
void launchHomeScreen() {
@@ -129,7 +132,7 @@ public class WelcomeActivity extends AppCompatActivity {
}
// viewpager change listener
- ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() {
+ final ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
@@ -167,6 +170,28 @@ public class WelcomeActivity extends AppCompatActivity {
window.setStatusBarColor(Color.TRANSPARENT);
}
+ @SuppressWarnings("deprecation")
+ private void setFullScreen(){
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ getWindow().setDecorFitsSystemWindows(false);
+ WindowInsetsController controller = getWindow().getInsetsController();
+ if(controller != null) {
+ controller.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
+ controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
+ }
+ }
+ else {
+ //noinspection
+ getWindow().getDecorView().setSystemUiVisibility(
+ View.SYSTEM_UI_FLAG_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_IMMERSIVE
+ | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
+ }
+ }
+
/**
* View pager adapter
*/
@@ -175,8 +200,9 @@ public class WelcomeActivity extends AppCompatActivity {
public MyViewPagerAdapter() {
}
+ @NonNull
@Override
- public Object instantiateItem(ViewGroup container, int position) {
+ public Object instantiateItem(@NonNull ViewGroup container, int position) {
LayoutInflater layoutInflater = getLayoutInflater();
View view = layoutInflater.inflate(layouts[position], container, false);
@@ -191,13 +217,13 @@ public class WelcomeActivity extends AppCompatActivity {
}
@Override
- public boolean isViewFromObject(View view, Object obj) {
+ public boolean isViewFromObject(@NonNull View view, @NonNull Object obj) {
return view == obj;
}
@Override
- public void destroyItem(ViewGroup container, int position, Object object) {
+ public void destroyItem(ViewGroup container, int position, @NonNull Object object) {
View view = (View) object;
container.removeView(view);
}
diff --git a/app/src/main/res/layout-w900dp/drug_list.xml b/app/src/main/res/layout-w900dp/drug_list.xml
index 05c8107..2d16261 100644
--- a/app/src/main/res/layout-w900dp/drug_list.xml
+++ b/app/src/main/res/layout-w900dp/drug_list.xml
@@ -17,8 +17,7 @@
-->
-
+ tools:context="net.foucry.pilldroid.CustomScannerActivity">
diff --git a/app/src/main/res/layout/activity_drug_list.xml b/app/src/main/res/layout/activity_drug_list.xml
index 8082bf0..6ded56d 100644
--- a/app/src/main/res/layout/activity_drug_list.xml
+++ b/app/src/main/res/layout/activity_drug_list.xml
@@ -45,7 +45,7 @@
android:backgroundTint="@android:color/transparent"
android:baselineAlignBottom="false"
android:clickable="false"
- android:onClick="scanNow"
+ android:onClick="onButtonClick"
android:src="@drawable/ic_add_circle_black_24dp"
app:backgroundTint="@android:color/darker_gray"
app:fabCustomSize="60dp"
diff --git a/app/src/main/res/layout/custom_barcode_scanner.xml b/app/src/main/res/layout/custom_barcode_scanner.xml
index 18161ba..0c93518 100644
--- a/app/src/main/res/layout/custom_barcode_scanner.xml
+++ b/app/src/main/res/layout/custom_barcode_scanner.xml
@@ -20,7 +20,7 @@
app:zxing_result_view="@color/zxing_custom_result_view"
app:zxing_viewfinder_laser="@color/zxing_custom_viewfinder_laser"
app:zxing_viewfinder_laser_visibility="true"
- app:zxing_viewfinder_mask="@color/zxing_custom_viewfinder_mask" />
+ app:zxing_viewfinder_mask="@color/grey"/>
+ android:src="@drawable/ic_keyboard_black_24dp"
+ tools:ignore="PrivateResource" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/welcome3.xml b/app/src/main/res/layout/welcome3.xml
index 2aa71b6..e1ab90f 100644
--- a/app/src/main/res/layout/welcome3.xml
+++ b/app/src/main/res/layout/welcome3.xml
@@ -10,7 +10,7 @@
Détail Médicament
Annuler
OK
- Présentation
+ Présentation
Nom
- Mode d\'adminitration
+ Mode d\'adminitration
Médicament introuvable dans la base de données
À propos
Aide
Prise
- Seuil critique
- Seuil d\'alerte
+ Seuil critique
+ Seuil d\'alerte
Médicament trouvé dans la base de données
Stock courant
Vous devez passer à la pharmacie
Utilisez le clavier
Vue de détail
Enrefistrez
- Allumez/Éteignez le Flash
+ Allumez/Éteignez le Flash
Enter cip 13 here..
Enter CIP 13
@@ -42,12 +42,12 @@
L\'icône Plus
Pour trouver le CIP13
Visage souriant
- Icône de code barre
+ Icône de code barre
icône de QR-Code
Visage neutre
Visage grincheux
Capture d\'écran sur la partie information du médicament
- Réglages
+ Réglages
Mettre la prise à zéro suspend le traitement et les calculs de stock
Icône de traitemernt suspendu
Pour enregistrer les changements, utilisez l\'icône de sauvegarde
@@ -64,4 +64,6 @@
Libellé
Attributs d\'un médicament
Le code barre ne peut pas être interprété
+ Scan annulé
+ Permission appareil photo manquante
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 9213a92..b689444 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -3,6 +3,7 @@
#3F51B5
#303F9F
#FF4081
+ #FFFFFF
#4f91ff
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 63b85e2..d4070ac 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -8,16 +8,16 @@
Help
You have to go to the pharmacy
Name
- Presentation
- Administration mode
+ Presentation
+ Administration mode
Current stock
Take
- Alert therehold
- Critical therehold
+ Alert threshold
+ Critical threshold
"Use the keyboard"
Detail view
Save
- Toggle Flash
+ Toggle Flash
Enter cip 13 here..
Enter CIP 13
PillDroid_NotificationChannel
@@ -25,7 +25,7 @@
Welcome on Pilldroid
- The theorical Pill Stock Manager
+ The theoretical Pill Stock Manager
To add a med, tap on the "Plus" button
You\'ll add a drug to the database
You can scan classic barcode
@@ -43,12 +43,12 @@
The plus icon
In order to find the CIP13
Happy face
- Barre code icon
+ Barre code icon
qr-code icon
neutral face
unhappy face
Drug info screenshot
- Tunables
+ Tunable
Take to 0 to suspend treatment
Treatment suspended icon
To save changes
@@ -65,5 +65,7 @@
Value
Label
Drug\'s attributes
- Barre code cannot be intrepreted
+ Barre code cannot be interpreted
+ Scan canceled
+ Missing camera permission
diff --git a/build.gradle b/build.gradle
index cfe6773..9f806dc 100644
--- a/build.gradle
+++ b/build.gradle
@@ -9,7 +9,7 @@ buildscript {
google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:7.0.4'
+ classpath 'com.android.tools.build:gradle:7.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@@ -20,10 +20,11 @@ ext {
buildToolsVersion = '28.0.1'
var = '3.4.2'
//buildToolsVersion1 = '29.0.3'
- defaultMinSdkVersion = 24
+ defaultMinSdkVersion = 26
defaultTargetSdkVersion = 30
defaultVersionCode = 1
defaultVersionCode1 = defaultVersionCode
+ defaultVersionName = 'beta-0.+$versioncode'
}
allprojects {
diff --git a/fastlane/metadata/android/en-US/changelogs/v0.100-beta.txt b/fastlane/metadata/android/en-US/changelogs/v0.100-beta.txt
index 2b9c958..fce252b 100644
--- a/fastlane/metadata/android/en-US/changelogs/v0.100-beta.txt
+++ b/fastlane/metadata/android/en-US/changelogs/v0.100-beta.txt
@@ -23,4 +23,4 @@ do not stress me it will be unproductive.
Pilldroid will available only from [f-droid](https://f-droid.org)
-You can reach me and discuss on [Pildroid](mailto://jacques+pilldroid@foucry.net).
+You can reach me and discuss on [Pilldroid](mailto://jacques+pilldroid@foucry.net).
diff --git a/fastlane/metadata/android/en-US/full_description.txt b/fastlane/metadata/android/en-US/full_description.txt
index 59c2be4..ef3fa4b 100644
--- a/fastlane/metadata/android/en-US/full_description.txt
+++ b/fastlane/metadata/android/en-US/full_description.txt
@@ -1,8 +1,12 @@
+<<<<<<< HEAD
Pilldroid is a theorical medics manager. It for French people
only.
Why for french people only?
Pilldroid use a medics databases that come from French governement website, with
+Pilldroid is a theoretical medics manager. It for French people
+only.
+
medics which are refund by french health care national insurance (Sécurité
Sociale).