use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.
the class PasswordActivity method loadDatabase.
private void loadDatabase(String pass, Uri keyfile) {
// Clear before we load
Database db = App.getDB();
db.clear();
// Clear the shutdown flag
App.clearShutdown();
Handler handler = new Handler();
AfterLoad afterLoad = new AfterLoad(handler, db);
LoadDB task = new LoadDB(db, PasswordActivity.this, mDbUri, pass, keyfile, afterLoad);
ProgressTask pt = new ProgressTask(PasswordActivity.this, task, R.string.loading_database);
pt.run();
}
use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.
the class NestedSettingsFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
int key = getArguments().getInt(TAG_KEY);
// Load the preferences from an XML resource
switch(key) {
case NESTED_SCREEN_APP_KEY:
setPreferencesFromResource(R.xml.app_preferences, rootKey);
Preference keyFile = findPreference(getString(R.string.keyfile_key));
keyFile.setOnPreferenceChangeListener((preference, newValue) -> {
Boolean value = (Boolean) newValue;
if (!value) {
App.getFileHistory().deleteAllKeys();
}
return true;
});
Preference recentHistory = findPreference(getString(R.string.recentfile_key));
recentHistory.setOnPreferenceChangeListener((preference, newValue) -> {
Boolean value = (Boolean) newValue;
if (value == null) {
value = true;
}
if (!value) {
App.getFileHistory().deleteAll();
}
return true;
});
Preference stylePreference = findPreference(getString(R.string.setting_style_key));
stylePreference.setOnPreferenceChangeListener((preference, newValue) -> {
String styleString = (String) newValue;
Stylish.assignStyle(getActivity(), styleString);
getActivity().recreate();
return true;
});
SwitchPreference fingerprintEnablePreference = (SwitchPreference) findPreference(getString(R.string.fingerprint_enable_key));
// < M solve verifyError exception
boolean fingerprintSupported = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
fingerprintSupported = FingerPrintHelper.isFingerprintSupported(FingerprintManagerCompat.from(getContext()));
if (!fingerprintSupported) {
// False if under Marshmallow
fingerprintEnablePreference.setChecked(false);
fingerprintEnablePreference.setOnPreferenceClickListener(preference -> {
FragmentManager fragmentManager = getFragmentManager();
assert fragmentManager != null;
((SwitchPreference) preference).setChecked(false);
UnavailableFeatureDialogFragment.getInstance(Build.VERSION_CODES.M).show(getFragmentManager(), "unavailableFeatureDialog");
return false;
});
}
Preference deleteKeysFingerprints = findPreference(getString(R.string.fingerprint_delete_all_key));
if (!fingerprintSupported) {
deleteKeysFingerprints.setEnabled(false);
} else {
deleteKeysFingerprints.setOnPreferenceClickListener(preference -> {
new AlertDialog.Builder(getContext()).setMessage(getResources().getString(R.string.fingerprint_delete_all_warning)).setIcon(getResources().getDrawable(android.R.drawable.ic_dialog_alert)).setPositiveButton(getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onClick(DialogInterface dialog, int which) {
FingerPrintHelper.deleteEntryKeyInKeystoreForFingerprints(getContext(), new FingerPrintHelper.FingerPrintErrorCallback() {
@Override
public void onInvalidKeyException(Exception e) {
}
@Override
public void onFingerPrintException(Exception e) {
Toast.makeText(getContext(), getString(R.string.fingerprint_error, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show();
}
});
PreferencesUtil.deleteAllValuesFromNoBackupPreferences(getContext());
}
}).setNegativeButton(getResources().getString(android.R.string.no), (dialog, which) -> {
}).show();
return false;
});
}
break;
case NESTED_SCREEN_FORM_FILLING_KEY:
setPreferencesFromResource(R.xml.form_filling_preferences, rootKey);
SwitchPreference autoFillEnablePreference = (SwitchPreference) findPreference(getString(R.string.settings_autofill_enable_key));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AutofillManager autofillManager = getActivity().getSystemService(AutofillManager.class);
if (autofillManager != null && autofillManager.hasEnabledAutofillServices())
autoFillEnablePreference.setChecked(autofillManager.hasEnabledAutofillServices());
autoFillEnablePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public boolean onPreferenceClick(Preference preference) {
if (((SwitchPreference) preference).isChecked()) {
try {
startEnableService();
} catch (ActivityNotFoundException e) {
String error = getString(R.string.error_autofill_enable_service);
((SwitchPreference) preference).setChecked(false);
Log.d(getClass().getName(), error, e);
Toast.makeText(getContext(), error, Toast.LENGTH_SHORT).show();
}
} else {
disableService();
}
return false;
}
@RequiresApi(api = Build.VERSION_CODES.O)
private void disableService() {
if (autofillManager != null && autofillManager.hasEnabledAutofillServices()) {
autofillManager.disableAutofillServices();
} else {
Log.d(getClass().getName(), "Sample service already disabled.");
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
private void startEnableService() throws ActivityNotFoundException {
if (autofillManager != null && !autofillManager.hasEnabledAutofillServices()) {
Intent intent = new Intent(Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE);
intent.setData(Uri.parse("package:com.example.android.autofill.service"));
Log.d(getClass().getName(), "enableService(): intent=" + intent);
startActivityForResult(intent, REQUEST_CODE_AUTOFILL);
} else {
Log.d(getClass().getName(), "Sample service already enabled.");
}
}
});
} else {
autoFillEnablePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
((SwitchPreference) preference).setChecked(false);
FragmentManager fragmentManager = getFragmentManager();
assert fragmentManager != null;
UnavailableFeatureDialogFragment.getInstance(Build.VERSION_CODES.O).show(fragmentManager, "unavailableFeatureDialog");
}
return false;
}
});
}
break;
case NESTED_SCREEN_DB_KEY:
setPreferencesFromResource(R.xml.db_preferences, rootKey);
Database db = App.getDB();
if (db.Loaded()) {
if (db.pm.algorithmSettingsEnabled()) {
Preference roundPref = findPreference(getString(R.string.rounds_key));
roundPref.setEnabled(true);
roundPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
setRounds(App.getDB(), preference);
return true;
}
});
setRounds(db, roundPref);
// TODO Algo
Preference algorithmPref = findPreference(getString(R.string.algorithm_key));
// algorithmPref.setEnabled(true);
setAlgorithm(db, algorithmPref);
}
if (db.pm.isRecycleBinAvailable()) {
SwitchPreference recycleBinPref = (SwitchPreference) findPreference(getString(R.string.recycle_bin_key));
// TODO Recycle
// recycleBinPref.setEnabled(true);
recycleBinPref.setChecked(db.pm.isRecycleBinEnable());
}
} else {
Log.e(getClass().getName(), "Database isn't ready");
}
break;
default:
break;
}
}
use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.
the class CreateDB method run.
@Override
public void run() {
// Create new database record
Database db = new Database();
App.setDB(db);
PwDatabase pm = PwDatabase.getNewDBInstance(mFilename);
pm.initNew(mFilename);
// Set Database state
db.pm = pm;
db.mUri = UriUtil.parseDefaultFile(mFilename);
db.setLoaded();
App.clearShutdown();
// Commit changes
SaveDB save = new SaveDB(ctx, db, mFinish, mDontSave);
mFinish = null;
save.run();
}
use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.
the class EntryEditActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.entry_edit);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.app_name));
setSupportActionBar(toolbar);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
scrollView = findViewById(R.id.entry_scroll);
scrollView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
entryTitleView = findViewById(R.id.entry_title);
entryUserNameView = findViewById(R.id.entry_user_name);
entryUrlView = findViewById(R.id.entry_url);
entryPasswordView = findViewById(R.id.entry_password);
entryConfirmationPasswordView = findViewById(R.id.entry_confpassword);
entryCommentView = findViewById(R.id.entry_comment);
entryExtraFieldsContainer = findViewById(R.id.advanced_container);
// Likely the app has been killed exit the activity
Database db = App.getDB();
if (!db.Loaded()) {
finish();
return;
}
Intent intent = getIntent();
byte[] uuidBytes = intent.getByteArrayExtra(KEY_ENTRY);
PwDatabase pm = db.pm;
if (uuidBytes == null) {
PwGroupId parentId = (PwGroupId) intent.getSerializableExtra(KEY_PARENT);
PwGroup parent = pm.groups.get(parentId);
mEntry = PwEntry.getInstance(parent);
mIsNew = true;
} else {
UUID uuid = Types.bytestoUUID(uuidBytes);
mEntry = pm.entries.get(uuid);
mIsNew = false;
fillData();
}
View iconButton = findViewById(R.id.icon_button);
iconButton.setOnClickListener(v -> IconPickerDialogFragment.launch(EntryEditActivity.this));
// Generate password button
View generatePassword = findViewById(R.id.generate_button);
generatePassword.setOnClickListener(v -> {
GeneratePasswordDialogFragment generatePasswordDialogFragment = new GeneratePasswordDialogFragment();
generatePasswordDialogFragment.show(getSupportFragmentManager(), "PasswordGeneratorFragment");
});
// Save button
View save = findViewById(R.id.entry_save);
save.setOnClickListener(v -> {
if (!validateBeforeSaving()) {
return;
}
mCallbackNewEntry = populateNewEntry();
OnFinish onFinish = new AfterSave();
EntryEditActivity act = EntryEditActivity.this;
RunnableOnFinish task;
if (mIsNew) {
task = new AddEntry(act, App.getDB(), mCallbackNewEntry, onFinish);
} else {
task = new UpdateEntry(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish);
}
ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
pt.run();
});
if (mEntry.allowExtraFields()) {
View add = findViewById(R.id.add_new_field);
add.setVisibility(View.VISIBLE);
add.setOnClickListener(v -> {
EntryEditNewField ees = new EntryEditNewField(EntryEditActivity.this);
ees.setData("", new ProtectedString(false, ""));
entryExtraFieldsContainer.addView(ees);
// Scroll bottom
scrollView.post(() -> scrollView.fullScroll(ScrollView.FOCUS_DOWN));
});
}
}
use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.
the class GroupActivity method initCurrentGroup.
protected PwGroup initCurrentGroup() {
PwGroup currentGroup;
Database db = App.getDB();
readOnly = db.readOnly;
PwGroup root = db.pm.rootGroup;
Log.w(TAG, "Creating tree view");
PwGroupId pwGroupId = (PwGroupId) getIntent().getSerializableExtra(GROUP_ID_KEY);
if (pwGroupId == null) {
currentGroup = root;
} else {
currentGroup = db.pm.groups.get(pwGroupId);
}
if (currentGroup != null) {
addGroupEnabled = !readOnly;
// TODO ReadOnly
addEntryEnabled = !readOnly;
isRoot = (currentGroup == root);
if (!currentGroup.allowAddEntryIfIsRoot())
addEntryEnabled = !isRoot && addEntryEnabled;
}
return currentGroup;
}
Aggregations