mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 17:18:50 -05:00
Patch for issue 946: Only able to get contacts from a primary google
account by cketti
This commit is contained in:
parent
85b65ca272
commit
8ca034c3db
@ -4,7 +4,7 @@
|
|||||||
android:versionName="2.513" package="com.fsck.k9">
|
android:versionName="2.513" package="com.fsck.k9">
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="3"
|
android:minSdkVersion="3"
|
||||||
android:targetSdkVersion="4"
|
android:targetSdkVersion="5"
|
||||||
/>
|
/>
|
||||||
<supports-screens
|
<supports-screens
|
||||||
largeScreens="true"
|
largeScreens="true"
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
application-package=com.fsck.k9
|
application-package=com.fsck.k9
|
||||||
target=android-4
|
target=android-5
|
||||||
|
@ -18,78 +18,65 @@ package com.fsck.k9;
|
|||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.os.Build;
|
||||||
import android.database.DatabaseUtils;
|
|
||||||
import android.provider.Contacts.ContactMethods;
|
|
||||||
import android.provider.Contacts.People;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.ResourceCursorAdapter;
|
import android.widget.ResourceCursorAdapter;
|
||||||
import android.widget.TextView;
|
|
||||||
import com.fsck.k9.mail.Address;
|
|
||||||
|
|
||||||
import static android.provider.Contacts.ContactMethods.CONTENT_EMAIL_URI;
|
public abstract class EmailAddressAdapter extends ResourceCursorAdapter
|
||||||
|
|
||||||
public class EmailAddressAdapter extends ResourceCursorAdapter
|
|
||||||
{
|
{
|
||||||
public static final int NAME_INDEX = 1;
|
private static EmailAddressAdapter sInstance;
|
||||||
|
private static Context sContext;
|
||||||
|
|
||||||
public static final int DATA_INDEX = 2;
|
public static EmailAddressAdapter getInstance(Context context)
|
||||||
|
|
||||||
private static final String SORT_ORDER = People.TIMES_CONTACTED + " DESC, " + People.NAME;
|
|
||||||
|
|
||||||
private ContentResolver mContentResolver;
|
|
||||||
|
|
||||||
private static final String[] PROJECTION =
|
|
||||||
{
|
{
|
||||||
ContactMethods._ID, // 0
|
if (sInstance == null)
|
||||||
ContactMethods.NAME, // 1
|
|
||||||
ContactMethods.DATA
|
|
||||||
// 2
|
|
||||||
};
|
|
||||||
|
|
||||||
public EmailAddressAdapter(Context context)
|
|
||||||
{
|
{
|
||||||
super(context, R.layout.recipient_dropdown_item, null);
|
String className;
|
||||||
mContentResolver = context.getContentResolver();
|
|
||||||
|
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";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public final String convertToString(Cursor cursor)
|
* Find the required class by name and instantiate it.
|
||||||
|
*/
|
||||||
|
try
|
||||||
{
|
{
|
||||||
String name = cursor.getString(NAME_INDEX);
|
Class<? extends EmailAddressAdapter> clazz =
|
||||||
String address = cursor.getString(DATA_INDEX);
|
Class.forName(className).asSubclass(EmailAddressAdapter.class);
|
||||||
|
sInstance = clazz.newInstance();
|
||||||
return new Address(address, name).toString();
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
return sInstance;
|
||||||
public final void bindView(View view, Context context, Cursor cursor)
|
|
||||||
{
|
|
||||||
TextView text1 = (TextView)view.findViewById(R.id.text1);
|
|
||||||
TextView text2 = (TextView)view.findViewById(R.id.text2);
|
|
||||||
text1.setText(cursor.getString(NAME_INDEX));
|
|
||||||
text2.setText(cursor.getString(DATA_INDEX));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static Context getContext()
|
||||||
public Cursor runQueryOnBackgroundThread(CharSequence constraint)
|
|
||||||
{
|
{
|
||||||
String where = null;
|
return sContext;
|
||||||
|
|
||||||
if (constraint != null)
|
|
||||||
{
|
|
||||||
String filter = DatabaseUtils.sqlEscapeString(constraint.toString() + '%');
|
|
||||||
|
|
||||||
StringBuilder s = new StringBuilder();
|
|
||||||
s.append("("+People.NAME+" LIKE ");
|
|
||||||
s.append(filter);
|
|
||||||
s.append(") OR ("+ContactMethods.DATA+" LIKE ");
|
|
||||||
s.append(filter);
|
|
||||||
s.append(")");
|
|
||||||
|
|
||||||
where = s.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mContentResolver.query(CONTENT_EMAIL_URI, PROJECTION, where, null, SORT_ORDER);
|
protected ContentResolver mContentResolver;
|
||||||
|
|
||||||
|
public EmailAddressAdapter()
|
||||||
|
{
|
||||||
|
super(getContext(), R.layout.recipient_dropdown_item, null);
|
||||||
|
mContentResolver = getContext().getContentResolver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
84
src/com/fsck/k9/EmailAddressAdapterSdk3_4.java
Normal file
84
src/com/fsck/k9/EmailAddressAdapterSdk3_4.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.fsck.k9;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.DatabaseUtils;
|
||||||
|
import android.provider.Contacts.ContactMethods;
|
||||||
|
import android.provider.Contacts.People;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import com.fsck.k9.mail.Address;
|
||||||
|
|
||||||
|
import static android.provider.Contacts.ContactMethods.CONTENT_EMAIL_URI;
|
||||||
|
|
||||||
|
public class EmailAddressAdapterSdk3_4 extends EmailAddressAdapter
|
||||||
|
{
|
||||||
|
public static final int NAME_INDEX = 1;
|
||||||
|
|
||||||
|
public static final int DATA_INDEX = 2;
|
||||||
|
|
||||||
|
private static final String SORT_ORDER = People.TIMES_CONTACTED + " DESC, " + People.NAME;
|
||||||
|
|
||||||
|
private static final String[] PROJECTION =
|
||||||
|
{
|
||||||
|
ContactMethods._ID, // 0
|
||||||
|
ContactMethods.NAME, // 1
|
||||||
|
ContactMethods.DATA // 2
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String convertToString(Cursor cursor)
|
||||||
|
{
|
||||||
|
String name = cursor.getString(NAME_INDEX);
|
||||||
|
String address = cursor.getString(DATA_INDEX);
|
||||||
|
|
||||||
|
return new Address(address, name).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void bindView(View view, Context context, Cursor cursor)
|
||||||
|
{
|
||||||
|
TextView text1 = (TextView)view.findViewById(R.id.text1);
|
||||||
|
TextView text2 = (TextView)view.findViewById(R.id.text2);
|
||||||
|
text1.setText(cursor.getString(NAME_INDEX));
|
||||||
|
text2.setText(cursor.getString(DATA_INDEX));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cursor runQueryOnBackgroundThread(CharSequence constraint)
|
||||||
|
{
|
||||||
|
String where = null;
|
||||||
|
|
||||||
|
if (constraint != null)
|
||||||
|
{
|
||||||
|
String filter = DatabaseUtils.sqlEscapeString(constraint.toString() + '%');
|
||||||
|
|
||||||
|
StringBuilder s = new StringBuilder();
|
||||||
|
s.append("("+People.NAME+" LIKE ");
|
||||||
|
s.append(filter);
|
||||||
|
s.append(") OR ("+ContactMethods.DATA+" LIKE ");
|
||||||
|
s.append(filter);
|
||||||
|
s.append(")");
|
||||||
|
|
||||||
|
where = s.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return mContentResolver.query(CONTENT_EMAIL_URI, PROJECTION, where, null, SORT_ORDER);
|
||||||
|
}
|
||||||
|
}
|
78
src/com/fsck/k9/EmailAddressAdapterSdk5.java
Normal file
78
src/com/fsck/k9/EmailAddressAdapterSdk5.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.fsck.k9;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.provider.ContactsContract.Contacts;
|
||||||
|
import android.provider.ContactsContract.CommonDataKinds.Email;
|
||||||
|
import android.provider.ContactsContract.Contacts.Data;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import com.fsck.k9.mail.Address;
|
||||||
|
|
||||||
|
public class EmailAddressAdapterSdk5 extends EmailAddressAdapter
|
||||||
|
{
|
||||||
|
public static final int NAME_INDEX = 1;
|
||||||
|
public static final int DATA_INDEX = 2;
|
||||||
|
|
||||||
|
private static final String SORT_ORDER = Contacts.TIMES_CONTACTED
|
||||||
|
+ " DESC, " + Contacts.DISPLAY_NAME;
|
||||||
|
|
||||||
|
private static final String[] PROJECTION = {
|
||||||
|
Data._ID, // 0
|
||||||
|
Contacts.DISPLAY_NAME, // 1
|
||||||
|
Email.DATA // 2
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String convertToString(Cursor cursor)
|
||||||
|
{
|
||||||
|
String name = cursor.getString(NAME_INDEX);
|
||||||
|
String address = cursor.getString(DATA_INDEX);
|
||||||
|
|
||||||
|
return new Address(address, name).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void bindView(View view, Context context, Cursor cursor)
|
||||||
|
{
|
||||||
|
TextView text1 = (TextView) view.findViewById(R.id.text1);
|
||||||
|
TextView text2 = (TextView) view.findViewById(R.id.text2);
|
||||||
|
text1.setText(cursor.getString(NAME_INDEX));
|
||||||
|
text2.setText(cursor.getString(DATA_INDEX));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cursor runQueryOnBackgroundThread(CharSequence constraint)
|
||||||
|
{
|
||||||
|
String filter = constraint == null ? "" : constraint.toString();
|
||||||
|
Uri uri = Uri.withAppendedPath(Email.CONTENT_FILTER_URI, Uri.encode(filter));
|
||||||
|
Cursor c = mContentResolver.query(uri, PROJECTION, null, null, SORT_ORDER);
|
||||||
|
// To prevent expensive execution in the UI thread
|
||||||
|
// Cursors get lazily executed, so if you don't call anything on the cursor before
|
||||||
|
// returning it from the background thread you'll have a complied program for the cursor,
|
||||||
|
// but it won't have been executed to generate the data yet. Often the execution is more
|
||||||
|
// expensive than the compilation...
|
||||||
|
if (c != null)
|
||||||
|
{
|
||||||
|
c.getCount();
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
@ -276,7 +276,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mAddressAdapter = new EmailAddressAdapter(this);
|
mAddressAdapter = EmailAddressAdapter.getInstance(this);
|
||||||
mAddressValidator = new EmailAddressValidator();
|
mAddressValidator = new EmailAddressValidator();
|
||||||
|
|
||||||
mFromView = (TextView)findViewById(R.id.from);
|
mFromView = (TextView)findViewById(R.id.from);
|
||||||
|
Loading…
Reference in New Issue
Block a user