Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26159fb3 authored by Steve Kondik's avatar Steve Kondik
Browse files

dialer: Remove proprietary SmartDial extension

Revert "Dialer: add upgrade for smart search table."

This reverts commit b9fde197.

Revert "Dialer: fix the runtime exception issue for smartsearch."

This reverts commit 412ad2cc.

Revert "Add support of multi language smart search in dialpad"

This reverts commit e47ebf09.

Change-Id: I9f9a7856d25d911a0fa1eebe42b71f2ba5818e03
parent 3ff0622b
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@
        <meta-data android:name="com.google.android.backup.api_key"
            android:value="AEdPqrEAAAAIBXgtCEKQ6W0PXVnW-ZVia2KmlV2AxsTw3GjAeQ" />

        <uses-library android:name="com.qualcomm.qti.smartsearch" android:required="false" />
        <!-- The entrance point for Phone UI.
             stateAlwaysHidden is set to suppress keyboard show up on
             dialpad screen. -->
+0 −2
Original line number Diff line number Diff line
@@ -1155,6 +1155,4 @@ e mode.</string>
    <string name="alert_call_over_wifi">Calls will be made over Wi-Fi.</string>
    <string name="alert_call_no_cellular_coverage">No cellular network available. Connect to available Wi-Fi to make calls.</string>
    <string name="alert_user_connect_to_wifi_for_call">Connect to Wi-Fi to make calls.</string>
    <string name="missing_account_type">(No type)</string>
    <string name="missing_account_name">(No name)</string>
</resources>
+20 −187
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.dialer.database;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
@@ -34,7 +33,6 @@ import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.Directory;
import android.provider.ContactsContract.RawContacts;
import android.text.TextUtils;
import android.util.Log;

@@ -51,8 +49,6 @@ import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;

import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
@@ -74,11 +70,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
    private static final AtomicBoolean sInUpdate = new AtomicBoolean(false);
    private final Context mContext;

    private Class mMultiMatchClass;
    private Object mMultiMatchObject;
    private Method mMultiMatchMethod;
    private Method mMultiGetNameNumberMethod;

    /**
     * SmartDial DB version ranges:
     * <pre>
@@ -86,8 +77,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
     * </pre>
     */
    public static final int DATABASE_VERSION = 9;
    public static final int DATABASE_SHAREPREF_VERSION = 1;
    public static final String DATABASE_SHAREPREF_KEY = "database_sharepref_key";
    public static final String DATABASE_NAME = "dialer.db";

    /**
@@ -97,7 +86,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
    private static final String LAST_UPDATED_MILLIS = "last_updated_millis";
    private static final String DATABASE_VERSION_PROPERTY = "database_version";

    private static final int MAX_ENTRIES = 40;
    private static final int MAX_ENTRIES = 20;

    public interface Tables {
        /** Saves a list of numbers to be blocked.*/
@@ -131,8 +120,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
        static final String IS_PRIMARY = "is_primary";
        static final String CARRIER_PRESENCE = "carrier_presence";
        static final String LAST_SMARTDIAL_UPDATE_TIME = "last_smartdial_update_time";
        static final String ACCOUNT_TYPE = "account_type";
        static final String ACCOUNT_NAME = "account_name";
    }

    public static interface PrefixColumns extends BaseColumns {
@@ -169,8 +156,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
            Contacts.IN_VISIBLE_GROUP,          // 12
            Data.IS_PRIMARY,                    // 13
            Data.CARRIER_PRESENCE,              // 14
            RawContacts.ACCOUNT_TYPE,           // 15
            RawContacts.ACCOUNT_NAME,           // 16
        };

        static final int PHONE_ID = 0;
@@ -188,8 +173,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
        static final int PHONE_IN_VISIBLE_GROUP = 12;
        static final int PHONE_IS_PRIMARY = 13;
        static final int PHONE_CARRIER_PRESENCE = 14;
        static final int PHONE_ACCOUNT_TYPE = 15;
        static final int PHONE_ACCOUNT_NAME = 16;

        /** Selects only rows that have been updated after a certain time stamp.*/
        static final String SELECT_UPDATED_CLAUSE =
