public Map<String, Object> createHistoryItem(Cursor cursor) {
      Map<String, Object> historyItem = new HashMap<String, Object>();

      String url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL));
      String title = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE));
      byte[] favicon = cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON));
      Integer bookmarkId = cursor.getInt(cursor.getColumnIndexOrThrow(Combined.BOOKMARK_ID));
      Integer historyId = cursor.getInt(cursor.getColumnIndexOrThrow(Combined.HISTORY_ID));
      Integer display = cursor.getInt(cursor.getColumnIndexOrThrow(Combined.DISPLAY));

      // Use the URL instead of an empty title for consistency with the normal URL
      // bar view - this is the equivalent of getDisplayTitle() in Tab.java
      if (title == null || title.length() == 0) title = url;

      historyItem.put(URLColumns.URL, url);
      historyItem.put(URLColumns.TITLE, title);

      if (favicon != null) historyItem.put(URLColumns.FAVICON, favicon);

      historyItem.put(Combined.BOOKMARK_ID, bookmarkId);
      historyItem.put(Combined.HISTORY_ID, historyId);
      historyItem.put(Combined.DISPLAY, display);

      return historyItem;
    }
 /* getTasks - gets all tasks a person may have from the database */
 public ArrayList<Task> getTasks() {
   ArrayList<Task> tasks = new ArrayList<Task>();
   SQLiteDatabase db = this.getReadableDatabase();
   Task task;
   // get all tasks from the tasks table
   Cursor c = db.rawQuery("SELECT * FROM " + TABLE_TASKS, null);
   if (c != null) {
     if (c.moveToFirst()) { // start at the first record
       do {
         task = new Task();
         // insert data from the table into a new task object
         task.mSubj = c.getString(c.getColumnIndex(KEY_SUBJ));
         task.mCode = c.getString(c.getColumnIndex(KEY_CODE));
         task.mAssign = c.getInt(c.getColumnIndex(KEY_ASSIGN));
         task.mName = c.getString(c.getColumnIndex(KEY_NAME));
         task.mMark = c.getInt(c.getColumnIndex(KEY_MARK));
         task.mBase = c.getInt(c.getColumnIndex(KEY_BASE));
         task.mWeight = c.getFloat(c.getColumnIndex(KEY_WEIGHT));
         task.mDueDate = c.getString(c.getColumnIndex(KEY_DUE));
         task.mIsDone = c.getInt(c.getColumnIndex(KEY_IS_DONE));
         task.mCreationDate = c.getString(c.getColumnIndex(KEY_CREATE_DATE));
         task.mPriority = c.getInt(c.getColumnIndex(KEY_PRIORITY));
         tasks.add(task); // add the task to the list
       } while (c.moveToNext());
     }
   }
   c.close(); // close cursor
   db.close(); // close database
   return tasks; // return the list of tasks
 }
  /**
   * Fills a track point from a cursor.
   *
   * @param cursor the cursor pointing to a location.
   * @param indexes the cached track points indexes
   * @param location the track point
   */
  private void fillTrackPoint(Cursor cursor, CachedTrackPointsIndexes indexes, Location location) {
    location.reset();

    if (!cursor.isNull(indexes.longitudeIndex)) {
      location.setLongitude(((double) cursor.getInt(indexes.longitudeIndex)) / 1E6);
    }
    if (!cursor.isNull(indexes.latitudeIndex)) {
      location.setLatitude(((double) cursor.getInt(indexes.latitudeIndex)) / 1E6);
    }
    if (!cursor.isNull(indexes.timeIndex)) {
      location.setTime(cursor.getLong(indexes.timeIndex));
    }
    if (!cursor.isNull(indexes.altitudeIndex)) {
      location.setAltitude(cursor.getFloat(indexes.altitudeIndex));
    }
    if (!cursor.isNull(indexes.accuracyIndex)) {
      location.setAccuracy(cursor.getFloat(indexes.accuracyIndex));
    }
    if (!cursor.isNull(indexes.speedIndex)) {
      location.setSpeed(cursor.getFloat(indexes.speedIndex));
    }
    if (!cursor.isNull(indexes.bearingIndex)) {
      location.setBearing(cursor.getFloat(indexes.bearingIndex));
    }
    if (location instanceof MyTracksLocation && !cursor.isNull(indexes.sensorIndex)) {
      MyTracksLocation myTracksLocation = (MyTracksLocation) location;
      try {
        myTracksLocation.setSensorDataSet(
            SensorDataSet.parseFrom(cursor.getBlob(indexes.sensorIndex)));
      } catch (InvalidProtocolBufferException e) {
        Log.w(TAG, "Failed to parse sensor data.", e);
      }
    }
  }
  private void loadNote() {
    Cursor cursor =
        mContext
            .getContentResolver()
            .query(
                ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId),
                NOTE_PROJECTION,
                null,
                null,
                null);

    if (cursor != null) {
      if (cursor.moveToFirst()) {
        mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
        mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
        mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN);
        mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN);
        mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN);
        mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
      }
      cursor.close();
    } else {
      Log.e(TAG, "No note with id:" + mNoteId);
      throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
    }
    loadNoteData();
  }
  /**
   * 从数据库中得到缩略图
   *
   * @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 static final Map instanceOf(TTSQLiteOpenHelper sqLiteOpenHelper, int mapId) {
    Map map = new Map();
    SQLiteDatabase database = sqLiteOpenHelper.getReadableDatabase();
    Cursor cursor =
        database.query(
            TABLE_MAPS, ALL_MAP_COLUMNS, COLUMN_ID + " = " + mapId, null, null, null, null);
    cursor.moveToFirst();
    map.id = mapId;
    map.name = cursor.getString(cursor.getColumnIndex(COLUMN_NAME));
    map.startTime = cursor.getInt(cursor.getColumnIndex(COLUMN_START_TIME));
    map.endTime = cursor.getInt(cursor.getColumnIndex(COLUMN_END_TIME));
    map.averageSpeed = cursor.getFloat(cursor.getColumnIndex(COLUMN_AVERAGE_SPEED));
    map.totalDistance = cursor.getFloat(cursor.getColumnIndex(COLUMN_TOTAL_DISTANCE));
    map.linearDistance = cursor.getFloat(cursor.getColumnIndex(COLUMN_LINEAR_DISTANCE));
    map.maximumSpeed = cursor.getFloat(cursor.getColumnIndex(COLUMN_MAXIMUM_SPEED));
    map.maximumAltitude = cursor.getFloat(cursor.getColumnIndex(COLUMN_MAX_ALTITUDE));
    map.minimumAltitude = cursor.getFloat(cursor.getColumnIndex(COLUMN_MIN_ALTITUDE));
    map.startAltitude = cursor.getFloat(cursor.getColumnIndex(COLUMN_START_ALTITUDE));
    map.endAltitude = cursor.getFloat(cursor.getColumnIndex(COLUMN_END_ALTITUDE));
    map.notes = cursor.getString(cursor.getColumnIndex(COLUMN_NOTES));
    cursor.close();

    map.locations = TTLocation.getAll(sqLiteOpenHelper, mapId);
    map.waypoints = Waypoint.getAll(sqLiteOpenHelper, mapId);
    map.stops = Stop.getAll(sqLiteOpenHelper, mapId);

    return map;
  }
Exemple #7
0
 public static List<StatEntry> listEntries(Context ctx, int limit, int offset) {
   DbHelper helper = new DbHelper(ctx);
   SQLiteDatabase db = helper.getReadableDatabase();
   Cursor c = db.query("stat", null, null, null, null, null, "date desc", offset + "," + limit);
   List<StatEntry> res = new ArrayList<StatEntry>();
   if (c.moveToFirst()) {
     int dateIdx = c.getColumnIndex("date");
     int digitsIdx = c.getColumnIndex("digits");
     int successIdx = c.getColumnIndex("success");
     int memMillisIdx = c.getColumnIndex("mem_millis");
     int recallMillisIdx = c.getColumnIndex("recall_millis");
     int event = c.getColumnIndex("event");
     do {
       StatEntry e = new StatEntry();
       e.setDate(new Date(c.getLong(dateIdx)));
       e.setDigits(c.getInt(digitsIdx));
       e.setSuccess(c.getInt(successIdx));
       e.setMemMillis(c.getInt(memMillisIdx));
       e.setRecallMillis(c.getInt(recallMillisIdx));
       e.setEvent(c.getInt(event));
       res.add(e);
     } while (c.moveToNext());
   }
   c.close();
   helper.close();
   return res;
 }
 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));
 }
Exemple #9
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();
    }
  }
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;
  }
 // Getters
 // Getting specific assignment
 public Assignment getAssignment(int aid) {
   Log.d("Went into getAssignment", "yes: " + Integer.toString(aid));
   String selectQuery = "SELECT * FROM Assignment " + " WHERE aid = " + aid;
   Log.d("selectQuery: ", selectQuery);
   SQLiteDatabase db = this.getWritableDatabase();
   Cursor cursor = db.rawQuery(selectQuery, null);
   cursor.moveToFirst();
   Log.d("getAssignment cursor size: ", Integer.toString(cursor.getCount()));
   Log.d("getAssignment cursor 1st entry: ", cursor.getString(0));
   Assignment assignment = new Assignment();
   assignment.setaid(Integer.parseInt(cursor.getString(0)));
   assignment.settitle(cursor.getString(1));
   assignment.settype(cursor.getString(2));
   assignment.setmonth(Integer.parseInt(cursor.getString(3)));
   assignment.setday(Integer.parseInt(cursor.getString(4)));
   assignment.setyear(Integer.parseInt(cursor.getString(5)));
   assignment.setpriority(Integer.parseInt(cursor.getString(6)));
   Log.d("Got priority", cursor.getString(6));
   Log.d("Course = ", cursor.getString(7));
   if (cursor.getInt(7) > 0)
     assignment.setCourse(getCourse(Integer.parseInt(cursor.getString(7))));
   else assignment.setCourse(null);
   if (cursor.getInt(8) > 0)
     assignment.setInstructor(getInstructor(Integer.parseInt(cursor.getString(8))));
   else assignment.setInstructor(null);
   assignment.setPartner(getPartners(assignment.getaid()));
   assignment.setnotes(cursor.getString(9));
   assignment.setCompleted(cursor.getInt(10));
   if (cursor.getInt(10) == 1) {
     assignment.setGrade(getGrade(assignment.getaid()));
   }
   Log.d("Got everything successfully", "yes");
   return assignment;
 }
 /**
  * 查找数据库记录
  *
  * @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;
 }
Exemple #14
0
  public Service(Cursor cursor) {
    int idColumn = cursor.getColumnIndex(ID);
    int serviceProviderColumn = cursor.getColumnIndex(SERVICE_PROVIDER);
    int serviceIdColumn = cursor.getColumnIndex(SERVICE_ID);
    int accountIDColumn = cursor.getColumnIndex(ACCOUNT_ID);
    int updateColumn = cursor.getColumnIndex(UPDATED);
    int statusColumn = cursor.getColumnIndex(STATUS);
    int dataColumn = cursor.getColumnIndex(DATA);

    id = cursor.getInt(idColumn);
    identifier =
        new ServiceIdentifier(
            cursor.getString(serviceProviderColumn), cursor.getString(serviceIdColumn));
    accountID = cursor.getInt(accountIDColumn);

    long l = cursor.getLong(updateColumn);
    lastUpdate = l == -1 ? null : new Date(l);
    updateStatus = UpdateStatus.values()[cursor.getInt(statusColumn)];

    // Plan, serviceType and metricGroups come from Data
    try {
      readFrom(new JSONObject(cursor.getString(dataColumn)));
    } catch (JSONException e) {
      Log.e("service", "Error procesisng JSON", e);
      throw new IllegalArgumentException("Error JSON processing");
    }
  }
 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;
   }
 }
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    Cursor note = extObjDB.fetchNote(id);
    startManagingCursor(note);
    ObjSource s;
    int resource_id = note.getInt(note.getColumnIndexOrThrow(ExternObjDB.KEY_RESRC_ID));
    if (resource_id == -1) {
      // obj from sdcard
      String path = note.getString(note.getColumnIndexOrThrow(ExternObjDB.KEY_PATH));
      s = new ObjFromSDcard(path);
    } else {
      // obj from resource
      s = new ObjFromResource(resource_id);
    }
    s.Title = note.getString(note.getColumnIndexOrThrow(ExternObjDB.KEY_TITLE));
    s.Info = note.getString(note.getColumnIndexOrThrow(ExternObjDB.KEY_INFO));
    s.ID = note.getInt(note.getColumnIndexOrThrow(ExternObjDB.KEY_ROWID));
    Bundle bundle = new Bundle();

    bundle.putSerializable(ObjSource.TITLE, s);

    Intent mIntent = new Intent();
    mIntent.putExtras(bundle);
    setResult(RESULT_OK, mIntent);
    finish();
  }
 /**
  * 查询群组成员用于列表显示
  *
  * @param groupId
  * @return
  */
 public static ArrayList<ECGroupMember> getGroupMemberWithName(String groupId) {
   String sql =
       "select voipaccount ,contacts.username ,contacts.remark ,role ,isban from group_members ,contacts where group_id ='"
           + groupId
           + "' and contacts.contact_id = group_members.voipaccount order by role";
   // String sql = "select voipaccount ,remark,role , isban from group_members where group_id ='" +
   // groupId + "'" ;
   ArrayList<ECGroupMember> list = null;
   try {
     Cursor cursor = getInstance().sqliteDB().rawQuery(sql, null);
     if (cursor != null && cursor.getCount() > 0) {
       list = new ArrayList<ECGroupMember>();
       while (cursor.moveToNext()) {
         ECGroupMember groupMember = new ECGroupMember();
         groupMember.setBelong(groupId);
         groupMember.setVoipAccount(cursor.getString(0));
         groupMember.setDisplayName(cursor.getString(1));
         groupMember.setRemark(cursor.getString(2));
         groupMember.setRole(cursor.getInt(3));
         groupMember.setBan(cursor.getInt(4) == 2 ? true : false);
         list.add(groupMember);
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return list;
 }
  public ArrayList<Info> getInfo() {
    cursor = musicBase.query("mytable", null, null, null, null, null, null);

    initColumns();

    ArrayList<Info> list = new ArrayList<>();
    if (cursor.moveToFirst()) {

      do {
        Info addedInfo =
            new Info(
                cursor.getString(nameCollumIndex),
                cursor.getInt(durationCollumIndex),
                new User(cursor.getString(authorCollumIndex)),
                cursor.getInt(likesCountCollumIndex),
                cursor.getString(streamUrlCollumIndex),
                cursor.getString(pathToFileCollumIndex),
                cursor.getString(artworkUrlCollumIndex));
        list.add(addedInfo);
        Log.i("list", addedInfo.toString());
        Log.i("list", "----------------------------------------------");
      } while (cursor.moveToNext());
    }
    return list;
  }
Exemple #19
0
  public static clsUsuario Buscar(Context context) {
    clsUsuario entidad = null;
    bdSQLite admin = new bdSQLite(context, null);
    SQLiteDatabase bd = admin.getWritableDatabase();
    if (bd != null) {
      String query =
          "select int_id_usuario,str_nombres,str_apellido_paterno,str_apellido_materno,"
              + "str_usuario,str_clave,str_email,str_dni,str_telefono,str_direccion,"
              + "bol_sexo,byte_foto,int_id_persona from "
              + NOMBRE_TABLA;

      Cursor fila = bd.rawQuery(query, null);

      if (fila.moveToFirst()) {
        entidad = new clsUsuario();
        entidad.setInt_id_usuario(fila.getInt(0));
        entidad.setStr_nombres(fila.getString(1));
        entidad.setStr_apellido_paterno(fila.getString(2));
        entidad.setStr_apellido_materno(fila.getString(3));
        entidad.setStr_usuario(fila.getString(4));
        entidad.setStr_clave(fila.getString(5));
        entidad.setStr_email(fila.getString(6));
        entidad.setStr_dni(fila.getString(7));
        entidad.setStr_telefono(fila.getString(8));
        entidad.setStr_direccion(fila.getString(9));
        if (fila.getInt(10) == 1) entidad.setBol_sexo(true);
        else entidad.setBol_sexo(false);

        entidad.setByte_foto(fila.getBlob(11));
        entidad.setInt_id_persona(fila.getInt(12));
      }
    }
    bd.close();
    return entidad;
  }
  public boolean checkForExist(Info info) {
    boolean b = false;
    cursor = musicBase.query("mytable", null, null, null, null, null, null);

    initColumns();

    if (cursor.moveToFirst()) {

      do {
        Info addedInfo =
            new Info(
                cursor.getString(nameCollumIndex),
                cursor.getInt(durationCollumIndex),
                new User(cursor.getString(authorCollumIndex)),
                cursor.getInt(likesCountCollumIndex),
                cursor.getString(streamUrlCollumIndex),
                cursor.getString(pathToFileCollumIndex),
                cursor.getString(artworkUrlCollumIndex));
        if (addedInfo.getStream_url().equals(info.getStream_url())) {
          b = true;
          break;
        }

      } while (cursor.moveToNext());
    }
    return b;
  }
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
      View view = layoutInflater.inflate(layout, parent, false);

      Chapter chapter = new Chapter();
      chapter.setNo(cursor.getInt(cursor.getColumnIndex(TableVerse.VERSE_NO)));
      chapter.setStart(cursor.getInt(cursor.getColumnIndex(TableChapter.START)));
      chapter.setEnd(cursor.getInt(cursor.getColumnIndex(TableChapter.END)));
      chapter.setTotal(cursor.getInt(cursor.getColumnIndex(TableChapter.TOTAL)));
      chapter.setTitlePali(cursor.getString(cursor.getColumnIndex(TableChapter.TITLE_PALI)));
      chapter.setTitleEng(cursor.getString(cursor.getColumnIndex(TableChapter.TITLE_ENG)));
      chapter.setTitleId(cursor.getString(cursor.getColumnIndex(TableChapter.TITLE_ID)));

      SearchVerse verse = new SearchVerse(chapter, cursor);
      if (verse.getContentPali().indexOf(query) >= 0) {
        verse.setSearchContent(getQueryPart(verse.getContentPali(), query));
      } else if (verse.getContentEng().indexOf(query) >= 0) {
        verse.setSearchContent(getQueryPart(verse.getContentEng(), query));
      } else if (verse.getContentId().indexOf(query) >= 0) {
        verse.setSearchContent(getQueryPart(verse.getContentId(), query));
      }
      verse.setQuery(query);
      view.setTag(verse);

      return view;
    }
  /**
   * 根据当前id获取下载信息
   *
   * @param id
   * @return
   */
  public synchronized DownloadInfo get(int id) {
    DownloadInfo info = null;
    open();
    Cursor cur =
        db.query(
            true,
            DATABASE_TABLE,
            new String[] {ID, NAME, LOCAL_NAME, URL, FILE_SIZE, COMPLETE_SIZE},
            ID + "=" + id,
            null,
            null,
            null,
            null,
            null);
    if (cur != null) {
      cur.moveToFirst();
      if (cur.getCount() <= 0) {
        return null;
      }
      info = new DownloadInfo();
      info.setId(cur.getInt(0));
      info.setFilename(cur.getString(1));
      info.setLocalname(cur.getString(2));
      info.setUrl(cur.getString(3));
      info.setFilesize(cur.getInt(4));
      info.setCompletesize(cur.getInt(5));
      cur.close();
      if (isDebug) Log.i(TAG, "-----dbHelper---getCount = " + cur.getCount());
    }

    return info;
  }
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    menuInfo.toString();

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final Cursor show =
        getActivity()
            .getContentResolver()
            .query(
                Shows.buildShowUri(String.valueOf(info.id)),
                new String[] {Shows.FAVORITE, Shows.HIDDEN},
                null,
                null,
                null);
    show.moveToFirst();
    if (show.getInt(0) == 0) {
      menu.add(0, CONTEXT_FAVORITE_ID, 2, R.string.context_favorite);
    } else {
      menu.add(0, CONTEXT_UNFAVORITE_ID, 2, R.string.context_unfavorite);
    }
    if (show.getInt(1) == 0) {
      menu.add(0, CONTEXT_HIDE_ID, 3, R.string.context_hide);
    } else {
      menu.add(0, CONTEXT_UNHIDE_ID, 3, R.string.context_unhide);
    }
    show.close();

    menu.add(0, CONTEXT_CHECKIN_ID, 0, R.string.checkin);
    menu.add(0, CONTEXT_FLAG_NEXT_ID, 1, R.string.context_marknext);
    menu.add(0, CONTEXT_MANAGE_LISTS_ID, 4, R.string.list_item_manage);
    menu.add(0, CONTEXT_UPDATE_ID, 5, R.string.context_updateshow);
    menu.add(0, CONTEXT_DELETE_ID, 6, R.string.delete_show);
  }
Exemple #24
0
 public NurseBean getNurseInfoById(String nurseId) {
   NurseBean bean = null;
   if (db != null) {
     Cursor cursor =
         db.query(
             DATABASE_TABLE,
             dispColumns,
             COLUMN_NURSEID + " = ? ",
             new String[] {nurseId},
             null,
             null,
             null);
     if (cursor == null) {
       return null;
     }
     if (cursor.moveToPosition(0)) {
       bean = new NurseBean();
       bean.setId(cursor.getInt(cursor.getColumnIndex(COLUMN_ID)));
       bean.setNurse_id(cursor.getInt(cursor.getColumnIndex(COLUMN_NURSEID)));
       bean.setNurse_name(cursor.getString(cursor.getColumnIndex(COLUMN_NAME)));
       bean.setMobile(cursor.getString(cursor.getColumnIndex(COLUMN_MOBILE)));
       bean.setPension_id(cursor.getInt(cursor.getColumnIndex(COLUMN_PENSIONID)));
       bean.setPension_areaid(cursor.getInt(cursor.getColumnIndex(COLUMN_AREAID)));
       bean.setAvatar_url(cursor.getString(cursor.getColumnIndex(COlUMN_AVATARURL)));
       bean.setNote(cursor.getString(cursor.getColumnIndex(COLUMN_NOTE)));
     }
     cursor.close();
   }
   return bean;
 }
 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 #26
0
 /**
  * 通过老人id 获取老人健康信息
  *
  * @param old_sn
  * @return
  */
 public List<NurseBean> getAllNurseInfo() {
   List<NurseBean> list = null;
   if (db != null) {
     Cursor cursor = db.query(DATABASE_TABLE, dispColumns, null, null, null, null, null);
     if (cursor == null) {
       return null;
     }
     int count = cursor.getCount();
     NurseBean bean = null;
     list = new ArrayList<NurseBean>();
     for (int i = 0; i < count; i++) {
       if (cursor.moveToPosition(i)) {
         bean = new NurseBean();
         bean.setId(cursor.getInt(cursor.getColumnIndex(COLUMN_ID)));
         bean.setNurse_id(cursor.getInt(cursor.getColumnIndex(COLUMN_NURSEID)));
         bean.setNurse_name(cursor.getString(cursor.getColumnIndex(COLUMN_NAME)));
         bean.setMobile(cursor.getString(cursor.getColumnIndex(COLUMN_MOBILE)));
         bean.setPension_id(cursor.getInt(cursor.getColumnIndex(COLUMN_PENSIONID)));
         bean.setPension_areaid(cursor.getInt(cursor.getColumnIndex(COLUMN_AREAID)));
         bean.setAvatar_url(cursor.getString(cursor.getColumnIndex(COlUMN_AVATARURL)));
         bean.setNote(cursor.getString(cursor.getColumnIndex(COLUMN_NOTE)));
         list.add(bean);
       }
     }
     cursor.close();
   }
   return list;
 }
 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)});
   }
 }
