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"> + +