diff options
author | Mohamed Zenadi <mohamed@zenadi.com> | 2015-04-20 00:26:21 +0200 |
---|---|---|
committer | Mohamed Zenadi <mohamed@zenadi.com> | 2015-05-17 18:45:40 +0200 |
commit | 47ffaf99bd98cb4f362f4446c2bd910e222989bf (patch) | |
tree | 853c292e5beeb2bdb38715479b04f06e25600654 /app/src/main/java | |
parent | 72ad36c6baa82b0b65163cfbb652e7262bbd343a (diff) |
add a preference option to select an external directory
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/UserPreference.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java index 0b7f3640..e8bacad5 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; +import android.os.Environment; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; @@ -19,6 +20,8 @@ import com.zeapo.pwdstore.crypto.PgpHandler; import com.zeapo.pwdstore.git.GitActivity; import com.zeapo.pwdstore.utils.PasswordRepository; +import net.rdrei.android.dirchooser.DirectoryChooserActivity; + import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.openintents.openpgp.util.OpenPgpKeyPreference; @@ -34,6 +37,7 @@ public class UserPreference extends AppCompatActivity { private final static int IMPORT_PGP_KEY = 2; private final static int EDIT_GIT_INFO = 3; private OpenPgpKeyPreference mKey; + private final static int SELECT_GIT_DIRECTORY = 4; public static class PrefsFragment extends PreferenceFragment { @Override @@ -108,6 +112,22 @@ public class UserPreference extends AppCompatActivity { callingActivity.mKey.setOpenPgpProvider((String) o); return false; }); + + findPreference("pref_select_external").setOnPreferenceClickListener((Preference pref) -> { + Uri selectedUri = Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath()); + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(selectedUri); + + if (intent.resolveActivity(callingActivity.getPackageManager()) != null) { + startActivityForResult(Intent.createChooser(intent, "Open folder"), SELECT_GIT_DIRECTORY); + } else { + intent = new Intent(callingActivity, DirectoryChooserActivity.class); + intent.putExtra(DirectoryChooserActivity.EXTRA_NEW_DIR_NAME, "DirChooserSample"); + + startActivityForResult(intent, SELECT_GIT_DIRECTORY); + } + return true; + }); } } @@ -150,7 +170,6 @@ public class UserPreference extends AppCompatActivity { startActivityForResult(intent, IMPORT_SSH_KEY); } - private void copySshKey(Uri uri) throws IOException { InputStream sshKey = this.getContentResolver().openInputStream(uri); byte[] privateKey = IOUtils.toByteArray(sshKey); |