@MediumTest
  public void testCursorUpdate() {
    mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, d INTEGER, s INTEGER);");
    for (int i = 0; i < 20; i++) {
      mDatabase.execSQL("INSERT INTO test (d, s) VALUES (" + i + "," + i % 2 + ");");
    }

    Cursor c = mDatabase.query("test", null, "s = 0", null, null, null, null);
    int dCol = c.getColumnIndexOrThrow("d");
    int sCol = c.getColumnIndexOrThrow("s");

    int count = 0;
    while (c.moveToNext()) {
      assertTrue(c.updateInt(dCol, 3));
      count++;
    }
    assertEquals(10, count);

    assertTrue(c.commitUpdates());

    assertTrue(c.requery());

    count = 0;
    while (c.moveToNext()) {
      assertEquals(3, c.getInt(dCol));
      count++;
    }

    assertEquals(10, count);
    assertTrue(c.moveToFirst());
    assertTrue(c.deleteRow());
    assertEquals(9, c.getCount());
    c.close();
  }
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    switch (item.getItemId()) {
      case 0:
        editTransactionIntent = new Intent(this, EditTransactionActivity.class);
        Log.d(TAG, "id of editTran " + info.id);
        editTransactionIntent.putExtra(AccountData.TRANSACTION_ID, info.id);
        startActivity(editTransactionIntent);
        return true;
      case 1:

        // TODO set Header method
        transactions.deleteTransaction(info.id);
        accountInfo.deactivate();
        accountInfo.requery();
        cursor.deactivate();
        cursor.requery();
        updateBalance();

        return true;
    }
    return false;
  }
  @Override
  public void onResume() {
    // TODO SET Header method
    super.onResume();
    Log.d(TAG, "transactionActivity: onResume");
    accountInfo.requery();
    cursor.requery();

    accountInfo.moveToFirst();
    Log.d(TAG, "" + accountInfo.getColumnCount());
    updateBalance();

    adView.requestFreshAd();
    adView.bringToFront();
  }
Ejemplo n.º 4
0
  public void delete_alarm(int position) {
    Cursor cursor = (Cursor) getListAdapter().getItem(position);

    Intent intent = new Intent(this, AlarmReceiver.class);
    String lecture_id = cursor.getString(4);
    intent.putExtra("lecture_id", lecture_id);
    int day = cursor.getInt(6);
    intent.putExtra("day", day);
    String title = cursor.getString(1);
    intent.putExtra("title", title);
    long startTime = cursor.getLong(5);
    intent.putExtra("startTime", startTime);

    intent.setAction("de.machtnix.fahrplan.ALARM");
    intent.setData(Uri.parse("alarm://" + lecture_id));

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    PendingIntent pendingintent =
        PendingIntent.getBroadcast(this, Integer.parseInt(lecture_id), intent, 0);
    alarmManager.cancel(pendingintent);

    String id = cursor.getString(0);
    db.delete("alarms", "_id = ?", new String[] {id});
    cursor.requery();
    mAdapter.notifyDataSetChanged();
  }
Ejemplo n.º 5
0
  public void onChange(boolean selfChange) {
    cursor.requery();
    cursor.moveToFirst();
    Toast.makeText(context, "Call:" + cursor.getString(6), Toast.LENGTH_SHORT).show();

    Log.i(
        TAG,
        "NewCall "
            + cursor.getString(0)
            + " "
            + cursor.getString(1)
            + " "
            + cursor.getString(2)
            + " "
            + cursor.getString(3)
            + " "
            + cursor.getString(4)
            + " "
            + cursor.getString(5)
            + " "
            + cursor.getString(6)
            + " "
            + cursor.getString(7)
            + " "
            + cursor.getString(8));
  }
Ejemplo n.º 6
0
 @Override
 public void onClick(DialogInterface dialog, int which, boolean isChecked) {
   ListView lv = ((AlertDialog) dialog).getListView();
   Log.d(LOG_TAG, "which = " + which + ", isChecked = " + isChecked);
   db.changeRec(which, isChecked);
   cursor.requery();
 }
