mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
Add toolbar in Settings
This commit is contained in:
1 parent
f2cf0ecc34
commit
49fca524af
11 files changed
+362
-195
No files matched your search
@@ -45,7 +45,7 @@ import com.keepassdroid.compat.ActivityCompat;
|
||||
import com.keepassdroid.compat.EditorCompat;
|
||||
import com.keepassdroid.database.PwGroup;
|
||||
import com.keepassdroid.database.edit.OnFinish;
|
||||
import com.keepassdroid.settings.AppSettingsActivity;
|
||||
import com.keepassdroid.settings.SettingsActivity;
|
||||
import com.keepassdroid.utils.Util;
|
||||
import com.keepassdroid.view.ClickView;
|
||||
import com.keepassdroid.view.GroupViewOnlyView;
|
||||
@@ -219,7 +219,7 @@ public abstract class GroupBaseActivity extends LockCloseListActivity {
|
||||
return true;
|
||||
|
||||
case R.id.menu_app_settings:
|
||||
AppSettingsActivity.Launch(this);
|
||||
SettingsActivity.Launch(this);
|
||||
return true;
|
||||
|
||||
case R.id.menu_change_master_key:
|
||||
|
||||
@@ -60,7 +60,7 @@ import com.keepassdroid.fileselect.BrowserDialog;
|
||||
import com.keepassdroid.fingerprint.FingerPrintHelper;
|
||||
import com.keepassdroid.fingerprint.FingerPrintUtils;
|
||||
import com.keepassdroid.intents.Intents;
|
||||
import com.keepassdroid.settings.AppSettingsActivity;
|
||||
import com.keepassdroid.settings.SettingsActivity;
|
||||
import com.keepassdroid.utils.EmptyUtils;
|
||||
import com.keepassdroid.utils.Interaction;
|
||||
import com.keepassdroid.utils.UriUtil;
|
||||
@@ -561,7 +561,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
|
||||
return true;
|
||||
|
||||
case R.id.menu_app_settings:
|
||||
AppSettingsActivity.Launch(this);
|
||||
SettingsActivity.Launch(this);
|
||||
return true;
|
||||
|
||||
case android.R.id.home:
|
||||
|
||||
@@ -66,7 +66,7 @@ import com.keepassdroid.database.edit.CreateDB;
|
||||
import com.keepassdroid.database.edit.FileOnFinish;
|
||||
import com.keepassdroid.database.exception.ContentFileNotFoundException;
|
||||
import com.keepassdroid.intents.Intents;
|
||||
import com.keepassdroid.settings.AppSettingsActivity;
|
||||
import com.keepassdroid.settings.SettingsActivity;
|
||||
import com.keepassdroid.utils.EmptyUtils;
|
||||
import com.keepassdroid.utils.Interaction;
|
||||
import com.keepassdroid.utils.UriUtil;
|
||||
@@ -523,7 +523,7 @@ public class FileSelectActivity extends AppCompatActivity {
|
||||
return true;
|
||||
|
||||
case R.id.menu_app_settings:
|
||||
AppSettingsActivity.Launch(this);
|
||||
SettingsActivity.Launch(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.keepassdroid.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
|
||||
import com.android.keepass.R;
|
||||
import com.keepassdroid.Database;
|
||||
import com.keepassdroid.app.App;
|
||||
import com.keepassdroid.database.PwEncryptionAlgorithm;
|
||||
|
||||
public class AppSettingsFragment extends PreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
Preference keyFile = findPreference(getString(R.string.keyfile_key));
|
||||
keyFile.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
Boolean value = (Boolean) newValue;
|
||||
|
||||
if (!value) {
|
||||
App.getFileHistory().deleteAllKeys();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Preference recentHistory = findPreference(getString(R.string.recentfile_key));
|
||||
recentHistory.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
Boolean value = (Boolean) newValue;
|
||||
|
||||
if (value == null) {
|
||||
value = true;
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
App.getFileHistory().deleteAll();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Database db = App.getDB();
|
||||
if (db.Loaded() && db.pm.appSettingsEnabled()) {
|
||||
Preference rounds = findPreference(getString(R.string.rounds_key));
|
||||
rounds.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
setRounds(App.getDB(), preference);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
setRounds(db, rounds);
|
||||
|
||||
Preference algorithm = findPreference(getString(R.string.algorithm_key));
|
||||
setAlgorithm(db, algorithm);
|
||||
|
||||
} else {
|
||||
Preference dbSettings = findPreference(getString(R.string.db_key));
|
||||
dbSettings.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void setRounds(Database db, Preference rounds) {
|
||||
rounds.setSummary(Long.toString(db.pm.getNumRounds()));
|
||||
}
|
||||
|
||||
private void setAlgorithm(Database db, Preference algorithm) {
|
||||
int resId;
|
||||
if ( db.pm.getEncAlgorithm() == PwEncryptionAlgorithm.Rjindal ) {
|
||||
resId = R.string.rijndael;
|
||||
} else {
|
||||
resId = R.string.twofish;
|
||||
}
|
||||
|
||||
algorithm.setSummary(resId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.keepassdroid.settings;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
|
||||
import com.android.keepass.R;
|
||||
import com.keepassdroid.Database;
|
||||
import com.keepassdroid.app.App;
|
||||
|
||||
public class MainPreferenceFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener {
|
||||
|
||||
private Callback mCallback;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
if (context instanceof Callback) {
|
||||
mCallback = (Callback) context;
|
||||
} else {
|
||||
throw new IllegalStateException("Owner must implement " + Callback.class.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
// add listeners for non-default actions
|
||||
Preference preference = findPreference(getString(R.string.app_key));
|
||||
preference.setOnPreferenceClickListener(this);
|
||||
|
||||
preference = findPreference(getString(R.string.db_key));
|
||||
Database db = App.getDB();
|
||||
if (!(db.Loaded() && db.pm.appSettingsEnabled())) {
|
||||
Preference dbSettings = findPreference(getString(R.string.db_key));
|
||||
dbSettings.setEnabled(false);
|
||||
} else {
|
||||
preference.setOnPreferenceClickListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
// here you should use the same keys as you used in the xml-file
|
||||
if (preference.getKey().equals(getString(R.string.app_key))) {
|
||||
mCallback.onNestedPreferenceSelected(NestedSettingsFragment.NESTED_SCREEN_APP_KEY);
|
||||
}
|
||||
|
||||
if (preference.getKey().equals(getString(R.string.db_key))) {
|
||||
mCallback.onNestedPreferenceSelected(NestedSettingsFragment.NESTED_SCREEN_DB_KEY);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public interface Callback {
|
||||
void onNestedPreferenceSelected(int key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright 2017 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.keepassdroid.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.keepass.R;
|
||||
import com.keepassdroid.Database;
|
||||
import com.keepassdroid.app.App;
|
||||
import com.keepassdroid.database.PwEncryptionAlgorithm;
|
||||
|
||||
public class NestedSettingsFragment extends PreferenceFragment {
|
||||
|
||||
public static final int NESTED_SCREEN_APP_KEY = 1;
|
||||
public static final int NESTED_SCREEN_DB_KEY = 2;
|
||||
|
||||
private static final String TAG_KEY = "NESTED_KEY";
|
||||
|
||||
public static NestedSettingsFragment newInstance(int key) {
|
||||
NestedSettingsFragment fragment = new NestedSettingsFragment();
|
||||
// supply arguments to bundle.
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(TAG_KEY, key);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
checkPreferenceResource();
|
||||
}
|
||||
|
||||
private void checkPreferenceResource() {
|
||||
int key = getArguments().getInt(TAG_KEY);
|
||||
// Load the preferences from an XML resource
|
||||
switch (key) {
|
||||
case NESTED_SCREEN_APP_KEY:
|
||||
addPreferencesFromResource(R.xml.app_preferences);
|
||||
|
||||
Preference keyFile = findPreference(getString(R.string.keyfile_key));
|
||||
keyFile.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
Boolean value = (Boolean) newValue;
|
||||
|
||||
if (!value) {
|
||||
App.getFileHistory().deleteAllKeys();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Preference recentHistory = findPreference(getString(R.string.recentfile_key));
|
||||
recentHistory.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
Boolean value = (Boolean) newValue;
|
||||
|
||||
if (value == null) {
|
||||
value = true;
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
App.getFileHistory().deleteAll();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case NESTED_SCREEN_DB_KEY:
|
||||
addPreferencesFromResource(R.xml.db_preferences);
|
||||
|
||||
Database db = App.getDB();
|
||||
if (db.Loaded() && db.pm.appSettingsEnabled()) {
|
||||
|
||||
Preference rounds = findPreference(getString(R.string.rounds_key));
|
||||
rounds.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
setRounds(App.getDB(), preference);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
setRounds(db, rounds);
|
||||
|
||||
Preference algorithm = findPreference(getString(R.string.algorithm_key));
|
||||
setAlgorithm(db, algorithm);
|
||||
|
||||
} else {
|
||||
Log.e(getClass().getName(), "Database isn't ready");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setRounds(Database db, Preference rounds) {
|
||||
rounds.setSummary(Long.toString(db.pm.getNumRounds()));
|
||||
}
|
||||
|
||||
private void setAlgorithm(Database db, Preference algorithm) {
|
||||
int resId;
|
||||
if ( db.pm.getEncAlgorithm() == PwEncryptionAlgorithm.Rjindal ) {
|
||||
resId = R.string.rijndael;
|
||||
} else {
|
||||
resId = R.string.twofish;
|
||||
}
|
||||
|
||||
algorithm.setSummary(resId);
|
||||
}
|
||||
}
|
||||
+29
-11
@@ -30,9 +30,10 @@ import com.android.keepass.R;
|
||||
import com.keepassdroid.compat.BackupManagerCompat;
|
||||
import com.keepassdroid.timeout.TimeoutHelper;
|
||||
|
||||
public class AppSettingsActivity extends AppCompatActivity {
|
||||
public static boolean KEYFILE_DEFAULT = false;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity implements MainPreferenceFragment.Callback {
|
||||
|
||||
private static final String TAG_NESTED = "TAG_NESTED";
|
||||
|
||||
private BackupManagerCompat backupManager;
|
||||
|
||||
private Toolbar toolbar;
|
||||
@@ -53,8 +54,7 @@ public class AppSettingsActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
public static void Launch(Context ctx) {
|
||||
Intent i = new Intent(ctx, AppSettingsActivity.class);
|
||||
|
||||
Intent i = new Intent(ctx, SettingsActivity.class);
|
||||
ctx.startActivity(i);
|
||||
}
|
||||
|
||||
@@ -64,24 +64,25 @@ public class AppSettingsActivity extends AppCompatActivity {
|
||||
|
||||
setContentView(R.layout.activity_toolbar);
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
toolbar.setTitle(R.string.application_settings);
|
||||
toolbar.setTitle(R.string.menu_app_settings);
|
||||
setSupportActionBar(toolbar);
|
||||
assert getSupportActionBar() != null;
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(R.id.fragment_container, new AppSettingsFragment()).commit();
|
||||
if (savedInstanceState == null) {
|
||||
getFragmentManager().beginTransaction()
|
||||
.add(R.id.fragment_container, new MainPreferenceFragment())
|
||||
.commit();
|
||||
}
|
||||
|
||||
backupManager = new BackupManagerCompat(this);
|
||||
|
||||
// TODO NESTED Preference
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch ( item.getItemId() ) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
onBackPressed();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -95,4 +96,21 @@ public class AppSettingsActivity extends AppCompatActivity {
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// this if statement is necessary to navigate through nested and main fragments
|
||||
if (getFragmentManager().getBackStackEntryCount() == 0) {
|
||||
super.onBackPressed();
|
||||
} else {
|
||||
getFragmentManager().popBackStack();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNestedPreferenceSelected(int key) {
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(R.id.fragment_container, NestedSettingsFragment.newInstance(key), TAG_NESTED)
|
||||
.addToBackStack(TAG_NESTED)
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user