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

Switch to UNIX EOL style

This commit is contained in:
Fiouz 2010-10-03 11:08:42 +00:00
parent f1d413ce77
commit a3f4429963
5 changed files with 394 additions and 394 deletions

View File

@ -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<T> 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<T> mFolders;
/**
* All folders.
*/
private ArrayList<T> mOriginalValues = null;
/**
* Create a filter for a list of folders.
*
* @param folderNames
*/
public FolderListFilter(final ArrayAdapter<T> 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<T>(count);
for (int i = 0; i < count; i++)
{
mOriginalValues.add(mFolders.getItem(i));
}
}
if ((searchTerm == null) || (searchTerm.length() == 0))
{
ArrayList<T> list = new ArrayList<T>(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<T> values = mOriginalValues;
final int count = values.size();
final ArrayList<T> newValues = new ArrayList<T>();
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<T> folders = (List<T>) 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<T> 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<T> mFolders;
/**
* All folders.
*/
private ArrayList<T> mOriginalValues = null;
/**
* Create a filter for a list of folders.
*
* @param folderNames
*/
public FolderListFilter(final ArrayAdapter<T> 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<T>(count);
for (int i = 0; i < count; i++)
{
mOriginalValues.add(mFolders.getItem(i));
}
}
if ((searchTerm == null) || (searchTerm.length() == 0))
{
ArrayList<T> list = new ArrayList<T>(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<T> values = mOriginalValues;
final int count = values.size();
final ArrayList<T> newValues = new ArrayList<T>();
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<T> folders = (List<T>) 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;
}
}

View File

@ -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<? extends IAutoSync> 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<? extends IAutoSync> 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();
}
}

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -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();
}