2016-08-15 21:29:41 +02:00
|
|
|
package me.impy.aegis;
|
|
|
|
|
2016-08-15 22:31:28 +02:00
|
|
|
import android.content.Intent;
|
2016-08-16 20:04:38 +02:00
|
|
|
import android.inputmethodservice.Keyboard;
|
2016-08-16 14:14:17 +02:00
|
|
|
import android.support.design.widget.FloatingActionButton;
|
2016-08-15 21:29:41 +02:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.os.Bundle;
|
2016-08-16 20:04:38 +02:00
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
2016-08-16 14:14:17 +02:00
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2016-08-15 22:31:28 +02:00
|
|
|
import android.view.View;
|
2016-08-16 00:08:01 +02:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2016-08-16 20:04:38 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2016-08-16 00:08:01 +02:00
|
|
|
import me.impy.aegis.crypto.KeyInfo;
|
2016-08-16 13:31:22 +02:00
|
|
|
import me.impy.aegis.crypto.OTP;
|
2016-08-15 21:29:41 +02:00
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
2016-08-16 00:08:01 +02:00
|
|
|
static final int GET_KEYINFO = 1;
|
2016-08-16 20:04:38 +02:00
|
|
|
RecyclerView rvKeyProfiles;
|
|
|
|
KeyProfileAdapter mKeyProfileAdapter;
|
|
|
|
ArrayList<KeyProfile> mKeyProfiles;
|
2016-08-16 14:14:17 +02:00
|
|
|
|
2016-08-15 21:29:41 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_main);
|
2016-08-16 14:14:17 +02:00
|
|
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
|
|
|
setSupportActionBar(toolbar);
|
2016-08-15 22:31:28 +02:00
|
|
|
|
2016-08-16 14:14:17 +02:00
|
|
|
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
|
|
|
fab.setOnClickListener(new View.OnClickListener() {
|
2016-08-15 22:31:28 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
Intent scannerActivity = new Intent(getApplicationContext(), ScannerActivity.class);
|
2016-08-16 00:08:01 +02:00
|
|
|
startActivityForResult(scannerActivity, GET_KEYINFO);
|
2016-08-15 22:31:28 +02:00
|
|
|
}
|
|
|
|
});
|
2016-08-16 14:14:17 +02:00
|
|
|
|
2016-08-16 20:04:38 +02:00
|
|
|
mKeyProfiles = new ArrayList<>();
|
|
|
|
|
|
|
|
rvKeyProfiles = (RecyclerView) findViewById(R.id.rvKeyProfiles);
|
|
|
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
|
|
|
|
rvKeyProfiles.setLayoutManager(mLayoutManager);
|
|
|
|
|
|
|
|
mKeyProfileAdapter = new KeyProfileAdapter(mKeyProfiles);
|
|
|
|
rvKeyProfiles.setAdapter(mKeyProfileAdapter);
|
2016-08-15 21:29:41 +02:00
|
|
|
}
|
2016-08-16 00:08:01 +02:00
|
|
|
|
|
|
|
@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) {
|
2016-08-16 20:04:38 +02:00
|
|
|
KeyProfile keyProfile = (KeyProfile)data.getSerializableExtra("KeyProfile");
|
2016-08-16 00:08:01 +02:00
|
|
|
|
2016-08-16 13:31:22 +02:00
|
|
|
String otp;
|
|
|
|
try {
|
2016-08-16 20:04:38 +02:00
|
|
|
otp = OTP.generateOTP(keyProfile.KeyInfo);
|
2016-08-16 13:31:22 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return;
|
|
|
|
}
|
2016-08-16 20:04:38 +02:00
|
|
|
|
|
|
|
keyProfile.Code = otp;
|
|
|
|
mKeyProfiles.add(keyProfile);
|
|
|
|
mKeyProfileAdapter.notifyDataSetChanged();
|
|
|
|
//TODO: do something with the result.
|
2016-08-16 00:08:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-16 14:14:17 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
// Handle action bar item clicks here. The action bar will
|
|
|
|
// automatically handle clicks on the Home/Up button, so long
|
|
|
|
// as you specify a parent activity in AndroidManifest.xml.
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
|
|
|
//noinspection SimplifiableIfStatement
|
|
|
|
if (id == R.id.action_settings) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
2016-08-15 21:29:41 +02:00
|
|
|
}
|