コード例 #1
0
 @Override
 public void onPause() {
   super.onPause();
   // When the app is paused, stop listening for changes and close the datastore.
   if (mDatastore != null) {
     mDatastore.removeSyncStatusListener(mDatastoreListener);
     mDatastore.close();
     mDatastore = null;
   }
 }
コード例 #2
0
 @Override
 public void onDatastoreStatusChange(DbxDatastore dbxDatastore) {
   if (dbxDatastore.getSyncStatus().hasIncoming) {
     try {
       dbxDatastore.sync();
     } catch (DbxException e) {
       e.printStackTrace();
     }
     updateLevel();
   }
 }
コード例 #3
0
 @Override
 public void onResume() {
   super.onResume();
   // When the app resumes, open the datastore and start listening for changes.
   if (mDatastore == null && mAccountManager.hasLinkedAccount()) {
     try {
       mDatastore = DbxDatastore.openDefault(mAccountManager.getLinkedAccount());
       DbxTable table = mDatastore.getTable("state");
       table.setResolutionRule("level", DbxTable.ResolutionRule.MAX);
       mDatastore.addSyncStatusListener(mDatastoreListener);
       updateLevel();
     } catch (DbxException e) {
       e.printStackTrace();
     }
   }
 }
コード例 #4
0
 DbxRecord getRecord() {
   DbxRecord record = null;
   try {
     // We use getOrInsert to initialize the record to level 0.
     record =
         mDatastore
             .getTable("state")
             .getOrInsert("current_level", new DbxFields().set("level", 0.0));
   } catch (DbxException e) {
     e.printStackTrace();
   }
   return record;
 }