From 51f29639b8787158012e0bc77bfcc09c4764b399 Mon Sep 17 00:00:00 2001
From: Hua Tao <1225674957@qq.com>
Date: Sat, 9 Apr 2022 19:40:52 +0800
Subject: [PATCH] tijoao
---
src/Logistics/.idea/misc.xml | 3 +-
src/Logistics/app/build.gradle | 1 +
.../app/src/main/AndroidManifest.xml | 7 +-
.../com/example/logistics/ui/MyFragment2.java | 73 ++++++++++++++++++-
.../app/src/main/res/layout/my_fragment2.xml | 22 ++++--
.../app/src/main/res/layout/pickup.xml | 37 ++++++++++
6 files changed, 135 insertions(+), 8 deletions(-)
create mode 100644 src/Logistics/app/src/main/res/layout/pickup.xml
diff --git a/src/Logistics/.idea/misc.xml b/src/Logistics/.idea/misc.xml
index 5799ea6..6b89b6d 100644
--- a/src/Logistics/.idea/misc.xml
+++ b/src/Logistics/.idea/misc.xml
@@ -22,9 +22,10 @@
-
+
+
diff --git a/src/Logistics/app/build.gradle b/src/Logistics/app/build.gradle
index 6bf05e2..99fe4bb 100644
--- a/src/Logistics/app/build.gradle
+++ b/src/Logistics/app/build.gradle
@@ -29,6 +29,7 @@ android {
dependencies {
+ implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
diff --git a/src/Logistics/app/src/main/AndroidManifest.xml b/src/Logistics/app/src/main/AndroidManifest.xml
index 414e4cc..b536cf6 100644
--- a/src/Logistics/app/src/main/AndroidManifest.xml
+++ b/src/Logistics/app/src/main/AndroidManifest.xml
@@ -1,6 +1,7 @@
+ package="com.example.logistics"
+ xmlns:tools="http://schemas.android.com/tools">
@@ -24,6 +25,10 @@
+
\ No newline at end of file
diff --git a/src/Logistics/app/src/main/java/com/example/logistics/ui/MyFragment2.java b/src/Logistics/app/src/main/java/com/example/logistics/ui/MyFragment2.java
index aa5ad5b..1d44a94 100644
--- a/src/Logistics/app/src/main/java/com/example/logistics/ui/MyFragment2.java
+++ b/src/Logistics/app/src/main/java/com/example/logistics/ui/MyFragment2.java
@@ -1,19 +1,31 @@
package com.example.logistics.ui;
import androidx.fragment.app.Fragment;
+
+import android.annotation.SuppressLint;
+import android.app.AlertDialog;
import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.EditText;
import android.widget.TextView;
+import android.widget.Toast;
import androidx.annotation.Nullable;
import com.example.logistics.R;
+import com.google.zxing.integration.android.IntentIntegrator;
+import com.google.zxing.integration.android.IntentResult;
+import com.journeyapps.barcodescanner.CaptureActivity;
public class MyFragment2 extends Fragment implements View.OnClickListener{
+
+ private Button mButton;
+ private Context mContext;
public MyFragment2(){
}
@@ -22,13 +34,72 @@ public class MyFragment2 extends Fragment implements View.OnClickListener{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.my_fragment2,container,false);
-
+ mButton = (Button)view.findViewById(R.id.Pick_Button);
+ mButton.setOnClickListener(this);
return view;
}
@Override
public void onClick(View view) {
+ switch(view.getId()){
+ case R.id.Pick_Button:
+ new IntentIntegrator(getActivity())
+ .setDesiredBarcodeFormats(IntentIntegrator.QR_CODE)// 扫码的类型,一维码,二维码,一/二维码,默认为一/二维码
+ .setPrompt("请对准摄像头")
+ .setCameraId(0)
+ .setBeepEnabled(false)
+ .setCaptureActivity(CaptureActivity.class)
+ .initiateScan();
+
+ }
+ }
+
+
+
+
+ @Override
+ @SuppressLint("MissingSuperCall")
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
+ if(result != null) {
+ if(result.getContents() != null) {
+ //Toast.makeText(mContext, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
+ pickup(result.getContents());
+ }
+ }
+ }
+
+ public void pickup(String result){
+ AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
+
+ View view2 = View.inflate(mContext, R.layout.pickup, null);
+
+ EditText PickUpCode = (EditText) view2.findViewById(R.id.pk_PickUp);
+ EditText PhoneNum = (EditText) view2.findViewById(R.id.pk_PhoneNum);
+ Button button = (Button) view2.findViewById(R.id.pk_button);
+
+ builder.setTitle("取件").setView(view2);
+
+ builder.create().show();
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ String pickupcode = PickUpCode.getText().toString().trim();
+ String phonenum = PhoneNum.getText().toString().trim();
+
+ String QR_pickup = result.split(" ")[0];
+ String QR_phone = result.split(" ")[1];
+
+ if(pickupcode.equals(QR_pickup) && pickupcode.equals(QR_phone)){
+ Toast.makeText(mContext, "取件成功", Toast.LENGTH_LONG).show();
+
+ }else{
+ Toast.makeText(mContext, "取件失败", Toast.LENGTH_LONG).show();
+ }
+ }
+ });
}
+
}
diff --git a/src/Logistics/app/src/main/res/layout/my_fragment2.xml b/src/Logistics/app/src/main/res/layout/my_fragment2.xml
index c7d98f5..ff1a7a5 100644
--- a/src/Logistics/app/src/main/res/layout/my_fragment2.xml
+++ b/src/Logistics/app/src/main/res/layout/my_fragment2.xml
@@ -5,10 +5,22 @@
android:orientation="vertical"
android:padding="5dp">
-
+ android:layout_height="match_parent"
+ android:orientation="horizontal"
+ android:gravity="center">
+
+
+
+
\ No newline at end of file
diff --git a/src/Logistics/app/src/main/res/layout/pickup.xml b/src/Logistics/app/src/main/res/layout/pickup.xml
new file mode 100644
index 0000000..6a8c944
--- /dev/null
+++ b/src/Logistics/app/src/main/res/layout/pickup.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file