diff --git a/src/com/fsck/k9/activity/FolderListFilter.java b/src/com/fsck/k9/activity/FolderListFilter.java index 9c5da9475..ea6b20e7f 100644 --- a/src/com/fsck/k9/activity/FolderListFilter.java +++ b/src/com/fsck/k9/activity/FolderListFilter.java @@ -1,143 +1,143 @@ -package com.fsck.k9.activity; - -import java.util.ArrayList; -import java.util.List; - -import android.util.Log; -import android.widget.ArrayAdapter; -import android.widget.Filter; - -import com.fsck.k9.K9; - -/** - * Filter to search for occurences of the search-expression in any place of the - * folder-name instead of doing jsut a prefix-search. - * - * @author Marcus@Wolschon.biz - */ -public class FolderListFilter extends Filter -{ - /** - * ArrayAdapter that contains the list of folders displayed in the - * ListView. - * This object is modified by {@link #publishResults} to reflect the - * changes due to the filtering performed by {@link #performFiltering}. - * This in turn will change the folders displayed in the ListView. - */ - private ArrayAdapter mFolders; - - /** - * All folders. - */ - private ArrayList mOriginalValues = null; - - /** - * Create a filter for a list of folders. - * - * @param folderNames - */ - public FolderListFilter(final ArrayAdapter folderNames) - { - this.mFolders = folderNames; - } - - /** - * Do the actual search. - * {@inheritDoc} - * - * @see #publishResults(CharSequence, FilterResults) - */ - @Override - protected FilterResults performFiltering(CharSequence searchTerm) - { - FilterResults results = new FilterResults(); - - // Copy the values from mFolders to mOriginalValues if this is the - // first time this method is called. - if (mOriginalValues == null) - { - int count = mFolders.getCount(); - mOriginalValues = new ArrayList(count); - for (int i = 0; i < count; i++) - { - mOriginalValues.add(mFolders.getItem(i)); - } - } - - if ((searchTerm == null) || (searchTerm.length() == 0)) - { - ArrayList list = new ArrayList(mOriginalValues); - results.values = list; - results.count = list.size(); - } - else - { - final String searchTermString = searchTerm.toString().toLowerCase(); - final String[] words = searchTermString.split(" "); - final int wordCount = words.length; - - final ArrayList values = mOriginalValues; - final int count = values.size(); - - final ArrayList newValues = new ArrayList(); - - for (int i = 0; i < count; i++) - { - final T value = values.get(i); - final String valueText = value.toString().toLowerCase(); - - for (int k = 0; k < wordCount; k++) - { - if (valueText.contains(words[k])) - { - newValues.add(value); - break; - } - } - } - - results.values = newValues; - results.count = newValues.size(); - } - - return results; - } - - /** - * Publish the results to the user-interface. - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - @Override - protected void publishResults(CharSequence constraint, FilterResults results) - { - // Don't notify for every change - mFolders.setNotifyOnChange(false); - - //noinspection unchecked - final List folders = (List) results.values; - mFolders.clear(); - if (folders != null) - { - for (T folder : folders) - { - if (folder != null) - { - mFolders.add(folder); - } - } - } - else - { - Log.w(K9.LOG_TAG, "FolderListFilter.publishResults - null search-result "); - } - - // Send notification that the data set changed now - mFolders.notifyDataSetChanged(); - } - - public void invalidate() - { - mOriginalValues = null; - } -} +package com.fsck.k9.activity; + +import java.util.ArrayList; +import java.util.List; + +import android.util.Log; +import android.widget.ArrayAdapter; +import android.widget.Filter; + +import com.fsck.k9.K9; + +/** + * Filter to search for occurences of the search-expression in any place of the + * folder-name instead of doing jsut a prefix-search. + * + * @author Marcus@Wolschon.biz + */ +public class FolderListFilter extends Filter +{ + /** + * ArrayAdapter that contains the list of folders displayed in the + * ListView. + * This object is modified by {@link #publishResults} to reflect the + * changes due to the filtering performed by {@link #performFiltering}. + * This in turn will change the folders displayed in the ListView. + */ + private ArrayAdapter mFolders; + + /** + * All folders. + */ + private ArrayList mOriginalValues = null; + + /** + * Create a filter for a list of folders. + * + * @param folderNames + */ + public FolderListFilter(final ArrayAdapter folderNames) + { + this.mFolders = folderNames; + } + + /** + * Do the actual search. + * {@inheritDoc} + * + * @see #publishResults(CharSequence, FilterResults) + */ + @Override + protected FilterResults performFiltering(CharSequence searchTerm) + { + FilterResults results = new FilterResults(); + + // Copy the values from mFolders to mOriginalValues if this is the + // first time this method is called. + if (mOriginalValues == null) + { + int count = mFolders.getCount(); + mOriginalValues = new ArrayList(count); + for (int i = 0; i < count; i++) + { + mOriginalValues.add(mFolders.getItem(i)); + } + } + + if ((searchTerm == null) || (searchTerm.length() == 0)) + { + ArrayList list = new ArrayList(mOriginalValues); + results.values = list; + results.count = list.size(); + } + else + { + final String searchTermString = searchTerm.toString().toLowerCase(); + final String[] words = searchTermString.split(" "); + final int wordCount = words.length; + + final ArrayList values = mOriginalValues; + final int count = values.size(); + + final ArrayList newValues = new ArrayList(); + + for (int i = 0; i < count; i++) + { + final T value = values.get(i); + final String valueText = value.toString().toLowerCase(); + + for (int k = 0; k < wordCount; k++) + { + if (valueText.contains(words[k])) + { + newValues.add(value); + break; + } + } + } + + results.values = newValues; + results.count = newValues.size(); + } + + return results; + } + + /** + * Publish the results to the user-interface. + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + protected void publishResults(CharSequence constraint, FilterResults results) + { + // Don't notify for every change + mFolders.setNotifyOnChange(false); + + //noinspection unchecked + final List folders = (List) results.values; + mFolders.clear(); + if (folders != null) + { + for (T folder : folders) + { + if (folder != null) + { + mFolders.add(folder); + } + } + } + else + { + Log.w(K9.LOG_TAG, "FolderListFilter.publishResults - null search-result "); + } + + // Send notification that the data set changed now + mFolders.notifyDataSetChanged(); + } + + public void invalidate() + { + mOriginalValues = null; + } +} diff --git a/src/com/fsck/k9/helper/AutoSyncHelper.java b/src/com/fsck/k9/helper/AutoSyncHelper.java index 07e9645e3..829130a06 100644 --- a/src/com/fsck/k9/helper/AutoSyncHelper.java +++ b/src/com/fsck/k9/helper/AutoSyncHelper.java @@ -1,137 +1,137 @@ -package com.fsck.k9.helper; - -import com.fsck.k9.K9; -import android.os.Build; -import android.util.Log; - -/** - * Helper class to get the current state of the auto-sync setting. - */ -public class AutoSyncHelper -{ - /** - * False, if we never tried to load the class for this SDK version. - * True, otherwise. +package com.fsck.k9.helper; + +import com.fsck.k9.K9; +import android.os.Build; +import android.util.Log; + +/** + * Helper class to get the current state of the auto-sync setting. + */ +public class AutoSyncHelper +{ + /** + * False, if we never tried to load the class for this SDK version. + * True, otherwise. * - * Note: if sAutoSync is null and sChecked is true, then an error occured - * while loading the class for the SDK version we're running on. - */ - private static boolean sChecked = false; - - /** - * Instance of the SDK specific class that implements the IAutoSync - * interface. - */ - private static IAutoSync sAutoSync = null; - - /** - * String for the auto-sync changed Intent. This isn't currently exposed by the API - */ - public static String SYNC_CONN_STATUS_CHANGE = "com.android.sync.SYNC_CONN_STATUS_CHANGED"; - /** - * Try loading the class that implements IAutoSync for this SDK version. + * Note: if sAutoSync is null and sChecked is true, then an error occured + * while loading the class for the SDK version we're running on. + */ + private static boolean sChecked = false; + + /** + * Instance of the SDK specific class that implements the IAutoSync + * interface. + */ + private static IAutoSync sAutoSync = null; + + /** + * String for the auto-sync changed Intent. This isn't currently exposed by the API + */ + public static String SYNC_CONN_STATUS_CHANGE = "com.android.sync.SYNC_CONN_STATUS_CHANGED"; + /** + * Try loading the class that implements IAutoSync for this SDK version. * - * @return the IAutoSync object for this SDK version, or null if something - * went wrong. - */ - private static IAutoSync loadAutoSync() - { - /* - * We're trying to load the class for this SDK version. If anything - * goes wrong after this point, we don't want to try again. - */ - sChecked = true; - - /* - * Check the version of the SDK we are running on. Choose an - * implementation class designed for that version of the SDK. - */ - int sdkVersion = Integer.parseInt(Build.VERSION.SDK); - - String className = null; - if (sdkVersion == Build.VERSION_CODES.CUPCAKE) - { - className = "com.fsck.k9.helper.AutoSyncSdk3"; - } - else if (sdkVersion == Build.VERSION_CODES.DONUT) - { - className = "com.fsck.k9.helper.AutoSyncSdk4"; - } - else if (sdkVersion >= Build.VERSION_CODES.ECLAIR) - { - className = "com.fsck.k9.helper.AutoSyncSdk5"; - } - - /* - * Find the required class by name and instantiate it. - */ - try - { - Class clazz = - Class.forName(className).asSubclass(IAutoSync.class); - - IAutoSync autoSync = clazz.newInstance(); - autoSync.initialize(K9.app); - - return autoSync; - } - catch (ClassNotFoundException e) - { - Log.e(K9.LOG_TAG, "Couldn't find class: " + className, e); - } - catch (InstantiationException e) - { - Log.e(K9.LOG_TAG, "Couldn't instantiate class: " + className, e); - } - catch (IllegalAccessException e) - { - Log.e(K9.LOG_TAG, "Couldn't access class: " + className, e); - } - catch (NoSuchMethodException e) - { - if (K9.DEBUG) - { - Log.d(K9.LOG_TAG, "Couldn't load method to get auto-sync state", e); - } - } - return null; - } - - /** - * Checks whether we can query the auto-sync state using - * getMasterSyncAutomatically() or not. + * @return the IAutoSync object for this SDK version, or null if something + * went wrong. + */ + private static IAutoSync loadAutoSync() + { + /* + * We're trying to load the class for this SDK version. If anything + * goes wrong after this point, we don't want to try again. + */ + sChecked = true; + + /* + * Check the version of the SDK we are running on. Choose an + * implementation class designed for that version of the SDK. + */ + int sdkVersion = Integer.parseInt(Build.VERSION.SDK); + + String className = null; + if (sdkVersion == Build.VERSION_CODES.CUPCAKE) + { + className = "com.fsck.k9.helper.AutoSyncSdk3"; + } + else if (sdkVersion == Build.VERSION_CODES.DONUT) + { + className = "com.fsck.k9.helper.AutoSyncSdk4"; + } + else if (sdkVersion >= Build.VERSION_CODES.ECLAIR) + { + className = "com.fsck.k9.helper.AutoSyncSdk5"; + } + + /* + * Find the required class by name and instantiate it. + */ + try + { + Class clazz = + Class.forName(className).asSubclass(IAutoSync.class); + + IAutoSync autoSync = clazz.newInstance(); + autoSync.initialize(K9.app); + + return autoSync; + } + catch (ClassNotFoundException e) + { + Log.e(K9.LOG_TAG, "Couldn't find class: " + className, e); + } + catch (InstantiationException e) + { + Log.e(K9.LOG_TAG, "Couldn't instantiate class: " + className, e); + } + catch (IllegalAccessException e) + { + Log.e(K9.LOG_TAG, "Couldn't access class: " + className, e); + } + catch (NoSuchMethodException e) + { + if (K9.DEBUG) + { + Log.d(K9.LOG_TAG, "Couldn't load method to get auto-sync state", e); + } + } + return null; + } + + /** + * Checks whether we can query the auto-sync state using + * getMasterSyncAutomatically() or not. * - * @return true, if calls to getMasterSyncAutomatically() will return the - * state of the auto-sync setting. false, otherwise. - */ - public static boolean isAvailable() - { - if (!sChecked) - { - sAutoSync = loadAutoSync(); - } - return (sAutoSync != null); - } - - /** - * Query the state of the auto-sync setting. + * @return true, if calls to getMasterSyncAutomatically() will return the + * state of the auto-sync setting. false, otherwise. + */ + public static boolean isAvailable() + { + if (!sChecked) + { + sAutoSync = loadAutoSync(); + } + return (sAutoSync != null); + } + + /** + * Query the state of the auto-sync setting. * - * @return the state of the auto-sync setting. - * @see IAutoSync - */ - public static boolean getMasterSyncAutomatically() - { - if (!sChecked) - { - sAutoSync = loadAutoSync(); - } - - if (sAutoSync == null) - { - throw new RuntimeException( + * @return the state of the auto-sync setting. + * @see IAutoSync + */ + public static boolean getMasterSyncAutomatically() + { + if (!sChecked) + { + sAutoSync = loadAutoSync(); + } + + if (sAutoSync == null) + { + throw new RuntimeException( "Called getMasterSyncAutomatically() before checking if it's available."); - } - - return sAutoSync.getMasterSyncAutomatically(); - } -} + } + + return sAutoSync.getMasterSyncAutomatically(); + } +} diff --git a/src/com/fsck/k9/helper/AutoSyncSdk3.java b/src/com/fsck/k9/helper/AutoSyncSdk3.java index cb3f67fcb..a317a4781 100644 --- a/src/com/fsck/k9/helper/AutoSyncSdk3.java +++ b/src/com/fsck/k9/helper/AutoSyncSdk3.java @@ -1,48 +1,48 @@ -package com.fsck.k9.helper; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import android.content.ContentResolver; -import android.content.Context; -import android.os.Handler; - -public class AutoSyncSdk3 implements IAutoSync -{ - private Method mGetListenForNetworkTickles; - private Object mQueryMap; - - public void initialize(Context context) throws NoSuchMethodException - { - /* - * There's no documented/official way to query the state of the - * auto-sync setting for a normal application in SDK 1.5/API 3. +package com.fsck.k9.helper; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import android.content.ContentResolver; +import android.content.Context; +import android.os.Handler; + +public class AutoSyncSdk3 implements IAutoSync +{ + private Method mGetListenForNetworkTickles; + private Object mQueryMap; + + public void initialize(Context context) throws NoSuchMethodException + { + /* + * There's no documented/official way to query the state of the + * auto-sync setting for a normal application in SDK 1.5/API 3. * - * We use reflection to get an Sync.Settings.QueryMap" object, so we - * can call its getListenForNetworkTickles() method. This will return - * the current auto-sync state. - */ - try - { - Class clazz = Class.forName("android.provider.Sync$Settings$QueryMap"); - Constructor c = clazz.getConstructor(ContentResolver.class, boolean.class, Handler.class); - mQueryMap = c.newInstance(context.getContentResolver(), true, null); - mGetListenForNetworkTickles = mQueryMap.getClass().getMethod("getListenForNetworkTickles"); - } - catch (Exception e) - { - throw new NoSuchMethodException(); - } - } - - public boolean getMasterSyncAutomatically() - { - try - { - return (Boolean) mGetListenForNetworkTickles.invoke(mQueryMap); - } - catch (Exception e) - { - return false; - } - } -} + * We use reflection to get an Sync.Settings.QueryMap" object, so we + * can call its getListenForNetworkTickles() method. This will return + * the current auto-sync state. + */ + try + { + Class clazz = Class.forName("android.provider.Sync$Settings$QueryMap"); + Constructor c = clazz.getConstructor(ContentResolver.class, boolean.class, Handler.class); + mQueryMap = c.newInstance(context.getContentResolver(), true, null); + mGetListenForNetworkTickles = mQueryMap.getClass().getMethod("getListenForNetworkTickles"); + } + catch (Exception e) + { + throw new NoSuchMethodException(); + } + } + + public boolean getMasterSyncAutomatically() + { + try + { + return (Boolean) mGetListenForNetworkTickles.invoke(mQueryMap); + } + catch (Exception e) + { + return false; + } + } +} diff --git a/src/com/fsck/k9/helper/AutoSyncSdk4.java b/src/com/fsck/k9/helper/AutoSyncSdk4.java index fce44ebee..f0bb766c3 100644 --- a/src/com/fsck/k9/helper/AutoSyncSdk4.java +++ b/src/com/fsck/k9/helper/AutoSyncSdk4.java @@ -1,50 +1,50 @@ -package com.fsck.k9.helper; - -import java.lang.reflect.Method; - -import com.fsck.k9.K9; - -import android.content.ContentResolver; -import android.content.Context; -import android.util.Log; - -public class AutoSyncSdk4 implements IAutoSync -{ - private Method mGetListenForNetworkTickles; - private Object mContentService; - - public void initialize(Context context) throws NoSuchMethodException - { - /* - * There's no documented/official way to query the state of the - * auto-sync setting for a normal application in SDK 1.6/API 4. +package com.fsck.k9.helper; + +import java.lang.reflect.Method; + +import com.fsck.k9.K9; + +import android.content.ContentResolver; +import android.content.Context; +import android.util.Log; + +public class AutoSyncSdk4 implements IAutoSync +{ + private Method mGetListenForNetworkTickles; + private Object mContentService; + + public void initialize(Context context) throws NoSuchMethodException + { + /* + * There's no documented/official way to query the state of the + * auto-sync setting for a normal application in SDK 1.6/API 4. * - * We use reflection to get an ContentService object, so we can call its - * getListenForNetworkTickles() method. This will return the current - * auto-sync state. - */ - try - { - Method getContentService = ContentResolver.class.getMethod("getContentService"); - mContentService = getContentService.invoke(null); - mGetListenForNetworkTickles = mContentService.getClass().getMethod("getListenForNetworkTickles"); - } - catch (Exception e) - { - throw new NoSuchMethodException(); - } - } - - public boolean getMasterSyncAutomatically() - { - try - { - return (Boolean) mGetListenForNetworkTickles.invoke(mContentService); - } - catch (Exception e) - { - Log.e(K9.LOG_TAG, "Could not query for network tickle", e); - return true; - } - } -} + * We use reflection to get an ContentService object, so we can call its + * getListenForNetworkTickles() method. This will return the current + * auto-sync state. + */ + try + { + Method getContentService = ContentResolver.class.getMethod("getContentService"); + mContentService = getContentService.invoke(null); + mGetListenForNetworkTickles = mContentService.getClass().getMethod("getListenForNetworkTickles"); + } + catch (Exception e) + { + throw new NoSuchMethodException(); + } + } + + public boolean getMasterSyncAutomatically() + { + try + { + return (Boolean) mGetListenForNetworkTickles.invoke(mContentService); + } + catch (Exception e) + { + Log.e(K9.LOG_TAG, "Could not query for network tickle", e); + return true; + } + } +} diff --git a/src/com/fsck/k9/helper/IAutoSync.java b/src/com/fsck/k9/helper/IAutoSync.java index d396b2303..76d643087 100644 --- a/src/com/fsck/k9/helper/IAutoSync.java +++ b/src/com/fsck/k9/helper/IAutoSync.java @@ -1,27 +1,27 @@ -package com.fsck.k9.helper; - -import android.content.Context; - -/** - * Classes that implement this interface know how to query the system for the - * current state of the auto-sync setting. This method differs from SDK 3 to +package com.fsck.k9.helper; + +import android.content.Context; + +/** + * Classes that implement this interface know how to query the system for the + * current state of the auto-sync setting. This method differs from SDK 3 to * SDK 5, so there are specialized implementations for each SDK version. - */ -public interface IAutoSync -{ - /** - * Do the necessary reflection magic to get the necessary objects and/or - * methods to later query the state of the auto-sync setting. + */ +public interface IAutoSync +{ + /** + * Do the necessary reflection magic to get the necessary objects and/or + * methods to later query the state of the auto-sync setting. * - * @param context The application context object. + * @param context The application context object. * @throws NoSuchMethodException if something went wrong. - */ - public void initialize(Context context) throws NoSuchMethodException; - - /** - * Query the state of the auto-sync setting. + */ + public void initialize(Context context) throws NoSuchMethodException; + + /** + * Query the state of the auto-sync setting. * - * @return the state of the auto-sync setting. - */ - public boolean getMasterSyncAutomatically(); -} + * @return the state of the auto-sync setting. + */ + public boolean getMasterSyncAutomatically(); +}