2016-08-15 22:31:28 +02:00
|
|
|
package me.impy.aegis;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2016-08-17 01:35:19 +02:00
|
|
|
import android.content.Context;
|
2016-08-16 00:08:01 +02:00
|
|
|
import android.content.Intent;
|
2016-08-15 22:31:28 +02:00
|
|
|
import android.os.Bundle;
|
2016-08-15 22:35:42 +02:00
|
|
|
import android.widget.Toast;
|
2016-08-15 22:31:28 +02:00
|
|
|
|
2016-08-15 22:45:33 +02:00
|
|
|
import com.google.zxing.BarcodeFormat;
|
2016-08-15 22:31:28 +02:00
|
|
|
import com.google.zxing.Result;
|
|
|
|
|
2017-08-26 21:15:53 +02:00
|
|
|
import java.util.Collections;
|
2016-08-15 22:45:33 +02:00
|
|
|
|
2016-08-17 01:35:19 +02:00
|
|
|
import me.dm7.barcodescanner.core.IViewFinder;
|
2016-08-15 22:31:28 +02:00
|
|
|
import me.dm7.barcodescanner.zxing.ZXingScannerView;
|
2016-08-15 23:31:26 +02:00
|
|
|
import me.impy.aegis.crypto.KeyInfo;
|
2017-08-26 21:15:53 +02:00
|
|
|
import me.impy.aegis.db.DatabaseEntry;
|
2016-08-17 01:35:19 +02:00
|
|
|
import me.impy.aegis.helpers.SquareFinderView;
|
2016-08-15 22:31:28 +02:00
|
|
|
|
2017-12-24 21:42:08 +01:00
|
|
|
public class ScannerActivity extends AegisActivity implements ZXingScannerView.ResultHandler {
|
2017-08-26 21:15:53 +02:00
|
|
|
private ZXingScannerView _scannerView;
|
2016-08-15 22:31:28 +02:00
|
|
|
|
|
|
|
@Override
|
2017-12-24 21:42:08 +01:00
|
|
|
protected void onCreate(Bundle state) {
|
2016-08-15 22:31:28 +02:00
|
|
|
super.onCreate(state);
|
2016-08-17 01:35:19 +02:00
|
|
|
|
2017-08-26 21:15:53 +02:00
|
|
|
_scannerView = new ZXingScannerView(this) {
|
2016-08-17 01:35:19 +02:00
|
|
|
@Override
|
|
|
|
protected IViewFinder createViewFinderView(Context context) {
|
|
|
|
return new SquareFinderView(context);
|
|
|
|
}
|
|
|
|
};
|
2017-12-24 22:06:27 +01:00
|
|
|
_scannerView.setResultHandler(this);
|
2017-08-26 21:15:53 +02:00
|
|
|
_scannerView.setFormats(Collections.singletonList(BarcodeFormat.QR_CODE));
|
2017-12-24 22:06:27 +01:00
|
|
|
_scannerView.startCamera();
|
|
|
|
|
2017-12-24 21:47:05 +01:00
|
|
|
setContentView(_scannerView);
|
2016-08-15 22:31:28 +02:00
|
|
|
}
|
|
|
|
|
2017-12-24 21:42:08 +01:00
|
|
|
@Override
|
|
|
|
protected void setPreferredTheme(boolean nightMode) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-15 22:31:28 +02:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
2017-08-26 21:15:53 +02:00
|
|
|
_scannerView.stopCamera();
|
2016-08-15 22:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleResult(Result rawResult) {
|
2016-08-15 23:31:26 +02:00
|
|
|
try {
|
2017-08-26 15:47:57 +02:00
|
|
|
KeyInfo info = KeyInfo.fromURL(rawResult.getText());
|
2017-08-26 21:15:53 +02:00
|
|
|
KeyProfile profile = new KeyProfile(new DatabaseEntry(info));
|
2016-08-16 20:04:38 +02:00
|
|
|
|
2016-08-16 00:08:01 +02:00
|
|
|
Intent resultIntent = new Intent();
|
2017-08-26 21:15:53 +02:00
|
|
|
resultIntent.putExtra("KeyProfile", profile);
|
2016-08-16 13:31:22 +02:00
|
|
|
|
2016-08-16 00:08:01 +02:00
|
|
|
setResult(Activity.RESULT_OK, resultIntent);
|
|
|
|
finish();
|
2016-08-15 23:31:26 +02:00
|
|
|
} catch (Exception e) {
|
2017-08-26 21:15:53 +02:00
|
|
|
Toast.makeText(this, "An error occurred while trying to parse the QR code contents", Toast.LENGTH_SHORT).show();
|
2016-08-15 23:31:26 +02:00
|
|
|
}
|
2016-08-15 22:31:28 +02:00
|
|
|
|
2017-08-26 21:15:53 +02:00
|
|
|
_scannerView.resumeCameraPreview(this);
|
2016-08-15 22:31:28 +02:00
|
|
|
}
|
2016-08-17 01:35:19 +02:00
|
|
|
}
|