Example usage for android.app SearchManager SUGGEST_COLUMN_TEXT_1

List of usage examples for android.app SearchManager SUGGEST_COLUMN_TEXT_1

Introduction

In this page you can find the example usage for android.app SearchManager SUGGEST_COLUMN_TEXT_1.

Prototype

String SUGGEST_COLUMN_TEXT_1

To view the source code for android.app SearchManager SUGGEST_COLUMN_TEXT_1.

Click Source Link

Document

Column name for suggestions cursor.

Usage

From source file:com.dvdprime.mobile.android.adapter.DocumentSuggestionsAdapter.java

public static MatrixCursor getCursor(String query) {
    //  ? ?? //w ww .  j a  v a2s  . c o  m
    final String[] COLUMNS = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_TEXT_2 };

    MatrixCursor cursor = new MatrixCursor(COLUMNS);
    cursor.addRow(new Object[] { 1, query, " " });
    cursor.addRow(new Object[] { 2, query, "ID " });
    cursor.addRow(new Object[] { 6, query, " " });
    cursor.addRow(new Object[] { 4, query, "? " });
    cursor.addRow(new Object[] { 7, query, "  " });

    return cursor;
}

From source file:com.dvdprime.mobile.android.adapter.DocumentSuggestionsAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    TextView tv1 = (TextView) view.findViewById(android.R.id.text1);
    tv1.setText(cursor.getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1)));
    TextView tv2 = (TextView) view.findViewById(android.R.id.text2);
    tv2.setTextAppearance(context, R.style.DarkGrayBaseSmallText);
    tv2.setText(cursor.getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2)));
}

From source file:com.dmsl.anyplace.nav.AnyPlaceSeachingHelper.java

public static Cursor prepareSearchViewCursor(List<? extends IPoisClass> places) {
    String req_columns[] = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_TEXT_2, SearchManager.SUGGEST_COLUMN_INTENT_DATA };
    MatrixCursor mcursor = new MatrixCursor(req_columns);
    int i = 0;/*w  w  w .ja  va  2s .c  o  m*/
    if (places != null) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.registerTypeAdapter(IPoisClass.class, new IPoisClass.MyInterfaceAdapter());
        Gson gson = gsonBuilder.create();
        for (IPoisClass p : places) {
            mcursor.addRow(new String[] { Integer.toString(i++), p.name(),
                    p.description().equals("") ? "no description" : p.description(),
                    gson.toJson(p, IPoisClass.class) });
        }
    }
    return mcursor;
}

From source file:com.dvdprime.mobile.android.adapter.DocumentSuggestionsAdapter.java

public static MatrixCursor getCursor2(String query) {
    //  ? ?? /*  www .j  a  v a  2 s.  c om*/
    final String[] COLUMNS = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_TEXT_2 };

    MatrixCursor cursor = new MatrixCursor(COLUMNS);
    cursor.addRow(new Object[] { 1, query, " " });
    cursor.addRow(new Object[] { 2, query, "ID " });
    cursor.addRow(new Object[] { 4, query, "? " });
    cursor.addRow(new Object[] { 7, query, "  " });

    return cursor;
}

From source file:com.conferenceengineer.android.iosched.io.SearchSuggestHandler.java

public ArrayList<ContentProviderOperation> parse(String json) throws IOException {
    final ArrayList<ContentProviderOperation> batch = Lists.newArrayList();

    try {/*from ww  w. jav  a2s.co m*/
        JSONObject root = new JSONObject(json);
        JSONArray suggestions = root.getJSONArray("words");

        batch.add(
                ContentProviderOperation
                        .newDelete(ScheduleContract
                                .addCallerIsSyncAdapterParameter(ScheduleContract.SearchSuggest.CONTENT_URI))
                        .build());
        for (int i = 0; i < suggestions.length(); i++) {
            batch.add(ContentProviderOperation
                    .newInsert(ScheduleContract
                            .addCallerIsSyncAdapterParameter(ScheduleContract.SearchSuggest.CONTENT_URI))
                    .withValue(SearchManager.SUGGEST_COLUMN_TEXT_1, suggestions.getString(i)).build());
        }
    } catch (JSONException e) {
        Log.e(Config.LOG_TAG, "Problem building word list", e);
    }

    return batch;
}

From source file:com.google.android.demos.jamendo.widget.SearchAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    bindTextView(view, cursor, R.id.text1, SearchManager.SUGGEST_COLUMN_TEXT_1);
    bindTextView(view, cursor, R.id.text2, SearchManager.SUGGEST_COLUMN_TEXT_2);
    bindImageView(view, cursor, R.id.icon, SearchManager.SUGGEST_COLUMN_ICON_2);
}

