1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Add a preference for selecting a default folder in which to save attachments

This commit is contained in:
Bernhard Redl 2011-04-24 13:54:28 +10:00 committed by Jesse Vincent
parent 44feb1563b
commit e278ea23e9
4 changed files with 80 additions and 6 deletions

View File

@ -1041,4 +1041,7 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="account_unavailable">Account \"<xliff:g id="account">%s</xliff:g>\" is unavailable; check storage</string>
<string name="settings_attachment_def_path">Attachments Default Path</string>
<string name="attachment_save_title">Save to</string>
<string name="attachment_save_desc">No filebrowser installed. Please enter destination foldername</string>
</resources>

View File

@ -231,7 +231,11 @@
android:dialogTitle="@string/global_settings_confirm_actions_title"
android:positiveButtonText="@android:string/ok"
android:negativeButtonText="@android:string/cancel" />
<Preference
android:persistent="false"
android:title="@string/settings_attachment_def_path"
android:key="attachment_default_path"
android:summary="- PATH - set by activty -"/>
</PreferenceScreen>
<PreferenceScreen

View File

@ -18,6 +18,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.text.format.Time;
@ -177,7 +178,7 @@ public class K9 extends Application {
private static String mQuietTimeStarts = null;
private static String mQuietTimeEnds = null;
private static boolean compactLayouts = false;
private static String mAttachmentDefaultPath = "";
private static boolean useGalleryBugWorkaround = false;
@ -452,7 +453,7 @@ public class K9 extends Application {
editor.putBoolean("keyguardPrivacy", mKeyguardPrivacy);
editor.putBoolean("compactLayouts", compactLayouts);
editor.putString("attachmentdefaultpath", mAttachmentDefaultPath);
fontSizes.save(editor);
}
@ -507,7 +508,7 @@ public class K9 extends Application {
mKeyguardPrivacy = sprefs.getBoolean("keyguardPrivacy", false);
compactLayouts = sprefs.getBoolean("compactLayouts", false);
mAttachmentDefaultPath = sprefs.getString("attachmentdefaultpath", Environment.getExternalStorageDirectory().toString());
fontSizes.load(sprefs);
try {
@ -995,4 +996,12 @@ public class K9 extends Application {
}
}
public static String getAttachmentDefaultPath() {
return mAttachmentDefaultPath;
}
public static void setAttachmentDefaultPath(String attachmentDefaultPath) {
K9.mAttachmentDefaultPath = attachmentDefaultPath;
}
}

View File

@ -1,5 +1,6 @@
package com.fsck.k9.activity.setup;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Vector;
@ -8,11 +9,13 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.view.KeyEvent;
import android.widget.Toast;
@ -23,6 +26,8 @@ import com.fsck.k9.activity.Accounts;
import com.fsck.k9.activity.ColorPickerDialog;
import com.fsck.k9.activity.K9PreferenceActivity;
import com.fsck.k9.helper.DateFormatter;
import com.fsck.k9.helper.FileBrowserHelper;
import com.fsck.k9.helper.FileBrowserHelper.FileBrowserFailOverCallback;
import com.fsck.k9.preferences.CheckBoxListPreference;
import com.fsck.k9.preferences.TimePickerPreference;
@ -76,7 +81,9 @@ public class Prefs extends K9PreferenceActivity {
private static final String PREFERENCE_DEBUG_LOGGING = "debug_logging";
private static final String PREFERENCE_SENSITIVE_LOGGING = "sensitive_logging";
private static final String PREFERENCE_ATTACHMENT_DEF_PATH = "attachment_default_path";
private static final int ACTIVITY_CHOOSE_FOLDER = 1;
private ListPreference mLanguage;
private ListPreference mTheme;
private ListPreference mDateFormat;
@ -110,7 +117,7 @@ public class Prefs extends K9PreferenceActivity {
private CheckBoxPreference mQuietTimeEnabled;
private com.fsck.k9.preferences.TimePickerPreference mQuietTimeStarts;
private com.fsck.k9.preferences.TimePickerPreference mQuietTimeEnds;
private Preference mAttachmentPathPreference;
public static void actionPrefs(Context context) {
@ -298,6 +305,36 @@ public class Prefs extends K9PreferenceActivity {
mDebugLogging.setChecked(K9.DEBUG);
mSensitiveLogging.setChecked(K9.DEBUG_SENSITIVE);
mAttachmentPathPreference = findPreference(PREFERENCE_ATTACHMENT_DEF_PATH);
mAttachmentPathPreference.setSummary(K9.getAttachmentDefaultPath());
mAttachmentPathPreference
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
FileBrowserHelper
.getInstance()
.showFileBrowserActivity(Prefs.this,
new File(K9.getAttachmentDefaultPath()),
ACTIVITY_CHOOSE_FOLDER, callback);
return true;
}
FileBrowserFailOverCallback callback = new FileBrowserFailOverCallback() {
@Override
public void onPathEntered(String path) {
mAttachmentPathPreference.setSummary(path);
K9.setAttachmentDefaultPath(path);
}
@Override
public void onCancel() {
// canceled, do nothing
}
};
});
}
private void saveSettings() {
@ -336,7 +373,7 @@ public class Prefs extends K9PreferenceActivity {
K9.setZoomControlsEnabled(mZoomControlsEnabled.isChecked());
K9.setAttachmentDefaultPath(mAttachmentPathPreference.getSummary().toString());
boolean needsRefresh = K9.setBackgroundOps(mBackgroundOps.getValue());
K9.setUseGalleryBugWorkaround(mUseGalleryBugWorkaround.isChecked());
@ -381,4 +418,25 @@ public class Prefs extends K9PreferenceActivity {
},
K9.getContactNameColor()).show();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ACTIVITY_CHOOSE_FOLDER:
if (resultCode == RESULT_OK && data != null) {
// obtain the filename
Uri fileUri = data.getData();
if (fileUri != null) {
String filePath = fileUri.getPath();
if (filePath != null) {
mAttachmentPathPreference.setSummary(filePath.toString());
K9.setAttachmentDefaultPath(filePath.toString());
}
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
}