diff options
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/UserPreference.java | 40 | ||||
-rw-r--r-- | app/src/main/res/xml/preference.xml | 5 |
2 files changed, 28 insertions, 17 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java index ff3ff1f9..54e04b70 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java @@ -87,7 +87,7 @@ public class UserPreference extends AppCompatActivity { findPreference("ssh_key").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - callingActivity.getSshKeyWithPermissions(); + callingActivity.getSshKeyWithPermissions(sharedPreferences.getBoolean("use_android_file_picker", false)); return true; } }); @@ -264,12 +264,13 @@ public class UserPreference extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) { + final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()); super.onCreate(savedInstanceState); if (getIntent() != null) { if (getIntent().getStringExtra("operation") != null) { switch (getIntent().getStringExtra("operation")) { case "get_ssh_key": - getSshKeyWithPermissions(); + getSshKeyWithPermissions(sharedPreferences.getBoolean("use_android_file_picker", false)); break; case "make_ssh_key": makeSshKey(false); @@ -334,7 +335,7 @@ public class UserPreference extends AppCompatActivity { /** * Opens a file explorer to import the private key */ - public void getSshKeyWithPermissions() { + public void getSshKeyWithPermissions(boolean useDefaultPicker) { final Activity activity = this; if (ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.READ_EXTERNAL_STORAGE)) { @@ -357,27 +358,31 @@ public class UserPreference extends AppCompatActivity { ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_STORAGE); } } else { - getSshKey(); + getSshKey(useDefaultPicker); } } /** * Opens a file explorer to import the private key */ - public void getSshKey() { - // This always works - Intent i = new Intent(getApplicationContext(), FilePickerActivity.class); - // This works if you defined the intent filter - // Intent i = new Intent(Intent.ACTION_GET_CONTENT); - - // Set these depending on your use case. These are the defaults. - i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false); - i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false); - i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE); + public void getSshKey(boolean useDefaultPicker) { + if (useDefaultPicker) { + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("*/*"); + startActivityForResult(intent, IMPORT_SSH_KEY); + } else { + // This always works + Intent i = new Intent(getApplicationContext(), FilePickerActivity.class); + // This works if you defined the intent filter + // Intent i = new Intent(Intent.ACTION_GET_CONTENT); - i.putExtra(FilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath()); + // Set these depending on your use case. These are the defaults. + i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false); + i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false); + i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE); - startActivityForResult(i, IMPORT_SSH_KEY); + i.putExtra(FilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath()); + } } public void exportPasswordsWithPermissions() { @@ -543,11 +548,12 @@ public class UserPreference extends AppCompatActivity { @Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { + final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()); switch (requestCode) { case REQUEST_EXTERNAL_STORAGE: { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - getSshKey(); + getSshKey(sharedPreferences.getBoolean("use_android_file_picker", false)); } } } diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index 250370e7..ec740836 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -103,6 +103,11 @@ android:key="clear_clipboard_20x" android:summary="@string/pref_clear_clipboard_hint" android:title="@string/pref_clear_clipboard_title" /> + + <CheckBoxPreference + android:defaultValue="false" + android:key="use_android_file_picker" + android:title="Use default file picker" /> </PreferenceCategory> <Preference |