Example #1
0
 private static RemoteViews buildUpdateForNextAccount(
     Context context, int widgetId, int layoutId, Class providerClass, long accountId) {
   DatabaseAdapter db = new DatabaseAdapter(context);
   db.open();
   try {
     MyEntityManager em = db.em();
     Cursor c = em.getAllActiveAccounts();
     try {
       int count = c.getCount();
       if (count > 0) {
         Log.d("FinancistoWidget", "buildUpdateForNextAccount " + widgetId + " -> " + accountId);
         if (count == 1 || accountId == -1) {
           if (c.moveToNext()) {
             Account a = EntityManager.loadFromCursor(c, Account.class);
             return updateWidgetFromAccount(context, widgetId, layoutId, providerClass, a);
           }
         } else {
           boolean found = false;
           while (c.moveToNext()) {
             Account a = EntityManager.loadFromCursor(c, Account.class);
             if (a.id == accountId) {
               found = true;
               Log.d("FinancistoWidget", "buildUpdateForNextAccount found -> " + accountId);
             } else {
               if (found) {
                 Log.d(
                     "FinancistoWidget",
                     "buildUpdateForNextAccount building update for -> " + a.id);
                 return updateWidgetFromAccount(context, widgetId, layoutId, providerClass, a);
               }
             }
           }
           c.moveToFirst();
           Account a = EntityManager.loadFromCursor(c, Account.class);
           Log.d(
               "FinancistoWidget",
               "buildUpdateForNextAccount not found, taking the first one -> " + a.id);
           return updateWidgetFromAccount(context, widgetId, layoutId, providerClass, a);
         }
       }
       return noDataUpdate(context, layoutId);
     } finally {
       c.close();
     }
   } catch (Exception ex) {
     return errorUpdate(context);
   } finally {
     db.close();
   }
 }
Example #2
0
 private static RemoteViews buildUpdateForCurrentAccount(
     Context context, int widgetId, int layoutId, Class providerClass, long accountId) {
   DatabaseAdapter db = new DatabaseAdapter(context);
   db.open();
   try {
     MyEntityManager em = db.em();
     Account a = em.getAccount(accountId);
     if (a != null) {
       Log.d(
           "FinancistoWidget",
           "buildUpdateForCurrentAccount building update for " + widgetId + " -> " + accountId);
       return updateWidgetFromAccount(context, widgetId, layoutId, providerClass, a);
     } else {
       Log.d(
           "FinancistoWidget",
           "buildUpdateForCurrentAccount not found " + widgetId + " -> " + accountId);
       return buildUpdateForNextAccount(context, widgetId, layoutId, providerClass, -1);
     }
   } catch (Exception ex) {
     return errorUpdate(context);
   } finally {
     db.close();
   }
 }