1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00
This commit is contained in:
danapple 2011-03-20 15:21:24 -05:00
parent 2e7a785209
commit 8e5c50a8ef
14 changed files with 1010 additions and 1074 deletions

View File

@ -347,18 +347,15 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
outState.putSerializable(ACCOUNT_STATS, accountStats);
}
private StorageManager.StorageListener storageListener = new StorageManager.StorageListener()
{
private StorageManager.StorageListener storageListener = new StorageManager.StorageListener() {
@Override
public void onUnmount(String providerId)
{
public void onUnmount(String providerId) {
refresh();
}
@Override
public void onMount(String providerId)
{
public void onMount(String providerId) {
refresh();
}
};
@ -858,11 +855,9 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
Log.i(K9.LOG_TAG, "onImport importing from URI " + uri.getPath());
final String fileName = uri.getPath();
AsyncUIProcessor.getInstance(Accounts.this.getApplication()).importSettings(this, uri, new ImportListener()
{
AsyncUIProcessor.getInstance(Accounts.this.getApplication()).importSettings(this, uri, new ImportListener() {
@Override
public void success(int numAccounts)
{
public void success(int numAccounts) {
mHandler.progress(false);
String messageText =
numAccounts != 1
@ -871,33 +866,28 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
showDialog(Accounts.this, R.string.settings_import_success_header, messageText);
runOnUiThread(new Runnable() {
@Override
public void run()
{
public void run() {
refresh();
}
});
}
@Override
public void failure(String message, Exception e)
{
public void failure(String message, Exception e) {
mHandler.progress(false);
showDialog(Accounts.this, R.string.settings_import_failed_header, Accounts.this.getString(R.string.settings_import_failure, fileName, e.getLocalizedMessage()));
}
@Override
public void canceled()
{
public void canceled() {
mHandler.progress(false);
}
@Override
public void started()
{
public void started() {
runOnUiThread(new Runnable() {
@Override
public void run()
{
public void run() {
mHandler.progress(true);
String toastText = Accounts.this.getString(R.string.settings_importing);
Toast toast = Toast.makeText(Accounts.this, toastText, Toast.LENGTH_SHORT);
@ -911,8 +901,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
private void showDialog(final Context context, final int headerRes, final String message) {
this.runOnUiThread(new Runnable() {
@Override
public void run()
{
public void run() {
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(headerRes);
builder.setMessage(message);

View File

@ -72,8 +72,7 @@ public class AsyncUIProcessor {
try {
ContentResolver resolver = mApplication.getContentResolver();
is = resolver.openInputStream(uri);
}
catch (Exception e) {
} catch (Exception e) {
Log.w(K9.LOG_TAG, "Exception while resolving Uri to InputStream", e);
if (listener != null) {
listener.failure(e.getLocalizedMessage(), e);
@ -107,8 +106,7 @@ public class AsyncUIProcessor {
}
@Override
public void started()
{
public void started() {
if (listener != null) {
listener.started();
}
@ -119,13 +117,11 @@ public class AsyncUIProcessor {
);
}
private void quietClose(InputStream is)
{
private void quietClose(InputStream is) {
if (is != null) {
try {
is.close();
}
catch (Exception e) {
} catch (Exception e) {
Log.w(K9.LOG_TAG, "Unable to close inputStream", e);
}
}

View File

@ -20,16 +20,14 @@ public class ExportHelper {
AsyncUIProcessor.getInstance(activity.getApplication()).exportSettings(activity, version, uuid, new ExportListener() {
@Override
public void canceled()
{
public void canceled() {
if (listener != null) {
listener.canceled();
}
}
@Override
public void failure(String message, Exception e)
{
public void failure(String message, Exception e) {
if (listener != null) {
listener.failure(message, e);
}
@ -37,16 +35,14 @@ public class ExportHelper {
}
@Override
public void started()
{
public void started() {
if (listener != null) {
listener.started();
}
activity.runOnUiThread(new Runnable() {
@Override
public void run()
{
public void run() {
String toastText = activity.getString(R.string.settings_exporting);
Toast toast = Toast.makeText(activity, toastText, Toast.LENGTH_SHORT);
toast.show();
@ -55,8 +51,7 @@ public class ExportHelper {
}
@Override
public void success(String fileName)
{
public void success(String fileName) {
if (listener != null) {
listener.success(fileName);
}
@ -64,8 +59,7 @@ public class ExportHelper {
}
@Override
public void success()
{
public void success() {
// This one should never be called here because the AsyncUIProcessor will generate a filename
}
});
@ -75,8 +69,7 @@ public class ExportHelper {
activity.runOnUiThread(new Runnable() {
@Override
public void run()
{
public void run() {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(headerRes);
builder.setMessage(message);

View File

@ -167,36 +167,30 @@ public class K9Activity extends Activity {
}
public void onExport(final Account account) {
ExportHelper.exportSettings(this, account, new ExportListener()
{
ExportHelper.exportSettings(this, account, new ExportListener() {
@Override
public void canceled()
{
public void canceled() {
setProgress(false);
}
@Override
public void failure(String message, Exception e)
{
public void failure(String message, Exception e) {
setProgress(false);
}
@Override
public void started()
{
public void started() {
setProgress(true);
}
@Override
public void success(String fileName)
{
public void success(String fileName) {
setProgress(false);
}
@Override
public void success()
{
public void success() {
setProgress(false);
}
});

View File

@ -94,36 +94,30 @@ public class K9ListActivity extends ListActivity {
}
public void onExport(final Account account) {
ExportHelper.exportSettings(this, account, new ExportListener()
{
ExportHelper.exportSettings(this, account, new ExportListener() {
@Override
public void canceled()
{
public void canceled() {
setProgress(false);
}
@Override
public void failure(String message, Exception e)
{
public void failure(String message, Exception e) {
setProgress(false);
}
@Override
public void started()
{
public void started() {
setProgress(true);
}
@Override
public void success(String fileName)
{
public void success(String fileName) {
setProgress(false);
}
@Override
public void success()
{
public void success() {
setProgress(false);
}
});

View File

@ -4,8 +4,7 @@ import java.io.OutputStream;
import android.content.Context;
public interface IStorageExporter
{
public interface IStorageExporter {
public boolean needsKey();
public void exportPreferences(Context context, String uuid, OutputStream os, String encryptionKey) throws StorageImportExportException;
}

View File

@ -13,8 +13,7 @@ import com.fsck.k9.activity.AsyncUIProcessor;
import com.fsck.k9.activity.ExportListener;
import com.fsck.k9.activity.PasswordEntryDialog;
public class StorageExporter
{
public class StorageExporter {
private static void exportPreferences(Activity activity, String version, String uuid, String fileName, OutputStream os, String encryptionKey, final ExportListener listener) {
try {
IStorageExporter storageExporter = StorageVersioning.createExporter(version);
@ -23,15 +22,12 @@ public class StorageExporter
}
if (storageExporter.needsKey() && encryptionKey == null) {
gatherPassword(activity, storageExporter, uuid, fileName, os, listener);
}
else
{
} else {
finishExport(activity, storageExporter, uuid, fileName, os, encryptionKey, listener);
}
}
catch (Exception e)
{
catch (Exception e) {
if (listener != null) {
listener.failure(e.getLocalizedMessage(), e);
}
@ -50,8 +46,7 @@ public class StorageExporter
activity.runOnUiThread(new Runnable() {
@Override
public void run()
{
public void run() {
PasswordEntryDialog dialog = new PasswordEntryDialog(activity, activity.getString(R.string.settings_encryption_password_prompt),
new PasswordEntryDialog.PasswordEntryListener() {
public void passwordChosen(final String chosenPassword) {
@ -59,12 +54,10 @@ public class StorageExporter
AsyncUIProcessor.getInstance(activity.getApplication()).execute(new Runnable() {
@Override
public void run()
{
public void run() {
try {
finishExport(activity, storageExporter, uuid, fileName, os, chosenPassword, listener);
}
catch (Exception e) {
} catch (Exception e) {
Log.w(K9.LOG_TAG, "Exception while finishing export", e);
if (listener != null) {
listener.failure(e.getLocalizedMessage(), e);
@ -105,25 +98,20 @@ public class StorageExporter
if (listener != null) {
if (fileName != null) {
listener.success(fileName);
}
else {
} else {
listener.success();
}
}
}
else {
} else {
throw new StorageImportExportException("Internal error; no fileName or OutputStream", null);
}
}
catch (Exception e) {
} catch (Exception e) {
throw new StorageImportExportException(e.getLocalizedMessage(), e);
}
finally {
} finally {
if (needToClose && os != null) {
try {
os.close();
}
catch (Exception e) {
} catch (Exception e) {
Log.w(K9.LOG_TAG, "Unable to close OutputStream", e);
}
}

View File

@ -85,8 +85,7 @@ public class StorageExporterVersion1 implements IStorageExporter {
}
@Override
public boolean needsKey()
{
public boolean needsKey() {
return true;
}
}

View File

@ -43,19 +43,15 @@ public class StorageImporter {
Log.i(K9.LOG_TAG, "Got settings file version " + version);
IStorageImporter storageImporter = StorageVersioning.createImporter(version);
if (storageImporter == null)
{
if (storageImporter == null) {
throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, version));
}
if (storageImporter.needsKey() && providedEncryptionKey == null) {
gatherPassword(activity, storageImporter, dataset, listener);
}
else {
} else {
finishImport(activity, storageImporter, dataset, providedEncryptionKey, listener);
}
}
catch (Exception e)
{
} catch (Exception e) {
if (listener != null) {
listener.failure(e.getLocalizedMessage(), e);
}
@ -84,22 +80,18 @@ public class StorageImporter {
}
private static void gatherPassword(final Activity activity, final IStorageImporter storageImporter, final ImportElement dataset, final ImportListener listener) {
activity.runOnUiThread(new Runnable()
{
activity.runOnUiThread(new Runnable() {
@Override
public void run()
{
public void run() {
PasswordEntryDialog dialog = new PasswordEntryDialog(activity, activity.getString(R.string.settings_encryption_password_prompt),
new PasswordEntryDialog.PasswordEntryListener() {
public void passwordChosen(final String chosenPassword) {
AsyncUIProcessor.getInstance(activity.getApplication()).execute(new Runnable() {
@Override
public void run()
{
public void run() {
try {
finishImport(activity, storageImporter, dataset, chosenPassword, listener);
}
catch (Exception e) {
} catch (Exception e) {
Log.w(K9.LOG_TAG, "Failure during import", e);
if (listener != null) {
listener.failure(e.getLocalizedMessage(), e);

View File

@ -88,8 +88,7 @@ public class StorageImporterVersion1 implements IStorageImporter {
}
@Override
public boolean needsKey()
{
public boolean needsKey() {
return true;
}
}

View File

@ -4,8 +4,7 @@ import java.util.HashMap;
import java.util.Map;
public class StorageVersioning
{
public class StorageVersioning {
public enum STORAGE_VERSION {
VERSION1(StorageImporterVersion1.class, StorageExporterVersion1.class, true, STORAGE_VERSION_1);
@ -52,31 +51,25 @@ public class StorageVersioning
versionMap.put(STORAGE_VERSION.VERSION1.getVersionString(), STORAGE_VERSION.VERSION1);
}
public static IStorageImporter createImporter(String version) throws InstantiationException, IllegalAccessException
{
public static IStorageImporter createImporter(String version) throws InstantiationException, IllegalAccessException {
STORAGE_VERSION storageVersion = versionMap.get(version);
if (storageVersion == null)
{
if (storageVersion == null) {
return null;
}
return storageVersion.createImporter();
}
public static IStorageExporter createExporter(String version) throws InstantiationException, IllegalAccessException
{
public static IStorageExporter createExporter(String version) throws InstantiationException, IllegalAccessException {
STORAGE_VERSION storageVersion = versionMap.get(version);
if (storageVersion == null)
{
if (storageVersion == null) {
return null;
}
return storageVersion.createExporter();
}
public Boolean needsKey(String version)
{
public Boolean needsKey(String version) {
STORAGE_VERSION storageVersion = versionMap.get(version);
if (storageVersion == null)
{
if (storageVersion == null) {
return null;
}
return storageVersion.needsKey();