private static String contactToNumber(Cursor cur, ContentResolver cr, String id) {
    try {
      if (Integer.parseInt(
              cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)))
          > 0) {
        Cursor pCur;

        pCur =
            cr.query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                null,
                ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
                new String[] {id},
                null);

        // first search for default number
        while (pCur.moveToNext()) {

          int defaultIfGreaterThanZero =
              pCur.getInt(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
          if (defaultIfGreaterThanZero > 0) {
            return pCur.getString(
                pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
          }
        }
        pCur.moveToPosition(-1);
        while (pCur.moveToNext()) {
          return pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
        }
        pCur.close();
      }
    } catch (Exception e) {
    }
    return null;
  }
 public void cleanOldBlock() {
   SQLiteDatabase db = this.mDb.getReadableDatabase();
   String sql = "select count(0) cnt from blocks";
   Cursor c = db.rawQuery(sql, null);
   int cnt = 0;
   if (c.moveToNext()) {
     int idColumn = c.getColumnIndex("cnt");
     if (idColumn != -1) {
       cnt = c.getInt(idColumn);
     }
   }
   c.close();
   if (cnt > 5000) {
     sql = "select max(block_no) max_block_no from blocks where is_main=1";
     c = db.rawQuery(sql, null);
     int maxBlockNo = 0;
     if (c.moveToNext()) {
       int idColumn = c.getColumnIndex("max_block_no");
       if (idColumn != -1) {
         maxBlockNo = c.getInt(idColumn);
       }
     }
     c.close();
     int blockNo =
         (maxBlockNo - BitherjSettings.BLOCK_DIFFICULTY_INTERVAL)
             - maxBlockNo % BitherjSettings.BLOCK_DIFFICULTY_INTERVAL;
     db = this.mDb.getWritableDatabase();
     db.delete(AbstractDb.Tables.BLOCKS, "block_no<?", new String[] {Integer.toString(blockNo)});
   }
 }
 private void checkFoodDatabase(String out) {
   // trim the "s" if there are any
   // this will not be a problem for words end with 's'
   // because we are using % in the query
   ArrayList<String> sData = new ArrayList<String>();
   if (out.substring(out.length() - 1).equals("s")) out = out.substring(0, out.length() - 1);
   String sql =
       "SELECT _ID,GL,Serve_Size,food_name FROM food WHERE lower(food_name) LIKE lower('%"
           + out
           + "%');";
   mCursor = mDb.rawQuery(sql, null);
   // if there is a match
   if (mCursor.getCount() > 0) { // now it is taking the first match WIP fix later
     mCursor.moveToFirst();
     sData.add(mCursor.getString(mCursor.getColumnIndex("food_name")));
     while (!mCursor.isLast()) {
       mCursor.moveToNext();
       String Name = mCursor.getString(mCursor.getColumnIndex("food_name"));
       sData.add(Name);
     }
   } else {
     sData.add("No matches");
     showToastMessage(out + " does not exist in food database! Add it");
   }
   isValid = true;
   mlv.setAdapter(
       new ArrayAdapter<String>(
           getActivity(), android.R.layout.simple_list_item_single_choice, sData));
 }
  private Word cursorToWord(Cursor cursor) {
    Word word = new Word();
    word.setWord(cursor.getString(cursor.getColumnIndex(NewWordsTable.Cols.ORIGINAL_WORD)));
    word.setTranslation(cursor.getString(cursor.getColumnIndex(NewWordsTable.Cols.TRANSLATION)));

    return word;
  }
  /** 得到影片收藏列表 */
  public synchronized List<DownLoadInfo> getSmovieSave() {

    List<DownLoadInfo> resultsInfos = new ArrayList<DownLoadInfo>();
    String sql =
        "select  *  from "
            + PipiDBHelp.SAVE_TABLENAME
            + " order by "
            + TableName.Movie_ID
            + " desc";
    try {
      database = pipiDBHelp.getWritableDatabase();
      cursor = database.rawQuery(sql, null);
      if (cursor != null && cursor.getCount() != 0) {
        while (cursor.moveToNext()) {
          DownLoadInfo info = new DownLoadInfo();
          info.setDownID(cursor.getString(cursor.getColumnIndex(TableName.MovieID)));
          info.setDownName(cursor.getString(cursor.getColumnIndex(TableName.MovieName)));
          info.setDownImg(cursor.getString(cursor.getColumnIndex(TableName.MovieImgUrl)));

          resultsInfos.add(info);
        }
      } else {

      }

    } catch (Exception e) {
      // TODO: handle exception
    } finally {
      closeCursor();
    }
    return resultsInfos;
  }
  /**
   * 从数据库中得到缩略图
   *
   * @param cur
   */
  private void getThumbnailColumnData(Cursor cur) {
    if (cur.moveToFirst()) {
      int _id;
      int image_id;
      String image_path;
      int _idColumn = cur.getColumnIndex(BaseColumns._ID);
      int image_idColumn = cur.getColumnIndex(Thumbnails.IMAGE_ID);
      int dataColumn = cur.getColumnIndex(Thumbnails.DATA);

      do {
        // Get the field values
        _id = cur.getInt(_idColumn);
        image_id = cur.getInt(image_idColumn);
        image_path = cur.getString(dataColumn);

        // Do something with the values.
        // Log.i(TAG, _id + " image_id:" + image_id + " path:"
        // + image_path + "---");
        // HashMap<String, String> hash = new HashMap<String, String>();
        // hash.put("image_id", image_id + "");
        // hash.put("path", image_path);
        // thumbnailList.add(hash);
        thumbnailList.put("" + image_id, image_path);
      } while (cur.moveToNext());
    }
  }
  public void printDatabase() {

    SQLiteDatabase MeasurementTableReadable =
        new MeasurementTableDbHelper(getApplicationContext()).getReadableDatabase();

    String[] myProjection = {
      MeasurementTable.MEASUREMENT,
      MeasurementTable.MEASUREMENT_VALUE,
      MeasurementTable.CALENDAR,
      MeasurementTable.GOAL_START
    };

    Cursor tempCur =
        MeasurementTableReadable.query(
            MeasurementTable.TABLE_NAME, myProjection, null, null, null, null, null);

    if (tempCur.moveToFirst()) {}

    while (tempCur.moveToNext()) {

      Log.d(
          "TABLE ITEM",
          tempCur.getString(tempCur.getColumnIndex(MeasurementTable.MEASUREMENT))
              + " - "
              + tempCur.getString(tempCur.getColumnIndex(MeasurementTable.MEASUREMENT_VALUE))
              + " - "
              + tempCur.getString(tempCur.getColumnIndex(MeasurementTable.CALENDAR))
              + " - "
              + tempCur.getString(tempCur.getColumnIndex(MeasurementTable.GOAL_START)));
    }
  }
 protected MDLUser(Cursor cursor) {
   this.id = cursor.getLong(cursor.getColumnIndex(Attribute.id));
   this.email = cursor.getString(cursor.getColumnIndex(Attribute.email));
   this.name = cursor.getString(cursor.getColumnIndex(Attribute.name));
   this.age = cursor.getInt(cursor.getColumnIndex(Attribute.age));
   this.gender = cursor.getInt(cursor.getColumnIndex(Attribute.gender));
 }
  public void bindView(Cursor cursor) {
    // Reinflate layout
    removeAllViewsInLayout();
    View view = LayoutInflater.from(getContext()).inflate(R.layout.sets_table, this);

    TableRow tableRowWeight = (TableRow) view.findViewById(R.id.tableRowWeight);
    TableRow tableRowReps = (TableRow) view.findViewById(R.id.tableRowReps);

    if (cursor != null && cursor.moveToFirst()) {
      do {
        TextView textViewWeight = new TextView(getContext());
        TextView textViewReps = new TextView(getContext());

        textViewWeight.setBackgroundResource(R.drawable.cell_right_border);
        textViewReps.setBackgroundResource(R.drawable.cell_right_top_border);

        textViewWeight.setPadding(4, 0, 5, 0);
        textViewReps.setPadding(4, 0, 5, 0);

        textViewWeight.setGravity(Gravity.CENTER_HORIZONTAL);
        textViewReps.setGravity(Gravity.CENTER_HORIZONTAL);

        tableRowWeight.addView(textViewWeight);
        tableRowReps.addView(textViewReps);

        // Bind data
        float weight = cursor.getFloat(cursor.getColumnIndex(Sets.WEIGHT));
        String reps = cursor.getString(cursor.getColumnIndex(Sets.REPS));

        textViewWeight.setText(SetUtils.weightFormat(weight));
        textViewReps.setText(reps);
      } while (cursor.moveToNext());
    }
  }
