/**
  * Increment the cursors past the rows indicated in the most recent call to next(). This will only
  * have an affect once per call to next().
  */
 private void incrementCursors() {
   if (mCompareResultIsValid) {
     switch (mCompareResult) {
       case LEFT:
         mCursorLeft.moveToNext();
         break;
       case RIGHT:
         mCursorRight.moveToNext();
         break;
       case BOTH:
         mCursorLeft.moveToNext();
         mCursorRight.moveToNext();
         break;
     }
     mCompareResultIsValid = false;
   }
 }
  private static void construyeListaFiltros() {

    int tmpInt;
    String tmpString;

    listaFiltros = new ArrayList<DatosFiltro>();
    DatosFiltro fltAnio = new DatosFiltro("Año", "year");
    Cursor cr = getAniosDiferentes();

    while (cr.moveToNext()) {
      tmpInt = cr.getInt(0);
      tmpString = String.valueOf(tmpInt).trim();
      fltAnio.addValor(tmpInt, tmpString);
    }
    cr.close();

    listaFiltros.add(fltAnio);

    DatosFiltro fltMes = new DatosFiltro("Mes", "month");

    cr = getMesesDiferentes();

    while (cr.moveToNext()) {
      tmpInt = cr.getInt(0);
      tmpString = Utilidades.getNombreMes(tmpInt).trim();
      fltMes.addValor(tmpInt, tmpString);
    }
    cr.close();

    listaFiltros.add(fltMes);

    DatosFiltro fltTipoDeporte = new DatosFiltro("Tipo deporte", "sportType");

    cr = getTiposDeporteDiferentes();

    while (cr.moveToNext()) {
      tmpInt = cr.getInt(0);
      tmpString = Utilidades.getSportType(tmpInt).trim();
      fltTipoDeporte.addValor(tmpInt, tmpString);
    }
    cr.close();

    listaFiltros.add(fltTipoDeporte);
  }
