本文整理汇总了Java中com.bottlerocketstudios.groundcontrol.convenience.GroundControl类的典型用法代码示例。如果您正苦于以下问题:Java GroundControl类的具体用法?Java GroundControl怎么用?Java GroundControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GroundControl类属于com.bottlerocketstudios.groundcontrol.convenience包,在下文中一共展示了GroundControl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: favoriteTapped
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
public void favoriteTapped(final LegislatorViewModel legislatorViewModel) {
//Launch a background agent against the repository to remove the favorite legislator.
GroundControl.uiAgent(this, new SetFavoriteLegislatorByBioguideId(mLegislatorRepository, legislatorViewModel.getBioguideId(), false))
.uiCallback(new FunctionalAgentListener<ResponseContainer<Legislator>, Float>() {
@Override
public void onCompletion(String agentIdentifier, ResponseContainer<Legislator> result) {
if (!result.isSuccess()) {
//In the case of failure (favorite was not removed), re-add the legislator.
mLegislatorViewModelList.add(legislatorViewModel);
updateEmptyState();
}
}
})
.execute();
//Preemptively update the UI in anticipation of success. Failure will correct UI state to match domain in the callback above.
mLegislatorViewModelList.remove(legislatorViewModel);
updateEmptyState();
}
示例2: favoriteTapped
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
public void favoriteTapped(final LegislatorViewModel legislatorViewModel) {
final boolean newFavoriteState = !legislatorViewModel.isFavorite();
//Start async operation to update favorite state.
GroundControl.uiAgent(this, new SetFavoriteLegislatorByBioguideId(mLegislatorRepository, legislatorViewModel.getBioguideId(), newFavoriteState))
.uiCallback(new FunctionalAgentListener<ResponseContainer<Legislator>, Float>() {
@Override
public void onCompletion(String agentIdentifier, ResponseContainer<Legislator> result) {
if (result.isSuccess()) {
//Update UI to match domain model.
legislatorViewModel.setFavorite(result.getValue().isFavorite());
} else {
//Roll back the change on failure.
legislatorViewModel.setFavorite(!newFavoriteState);
}
}
})
.execute();
//Preemptively update UI assuming happy path, change is rolled back on failure.
legislatorViewModel.setFavorite(newFavoriteState);
}
示例3: favoriteTapped
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
public void favoriteTapped(final LegislatorViewModel legislatorViewModel) {
//Perform the command based on the state the user clicked i.e. the state of the ViewModel.
final boolean newFavoriteState = !legislatorViewModel.isFavorite();
//Start background operation to change favorite to new state.
GroundControl.uiAgent(this, new SetFavoriteLegislatorByBioguideId(mLegislatorRepository, legislatorViewModel.getBioguideId(), newFavoriteState))
.uiCallback(new FunctionalAgentListener<ResponseContainer<Legislator>, Float>() {
@Override
public void onCompletion(String agentIdentifier, ResponseContainer<Legislator> result) {
if (result.isSuccess()) {
//The operation worked, update the view model. In this case we know what the changed field was.
//In some cases you could just call LegislatorMapper.INSTANCE.updateLegislatorViewModel() and update everything.
legislatorViewModel.setFavorite(result.getValue().isFavorite());
} else {
//Update failed, swap UI back to previous state.
legislatorViewModel.setFavorite(!newFavoriteState);
}
}
})
.execute();
//Assume the update works and update the UI. Async callback will revert the change if it fails.
legislatorViewModel.setFavorite(newFavoriteState);
}
示例4: onCreate
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
//Avoid adding a whole DI framework and all of that just to keep a few objects around.
ServiceInitializer.initializeContext(this);
/**
* Set the default component for DataBinding to use Picasso. This could also be GlideDataBindingComponent();
* If there is an actual need to decide at launch which DataBindingComponent to use, it can be done here.
* Avoid repeatedly calling setDefaultComponent to switch on the fly. It will cause your application
* to behave unpredictably and is not thread safe. If a different DataBindingComponent is needed for a
* specific layout, you can specify that DataBindingComponent when you inflate the layout/setContentView.
*/
DataBindingUtil.setDefaultComponent(new PicassoDataBindingComponent());
/**
* GroundControl's default UI policy will use a built in cache. It isn't necessary and actually
* causes confusion as the Presenters serve this role.
*/
GroundControl.disableCache();
}
示例5: testGroundControlHappyPath
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
public void testGroundControlHappyPath() {
SynchronousAgent synchronousAgent = new SynchronousAgent(TEST_ID_1, EXECUTION_TIME_MS);
final TestUtils.Container<Boolean> testCompleted = new TestUtils.Container<>(false);
GroundControl.agent(synchronousAgent).bgParallelCallback(new FunctionalAgentListener<String, Float>() {
@Override
public void onCompletion(String agentIdentifier, String result) {
testCompleted.setValue(true);
}
}).execute();
long startTime = SystemClock.uptimeMillis();
long deadline = startTime + EXECUTION_TIME_MS + FUDGE_TIME_MS;
while(!testCompleted.getValue() && SystemClock.uptimeMillis() < deadline) {
TestUtils.safeSleep(50);
}
assertTrue("Test was not completed on time gave up after " + String.valueOf(SystemClock.uptimeMillis() - startTime) + "ms", testCompleted.getValue());
}
示例6: runIteration
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
private void runIteration() {
final TestUtils.Container<List<Long>> resultContainer = new TestUtils.Container<>(null);
GroundControl.agent(new MultipleDependencyAgent(NUMBER_OF_TEST_DEPENDENCIES, MAX_CONCURRENT_AGENTS, MIN_CONCURRENT_AGENTS)).bgParallelCallback(new FunctionalAgentListener<List<Long>, Void>() {
@Override
public void onCompletion(String agentIdentifier, List<Long> result) {
resultContainer.setValue(result);
}
}).execute();
TestUtils.blockUntilNotNullOrTimeout(resultContainer, 10, TimeUnit.SECONDS.toMillis(NUMBER_OF_TEST_DEPENDENCIES));
assertNotNull("Container had no value", resultContainer.getValue());
assertEquals("Wrong number of results", NUMBER_OF_TEST_DEPENDENCIES, resultContainer.getValue().size());
for (Long value: resultContainer.getValue()) {
Log.d("DELETEME", "Execution completed at time " + value);
}
}
示例7: startTheLimit
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
private void startTheLimit() {
while (mConcurrentExecutions.get() < mMaximumConcurrentExecutions && mTotalExecutions.get() < mNumberOfTestDependencies) {
mConcurrentExecutions.incrementAndGet();
mTotalExecutions.incrementAndGet();
String tempId = String.format(Locale.US, AGENT_ID_FORMAT, mTotalExecutions.get());
long interval = mRandom.nextInt(INTERVAL_RANGE) * INTERVAL_STEP + MIN_INTERVAL;
SynchronousTimeAgent synchronousTimeAgent = new SynchronousTimeAgent(tempId, interval);
addParallelDependency(GroundControl.agent(synchronousTimeAgent), new FunctionalAgentListener<Long, Float>() {
@Override
public void onCompletion(String agentIdentifier, Long result) {
mTestContainerList.add(result);
if (mConcurrentExecutions.decrementAndGet() < mMinimumConcurrentExecutions) {
startTheLimit();
}
}
});
}
executeDependencies();
}
示例8: testUserWithGroundControl
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
@Test
public void testUserWithGroundControl() throws InterruptedException {
ServiceLocator.put(OkHttpClient.class, OkHttpClientUtil.getOkHttpClient(null, MockBehavior.MOCK));
CountDownLatch latch = new CountDownLatch(1);
TestListener<User> listener = new TestListener<User>() { };
GroundControl.agent(new UserAgent("bottlerocketstudios"))
.bgParallelCallback(listener.withLatch(latch))
.execute();
latch.await(5, TimeUnit.SECONDS);
ResultWrapper<User> wrapper = listener.getResultWrapper();
assertEquals(HttpURLConnection.HTTP_OK, wrapper.getErrorCode());
assertEquals("OK", wrapper.getErrorMessage());
assertEquals("Bottle Rocket Studios", wrapper.getResult().getName());
}
示例9: onContinuityDiscard
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
@Override
public void onContinuityDiscard() {
//Notify GroundControl that we are no longer interested in any ongoing asynchronous work started here.
//We don't even start any async work in this presenter, but it is a good habit and probably belongs in a BasePresenter.
//I stopped short of making a BasePresenter with a base Listener to keep things simple.
GroundControl.onDestroy(this);
}
示例10: testAgent
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
@Test
public void testAgent() {
final ResultContainer<ResponseContainer<List<Legislator>>> testResultContainer = new ResultContainer<>();
GroundControl.agent(new GetLegislatorsByZipAgent(mLegislatorRepository, "75001"))
.bgSerialCallback(new FunctionalAgentListener<ResponseContainer<List<Legislator>>, Float>() {
@Override
public void onCompletion(String agentIdentifier, ResponseContainer<List<Legislator>> result) {
testResultContainer.setResult(result);
}
}).execute();
Assert.assertTrue("Timeout occurred", SafeWait.waitOnContainer(testResultContainer));
Assert.assertTrue("Legislators were not returned", testResultContainer.getResult().getValue().size() > 0);
}
示例11: onStart
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
@Override
protected void onStart() {
super.onStart();
GroundControl.uiAgent(this, new GetLatestLocalProductsAgent(this))
.cacheAgeMs(0)
.uiCallback(mProductAgentListener)
.execute();
}
示例12: run
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
@Override
public void run() {
GroundControl.bgAgent(getAgentExecutor(), new LocationAgent())
.bgParallelCallback(new FunctionalAgentListener<Location, Void>() {
@Override
public void onCompletion(String agentIdentifier, Location result) {
startGeocoding(result);
}
})
.execute();
}
示例13: startGeocoding
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
private void startGeocoding(Location location) {
GroundControl.bgAgent(getAgentExecutor(), new ReverseGeocodeAgent(mContext, location))
.bgParallelCallback(new FunctionalAgentListener<AddressContainer, Void>() {
@Override
public void onCompletion(String agentIdentifier, AddressContainer result) {
getAgentListener().onCompletion(getUniqueIdentifier(), result);
}
})
.execute();
}
示例14: run
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
@Override
public void run() {
GroundControl.bgAgent(getAgentExecutor(), new ConfigurationAgent(mContext))
.bgParallelCallback(new FunctionalAgentListener<Configuration, Void>() {
@Override
public void onCompletion(String agentIdentifier, Configuration result) {
handleConfigurationResult(result);
}
})
.execute();
}
示例15: onContinuityDiscard
import com.bottlerocketstudios.groundcontrol.convenience.GroundControl; //导入依赖的package包/类
@Override
public void onContinuityDiscard() {
//Notify GroundControl that we are no longer interested in any ongoing asynchronous work started here.
GroundControl.onDestroy(this);
}