Ejemplo n.º 7
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   if (resultCode == RESULT_OK) {
     switch (requestCode) {
       case NEW_ATTRIBUTE_REQUEST:
         {
           long attributeId = data.getLongExtra(AttributeColumns.ID, -1);
           if (attributeId != -1) {
             Attribute a = db.getAttribute(attributeId);
             addAttribute(a);
           }
         }
         break;
       case EDIT_ATTRIBUTE_REQUEST:
         {
           long attributeId = data.getLongExtra(AttributeColumns.ID, -1);
           if (attributeId != -1) {
             Attribute a = db.getAttribute(attributeId);
             attributeCursor.requery();
             updateAttribute(attributesLayout, a);
             updateAttribute(parentAttributesLayout, a);
           }
         }
         break;
     }
   }
 }
  /**
   * @param canvas
   * @param mapView
   * @param shadow
   * @see SegmentOverlay#draw(Canvas, MapView, boolean)
   */
  private void calculateDots() {
    mPathCalculation.reset();
    mDotPathCalculation.clear();

    mCalculatedPoints = 0;

    if (mWaypointsCursor == null) {
      mWaypointsCursor =
          this.mResolver.query(
              this.mWaypointsUri,
              new String[] {
                Waypoints.LATITUDE,
                Waypoints.LONGITUDE,
                Waypoints.SPEED,
                Waypoints.TIME,
                Waypoints.ACCURACY
              },
              null,
              null,
              null);
    }
    if (mRequeryFlag) {
      mWaypointsCursor.requery();
      mRequeryFlag = false;
    }
    if (mProjection != null && mWaypointsCursor.moveToFirst()) {
      GeoPoint geoPoint;

      mStartPoint = extractGeoPoint();
      mPrevGeoPoint = mStartPoint;

      do {
        geoPoint = extractGeoPoint();
        setScreenPoint(geoPoint);

        float distance = (float) distanceInPoints(this.mPrevDrawnScreenPoint, this.mScreenPoint);
        if (distance > MINIMUM_PX_DISTANCE) {
          DotVO dotVO = new DotVO();
          dotVO.x = this.mScreenPoint.x;
          dotVO.y = this.mScreenPoint.y;
          dotVO.speed = mWaypointsCursor.getLong(2);
          dotVO.time = mWaypointsCursor.getLong(3);
          dotVO.radius = mProjection.metersToEquatorPixels(mWaypointsCursor.getFloat(4));
          mDotPathCalculation.add(dotVO);

          this.mPrevDrawnScreenPoint.x = this.mScreenPoint.x;
          this.mPrevDrawnScreenPoint.y = this.mScreenPoint.y;
        }
      } while (moveToNextWayPoint());

      this.mEndPoint = extractGeoPoint();
      DotVO pointVO = new DotVO();
      pointVO.x = this.mScreenPoint.x;
      pointVO.y = this.mScreenPoint.y;
      pointVO.speed = mWaypointsCursor.getLong(2);
      pointVO.time = mWaypointsCursor.getLong(3);
      pointVO.radius = mProjection.metersToEquatorPixels(mWaypointsCursor.getFloat(4));
      mDotPathCalculation.add(pointVO);
    }
  }
Ejemplo n.º 9
0
 @Override
 public void updatePartialSync() {
   stories.requery();
   readingAdapter.notifyDataSetChanged();
   this.enableOverlays();
   checkStoryCount(pager.getCurrentItem());
 }
Ejemplo n.º 10
0
  private void updateButtons() {
    mFinalizedCursor.requery();
    mCompletedCount = mFinalizedCursor.getCount();
    if (mCompletedCount > 0) {
      mSendDataButton.setText(getString(R.string.send_data_button, mCompletedCount));
    } else {
      mSendDataButton.setText(getString(R.string.send_data));
    }

    mSavedCursor.requery();
    mSavedCount = mSavedCursor.getCount();
    if (mSavedCount > 0) {
      mReviewDataButton.setText(getString(R.string.review_data_button, mSavedCount));
    } else {
      mReviewDataButton.setText(getString(R.string.review_data));
    }
  }
