Exemplo n.º 1
0
 /**
  * Stores the current state of the widget.
  *
  * <p>It replaces any stored state for the widget.
  *
  * @param decks an array of {@link DeckStatus} objects, one for each of the know decks.
  */
 public static void storeWidgetStatus(Context context, DeckStatus[] decks) {
   openDBIfClosed(context);
   try {
     mMetaDb.beginTransaction();
     try {
       // First clear all the existing content.
       mMetaDb.execSQL("DELETE FROM widgetStatus");
       for (DeckStatus deck : decks) {
         mMetaDb.execSQL(
             "INSERT INTO widgetStatus(deckId, deckName, newCards, lrnCards, dueCards, progress, eta) "
                 + "VALUES (?, ?, ?, ?, ?, ?, ?)",
             new Object[] {
               deck.mDeckId,
               deck.mDeckName,
               deck.mNewCards,
               deck.mLrnCards,
               deck.mDueCards,
               deck.mProgress,
               deck.mEta
             });
       }
       mMetaDb.setTransactionSuccessful();
     } finally {
       mMetaDb.endTransaction();
     }
   } catch (IllegalStateException e) {
     Timber.e(e, "MetaDB.storeWidgetStatus: failed");
   } catch (SQLiteException e) {
     Timber.e(e, "MetaDB.storeWidgetStatus: failed");
     closeDB();
     Timber.i("MetaDB:: Trying to reset Widget: " + resetWidget(context));
   }
 }
Exemplo n.º 2
0
 public static void storeSmallWidgetStatus(Context context, float[] progress) {
   openDBIfClosed(context);
   try {
     mMetaDb.beginTransaction();
     try {
       // First clear all the existing content.
       mMetaDb.execSQL("DELETE FROM smallWidgetStatus");
       mMetaDb.execSQL(
           "INSERT INTO smallWidgetStatus(progress, left, eta) VALUES (?, ?, ?)",
           new Object[] {(int) (progress[1] * 1000), (int) progress[2], (int) progress[3]});
       mMetaDb.setTransactionSuccessful();
     } finally {
       mMetaDb.endTransaction();
     }
   } catch (IllegalStateException e) {
     Timber.e(e, "MetaDB.storeSmallWidgetStatus: failed");
   } catch (SQLiteException e) {
     Timber.e(e, "MetaDB.storeSmallWidgetStatus: failed");
     closeDB();
     Timber.i("MetaDB:: Trying to reset Widget: " + resetWidget(context));
   }
 }