|
|
|
@ -8,7 +8,6 @@ import android.content.DialogInterface;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.media.MediaScannerConnection;
|
|
|
|
|
import android.support.design.widget.BottomSheetDialog;
|
|
|
|
|
import android.support.design.widget.FloatingActionButton;
|
|
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
|
@ -18,6 +17,9 @@ import android.view.View;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import com.getbase.floatingactionbutton.FloatingActionButton;
|
|
|
|
|
import com.getbase.floatingactionbutton.FloatingActionsMenu;
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.lang.reflect.UndeclaredThrowableException;
|
|
|
|
@ -32,13 +34,14 @@ import me.impy.aegis.util.ByteInputStream;
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends AegisActivity implements KeyProfileView.Listener {
|
|
|
|
|
// activity request codes
|
|
|
|
|
private static final int CODE_GET_KEYINFO = 0;
|
|
|
|
|
private static final int CODE_SCAN_KEYINFO = 0;
|
|
|
|
|
private static final int CODE_ADD_KEYINFO = 1;
|
|
|
|
|
private static final int CODE_EDIT_KEYINFO = 2;
|
|
|
|
|
private static final int CODE_DO_INTRO = 3;
|
|
|
|
|
private static final int CODE_DECRYPT = 4;
|
|
|
|
|
private static final int CODE_IMPORT = 5;
|
|
|
|
|
private static final int CODE_PREFERENCES = 6;
|
|
|
|
|
private static final int CODE_ENTER_KEYINFO = 3;
|
|
|
|
|
private static final int CODE_DO_INTRO = 4;
|
|
|
|
|
private static final int CODE_DECRYPT = 5;
|
|
|
|
|
private static final int CODE_IMPORT = 6;
|
|
|
|
|
private static final int CODE_PREFERENCES = 7;
|
|
|
|
|
|
|
|
|
|
// permission request codes
|
|
|
|
|
private static final int CODE_PERM_EXPORT = 0;
|
|
|
|
@ -60,8 +63,7 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|
|
|
|
|
|
|
|
|
// set up the main view
|
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
setSupportActionBar(findViewById(R.id.toolbar));
|
|
|
|
|
|
|
|
|
|
// set up the key profile view
|
|
|
|
|
_keyProfileView = (KeyProfileView) getSupportFragmentManager().findFragmentById(R.id.key_profiles);
|
|
|
|
@ -69,9 +71,15 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|
|
|
|
_keyProfileView.setShowIssuer(_app.getPreferences().getBoolean("pref_issuer", false));
|
|
|
|
|
|
|
|
|
|
// set up the floating action button
|
|
|
|
|
FloatingActionButton fab = findViewById(R.id.fab);
|
|
|
|
|
fab.setEnabled(true);
|
|
|
|
|
fab.setOnClickListener(view -> onGetKeyInfo());
|
|
|
|
|
FloatingActionsMenu fabMenu = findViewById(R.id.fab);
|
|
|
|
|
findViewById(R.id.fab_enter).setOnClickListener(view -> {
|
|
|
|
|
fabMenu.collapse();
|
|
|
|
|
onEnterKeyInfo();
|
|
|
|
|
});
|
|
|
|
|
findViewById(R.id.fab_scan).setOnClickListener(view -> {
|
|
|
|
|
fabMenu.collapse();
|
|
|
|
|
onScanKeyInfo();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// skip this part if this is the not initial startup and the database has been unlocked
|
|
|
|
|
if (!_app.isRunning() && _db.isLocked()) {
|
|
|
|
@ -133,8 +141,8 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (requestCode) {
|
|
|
|
|
case CODE_GET_KEYINFO:
|
|
|
|
|
onGetKeyInfoResult(resultCode, data);
|
|
|
|
|
case CODE_SCAN_KEYINFO:
|
|
|
|
|
onScanKeyInfoResult(resultCode, data);
|
|
|
|
|
break;
|
|
|
|
|
case CODE_ADD_KEYINFO:
|
|
|
|
|
onAddKeyInfoResult(resultCode, data);
|
|
|
|
@ -142,6 +150,9 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|
|
|
|
case CODE_EDIT_KEYINFO:
|
|
|
|
|
onEditKeyInfoResult(resultCode, data);
|
|
|
|
|
break;
|
|
|
|
|
case CODE_ENTER_KEYINFO:
|
|
|
|
|
onEnterKeyInfoResult(resultCode, data);
|
|
|
|
|
break;
|
|
|
|
|
case CODE_DO_INTRO:
|
|
|
|
|
onDoIntroResult(resultCode, data);
|
|
|
|
|
break;
|
|
|
|
@ -172,7 +183,7 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|
|
|
|
onImport();
|
|
|
|
|
break;
|
|
|
|
|
case CODE_PERM_CAMERA:
|
|
|
|
|
onGetKeyInfo();
|
|
|
|
|
onScanKeyInfo();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -297,7 +308,12 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|
|
|
|
saveDatabase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onGetKeyInfo() {
|
|
|
|
|
private void onEnterKeyInfo() {
|
|
|
|
|
Intent intent = new Intent(this, EditProfileActivity.class);
|
|
|
|
|
startActivityForResult(intent, CODE_ENTER_KEYINFO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onScanKeyInfo() {
|
|
|
|
|
if (!PermissionHelper.request(this, CODE_PERM_CAMERA, Manifest.permission.CAMERA)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -305,7 +321,7 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|
|
|
|
startScanActivity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onGetKeyInfoResult(int resultCode, Intent data) {
|
|
|
|
|
private void onScanKeyInfoResult(int resultCode, Intent data) {
|
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
|
KeyProfile keyProfile = (KeyProfile)data.getSerializableExtra("KeyProfile");
|
|
|
|
|
Intent intent = new Intent(this, AddProfileActivity.class);
|
|
|
|
@ -339,6 +355,21 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onEnterKeyInfoResult(int resultCode, Intent data) {
|
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
|
KeyProfile profile = (KeyProfile) data.getSerializableExtra("KeyProfile");
|
|
|
|
|
try {
|
|
|
|
|
addKey(profile);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
Toast.makeText(this, "An error occurred while trying to add an entry", Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_keyProfileView.addKey(profile);
|
|
|
|
|
saveDatabase();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addKey(KeyProfile profile) {
|
|
|
|
|
profile.refreshCode();
|
|
|
|
|
|
|
|
|
@ -395,7 +426,7 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|
|
|
|
|
|
|
|
|
private void startScanActivity() {
|
|
|
|
|
Intent scannerActivity = new Intent(getApplicationContext(), ScannerActivity.class);
|
|
|
|
|
startActivityForResult(scannerActivity, CODE_GET_KEYINFO);
|
|
|
|
|
startActivityForResult(scannerActivity, CODE_SCAN_KEYINFO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean doShortcutActions() {
|
|
|
|
|