/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.quicksearchbox;
import com.android.quicksearchbox.util.Consumer;
import com.android.quicksearchbox.util.Consumers;
import com.android.quicksearchbox.util.SQLiteAsyncQuery;
import com.android.quicksearchbox.util.SQLiteTransaction;
import com.android.quicksearchbox.util.Util;
import com.google.common.annotations.VisibleForTesting;
import org.json.JSONException;
import android.app.SearchManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
/**
* A shortcut repository implementation that uses a log of every click.
*
* To inspect DB:
* # sqlite3 /data/data/com.android.quicksearchbox/databases/qsb-log.db
*
* TODO: Refactor this class.
*/
public class ShortcutRepositoryImplLog implements ShortcutRepository {
private static final boolean DBG = false;
private static final String TAG = "QSB.ShortcutRepositoryImplLog";
private static final String DB_NAME = "qsb-log.db";
private static final int DB_VERSION = 32;
private static final String HAS_HISTORY_QUERY =
"SELECT " + Shortcuts.intent_key.fullName + " FROM " + Shortcuts.TABLE_NAME;
private String mEmptyQueryShortcutQuery ;
private String mShortcutQuery;
private static final String SHORTCUT_BY_ID_WHERE =
Shortcuts.shortcut_id.name() + "=? AND " + Shortcuts.source.name() + "=?";
private static final String SOURCE_RANKING_SQL = buildSourceRankingSql();
private final Context mContext;
private final Config mConfig;
private final Corpora mCorpora;
private final ShortcutRefresher mRefresher;
private final Handler mUiThread;
// Used to perform log write operations asynchronously
private final Executor mLogExecutor;
private final DbOpenHelper mOpenHelper;
private final String mSearchSpinner;
/**
* Create an instance to the repo.
*/
public static ShortcutRepository create(Context context, Config config,
Corpora sources, ShortcutRefresher refresher, Handler uiThread,
Executor logExecutor) {
return new ShortcutRepositoryImplLog(context, config, sources, refresher,
uiThread, logExecutor, DB_NAME);
}
/**
* @param context Used to create / open db
* @param name The name of the database to create.
*/
@VisibleForTesting
ShortcutRepositoryImplLog(Context context, Config config, Corpora corpora,
ShortcutRefresher refresher, Handler uiThread, Executor logExecutor, String name) {
mContext = context;
mConfig = config;
mCorpora = corpora;
mRefresher = refresher;
mUiThread = uiThread;
mLogExecutor = logExecutor;
mOpenHelper = new DbOpenHelper(context, name, DB_VERSION, config);
buildShortcutQueries();
mSearchSpinner = Util.getResourceUri(mContext, R.drawable.search_spinner).toString();
}
// clicklog first, since that's where restrict the result set
private static final String TABLES = ClickLog.TABLE_NAME + " INNER JOIN " +
Shortcuts.TABLE_NAME + " ON " + ClickLog.intent_key.fullName + " = " +
Shortcuts.intent_key.fullName;
private static final String AS = " AS ";
private static final String[] SHORTCUT_QUERY_COLUMNS = {
Shortcuts.intent_key.fullName,
Shortcuts.source.fullName,
Shortcuts.source_version_code.fullName,
Shortcuts.format.fullName + AS + SearchManager.SUGGEST_COLUMN_FORMAT,
Shortcuts.title + AS + SearchManager.SUGGEST_COLUMN_TEXT_1,
Shortcuts.description + AS + SearchManager.SUGGEST_COLUMN_TEXT_2,
Shortcuts.description_url + AS + SearchManager.SUGGEST_COLUMN_TEXT_2_URL,
Shortcuts.icon1 + AS + SearchManager.SUGGEST_COLUMN_ICON_1,
Shortcuts.icon2 + AS + SearchManager.SUGGEST_COLUMN_ICON_2,
Shortcuts.intent_action + AS + SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
Shortcuts.intent_component.fullName,
Shortcuts.intent_data + AS + SearchManager.SUGGEST_COLUMN_INTENT_DATA,
Shortcuts.intent_query + AS + SearchManager.SUGGEST_COLUMN_QUERY,
Shortcuts.intent_extradata + AS + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA,
Shortcuts.shortcut_id + AS + SearchManager.SUGGEST_COLUMN_SHORTCUT_ID,
Shortcuts.spinner_while_refreshing + AS +
SearchManager.SUGGEST_COLUMN_SPINNER_WHILE_REFRESHING,
Shortcuts.log_type + AS + CursorBackedSuggestionCursor.SUGGEST_COLUMN_LOG_TYPE,
Shortcuts.custom_columns.fullName,
};
// Avoid GLOB by using >= AND <, with some manipulation (see nextString(String)).
// to figure out the upper bound (e.g. >= "abc" AND < "abd"
// This allows us to use parameter binding and still take advantage of the
// index on the query column.
private static final String PREFIX_RESTRICTION =
ClickLog.query.fullName + " >= ?1 AND " + ClickLog.query.fullName + " < ?2";
private static final String LAST_HIT_TIME_EXPR = "MAX(" + ClickLog.hit_time.fullName + ")";
private static final String GROUP_BY = ClickLog.intent_key.fullName;
private static final String PREFER_LATEST_PREFIX =
"(" + LAST_HIT_TIME_EXPR + " = (SELECT " + LAST_HIT_TIME_EXPR + " FROM " +
ClickLog.TABLE_NAME + " WHERE ";
private static final String PREFER_LATEST_SUFFIX = "))";
private void buildShortcutQueries() {
// SQL expression for the time before which no clicks should be counted.
String cutOffTime_expr = "(?3 - " + mConfig.getMaxStatAgeMillis() + ")";
// Filter out clicks that are too old
String ageRestriction = ClickLog.hit_time.fullName + " >= " + cutOffTime_expr;
String having = null;
// Order by sum of hit times (seconds since cutoff) for the clicks for each shortcut.
// This has the effect of multiplying the average hit time with the click count
String ordering_expr =
"SUM((" + ClickLog.hit_time.fullName + " - " + cutOffTime_expr + ") / 1000)";
String where = ageRestriction;
String preferLatest = PREFER_LATEST_PREFIX + where + PREFER_LATEST_SUFFIX;
String orderBy = preferLatest + " DESC, " + ordering_expr + " DESC";
mEmptyQueryShortcutQuery = SQLiteQueryBuilder.buildQueryString(
false, TABLES, SHORTCUT_QUERY_COLUMNS, where, GROUP_BY, having, orderBy, null);
if (DBG) Log.d(TAG, "Empty shortcut query:\n" + mEmptyQueryShortcutQuery);
where = PREFIX_RESTRICTION + " AND " + ageRestriction;
preferLatest = PREFER_LATEST_PREFIX + where + PREFER_LATEST_SUFFIX;
orderBy = preferLatest + " DESC, " + ordering_expr + " DESC";
mShortcutQuery = SQLiteQueryBuilder.buildQueryString(
false, TABLES, SHORTCUT_QUE
没有合适的资源?快使用搜索试试~ 我知道了~
Android应用源码之QuickSearchBox.zip项目安卓应用源码下载
共525个文件
java:208个
png:168个
xml:135个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 183 浏览量
2022-03-08
06:47:33
上传
评论
收藏 1001KB ZIP 举报
温馨提示
Android应用源码之QuickSearchBox.zip项目安卓应用源码下载Android应用源码之QuickSearchBox.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
Android应用源码之QuickSearchBox.zip项目安卓应用源码下载 (525个子文件)
proguard.flags 148B
HEAD 41B
index 58KB
ShortcutRepositoryImplLog.java 39KB
ShortcutRepositoryTest.java 35KB
SearchActivity.java 25KB
SearchActivityView.java 22KB
SearchableSource.java 17KB
QsbApplication.java 16KB
LevenshteinFormatterTest.java 14KB
Suggestions.java 11KB
Config.java 11KB
SourceLatency.java 11KB
SearchActivityViewTwoPane.java 10KB
SuggestionCursorUtil.java 10KB
SuggestionData.java 10KB
CursorBackedSuggestionCursor.java 10KB
DefaultSuggestionView.java 9KB
SearchSettingsImpl.java 9KB
SuggestionsAdapterBase.java 9KB
ClusteredSuggestionsAdapter.java 9KB
PackageIconLoader.java 9KB
SuggestionsProviderImpl.java 9KB
RankAwarePromoter.java 8KB
ShortcutsProvider.java 7KB
GoogleSuggestClient.java 7KB
SuggestionCursorWithExtrasTest.java 7KB
SearchWidgetProvider.java 7KB
SuggestionCursorBackedCursor.java 7KB
MultiSourceCorpus.java 7KB
LevenshteinDistance.java 7KB
JavaNetHttpHelper.java 6KB
GoogleSearch.java 6KB
CorpusSelectionDialog.java 6KB
DelayingSuggestionsAdapter.java 6KB
SearchBaseUrlHelper.java 6KB
BlendingPromoterTest.java 6KB
CorporaAdapter.java 6KB
RankAwarePromoterTest.java 6KB
WebCorpus.java 6KB
MockSource.java 6KB
ShortcutCursor.java 5KB
Source.java 5KB
SourceShortcutRefresher.java 5KB
ListSuggestionCursor.java 5KB
LevenshteinDistanceTest.java 5KB
SearchableCorpusFactory.java 5KB
ShouldQueryStrategyTest.java 5KB
SuggestionsProviderImplTest.java 5KB
SourceShortcutRefresherTest.java 5KB
SearchableSources.java 5KB
WebPromoterTest.java 5KB
SearchableCorpora.java 5KB
EventLogLogger.java 5KB
LevenshteinSuggestionFormatter.java 5KB
GoogleSuggestionProvider.java 5KB
DefaultCorpusRanker.java 5KB
CachingIconLoader.java 4KB
SearchableItemsController.java 4KB
SuggestionUtils.java 4KB
ResultPromoterTest.java 4KB
SearchActivityViewSinglePane.java 4KB
PartialSuggestionProvider.java 4KB
MockSuggestionProviderCursor.java 4KB
SuggestionsView.java 4KB
AbstractSource.java 4KB
BaseSuggestionView.java 4KB
MultiSourceCorpusTest.java 4KB
ShouldQueryStrategy.java 4KB
CachedLater.java 4KB
HttpHelper.java 4KB
CrashingSuggestionProvider.java 4KB
MockCorpus.java 4KB
HangingSuggestionProvider.java 4KB
CursorBackedSuggestionExtras.java 4KB
AbstractGoogleSource.java 4KB
QueryTask.java 4KB
VoiceSearch.java 4KB
SuggestionsAdapter.java 4KB
AppsCorpus.java 4KB
ShortcutRepository.java 4KB
AbstractGoogleSourceResult.java 3KB
MockCorpora.java 3KB
Suggestion.java 3KB
SearchableCorporaTest.java 3KB
PerNameExecutorTest.java 3KB
WebSearchSuggestionView.java 3KB
SingleThreadNamedTaskExecutor.java 3KB
Util.java 3KB
PreferenceControllerFactory.java 3KB
SuggestionsTest.java 3KB
CachedLaterTest.java 3KB
QueryTextView.java 3KB
ContactSuggestionView.java 3KB
PackageIconLoaderTest.java 3KB
DefaultSuggestionViewFactory.java 3KB
IconLoaderTest.java 3KB
BarrierConsumer.java 3KB
SearchSettingsActivity.java 3KB
Logger.java 3KB
共 525 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
yxkfw
- 粉丝: 81
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功