Exemple #10
0
  public ArrayList<Episode> listBySerieAndSeason(Serie serie) {
    Cursor c = getCursor();
    ArrayList<Episode> episodes = new ArrayList<Episode>();
    if (c.moveToFirst()) {

      int idxName = c.getColumnIndex(Episodes.NAME);
      int idxId = c.getColumnIndex(Episodes.PK_ID);
      int idxSeason = c.getColumnIndex(Episodes.SEASON);
      int idxEpisode = c.getColumnIndex(Episodes.NUMBER);
      int idxIdSerie = c.getColumnIndex(Episodes.ID_SERIE);

      do {
        if (serie.getId() == c.getLong(idxIdSerie)
            && serie.getSeason().intValue() == c.getInt(idxSeason)) {
          Episode episode = new Episode();
          episode.setName(c.getString(idxName));
          episode.setId(c.getLong(idxId));
          episode.setSeason(c.getInt(idxSeason));
          episode.setNumber(c.getInt(idxEpisode));
          episodes.add(episode);
        }
      } while (c.moveToNext());
    }
    c.close();
    super.close();
    return episodes;
  }
Exemple #11
0
  public Episode searchEpisode(Serie serie) {
    Cursor c = getCursor();

    Episode episode = new Episode();
    if (c.moveToFirst()) {

      int idxName = c.getColumnIndex(Episodes.NAME);
      int idxId = c.getColumnIndex(Episodes.PK_ID);
      int idxSeason = c.getColumnIndex(Episodes.SEASON);
      int idxEpisode = c.getColumnIndex(Episodes.NUMBER);
      int idxIdSerie = c.getColumnIndex(Episodes.ID_SERIE);

      do {
        if (serie.getId() == c.getLong(idxIdSerie)
            && serie.getSeason().intValue() == c.getInt(idxSeason)
            && serie.getEpisode().intValue() == c.getInt(idxEpisode)) {
          episode.setName(c.getString(idxName));
          episode.setId(c.getLong(idxId));
          episode.setSeason(c.getInt(idxSeason));
          episode.setNumber(c.getInt(idxEpisode));
          break;
        }
      } while (c.moveToNext());
    }
    c.close();
    super.close();
    return episode;
  }
 /**
  * 查找数据库记录
  *
  * @return
  * @throws SQLException
  */
 public PasswordInfo find() throws SQLException {
   PasswordInfo passwordInfo = null;
   synchronized (dbHelper) {
     SQLiteDatabase db = dbHelper.getReadableDatabase();
     String querySql = "select * from password";
     // 由于该表的特殊性,password最多只有一条记录
     Cursor cursor = null;
     try {
       cursor = db.rawQuery(querySql, null);
       if (cursor.moveToNext()) {
         int _id = cursor.getInt(cursor.getColumnIndex("_id"));
         String password = cursor.getString(cursor.getColumnIndex("password"));
         String question = cursor.getString(cursor.getColumnIndex("question"));
         String answer = cursor.getString(cursor.getColumnIndex("answer"));
         int flag = cursor.getInt(cursor.getColumnIndex("flag"));
         passwordInfo = new PasswordInfo(_id, password, question, answer, flag);
       } else {
         passwordInfo = null;
       }
     } catch (Exception e) {
       e.printStackTrace();
     } finally {
       cursor.close();
       db.close();
     }
   }
   return passwordInfo;
 }
    public Image getImageFromContentUri(Uri contentUri) {
      String[] cols = {MediaStore.Images.Media.DATA, MediaStore.Images.ImageColumns.ORIENTATION};

      // can post image
      Cursor cursor = getActivity().getContentResolver().query(contentUri, cols, null, null, null);

      Uri uri = null;
      int orientation = -1;

      try {
        if (cursor.moveToFirst()) {
          uri = Uri.parse(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)));
          orientation =
              cursor.getInt(cursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION));
        }
      } catch (SQLiteException e) {
        e.printStackTrace();
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        if (cursor != null && !cursor.isClosed()) {
          cursor.close();
        }
      }

      return new Image(uri, orientation);
    }