Beispiel #3
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    String filePickerResult = "";
    if (data != null && resultCode == RESULT_OK) {
      try {
        ContentResolver cr = getContentResolver();
        Uri uri = data.getData();
        Cursor cursor =
            GeckoApp.mAppContext
                .getContentResolver()
                .query(uri, new String[] {OpenableColumns.DISPLAY_NAME}, null, null, null);
        String name = null;
        if (cursor != null) {
          try {
            if (cursor.moveToNext()) {
              name = cursor.getString(0);
            }
          } finally {
            cursor.close();
          }
        }
        String fileName = "tmp_";
        String fileExt = null;
        int period;
        if (name == null || (period = name.lastIndexOf('.')) == -1) {
          String mimeType = cr.getType(uri);
          fileExt = "." + GeckoAppShell.getExtensionFromMimeType(mimeType);
        } else {
          fileExt = name.substring(period);
          fileName = name.substring(0, period);
        }
        File file = File.createTempFile(fileName, fileExt, sGREDir);

        FileOutputStream fos = new FileOutputStream(file);
        InputStream is = cr.openInputStream(uri);
        byte[] buf = new byte[4096];
        int len = is.read(buf);
        while (len != -1) {
          fos.write(buf, 0, len);
          len = is.read(buf);
        }
        fos.close();
        filePickerResult = file.getAbsolutePath();
      } catch (Exception e) {
        Log.e(LOG_FILE_NAME, "showing file picker", e);
      }
    }
    try {
      mFilePickerResult.put(filePickerResult);
    } catch (InterruptedException e) {
      Log.i(LOG_FILE_NAME, "error returning file picker result", e);
    }
  }
  /**
   * Prints the contents of a Cursor to a StringBuilder. The position is restored after printing.
   *
   * @param cursor the cursor to print
   * @param sb the StringBuilder to print to
   */
  public static void dumpCursor(Cursor cursor, StringBuilder sb) {
    sb.append(">>>>> Dumping cursor " + cursor + "\n");
    if (cursor != null) {
      int startPos = cursor.getPosition();

      cursor.moveToPosition(-1);
      while (cursor.moveToNext()) {
        dumpCurrentRow(cursor, sb);
      }
      cursor.moveToPosition(startPos);
    }
    sb.append("<<<<<\n");
  }
  /**
   * Prints the contents of a Cursor to a PrintSteam. The position is restored after printing.
   *
   * @param cursor the cursor to print
   * @param stream the stream to print to
   */
  public static void dumpCursor(Cursor cursor, PrintStream stream) {
    stream.println(">>>>> Dumping cursor " + cursor);
    if (cursor != null) {
      int startPos = cursor.getPosition();

      cursor.moveToPosition(-1);
      while (cursor.moveToNext()) {
        dumpCurrentRow(cursor, stream);
      }
      cursor.moveToPosition(startPos);
    }
    stream.println("<<<<<");
  }
 public static void dumpCursor(Cursor paramCursor, StringBuilder paramStringBuilder)
 {
   paramStringBuilder.append(">>>>> Dumping cursor " + paramCursor + "\n");
   if (paramCursor != null)
   {
     int i = paramCursor.getPosition();
     paramCursor.moveToPosition(-1);
     while (paramCursor.moveToNext()) {
       dumpCurrentRow(paramCursor, paramStringBuilder);
     }
     paramCursor.moveToPosition(i);
   }
   paramStringBuilder.append("<<<<<\n");
 }
 public static void dumpCursor(Cursor paramCursor, PrintStream paramPrintStream)
 {
   paramPrintStream.println(">>>>> Dumping cursor " + paramCursor);
   if (paramCursor != null)
   {
     int i = paramCursor.getPosition();
     paramCursor.moveToPosition(-1);
     while (paramCursor.moveToNext()) {
       dumpCurrentRow(paramCursor, paramPrintStream);
     }
     paramCursor.moveToPosition(i);
   }
   paramPrintStream.println("<<<<<");
 }
    private void buildSQL() throws SQLException {
      StringBuilder sb = new StringBuilder(128);
      sb.append("INSERT INTO ");
      sb.append(mTableName);
      sb.append(" (");

      StringBuilder sbv = new StringBuilder(128);
      sbv.append("VALUES (");

      int i = 1;
      Cursor cur = null;
      try {
        cur = mDb.rawQuery("PRAGMA table_info(" + mTableName + ")", null);
        mColumns = new HashMap<String, Integer>(cur.getCount());
        while (cur.moveToNext()) {
          String columnName = cur.getString(TABLE_INFO_PRAGMA_COLUMNNAME_INDEX);
          String defaultValue = cur.getString(TABLE_INFO_PRAGMA_DEFAULT_INDEX);

          mColumns.put(columnName, i);
          sb.append("'");
          sb.append(columnName);
          sb.append("'");

          if (defaultValue == null) {
            sbv.append("?");
          } else {
            sbv.append("COALESCE(?, ");
            sbv.append(defaultValue);
            sbv.append(")");
          }

          sb.append(i == cur.getCount() ? ") " : ", ");
          sbv.append(i == cur.getCount() ? ");" : ", ");
          ++i;
        }
      } finally {
        if (cur != null) cur.close();
      }

      sb.append(sbv);

      mInsertSQL = sb.toString();
      if (LOCAL_LOGV) Log.v(TAG, "insert statement is " + mInsertSQL);
    }
 @Override
 protected void onQueryComplete(int token, Object cookie, android.database.Cursor cursor) {
   if (cursor == null) {
     mCallback = null;
     return;
   }
   // cookie represents itemId
   if (cookie != null) {
     mCallback.onCheckComplete(cursor.getCount() > 0);
   } else {
     Favorite[] favorites = new Favorite[cursor.getCount()];
     int count = 0;
     Cursor favoriteCursor = new Cursor(cursor);
     boolean any = favoriteCursor.moveToFirst();
     if (any) {
       do {
         favorites[count] = favoriteCursor.getFavorite();
         count++;
       } while (favoriteCursor.moveToNext());
     }
     mCallback.onQueryComplete(favorites);
   }
   mCallback = null;
 }
 private void buildSQL()
 {
   Object localObject1 = null;
   StringBuilder localStringBuilder1 = new StringBuilder(128);
   localStringBuilder1.append("INSERT INTO ");
   localStringBuilder1.append(mTableName);
   localStringBuilder1.append(" (");
   StringBuilder localStringBuilder2 = new StringBuilder(128);
   localStringBuilder2.append("VALUES (");
   Cursor localCursor;
   for (;;)
   {
     try
     {
       localCursor = mDb.rawQuery("PRAGMA table_info(" + mTableName + ")", null);
       localObject1 = localCursor;
       mColumns = new HashMap(localCursor.getCount());
       int i = 1;
       localObject1 = localCursor;
       if (!localCursor.moveToNext()) {
         break;
       }
       localObject1 = localCursor;
       String str1 = localCursor.getString(1);
       localObject1 = localCursor;
       String str3 = localCursor.getString(4);
       localObject1 = localCursor;
       mColumns.put(str1, Integer.valueOf(i));
       localObject1 = localCursor;
       localStringBuilder1.append("'");
       localObject1 = localCursor;
       localStringBuilder1.append(str1);
       localObject1 = localCursor;
       localStringBuilder1.append("'");
       if (str3 == null)
       {
         localObject1 = localCursor;
         localStringBuilder2.append("?");
         localObject1 = localCursor;
         if (i == localCursor.getCount())
         {
           str1 = ") ";
           localObject1 = localCursor;
           localStringBuilder1.append(str1);
           localObject1 = localCursor;
           if (i != localCursor.getCount()) {
             break label335;
           }
           str1 = ");";
           localObject1 = localCursor;
           localStringBuilder2.append(str1);
           i += 1;
         }
       }
       else
       {
         localObject1 = localCursor;
         localStringBuilder2.append("COALESCE(?, ");
         localObject1 = localCursor;
         localStringBuilder2.append(str3);
         localObject1 = localCursor;
         localStringBuilder2.append(")");
         continue;
       }
       str2 = ", ";
     }
     finally
     {
       if (localObject1 != null) {
         ((Cursor)localObject1).close();
       }
     }
     continue;
     label335:
     String str2 = ", ";
   }
   if (localCursor != null) {
     localCursor.close();
   }
   localStringBuilder1.append(localStringBuilder2);
   mInsertSQL = localStringBuilder1.toString();
 }
 public static void cursorFillWindow(Cursor paramCursor, int paramInt, CursorWindow paramCursorWindow)
 {
   if ((paramInt < 0) || (paramInt >= paramCursor.getCount())) {
     return;
   }
   int j = paramCursor.getPosition();
   int k = paramCursor.getColumnCount();
   paramCursorWindow.clear();
   paramCursorWindow.setStartPosition(paramInt);
   paramCursorWindow.setNumColumns(k);
   int i;
   if (paramCursor.moveToPosition(paramInt)) {
     if (paramCursorWindow.allocRow()) {
       i = 0;
     }
   }
   for (;;)
   {
     Object localObject;
     boolean bool;
     if (i < k) {
       switch (paramCursor.getType(i))
       {
       case 3: 
       default: 
         localObject = paramCursor.getString(i);
         if (localObject != null) {
           bool = paramCursorWindow.putString((String)localObject, paramInt, i);
         }
         break;
       }
     }
     for (;;)
     {
       if (bool) {
         break label264;
       }
       paramCursorWindow.freeLastRow();
       paramInt += 1;
       if (paramCursor.moveToNext()) {
         break;
       }
       paramCursor.moveToPosition(j);
       return;
       bool = paramCursorWindow.putNull(paramInt, i);
       continue;
       bool = paramCursorWindow.putLong(paramCursor.getLong(i), paramInt, i);
       continue;
       bool = paramCursorWindow.putDouble(paramCursor.getDouble(i), paramInt, i);
       continue;
       localObject = paramCursor.getBlob(i);
       if (localObject != null)
       {
         bool = paramCursorWindow.putBlob((byte[])localObject, paramInt, i);
       }
       else
       {
         bool = paramCursorWindow.putNull(paramInt, i);
         continue;
         bool = paramCursorWindow.putNull(paramInt, i);
       }
     }
     label264:
     i += 1;
   }
 }
  public static void cursorFillWindow(
      final Cursor cursor, int position, final android.database.CursorWindow window) {
    if (position < 0 || position >= cursor.getCount()) {
      return;
    }
    final int oldPos = cursor.getPosition();
    final int numColumns = cursor.getColumnCount();
    window.clear();
    window.setStartPosition(position);
    window.setNumColumns(numColumns);
    if (cursor.moveToPosition(position)) {
      do {
        if (!window.allocRow()) {
          break;
        }
        for (int i = 0; i < numColumns; i++) {
          final int type = cursor.getType(i);
          final boolean success;
          switch (type) {
            case Cursor.FIELD_TYPE_NULL:
              success = window.putNull(position, i);
              break;

            case Cursor.FIELD_TYPE_INTEGER:
              success = window.putLong(cursor.getLong(i), position, i);
              break;

            case Cursor.FIELD_TYPE_FLOAT:
              success = window.putDouble(cursor.getDouble(i), position, i);
              break;

            case Cursor.FIELD_TYPE_BLOB:
              {
                final byte[] value = cursor.getBlob(i);
                success =
                    value != null
                        ? window.putBlob(value, position, i)
                        : window.putNull(position, i);
                break;
              }

            default: // assume value is convertible to String
            case Cursor.FIELD_TYPE_STRING:
              {
                final String value = cursor.getString(i);
                success =
                    value != null
                        ? window.putString(value, position, i)
                        : window.putNull(position, i);
                break;
              }
          }
          if (!success) {
            window.freeLastRow();
            break;
          }
        }
        position += 1;
      } while (cursor.moveToNext());
    }
    cursor.moveToPosition(oldPos);
  }