Ejemplo n.º 11
0
 @OnClick(R.id.buttonUnique)
 void buttonUniqueClick() {
   Note note = noteDao.queryBuilder().orderAsc(NoteDao.Properties.Id).limit(1).unique();
   Log.d("note  ", note.getComment());
   noteDao.delete(note);
   cursor.requery();
   adapter.notifyDataSetChanged();
 }
Ejemplo n.º 12
0
 @Override
 public void updateAfterSync() {
   setSupportProgressBarIndeterminateVisibility(false);
   stories.requery();
   readingAdapter.notifyDataSetChanged();
   this.enableOverlays();
   checkStoryCount(pager.getCurrentItem());
 }
Ejemplo n.º 13
0
 public static boolean requery(Context context, Cursor cursor) {
   try {
     return cursor.requery();
   } catch (SQLiteException e) {
     Log.e(TAG, "Catch a SQLiteException when requery: ", e);
     checkSQLiteException(context, e);
     return false;
   }
 }
Ejemplo n.º 14
0
  /** Requery the database and update the UI. */
  private void refresh() {
    mDateSortedCursor.requery();
    //		mSizeSortedCursor.requery();

    mSizeSortedAdapter.changeCursor(mSizeSortedCursor);
    //		mDateSortedAdapter.changeCursor(mDateSortedCursor);

    // Adapters get notification of changes and update automatically
  }
Ejemplo n.º 15
0
 public long getItemId(int pos) {
   if (cursor.requery() == true) {
     if (cursor.moveToFirst()) {
       if (cursor.moveToPosition(pos)) {
         return cursor.getLong(cursor.getColumnIndex(PageCol.PAGEID));
       }
     }
   }
   return -1;
 }
Ejemplo n.º 16
0
 public Object getItem(int pos) {
   if (cursor.requery() == true) {
     if (cursor.moveToFirst()) {
       if (cursor.moveToPosition(pos)) {
         return orm.formatPage(cursor);
       }
     }
   }
   return null;
 }
Ejemplo n.º 17
0
 private Cursor getCursor() {
   synchronized (this) {
     if (mCursor == null) return null;
     if (mCursorDeactivated) {
       mCursor.requery();
       mCursorDeactivated = false;
     }
     return mCursor;
   }
 }