Exemple #14
0
 public static List<Contact> getActiveContacts() {
   List<Contact> list = new ArrayList<>();
   Cursor cursor = null;
   try {
     cursor =
         SawimApplication.getDatabaseHelper()
             .getReadableDatabase()
             .query(
                 DatabaseHelper.TABLE_CHAT_HISTORY,
                 null,
                 null,
                 null,
                 DatabaseHelper.CONTACT_ID,
                 null,
                 null,
                 null);
     if (cursor.moveToLast()) {
       do {
         String protocolId = cursor.getString(cursor.getColumnIndex(DatabaseHelper.ACCOUNT_ID));
         String uniqueUserId = cursor.getString(cursor.getColumnIndex(DatabaseHelper.CONTACT_ID));
         Protocol protocol = RosterHelper.getInstance().getProtocol(protocolId);
         if (protocol != null) {
           list.add(protocol.getItemByUID(uniqueUserId));
         }
       } while (cursor.moveToPrevious());
     }
   } finally {
     if (cursor != null) {
       cursor.close();
     }
   }
   return list;
 }
  public static Album getAlbum(ContentResolver contentResolver, long albumId) {
    String[] projection = {
      MediaStore.Audio.Albums._ID,
      MediaStore.Audio.Albums.ARTIST,
      MediaStore.Audio.Albums.ALBUM,
      MediaStore.Audio.Albums.ALBUM_ART
    };

    String selection = MediaStore.Audio.Albums._ID + "=" + albumId;

    Cursor cursor =
        contentResolver.query(
            MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
            projection,
            selection,
            null,
            MediaStore.Audio.Albums.ALBUM);

    if (cursor != null) {
      if (cursor.moveToFirst()) {
        Album album = new Album();
        album.setId(cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Albums._ID)));
        album.setArtist(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ARTIST)));
        album.setTitle(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM)));
        album.setThumbnail(
            cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART)));

        return album;
      }
    }

    return null;
  }
  public List<Todo> getTodoItems() {
    ArrayList<Todo> todoItems = new ArrayList<Todo>();

    String TODO_SELECT_QUERY = "SELECT * FROM " + TABLE_TODO;

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(TODO_SELECT_QUERY, null);

    try {
      if (cursor.moveToFirst()) {
        do {
          Todo todo = new Todo();
          todo.todoId = cursor.getInt(cursor.getColumnIndex(KEY_TODO_ID));
          todo.todoItem = cursor.getString(cursor.getColumnIndex(KEY_TODO_ITEM));

          // Convert ISO date string to date
          String isoDate = cursor.getString(cursor.getColumnIndex(KEY_TODO_DATE));
          SimpleDateFormat format = new SimpleDateFormat(ISO_FORMAT);
          todo.dueDate = format.parse(isoDate);

          todoItems.add(todo);
        } while (cursor.moveToNext());
      }
    } catch (Exception e) {
      Log.d(TAG, "Error while trying to get todo items from database");
    } finally {
      if (cursor != null && !cursor.isClosed()) {
        cursor.close();
      }
    }

    ToDoMainActivity.sortActivityItems(todoItems);

    return todoItems;
  }
  public GiftListDAO getGifts(long friendid) {
    String query =
        "SELECT "
            + COLUMN_G_ASIN
            + ","
            + COLUMN_G_TITLE
            + " FROM "
            + TABLE_GIFT
            + " WHERE "
            + COLUMN_G_FRIENDID
            + "="
            + friendid
            + ";";
    List<GiftDAO> giftList = new ArrayList<GiftDAO>();
    String asin = null, title = null;
    SQLiteDatabase db = getWritableDatabase();
    Cursor c = db.rawQuery(query, null);
    if (c != null && c.moveToFirst()) {
      do {
        asin = title = null;
        try {
          asin = c.getString(c.getColumnIndex(COLUMN_G_ASIN));
          title = c.getString(c.getColumnIndex(COLUMN_G_TITLE));
        } catch (Exception e) {

        }
        if (asin.equals(null) || title.equals(null)) {
          System.out.println("Bad gift data, pass");
        } else {
          giftList.add(new GiftDAO(asin, friendid, title));
        }
      } while (c.moveToNext());
    }
    return new GiftListDAO(giftList);
  }