@@ -292,8 +275,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
        public final String lookupKey;
        public final long photoId;
        public final int carrierPresence;
        public final String accountType;
        public final String accountName;

        public ContactNumber(long id, long dataID, String displayName, String phoneNumber,
                String lookupKey, long photoId, int carrierPresence) {
@@ -304,22 +285,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
            this.lookupKey = lookupKey;
            this.photoId = photoId;
            this.carrierPresence = carrierPresence;
            this.accountType = null;
            this.accountName = null;
        }

        public ContactNumber(long id, long dataID, String displayName, String phoneNumber,
                String lookupKey, long photoId, int carrierPresence,
                        String accountType, String accountName) {
            this.dataId = dataID;
            this.id = id;
            this.displayName = displayName;
            this.phoneNumber = phoneNumber;
            this.lookupKey = lookupKey;
            this.photoId = photoId;
            this.carrierPresence = carrierPresence;
            this.accountType = accountType;
            this.accountName = accountName;
        }

        @Override
@@ -341,10 +306,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                        && Objects.equal(this.phoneNumber, that.phoneNumber)
                        && Objects.equal(this.lookupKey, that.lookupKey)
                        && Objects.equal(this.photoId, that.photoId)
                        && Objects.equal(this.carrierPresence, that.carrierPresence)
                        && Objects.equal(this.accountType, that.accountType)
                        && Objects.equal(this.accountName, that.accountName);

                        && Objects.equal(this.carrierPresence, that.carrierPresence);
            }
            return false;
        }
