diff options
author | Qiang Chen <cqiang@codeaurora.org> | 2013-12-20 15:09:18 +0800 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2014-03-03 03:59:41 -0800 |
commit | c3907dd88f15539c0849dc47de6f17da0e2f382a (patch) | |
tree | b763f2020c862fe14fa43dc9421c9cded391043a | |
parent | fb6b2868899c3df745ef85d58ae46b44d694b31a (diff) | |
download | android_packages_apps_Dialer-c3907dd88f15539c0849dc47de6f17da0e2f382a.tar.gz android_packages_apps_Dialer-c3907dd88f15539c0849dc47de6f17da0e2f382a.tar.bz2 android_packages_apps_Dialer-c3907dd88f15539c0849dc47de6f17da0e2f382a.zip |
Dialer: Add call log to google search
User can search the call log information in google search app.
Change-Id: I44480d2e1fc8e30f533839defa1c1d8110531f05
-rw-r--r-- | AndroidManifest.xml | 22 | ||||
-rw-r--r-- | res/values-zh-rCN/strings.xml | 1 | ||||
-rw-r--r-- | res/values/strings.xml | 1 | ||||
-rwxr-xr-x | res/xml/calllog_searchable.xml | 39 | ||||
-rwxr-xr-x | src/com/android/dialer/CallLogSearchActivity.java | 54 | ||||
-rwxr-xr-x | src/com/android/dialer/calllog/CallLogSearchProvider.java | 217 |
6 files changed, 334 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 91f454287..e61d56545 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -126,6 +126,17 @@ </intent-filter> </activity> + <activity android:name="CallLogSearchActivity" + android:label="@string/recentCallsIconLabel" > + <intent-filter> + <action android:name="android.intent.action.SEARCH" /> + </intent-filter> + + <meta-data + android:name="android.app.searchable" + android:resource="@xml/calllog_searchable" /> + </activity> + <activity android:name="com.android.dialer.calllog.CallLogActivity" android:label="@string/call_log_activity_title" android:theme="@style/DialtactsThemeWithActionBarOverlay" @@ -176,6 +187,17 @@ </intent-filter> </activity> + <provider android:name=".calllog.CallLogSearchProvider" + android:authorities="com.android.dialer.calllog.calllogsearchprovider" + android:exported="true" > + <path-permission + android:pathPrefix="/search_suggest_query" + android:readPermission="android.permission.GLOBAL_SEARCH" /> + <path-permission + android:pathPrefix="/search_suggest_shortcut" + android:readPermission="android.permission.GLOBAL_SEARCH" /> + </provider> + <!-- Backwards compatibility: "Phone" from Gingerbread and earlier --> <activity-alias android:name="DialtactsActivity" android:targetActivity=".DialtactsActivity" diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index bbe4eb800..ad8e47db0 100644 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -161,4 +161,5 @@ <string name="no_favorites" msgid="5212485868783382971">"您收藏的联系人和经常通话\n的联系人都会显示在这里。\n现在就开始与联系人通话吧。"</string> <string name="contact_tooltip" msgid="7817483485692282287">"点按图片可查看所有号码,按住图片可重新排序"</string> <string name="description_dismiss" msgid="2146276780562549643">"关闭"</string> + <string name="calllog_search_hint">"搜索通话记录"</string> </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index c151dafba..1ca860ce5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -632,6 +632,7 @@ [CHAR LIMIT=NONE] --> <string name="contact_tooltip">Tap image to see all numbers or press and hold to reorder</string> + <string name="calllog_search_hint">"Search call log"</string> <string name="dial_conference">Dial conference</string> <string name="to_hint">1111:to;sip:abby@example.com:bcc;sip:bill@example.com:cc;</string> </resources> diff --git a/res/xml/calllog_searchable.xml b/res/xml/calllog_searchable.xml new file mode 100755 index 000000000..5c044fc37 --- /dev/null +++ b/res/xml/calllog_searchable.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Copyright (c) 2013, The Linux Foundation. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation, Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--> +<searchable xmlns:android="http://schemas.android.com/apk/res/android" + android:hint="@string/calllog_search_hint" + android:icon="@drawable/ic_menu_history_dk" + android:includeInGlobalSearch="true" + android:label="@string/recentCallsIconLabel" + android:queryAfterZeroResults="true" + android:searchMode="queryRewriteFromText" + android:searchSuggestAuthority="com.android.dialer.calllog.calllogsearchprovider" + android:searchSuggestIntentAction="android.intent.action.VIEW" + android:searchSuggestSelection=" ?" > +</searchable> diff --git a/src/com/android/dialer/CallLogSearchActivity.java b/src/com/android/dialer/CallLogSearchActivity.java new file mode 100755 index 000000000..ae44ed643 --- /dev/null +++ b/src/com/android/dialer/CallLogSearchActivity.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2013, The Linux Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation, Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.android.dialer; + +import android.app.Activity; +import android.content.Intent; + +public class CallLogSearchActivity extends Activity { + private static final String ACTION_SEARCH = "android.intent.action.SEARCH"; + + @Override + public void onStart() { + super.onStart(); + if (ACTION_SEARCH.equals(this.getIntent().getAction())) { + Intent intent = new Intent(this, CallDetailActivity.class); + String id = "0"; + if (this.getIntent().getData() != null) { + id = this.getIntent().getData().getQueryParameter("id"); + } + intent.putExtra(CallDetailActivity.EXTRA_CALL_LOG_IDS, new long[] { + Long.decode(id) + }); + startActivity(intent); + finish(); + } + } +} diff --git a/src/com/android/dialer/calllog/CallLogSearchProvider.java b/src/com/android/dialer/calllog/CallLogSearchProvider.java new file mode 100755 index 000000000..98a6703ed --- /dev/null +++ b/src/com/android/dialer/calllog/CallLogSearchProvider.java @@ -0,0 +1,217 @@ +/* + * Copyright (C) 2013, The Linux Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation, Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.android.dialer.calllog; + +import android.app.SearchManager; +import android.content.ContentProvider; +import android.content.ContentValues; +import android.content.Intent; +import android.database.Cursor; +import android.database.CursorWrapper; +import android.net.Uri; +import android.provider.CallLog.Calls; +import android.util.Log; + +import java.util.ArrayList; + +public class CallLogSearchProvider extends ContentProvider { + + private static final String TAG = "CallLogSearchProvider"; + public static String AUTHORITY = "com.android.dialer.calllog.calllogsearchprovider"; + public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/dictionary"); + private String[] mSuggestColumns = new String[] { + SearchManager.SUGGEST_COLUMN_INTENT_DATA, + SearchManager.SUGGEST_COLUMN_INTENT_ACTION, + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA, + SearchManager.SUGGEST_COLUMN_TEXT_1, + SearchManager.SUGGEST_COLUMN_TEXT_2 + }; + private final int SUGGEST_DATA_COLUMN_INDEX = 0; + private final int SUGGEST_ACTION_COLUMN_INDEX = 1; + private final int SUGGEST_EXTRA_DATA_COLUMN_INDEX = 2; + private final int SUGGEST_TEXT_COLUMN_INDEX = 3; + private final int SUGGEST_TEXT2_COLUMN_INDEX = 4; + + @Override + public boolean onCreate() { + return true; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, + String sortOrder) { + Log.d(TAG, "query selectionArgs[0]: " + selectionArgs[0]); + String select = "(" + Calls.NUMBER + " like '%" + selectionArgs[0] + "%' or " + + Calls.CACHED_NAME + + " like '%" + selectionArgs[0] + "%' )"; + Cursor cursor = getContext().getContentResolver().query( + Calls.CONTENT_URI, + new String[] { + "_id", Calls.NUMBER, Calls.CACHED_NAME + }, + select, + null, + null); + if (null == cursor) { + return null; + } + + return new SuggestionsCursor(cursor); + } + + private class SuggestionsCursor extends CursorWrapper { + int mColumnCount; + ArrayList<Row> mRows = new ArrayList<Row>(); + + public SuggestionsCursor(Cursor cursor) { + super(cursor); + mColumnCount = cursor.getColumnCount(); + fillRows(); + } + + public int getCount() { + return mRows.size(); + } + + public int getType(int columnIndex) { + return -1; + } + + private class Row { + String mName; + String mNumber; + + public Row(String name, String number) { + mName = name; + mNumber = number; + } + + public String getLine1() { + if (mName != null && !mName.equals("")) { + return mName; + } else { + return mNumber; + } + } + + public String getLine2() { + if (mName != null && !mName.equals("")) { + return mNumber; + } else { + return null; + } + } + } + + private void fillRows() { + int nameColumn = mCursor.getColumnIndex(Calls.CACHED_NAME); + int numberColumn = mCursor.getColumnIndex(Calls.NUMBER); + int count = mCursor.getCount(); + for (int i = 0; i < count; i++) { + mCursor.moveToPosition(i); + String name = mCursor.getString(nameColumn); + String number = mCursor.getString(numberColumn); + mRows.add(new Row(name, number)); + } + } + + public int getColumnCount() { + return mColumnCount + mSuggestColumns.length; + } + + public int getColumnIndex(String columnName) { + for (int i = 0; i < mSuggestColumns.length; i++) { + if (mSuggestColumns[i].equals(columnName)) { + return mColumnCount + i; + } + } + return mCursor.getColumnIndex(columnName); + } + + public String[] getColumnNames() { + String[] x = mCursor.getColumnNames(); + String[] y = new String[x.length + mSuggestColumns.length]; + + for (int i = 0; i < x.length; i++) { + y[i] = x[i]; + } + for (int i = 0; i < mSuggestColumns.length; i++) { + y[x.length + i] = mSuggestColumns[i]; + } + + return y; + } + + public String getString(int column) { + Log.d(TAG, "getString column" + column); + if (column < mColumnCount) { + return mCursor.getString(column); + } + + Row row = mRows.get(mCursor.getPosition()); + switch (column - mColumnCount) { + case SUGGEST_DATA_COLUMN_INDEX: + Uri uri = Calls.CONTENT_URI.buildUpon() + .appendQueryParameter("id", mCursor.getString(0)).build(); + return uri.toString(); + case SUGGEST_ACTION_COLUMN_INDEX: + return Intent.ACTION_SEARCH; + case SUGGEST_EXTRA_DATA_COLUMN_INDEX: + return getString(getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1)); + case SUGGEST_TEXT_COLUMN_INDEX: + return row.getLine1(); + case SUGGEST_TEXT2_COLUMN_INDEX: + return row.getLine2(); + default: + return null; + } + } + } + + @Override + public String getType(Uri uri) { + return null; + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + throw new UnsupportedOperationException(); + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + throw new UnsupportedOperationException(); + } + + @Override + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + throw new UnsupportedOperationException(); + } +} |