From source file:com.dmsl.anyplace.nav.AnyPlaceSeachingHelper.java

public static Cursor prepareSearchViewCursor(List<? extends IPoisClass> places, String query) {
    String req_columns[] = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_INTENT_DATA };
    MatrixCursor mcursor = new MatrixCursor(req_columns);
    int i = 0;/*w w w  .j  a v a 2  s .co  m*/
    if (places != null) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.registerTypeAdapter(IPoisClass.class, new IPoisClass.MyInterfaceAdapter());
        Gson gson = gsonBuilder.create();

        // Better Use AndroidUtils.fillTextBox instead of regular expression
        // Regular expression
        // ?i ignore case
        Pattern patternTitle = Pattern.compile(String.format("((?i)%s)", query));
        // Matches X words before query and Y words after
        Pattern patternDescription = Pattern.compile(
                String.format("(([^\\s]+\\s+){0,%d}[^\\s]*)((?i)%s)([^\\s]*(\\s+[^\\s]+){0,%d})", 2, query, 2));
        for (IPoisClass p : places) {
            String name = "", description = "";
            Matcher m;
            m = patternTitle.matcher(p.name());
            // Makes matched query bold using HTML format
            // $1 returns the regular's expression outer parenthesis value
            name = m.replaceAll("<b>$1</b>");

            m = patternDescription.matcher(p.description());
            if (m.find()) {
                // Makes matched query bold using HTML format
                description = String.format(" %s<b>%s</b>%s", m.group(1), m.group(3), m.group(4));
            }

            mcursor.addRow(new String[] { Integer.toString(i++), name + description,
                    gson.toJson(p, IPoisClass.class) });
        }
    }
    return mcursor;
}

From source file:au.com.cybersearch2.classyfy.ClassyfyLogic.java

/**
 * Perform content provider query for fast text search, Must be executed on background thread. 
 * @param searchQuery Query string// w  ww  . j a v  a 2s  .  com
 * @return
 */
public List<ListItem> doSearchQuery(String searchQuery) {
    // Perform the search, passing in the search query as an argument to the Cursor Loader
    SuggestionCursorParameters params = new SuggestionCursorParameters(searchQuery,
            ClassyFySearchEngine.LEX_CONTENT_URI, ClassyFyProvider.SEARCH_RESULTS_LIMIT);

    ContentResolver contentResolver = context.getContentResolver();
    Cursor cursor = contentResolver.query(params.getUri(), params.getProjection(), params.getSelection(),
            params.getSelectionArgs(), params.getSortOrder());
    List<ListItem> fieldList = new ArrayList<ListItem>();
    int nameColumnId = cursor.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_1);
    int valueColumnId = cursor.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_2);
    // Id column name set in android.support.v4.widget.CursorAdaptor
    int idColumnId = cursor.getColumnIndexOrThrow("_id");
    if (cursor.getCount() > 0) {
        cursor.moveToPosition(-1);
        while (cursor.moveToNext()) {
            String name = cursor.getString(nameColumnId);
            String value = cursor.getString(valueColumnId);
            long id = cursor.getLong(idColumnId);
            fieldList.add(new ListItem(name, value, id));
        }
    }
    cursor.close();
    return fieldList;
}

From source file:com.actionbarsherlock.sample.demos.SearchViews.java

@Override
public boolean onSuggestionClick(int position) {
    Cursor c = (Cursor) mSuggestionsAdapter.getItem(position);
    String query = c.getString(c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1));
    Toast.makeText(this, "Suggestion clicked: " + query, Toast.LENGTH_LONG).show();
    return true;/*  w ww .j a  va2  s.c o m*/
}

From source file:com.google.android.demos.jamendo.app.SearchActivity.java

/** {@inheritDoc} */
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Intent intent = getIntent();//ww  w.  jav  a2s.c om
    String query = intent.getStringExtra(SearchManager.QUERY);

    Uri.Builder builder = JamendoContract.AUTHORITY_URI.buildUpon();
    builder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY);
    builder.appendPath(query);
    Uri uri = builder.build();
    String[] projection = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_ICON_2,
            SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2 };
    String selection = JamendoContract.PARAM_IMAGE_SIZE + "=" + mImageSize;
    String[] selectionArgs = null;
    String sortOrder = null;
    return new CursorLoader(this, uri, projection, selection, selectionArgs, sortOrder);
}