@@ -420,39 +382,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
        mContext = Preconditions.checkNotNull(context, "Context must not be null");
    }

    private void initMultiLanguageSearch() {
        try {
            if (mMultiMatchClass == null) {
                mMultiMatchClass = Class.forName("com.qualcomm.qti.smartsearch.SmartMatch");
                Log.d(TAG, "create multi match success");
            }
            if (mMultiMatchClass != null) {
                if (mMultiMatchObject == null) {
                    mMultiMatchObject = mMultiMatchClass.newInstance();
                }
                if (mMultiMatchMethod == null) {
                    mMultiMatchMethod = mMultiMatchClass.getDeclaredMethod(
                            "getMatchStringIndex", String.class, String.class,
                            int.class);
                }
                if (mMultiGetNameNumberMethod == null) {
                    mMultiGetNameNumberMethod = mMultiMatchClass.getDeclaredMethod(
                            "getNameNumber", String.class, int.class);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public Object getMultiMatchObject() {
        return mMultiMatchObject;
    }

    public Method getMultiMatchMethod() {
        return mMultiMatchMethod;
    }

    /**
     * Creates tables in the database when database is created for the first time.
     *
@@ -463,11 +392,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
        setupTables(db);
    }

    @Override
    public void onOpen(SQLiteDatabase db) {
        upgradeSmartSearchDatabase(db);
    }

    private void setupTables(SQLiteDatabase db) {
        dropTables(db);
        db.execSQL("CREATE TABLE " + Tables.SMARTDIAL_TABLE + " ("
@@ -485,9 +409,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                + SmartDialDbColumns.IS_SUPER_PRIMARY + " INTEGER, "
                + SmartDialDbColumns.IN_VISIBLE_GROUP + " INTEGER, "
                + SmartDialDbColumns.IS_PRIMARY + " INTEGER, "
                + SmartDialDbColumns.CARRIER_PRESENCE + " INTEGER NOT NULL DEFAULT 0,"
                + SmartDialDbColumns.ACCOUNT_TYPE + " TEXT, "
                + SmartDialDbColumns.ACCOUNT_NAME + " TEXT "
                + SmartDialDbColumns.CARRIER_PRESENCE + " INTEGER NOT NULL DEFAULT 0"
                + ");");

        db.execSQL("CREATE TABLE " + Tables.PREFIX_TABLE + " ("
@@ -523,49 +445,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
        }
    }

    private boolean isNeedUpgradeForSmartSearch() {
        String FILENAME = "upgradeSmartSearchTable";

        Log.d(TAG, "Shared Preference Created with name:  " + FILENAME);
        SharedPreferences pref = mContext.getSharedPreferences(FILENAME,
                mContext.MODE_PRIVATE);
        if (pref != null) {
            int mSharePrefVersion = pref.getInt(DATABASE_SHAREPREF_KEY,0);
            if(mSharePrefVersion < DATABASE_SHAREPREF_VERSION) {
                Editor editor;
                editor = pref.edit();
                editor.putInt(DATABASE_SHAREPREF_KEY, DATABASE_SHAREPREF_VERSION);
                editor.commit();
                return true;
            }
            return false;
        } else {
            Log.d(TAG, "fail to get SharedPreferences !");
            return false;
        }
    }

    private void upgradeSmartSearchDatabase(SQLiteDatabase db) {
        if (isNeedUpgradeForSmartSearch()) {
            db.beginTransaction();
            try {
                upgradeDatabaseSmartSearch(db);
                db.setTransactionSuccessful();
            } catch (Throwable ex) {
                Log.e(TAG, ex.getMessage(), ex);
            } finally {
                db.endTransaction();
            }
        }
    }

    private void upgradeDatabaseSmartSearch(SQLiteDatabase db) {
        db.execSQL("ALTER TABLE " +  Tables.SMARTDIAL_TABLE + " ADD COLUMN " +
                SmartDialDbColumns.ACCOUNT_TYPE + " TEXT;");
        db.execSQL("ALTER TABLE " +  Tables.SMARTDIAL_TABLE + " ADD COLUMN " +
                SmartDialDbColumns.ACCOUNT_NAME + " TEXT;");
    }

    public void dropTables(SQLiteDatabase db) {
        db.execSQL("DROP TABLE IF EXISTS " + Tables.PREFIX_TABLE);
        db.execSQL("DROP TABLE IF EXISTS " + Tables.SMARTDIAL_TABLE);
@@ -891,10 +770,8 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                    SmartDialDbColumns.IN_VISIBLE_GROUP+ ", " +
                    SmartDialDbColumns.IS_PRIMARY + ", " +
                    SmartDialDbColumns.CARRIER_PRESENCE + ", " +
                    SmartDialDbColumns.LAST_SMARTDIAL_UPDATE_TIME + ", " +
                    SmartDialDbColumns.ACCOUNT_TYPE + ", " +
                    SmartDialDbColumns.ACCOUNT_NAME + ") " +
                    " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                    SmartDialDbColumns.LAST_SMARTDIAL_UPDATE_TIME + ") " +
                    " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            final SQLiteStatement insert = db.compileStatement(sqlInsert);

            final String numberSqlInsert = "INSERT INTO " + Tables.PREFIX_TABLE + " (" +
@@ -943,24 +820,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                insert.bindLong(12, updatedContactCursor.getInt(PhoneQuery.PHONE_IS_PRIMARY));
                insert.bindLong(13, updatedContactCursor.getInt(PhoneQuery.PHONE_CARRIER_PRESENCE));
                insert.bindLong(14, currentMillis);

                final String accountType = updatedContactCursor.getString(
                        PhoneQuery.PHONE_ACCOUNT_TYPE);
                if (accountType == null) {
                    insert.bindString(15, mContext.getResources().getString(
                            R.string.missing_account_type));
                } else {
                    insert.bindString(15, accountType);
                }

                final String accountName = updatedContactCursor.getString(
                        PhoneQuery.PHONE_ACCOUNT_NAME);
                if (accountName == null) {
                    insert.bindString(16, mContext.getResources().getString(
                            R.string.missing_account_name));
                } else {
                    insert.bindString(16, accountName);
                }
                insert.executeInsert();
                final String contactPhoneNumber =
                        updatedContactCursor.getString(PhoneQuery.PHONE_NUMBER);
@@ -1004,21 +863,9 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {

            while (nameCursor.moveToNext()) {
                /** Computes a list of prefixes of a given contact name. */
                if (mMultiGetNameNumberMethod != null) {
                    try {
                        String nameNumber = (String) mMultiGetNameNumberMethod.invoke(
                                mMultiMatchObject,nameCursor.getString(columnIndexName), 0);
                        nameNumber = nameNumber.replaceAll("[\\[\\.\\]]", "");
                        insert.bindLong(1,nameCursor.getLong(columnIndexContactId));
                        insert.bindString(2, nameNumber);
                        insert.executeInsert();
                        insert.clearBindings();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    final ArrayList<String> namePrefixes = SmartDialPrefix
                            .generateNamePrefixes(nameCursor.getString(columnIndexName));
                final ArrayList<String> namePrefixes =
                        SmartDialPrefix.generateNamePrefixes(nameCursor.getString(columnIndexName));

                for (String namePrefix : namePrefixes) {
                    insert.bindLong(1, nameCursor.getLong(columnIndexContactId));
                    insert.bindString(2, namePrefix);
@@ -1026,7 +873,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                    insert.clearBindings();
                }
            }
            }

            db.setTransactionSuccessful();
        } finally {
@@ -1042,8 +888,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
     * update.
     */
    public void updateSmartDialDatabase() {
        initMultiLanguageSearch();

        final SQLiteDatabase db = getWritableDatabase();

        synchronized(mLock) {
@@ -1220,19 +1064,14 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
    public ArrayList<ContactNumber>  getLooseMatches(String query,
            SmartDialNameMatcher nameMatcher) {
        final boolean inUpdate = sInUpdate.get();
        if (inUpdate || query.length() == 0) {
        if (inUpdate) {
            return Lists.newArrayList();
        }

        final SQLiteDatabase db = getReadableDatabase();

        /** Uses SQL query wildcard '%' to represent prefix matching.*/
        StringBuilder looseQuery = new StringBuilder(query);
        for (int i = 0; i < looseQuery.toString().length();) {
            looseQuery.insert(i, "%");
            i = i + 2;
        }
        looseQuery.append("%");
        final String looseQuery = query + "%";

        final ArrayList<ContactNumber> result = Lists.newArrayList();

@@ -1248,11 +1087,9 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                SmartDialDbColumns.NUMBER + ", " +
                SmartDialDbColumns.CONTACT_ID + ", " +
                SmartDialDbColumns.LOOKUP_KEY + ", " +
                SmartDialDbColumns.CARRIER_PRESENCE + ", " +
                SmartDialDbColumns.ACCOUNT_TYPE + ", " +
                SmartDialDbColumns.ACCOUNT_NAME +
                " FROM " + Tables.SMARTDIAL_TABLE +
                " WHERE " + SmartDialDbColumns.CONTACT_ID + " IN " +
                SmartDialDbColumns.CARRIER_PRESENCE +
                " FROM " + Tables.SMARTDIAL_TABLE + " WHERE " +
                SmartDialDbColumns.CONTACT_ID + " IN " +
                    " (SELECT " + PrefixColumns.CONTACT_ID +
                    " FROM " + Tables.PREFIX_TABLE +
                    " WHERE " + Tables.PREFIX_TABLE + "." + PrefixColumns.PREFIX +
@@ -1275,8 +1112,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
            final int columnId = 4;
            final int columnLookupKey = 5;
            final int columnCarrierPresence = 6;
            final int columnAccountType = 7;
            final int columnAccountName = 8;
            if (DEBUG) {
                stopWatch.lap("Found column IDs");
            }
@@ -1295,8 +1130,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                final long photoId = cursor.getLong(columnPhotoId);
                final String lookupKey = cursor.getString(columnLookupKey);
                final int carrierPresence = cursor.getInt(columnCarrierPresence);
                final String accountType = cursor.getString(columnAccountType);
                final String accountName = cursor.getString(columnAccountName);

                /** If a contact already exists and another phone number of the contact is being
                 * processed, skip the second instance.
@@ -1317,7 +1150,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                    /** If a contact has not been added, add it to the result and the hash set.*/
                    duplicates.add(contactMatch);
                    result.add(new ContactNumber(id, dataID, displayName, phoneNumber, lookupKey,
                            photoId, carrierPresence, accountType, accountName));
                            photoId, carrierPresence));
                    counter++;
                    if (DEBUG) {
                        stopWatch.lap("Added one result: Name: " + displayName);
+1 −3
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public class SmartDialCursorLoader extends AsyncTaskLoader<Cursor> {
        mQuery = SmartDialNameMatcher.normalizeNumber(query, SmartDialPrefix.getMap());

        /** Constructs a name matcher object for matching names. */
        mNameMatcher = new SmartDialNameMatcher(mQuery, SmartDialPrefix.getMap(), mContext);
        mNameMatcher = new SmartDialNameMatcher(mQuery, SmartDialPrefix.getMap());
    }

    /**
@@ -103,8 +103,6 @@ public class SmartDialCursorLoader extends AsyncTaskLoader<Cursor> {
            row[PhoneQuery.PHOTO_ID] = contact.photoId;
            row[PhoneQuery.DISPLAY_NAME] = contact.displayName;
            row[PhoneQuery.CARRIER_PRESENCE] = contact.carrierPresence;
            row[PhoneQuery.PHONE_ACCOUNT_TYPE] = contact.accountType;
            row[PhoneQuery.PHONE_ACCOUNT_NAME] = contact.accountName;
            cursor.addRow(row);
        }
        return cursor;
+47 −101
Original line number Diff line number Diff line
@@ -17,17 +17,13 @@
package com.android.dialer.dialpad;

import android.support.annotation.Nullable;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.android.dialer.database.DialerDatabaseHelper;
import com.android.dialer.dialpad.SmartDialPrefix.PhoneNumberTokens;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;

import java.lang.reflect.Method;
import java.util.ArrayList;

/**
@@ -39,8 +35,6 @@ import java.util.ArrayList;
 */
public class SmartDialNameMatcher {

    private final static String TAG = "SmartDialNameMatcher";

    private String mQuery;

    // Whether or not we allow matches like 57 - (J)ohn (S)mith
@@ -59,24 +53,14 @@ public class SmartDialNameMatcher {
    private String mNameMatchMask = "";
    private String mPhoneNumberMatchMask = "";

    private Context mContext;
    private String mSchar = "+*#-.(,)/ ";
    private Object mMultiMatchObject;
    private Method mMultiMatchMethod;

    @VisibleForTesting
    public SmartDialNameMatcher(String query, Context context) {
        this(query, LATIN_SMART_DIAL_MAP, context);
    public SmartDialNameMatcher(String query) {
        this(query, LATIN_SMART_DIAL_MAP);
    }

    public SmartDialNameMatcher(String query, SmartDialMap map, Context context) {
    public SmartDialNameMatcher(String query, SmartDialMap map) {
        mQuery = query;
        mMap = map;
        mContext = context;
        mMultiMatchObject = DialerDatabaseHelper.getInstance(mContext)
                .getMultiMatchObject();
        mMultiMatchMethod = DialerDatabaseHelper.getInstance(mContext)
                .getMultiMatchMethod();
    }

    /**
@@ -151,6 +135,22 @@ public class SmartDialNameMatcher {

        // Try matching the number as is
        SmartDialMatchPosition matchPos = matchesNumberWithOffset(phoneNumber, query, 0);
        if (matchPos == null) {
            final PhoneNumberTokens phoneNumberTokens =
                    SmartDialPrefix.parsePhoneNumber(phoneNumber);

            if (phoneNumberTokens == null) {
                return matchPos;
            }
            if (phoneNumberTokens.countryCodeOffset != 0) {
                matchPos = matchesNumberWithOffset(phoneNumber, query,
                        phoneNumberTokens.countryCodeOffset);
            }
            if (matchPos == null && phoneNumberTokens.nanpCodeOffset != 0 && useNanp) {
                matchPos = matchesNumberWithOffset(phoneNumber, query,
                        phoneNumberTokens.nanpCodeOffset);
            }
        }
        if (matchPos != null) {
            replaceBitInMask(builder, matchPos);
            mPhoneNumberMatchMask = builder.toString();
@@ -195,47 +195,40 @@ public class SmartDialNameMatcher {
     */
    private SmartDialMatchPosition matchesNumberWithOffset(String phoneNumber, String query,
            int offset) {
        if (TextUtils.isEmpty(phoneNumber) || TextUtils.isEmpty(query)
                || query.length() > phoneNumber.length()) {
        if (TextUtils.isEmpty(phoneNumber) || TextUtils.isEmpty(query)) {
            return null;
        }

        String phoneNum = phoneNumber.replaceAll("[\\+\\*\\#\\-\\.\\(\\,\\)\\/ ]", "");
        if (!TextUtils.isEmpty(phoneNum) && phoneNum.contains(query)) {
            // firstly, find the start position in original phone number.
            int start = phoneNum.indexOf(query);
            int length = phoneNumber.length();
            for (int i = start; i < length; i++) {
                char ch = phoneNumber.charAt(i);
                if (ch != phoneNum.charAt(start)) {
                    continue;
                }
                if (phoneNumber.substring(i).replaceAll("[\\+\\*\\#\\-\\.\\(\\,\\)\\/ ]", "")
                        .indexOf(query) == 0) {
                    start = i;
        int queryAt = 0;
        int numberAt = offset;
        for (int i = offset; i < phoneNumber.length(); i++) {
            if (queryAt == query.length()) {
                break;
            }
            }
            // secondly, find the end position in original phone number.
            int specialCount = 0;
            int queryLength = query.length();
            int end = start + queryLength;
            for (int i = start; i < length; i++) {
            char ch = phoneNumber.charAt(i);
                if (mSchar.indexOf(ch) != -1) {
                    specialCount++;
                    continue;
            if (mMap.isValidDialpadNumericChar(ch)) {
                if (ch != query.charAt(queryAt)) {
                    return null;
                }

                if (i - start + 1 - specialCount == queryLength) {
                    end = i + 1;
                    break;
                queryAt++;
            } else {
                if (queryAt == 0) {
                    // Found a separator before any part of the query was matched, so advance the
                    // offset to avoid prematurely highlighting separators before the rest of the
                    // query.
                    // E.g. don't highlight the first '-' if we're matching 1-510-111-1111 with
                    // '510'.
                    // However, if the current offset is 0, just include the beginning separators
                    // anyway, otherwise the highlighting ends up looking weird.
                    // E.g. if we're matching (510)-111-1111 with '510', we should include the
                    // first '('.
                    if (offset != 0) {
                        offset++;
                    }
                }
            return new SmartDialMatchPosition(start, end);
        } else {
            return null;
            }
            numberAt++;
        }
        return new SmartDialMatchPosition(0 + offset, numberAt);
    }

    /**
@@ -419,12 +412,8 @@ public class SmartDialNameMatcher {

    public boolean matches(String displayName) {
        mMatchPositions.clear();
        if (mMultiMatchObject != null && mMultiMatchMethod != null) {
            return matchesMultiLanguage(displayName, mQuery, mMatchPositions);
        } else {
        return matchesCombination(displayName, mQuery, mMatchPositions);
    }
    }

    public ArrayList<SmartDialMatchPosition> getMatchPositions() {
        // Return a clone of mMatchPositions so that the caller can use it without
@@ -447,47 +436,4 @@ public class SmartDialNameMatcher {
    public String getQuery() {
        return mQuery;
    }

    boolean matchesMultiLanguage(String displayName, String query,
            ArrayList<SmartDialMatchPosition> matchList) {
        StringBuilder builder = new StringBuilder();
        constructEmptyMask(builder, displayName.length());
        mNameMatchMask = builder.toString();
        final int nameLength = displayName.length();
        final int queryLength = query.length();

        if (queryLength == 0) {
            return false;
        }
        // contains the start, not the end poing
        int[] indexs = null;
        try {
            indexs = (int[]) mMultiMatchMethod.invoke(mMultiMatchObject,
                    query, displayName, 0);
            // mMultimatch.getMatchStringIndex(query, displayName, 0);
            if (indexs == null) {
                return false;
            }
        } catch (Exception e) {
            Log.d(TAG, "Exception:" + e);
            return false;
        }

        for (int i = 0; i < indexs.length; i = i + 2) {
            int start = indexs[i];
            int end = indexs[i + 1];
            if (start >= 0 && end >= 0) {
                matchList.add(new SmartDialMatchPosition(start, end + 1));
            } else {
                Log.d(TAG, "Invalid index, start is:" + start + " end is:"
                        + end + " for name:" + displayName);
            }
        }

        for (SmartDialMatchPosition match : matchList) {
            replaceBitInMask(builder, match);
        }
        mNameMatchMask = builder.toString();
        return true;
    }
}
Loading