Exemple #28
0
  /**
   * *
   *
   * @param db SQLiteDatabase - The database resource to query
   * @return ArrayList<Price>
   */
  public static ArrayList<Price> findAll(SQLiteDatabase db) {

    String sql = "SELECT * FROM price ORDER BY created_at DESC";
    Cursor cursor = db.rawQuery(sql, null);

    ArrayList<Price> prices = new ArrayList<>();
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
      int id = (cursor.getInt(cursor.getColumnIndex(PriceTable.COLUMN_NAME_ID)));
      int stationId = (cursor.getInt(cursor.getColumnIndex(PriceTable.COLUMN_NAME_STATION_ID)));
      int productClass =
          (cursor.getInt(cursor.getColumnIndex(PriceTable.COLUMN_NAME_PRODUCT_CLASS)));
      Double priceValue = (cursor.getDouble(cursor.getColumnIndex(PriceTable.COLUMN_NAME_PRICE)));
      int verified = (cursor.getInt(cursor.getColumnIndex(PriceTable.COLUMN_NAME_VERIFIED)));
      int createdAt = (cursor.getInt(cursor.getColumnIndex(PriceTable.COLUMN_NAME_CREATED_AT)));
      String productName =
          (cursor.getString(cursor.getColumnIndex(PriceTable.COLUMN_NAME_PRODUCT_NAME)));
      Price price =
          new Price(createdAt, id, priceValue, productClass, productName, stationId, verified);
      prices.add(price);
      cursor.moveToNext();
    }
    cursor.close();
    return prices;
  }
  @MediumTest
  public void testCursor2() throws Exception {
    populateDefaultTable();

    Cursor c = mDatabase.query("test", null, "_id > 1000", null, null, null, null);
    assertEquals(0, c.getCount());
    assertTrue(c.isBeforeFirst());

    try {
      c.getInt(0);
      fail("CursorIndexOutOfBoundsException expected");
    } catch (CursorIndexOutOfBoundsException ex) {
      // expected
    }

    int i;
    for (c.moveToFirst(), i = 0; !c.isAfterLast(); c.moveToNext(), i++) {
      c.getInt(0);
    }
    assertEquals(0, i);
    try {
      c.getInt(0);
      fail("CursorIndexOutOfBoundsException expected");
    } catch (CursorIndexOutOfBoundsException ex) {
      // expected
    }
    c.close();
  }