Beispiel #13
0
        public void onClick(View v) {
          ContentResolver cr = getContentResolver();
          switch (v.getId()) {
              // 전부 읽기
            case R.id.readall:
              Cursor cursor = cr.query(Uri.parse(WORDURI), null, null, null, null);

              String Result = "";
              while (cursor.moveToNext()) {
                String eng = cursor.getString(0);
                String han = cursor.getString(1);
                Result += (eng + " = " + han + "\n");
              }

              if (Result.length() == 0) {
                mText.setText("Empyt Set");
              } else {
                mText.setText(Result);
              }
              cursor.close();
              break;
              // 하나만 읽기
            case R.id.readone:
              Cursor cursor2 = cr.query(Uri.parse(WORDURI + "/boy"), null, null, null, null);

              String Result2 = "";
              if (cursor2.moveToFirst()) {
                String eng = cursor2.getString(0);
                String han = cursor2.getString(1);
                Result2 += (eng + " = " + han + "\n");
              }

              if (Result2.length() == 0) {
                mText.setText("Empyt Set");
              } else {
                mText.setText(Result2);
              }
              cursor2.close();
              break;
              // 삽입
            case R.id.insert:
              ContentValues row = new ContentValues();
              row.put("eng", "school");
              row.put("han", "학교");

              cr.insert(Uri.parse(WORDURI), row);
              mText.setText("Insert Success");
              break;
              // 삭제
            case R.id.delete:
              cr.delete(Uri.parse(WORDURI), null, null);
              mText.setText("Delete Success");
              break;
              // 수정
            case R.id.update:
              ContentValues row2 = new ContentValues();
              row2.put("han", "핵교");
              cr.update(Uri.parse(WORDURI + "/school"), row2, null, null);
              mText.setText("Update Success");
              break;
          }
        }