Search in sources :

Example 1 with SearchIndexableResource

use of android.provider.SearchIndexableResource in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SettingsSearchIndexablesProvider method queryXmlResources.

@Override
public Cursor queryXmlResources(String[] projection) {
    MatrixCursor cursor = new MatrixCursor(INDEXABLES_XML_RES_COLUMNS);
    Collection<SearchIndexableResource> values = SearchIndexableResources.values();
    for (SearchIndexableResource val : values) {
        Object[] ref = new Object[7];
        ref[COLUMN_INDEX_XML_RES_RANK] = val.rank;
        ref[COLUMN_INDEX_XML_RES_RESID] = val.xmlResId;
        ref[COLUMN_INDEX_XML_RES_CLASS_NAME] = val.className;
        ref[COLUMN_INDEX_XML_RES_ICON_RESID] = val.iconResId;
        // intent action
        ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = null;
        // intent target package
        ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = null;
        // intent target class
        ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS] = null;
        cursor.addRow(ref);
    }
    return cursor;
}
Also used : SearchIndexableResource(android.provider.SearchIndexableResource) MatrixCursor(android.database.MatrixCursor)

Example 2 with SearchIndexableResource

use of android.provider.SearchIndexableResource in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class Index method updateFromClassNameResource.

/**
     * Update the Index for a specific class name resources
     *
     * @param className the class name (typically a fragment name).
     * @param rebuild true means that you want to delete the data from the Index first.
     * @param includeInSearchResults true means that you want the bit "enabled" set so that the
     *                               data will be seen included into the search results
     */
public void updateFromClassNameResource(String className, final boolean rebuild, boolean includeInSearchResults) {
    if (className == null) {
        throw new IllegalArgumentException("class name cannot be null!");
    }
    final SearchIndexableResource res = SearchIndexableResources.getResourceByName(className);
    if (res == null) {
        Log.e(LOG_TAG, "Cannot find SearchIndexableResources for class name: " + className);
        return;
    }
    res.context = mContext;
    res.enabled = includeInSearchResults;
    AsyncTask.execute(new Runnable() {

        @Override
        public void run() {
            if (rebuild) {
                deleteIndexableData(res);
            }
            addIndexableData(res);
            mDataToProcess.forceUpdate = true;
            updateInternal();
            res.enabled = false;
        }
    });
}
Also used : SearchIndexableResource(android.provider.SearchIndexableResource)

Example 3 with SearchIndexableResource

use of android.provider.SearchIndexableResource in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class Index method addIndexablesForXmlResourceUri.

private void addIndexablesForXmlResourceUri(Context packageContext, String packageName, Uri uri, String[] projection, int baseRank) {
    final ContentResolver resolver = packageContext.getContentResolver();
    final Cursor cursor = resolver.query(uri, projection, null, null, null);
    if (cursor == null) {
        Log.w(LOG_TAG, "Cannot add index data for Uri: " + uri.toString());
        return;
    }
    try {
        final int count = cursor.getCount();
        if (count > 0) {
            while (cursor.moveToNext()) {
                final int providerRank = cursor.getInt(COLUMN_INDEX_XML_RES_RANK);
                final int rank = (providerRank > 0) ? baseRank + providerRank : baseRank;
                final int xmlResId = cursor.getInt(COLUMN_INDEX_XML_RES_RESID);
                final String className = cursor.getString(COLUMN_INDEX_XML_RES_CLASS_NAME);
                final int iconResId = cursor.getInt(COLUMN_INDEX_XML_RES_ICON_RESID);
                final String action = cursor.getString(COLUMN_INDEX_XML_RES_INTENT_ACTION);
                final String targetPackage = cursor.getString(COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE);
                final String targetClass = cursor.getString(COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS);
                SearchIndexableResource sir = new SearchIndexableResource(packageContext);
                sir.rank = rank;
                sir.xmlResId = xmlResId;
                sir.className = className;
                sir.packageName = packageName;
                sir.iconResId = iconResId;
                sir.intentAction = action;
                sir.intentTargetPackage = targetPackage;
                sir.intentTargetClass = targetClass;
                addIndexableData(sir);
            }
        }
    } finally {
        cursor.close();
    }
}
Also used : SearchIndexableResource(android.provider.SearchIndexableResource) Cursor(android.database.Cursor) MergeCursor(android.database.MergeCursor) ContentResolver(android.content.ContentResolver)

Example 4 with SearchIndexableResource

use of android.provider.SearchIndexableResource in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class Index method indexFromProvider.

private void indexFromProvider(Context context, SQLiteDatabase database, String localeStr, Indexable.SearchIndexProvider provider, String className, int iconResId, int rank, boolean enabled, List<String> nonIndexableKeys) {
    if (provider == null) {
        Log.w(LOG_TAG, "Cannot find provider: " + className);
        return;
    }
    final List<SearchIndexableRaw> rawList = provider.getRawDataToIndex(context, enabled);
    if (rawList != null) {
        final int rawSize = rawList.size();
        for (int i = 0; i < rawSize; i++) {
            SearchIndexableRaw raw = rawList.get(i);
            // Should be the same locale as the one we are processing
            if (!raw.locale.toString().equalsIgnoreCase(localeStr)) {
                continue;
            }
            if (nonIndexableKeys.contains(raw.key)) {
                continue;
            }
            updateOneRowWithFilteredData(database, localeStr, raw.title, raw.summaryOn, raw.summaryOff, raw.entries, className, raw.screenTitle, iconResId, rank, raw.keywords, raw.intentAction, raw.intentTargetPackage, raw.intentTargetClass, raw.enabled, raw.key, raw.userId);
        }
    }
    final List<SearchIndexableResource> resList = provider.getXmlResourcesToIndex(context, enabled);
    if (resList != null) {
        final int resSize = resList.size();
        for (int i = 0; i < resSize; i++) {
            SearchIndexableResource item = resList.get(i);
            // Should be the same locale as the one we are processing
            if (!item.locale.toString().equalsIgnoreCase(localeStr)) {
                continue;
            }
            final int itemIconResId = (item.iconResId == 0) ? iconResId : item.iconResId;
            final int itemRank = (item.rank == 0) ? rank : item.rank;
            String itemClassName = (TextUtils.isEmpty(item.className)) ? className : item.className;
            indexFromResource(context, database, localeStr, item.xmlResId, itemClassName, itemIconResId, itemRank, item.intentAction, item.intentTargetPackage, item.intentTargetClass, nonIndexableKeys);
        }
    }
}
Also used : SearchIndexableResource(android.provider.SearchIndexableResource)

Aggregations

SearchIndexableResource (android.provider.SearchIndexableResource)4 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 MatrixCursor (android.database.MatrixCursor)1 MergeCursor (android.database.MergeCursor)1