mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
Change Text by a imageButton
This commit is contained in:
parent
9eb5d9f64a
commit
dbed48c3da
12 changed files with 99 additions and 152 deletions
|
@ -1,14 +1,12 @@
|
|||
package net.foucry.pilldroid;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -27,23 +25,17 @@ public class CustomScannerActivity extends Activity implements
|
|||
|
||||
private CaptureManager capture;
|
||||
private DecoratedBarcodeView barcodeScannerView;
|
||||
private Button switchFlashlightButton;
|
||||
private ImageButton switchFlashlightButton;
|
||||
private ViewfinderView viewfinderView;
|
||||
|
||||
private static final String TAG = MedicamentListActivity.class.getName();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_custom_scanner);
|
||||
|
||||
final Context context = this;
|
||||
barcodeScannerView = findViewById(R.id.zxing_barcode_scanner);
|
||||
barcodeScannerView.setTorchListener(this);
|
||||
|
||||
ImageButton cancelButton = findViewById(R.id.cancel_button);
|
||||
ImageButton keyboardButton = findViewById(R.id.keyboard_button);
|
||||
|
||||
switchFlashlightButton = findViewById(R.id.switch_flashlight);
|
||||
|
||||
viewfinderView = findViewById(R.id.zxing_viewfinder_view);
|
||||
|
@ -102,10 +94,10 @@ public class CustomScannerActivity extends Activity implements
|
|||
}
|
||||
|
||||
public void switchFlashlight(View view) {
|
||||
if (getString(R.string.turn_on_flashlight).contentEquals(switchFlashlightButton.getText())) {
|
||||
barcodeScannerView.setTorchOn();
|
||||
} else {
|
||||
if (switchFlashlightButton.isActivated()) {
|
||||
barcodeScannerView.setTorchOff();
|
||||
} else {
|
||||
barcodeScannerView.setTorchOn();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,12 +113,12 @@ public class CustomScannerActivity extends Activity implements
|
|||
|
||||
@Override
|
||||
public void onTorchOn() {
|
||||
switchFlashlightButton.setText(R.string.turn_off_flashlight);
|
||||
switchFlashlightButton.setActivated(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTorchOff() {
|
||||
switchFlashlightButton.setText(R.string.turn_on_flashlight);
|
||||
switchFlashlightButton.setActivated(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.database.Cursor;
|
|||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -19,7 +18,8 @@ import java.util.List;
|
|||
class DBHelper extends SQLiteOpenHelper {
|
||||
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
private static String DATABASE_NAME = "ordonnance.db";
|
||||
@SuppressWarnings("CanBeFinal")
|
||||
private static final ThreadLocal<String> DATABASE_NAME = ThreadLocal.withInitial(() -> "ordonnance.db");
|
||||
|
||||
private static final String TABLE_DRUG = "drug";
|
||||
private static final String KEY_ID = "id";
|
||||
|
@ -48,7 +48,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
DBHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
super(context, DATABASE_NAME.get(), null, DATABASE_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -119,19 +119,19 @@ public class MedicamentDetailActivity extends AppCompatActivity {
|
|||
View warningView;
|
||||
View alertView;
|
||||
|
||||
stockView = (View) findViewById(R.id.stock_cell);
|
||||
stockView = findViewById(R.id.stock_cell);
|
||||
EditText stockTextView = stockView.findViewById(R.id.valeur);
|
||||
String stockValue = stockTextView.getText().toString();
|
||||
|
||||
priseView = (View) findViewById(R.id.prise_cell);
|
||||
priseView = findViewById(R.id.prise_cell);
|
||||
TextView priseTextView = priseView.findViewById(R.id.valeur);
|
||||
String priseValue = priseTextView.getText().toString();
|
||||
|
||||
alertView = (View) findViewById(R.id.alert_cell);
|
||||
alertView = findViewById(R.id.alert_cell);
|
||||
TextView alertTextView = alertView.findViewById(R.id.valeur);
|
||||
String alertValue = alertTextView.getText().toString();
|
||||
|
||||
warningView = (View) findViewById(R.id.warning_cell);
|
||||
warningView = findViewById(R.id.warning_cell);
|
||||
TextView warningTextView = warningView.findViewById(R.id.valeur);
|
||||
String warningValue = warningTextView.getText().toString();
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.app.Notification;
|
|||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
@ -291,11 +290,12 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
if (result.getContents() == null) {
|
||||
Intent originalIntent = result.getOriginalIntent();
|
||||
if (originalIntent == null) {
|
||||
if (resultCode == 3) { // TODO: Should call showInputDialog and have keyboardInput back
|
||||
if (resultCode == 3) {
|
||||
Toast.makeText(this, "Keyboard input", Toast.LENGTH_SHORT).show();
|
||||
Log.d(TAG, "Keyboard Input");
|
||||
showInputDialog();
|
||||
} else {
|
||||
Log.d(TAG, "Cancelled scan"); // Todo: put here resultCode =3 test
|
||||
Log.d(TAG, "Cancelled scan");
|
||||
Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
|
||||
}
|
||||
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
|
||||
|
@ -314,9 +314,6 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
|
||||
String cip13;
|
||||
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
|
||||
dlg.setTitle(getString(R.string.app_name));
|
||||
|
||||
// Handle successful scan
|
||||
if (result.getFormatName().equals("CODE_128")) { //CODE_128
|
||||
cip13 = result.getContents();
|
||||
|
@ -326,37 +323,12 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
|
||||
// Get Medoc from database
|
||||
final Medicament scannedMedoc = dbMedoc.getMedocByCIP13(cip13);
|
||||
|
||||
if (scannedMedoc != null) {
|
||||
String msg = scannedMedoc.getNom() + " " + getString(R.string.msgFound);
|
||||
|
||||
dlg.setMessage(msg);
|
||||
dlg.setNegativeButton(getString(R.string.button_cancel), (DialogInterface.OnClickListener) (dialog, which) -> {
|
||||
// Nothing to do in case of cancel
|
||||
});
|
||||
dlg.setPositiveButton(getString(R.string.button_ok), (dialog, which) -> {
|
||||
// Add Medicament to DB then try to show it
|
||||
scannedMedoc.setDateEndOfStock();
|
||||
dbHelper.addDrug(scannedMedoc);
|
||||
mAdapter.addItem(scannedMedoc);
|
||||
});
|
||||
dlg.show();
|
||||
} else {
|
||||
dlg.setMessage(getString(R.string.msgNotFound));
|
||||
dlg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// nothing to do to just dismiss dialog
|
||||
}
|
||||
});
|
||||
dlg.show();
|
||||
}
|
||||
askToAddInDB(scannedMedoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void showInputDialog() {
|
||||
|
||||
// get prompts.xml view
|
||||
LayoutInflater layoutInflater = LayoutInflater.from(MedicamentListActivity.this);
|
||||
View promptView = layoutInflater.inflate(R.layout.input_dialog, null);
|
||||
|
@ -366,23 +338,51 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
final EditText editText = promptView.findViewById(R.id.edittext);
|
||||
// setup a dialog window
|
||||
alertDialogBuilder.setCancelable(false)
|
||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
editText.getText();
|
||||
}
|
||||
.setPositiveButton("OK", (dialog, id) -> {
|
||||
String cip13 = editText.getText().toString();
|
||||
Medicament med = dbMedoc.getMedocByCIP13(cip13);
|
||||
askToAddInDB(med);
|
||||
addMedToList(med);
|
||||
})
|
||||
.setNegativeButton("Cancel",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
(dialog, id) -> dialog.cancel());
|
||||
|
||||
// create an alert dialog
|
||||
AlertDialog alert = alertDialogBuilder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
private void askToAddInDB(Medicament med) {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
|
||||
dlg.setTitle(getString(R.string.app_name));
|
||||
|
||||
if (med != null) {
|
||||
String msg = med.getNom() + " " + getString(R.string.msgFound);
|
||||
|
||||
dlg.setMessage(msg);
|
||||
dlg.setNegativeButton(getString(R.string.button_cancel), (dialog, which) -> {
|
||||
// Nothing to do in case of cancel
|
||||
});
|
||||
dlg.setPositiveButton(getString(R.string.button_ok), (dialog, which) -> {
|
||||
// Add Medicament to DB then try to show it
|
||||
addMedToList(med);
|
||||
});
|
||||
} else {
|
||||
dlg.setMessage(getString(R.string.msgNotFound));
|
||||
dlg.setPositiveButton("OK", (dialog, which) -> {
|
||||
// nothing to do to just dismiss dialog
|
||||
});
|
||||
}
|
||||
dlg.show();
|
||||
}
|
||||
|
||||
private void addMedToList(Medicament med)
|
||||
{
|
||||
med.setDateEndOfStock();
|
||||
dbHelper.addDrug(med);
|
||||
mAdapter.addItem(med);
|
||||
}
|
||||
|
||||
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext()));
|
||||
mAdapter = new SimpleItemRecyclerViewAdapter(medicaments);
|
||||
|
@ -439,7 +439,7 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
void addItem(Medicament scannedMedoc) {
|
||||
if (!dbHelper.isMedicamentExist(scannedMedoc.getCip13().toString())) {
|
||||
if (!dbHelper.isMedicamentExist(scannedMedoc.getCip13())) {
|
||||
mValues.add(scannedMedoc);
|
||||
notifyDataSetChanged();
|
||||
dbHelper.addDrug(scannedMedoc);
|
||||
|
@ -448,6 +448,7 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
|
@ -542,71 +543,4 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
Context context = getApplicationContext();
|
||||
String cip13;
|
||||
if (requestCode == 0) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
String contents = intent.getStringExtra("SCAN_RESULT");
|
||||
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
|
||||
Log.i(TAG, "Format:" + format);
|
||||
Log.i(TAG, "Content:" + contents);
|
||||
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
|
||||
dlg.setTitle(context.getString(R.string.app_name));
|
||||
|
||||
// Handle successful scan
|
||||
assert format != null;
|
||||
if (format.equals("CODE_128")) { //CODE_128
|
||||
cip13 = contents;
|
||||
} else {
|
||||
assert contents != null;
|
||||
cip13 = contents.substring(4, 17);
|
||||
}
|
||||
|
||||
dbMedoc.openDatabase();
|
||||
final Medicament scannedMedoc = dbMedoc.getMedocByCIP13(cip13);
|
||||
dbMedoc.close();
|
||||
|
||||
if (scannedMedoc != null) {
|
||||
String msg = scannedMedoc.getNom() + " " + getString(R.string.msgFound);
|
||||
|
||||
dlg.setMessage(msg);
|
||||
dlg.setNegativeButton(context.getString(R.string.button_cancel), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Nothing to do in case of cancel
|
||||
}
|
||||
});
|
||||
dlg.setPositiveButton(context.getString(R.string.button_ok), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Add Medicament to DB then try to show it
|
||||
scannedMedoc.setDateEndOfStock();
|
||||
dbHelper.addDrug(scannedMedoc);
|
||||
mAdapter.addItem(scannedMedoc);
|
||||
}
|
||||
});
|
||||
dlg.show();
|
||||
} else {
|
||||
dlg.setMessage(context.getString(R.string.msgNotFound));
|
||||
dlg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// nothing to do to just dismiss dialog
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (resultCode == RESULT_CANCELED) {
|
||||
// Handle cancel
|
||||
Toast.makeText(context, "Scan annulé", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else if (requestCode == 1){
|
||||
Toast.makeText(context, "back from detail", Toast.LENGTH_SHORT).show();
|
||||
constructMedsList();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -29,7 +29,7 @@ public class Utils {
|
|||
* @param max maximum value accepted
|
||||
* @return
|
||||
*/
|
||||
static final int intRandomExclusive(int min, int max) {
|
||||
static int intRandomExclusive(int min, int max) {
|
||||
Random r = new Random();
|
||||
return r.nextInt(max - min) +max;
|
||||
}
|
||||
|
|
9
app/src/main/res/drawable/ic_baseline_highlight_24.xml
Normal file
9
app/src/main/res/drawable/ic_baseline_highlight_24.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="64dp"
|
||||
android:height="64dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/black"
|
||||
android:pathData="M6,14l3,3v5h6v-5l3,-3V9H6V14zM11,2h2v3h-2V2zM3.5,5.88l1.41,-1.41l2.12,2.12L5.62,8L3.5,5.88zM16.96,6.59l2.12,-2.12l1.41,1.41L18.38,8L16.96,6.59z"/>
|
||||
</vector>
|
|
@ -1,6 +1,6 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="85dp"
|
||||
android:height="85dp"
|
||||
android:width="64dp"
|
||||
android:height="64dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
<vector android:height="100dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="100dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M20,5L4,5c-1.1,0 -1.99,0.9 -1.99,2L2,17c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,7c0,-1.1 -0.9,-2 -2,-2zM11,8h2v2h-2L11,8zM11,11h2v2h-2v-2zM8,8h2v2L8,10L8,8zM8,11h2v2L8,13v-2zM7,13L5,13v-2h2v2zM7,10L5,10L5,8h2v2zM16,17L8,17v-2h8v2zM16,13h-2v-2h2v2zM16,10h-2L14,8h2v2zM19,13h-2v-2h2v2zM19,10h-2L17,8h2v2z"/>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="64dp"
|
||||
android:height="64dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M20,5L4,5c-1.1,0 -1.99,0.9 -1.99,2L2,17c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,7c0,-1.1 -0.9,-2 -2,-2zM11,8h2v2h-2L11,8zM11,11h2v2h-2v-2zM8,8h2v2L8,10L8,8zM8,11h2v2L8,13v-2zM7,13L5,13v-2h2v2zM7,10L5,10L5,8h2v2zM16,17L8,17v-2h8v2zM16,13h-2v-2h2v2zM16,10h-2L14,8h2v2zM19,13h-2v-2h2v2zM19,10h-2L17,8h2v2z" />
|
||||
</vector>
|
||||
|
|
|
@ -11,15 +11,20 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:zxing_scanner_layout="@layout/custom_barcode_scanner">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/switch_flashlight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal|bottom"
|
||||
android:layout_marginStart="@dimen/fab_margin"
|
||||
android:layout_marginTop="@dimen/fab_margin"
|
||||
android:layout_marginEnd="@dimen/fab_margin"
|
||||
android:layout_marginBottom="@dimen/fab_margin"
|
||||
android:backgroundTint="@android:color/transparent"
|
||||
android:contentDescription="@string/flashlighButton"
|
||||
android:onClick="switchFlashlight"
|
||||
android:src="@drawable/ic_baseline_highlight_24" />
|
||||
</com.journeyapps.barcodescanner.DecoratedBarcodeView>
|
||||
|
||||
<Button
|
||||
android:id="@+id/switch_flashlight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/turn_on_flashlight"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:onClick="switchFlashlight"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -13,8 +13,8 @@
|
|||
|
||||
<com.journeyapps.barcodescanner.ViewfinderView
|
||||
android:id="@+id/zxing_viewfinder_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
app:zxing_possible_result_points="@color/zxing_custom_possible_result_points"
|
||||
app:zxing_result_view="@color/zxing_custom_result_view"
|
||||
|
@ -35,8 +35,8 @@
|
|||
|
||||
<ImageButton
|
||||
android:id="@+id/cancel_button"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|start"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:accessibilityHeading="true"
|
||||
|
@ -50,8 +50,8 @@
|
|||
|
||||
<ImageButton
|
||||
android:id="@+id/keyboard_button"
|
||||
android:layout_width="86dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:backgroundTint="@android:color/transparent"
|
||||
|
|
|
@ -22,4 +22,5 @@
|
|||
<string name="detail_view">Vue de détail</string>
|
||||
<string name="scan_action">Scanner un code barre de médicament</string>
|
||||
<string name="save_button">Save</string>
|
||||
<string name="flashlighButton">Toggle Flash</string>
|
||||
</resources>
|
|
@ -22,4 +22,5 @@
|
|||
<string name="scan_action">Scan a drug barcode</string>
|
||||
<string name="save_button">Save</string>
|
||||
<string name="input_cip13">Input Cip13 with the keyboard</string>
|
||||
<string name="flashlighButton">Toggle Flash</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue