Skip to content

Commit

Permalink
Merge pull request #1 from birajpatel/master
Browse files Browse the repository at this point in the history
Compat support upto API Level-5 Eclair.
  • Loading branch information
DSteve595 committed Nov 3, 2014
2 parents e65eca5 + 6259dd8 commit 3bb02a3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ An editable text view based on AutoCompleteTextView that reads the names of the

Useful for login/register fields.

__Works on API 8 (2.2, Froyo) and up.__
__Works on API 5 (2.0, Eclair) and up.__

![Screenshot](http://i.imgur.com/YaXGjvG.png "Screenshot")

Expand Down
6 changes: 5 additions & 1 deletion library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.stevenschoen.accountsuggesttextview">

<uses-sdk
android:minSdkVersion="5"
android:targetSdkVersion="21" />

<application android:allowBackup="true" />

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Patterns;
import android.widget.ArrayAdapter;
Expand All @@ -45,6 +47,11 @@ public class AccountSuggestTextView extends AutoCompleteTextView {
private ArrayList<String> emails = new ArrayList<String>();
private ArrayAdapter<String> adapter;

public static final Pattern EMAIL_ADDRESS_COMPAT = Pattern
.compile("[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + "\\@"
+ "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + "(" + "\\."
+ "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + ")+");

private boolean showDropDownWithNoText = false;

public AccountSuggestTextView(Context context) {
Expand All @@ -71,7 +78,7 @@ private void init() {

private void populateEmails() {
emails.clear();
Pattern emailPattern = Patterns.EMAIL_ADDRESS;
Pattern emailPattern = getEmailPattern();
Account[] accounts = AccountManager.get(getContext()).getAccounts();
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches() && !emails.contains(account.name)) {
Expand Down Expand Up @@ -107,4 +114,13 @@ public void setShowDropDownWithNoText(boolean show) {
this.showDropDownWithNoText = show;
invalidate();
}

@SuppressLint("NewApi")
private Pattern getEmailPattern() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
return Patterns.EMAIL_ADDRESS;
} else {
return EMAIL_ADDRESS_COMPAT;
}
}
}

0 comments on commit 3bb02a3

Please sign in to comment.