use of android.support.annotation.UiThread in project Casty by DroidsOnRoids.
the class Casty method addMediaRouteMenuItem.
/**
* Adds the discovery menu item on a toolbar and creates Introduction Overlay
* Should be used in {@link Activity#onCreateOptionsMenu(Menu)}.
*
* @param menu Menu in which MenuItem should be added
*/
@UiThread
public void addMediaRouteMenuItem(@NonNull Menu menu) {
activity.getMenuInflater().inflate(R.menu.casty_discovery, menu);
setUpMediaRouteMenuItem(menu);
MenuItem menuItem = menu.findItem(R.id.casty_media_route_menu_item);
introductionOverlay = createIntroductionOverlay(menuItem);
}
use of android.support.annotation.UiThread in project Conductor by bluelinelabs.
the class Router method rebindIfNeeded.
/**
* Attaches this Router's existing backstack to its container if one exists.
*/
@UiThread
public void rebindIfNeeded() {
ThreadUtils.ensureMainThread();
Iterator<RouterTransaction> backstackIterator = backstack.reverseIterator();
while (backstackIterator.hasNext()) {
RouterTransaction transaction = backstackIterator.next();
if (transaction.controller.getNeedsAttach()) {
performControllerChange(transaction, null, true, new SimpleSwapChangeHandler(false));
}
}
}
use of android.support.annotation.UiThread in project Conductor by bluelinelabs.
the class Router method setBackstack.
/**
* Sets the backstack, transitioning from the current top controller to the top of the new stack (if different)
* using the passed {@link ControllerChangeHandler}
*
* @param newBackstack The new backstack
* @param changeHandler An optional change handler to be used to handle the root view of transition
*/
@SuppressWarnings("WeakerAccess")
@UiThread
public void setBackstack(@NonNull List<RouterTransaction> newBackstack, @Nullable ControllerChangeHandler changeHandler) {
ThreadUtils.ensureMainThread();
List<RouterTransaction> oldTransactions = getBackstack();
List<RouterTransaction> oldVisibleTransactions = getVisibleTransactions(backstack.iterator());
removeAllExceptVisibleAndUnowned();
ensureOrderedTransactionIndices(newBackstack);
ensureNoDuplicateControllers(newBackstack);
backstack.setBackstack(newBackstack);
List<RouterTransaction> transactionsToBeRemoved = new ArrayList<>();
for (RouterTransaction oldTransaction : oldTransactions) {
boolean contains = false;
for (RouterTransaction newTransaction : newBackstack) {
if (oldTransaction.controller == newTransaction.controller) {
contains = true;
break;
}
}
if (!contains) {
// Inform the controller that it will be destroyed soon
oldTransaction.controller.isBeingDestroyed = true;
transactionsToBeRemoved.add(oldTransaction);
}
}
// Ensure all new controllers have a valid router set
Iterator<RouterTransaction> backstackIterator = backstack.reverseIterator();
while (backstackIterator.hasNext()) {
RouterTransaction transaction = backstackIterator.next();
transaction.onAttachedToRouter();
setControllerRouter(transaction.controller);
}
if (newBackstack.size() > 0) {
List<RouterTransaction> reverseNewBackstack = new ArrayList<>(newBackstack);
Collections.reverse(reverseNewBackstack);
List<RouterTransaction> newVisibleTransactions = getVisibleTransactions(reverseNewBackstack.iterator());
boolean newRootRequiresPush = !(newVisibleTransactions.size() > 0 && oldTransactions.contains(newVisibleTransactions.get(0)));
boolean visibleTransactionsChanged = !backstacksAreEqual(newVisibleTransactions, oldVisibleTransactions);
if (visibleTransactionsChanged) {
RouterTransaction oldRootTransaction = oldVisibleTransactions.size() > 0 ? oldVisibleTransactions.get(0) : null;
RouterTransaction newRootTransaction = newVisibleTransactions.get(0);
// Replace the old root with the new one
if (oldRootTransaction == null || oldRootTransaction.controller != newRootTransaction.controller) {
// Ensure the existing root controller is fully pushed to the view hierarchy
if (oldRootTransaction != null) {
ControllerChangeHandler.completeHandlerImmediately(oldRootTransaction.controller.getInstanceId());
}
performControllerChange(newRootTransaction, oldRootTransaction, newRootRequiresPush, changeHandler);
}
// Remove all visible controllers that were previously on the backstack
for (int i = oldVisibleTransactions.size() - 1; i > 0; i--) {
RouterTransaction transaction = oldVisibleTransactions.get(i);
if (!newVisibleTransactions.contains(transaction)) {
ControllerChangeHandler localHandler = changeHandler != null ? changeHandler.copy() : new SimpleSwapChangeHandler();
localHandler.setForceRemoveViewOnPush(true);
ControllerChangeHandler.completeHandlerImmediately(transaction.controller.getInstanceId());
performControllerChange(null, transaction, newRootRequiresPush, localHandler);
}
}
// Add any new controllers to the backstack
for (int i = 1; i < newVisibleTransactions.size(); i++) {
RouterTransaction transaction = newVisibleTransactions.get(i);
if (!oldVisibleTransactions.contains(transaction)) {
performControllerChange(transaction, newVisibleTransactions.get(i - 1), true, transaction.pushChangeHandler());
}
}
}
} else {
// Remove all visible controllers that were previously on the backstack
for (int i = oldVisibleTransactions.size() - 1; i >= 0; i--) {
RouterTransaction transaction = oldVisibleTransactions.get(i);
ControllerChangeHandler localHandler = changeHandler != null ? changeHandler.copy() : new SimpleSwapChangeHandler();
ControllerChangeHandler.completeHandlerImmediately(transaction.controller.getInstanceId());
performControllerChange(null, transaction, false, localHandler);
}
}
// change handler runs.
for (RouterTransaction removedTransaction : transactionsToBeRemoved) {
removedTransaction.controller.destroy();
}
}
use of android.support.annotation.UiThread in project ChipsLayoutManager by BelooS.
the class TestActivity method initRv.
@UiThread
private void initRv() {
adapter = createAdapter();
RecyclerView.LayoutManager layoutManager = lmFactory.layoutManager(this);
if (layoutManager == null)
Log.e("initRv", "lm manager is null");
rvTest.addItemDecoration(new SpacingItemDecoration(getResources().getDimensionPixelOffset(R.dimen.item_space), getResources().getDimensionPixelOffset(R.dimen.item_space)));
positions = new LinkedList<>();
for (int i = 0; i < items.size(); i++) {
positions.add(String.valueOf(i));
}
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, android.R.id.text1, positions);
ArrayAdapter<String> spinnerAdapterMoveTo = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, android.R.id.text1, positions);
spinnerPosition.setAdapter(spinnerAdapter);
spinnerMoveTo.setAdapter(spinnerAdapterMoveTo);
rvTest.setLayoutManager(layoutManager);
// rvTest.setLayoutManager(new LinearLayoutManager(this));
rvTest.getRecycledViewPool().setMaxRecycledViews(0, 10);
rvTest.getRecycledViewPool().setMaxRecycledViews(1, 10);
rvTest.setAdapter(adapter);
}
use of android.support.annotation.UiThread in project ChipsLayoutManager by BelooS.
the class RTLRowTest method getLayoutManager.
@UiThread
@Override
protected ChipsLayoutManager getLayoutManager() {
ChipsLayoutManager layoutManager = super.getLayoutManager();
if (activityTestRule.getActivity() != null) {
View recyclerView = activityTestRule.getActivity().findViewById(R.id.rvTest);
ViewCompat.setLayoutDirection(recyclerView, ViewCompat.LAYOUT_DIRECTION_RTL);
}
return layoutManager;
}
Aggregations