Some improvement after code Analysis

This commit is contained in:
jacques 2022-03-04 11:46:06 +01:00
parent 207179a5b1
commit 8fccb00f3a
13 changed files with 48 additions and 123 deletions

View file

@ -96,26 +96,24 @@ public class AlarmReceiver extends BroadcastReceiver {
String description = context.getString(R.string.channel_description); String description = context.getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_DEFAULT; int importance = NotificationManager.IMPORTANCE_DEFAULT;
String CHANNEL_ID = "PillDroid"; 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);
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); channel.setDescription(description);
channel.setDescription(description); channel.enableLights(true);
channel.enableLights(true); channel.setLightColor(R.color.led);
channel.setLightColor(R.color.led); channel.enableVibration(true);
channel.enableVibration(true); channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
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
// Register the channel with the system; you can't change the importance // or other notification behaviors after this
// or other notification behaviors after this NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
NotificationManager notificationManager = context.getSystemService(NotificationManager.class); try {
try { notificationManager.createNotificationChannel(channel);
notificationManager.createNotificationChannel(channel); } catch (Exception e) {
} catch (Exception e) { // This will catch any exception, because they are all descended from Exception
// This will catch any exception, because they are all descended from Exception Log.e(TAG, e.toString());
Log.e(TAG, e.toString()); //At the level Exception Class handle the error in Exception Table
//At the level Exception Class handle the error in Exception Table // Exception Create That Error Object and throw it
// Exception Create That Error Object and throw it //E.g: FileNotFoundException ,etc
//E.g: FileNotFoundException ,etc e.printStackTrace();
e.printStackTrace();
}
} }
} }
public static void scheduleAlarm(Context context) { public static void scheduleAlarm(Context context) {

View file

@ -12,7 +12,6 @@ import android.widget.ImageButton;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.google.zxing.client.android.Intents;
import com.journeyapps.barcodescanner.BarcodeCallback; import com.journeyapps.barcodescanner.BarcodeCallback;
import com.journeyapps.barcodescanner.BarcodeResult; import com.journeyapps.barcodescanner.BarcodeResult;
import com.journeyapps.barcodescanner.CaptureManager; import com.journeyapps.barcodescanner.CaptureManager;
@ -24,7 +23,7 @@ import java.util.Random;
/** /**
* Custom Scanner Activity extending from Activity to display a custom layout form scanner view. * Custom Scanner Activity extending from Activity to display a custom layout form scanner view.
*/ */
public class CustomScannerActivity extends Activity { public class CustomScannerActivity extends Activity implements DecoratedBarcodeView.TorchListener {
private static final String TAG = CustomScannerActivity.class.getName(); private static final String TAG = CustomScannerActivity.class.getName();
@ -33,7 +32,6 @@ public class CustomScannerActivity extends Activity {
private ImageButton switchFlashlightButton; private ImageButton switchFlashlightButton;
private ViewfinderView viewfinderView; private ViewfinderView viewfinderView;
final Intent captureIntent = new Intent();
final Bundle captureIntentBundle = new Bundle(); final Bundle captureIntentBundle = new Bundle();
@Override @Override
@ -41,9 +39,6 @@ public class CustomScannerActivity extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_scanner); setContentView(R.layout.activity_custom_scanner);
/* manualAddLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
result -> handleActivityResult(result.getResultCode(),
result.getData()));*/
//barcodeScannerView.setTorchListener(this); //barcodeScannerView.setTorchListener(this);
@ -61,22 +56,11 @@ public class CustomScannerActivity extends Activity {
findViewById(R.id.switch_flashlight).setVisibility(View.GONE); findViewById(R.id.switch_flashlight).setVisibility(View.GONE);
} }
captureIntentBundle.putBoolean(Intents.Scan.BEEP_ENABLED, true);
captureIntentBundle.putInt("Intents.Scan.MIXED_SCAN", Intents.Scan.MIXED_SCAN);
captureIntentBundle.putInt("Intents.Scan.INVERTED_SCAN", Intents.Scan.INVERTED_SCAN);
captureIntent.putExtras(captureIntentBundle);
/*captureIntent.putExtra("Intents.Scan.MIXED_SCAN", Intents.Scan.MIXED_SCAN);
captureIntent.putExtra("Intents.Scan.INVERTED_SCAN", Intents.Scan.INVERTED_SCAN);
captureIntent.putExtra("Intents.Scan.BEEP_ENABLED", Intents.Scan.BEEP_ENABLED);*/
capture = new CaptureManager(this, barcodeScannerView); capture = new CaptureManager(this, barcodeScannerView);
capture.initializeFromIntent(getIntent(), savedInstanceState); capture.initializeFromIntent(getIntent(), savedInstanceState);
capture.setShowMissingCameraPermissionDialog(false); capture.setShowMissingCameraPermissionDialog(false);
//capture.decode();
changeMaskColor(null); //changeMaskColor(null);
changeLaserVisibility(true); changeLaserVisibility(true);
barcodeScannerView.decodeSingle(new BarcodeCallback() { barcodeScannerView.decodeSingle(new BarcodeCallback() {
@Override @Override
@ -137,8 +121,10 @@ public class CustomScannerActivity extends Activity {
Log.d(TAG, "Switch torch"); Log.d(TAG, "Switch torch");
if (switchFlashlightButton.isActivated()) { if (switchFlashlightButton.isActivated()) {
barcodeScannerView.setTorchOff(); barcodeScannerView.setTorchOff();
switchFlashlightButton.setActivated(false);
} else { } else {
barcodeScannerView.setTorchOn(); barcodeScannerView.setTorchOn();
switchFlashlightButton.setActivated(true);
} }
} }
@ -183,27 +169,4 @@ public class CustomScannerActivity extends Activity {
finish(); finish();
} }
/*private void handleActivityResult(int resultCode, Intent intent) {
super.onActivityResult(Utils.SELECT_BARCODE_REQUEST, resultCode, intent);
BarcodeValues barcodeValues;
try {
barcodeValues = Utils.parseSetBarcodeActivityResult(Utils.SELECT_BARCODE_REQUEST, resultCode, intent, this);
} catch (NullPointerException e) {
Toast.makeText(this, "Error reading image", Toast.LENGTH_LONG).show();
return;
}
if (!barcodeValues.isEmpty()) {
Intent manualResult = new Intent();
Bundle manualResultBundle = new Bundle();
manualResultBundle.putString("BarcodeContent", barcodeValues.content());
manualResultBundle.putString("BarcodeFormat", barcodeValues.format());
manualResult.putExtras(manualResultBundle);
CustomScannerActivity.this.setResult(RESULT_OK, manualResult);
finish();
}
}*/
} }

View file

@ -109,9 +109,8 @@ class DBDrugs extends SQLiteOpenHelper {
@Override @Override
public synchronized void close() { public synchronized void close() {
if (myDataBase != null) { assert false;
myDataBase.close(); myDataBase.close();
}
} }
/** /**

View file

@ -276,9 +276,6 @@ class DBHelper extends SQLiteOpenHelper {
Log.d(TAG, "Before sort == " + drugs); Log.d(TAG, "Before sort == " + drugs);
/*drugs.sort(Comparator.comparing(Drug::getDateEndOfStock)
.thenComparing(Drug::getStock));*/
drugs.sort(new Comparator<Drug>() { drugs.sort(new Comparator<Drug>() {
@Override @Override
public int compare(Drug lhs, Drug rhs) { public int compare(Drug lhs, Drug rhs) {

View file

@ -88,7 +88,7 @@ public class PillDroidJobService extends JobService {
Log.d(TAG, "schedule notification"); Log.d(TAG, "schedule notification");
createNotificationChannel(); createNotificationChannel();
Intent intent = new Intent(this, DrugListActivity.class); 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") NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "PillDroid")
.setSmallIcon(R.drawable.ic_pill_alarm) .setSmallIcon(R.drawable.ic_pill_alarm)
.setContentTitle(getString(R.string.app_name)) .setContentTitle(getString(R.string.app_name))
@ -113,23 +113,21 @@ public class PillDroidJobService extends JobService {
int importance = NotificationManager.IMPORTANCE_DEFAULT; int importance = NotificationManager.IMPORTANCE_DEFAULT;
String CHANNEL_ID = "PillDroid"; String CHANNEL_ID = "PillDroid";
NotificationChannel channel; 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); channel.setDescription(description);
// Register the channel with the system; you can't change the importance // Register the channel with the system; you can't change the importance
// or other notification behaviors after this // or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class); NotificationManager notificationManager = getSystemService(NotificationManager.class);
try { try {
notificationManager.createNotificationChannel(channel); notificationManager.createNotificationChannel(channel);
} catch (Exception e) { } catch (Exception e) {
// This will catch any exception, because they are all descended from Exception // This will catch any exception, because they are all descended from Exception
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
//At the level Exception Class handle the error in Exception Table //At the level Exception Class handle the error in Exception Table
// Exception Create That Error Object and throw it // Exception Create That Error Object and throw it
//E.g: FileNotFoundException ,etc //E.g: FileNotFoundException ,etc
e.printStackTrace(); e.printStackTrace();
}
} }
} }
} }

View file

@ -45,34 +45,4 @@ public class Utils {
Random r = new Random(); Random r = new Random();
return r.nextInt(max - min) +max; return r.nextInt(max - min) +max;
} }
/**
* parse barcode result into barcodevalues
* @param requestCode int
* @param resultCode int
* @param intent Intent
* @param context Context
* @return BarcodeValues
*/
static public BarcodeValues parseSetBarcodeActivityResult(int requestCode, int resultCode,
Intent intent, Context context) {
String contents = null;
String format = null;
if (resultCode != Activity.RESULT_OK) {
return new BarcodeValues(null, null);
}
if (requestCode == Utils.BARCODE_SCAN || requestCode == Utils.SELECT_BARCODE_REQUEST) {
if (requestCode == Utils.BARCODE_SCAN) {
Log.d(TAG, "Received barcode information form camera");
} else if (requestCode == Utils.SELECT_BARCODE_REQUEST) {
Log.d(TAG, "Received barcode information form typeing it");
}
contents = intent.getStringExtra("BarcodeContent");
format = intent.getStringExtra("BarcodeFormat");
}
return new BarcodeValues(format, contents);
}
} }

View file

@ -217,7 +217,7 @@ public class WelcomeActivity extends AppCompatActivity {
} }
@Override @Override
public boolean isViewFromObject(@NonNull View view, Object obj) { public boolean isViewFromObject(@NonNull View view, @NonNull Object obj) {
return view == obj; return view == obj;
} }

View file

@ -17,8 +17,7 @@
--> -->
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.recyclerview.widget.RecyclerView
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drug_list" android:id="@+id/drug_list"
android:name="net.foucry.pilldroid.MedicamentListFragment" android:name="net.foucry.pilldroid.MedicamentListFragment"
android:layout_width="@dimen/item_width" android:layout_width="@dimen/item_width"

View file

@ -20,7 +20,7 @@
app:zxing_result_view="@color/zxing_custom_result_view" app:zxing_result_view="@color/zxing_custom_result_view"
app:zxing_viewfinder_laser="@color/zxing_custom_viewfinder_laser" app:zxing_viewfinder_laser="@color/zxing_custom_viewfinder_laser"
app:zxing_viewfinder_laser_visibility="true" app:zxing_viewfinder_laser_visibility="true"
app:zxing_viewfinder_mask="@color/zxing_custom_viewfinder_mask" /> app:zxing_viewfinder_mask="@color/grey"/>
<TextView <TextView
android:id="@+id/zxing_status_view" android:id="@+id/zxing_status_view"
@ -33,7 +33,7 @@
android:textSize="32sp" android:textSize="32sp"
android:textAlignment="center" android:textAlignment="center"
android:text="@string/zxing_msg_default_status" android:text="@string/zxing_msg_default_status"
android:textColor="@color/design_default_color_primary_dark" android:textColor="@color/white"
tools:ignore="PrivateResource" /> tools:ignore="PrivateResource" />
<ImageButton <ImageButton

View file

View file

@ -3,6 +3,7 @@
<color name="colorPrimary">#3F51B5</color> <color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color> <color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color> <color name="colorAccent">#FF4081</color>
<color name="white">#FFFFFF</color>
<!-- slide bg --> <!-- slide bg -->
<color name="bg_screen1">#4f91ff</color> <color name="bg_screen1">#4f91ff</color>

View file

@ -1,6 +1,6 @@
# beta-0.100 First public release # beta-0.100 First public release
**REMENBER** Pilldroid is a French people user only. **REMEMBER** Pilldroid is a French people user only.
I made a lot a tests but there must stay some bugs. I made a lot a tests but there must stay some bugs.
@ -23,4 +23,4 @@ do not stress me it will be unproductive.
Pilldroid will available only from [f-droid](https://f-droid.org) 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).

View file

@ -1,8 +1,8 @@
<strong>Pilldroid</strong> is a theorical medics manager. It for French people <strong>Pilldroid</strong> is a theoretical medics manager. It for French people
only. only.
<strong>Why for french people only?</strong> <strong>Why for french people only?</strong>
<p>Pilldroid use a medics databases that come from French governement website, with <p>Pilldroid use a medics databases that come from French government website, with
medics which are refund by french health care national insurance (Sécurité medics which are refund by french health care national insurance (Sécurité
Sociale).</p> Sociale).</p>