mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-22 23:09:13 +00:00
Scanner now passes result correctly to MainActivity
This commit is contained in:
parent
745e5c13b6
commit
b14eb42b12
4 changed files with 49 additions and 5 deletions
|
@ -5,22 +5,48 @@ import android.support.v7.app.AppCompatActivity;
|
|||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import me.impy.aegis.crypto.KeyInfo;
|
||||
import me.impy.aegis.crypto.TOTP;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
static final int GET_KEYINFO = 1;
|
||||
Button btnScan;
|
||||
TextView tvTotp;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
btnScan = (Button) findViewById(R.id.button);
|
||||
tvTotp = (TextView) findViewById(R.id.textView2);
|
||||
btnScan.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent scannerActivity = new Intent(getApplicationContext(), ScannerActivity.class);
|
||||
startActivity(scannerActivity);
|
||||
startActivityForResult(scannerActivity, GET_KEYINFO);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// Check which request we're responding to
|
||||
if (requestCode == GET_KEYINFO) {
|
||||
// Make sure the request was successful
|
||||
if (resultCode == RESULT_OK) {
|
||||
KeyInfo info = (KeyInfo)data.getSerializableExtra("Keyinfo");
|
||||
|
||||
String nowTimeString = (Long.toHexString(System.currentTimeMillis() / 1000 / info.getPeriod()));
|
||||
String totp = TOTP.generateTOTP(info.getSecret(), nowTimeString, info.getDigits(), info.getAlgo());
|
||||
|
||||
tvTotp.setText(totp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package me.impy.aegis;
|
|||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.util.TimeUtils;
|
||||
|
@ -13,6 +14,7 @@ import android.widget.Toast;
|
|||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Time;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -53,14 +55,19 @@ public class ScannerActivity extends Activity implements ZXingScannerView.Result
|
|||
try {
|
||||
KeyInfo info = KeyInfo.FromURL(rawResult.getText());
|
||||
|
||||
String nowTimeString = (Long.toHexString(System.currentTimeMillis() / 1000 / info.getPeriod()));
|
||||
Toast.makeText(this, TOTP.generateTOTP(info.getSecret(), nowTimeString, info.getDigits(), info.getAlgo()), Toast.LENGTH_LONG).show();
|
||||
//String nowTimeString = (Long.toHexString(System.currentTimeMillis() / 1000 / info.getPeriod()));
|
||||
//Toast.makeText(this, TOTP.generateTOTP(info.getSecret(), nowTimeString, info.getDigits(), info.getAlgo()), Toast.LENGTH_LONG).show();
|
||||
|
||||
Intent resultIntent = new Intent();
|
||||
resultIntent.putExtra("Keyinfo", info);
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
finish();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// If you would like to resume scanning, call this method below:
|
||||
mScannerView.resumeCameraPreview(this);
|
||||
//mScannerView.resumeCameraPreview(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,9 +2,11 @@ package me.impy.aegis.crypto;
|
|||
|
||||
import android.net.Uri;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import me.impy.aegis.encoding.Base32;
|
||||
|
||||
public class KeyInfo {
|
||||
public class KeyInfo implements Serializable {
|
||||
private String type;
|
||||
private String label;
|
||||
private byte[] secret;
|
||||
|
|
|
@ -17,4 +17,13 @@
|
|||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"/>
|
||||
|
||||
<TextView
|
||||
android:text="TextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/textView2"
|
||||
android:textSize="24sp"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_centerHorizontal="true"/>
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Add table
Reference in a new issue