Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/FragmentHelper.java
Show First 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | public class FragmentHelper { | ||||
/** | /** | ||||
* Attach a new fragment to a cointainer | * Attach a new fragment to a cointainer | ||||
* @param fm the FragmentManager | * @param fm the FragmentManager | ||||
* @param fragment the Fragment | * @param fragment the Fragment | ||||
* @param parameters attach parameters | * @param parameters attach parameters | ||||
*/ | */ | ||||
protected void attachFragmentToContainer(FragmentManager fm,Fragment fragment, AttachParameters parameters){ | protected void attachFragmentToContainer(FragmentManager fm,Fragment fragment, AttachParameters parameters){ | ||||
if(shouldHaltAllActivities) //nothing to do | |||||
return; | |||||
FragmentTransaction ft = fm.beginTransaction(); | FragmentTransaction ft = fm.beginTransaction(); | ||||
int frameID; | int frameID; | ||||
if(parameters.attachToSecondaryFrame && secondaryFrameLayout!=NO_FRAME) | if(parameters.attachToSecondaryFrame && secondaryFrameLayout!=NO_FRAME) | ||||
// ft.replace(secondaryFrameLayout,fragment,tag); | // ft.replace(secondaryFrameLayout,fragment,tag); | ||||
frameID = secondaryFrameLayout; | frameID = secondaryFrameLayout; | ||||
else frameID = primaryFrameLayout; | else frameID = primaryFrameLayout; | ||||
switch (parameters.transaction){ | switch (parameters.transaction){ | ||||
case REPLACE: | case REPLACE: | ||||
ft.replace(frameID,fragment,parameters.tag); | ft.replace(frameID,fragment,parameters.tag); | ||||
} | } | ||||
if (parameters.addToBackStack) | if (parameters.addToBackStack) | ||||
ft.addToBackStack("state_"+parameters.tag); | ft.addToBackStack("state_"+parameters.tag); | ||||
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE); | ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE); | ||||
if(!fm.isDestroyed()) | if(!fm.isDestroyed() && !shouldHaltAllActivities) | ||||
ft.commit(); | ft.commit(); | ||||
//fm.executePendingTransactions(); | //fm.executePendingTransactions(); | ||||
} | } | ||||
public void setBlockAllActivities(boolean shouldI) { | public synchronized void setBlockAllActivities(boolean shouldI) { | ||||
this.shouldHaltAllActivities = shouldI; | this.shouldHaltAllActivities = shouldI; | ||||
} | } | ||||
public void stopLastRequestIfNeeded(){ | public void stopLastRequestIfNeeded(){ | ||||
if(lastTaskRef == null) return; | if(lastTaskRef == null) return; | ||||
AsyncDataDownload task = lastTaskRef.get(); | AsyncDataDownload task = lastTaskRef.get(); | ||||
if(task!=null){ | if(task!=null){ | ||||
task.cancel(true); | task.cancel(false); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Wrapper to show the errors/status that happened | * Wrapper to show the errors/status that happened | ||||
* @param res result from Fetcher | * @param res result from Fetcher | ||||
*/ | */ | ||||
public void showErrorMessage(Fetcher.Result res){ | public void showErrorMessage(Fetcher.Result res){ | ||||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register