Ejemplo n.º 18
0
 public long getItemId(int pos) {
   if (cursor != null && cursor.requery() == true) {
     if (cursor.moveToFirst()) {
       if (cursor.moveToPosition(pos)) {
         return cursor.getLong(cursor.getColumnIndex(FacebookUsersCol.UID));
       }
     }
   }
   return -1;
 }
  @MediumTest
  public void testBlob() throws Exception {
    // create table
    mDatabase.execSQL(
        "CREATE TABLE test (_id INTEGER PRIMARY KEY, s TEXT, d REAL, l INTEGER, b BLOB);");
    // insert blob
    Object[] args = new Object[4];

    byte[] blob = new byte[1000];
    byte value = 99;
    Arrays.fill(blob, value);
    args[3] = blob;

    String s = new String("text");
    args[0] = s;
    Double d = 99.9;
    args[1] = d;
    Long l = (long) 1000;
    args[2] = l;

    String sql = "INSERT INTO test (s, d, l, b) VALUES (?,?,?,?)";
    mDatabase.execSQL(sql, args);
    // use cursor to access blob
    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    c.moveToNext();
    ContentValues cv = new ContentValues();
    DatabaseUtils.cursorRowToContentValues(c, cv);

    int bCol = c.getColumnIndexOrThrow("b");
    int sCol = c.getColumnIndexOrThrow("s");
    int dCol = c.getColumnIndexOrThrow("d");
    int lCol = c.getColumnIndexOrThrow("l");
    byte[] cBlob = c.getBlob(bCol);
    assertTrue(Arrays.equals(blob, cBlob));
    assertEquals(s, c.getString(sCol));
    assertEquals((double) d, c.getDouble(dCol));
    assertEquals((long) l, c.getLong(lCol));

    // new byte[]
    byte[] newblob = new byte[1000];
    value = 98;
    Arrays.fill(blob, value);

    c.updateBlob(bCol, newblob);
    cBlob = c.getBlob(bCol);
    assertTrue(Arrays.equals(newblob, cBlob));

    // commit
    assertTrue(c.commitUpdates());
    assertTrue(c.requery());
    c.moveToNext();
    cBlob = c.getBlob(bCol);
    assertTrue(Arrays.equals(newblob, cBlob));
    c.close();
  }
  private void sendShoppingItem(int pos) {

    boolean sent = false;
    if (mExistingItems != null) {
      mExistingItems.requery();
      mExistingItems.moveToPosition(pos);

      if (mExistingItems.getCount() > 0) {

        mSentItemId = mExistingItems.getString(0);
        String item = mExistingItems.getString(1);
        String tags = mExistingItems.getString(2);

        String quantity = mExistingItems.getString(3);
        int status = mExistingItems.getInt(5);

        Uri boughtUri = Uri.withAppendedPath(Contains.CONTENT_URI, mExistingItems.getString(0));

        Log.v(LOG_TAG, "sending:" + item);
        Log.v(LOG_TAG, "sending uri:" + boughtUri.toString());

        if (!TextUtils.isEmpty(quantity)) {
          item = quantity + " x " + item;
        }

        Log.d(LOG_TAG, "status: [" + status + "]");

        if (status == 1) {
          item = "\u2610 " + item;
        } else {
          //                    item = "\u2611 " + item;
          item = "\u2713 " + item;
        }
        sendItemTextBitmap(mLiveViewAdapter, mPluginId, tags, item);
        sent = true;

        // mJerryService.sendAnnounce(mPluginId, mMenuIcon, quantity
        // + " " + tags, item, System.currentTimeMillis(), boughtUri
        // .toString());
        // mJerryService.sendImage(mPluginId, 1, 1, mMenuIcon);
      }
    }

    if (!sent) {
      sendTextBitmap(mLiveViewAdapter, mPluginId, "no entries");
      mLiveViewAdapter.sendAnnounce(
          mPluginId,
          mMenuIcon,
          getString(R.string.info),
          getString(R.string.no_item),
          System.currentTimeMillis(),
          OPEN_IN_PHONE_ACTION_RETRY);
      mSentItemId = null;
    }
  }
  @MediumTest
  public void testRequeryWithAlteredSelectionArgs() throws Exception {
    /** Test the ability of a subclass of SQLiteCursor to change its query arguments. */
    populateDefaultTable();

    SQLiteDatabase.CursorFactory factory =
        new SQLiteDatabase.CursorFactory() {
          public Cursor newCursor(
              SQLiteDatabase db,
              SQLiteCursorDriver masterQuery,
              String editTable,
              SQLiteQuery query) {
            return new SQLiteCursor(db, masterQuery, editTable, query) {
              @Override
              public boolean requery() {
                setSelectionArguments(new String[] {"2"});
                return super.requery();
              }
            };
          }
        };
    Cursor c =
        mDatabase.rawQueryWithFactory(
            factory, "SELECT data FROM test WHERE _id <= ?", new String[] {"1"}, null);
    assertNotNull(c);
    assertEquals(1, c.getCount());
    assertTrue(c.moveToFirst());
    assertEquals(sString1, c.getString(0));

    // Our hacked requery() changes the query arguments in the cursor.
    c.requery();

    assertEquals(2, c.getCount());
    assertTrue(c.moveToFirst());
    assertEquals(sString1, c.getString(0));
    assertTrue(c.moveToNext());
    assertEquals(sString2, c.getString(0));

    // Test that setting query args on a deactivated cursor also works.
    c.deactivate();
    c.requery();
  }
 @Override
 public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
   // データベースから項目を削除する
   mCursor.moveToPosition(position);
   // この行のID値(カラムの0番目)を取得する
   String rowId = mCursor.getString(0);
   mDB.delete(MyDBHelper.TABLE_NAME, "_id = ?", new String[] {rowId});
   // リストをリフレッシュ
   mCursor.requery();
   mAdapter.notifyDataSetChanged();
 }
