How to display loading animation when transitioning between fragmens? - android

I am still in fragment, for display new fragment using the code:
CatalogFragment catalogFragment = new CatalogFragment();
var fragmentManager = Activity.SupportFragmentManager.BeginTransaction();
fragmentManager.Replace(Resource.Id.flContent, (SupportFragment)catalogFragment);
fragmentManager.AddToBackStack(null);
fragmentManager.Commit();
How to display loading animation (such as "animated circle" or gif) when transitioning between fragmens?
Sorry for my English.

For animated circle you should put a progress dialog before replacing the fragment. After that you should disable it in new fragment. But fragments can be animated natively. You should checkout this link. https://developer.android.com/training/animation/cardflip.html

Related

Created a Page as LoadingIndicator in Xamarin.forms?

In my application I have created my own Loading indicator with the help of Page class in xamarin.forms, and I use 'PushModalAsync' api to show Loading Indicator wherever needed like below
var loadingindicator=new LoadingIndicator();
MyApp.CurrentAppInstance.MainPage.Navigation.PushModalAsync(loadingindicator,false);
Everything works as expected and It is looking fine and I also managed to make it look like AndHUD by tweeking the alpha for the controls in that page until I hit an issue,
The issue is that, every time I show and hide the loadingindicator page 'OnAppearing()' getting called on the current top page on view stack.
I can fix this by introducing one additional functionality on all pages where I am using my LoadingIndicator, But I feel there might be some other cleaner way to solve this issue.
Can you guys suggest me if there is any cleaner approach available to solve this issue?
(I target this solution mainly for android and I want to achieve it through common code)
If I have understand the problem, I think there are some way to add Loading indicator.
Use ActivityIndicator
Use aritchie/userdialogs's Loading
using (this.Dialogs.Loading("Test Loading"))
await Task.Delay(3000);
Create a PopUp With Rg.Plugins.Popup
// Use these methods in PopupNavigation globally or Navigation in your pages
// Open new PopupPage
Task PushAsync(PopupPage page, bool animate = true) // Navigation.PushPopupAsync
// Hide last PopupPage
Task PopAsync(bool animate = true) // Navigation.PopPopupAsync
// Hide all PopupPage with animations
Task PopAllAsync(bool animate = true) // Navigation.PopAllPopupAsync
// Remove one popup page in stack
Task RemovePageAsync(PopupPage page, bool animate = true) // Navigation.RemovePopupPageAsync

Android fragment `setEnterTransition` doesn't work

I'm trying to animate the showing of a fragment in a very basic way but it doesn't work:
MyFragment myFragment = (MyFragment) getFragmentManager().findFragmentById(R.id.myFragment);
getFragmentManager().beginTransaction()
.hide(myFragment)
.commit();
Slide slideRight = new Slide(Gravity.RIGHT);
slideRight.setDuration(3000);
Slide slideLeft = new Slide(Gravity.LEFT);
slideLeft.setDuration(3000);
myFragment.setEnterTransition(slideRight);
myFragment.setExitTransition(slideLeft);
then later
getFragmentManager().beginTransaction()
.show(myFragment)
.commit();
But fragment just appears without any transition. I can't figure out why it doesn't animate.
Edit:
I ended up using the fragment support library with setCustomAnimations cause the native library doesn't support animation with relative values.
Also using the new API with setEnterTransition doesn't seem to work properly with show/hide and for some unknown reason worked only with replace which doesn't fit my needs.
setCustomAnimation will do the trick.
FragmentManager.beginTransaction()
.replace(R.id.fragment, new Fragment)
.setCustomAnimations(R.anim.slide_out_left, R.anim.slide_in_right).commit();

Use two osmdroid Map Views in one Activity

