From 47ffaf99bd98cb4f362f4446c2bd910e222989bf Mon Sep 17 00:00:00 2001 From: Mohamed Zenadi Date: Mon, 20 Apr 2015 00:26:21 +0200 Subject: add a preference option to select an external directory --- app/src/main/AndroidManifest.xml | 3 +++ .../java/com/zeapo/pwdstore/UserPreference.java | 21 ++++++++++++++++++++- app/src/main/res/color/text_color.xml | 5 +++++ app/src/main/res/values/styles.xml | 2 +- app/src/main/res/xml/preference.xml | 7 ++++++- 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/color/text_color.xml (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cc21dc54..e3e0837e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,9 +30,12 @@ + + + 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); diff --git a/app/src/main/res/color/text_color.xml b/app/src/main/res/color/text_color.xml new file mode 100644 index 00000000..9e70185e --- /dev/null +++ b/app/src/main/res/color/text_color.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 556da8f2..a183f724 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -6,7 +6,7 @@ @color/blue_grey_500 @color/blue_grey_50 @color/teal_900 - @color/blue_grey_900 + @color/text_color @style/ActionMode diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index 1d81f987..b3bed289 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -3,7 +3,12 @@ - + + + -- cgit v1.2.3