This commit is contained in:
danapple 2011-03-02 07:34:54 -06:00
parent 107408c0d9
commit 32b5afc702
10 changed files with 83 additions and 115 deletions

View File

@ -139,8 +139,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
} }
} }
public void setProgress(boolean progress) public void setProgress(boolean progress) {
{
mHandler.progress(progress); mHandler.progress(progress);
} }
@ -242,8 +241,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
} }
@Override @Override
public void onNewIntent(Intent intent) public void onNewIntent(Intent intent) {
{
Uri uri = intent.getData(); Uri uri = intent.getData();
Log.i(K9.LOG_TAG, "Accounts Activity got uri " + uri); Log.i(K9.LOG_TAG, "Accounts Activity got uri " + uri);
if (uri != null) { if (uri != null) {
@ -783,8 +781,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
} }
} }
private void onImport() private void onImport() {
{
Intent i = new Intent(Intent.ACTION_GET_CONTENT); Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE); i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*"); i.setType("*/*");
@ -792,66 +789,52 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
} }
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) protected void onActivityResult(int requestCode, int resultCode, Intent data) {
{
Log.i(K9.LOG_TAG, "onActivityResult requestCode = " + requestCode + ", resultCode = " + resultCode + ", data = " + data); Log.i(K9.LOG_TAG, "onActivityResult requestCode = " + requestCode + ", resultCode = " + resultCode + ", data = " + data);
if (resultCode != RESULT_OK) if (resultCode != RESULT_OK)
return; return;
if (data == null) if (data == null) {
{
return; return;
} }
switch (requestCode) switch (requestCode) {
{
case ACTIVITY_REQUEST_PICK_SETTINGS_FILE: case ACTIVITY_REQUEST_PICK_SETTINGS_FILE:
onImport(data.getData()); onImport(data.getData());
break; break;
} }
} }
private void onImport(Uri uri) private void onImport(Uri uri) {
{
Log.i(K9.LOG_TAG, "onImport importing from URI " + uri.getPath()); Log.i(K9.LOG_TAG, "onImport importing from URI " + uri.getPath());
try try {
{
final String fileName = uri.getPath(); final String fileName = uri.getPath();
ContentResolver resolver = getContentResolver(); ContentResolver resolver = getContentResolver();
final InputStream is = resolver.openInputStream(uri); final InputStream is = resolver.openInputStream(uri);
PasswordEntryDialog dialog = new PasswordEntryDialog(this, getString(R.string.settings_encryption_password_prompt), PasswordEntryDialog dialog = new PasswordEntryDialog(this, getString(R.string.settings_encryption_password_prompt),
new PasswordEntryDialog.PasswordEntryListener() new PasswordEntryDialog.PasswordEntryListener() {
{ public void passwordChosen(String chosenPassword) {
public void passwordChosen(String chosenPassword) String toastText = Accounts.this.getString(R.string.settings_importing);
{
String toastText = Accounts.this.getString(R.string.settings_importing );
Toast toast = Toast.makeText(Accounts.this.getApplication(), toastText, Toast.LENGTH_SHORT); Toast toast = Toast.makeText(Accounts.this.getApplication(), toastText, Toast.LENGTH_SHORT);
toast.show(); toast.show();
mHandler.progress(true); mHandler.progress(true);
AsyncUIProcessor.getInstance(Accounts.this.getApplication()).importSettings(is, chosenPassword, new ImportListener() AsyncUIProcessor.getInstance(Accounts.this.getApplication()).importSettings(is, chosenPassword, new ImportListener() {
{ public void failure(final String message, Exception e) {
public void failure(final String message, Exception e) Accounts.this.runOnUiThread(new Runnable() {
{ public void run() {
Accounts.this.runOnUiThread(new Runnable()
{
public void run()
{
mHandler.progress(false); mHandler.progress(false);
showDialog(Accounts.this, R.string.settings_import_failed_header, Accounts.this.getString(R.string.settings_import_failure, fileName, message)); showDialog(Accounts.this, R.string.settings_import_failed_header, Accounts.this.getString(R.string.settings_import_failure, fileName, message));
} }
}); });
} }
public void importSuccess(final int numAccounts) public void importSuccess(final int numAccounts) {
{ Accounts.this.runOnUiThread(new Runnable() {
Accounts.this.runOnUiThread(new Runnable() public void run() {
{
public void run()
{
mHandler.progress(false); mHandler.progress(false);
String messageText = String messageText =
numAccounts != 1 numAccounts != 1
? Accounts.this.getString(R.string.settings_import_success_multiple, numAccounts, fileName ) ? Accounts.this.getString(R.string.settings_import_success_multiple, numAccounts, fileName)
: Accounts.this.getString(R.string.settings_import_success_single, fileName ); : Accounts.this.getString(R.string.settings_import_success_single, fileName);
showDialog(Accounts.this, R.string.settings_import_success_header, messageText); showDialog(Accounts.this, R.string.settings_import_success_header, messageText);
refresh(); refresh();
} }
@ -860,22 +843,18 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}); });
} }
public void cancel() public void cancel() {
{
} }
}); });
dialog.show(); dialog.show();
} } catch (FileNotFoundException fnfe) {
catch (FileNotFoundException fnfe) String toastText = Accounts.this.getString(R.string.settings_import_failure, uri.getPath(), fnfe.getMessage());
{
String toastText = Accounts.this.getString(R.string.settings_import_failure, uri.getPath(), fnfe.getMessage() );
Toast toast = Toast.makeText(Accounts.this.getApplication(), toastText, 1); Toast toast = Toast.makeText(Accounts.this.getApplication(), toastText, 1);
toast.show(); toast.show();
} }
} }
private static void showDialog(final Activity activity, int headerRes, String message) private static void showDialog(final Activity activity, int headerRes, String message) {
{
final AlertDialog.Builder builder = new AlertDialog.Builder(activity); final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(headerRes); builder.setTitle(headerRes);
builder.setMessage(message); builder.setMessage(message);

View File

@ -37,8 +37,7 @@ public class ActivityListener extends MessagingListener {
String displayName = mLoadingFolderName; String displayName = mLoadingFolderName;
if (K9.INBOX.equalsIgnoreCase(displayName)) { if (K9.INBOX.equalsIgnoreCase(displayName)) {
displayName = context.getString(R.string.special_mailbox_name_inbox); displayName = context.getString(R.string.special_mailbox_name_inbox);
} } else if ((mAccount != null) && mAccount.getOutboxFolderName().equals(displayName)) {
else if ((mAccount != null) && mAccount.getOutboxFolderName().equals(displayName)) {
displayName = context.getString(R.string.special_mailbox_name_outbox); displayName = context.getString(R.string.special_mailbox_name_outbox);
} }

View File

@ -48,8 +48,7 @@ public class ExportHelper {
}); });
dialog.show(); dialog.show();
} }
private static void showDialog(final Activity activity, int headerRes, String message) private static void showDialog(final Activity activity, int headerRes, String message) {
{
final AlertDialog.Builder builder = new AlertDialog.Builder(activity); final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(headerRes); builder.setTitle(headerRes);
builder.setMessage(message); builder.setMessage(message);

View File

@ -151,8 +151,7 @@ public class FolderList extends K9ListActivity {
} }
} }
public void setProgress(boolean progress) public void setProgress(boolean progress) {
{
mHandler.progress(progress); mHandler.progress(progress);
} }

View File

@ -519,8 +519,7 @@ public class MessageList
} }
} }
public void setProgress(boolean progress) public void setProgress(boolean progress) {
{
mHandler.progress(progress); mHandler.progress(progress);
} }

View File

@ -853,12 +853,10 @@ public class AccountSettings extends K9PreferenceActivity {
// TODO: In the future the call above should be changed to only return remote folders. // TODO: In the future the call above should be changed to only return remote folders.
// For now we just remove the Outbox folder if present. // For now we just remove the Outbox folder if present.
Iterator<? extends Folder> iter = folders.iterator(); Iterator <? extends Folder > iter = folders.iterator();
while (iter.hasNext()) while (iter.hasNext()) {
{
Folder folder = iter.next(); Folder folder = iter.next();
if (mAccount.getOutboxFolderName().equals(folder.getName())) if (mAccount.getOutboxFolderName().equals(folder.getName())) {
{
iter.remove(); iter.remove();
} }
} }

View File

@ -142,8 +142,7 @@ public class MimeHeader {
} }
} }
public void setCharset(String charset) public void setCharset(String charset) {
{
mCharset = charset; mCharset = charset;
} }
} }

View File

@ -14,21 +14,18 @@ import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
public class K9Krypto public class K9Krypto {
{
final Base64 mBase64; final Base64 mBase64;
final Cipher mCipher; final Cipher mCipher;
private final static String AES = "AES"; private final static String AES = "AES";
private final static String SECURE_RANDOM_TYPE = "SHA1PRNG"; private final static String SECURE_RANDOM_TYPE = "SHA1PRNG";
public enum MODE public enum MODE {
{
ENCRYPT(Cipher.ENCRYPT_MODE), DECRYPT(Cipher.DECRYPT_MODE); ENCRYPT(Cipher.ENCRYPT_MODE), DECRYPT(Cipher.DECRYPT_MODE);
int mode; int mode;
private MODE(int nMode) private MODE(int nMode) {
{
mode = nMode; mode = nMode;
} }
} }
@ -56,8 +53,7 @@ public class K9Krypto
return new String(plainText); return new String(plainText);
} }
private Cipher setupCipher(int mode, byte[] processedKey) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException private Cipher setupCipher(int mode, byte[] processedKey) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {
{
SecretKeySpec secretKeySpec = new SecretKeySpec(processedKey, AES); SecretKeySpec secretKeySpec = new SecretKeySpec(processedKey, AES);
Cipher cipher = Cipher.getInstance(AES); Cipher cipher = Cipher.getInstance(AES);
cipher.init(mode, secretKeySpec); cipher.init(mode, secretKeySpec);