I want to use two Map Fragments, each with a different fragment, side-by-side in an activity. The left map is planned to show a overview over a specific area, the right one zooms in to a specific point.
The problem I'm having is, that only the first (left) map fragment is being correctly shown, the second (right) one shows a world map:
Zooming is not working on the right map.
Here is a part of the code I'm using:
private void initializeMap()
{
MapTileProviderBasic tileProviderOSM = new MapTileProviderBasic(getApplicationContext());
ITileSource tileSourceOSM = new XYTileSource("OpenFireMap", null, 1, 18, 256, ".png", new String[]{"http://openfiremap.org/hytiles/"});
tileProviderOSM.setTileSource(tileSourceOSM);
TilesOverlay tilesOverlayOSM = new TilesOverlay(tileProviderOSM, this.getBaseContext());
tilesOverlayOSM.setLoadingBackgroundColor(Color.TRANSPARENT);
OsmFragment frag = (OsmFragment) getFragmentManager().findFragmentById(R.id.osmMap);
osmMap = frag.getMap();
osmMap.setMultiTouchControls(true);
osmMap.getOverlays().add(tilesOverlayOSM);
MapTileProviderBasic tileProviderOSMDetail = new MapTileProviderBasic(getApplicationContext());
ITileSource tileSourceOSMDetail = new XYTileSource("OpenFireMap", null, 1, 18, 256, ".png", new String[]{"http://openfiremap.org/hytiles/"});
tileProviderOSMDetail.setTileSource(tileSourceOSMDetail);
TilesOverlay tilesOverlayOSMDetail = new TilesOverlay(tileProviderOSMDetail, this.getBaseContext());
tilesOverlayOSMDetail.setLoadingBackgroundColor(Color.TRANSPARENT);
OsmFragment fragDetail = (OsmFragment) getFragmentManager().findFragmentById(R.id.osmMapDetail);
osmMapDetail = fragDetail.getMap();
osmMapDetail.setMultiTouchControls(true);
osmMapDetail.getOverlays().add(tilesOverlayOSMDetail);
}
If I change either one of the fragments to a GoogleMaps fragment, the osmdroid map loads correctly.
Any ideas why this is happening and how I can fix it? I'm using the newest osmdroid version from gradle (v5.6.4)
Thanks in advance.
EDIT:
I changed the variable declation, but it still doesn't work.
You have to create separate TilesOverlays for different map views. Currently you are using the single overlay in two fragments, this can not work.
So I found the solution. The problem was, that the MapView is within a fragment and the fragment is a custom class which had the hardcoded ID's and layouts in it. The solution which worked for me was duplicating the custom fragment class and editing the ID and Layout. Then in MainActivity I had to change the varaible declaration and the cast from OsmFragment to OsmFragmentDetail
Now both maps are showing the wanted content.

How can I use chenupt/SpringIndicator in Fragment

I want to use it in a v4.Fragment to load childFragment, and the SpringIndicator sample code based on MultipleModel.
I tryed to deliver a ChildFragmentManager to ModelPagerAdapter in Fragment follow this:
ModelPagerAdapter adapter = new ModelPagerAdapter(getChildFragmentManager(), new PagerModelManager());
But that not works, nothing displayed on phone's screen.
Actually,The SpringIndicator will works in a Activity.(use getSupportFragmentManager as the arg)
How can I do?Thank you very much.
Sorry,everyBody.That code in question taked effect but not display beacause of background color.So, You can use SpringIndicator in Fragment to load childFragment with:
ModelPagerAdapter adapter = new ModelPagerAdapter(getChildFragmentManager(), new PagerModelManager());
The first arg is getChildFragmentManager() worked for me.

How Does Navigation in xamarin.forms Works?

As I am using xamarin.forms for my application in android which I have to navigate from one page to another. My question is, if navigating from one page to another page adds it to the navigation stack. For example, If my app has navigation such as Page1 --> Page2 --> Page3 --> Page4 --> Page1 (It behaves like cycle) will it replace Page1 when I navigate to that page on second time or will it be adding it to the stack. Can anyone explain about navigation in a simple way??
EDIT
What I mean by replace means if navigating from one page to another adds it to the stack, Won't it affect the performance of the application if the navigation continues like a loop and keeps on adding it to the stack??
Note: I don't want to go back to previous page, Just want to navigate from one to another continously.
Thanks in advance
Can you try to elaborate on the question a bit more? What do you mean by 'replace'?
It's a stack, so no: the first page1 will not be 'replaced', rather a 'copy' will be in place.
Example:
Imagine a list view with bound data objects. When you click an item, you get to an item details page. Imagine the details page to have previous and next buttons to navigate to other items and you press one. The stack will look like this: ListViewPage -> ItemsPage -> ItemsPage.
What you're talking about is CarouselPage
CarouselPage takes several ContentPage children and allows you to swipe sideways to switch the page.
public class App
{
public static Page GetMainPage ()
{
var carousel = new CarouselPage ();
carousel.Children.Add (new ContentPage () {
Title="One",
Content = new BoxView {
WidthRequest = 90,
HeightRequest = 100,
BackgroundColor = Color.Blue
}
});
carousel.Children.Add (new ContentPage () {
Title="TWO",
Content = new BoxView {
WidthRequest = 90,
HeightRequest = 100,
BackgroundColor = Color.Red
}
});
return carousel;
}
}
Alternatively you can put two buttons (or suitable UI elements) on each page you want to show and use Navigation.PushModalAsync() to navigate to previous/next pages
Using this.Navigation.PopModalAsync () before PushModalAsync did the trick for me.
this.Navigation.PopModalAsync ();
Now my application runs smoothly :)

Categories

Resources