Exemple #18
0
  /**
   * Method loads data from the bridges table
   *
   * @param db data base to read the data frim
   */
  static void load(SQLiteDatabase db, Context context) {
    assert (db != null);
    assert (context != null);
    Cursor cursor = db.rawQuery("select * from " + BridgeEntry.TABLE_NAME, null);

    if (cursor.moveToFirst()) {
      Bridge bridge;

      while (!cursor.isAfterLast()) {
        int id = cursor.getInt(cursor.getColumnIndex(BridgeEntry.COLUMN_NAME_BRIDGE_ID));
        String userDefName =
            cursor.getString(cursor.getColumnIndex(BridgeEntry.COLUMN_NAME_USER_DEF_NAME));
        if (userDefName == null)
          userDefName = context.getResources().getString(R.string.default_bridge);
        bridge =
            new Bridge(
                id,
                userDefName,
                cursor.getString(cursor.getColumnIndex(BridgeEntry.COLUMN_NAME_FACTORY_NAME)));

        DataManager.getInstance().addBridge(bridge);
        if (cursor.getInt(cursor.getColumnIndex(BridgeEntry.COLUMN_NAME_ACTIVE)) == 1)
          DataManager.getInstance().setActiveBridgeId(id);

        cursor.moveToNext();
      }

      cursor.close();
    }
  }
 private void deletePrivacyCallogs() {
   int sum = PrivacyContactsActivity.sPrivacyContactsListItems.size();
   for (int i = 0; i < sum; i++) {
     PrivacyContactDataItem item = PrivacyContactsActivity.sPrivacyContactsListItems.get(i);
     PhoneType pt = ConvertUtils.getPhonetype(item.getPhoneNumber());
     Cursor localCursor =
         context
             .getContentResolver()
             .query(
                 CALLOG_URI,
                 CALLOG_PROJECTION,
                 "number LIKE '%" + pt.getPhoneNo() + "%'",
                 null,
                 null);
     if (localCursor != null && localCursor.getCount() > 0) {
       while (localCursor.moveToNext()) {
         int isNew = localCursor.getInt(localCursor.getColumnIndex(CallLog.Calls.NEW));
         int type = localCursor.getInt(localCursor.getColumnIndex(CallLog.Calls.TYPE));
         System.out.println("isNew :" + isNew);
         if (isNew == 1 || type == CallLog.Calls.MISSED_TYPE) {
           updateNotification();
         }
       }
       context
           .getContentResolver()
           .delete(CALLOG_URI, "number LIKE '%" + pt.getPhoneNo() + "%'", null);
     }
   }
 }
