2008-11-01 17:32:06 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.Context;
|
2010-03-22 23:19:12 -04:00
|
|
|
import android.os.Build;
|
2008-11-01 17:32:06 -04:00
|
|
|
import android.widget.ResourceCursorAdapter;
|
|
|
|
|
2010-03-22 23:19:12 -04:00
|
|
|
public abstract class EmailAddressAdapter extends ResourceCursorAdapter
|
2009-11-24 19:40:29 -05:00
|
|
|
{
|
2010-03-22 23:19:12 -04:00
|
|
|
private static EmailAddressAdapter sInstance;
|
|
|
|
private static Context sContext;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-03-22 23:19:12 -04:00
|
|
|
public static EmailAddressAdapter getInstance(Context context)
|
2009-11-24 19:40:29 -05:00
|
|
|
{
|
2010-03-22 23:19:12 -04:00
|
|
|
if (sInstance == null)
|
|
|
|
{
|
|
|
|
String className;
|
|
|
|
|
|
|
|
sContext = context;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the version of the SDK we are running on. Choose an
|
|
|
|
* implementation class designed for that version of the SDK.
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
int sdkVersion = Integer.parseInt(Build.VERSION.SDK); // Cupcake style
|
|
|
|
if (sdkVersion < Build.VERSION_CODES.ECLAIR)
|
|
|
|
{
|
|
|
|
className = "com.fsck.k9.EmailAddressAdapterSdk3_4";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
className = "com.fsck.k9.EmailAddressAdapterSdk5";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the required class by name and instantiate it.
|
|
|
|
*/
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Class<? extends EmailAddressAdapter> clazz =
|
2010-04-29 00:59:14 -04:00
|
|
|
Class.forName(className).asSubclass(EmailAddressAdapter.class);
|
2010-03-22 23:19:12 -04:00
|
|
|
sInstance = clazz.newInstance();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
throw new IllegalStateException(e);
|
|
|
|
}
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-03-22 23:19:12 -04:00
|
|
|
return sInstance;
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2010-03-22 23:19:12 -04:00
|
|
|
public static Context getContext()
|
2009-11-24 19:40:29 -05:00
|
|
|
{
|
2010-03-22 23:19:12 -04:00
|
|
|
return sContext;
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2010-03-22 23:19:12 -04:00
|
|
|
protected ContentResolver mContentResolver;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-03-22 23:19:12 -04:00
|
|
|
public EmailAddressAdapter()
|
2009-11-24 19:40:29 -05:00
|
|
|
{
|
2010-03-22 23:19:12 -04:00
|
|
|
super(getContext(), R.layout.recipient_dropdown_item, null);
|
|
|
|
mContentResolver = getContext().getContentResolver();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|