94 lines
3.1 KiB
Java
94 lines
3.1 KiB
Java
package monnethic.mobile.qrcode;
|
|
|
|
import android.content.Intent;
|
|
import android.graphics.Bitmap;
|
|
import android.os.AsyncTask;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
import com.example.monnthic.monnethicmobile.R;
|
|
import com.google.zxing.BarcodeFormat;
|
|
import com.google.zxing.MultiFormatWriter;
|
|
import com.google.zxing.WriterException;
|
|
import com.google.zxing.common.BitMatrix;
|
|
import com.journeyapps.barcodescanner.BarcodeEncoder;
|
|
import monnethic.mobile.restApi.SessionApiHandler;
|
|
|
|
|
|
public class QrCodeActivity extends AppCompatActivity {
|
|
ImageView qrCode;
|
|
Button closeButton;
|
|
TextView adresseView;
|
|
TextView amountView;
|
|
|
|
private String user_hash;
|
|
private String user_password;
|
|
private String session_id;
|
|
private String wallet_hash;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_qr_code);
|
|
qrCode=findViewById(R.id.qrCodeViewer);
|
|
closeButton=findViewById(R.id.buttonClose);
|
|
adresseView=findViewById(R.id.textViewAdresseDisplay);
|
|
amountView=findViewById(R.id.textViewAmountDisplay);
|
|
|
|
Intent intent = getIntent();
|
|
user_hash = intent.getStringExtra("USER_HASH");
|
|
user_password = intent.getStringExtra("USER_PWD");
|
|
session_id = intent.getStringExtra("SESSION_ID");
|
|
wallet_hash = intent.getStringExtra("WALLET_HASH");
|
|
String amount = intent.getStringExtra("AMOUNT");
|
|
try{
|
|
generateQrCode(wallet_hash,amount);
|
|
}catch(Exception e){
|
|
e.getMessage();
|
|
}
|
|
closeButton.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
finish();
|
|
}
|
|
});
|
|
}
|
|
|
|
private void generateQrCode(String wallet_hash, String amount) throws WriterException {
|
|
BitMatrix bitMatrix;
|
|
String valueToEncode = wallet_hash+";"+amount;
|
|
try{
|
|
bitMatrix = new MultiFormatWriter().encode(valueToEncode, BarcodeFormat.QR_CODE,300,300);
|
|
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
|
|
Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
|
|
qrCode.setImageBitmap(bitmap);
|
|
adresseView.setText(wallet_hash);
|
|
amountView.setText(amount);
|
|
}catch (Exception e){
|
|
e.getMessage();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onStop() {
|
|
super.onStop(); // Always call the superclass method first
|
|
new EndSessionTask().execute(session_id);
|
|
}
|
|
|
|
private class EndSessionTask extends AsyncTask<String,Void,Void> {
|
|
@Override
|
|
protected Void doInBackground(String... strings) {
|
|
try{
|
|
SessionApiHandler sessionApiHandler = new SessionApiHandler();
|
|
sessionApiHandler.endSession(strings[0]);
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|