当前位置: 首页>>代码示例>>Java>>正文


Java SearchManager.SUGGEST_COLUMN_TEXT_1属性代码示例

本文整理汇总了Java中android.app.SearchManager.SUGGEST_COLUMN_TEXT_1属性的典型用法代码示例。如果您正苦于以下问题:Java SearchManager.SUGGEST_COLUMN_TEXT_1属性的具体用法?Java SearchManager.SUGGEST_COLUMN_TEXT_1怎么用?Java SearchManager.SUGGEST_COLUMN_TEXT_1使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.app.SearchManager的用法示例。


在下文中一共展示了SearchManager.SUGGEST_COLUMN_TEXT_1属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSuggestions

private Cursor getSuggestions(String query) {
  if (query.length() < 3) {
    return null;
  }

  boolean haveArabic = false;
  if (QuranUtils.doesStringContainArabic(query) &&
      QuranFileUtils.hasTranslation(getContext(), QURAN_ARABIC_DATABASE)) {
    haveArabic = true;
  }

  boolean haveTranslation = false;
  String active = getActiveTranslation();
  if (!TextUtils.isEmpty(active)) {
    haveTranslation = true;
  }

  int numItems = (haveArabic ? 1 : 0) + (haveTranslation ? 1 : 0);
  if (numItems == 0) {
    return null;
  }

  String[] items = new String[numItems];
  if (haveArabic) {
    items[0] = QURAN_ARABIC_DATABASE;
  }

  if (haveTranslation) {
    items[numItems - 1] = active;
  }

  String[] cols = new String[] { BaseColumns._ID,
      SearchManager.SUGGEST_COLUMN_TEXT_1,
      SearchManager.SUGGEST_COLUMN_TEXT_2,
      SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID };
  MatrixCursor mc = new MatrixCursor(cols);

  Context context = getContext();
  boolean gotResults = false;
  for (String item : items) {
    if (gotResults) {
      continue;
    }

    Cursor suggestions = null;
    try {
      suggestions = search(query, item, false);
      if (suggestions != null && suggestions.moveToFirst()) {
        do {
          int sura = suggestions.getInt(1);
          int ayah = suggestions.getInt(2);
          String text = suggestions.getString(3);
          String foundText = context.getString(
              R.string.found_in_sura, QuranInfo.getSuraName(context, sura, false), ayah);

          gotResults = true;
          MatrixCursor.RowBuilder row = mc.newRow();
          int id = suggestions.getInt(0);

          row.add(id);
          row.add(text);
          row.add(foundText);
          row.add(id);
        } while (suggestions.moveToNext());
      }
    } finally {
      DatabaseUtils.closeCursor(suggestions);
    }
  }

  return mc;
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:72,代码来源:QuranDataProvider.java

示例2: GetStationsForSearchProvider

public Cursor GetStationsForSearchProvider(String selection,
                                               String[] selectionArgs) {
        //prepare query for search suggesions
        Cursor cursor;
        StorageHelper storageHelper = new StorageHelper(mContect);
        final File folder = storageHelper.getCollectionDirectory();

        String[] projection = new String[]{
                StationsDbContract.StationEntry._ID,
                StationsDbContract.StationEntry.COLUMN_NAME_TITLE + " AS " + SearchManager.SUGGEST_COLUMN_TEXT_2,
                StationsDbContract.StationEntry.COLUMN_NAME_SUBTITLE + " AS " + SearchManager.SUGGEST_COLUMN_TEXT_1,
                StationsDbContract.StationEntry._ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA
                , "'file://" + folder.toString() + "/'  || " + StationsDbContract.StationEntry.COLUMN_IMAGE_FILE_NAME + " AS " + SearchManager.SUGGEST_COLUMN_ICON_1,
        };
        //get stations from DB
        // Gets the data repository in read mode
        SQLiteDatabase db = this.getReadableDatabase();
        try {
            cursor = db.query(
                    TABLE_NAME, // The table to query
                    projection,                                 // The columns to return
                    selection,                                  // The columns for the WHERE clause
                    new String[]{"%" + selectionArgs[0].toString() + "%","%" + selectionArgs[0].toString() + "%"},  // The values for the WHERE clause
                    null,                                       // don't group the rows
                    null,                                       // don't filter by row groups
                    null,
                    "20" //limit
            );
            return cursor;
        } catch (Exception ex) {
            LogHelper.e(LOG_TAG, ex.getMessage());
            return null;
        }

//
//
//        String countQuery = "SELECT  " + StationsDbContract.StationEntry._ID + "AS _ID,"
//                + StationsDbContract.StationEntry.COLUMN_NAME_TITLE + " AS SUGGEST_COLUMN_TEXT_1,"
//                + StationsDbContract.StationEntry.COLUMN_NAME_SUBTITLE + " AS SUGGEST_COLUMN_TEXT_2,"
//                + "'file://" + folder.toString() + "/'  || " + StationsDbContract.StationEntry.COLUMN_SMALL_IMAGE_FILE_NAME + " AS SUGGEST_COLUMN_ICON_1,"
//                + " FROM " + StationsDbContract.StationEntry.TABLE_NAME;
////                + " WHERE " + StationsDbContract.StationEntry.COLUMN_NAME_TITLE + " LIKE '%" + searchText + "%'"
////                + " Or " + StationsDbContract.StationEntry.COLUMN_NAME_SUBTITLE + " LIKE '%" + searchText + "%'" ;
//        SQLiteDatabase db = this.getReadableDatabase();
//        Cursor cursor = db.rawQuery(countQuery, null);
//        return cursor;
    }
 
开发者ID:malah-code,项目名称:Open-Quran-Radio,代码行数:47,代码来源:StationsDbHelper.java


注:本文中的android.app.SearchManager.SUGGEST_COLUMN_TEXT_1属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。