Exemple #30
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.musuc_details);
   TextView t1 = (TextView) findViewById(R.id.textView1);
   TextView t2 = (TextView) findViewById(R.id.textView2);
   TextView t3 = (TextView) findViewById(R.id.textView3);
   TextView t4 = (TextView) findViewById(R.id.textView4);
   TextView t5 = (TextView) findViewById(R.id.textView5);
   TextView t6 = (TextView) findViewById(R.id.textView6);
   TextView t7 = (TextView) findViewById(R.id.textView7);
   String[] projection = new String[] {"title", "album", "artist", "_data", "duration", "_size"};
   Cursor cur =
       this.getContentResolver()
           .query(
               MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
               projection,
               "_id=?",
               new String[] {getIntent().getExtras().getString("_id")},
               null);
   if (cur.moveToFirst()) {
     t1.setText("ID:" + getIntent().getExtras().getString("_id"));
     t2.setText("名称:" + cur.getString(cur.getColumnIndex("title")));
     t3.setText("专辑:" + cur.getString(cur.getColumnIndex("album")));
     t4.setText("作者:" + cur.getString(cur.getColumnIndex("artist")));
     t5.setText("位置:" + cur.getString(cur.getColumnIndex("_data")));
     double _size = cur.getInt(cur.getColumnIndex("_size"));
     String sec = "" + cur.getInt(cur.getColumnIndex("duration")) / 1000 % 60;
     String min = "" + cur.getInt(cur.getColumnIndex("duration")) / 1000 / 60;
     if (sec.length() == 1) sec = "0" + sec;
     if (min.length() == 1) min = "0" + min;
     t6.setText("时间:" + min + ":" + sec);
     t7.setText("大小:" + String.format("%.2f", _size / 1024 / 1024) + " MB");
   }
 }