首页 > 代码库 > android +7与8开头的号码在拨号盘上搜索相互匹配
android +7与8开头的号码在拨号盘上搜索相互匹配
某些运营商,要求在拨号盘的DialerSearch上面,对于+7与8开头的号码要能够互相搜索:
1.查询“+7123456”这个号码,输入“8123456”也能够检索到。反之亦然。
2. 输入“8”,能匹配“8”开头的数字或者“TUV”开头的名字。
KK版本对DialerSearch有一定的修改,请参考FAQ11308 [DialerSearch] 在KK上如何实现+7与8开头的号码在拨号盘上搜索相互匹配。
修改的部分有XT and标识
1、修改ContactsProvider2.java
先添加定义
private int prevSearchNumberLengXXX = 0;
private static final String TEMP_DIALER_SEARCH_VIEW_XXX = "temp_dialer_search_view_xxx";
private static final String TEMP_DIALER_SEARCH_TABLE_XXX = "temp_dialer_search_table_xxx";
private static final String COMBINE_RESULT_VIEW_TABLE = "combine_result_view_table";
再修改
private Cursor queryDialerSearchSimple(SQLiteDatabase db, Uri uri) {
log(" DIALER_SEARCH_SIMPLE");
String filterParam = "";
String uriStr = uri.toString();
StringBuilder searchInfo = new StringBuilder();
if (uriStr.indexOf("dialer_search_number") > 0) {
String uriString = uri.toString();
int previous = 0;
int current;
while ((current = uriString.indexOf(‘/‘, previous)) > -1) {
previous = current + 1;
}
filterParam = uriString.substring(previous);
Log.i(TAG, "filterParam: "+filterParam);
} else {
return null;
}
//XT and
if(filterParam.startsWith("8") || filterParam.startsWith("+7")){
String filterParam2 = null;
if(filterParam.startsWith("8"))
filterParam2 = filterParam.substring(1);
else if(filterParam.startsWith("+7"))
filterParam2 = filterParam.substring(2);
String tempViewTableXXX = queryDialerSearchSimpleXXX(db, filterParam2);
String tempViewTable8XXX = queryDialerSearchSimple8XXX(db, filterParam);
Cursor result = combineTwoViewTable(db, tempViewTableXXX, tempViewTable8XXX);
return result;
}
//XT and end
String tempTable = "temp_ds_name_lookup_table_number" ;
String tempViewTable = "temp_ds_view_table_number";
String mTableColumns = getDialerSearchNameTableColumns(mDisplayOrder,filterParam,true);
Cursor searchResultCursor = null;
db.beginTransaction();
try {
if (prevSearchNumberLeng > 0) {
for (int tmpLeng=prevSearchNumberLeng;tmpLeng>0;tmpLeng--) {
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE + tmpLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW + tmpLeng);
}
}
db.execSQL("DROP INDEX IF EXISTS idx_" + tempTable);
db.execSQL("DROP TABLE IF EXISTS " + tempTable);
db.execSQL("CREATE TEMP TABLE " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + TEMP_DIALER_SEARCH_TABLE
+ " WHERE " + DialerSearchLookupColumns.IS_VISIABLE + "=1 AND " + DialerSearch.MATCHED_DATA_OFFSETS + " IS NOT NULL ");
db.execSQL("CREATE INDEX idx_" + tempTable + " ON " + tempTable + "(" + DsTempTableColumns._ID + "," + DsTempTableColumns.NAME_TYPE + ")");
db.execSQL("DROP TABLE IF EXISTS " + tempViewTable);
db.execSQL("CREATE TEMP TABLE " + tempViewTable
+ " AS SELECT " + DS_VIEW_NAME_COLUMNS
+ ", " + TEMP_TABLE_ALIAS_NUMBER + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_DATA_OFFSETS
+ ", " + TEMP_TABLE_ALIAS_NAME + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_NAME_OFFSETS
+ " FROM (SELECT * FROM " + TEMP_DIALER_SEARCH_VIEW
+ " WHERE " + DialerSearch.RAW_CONTACT_ID + " IN "
+ " (SELECT " + DsTempTableColumns.RAW_CONTACT_ID + " FROM " + tempTable + ") "
+ ") AS " + TEMP_BASEVIEW_ALIAS
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NUMBER
+ " ON " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_LOOKUP_ID
+ " AND " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.PHONE_EXACT
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NAME
+ " ON " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_ID
+ " AND " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.NAME_EXACT
+ " ORDER BY " + DialerSearch.RAW_CONTACT_ID + ","
+ TEMP_TABLE_ALIAS_NUMBER + "."
+ DsTempTableColumns.NAME_TYPE + ","
+ DialerSearch.CALL_DATE);
searchResultCursor = db.rawQuery(
"SELECT " + DS_SEARCH_RESULTS_COLUMNS + " FROM " + tempViewTable
+ " GROUP BY " + DialerSearch.RAW_CONTACT_ID
+ " ORDER BY " + DialerSearch.CALL_DATE + " DESC,"
+ DialerSearch.SORT_KEY_PRIMARY + " COLLATE NOCASE",null);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return searchResultCursor;
}
private Cursor queryDialerSearchIncrement(SQLiteDatabase db, Uri uri) {
//TO get filter parameter
log(" DIALER_SEARCH_INCREMENT");
String filterParam = "";
String uriStr = uri.toString();
if (uriStr.indexOf("dialer_search") > 0) {
String uriString = uri.toString();
int previous = 0;
int current;
while ((current = uriString.indexOf(‘/‘, previous)) > -1) {
previous = current + 1;
}
filterParam = uriString.substring(previous);
log("filterParam: "+filterParam);
} else {
Log.i(TAG, "filterParam is null");
return null;
}
if (filterParam.indexOf("init") > -1) { // the initial state of dialer search is call log list
int pos = filterParam.indexOf(‘#‘, 0);
mDisplayOrder = (int)(filterParam.charAt(pos+1) - ‘0‘);
mSortOrder = (int)((filterParam.charAt(filterParam.indexOf(‘#‘, pos+1)+1)) - ‘0‘);
/*
* Bug Fix by Mediatek Begin.
* CR ID: ALPS00114597
* Descriptions:
*/
while (prevSearchNumberLeng > 0) {
// current operation is delete all digit number
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE + prevSearchNumberLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW + prevSearchNumberLeng);
prevSearchNumberLeng--;
}
/*
* Bug Fix by Mediatek End.
*/
if(prevSearchNumberLeng ==0 ){
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE);
db.execSQL("CREATE TEMP TABLE " + TEMP_DIALER_SEARCH_TABLE
+ " AS SELECT "
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns._ID + " AS " + DialerSearchLookupColumns._ID + " ,"
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.DATA_ID + " AS " + DialerSearchLookupColumns.DATA_ID + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.RAW_CONTACT_ID + " AS " + DialerSearchLookupColumns.RAW_CONTACT_ID + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NAME_TYPE + " AS " + DialerSearchLookupColumns.NAME_TYPE + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.CALL_LOG_ID + " AS " + DialerSearchLookupColumns.CALL_LOG_ID + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NUMBER_COUNT + " AS " + DialerSearchLookupColumns.NUMBER_COUNT + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.IS_VISIABLE + " AS " + DialerSearchLookupColumns.IS_VISIABLE + ","
+ " (CASE WHEN " + DialerSearchLookupColumns.CALL_LOG_ID + " > 0 " + " AND " + DialerSearchLookupColumns.NAME_TYPE + "=" + DialerSearchLookupType.PHONE_EXACT
+ " THEN " + Tables.CALLS + "." + Calls.NUMBER
+ " ELSE " + Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NORMALIZED_NAME
+ " END) AS " + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + " AS " + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ " (CASE WHEN " + DialerSearchLookupColumns.CALL_LOG_ID + " > 0 " + " AND " + DialerSearchLookupColumns.NAME_TYPE + "=" + DialerSearchLookupType.PHONE_EXACT
+ " THEN " + Tables.CALLS + "." + Calls.NUMBER
+ " ELSE " + Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NORMALIZED_NAME_ALTERNATIVE
+ " END) AS " + DialerSearchLookupColumns.NORMALIZED_NAME_ALTERNATIVE + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS_ALTERNATIVE + " AS " + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS_ALTERNATIVE
+ " FROM " + Tables.DIALER_SEARCH
+ " LEFT JOIN " + Tables.CALLS
+ " ON " + Tables.CALLS + "." + Calls._ID + "=" + DialerSearchLookupColumns.CALL_LOG_ID
+ " WHERE " + DialerSearchLookupColumns.IS_VISIABLE + "=1");
String mViewColumns = getDialerSearchViewColumns(mDisplayOrder,mSortOrder);
db.execSQL("DROP INDEX IF EXISTS idx_" + TEMP_DIALER_SEARCH_VIEW + "_rawid");
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW);
db.execSQL("CREATE TEMP TABLE " + TEMP_DIALER_SEARCH_VIEW
+ " AS SELECT " + mViewColumns + " FROM " + Views.DIALER_SEARCH_VIEW);
db.execSQL("CREATE INDEX idx_" + TEMP_DIALER_SEARCH_VIEW + "_rawid ON "
+ TEMP_DIALER_SEARCH_VIEW + "(" + DialerSearch.RAW_CONTACT_ID + ")");
}
return db.rawQuery(
"SELECT " + DS_INIT_SEARCH_RESULTS_COLUMNS
+" FROM (SELECT " + DS_INIT_SEARCH_RESULTS_COLUMNS + ", " + DialerSearch.RAW_CONTACT_ID
+ " FROM " + TEMP_DIALER_SEARCH_VIEW
+ " WHERE " + DialerSearch.CALL_LOG_ID + " > 0 "
+ " ORDER BY " + DialerSearch.CALL_DATE + " )"
+ " GROUP BY " + DialerSearch.RAW_CONTACT_ID
+ " ORDER BY " + DialerSearch.CALL_DATE + " DESC", null); // for call log only need to search number
} else if (filterParam.indexOf("null_input") > -1) {
while (prevSearchNumberLeng > 0) {
// current operation is delete all digit number
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE + prevSearchNumberLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW + prevSearchNumberLeng);
prevSearchNumberLeng--;
}
return db.rawQuery(
"SELECT " + DS_INIT_SEARCH_RESULTS_COLUMNS
+" FROM (SELECT " + DS_INIT_SEARCH_RESULTS_COLUMNS + ", " + DialerSearch.RAW_CONTACT_ID
+ " FROM " + TEMP_DIALER_SEARCH_VIEW
+ " WHERE " + DialerSearch.CALL_LOG_ID + " > 0 "
+ " ORDER BY " + DialerSearch.CALL_DATE + " )"
+ " GROUP BY " + DialerSearch.RAW_CONTACT_ID
+ " ORDER BY " + DialerSearch.CALL_DATE + " DESC", null);
}
//XT and
if(filterParam.startsWith("8") || filterParam.startsWith("+7")){
String filterParam2 = null;
if(filterParam.startsWith("8"))
filterParam2 = filterParam.substring(1);
else if(filterParam.startsWith("+7"))
filterParam2 = filterParam.substring(2);
String tempViewTableXXX = queryDialerSearchIncrementXXX(db, filterParam2);
String tempViewTable8XXX = queryDialerSearchIncrement8XXX(db, filterParam);
Cursor result = combineTwoViewTable(db, tempViewTableXXX, tempViewTable8XXX);
return result;
}
//XT and end
//Check Input OR Delete
int numberCount = filterParam.length();
String baseLookUpTable,baseViewTable;
boolean deleteOperation = false;
if (prevSearchNumberLeng > numberCount) {
// current operation is delete number to search
db.execSQL("DROP INDEX IF EXISTS idx_" + TEMP_DIALER_SEARCH_TABLE + prevSearchNumberLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE + prevSearchNumberLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW + prevSearchNumberLeng);
deleteOperation = true;
}
prevSearchNumberLeng = numberCount;
//Check to input OR delete END
if (numberCount == 1) {
baseLookUpTable = new String(TEMP_DIALER_SEARCH_TABLE);
baseViewTable = new String(TEMP_DIALER_SEARCH_VIEW);
} else {
int idx = numberCount - 1;
baseLookUpTable = new String(TEMP_DIALER_SEARCH_TABLE + idx);
baseViewTable = new String(TEMP_DIALER_SEARCH_VIEW + idx);
}
String tempViewTable = TEMP_DIALER_SEARCH_VIEW + numberCount;
Cursor searchResultCursor = null;
db.beginTransaction();
try {
//TO CREATE NEW TEMP TABLE
if (deleteOperation == false) {
/* Create temp table from name_lookup table */
String tempTable = TEMP_DIALER_SEARCH_TABLE + numberCount;
boolean isFirstQuery = numberCount==1;
String mTableColumns = getDialerSearchNameTableColumns(mDisplayOrder,filterParam,isFirstQuery);
if(isFirstQuery){
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + baseLookUpTable
+ " WHERE " + " DIALER_SEARCH_MATCH_FILTER(" + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ DialerSearchLookupColumns.NAME_TYPE + ",‘"
+ filterParam + "‘" + ")");
}else{
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + baseLookUpTable
+ " WHERE " + " DIALER_SEARCH_MATCH_FILTER(" + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ DialerSearchLookupColumns.NAME_TYPE + ",‘"
+ filterParam + "‘" + ")");
}
db.execSQL("DROP INDEX IF EXISTS idx_" + tempTable);
db.execSQL("CREATE INDEX idx_" + tempTable + " ON " + tempTable + "(" + DsTempTableColumns._ID + "," + DsTempTableColumns.NAME_TYPE + ")");
//Use name_type AS order key.
//Name_type is just a flag to distinguish matched number and mismatched number
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempViewTable
+ " AS SELECT " + DS_VIEW_NAME_COLUMNS
+ ", " + TEMP_TABLE_ALIAS_NUMBER + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_DATA_OFFSETS
+ ", " + TEMP_TABLE_ALIAS_NAME + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_NAME_OFFSETS
+ " FROM (SELECT * FROM " + baseViewTable
+ " WHERE " + DialerSearch.RAW_CONTACT_ID
+ " IN (SELECT " + DsTempTableColumns.RAW_CONTACT_ID
+ " FROM " + tempTable + ") "
+ ") AS " + TEMP_BASEVIEW_ALIAS
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NUMBER
+ " ON " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_LOOKUP_ID
+ " AND " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.PHONE_EXACT
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NAME
+ " ON " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_ID
+ " AND " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.NAME_EXACT
+ " ORDER BY " + DialerSearch.RAW_CONTACT_ID + ","
+ TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + ","
+ DialerSearch.CALL_DATE);
}
//GET RESULTE FROM NEW TEMP TABLE
searchResultCursor = db.rawQuery(
"SELECT " + DS_SEARCH_RESULTS_COLUMNS + " FROM " + tempViewTable
+ " GROUP BY " + DialerSearch.RAW_CONTACT_ID
+ " ORDER BY " + DialerSearch.CALL_DATE + " DESC,"
+ DialerSearch.SORT_KEY_PRIMARY + " COLLATE NOCASE",null);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return searchResultCursor;
}
//XT and
private String queryDialerSearchIncrementXXX(SQLiteDatabase db, String filterParam) {
//TO get filter parameter
log(" DIALER_SEARCH_INCREMENT XXX");
String noResultXXX = "NA";
if (filterParam.length() == 0) {
while (prevSearchNumberLengXXX > 0) {
// current operation is delete all digit number
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE_XXX + prevSearchNumberLengXXX);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW_XXX + prevSearchNumberLengXXX);
prevSearchNumberLengXXX--;
}
if(prevSearchNumberLengXXX ==0 ){
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE_XXX);
db.execSQL("CREATE TEMP TABLE " + TEMP_DIALER_SEARCH_TABLE_XXX
+ " AS SELECT "
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns._ID + " AS " + DialerSearchLookupColumns._ID + " ,"
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.DATA_ID + " AS " + DialerSearchLookupColumns.DATA_ID + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.RAW_CONTACT_ID + " AS " + DialerSearchLookupColumns.RAW_CONTACT_ID + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NAME_TYPE + " AS " + DialerSearchLookupColumns.NAME_TYPE + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.CALL_LOG_ID + " AS " + DialerSearchLookupColumns.CALL_LOG_ID + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NUMBER_COUNT + " AS " + DialerSearchLookupColumns.NUMBER_COUNT + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.IS_VISIABLE + " AS " + DialerSearchLookupColumns.IS_VISIABLE + ","
+ " (CASE WHEN " + DialerSearchLookupColumns.CALL_LOG_ID + " > 0 " + " AND " + DialerSearchLookupColumns.NAME_TYPE + "=" + DialerSearchLookupType.PHONE_EXACT
+ " THEN " + Tables.CALLS + "." + Calls.NUMBER
+ " ELSE " + Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NORMALIZED_NAME
+ " END) AS " + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + " AS " + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ " (CASE WHEN " + DialerSearchLookupColumns.CALL_LOG_ID + " > 0 " + " AND " + DialerSearchLookupColumns.NAME_TYPE + "=" + DialerSearchLookupType.PHONE_EXACT
+ " THEN " + Tables.CALLS + "." + Calls.NUMBER
+ " ELSE " + Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NORMALIZED_NAME_ALTERNATIVE
+ " END) AS " + DialerSearchLookupColumns.NORMALIZED_NAME_ALTERNATIVE + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS_ALTERNATIVE + " AS " + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS_ALTERNATIVE
+ " FROM " + Tables.DIALER_SEARCH
+ " LEFT JOIN " + Tables.CALLS
+ " ON " + Tables.CALLS + "." + Calls._ID + "=" + DialerSearchLookupColumns.CALL_LOG_ID
+ " WHERE " + DialerSearchLookupColumns.IS_VISIABLE + "=1");
String mViewColumns = getDialerSearchViewColumns(mDisplayOrder,mSortOrder);
db.execSQL("DROP INDEX IF EXISTS idx_" + TEMP_DIALER_SEARCH_VIEW_XXX + "_rawid");
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW_XXX);
db.execSQL("CREATE TEMP TABLE " + TEMP_DIALER_SEARCH_VIEW_XXX
+ " AS SELECT " + mViewColumns + " FROM " + Views.DIALER_SEARCH_VIEW);
db.execSQL("CREATE INDEX idx_" + TEMP_DIALER_SEARCH_VIEW_XXX + "_rawid ON "
+ TEMP_DIALER_SEARCH_VIEW_XXX + "(" + DialerSearch.RAW_CONTACT_ID + ")");
}
return noResultXXX;
}
//Check Input OR Delete
int numberCount = filterParam.length();
String baseLookUpTable,baseViewTable;
boolean deleteOperation = false;
if (prevSearchNumberLengXXX > numberCount) {
// current operation is delete number to search
db.execSQL("DROP INDEX IF EXISTS idx_" + TEMP_DIALER_SEARCH_TABLE_XXX + prevSearchNumberLengXXX);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE_XXX + prevSearchNumberLengXXX);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW_XXX + prevSearchNumberLengXXX);
deleteOperation = true;
}
prevSearchNumberLengXXX = numberCount;
//Check to input OR delete END
if (numberCount == 1) {
baseLookUpTable = new String(TEMP_DIALER_SEARCH_TABLE_XXX);
baseViewTable = new String(TEMP_DIALER_SEARCH_VIEW_XXX);
} else {
int idx = numberCount - 1;
baseLookUpTable = new String(TEMP_DIALER_SEARCH_TABLE_XXX + idx);
baseViewTable = new String(TEMP_DIALER_SEARCH_VIEW_XXX + idx);
}
String tempViewTable = TEMP_DIALER_SEARCH_VIEW_XXX + numberCount;
db.beginTransaction();
try {
//TO CREATE NEW TEMP TABLE
if (deleteOperation == false) {
/* Create temp table from name_lookup table */
String tempTable = TEMP_DIALER_SEARCH_TABLE_XXX + numberCount;
boolean isFirstQuery = numberCount==1;
String mTableColumns = getDialerSearchNameTableColumns(mDisplayOrder,filterParam,isFirstQuery);
if(isFirstQuery){
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + baseLookUpTable
+ " WHERE " + " DIALER_SEARCH_MATCH_FILTER(" + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ DialerSearchLookupColumns.NAME_TYPE + ",‘"
+ filterParam + "‘" + ")");
}else{
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + baseLookUpTable
+ " WHERE " + " DIALER_SEARCH_MATCH_FILTER(" + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ DialerSearchLookupColumns.NAME_TYPE + ",‘"
+ filterParam + "‘" + ")");
}
db.execSQL("DROP INDEX IF EXISTS idx_" + tempTable);
db.execSQL("CREATE INDEX idx_" + tempTable + " ON " + tempTable + "(" + DsTempTableColumns._ID + "," + DsTempTableColumns.NAME_TYPE + ")");
//Use name_type AS order key.
//Name_type is just a flag to distinguish matched number and mismatched number
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempViewTable
+ " AS SELECT " + DS_VIEW_NAME_COLUMNS
+ ", " + TEMP_TABLE_ALIAS_NUMBER + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_DATA_OFFSETS
+ ", " + TEMP_TABLE_ALIAS_NAME + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_NAME_OFFSETS
+ " FROM (SELECT * FROM " + baseViewTable
+ " WHERE " + DialerSearch.RAW_CONTACT_ID
+ " IN (SELECT " + DsTempTableColumns.RAW_CONTACT_ID
+ " FROM " + tempTable + ") "
+ ") AS " + TEMP_BASEVIEW_ALIAS
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NUMBER
+ " ON " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_LOOKUP_ID
+ " AND " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.PHONE_EXACT
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NAME
+ " ON " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_ID
+ " AND " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.NAME_EXACT
+ " ORDER BY " + DialerSearch.RAW_CONTACT_ID + ","
+ TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + ","
+ DialerSearch.CALL_DATE);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return tempViewTable;
}
private String queryDialerSearchIncrement8XXX(SQLiteDatabase db, String filterParam) {
//TO get filter parameter
log(" DIALER_SEARCH_INCREMENT 8XXX");
//Check Input OR Delete
int numberCount = filterParam.length();
String baseLookUpTable,baseViewTable;
boolean deleteOperation = false;
if (prevSearchNumberLeng > numberCount) {
// current operation is delete number to search
db.execSQL("DROP INDEX IF EXISTS idx_" + TEMP_DIALER_SEARCH_TABLE + prevSearchNumberLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE + prevSearchNumberLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW + prevSearchNumberLeng);
deleteOperation = true;
}
prevSearchNumberLeng = numberCount;
//Check to input OR delete END
if (numberCount == 1) {
baseLookUpTable = new String(TEMP_DIALER_SEARCH_TABLE);
baseViewTable = new String(TEMP_DIALER_SEARCH_VIEW);
} else {
int idx = numberCount - 1;
baseLookUpTable = new String(TEMP_DIALER_SEARCH_TABLE + idx);
baseViewTable = new String(TEMP_DIALER_SEARCH_VIEW + idx);
}
String tempViewTable = TEMP_DIALER_SEARCH_VIEW + numberCount;
db.beginTransaction();
try {
//TO CREATE NEW TEMP TABLE
if (deleteOperation == false) {
/* Create temp table from name_lookup table */
String tempTable = TEMP_DIALER_SEARCH_TABLE + numberCount;
boolean isFirstQuery = numberCount==1;
String mTableColumns = getDialerSearchNameTableColumns(mDisplayOrder,filterParam,isFirstQuery);
if(isFirstQuery){
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + baseLookUpTable
+ " WHERE " + " DIALER_SEARCH_MATCH_FILTER(" + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ DialerSearchLookupColumns.NAME_TYPE + ",‘"
+ filterParam + "‘" + ")");
}else{
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + baseLookUpTable
+ " WHERE " + " DIALER_SEARCH_MATCH_FILTER(" + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ DialerSearchLookupColumns.NAME_TYPE + ",‘"
+ filterParam + "‘" + ")");
}
db.execSQL("DROP INDEX IF EXISTS idx_" + tempTable);
db.execSQL("CREATE INDEX idx_" + tempTable + " ON " + tempTable + "(" + DsTempTableColumns._ID + "," + DsTempTableColumns.NAME_TYPE + ")");
//Use name_type AS order key.
//Name_type is just a flag to distinguish matched number and mismatched number
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempViewTable
+ " AS SELECT " + DS_VIEW_NAME_COLUMNS
+ ", " + TEMP_TABLE_ALIAS_NUMBER + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_DATA_OFFSETS
+ ", " + TEMP_TABLE_ALIAS_NAME + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_NAME_OFFSETS
+ " FROM (SELECT * FROM " + baseViewTable
+ " WHERE " + DialerSearch.RAW_CONTACT_ID
+ " IN (SELECT " + DsTempTableColumns.RAW_CONTACT_ID
+ " FROM " + tempTable + ") "
+ ") AS " + TEMP_BASEVIEW_ALIAS
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NUMBER
+ " ON " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_LOOKUP_ID
+ " AND " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.PHONE_EXACT
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NAME
+ " ON " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_ID
+ " AND " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.NAME_EXACT
+ " ORDER BY " + DialerSearch.RAW_CONTACT_ID + ","
+ TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + ","
+ DialerSearch.CALL_DATE);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return tempViewTable;
}
private String queryDialerSearchSimpleXXX(SQLiteDatabase db, String filterParam) {
log(" DIALER_SEARCH_SIMPLE XXX");
String tempTable = "temp_ds_name_lookup_table_number_XXX";
String tempViewTable = "temp_ds_view_table_number_XXX";
String mTableColumns = getDialerSearchNameTableColumns(mDisplayOrder,filterParam,true);
String noResult = "NA";
if(filterParam.length() == 0)
return noResult;
db.beginTransaction();
try {
if (prevSearchNumberLengXXX> 0) {
for (int tmpLeng=prevSearchNumberLengXXX;tmpLeng>0;tmpLeng--) {
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE_XXX + tmpLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW_XXX + tmpLeng);
}
}
db.execSQL("DROP INDEX IF EXISTS idx_" + tempTable);
db.execSQL("DROP TABLE IF EXISTS " + tempTable);
db.execSQL("CREATE TEMP TABLE " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + TEMP_DIALER_SEARCH_TABLE_XXX
+ " WHERE " + DialerSearchLookupColumns.IS_VISIABLE + "=1 AND " + DialerSearch.MATCHED_DATA_OFFSETS + " IS NOT NULL ");
db.execSQL("CREATE INDEX idx_" + tempTable + " ON " + tempTable + "(" + DsTempTableColumns._ID + "," + DsTempTableColumns.NAME_TYPE + ")");
db.execSQL("DROP TABLE IF EXISTS " + tempViewTable);
db.execSQL("CREATE TEMP TABLE " + tempViewTable
+ " AS SELECT " + DS_VIEW_NAME_COLUMNS
+ ", " + TEMP_TABLE_ALIAS_NUMBER + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_DATA_OFFSETS
+ ", " + TEMP_TABLE_ALIAS_NAME + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_NAME_OFFSETS
+ " FROM (SELECT * FROM " + TEMP_DIALER_SEARCH_VIEW_XXX
+ " WHERE " + DialerSearch.RAW_CONTACT_ID + " IN "
+ " (SELECT " + DsTempTableColumns.RAW_CONTACT_ID + " FROM " + tempTable + ") "
+ ") AS " + TEMP_BASEVIEW_ALIAS
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NUMBER
+ " ON " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_LOOKUP_ID
+ " AND " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.PHONE_EXACT
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NAME
+ " ON " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_ID
+ " AND " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.NAME_EXACT
+ " ORDER BY " + DialerSearch.RAW_CONTACT_ID + ","
+ TEMP_TABLE_ALIAS_NUMBER + "."
+ DsTempTableColumns.NAME_TYPE + ","
+ DialerSearch.CALL_DATE);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return tempViewTable;
}
private String queryDialerSearchSimple8XXX(SQLiteDatabase db, String filterParam) {
log(" DIALER_SEARCH_SIMPLE 8XXX");
String tempTable = "temp_ds_name_lookup_table_number" ;
String tempViewTable = "temp_ds_view_table_number";
String mTableColumns = getDialerSearchNameTableColumns(mDisplayOrder,filterParam,true);
db.beginTransaction();
try {
if (prevSearchNumberLeng > 0) {
for (int tmpLeng=prevSearchNumberLeng;tmpLeng>0;tmpLeng--) {
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE + tmpLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW + tmpLeng);
}
}
db.execSQL("DROP INDEX IF EXISTS idx_" + tempTable);
db.execSQL("DROP TABLE IF EXISTS " + tempTable);
db.execSQL("CREATE TEMP TABLE " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + TEMP_DIALER_SEARCH_TABLE
+ " WHERE " + DialerSearchLookupColumns.IS_VISIABLE + "=1 AND " + DialerSearch.MATCHED_DATA_OFFSETS + " IS NOT NULL ");
db.execSQL("CREATE INDEX idx_" + tempTable + " ON " + tempTable + "(" + DsTempTableColumns._ID + "," + DsTempTableColumns.NAME_TYPE + ")");
db.execSQL("DROP TABLE IF EXISTS " + tempViewTable);
db.execSQL("CREATE TEMP TABLE " + tempViewTable
+ " AS SELECT " + DS_VIEW_NAME_COLUMNS
+ ", " + TEMP_TABLE_ALIAS_NUMBER + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_DATA_OFFSETS
+ ", " + TEMP_TABLE_ALIAS_NAME + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_NAME_OFFSETS
+ " FROM (SELECT * FROM " + TEMP_DIALER_SEARCH_VIEW
+ " WHERE " + DialerSearch.RAW_CONTACT_ID + " IN "
+ " (SELECT " + DsTempTableColumns.RAW_CONTACT_ID + " FROM " + tempTable + ") "
+ ") AS " + TEMP_BASEVIEW_ALIAS
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NUMBER
+ " ON " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_LOOKUP_ID
+ " AND " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.PHONE_EXACT
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NAME
+ " ON " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_ID
+ " AND " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.NAME_EXACT
+ " ORDER BY " + DialerSearch.RAW_CONTACT_ID + ","
+ TEMP_TABLE_ALIAS_NUMBER + "."
+ DsTempTableColumns.NAME_TYPE + ","
+ DialerSearch.CALL_DATE);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return tempViewTable;
}
private Cursor combineTwoViewTable(SQLiteDatabase db, String viewTableXXX, String viewTable8XXX){
Log.d(TAG,"combineTwoViewTable, viewTableXXX:" + viewTableXXX + ". viewTable8XXX: " + viewTable8XXX);
Cursor searchResultCursor = null;
if(viewTableXXX.equels("NA") || viewTableXXX == null){
db.beginTransaction();
try {
searchResultCursor = db.rawQuery(
"SELECT " + DS_SEARCH_RESULTS_COLUMNS + " FROM " + viewTable8XXX
+ " GROUP BY " + DialerSearch.RAW_CONTACT_ID
+ " ORDER BY " + DialerSearch.CALL_DATE + " DESC,"
+ DialerSearch.SORT_KEY_PRIMARY + " COLLATE NOCASE",null);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return searchResultCursor;
}
db.beginTransaction();
try {
db.execSQL("DROP TABLE IF EXISTS " + COMBINE_RESULT_VIEW_TABLE);
db.execSQL("CREATE TEMP TABLE " + COMBINE_RESULT_VIEW_TABLE
+ " AS SELECT * FROM " + viewTableXXX
+ " UNION "
+ " SELECT * FROM " + viewTable8XXX);
searchResultCursor = db.rawQuery(
"SELECT " + DS_SEARCH_RESULTS_COLUMNS + " FROM " + COMBINE_RESULT_VIEW_TABLE
+ " GROUP BY " + DialerSearch.RAW_CONTACT_ID
+ " ORDER BY " + DialerSearch.CALL_DATE + " DESC,"
+ DialerSearch.SORT_KEY_PRIMARY + " COLLATE NOCASE",null);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return searchResultCursor;
}
//XT and end
2、修改DialerSearchController.java
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
log("[onQueryComplete]mIsShowLoadingTip:" + mIsShowLoadingTip);
if (mIsShowLoadingTip) {
showLoadingTips(mFragmentView, false, null, false);
}
Integer cnt = mSearchNumCntQ.poll();
if (cnt != null) {
mPrevQueryDigCnt = cnt.intValue();
}
log("+onQueryComplete");
final DialerSearchAdapter dialerSearchAdapter = mAdapter;
// Whenever we get a suggestions cursor, we need to immediately kick
// off another query for the complete list of contacts
if (cursor != null) {
log("[onQueryComplete]mIsLocaleChanging" + mIsLocaleChanging);
if (mIsLocaleChanging) {
cursor.close();
return;
}
mDialerSearchCursorCount = cursor.getCount();
log("[onQueryComplete]cursor count: " + mDialerSearchCursorCount);
String tempStr = mDigits.getText().toString();
if (tempStr != null && mDialerSearchCursorCount > 0) {
mNoResultDigCnt = 0;
/** M: New Feature Phone Landscape UI @{ */
if (mSearchTitle != null) {
mSearchTitle.setVisibility(View.GONE);
}
/** @ } */
// notify UI to update view only if the search digit count
// is equal to current input search digits in text view
// since user may input/delete quickly, the list view will
// be update continuously and take a lot of time
if (DialerSearchUtils.tripHyphen(tempStr).length() == mPrevQueryDigCnt) {
// Don‘t need to close cursor every time after query
// complete.
if (mOnDialerSearchResult != null) {
mOnDialerSearchResult
.onDialerSearchResult(obtainDialerSearchResult(mDialerSearchCursorCount));
}
dialerSearchAdapter.setResultCursor(cursor);
dialerSearchAdapter.changeCursor(cursor);
} else {
cursor.close();
}
} else {
if (mOnDialerSearchResult != null) {
mOnDialerSearchResult
.onDialerSearchResult(obtainDialerSearchResult(mDialerSearchCursorCount));
}
//XT and
//mNoResultDigCnt = mDigits.getText().length();
if(tempStr != null && (tempStr.startsWith("+") || tempStr.startsWith("+7") || tempStr.startsWith("8"))){
mNoResultDigCnt = 0;
}else{
mNoResultDigCnt = mDigits.getText().length();
}
log("[onQueryComplete]mNoResultDigCnt: " + mNoResultDigCnt);
//XT and end
cursor.close();
dialerSearchAdapter.setResultCursor(null);
/** M: New Feature Phone Landscape UI @{ */
if (mSearchTitle != null) {
if (mDigits.length() > 0) {
mSearchTitle.setText(R.string.no_match_call_log);
} else {
mSearchTitle.setText(R.string.no_call_log);
}
mSearchTitle.setVisibility(View.VISIBLE);
}
/** @ }*/
}
}
log("-onQueryComplete");
}
1.查询“+7123456”这个号码,输入“8123456”也能够检索到。反之亦然。
2. 输入“8”,能匹配“8”开头的数字或者“TUV”开头的名字。
KK版本对DialerSearch有一定的修改,请参考FAQ11308 [DialerSearch] 在KK上如何实现+7与8开头的号码在拨号盘上搜索相互匹配。
修改的部分有XT and标识
1、修改ContactsProvider2.java
先添加定义
private int prevSearchNumberLengXXX = 0;
private static final String TEMP_DIALER_SEARCH_VIEW_XXX = "temp_dialer_search_view_xxx";
private static final String TEMP_DIALER_SEARCH_TABLE_XXX = "temp_dialer_search_table_xxx";
private static final String COMBINE_RESULT_VIEW_TABLE = "combine_result_view_table";
再修改
private Cursor queryDialerSearchSimple(SQLiteDatabase db, Uri uri) {
log(" DIALER_SEARCH_SIMPLE");
String filterParam = "";
String uriStr = uri.toString();
StringBuilder searchInfo = new StringBuilder();
if (uriStr.indexOf("dialer_search_number") > 0) {
String uriString = uri.toString();
int previous = 0;
int current;
while ((current = uriString.indexOf(‘/‘, previous)) > -1) {
previous = current + 1;
}
filterParam = uriString.substring(previous);
Log.i(TAG, "filterParam: "+filterParam);
} else {
return null;
}
//XT and
if(filterParam.startsWith("8") || filterParam.startsWith("+7")){
String filterParam2 = null;
if(filterParam.startsWith("8"))
filterParam2 = filterParam.substring(1);
else if(filterParam.startsWith("+7"))
filterParam2 = filterParam.substring(2);
String tempViewTableXXX = queryDialerSearchSimpleXXX(db, filterParam2);
String tempViewTable8XXX = queryDialerSearchSimple8XXX(db, filterParam);
Cursor result = combineTwoViewTable(db, tempViewTableXXX, tempViewTable8XXX);
return result;
}
//XT and end
String tempTable = "temp_ds_name_lookup_table_number" ;
String tempViewTable = "temp_ds_view_table_number";
String mTableColumns = getDialerSearchNameTableColumns(mDisplayOrder,filterParam,true);
Cursor searchResultCursor = null;
db.beginTransaction();
try {
if (prevSearchNumberLeng > 0) {
for (int tmpLeng=prevSearchNumberLeng;tmpLeng>0;tmpLeng--) {
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE + tmpLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW + tmpLeng);
}
}
db.execSQL("DROP INDEX IF EXISTS idx_" + tempTable);
db.execSQL("DROP TABLE IF EXISTS " + tempTable);
db.execSQL("CREATE TEMP TABLE " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + TEMP_DIALER_SEARCH_TABLE
+ " WHERE " + DialerSearchLookupColumns.IS_VISIABLE + "=1 AND " + DialerSearch.MATCHED_DATA_OFFSETS + " IS NOT NULL ");
db.execSQL("CREATE INDEX idx_" + tempTable + " ON " + tempTable + "(" + DsTempTableColumns._ID + "," + DsTempTableColumns.NAME_TYPE + ")");
db.execSQL("DROP TABLE IF EXISTS " + tempViewTable);
db.execSQL("CREATE TEMP TABLE " + tempViewTable
+ " AS SELECT " + DS_VIEW_NAME_COLUMNS
+ ", " + TEMP_TABLE_ALIAS_NUMBER + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_DATA_OFFSETS
+ ", " + TEMP_TABLE_ALIAS_NAME + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_NAME_OFFSETS
+ " FROM (SELECT * FROM " + TEMP_DIALER_SEARCH_VIEW
+ " WHERE " + DialerSearch.RAW_CONTACT_ID + " IN "
+ " (SELECT " + DsTempTableColumns.RAW_CONTACT_ID + " FROM " + tempTable + ") "
+ ") AS " + TEMP_BASEVIEW_ALIAS
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NUMBER
+ " ON " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_LOOKUP_ID
+ " AND " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.PHONE_EXACT
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NAME
+ " ON " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_ID
+ " AND " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.NAME_EXACT
+ " ORDER BY " + DialerSearch.RAW_CONTACT_ID + ","
+ TEMP_TABLE_ALIAS_NUMBER + "."
+ DsTempTableColumns.NAME_TYPE + ","
+ DialerSearch.CALL_DATE);
searchResultCursor = db.rawQuery(
"SELECT " + DS_SEARCH_RESULTS_COLUMNS + " FROM " + tempViewTable
+ " GROUP BY " + DialerSearch.RAW_CONTACT_ID
+ " ORDER BY " + DialerSearch.CALL_DATE + " DESC,"
+ DialerSearch.SORT_KEY_PRIMARY + " COLLATE NOCASE",null);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return searchResultCursor;
}
private Cursor queryDialerSearchIncrement(SQLiteDatabase db, Uri uri) {
//TO get filter parameter
log(" DIALER_SEARCH_INCREMENT");
String filterParam = "";
String uriStr = uri.toString();
if (uriStr.indexOf("dialer_search") > 0) {
String uriString = uri.toString();
int previous = 0;
int current;
while ((current = uriString.indexOf(‘/‘, previous)) > -1) {
previous = current + 1;
}
filterParam = uriString.substring(previous);
log("filterParam: "+filterParam);
} else {
Log.i(TAG, "filterParam is null");
return null;
}
if (filterParam.indexOf("init") > -1) { // the initial state of dialer search is call log list
int pos = filterParam.indexOf(‘#‘, 0);
mDisplayOrder = (int)(filterParam.charAt(pos+1) - ‘0‘);
mSortOrder = (int)((filterParam.charAt(filterParam.indexOf(‘#‘, pos+1)+1)) - ‘0‘);
/*
* Bug Fix by Mediatek Begin.
* CR ID: ALPS00114597
* Descriptions:
*/
while (prevSearchNumberLeng > 0) {
// current operation is delete all digit number
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE + prevSearchNumberLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW + prevSearchNumberLeng);
prevSearchNumberLeng--;
}
/*
* Bug Fix by Mediatek End.
*/
if(prevSearchNumberLeng ==0 ){
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE);
db.execSQL("CREATE TEMP TABLE " + TEMP_DIALER_SEARCH_TABLE
+ " AS SELECT "
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns._ID + " AS " + DialerSearchLookupColumns._ID + " ,"
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.DATA_ID + " AS " + DialerSearchLookupColumns.DATA_ID + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.RAW_CONTACT_ID + " AS " + DialerSearchLookupColumns.RAW_CONTACT_ID + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NAME_TYPE + " AS " + DialerSearchLookupColumns.NAME_TYPE + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.CALL_LOG_ID + " AS " + DialerSearchLookupColumns.CALL_LOG_ID + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NUMBER_COUNT + " AS " + DialerSearchLookupColumns.NUMBER_COUNT + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.IS_VISIABLE + " AS " + DialerSearchLookupColumns.IS_VISIABLE + ","
+ " (CASE WHEN " + DialerSearchLookupColumns.CALL_LOG_ID + " > 0 " + " AND " + DialerSearchLookupColumns.NAME_TYPE + "=" + DialerSearchLookupType.PHONE_EXACT
+ " THEN " + Tables.CALLS + "." + Calls.NUMBER
+ " ELSE " + Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NORMALIZED_NAME
+ " END) AS " + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + " AS " + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ " (CASE WHEN " + DialerSearchLookupColumns.CALL_LOG_ID + " > 0 " + " AND " + DialerSearchLookupColumns.NAME_TYPE + "=" + DialerSearchLookupType.PHONE_EXACT
+ " THEN " + Tables.CALLS + "." + Calls.NUMBER
+ " ELSE " + Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NORMALIZED_NAME_ALTERNATIVE
+ " END) AS " + DialerSearchLookupColumns.NORMALIZED_NAME_ALTERNATIVE + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS_ALTERNATIVE + " AS " + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS_ALTERNATIVE
+ " FROM " + Tables.DIALER_SEARCH
+ " LEFT JOIN " + Tables.CALLS
+ " ON " + Tables.CALLS + "." + Calls._ID + "=" + DialerSearchLookupColumns.CALL_LOG_ID
+ " WHERE " + DialerSearchLookupColumns.IS_VISIABLE + "=1");
String mViewColumns = getDialerSearchViewColumns(mDisplayOrder,mSortOrder);
db.execSQL("DROP INDEX IF EXISTS idx_" + TEMP_DIALER_SEARCH_VIEW + "_rawid");
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW);
db.execSQL("CREATE TEMP TABLE " + TEMP_DIALER_SEARCH_VIEW
+ " AS SELECT " + mViewColumns + " FROM " + Views.DIALER_SEARCH_VIEW);
db.execSQL("CREATE INDEX idx_" + TEMP_DIALER_SEARCH_VIEW + "_rawid ON "
+ TEMP_DIALER_SEARCH_VIEW + "(" + DialerSearch.RAW_CONTACT_ID + ")");
}
return db.rawQuery(
"SELECT " + DS_INIT_SEARCH_RESULTS_COLUMNS
+" FROM (SELECT " + DS_INIT_SEARCH_RESULTS_COLUMNS + ", " + DialerSearch.RAW_CONTACT_ID
+ " FROM " + TEMP_DIALER_SEARCH_VIEW
+ " WHERE " + DialerSearch.CALL_LOG_ID + " > 0 "
+ " ORDER BY " + DialerSearch.CALL_DATE + " )"
+ " GROUP BY " + DialerSearch.RAW_CONTACT_ID
+ " ORDER BY " + DialerSearch.CALL_DATE + " DESC", null); // for call log only need to search number
} else if (filterParam.indexOf("null_input") > -1) {
while (prevSearchNumberLeng > 0) {
// current operation is delete all digit number
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE + prevSearchNumberLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW + prevSearchNumberLeng);
prevSearchNumberLeng--;
}
return db.rawQuery(
"SELECT " + DS_INIT_SEARCH_RESULTS_COLUMNS
+" FROM (SELECT " + DS_INIT_SEARCH_RESULTS_COLUMNS + ", " + DialerSearch.RAW_CONTACT_ID
+ " FROM " + TEMP_DIALER_SEARCH_VIEW
+ " WHERE " + DialerSearch.CALL_LOG_ID + " > 0 "
+ " ORDER BY " + DialerSearch.CALL_DATE + " )"
+ " GROUP BY " + DialerSearch.RAW_CONTACT_ID
+ " ORDER BY " + DialerSearch.CALL_DATE + " DESC", null);
}
//XT and
if(filterParam.startsWith("8") || filterParam.startsWith("+7")){
String filterParam2 = null;
if(filterParam.startsWith("8"))
filterParam2 = filterParam.substring(1);
else if(filterParam.startsWith("+7"))
filterParam2 = filterParam.substring(2);
String tempViewTableXXX = queryDialerSearchIncrementXXX(db, filterParam2);
String tempViewTable8XXX = queryDialerSearchIncrement8XXX(db, filterParam);
Cursor result = combineTwoViewTable(db, tempViewTableXXX, tempViewTable8XXX);
return result;
}
//XT and end
//Check Input OR Delete
int numberCount = filterParam.length();
String baseLookUpTable,baseViewTable;
boolean deleteOperation = false;
if (prevSearchNumberLeng > numberCount) {
// current operation is delete number to search
db.execSQL("DROP INDEX IF EXISTS idx_" + TEMP_DIALER_SEARCH_TABLE + prevSearchNumberLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE + prevSearchNumberLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW + prevSearchNumberLeng);
deleteOperation = true;
}
prevSearchNumberLeng = numberCount;
//Check to input OR delete END
if (numberCount == 1) {
baseLookUpTable = new String(TEMP_DIALER_SEARCH_TABLE);
baseViewTable = new String(TEMP_DIALER_SEARCH_VIEW);
} else {
int idx = numberCount - 1;
baseLookUpTable = new String(TEMP_DIALER_SEARCH_TABLE + idx);
baseViewTable = new String(TEMP_DIALER_SEARCH_VIEW + idx);
}
String tempViewTable = TEMP_DIALER_SEARCH_VIEW + numberCount;
Cursor searchResultCursor = null;
db.beginTransaction();
try {
//TO CREATE NEW TEMP TABLE
if (deleteOperation == false) {
/* Create temp table from name_lookup table */
String tempTable = TEMP_DIALER_SEARCH_TABLE + numberCount;
boolean isFirstQuery = numberCount==1;
String mTableColumns = getDialerSearchNameTableColumns(mDisplayOrder,filterParam,isFirstQuery);
if(isFirstQuery){
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + baseLookUpTable
+ " WHERE " + " DIALER_SEARCH_MATCH_FILTER(" + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ DialerSearchLookupColumns.NAME_TYPE + ",‘"
+ filterParam + "‘" + ")");
}else{
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + baseLookUpTable
+ " WHERE " + " DIALER_SEARCH_MATCH_FILTER(" + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ DialerSearchLookupColumns.NAME_TYPE + ",‘"
+ filterParam + "‘" + ")");
}
db.execSQL("DROP INDEX IF EXISTS idx_" + tempTable);
db.execSQL("CREATE INDEX idx_" + tempTable + " ON " + tempTable + "(" + DsTempTableColumns._ID + "," + DsTempTableColumns.NAME_TYPE + ")");
//Use name_type AS order key.
//Name_type is just a flag to distinguish matched number and mismatched number
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempViewTable
+ " AS SELECT " + DS_VIEW_NAME_COLUMNS
+ ", " + TEMP_TABLE_ALIAS_NUMBER + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_DATA_OFFSETS
+ ", " + TEMP_TABLE_ALIAS_NAME + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_NAME_OFFSETS
+ " FROM (SELECT * FROM " + baseViewTable
+ " WHERE " + DialerSearch.RAW_CONTACT_ID
+ " IN (SELECT " + DsTempTableColumns.RAW_CONTACT_ID
+ " FROM " + tempTable + ") "
+ ") AS " + TEMP_BASEVIEW_ALIAS
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NUMBER
+ " ON " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_LOOKUP_ID
+ " AND " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.PHONE_EXACT
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NAME
+ " ON " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_ID
+ " AND " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.NAME_EXACT
+ " ORDER BY " + DialerSearch.RAW_CONTACT_ID + ","
+ TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + ","
+ DialerSearch.CALL_DATE);
}
//GET RESULTE FROM NEW TEMP TABLE
searchResultCursor = db.rawQuery(
"SELECT " + DS_SEARCH_RESULTS_COLUMNS + " FROM " + tempViewTable
+ " GROUP BY " + DialerSearch.RAW_CONTACT_ID
+ " ORDER BY " + DialerSearch.CALL_DATE + " DESC,"
+ DialerSearch.SORT_KEY_PRIMARY + " COLLATE NOCASE",null);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return searchResultCursor;
}
//XT and
private String queryDialerSearchIncrementXXX(SQLiteDatabase db, String filterParam) {
//TO get filter parameter
log(" DIALER_SEARCH_INCREMENT XXX");
String noResultXXX = "NA";
if (filterParam.length() == 0) {
while (prevSearchNumberLengXXX > 0) {
// current operation is delete all digit number
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE_XXX + prevSearchNumberLengXXX);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW_XXX + prevSearchNumberLengXXX);
prevSearchNumberLengXXX--;
}
if(prevSearchNumberLengXXX ==0 ){
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE_XXX);
db.execSQL("CREATE TEMP TABLE " + TEMP_DIALER_SEARCH_TABLE_XXX
+ " AS SELECT "
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns._ID + " AS " + DialerSearchLookupColumns._ID + " ,"
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.DATA_ID + " AS " + DialerSearchLookupColumns.DATA_ID + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.RAW_CONTACT_ID + " AS " + DialerSearchLookupColumns.RAW_CONTACT_ID + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NAME_TYPE + " AS " + DialerSearchLookupColumns.NAME_TYPE + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.CALL_LOG_ID + " AS " + DialerSearchLookupColumns.CALL_LOG_ID + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NUMBER_COUNT + " AS " + DialerSearchLookupColumns.NUMBER_COUNT + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.IS_VISIABLE + " AS " + DialerSearchLookupColumns.IS_VISIABLE + ","
+ " (CASE WHEN " + DialerSearchLookupColumns.CALL_LOG_ID + " > 0 " + " AND " + DialerSearchLookupColumns.NAME_TYPE + "=" + DialerSearchLookupType.PHONE_EXACT
+ " THEN " + Tables.CALLS + "." + Calls.NUMBER
+ " ELSE " + Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NORMALIZED_NAME
+ " END) AS " + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + " AS " + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ " (CASE WHEN " + DialerSearchLookupColumns.CALL_LOG_ID + " > 0 " + " AND " + DialerSearchLookupColumns.NAME_TYPE + "=" + DialerSearchLookupType.PHONE_EXACT
+ " THEN " + Tables.CALLS + "." + Calls.NUMBER
+ " ELSE " + Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.NORMALIZED_NAME_ALTERNATIVE
+ " END) AS " + DialerSearchLookupColumns.NORMALIZED_NAME_ALTERNATIVE + ","
+ Tables.DIALER_SEARCH + "." + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS_ALTERNATIVE + " AS " + DialerSearchLookupColumns.SEARCH_DATA_OFFSETS_ALTERNATIVE
+ " FROM " + Tables.DIALER_SEARCH
+ " LEFT JOIN " + Tables.CALLS
+ " ON " + Tables.CALLS + "." + Calls._ID + "=" + DialerSearchLookupColumns.CALL_LOG_ID
+ " WHERE " + DialerSearchLookupColumns.IS_VISIABLE + "=1");
String mViewColumns = getDialerSearchViewColumns(mDisplayOrder,mSortOrder);
db.execSQL("DROP INDEX IF EXISTS idx_" + TEMP_DIALER_SEARCH_VIEW_XXX + "_rawid");
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW_XXX);
db.execSQL("CREATE TEMP TABLE " + TEMP_DIALER_SEARCH_VIEW_XXX
+ " AS SELECT " + mViewColumns + " FROM " + Views.DIALER_SEARCH_VIEW);
db.execSQL("CREATE INDEX idx_" + TEMP_DIALER_SEARCH_VIEW_XXX + "_rawid ON "
+ TEMP_DIALER_SEARCH_VIEW_XXX + "(" + DialerSearch.RAW_CONTACT_ID + ")");
}
return noResultXXX;
}
//Check Input OR Delete
int numberCount = filterParam.length();
String baseLookUpTable,baseViewTable;
boolean deleteOperation = false;
if (prevSearchNumberLengXXX > numberCount) {
// current operation is delete number to search
db.execSQL("DROP INDEX IF EXISTS idx_" + TEMP_DIALER_SEARCH_TABLE_XXX + prevSearchNumberLengXXX);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE_XXX + prevSearchNumberLengXXX);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW_XXX + prevSearchNumberLengXXX);
deleteOperation = true;
}
prevSearchNumberLengXXX = numberCount;
//Check to input OR delete END
if (numberCount == 1) {
baseLookUpTable = new String(TEMP_DIALER_SEARCH_TABLE_XXX);
baseViewTable = new String(TEMP_DIALER_SEARCH_VIEW_XXX);
} else {
int idx = numberCount - 1;
baseLookUpTable = new String(TEMP_DIALER_SEARCH_TABLE_XXX + idx);
baseViewTable = new String(TEMP_DIALER_SEARCH_VIEW_XXX + idx);
}
String tempViewTable = TEMP_DIALER_SEARCH_VIEW_XXX + numberCount;
db.beginTransaction();
try {
//TO CREATE NEW TEMP TABLE
if (deleteOperation == false) {
/* Create temp table from name_lookup table */
String tempTable = TEMP_DIALER_SEARCH_TABLE_XXX + numberCount;
boolean isFirstQuery = numberCount==1;
String mTableColumns = getDialerSearchNameTableColumns(mDisplayOrder,filterParam,isFirstQuery);
if(isFirstQuery){
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + baseLookUpTable
+ " WHERE " + " DIALER_SEARCH_MATCH_FILTER(" + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ DialerSearchLookupColumns.NAME_TYPE + ",‘"
+ filterParam + "‘" + ")");
}else{
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + baseLookUpTable
+ " WHERE " + " DIALER_SEARCH_MATCH_FILTER(" + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ DialerSearchLookupColumns.NAME_TYPE + ",‘"
+ filterParam + "‘" + ")");
}
db.execSQL("DROP INDEX IF EXISTS idx_" + tempTable);
db.execSQL("CREATE INDEX idx_" + tempTable + " ON " + tempTable + "(" + DsTempTableColumns._ID + "," + DsTempTableColumns.NAME_TYPE + ")");
//Use name_type AS order key.
//Name_type is just a flag to distinguish matched number and mismatched number
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempViewTable
+ " AS SELECT " + DS_VIEW_NAME_COLUMNS
+ ", " + TEMP_TABLE_ALIAS_NUMBER + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_DATA_OFFSETS
+ ", " + TEMP_TABLE_ALIAS_NAME + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_NAME_OFFSETS
+ " FROM (SELECT * FROM " + baseViewTable
+ " WHERE " + DialerSearch.RAW_CONTACT_ID
+ " IN (SELECT " + DsTempTableColumns.RAW_CONTACT_ID
+ " FROM " + tempTable + ") "
+ ") AS " + TEMP_BASEVIEW_ALIAS
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NUMBER
+ " ON " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_LOOKUP_ID
+ " AND " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.PHONE_EXACT
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NAME
+ " ON " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_ID
+ " AND " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.NAME_EXACT
+ " ORDER BY " + DialerSearch.RAW_CONTACT_ID + ","
+ TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + ","
+ DialerSearch.CALL_DATE);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return tempViewTable;
}
private String queryDialerSearchIncrement8XXX(SQLiteDatabase db, String filterParam) {
//TO get filter parameter
log(" DIALER_SEARCH_INCREMENT 8XXX");
//Check Input OR Delete
int numberCount = filterParam.length();
String baseLookUpTable,baseViewTable;
boolean deleteOperation = false;
if (prevSearchNumberLeng > numberCount) {
// current operation is delete number to search
db.execSQL("DROP INDEX IF EXISTS idx_" + TEMP_DIALER_SEARCH_TABLE + prevSearchNumberLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE + prevSearchNumberLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW + prevSearchNumberLeng);
deleteOperation = true;
}
prevSearchNumberLeng = numberCount;
//Check to input OR delete END
if (numberCount == 1) {
baseLookUpTable = new String(TEMP_DIALER_SEARCH_TABLE);
baseViewTable = new String(TEMP_DIALER_SEARCH_VIEW);
} else {
int idx = numberCount - 1;
baseLookUpTable = new String(TEMP_DIALER_SEARCH_TABLE + idx);
baseViewTable = new String(TEMP_DIALER_SEARCH_VIEW + idx);
}
String tempViewTable = TEMP_DIALER_SEARCH_VIEW + numberCount;
db.beginTransaction();
try {
//TO CREATE NEW TEMP TABLE
if (deleteOperation == false) {
/* Create temp table from name_lookup table */
String tempTable = TEMP_DIALER_SEARCH_TABLE + numberCount;
boolean isFirstQuery = numberCount==1;
String mTableColumns = getDialerSearchNameTableColumns(mDisplayOrder,filterParam,isFirstQuery);
if(isFirstQuery){
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + baseLookUpTable
+ " WHERE " + " DIALER_SEARCH_MATCH_FILTER(" + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ DialerSearchLookupColumns.NAME_TYPE + ",‘"
+ filterParam + "‘" + ")");
}else{
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + baseLookUpTable
+ " WHERE " + " DIALER_SEARCH_MATCH_FILTER(" + DialerSearchLookupColumns.NORMALIZED_NAME + ","
+ DialerSearchLookupColumns.SEARCH_DATA_OFFSETS + ","
+ DialerSearchLookupColumns.NAME_TYPE + ",‘"
+ filterParam + "‘" + ")");
}
db.execSQL("DROP INDEX IF EXISTS idx_" + tempTable);
db.execSQL("CREATE INDEX idx_" + tempTable + " ON " + tempTable + "(" + DsTempTableColumns._ID + "," + DsTempTableColumns.NAME_TYPE + ")");
//Use name_type AS order key.
//Name_type is just a flag to distinguish matched number and mismatched number
db.execSQL("CREATE TEMP TABLE IF NOT EXISTS " + tempViewTable
+ " AS SELECT " + DS_VIEW_NAME_COLUMNS
+ ", " + TEMP_TABLE_ALIAS_NUMBER + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_DATA_OFFSETS
+ ", " + TEMP_TABLE_ALIAS_NAME + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_NAME_OFFSETS
+ " FROM (SELECT * FROM " + baseViewTable
+ " WHERE " + DialerSearch.RAW_CONTACT_ID
+ " IN (SELECT " + DsTempTableColumns.RAW_CONTACT_ID
+ " FROM " + tempTable + ") "
+ ") AS " + TEMP_BASEVIEW_ALIAS
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NUMBER
+ " ON " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_LOOKUP_ID
+ " AND " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.PHONE_EXACT
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NAME
+ " ON " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_ID
+ " AND " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.NAME_EXACT
+ " ORDER BY " + DialerSearch.RAW_CONTACT_ID + ","
+ TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + ","
+ DialerSearch.CALL_DATE);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return tempViewTable;
}
private String queryDialerSearchSimpleXXX(SQLiteDatabase db, String filterParam) {
log(" DIALER_SEARCH_SIMPLE XXX");
String tempTable = "temp_ds_name_lookup_table_number_XXX";
String tempViewTable = "temp_ds_view_table_number_XXX";
String mTableColumns = getDialerSearchNameTableColumns(mDisplayOrder,filterParam,true);
String noResult = "NA";
if(filterParam.length() == 0)
return noResult;
db.beginTransaction();
try {
if (prevSearchNumberLengXXX> 0) {
for (int tmpLeng=prevSearchNumberLengXXX;tmpLeng>0;tmpLeng--) {
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE_XXX + tmpLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW_XXX + tmpLeng);
}
}
db.execSQL("DROP INDEX IF EXISTS idx_" + tempTable);
db.execSQL("DROP TABLE IF EXISTS " + tempTable);
db.execSQL("CREATE TEMP TABLE " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + TEMP_DIALER_SEARCH_TABLE_XXX
+ " WHERE " + DialerSearchLookupColumns.IS_VISIABLE + "=1 AND " + DialerSearch.MATCHED_DATA_OFFSETS + " IS NOT NULL ");
db.execSQL("CREATE INDEX idx_" + tempTable + " ON " + tempTable + "(" + DsTempTableColumns._ID + "," + DsTempTableColumns.NAME_TYPE + ")");
db.execSQL("DROP TABLE IF EXISTS " + tempViewTable);
db.execSQL("CREATE TEMP TABLE " + tempViewTable
+ " AS SELECT " + DS_VIEW_NAME_COLUMNS
+ ", " + TEMP_TABLE_ALIAS_NUMBER + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_DATA_OFFSETS
+ ", " + TEMP_TABLE_ALIAS_NAME + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_NAME_OFFSETS
+ " FROM (SELECT * FROM " + TEMP_DIALER_SEARCH_VIEW_XXX
+ " WHERE " + DialerSearch.RAW_CONTACT_ID + " IN "
+ " (SELECT " + DsTempTableColumns.RAW_CONTACT_ID + " FROM " + tempTable + ") "
+ ") AS " + TEMP_BASEVIEW_ALIAS
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NUMBER
+ " ON " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_LOOKUP_ID
+ " AND " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.PHONE_EXACT
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NAME
+ " ON " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_ID
+ " AND " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.NAME_EXACT
+ " ORDER BY " + DialerSearch.RAW_CONTACT_ID + ","
+ TEMP_TABLE_ALIAS_NUMBER + "."
+ DsTempTableColumns.NAME_TYPE + ","
+ DialerSearch.CALL_DATE);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return tempViewTable;
}
private String queryDialerSearchSimple8XXX(SQLiteDatabase db, String filterParam) {
log(" DIALER_SEARCH_SIMPLE 8XXX");
String tempTable = "temp_ds_name_lookup_table_number" ;
String tempViewTable = "temp_ds_view_table_number";
String mTableColumns = getDialerSearchNameTableColumns(mDisplayOrder,filterParam,true);
db.beginTransaction();
try {
if (prevSearchNumberLeng > 0) {
for (int tmpLeng=prevSearchNumberLeng;tmpLeng>0;tmpLeng--) {
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_TABLE + tmpLeng);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_DIALER_SEARCH_VIEW + tmpLeng);
}
}
db.execSQL("DROP INDEX IF EXISTS idx_" + tempTable);
db.execSQL("DROP TABLE IF EXISTS " + tempTable);
db.execSQL("CREATE TEMP TABLE " + tempTable
+ " AS SELECT " + mTableColumns
+ " FROM " + TEMP_DIALER_SEARCH_TABLE
+ " WHERE " + DialerSearchLookupColumns.IS_VISIABLE + "=1 AND " + DialerSearch.MATCHED_DATA_OFFSETS + " IS NOT NULL ");
db.execSQL("CREATE INDEX idx_" + tempTable + " ON " + tempTable + "(" + DsTempTableColumns._ID + "," + DsTempTableColumns.NAME_TYPE + ")");
db.execSQL("DROP TABLE IF EXISTS " + tempViewTable);
db.execSQL("CREATE TEMP TABLE " + tempViewTable
+ " AS SELECT " + DS_VIEW_NAME_COLUMNS
+ ", " + TEMP_TABLE_ALIAS_NUMBER + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_DATA_OFFSETS
+ ", " + TEMP_TABLE_ALIAS_NAME + "." + DialerSearch.MATCHED_DATA_OFFSETS + " AS " + DialerSearch.MATCHED_NAME_OFFSETS
+ " FROM (SELECT * FROM " + TEMP_DIALER_SEARCH_VIEW
+ " WHERE " + DialerSearch.RAW_CONTACT_ID + " IN "
+ " (SELECT " + DsTempTableColumns.RAW_CONTACT_ID + " FROM " + tempTable + ") "
+ ") AS " + TEMP_BASEVIEW_ALIAS
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NUMBER
+ " ON " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_LOOKUP_ID
+ " AND " + TEMP_TABLE_ALIAS_NUMBER + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.PHONE_EXACT
+ " LEFT JOIN "
+ tempTable + " AS " + TEMP_TABLE_ALIAS_NAME
+ " ON " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns._ID + " = " + TEMP_BASEVIEW_ALIAS + "." + DialerSearch.NAME_ID
+ " AND " + TEMP_TABLE_ALIAS_NAME + "." + DsTempTableColumns.NAME_TYPE + " = " + DialerSearchLookupType.NAME_EXACT
+ " ORDER BY " + DialerSearch.RAW_CONTACT_ID + ","
+ TEMP_TABLE_ALIAS_NUMBER + "."
+ DsTempTableColumns.NAME_TYPE + ","
+ DialerSearch.CALL_DATE);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return tempViewTable;
}
private Cursor combineTwoViewTable(SQLiteDatabase db, String viewTableXXX, String viewTable8XXX){
Log.d(TAG,"combineTwoViewTable, viewTableXXX:" + viewTableXXX + ". viewTable8XXX: " + viewTable8XXX);
Cursor searchResultCursor = null;
if(viewTableXXX.equels("NA") || viewTableXXX == null){
db.beginTransaction();
try {
searchResultCursor = db.rawQuery(
"SELECT " + DS_SEARCH_RESULTS_COLUMNS + " FROM " + viewTable8XXX
+ " GROUP BY " + DialerSearch.RAW_CONTACT_ID
+ " ORDER BY " + DialerSearch.CALL_DATE + " DESC,"
+ DialerSearch.SORT_KEY_PRIMARY + " COLLATE NOCASE",null);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return searchResultCursor;
}
db.beginTransaction();
try {
db.execSQL("DROP TABLE IF EXISTS " + COMBINE_RESULT_VIEW_TABLE);
db.execSQL("CREATE TEMP TABLE " + COMBINE_RESULT_VIEW_TABLE
+ " AS SELECT * FROM " + viewTableXXX
+ " UNION "
+ " SELECT * FROM " + viewTable8XXX);
searchResultCursor = db.rawQuery(
"SELECT " + DS_SEARCH_RESULTS_COLUMNS + " FROM " + COMBINE_RESULT_VIEW_TABLE
+ " GROUP BY " + DialerSearch.RAW_CONTACT_ID
+ " ORDER BY " + DialerSearch.CALL_DATE + " DESC,"
+ DialerSearch.SORT_KEY_PRIMARY + " COLLATE NOCASE",null);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return searchResultCursor;
}
//XT and end
2、修改DialerSearchController.java
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
log("[onQueryComplete]mIsShowLoadingTip:" + mIsShowLoadingTip);
if (mIsShowLoadingTip) {
showLoadingTips(mFragmentView, false, null, false);
}
Integer cnt = mSearchNumCntQ.poll();
if (cnt != null) {
mPrevQueryDigCnt = cnt.intValue();
}
log("+onQueryComplete");
final DialerSearchAdapter dialerSearchAdapter = mAdapter;
// Whenever we get a suggestions cursor, we need to immediately kick
// off another query for the complete list of contacts
if (cursor != null) {
log("[onQueryComplete]mIsLocaleChanging" + mIsLocaleChanging);
if (mIsLocaleChanging) {
cursor.close();
return;
}
mDialerSearchCursorCount = cursor.getCount();
log("[onQueryComplete]cursor count: " + mDialerSearchCursorCount);
String tempStr = mDigits.getText().toString();
if (tempStr != null && mDialerSearchCursorCount > 0) {
mNoResultDigCnt = 0;
/** M: New Feature Phone Landscape UI @{ */
if (mSearchTitle != null) {
mSearchTitle.setVisibility(View.GONE);
}
/** @ } */
// notify UI to update view only if the search digit count
// is equal to current input search digits in text view
// since user may input/delete quickly, the list view will
// be update continuously and take a lot of time
if (DialerSearchUtils.tripHyphen(tempStr).length() == mPrevQueryDigCnt) {
// Don‘t need to close cursor every time after query
// complete.
if (mOnDialerSearchResult != null) {
mOnDialerSearchResult
.onDialerSearchResult(obtainDialerSearchResult(mDialerSearchCursorCount));
}
dialerSearchAdapter.setResultCursor(cursor);
dialerSearchAdapter.changeCursor(cursor);
} else {
cursor.close();
}
} else {
if (mOnDialerSearchResult != null) {
mOnDialerSearchResult
.onDialerSearchResult(obtainDialerSearchResult(mDialerSearchCursorCount));
}
//XT and
//mNoResultDigCnt = mDigits.getText().length();
if(tempStr != null && (tempStr.startsWith("+") || tempStr.startsWith("+7") || tempStr.startsWith("8"))){
mNoResultDigCnt = 0;
}else{
mNoResultDigCnt = mDigits.getText().length();
}
log("[onQueryComplete]mNoResultDigCnt: " + mNoResultDigCnt);
//XT and end
cursor.close();
dialerSearchAdapter.setResultCursor(null);
/** M: New Feature Phone Landscape UI @{ */
if (mSearchTitle != null) {
if (mDigits.length() > 0) {
mSearchTitle.setText(R.string.no_match_call_log);
} else {
mSearchTitle.setText(R.string.no_call_log);
}
mSearchTitle.setVisibility(View.VISIBLE);
}
/** @ }*/
}
}
log("-onQueryComplete");
}
android +7与8开头的号码在拨号盘上搜索相互匹配
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。