Exemple #20
0
    protected Void processCursor(Cursor cursor) {
      int iFilename = cursor.getColumnIndex(Image.COLUMN_FILENAME);
      String filename;

      int iID = cursor.getColumnIndex("_id");

      int i = 0;
      int size = mCheckedPositions.size();

      while (cursor.moveToNext()) {

        if (mCheckedPositions.get(cursor.getPosition())) {
          filename = cursor.getString(iFilename);

          try {
            if (FileUtils.deleteFile(filename)) publishProgress(++i, size);

            context
                .getContentResolver()
                .delete(
                    Uri.withAppendedPath(SPOCContentProvider.IMAGES_URI, cursor.getString(iID)),
                    null,
                    null);
          } catch (IOException e) {
            Log.w(getClass().getName(), e);
            // TODO: pass exception to UI
          }
        }
      }
      return null;
    }
 @Override
 public void bindView(View view, Context context, final Cursor cursor) {
   View w = view;
   ((TextView) w.findViewById(R.id.textHeading))
       .setText(
           cursor.getString(
               cursor.getColumnIndex(
                   ru.ifmo.md.lesson6.RssDatabase.Structure.FEEDS_COLUMN_NAME)));
   ((TextView) w.findViewById(R.id.textDescription))
       .setText(
           Html.fromHtml(
               cursor.getString(
                   cursor.getColumnIndex(
                       ru.ifmo.md.lesson6.RssDatabase.Structure.FEEDS_COLUMN_DESCRIPTION))));
   final int id =
       cursor.getInt(
           cursor.getColumnIndex(
               ru.ifmo.md.lesson6.RssDatabase.Structure.COLUMN_ROWID_AFTER_QUERY));
   w.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View view) {
           Intent it = new Intent(MainActivity.this, ru.ifmo.md.lesson6.RssActivity.class);
           it.putExtra("feedId", id);
           MainActivity.this.startActivity(it);
         }
       });
 }
  public static CallContact buildUserContact(Context c) {
    CallContact result = null;
    try {
      Cursor mProfileCursor =
          c.getContentResolver().query(Profile.CONTENT_URI, PROFILE_PROJECTION, null, null, null);
      if (mProfileCursor != null) {
        if (mProfileCursor.moveToFirst()) {
          String key = mProfileCursor.getString(mProfileCursor.getColumnIndex(Profile.LOOKUP_KEY));
          String displayName =
              mProfileCursor.getString(mProfileCursor.getColumnIndex(Profile.DISPLAY_NAME_PRIMARY));

          if (displayName == null || displayName.isEmpty())
            displayName = c.getResources().getString(R.string.me);
          result =
              new CallContact(
                  mProfileCursor.getLong(mProfileCursor.getColumnIndex(Profile._ID)),
                  key,
                  displayName,
                  mProfileCursor.getLong(mProfileCursor.getColumnIndex(Profile.PHOTO_ID)),
                  new ArrayList<Phone>(),
                  "",
                  true);
        }
        mProfileCursor.close();
      }
    } catch (Exception e) {
      Log.w(TAG, e);
    }
    return result == null
        ? new CallContact(
            -1, null, c.getResources().getString(R.string.me), 0, new ArrayList<Phone>(), "", true)
        : result;
  }
  // 查找第几集播放进度
  public synchronized long getHistroyProgressByID(String sMovieID, int position) {
    // TODO Auto-generated method stub
    try {
      database = pipiDBHelp.getReadableDatabase();

      String sql =
          "select * from "
              + PipiDBHelp.HISTROY_TABLENAME
              + " where "
              + TableName.MovieID
              + "= '"
              + sMovieID
              + "'";
      cursor = database.rawQuery(sql, null);
      if (cursor.moveToNext()) {
        if (position == cursor.getInt(cursor.getColumnIndex(TableName.MoviePlayPosition))) {
          long progress = cursor.getLong(cursor.getColumnIndex(TableName.MoviePlayProgress));
          Log.i("TAG999", "insertMovieHistroy  = " + position + "*******" + progress);
          return progress;
        }
      }
    } catch (Exception e) {
      // TODO: handle exception
    } finally {
      closeCursor();
    }

    return 0;
  }
 public ArchiveShowObj getShow(String identifier) {
   Logging.Log(LOG_TAG, "Getting show: " + identifier);
   ArchiveShowObj show = null;
   Cursor cur =
       db.query(
           true,
           SHOW_TBL,
           new String[] {
             SHOW_IDENT, SHOW_TITLE, SHOW_ARTIST, SHOW_SOURCE, SHOW_HASVBR, SHOW_HASLBR, "_id"
           },
           SHOW_IDENT + "=" + "'" + identifier + "'",
           null,
           null,
           null,
           null,
           null);
   if (cur != null) {
     cur.moveToFirst();
     show =
         new ArchiveShowObj(
             cur.getString(cur.getColumnIndex(SHOW_IDENT)),
             cur.getString(cur.getColumnIndex(SHOW_TITLE)),
             cur.getString(cur.getColumnIndex(SHOW_ARTIST)),
             cur.getString(cur.getColumnIndex(SHOW_SOURCE)),
             cur.getString(cur.getColumnIndex(SHOW_HASVBR)),
             cur.getString(cur.getColumnIndex(SHOW_HASLBR)),
             cur.getInt(cur.getColumnIndex("_id")));
   }
   cur.close();
   return show;
 }
  public synchronized List<String> getKeys(int num) {

    List<String> keys = new ArrayList<String>();
    String sql =
        "select  *  from "
            + TableName.KEYS_TABLENAME
            + " order by "
            + TableName.Movie_ID
            + " desc ";
    try {
      database = pipiDBHelp.getWritableDatabase();
      cursor = database.rawQuery(sql, null);
      if (cursor != null && cursor.getCount() != 0) {
        while (cursor.moveToNext()) {
          if (keys.size() < 6) {
            keys.add(cursor.getString(cursor.getColumnIndex(TableName.KEY)));
          } else {
            delSingleKey(cursor.getString(cursor.getColumnIndex(TableName.KEY)));
          }
        }
      }
    } catch (Exception e) {
      // TODO: handle exception
    } finally {
      closeCursor();
    }

    return keys;
  }
 public int getShowDownloadStatus(ArchiveShowObj show) {
   Cursor cur =
       db.rawQuery(
           "Select "
               + "(Select count(1) from songTbl song "
               + "inner join showTbl show on show._id = song.show_id and show.showIdent = '"
               + show.getIdentifier()
               + "' "
               + "where song.isDownloaded = 'true') as 'downloaded', "
               + "(Select count(1) from songTbl song "
               + "inner join showTbl show on show._id = song.show_id and show.showIdent = '"
               + show.getIdentifier()
               + "') "
               + "as 'total'",
           null);
   cur.moveToFirst();
   int downloaded = cur.getInt(cur.getColumnIndex("downloaded"));
   int total = cur.getInt(cur.getColumnIndex("total"));
   cur.close();
   if (downloaded > 0) {
     if (downloaded < total) {
       return SHOW_STATUS_PARTIALLY_DOWNLOADED;
     } else {
       return SHOW_STATUS_FULLY_DOWNLOADED;
     }
   } else {
     return SHOW_STATUS_NOT_DOWNLOADED;
   }
 }
 public Indices(Cursor cursor) {
   type = cursor.getColumnIndex(Suggestions.TYPE);
   title = cursor.getColumnIndex(Suggestions.TITLE);
   summary = cursor.getColumnIndex(Suggestions.SUMMARY);
   icon = cursor.getColumnIndex(Suggestions.ICON);
   extra_id = cursor.getColumnIndex(Suggestions.EXTRA_ID);
 }
  public static List<Album> getAllAlbums(ContentResolver contentResolver) {
    String[] projection = {
      MediaStore.Audio.Albums._ID,
      MediaStore.Audio.Albums.ARTIST,
      MediaStore.Audio.Albums.ALBUM,
      MediaStore.Audio.Albums.ALBUM_ART
    };

    Cursor cursor =
        contentResolver.query(
            MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
            projection,
            null,
            null,
            MediaStore.Audio.Albums.ALBUM);

    List<Album> albums = null;
    if (cursor != null) {
      albums = new ArrayList<Album>();
      while (cursor.moveToNext()) {
        Album album = new Album();
        album.setId(cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Albums._ID)));
        album.setArtist(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ARTIST)));
        album.setTitle(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM)));
        album.setThumbnail(
            cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART)));

        albums.add(album);
      }
    }

    return albums;
  }
  /**
   * fills the list with stops from the local database
   *
   * @param db the database adapter to use
   */
  private void fillList(BusDbAdapter db) {
    Cursor c;
    if (listType == FAVORITES) {
      c = db.getFavoriteDest(NUM_ENTRIES_TO_FETCH);
    } else { // listType == MAJOR
      c = db.getMajorDest(NUM_ENTRIES_TO_FETCH);
    }
    int stopIDIndex = c.getColumnIndex("stop_id");
    int stopDescIndex = c.getColumnIndex("stop_desc");
    int routeIDIndex = c.getColumnIndex("route_id");
    int routeDescIndex = c.getColumnIndex("route_desc");
    if (c != null) {
      for (int i = 0; i < c.getCount(); i++) {
        HashMap<String, String> item = new HashMap<String, String>();

        String stopID = c.getString(stopIDIndex);
        String stopName = c.getString(stopDescIndex);
        String route = c.getString(routeIDIndex);
        String routeDesc = c.getString(routeDescIndex);
        Log.v(TAG, "PUT");
        Log.v(TAG, "stopID " + stopID + " stopName " + stopName);
        Log.v(TAG, "routeID " + route + " routeDesc" + routeDesc);
        item.put("stopID", stopID);
        item.put("stopName", stopName);
        item.put("routeID", route);
        item.put("routeDesc", routeDesc);
        c.moveToNext();
        locationList.add(item);
      }
      listAdapter.notifyDataSetChanged();
    }
  }
  private static String contactToEmail(Cursor cur, ContentResolver cr, String id) {
    Cursor emailCur =
        cr.query(
            ContactsContract.CommonDataKinds.Email.CONTENT_URI,
            null,
            ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
            new String[] {id},
            null);
    // first search for default number
    while (emailCur.moveToNext()) {

      int defaultIfGreaterThanZero =
          emailCur.getInt(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
      if (defaultIfGreaterThanZero > 0) {
        return emailCur.getString(
            emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
      }
    }
    emailCur.moveToPosition(-1);
    while (emailCur.moveToNext()) {
      // This would allow you get several email addresses
      // if the email addresses were stored in an array
      return emailCur.getString(
          emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
    }
    emailCur.close();
    return null;
  }