mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
Change to scan part
This commit is contained in:
parent
b21e6c58d3
commit
0eadeb9158
5 changed files with 78 additions and 21 deletions
|
@ -36,7 +36,7 @@
|
|||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="net.foucry.pilldroid.MedicamentListActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
<!-- <activity
|
||||
android:name="com.google.zxing.client.android.CaptureActivity"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:screenOrientation="landscape"
|
||||
|
@ -52,7 +52,7 @@
|
|||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</activity>-->
|
||||
<activity
|
||||
android:name=".About"
|
||||
android:label="À propos de PillDroid"
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.zxing.client.android.Intents;
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
|
@ -64,6 +65,7 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
final Boolean DEMO = true;
|
||||
final Boolean DBDEMO = true;
|
||||
final static Random random = new Random();
|
||||
public final int CUSTOMIZED_REQUEST_CODE = 0x0000ffff;
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
|
@ -237,20 +239,21 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
public void scanNow(View view) {
|
||||
// new IntentIntegrator(this).initiateScan(); Simpliest way
|
||||
|
||||
IntentIntegrator integrator = new IntentIntegrator(this);
|
||||
/* IntentIntegrator integrator = new IntentIntegrator(this);
|
||||
integrator.setDesiredBarcodeFormats(IntentIntegrator.CODE_128, IntentIntegrator.DATA_MATRIX);
|
||||
integrator.setPrompt("Scanner un Médicament");
|
||||
integrator.setCameraId(0); // Use a specific camera of the device
|
||||
integrator.setBeepEnabled(true);
|
||||
integrator.setBarcodeImageEnabled(false);
|
||||
integrator.initiateScan();
|
||||
integrator.initiateScan();*/
|
||||
|
||||
new IntentIntegrator(this).setOrientationLocked(false).setCaptureActivity(scanActivity.class).initiateScan();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculation of newStock
|
||||
*/
|
||||
public void newStockCalculation() {
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Date now = calendar.getTime();
|
||||
|
||||
|
@ -273,18 +276,36 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule));
|
||||
}
|
||||
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
Context context = getApplicationContext();
|
||||
|
||||
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (result !=null ) {
|
||||
if (result.getContents() == null) {
|
||||
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
|
||||
@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;
|
||||
}
|
||||
switch (requestCode) {
|
||||
case CUSTOMIZED_REQUEST_CODE: {
|
||||
Toast.makeText(this, "REQUEST_CODE = " + requestCode, Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data);
|
||||
|
||||
if(result.getContents() == null) {
|
||||
Intent originalIntent = result.getOriginalIntent();
|
||||
if (originalIntent == null) {
|
||||
Log.d(TAG, "Cancelled scan");
|
||||
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");
|
||||
Toast.makeText(this, "Cancelled due to missing camera permission", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Scanned");
|
||||
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,17 +40,20 @@ public class scanActivity extends Activity {
|
|||
private DecoratedBarcodeView barcodeScannerView;
|
||||
private ImageButton keyboardButton;
|
||||
private ImageButton cancelButton;
|
||||
//private Button switchFlashlightButton;
|
||||
private ViewfinderView viewfinderView;
|
||||
|
||||
@SuppressLint("WrongViewCast")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_scan);
|
||||
|
||||
barcodeScannerView = findViewById(R.id.zxing_barcode_scanner);
|
||||
// barcodeScannerView.setTorchListener(this);
|
||||
//barcodeScannerView = findViewById(R.id.custom_barcode_scanner);
|
||||
//barcodeScannerView.setTorchListener((DecoratedBarcodeView.TorchListener) this);
|
||||
|
||||
// switchFlashlightButton = findViewById(R.id.switch_flashlight);
|
||||
//switchFlashlightButton = findViewById(R.id.switch_flashlight);
|
||||
|
||||
keyboardButton = findViewById(R.id.keyboard);
|
||||
cancelButton = findViewById(R.id.cancel);
|
||||
|
@ -59,9 +62,9 @@ public class scanActivity extends Activity {
|
|||
|
||||
// if the device does not have flashlight in its camera,
|
||||
// then remove the switch flashlight button...
|
||||
// if (!hasFlash()) {
|
||||
// switchFlashlightButton.setVisibility(View.GONE);
|
||||
// }
|
||||
/* if (!hasFlash()) {
|
||||
switchFlashlightButton.setVisibility(View.GONE);
|
||||
}*/
|
||||
|
||||
capture = new CaptureManager(this, barcodeScannerView);
|
||||
capture.initializeFromIntent(getIntent(), savedInstanceState);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
app:srcCompat="@drawable/ic_reticule_rouge"
|
||||
/>
|
||||
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/keyboard"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
32
app/src/main/res/layout/custom_barcode_scanner.xml
Normal file
32
app/src/main/res/layout/custom_barcode_scanner.xml
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<com.journeyapps.barcodescanner.BarcodeView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/zxing_barcode_surface"
|
||||
app:zxing_framing_rect_width="250dp"
|
||||
app:zxing_framing_rect_height="50dp"/>
|
||||
|
||||
<com.journeyapps.barcodescanner.ViewfinderView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/zxing_viewfinder_view"
|
||||
app:zxing_possible_result_points="@color/zxing_custom_possible_result_points"
|
||||
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"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/zxing_status_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:background="@color/zxing_transparent"
|
||||
android:text="@string/zxing_msg_default_status"
|
||||
android:textColor="@color/zxing_status_text"/>
|
||||
|
||||
</merge>
|
Loading…
Reference in a new issue