Ejemplo n.º 23
0
    public Object getItem(int pos) {
      if (cursor != null && cursor.requery() == true) {
        if (cursor.moveToFirst()) {
          if (cursor.moveToPosition(pos)) {
            return orm.formatSimpleFacebookUser(cursor);
          }
        }
      }

      return null;
    }
  @MediumTest
  public void testRequery() throws Exception {
    populateDefaultTable();

    Cursor c = mDatabase.rawQuery("SELECT * FROM test", null);
    assertNotNull(c);
    assertEquals(3, c.getCount());
    c.deactivate();
    c.requery();
    assertEquals(3, c.getCount());
    c.close();
  }
Ejemplo n.º 25
0
  private void addNote() {

    for (int i = 0; i < 50; i++) {
      final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
      String comment = "Added on " + df.format(new Date());
      Note note = new Note(null, "AA" + i + "" + i + "" + i, comment, new Date());
      noteDao.insert(note);
      Log.d("Dao", "Inserted new note ,Id: " + note.getId());
      cursor.requery();
    }
    adapter.notifyDataSetChanged();
  }
 @Override
 public void onResume() {
   super.onResume();
   mMessageQueueHandler.post(mRefreshSessionsRunnable);
   getActivity()
       .getContentResolver()
       .registerContentObserver(
           ScheduleContract.Sessions.CONTENT_URI, true, mSessionChangesObserver);
   if (mCursor != null) {
     mCursor.requery();
   }
 }
Ejemplo n.º 27
0
    private void addNote() {
        String noteText = editText.getText().toString();
        editText.setText("");

        final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        String comment = "Added on " + df.format(new Date());
        Note note = new Note(null, noteText, comment, new Date());
        noteDao.insert(note);
        Log.d("DaoExample", "Inserted new note, ID: " + note.getId());

        cursor.requery();
    }
Ejemplo n.º 28
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   if (item.getItemId() == CM_DELETE_ID) {
     // получаем из пункта контекстного меню данные по пункту списка
     AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) item.getMenuInfo();
     // извлекаем id записи и удаляем соответствующую запись в БД
     store.delSave(acmi.id);
     // обновляем курсор
     cursor.requery();
     return true;
   }
   return super.onContextItemSelected(item);
 }
  @Override
  public void onClick(View v) {
    // データベースに新しい値を追加する
    ContentValues cv = new ContentValues(2);
    cv.put(MyDBHelper.COL_NAME, mEditText.getText().toString());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    cv.put(MyDBHelper.COL_DATE, sdf.format(new Date()));
    mDB.insert(MyDBHelper.TABLE_NAME, null, cv);

    // リストをリフレッシュ
    mCursor.requery();
    mAdapter.notifyDataSetChanged();
    mEditText.setText(null);
  }
  @MediumTest
  public void testRequeryWithSelectionArgs() throws Exception {
    populateDefaultTable();

    Cursor c = mDatabase.rawQuery("SELECT data FROM test WHERE data = ?", new String[] {sString1});
    assertNotNull(c);
    assertEquals(1, c.getCount());
    assertTrue(c.moveToFirst());
    assertEquals(sString1, c.getString(0));
    c.deactivate();
    c.requery();
    assertEquals(1, c.getCount());
    assertTrue(c.moveToFirst());
    assertEquals(sString1, c.getString(0));
    c.close();
  }