Giter VIP home page Giter VIP logo

navigationfragment's Introduction

Navigation Manager Fragment

Slack

Author

Daniel Carmo, [email protected]

Adding the library to your android studio project

In your app build.gradle file add the following to your dependencies. Project only available on jCenter repository.

compile 'com.github.dmcapps:navigation-fragment:2.0.2-alpha'

Current Version

2.0.2-alpha

This version is an alpha. Please send any feedback on the Issue Tracker

Migration

From 1.0.0 to 2.0.0

MAJOR CHANGE:

The package has been changed from

com.dmcapps.navigationfragment 

to

com.github.dmcapps.navigationfragment

I appologize for the inconvenience but it was necessary to get this into maven and out to more possible users.

In order to ease future development. The update to version 2.0.0 has been a major refactor to remove code duplication between the support and non-support version. This will make future implementations and maintanence much easier.

All the present and dismiss methods work as is. In order to perform more advanced functionality (e.g. overriding animations) you will need to call beginPresentation() first and string together the builder patter items to perform the required tasks.

Presenting a fragment

// Basic Presenting has not changed. Just call:
presentFragment(Fragment);
// as well as 
presentFramgent(Fragment, Bundle);

// The biggest change is adding additional options to your presentation. In order to present with a bundle or override animations you would do that as follows:
// 1.0.0 
overrideNextAnimation(int, int);
presentFragment(Fragment, Bundle);

// 2.0.0
// Animations must now be set before presentation. They cannot be overriden at dismiss time.
// Presenting a fragment now has additional options and is done through a builder style.
beginPresentation().setCustomAnimations(int, int, int, int)
    .setNavBundle(Bundle)
    .presentFragment(Fragment);

Dismissing a Fragment

// This have not changed. Just call:
dismissFragment();
// OR
dismissFragment(Bundle);
// From within your fragment

// NOTE: animations must all be set at presentation time now and cannot be overridden before a dismiss.

Trasitions

This implementation of the NavigationManager include support for transitions (API 21 and above). See the Transtions example in the v17 project. At this point I have only added the shared element portion as that is all that is required in the transaction. The rest can be set up in the fragments themselves. (FUTURE implementation will do this all in the transaction once set up as well as allow for default implementations much like the )

NavigationFragment fragment = LargeImageFragment.newInstance();
PresentationTransaction transaction = beginPresentation();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    setExitTransition(new Slide(Gravity.START));
    setEnterTransition(new Slide(Gravity.START));

    fragment.setSharedElementEnterTransition(new DetailTransition());
    fragment.setSharedElementReturnTransition(new DetailTransition());

    fragment.setEnterTransition(new Slide(Gravity.END));

    transaction.addSharedElement(smallImageView, "trans_largeImageView");
}
transaction.presentFragment(fragment);

Items Removed:

MasterDetail implementation (this was created as something that I needed for a project. I've removed it so remove excess coding when adding to the interface declaration) ListFragment implementation (this is not needed with the recycler view being widely accepted and used and it's been around so long)

Introduction

The purpose of this manager is to handle a single stack flow of fragments on the screen so that the developer can easily create flows without having to worry about using the FragmentManager and ChildFragmentManager. The single instance of the NavigationManagerFragment will easily handle the presenting and dismissing of Fragments as they are created and added or removed from the stack.

Every Fragment in the Navigation Stack must extend NavigationFragment in order to properly be displayed and navigated. Every NavigationFragment will have access to the NavigationManagerFragment in order to push and pop Fragments from the stack. Further details below will explain how to use the functionality provided by this Manager.

Implementation

The Stack Fragment Manager

Use the Stack Fragment Manager just like a normal fragment. In your activity, add it to the manager with an initial fragment and you are ready to use the Navigation Manager.

public class SingleStackNavigationExampleActivity extends AppCompatActivity {

    private static final String STATE_NAV_TAG = "NAV_TAG";

    private String mStackNavigationManagerFragmentTag;

    // ... 

    // In the activity, create the stack manager fragment and add it to the screen with the initial fragment.
    StackNavigationManagerFragment navManager = StackNavigationManagerFragment.newInstance(SampleFragment.newInstance("Root Fragment in the Stack", 0));

    mStackNavigationManagerFragmentTag = UUID.randomUUID().toString();

    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.add(android.R.id.content, navManager, mStackNavigationManagerFragmentTag);
    ft.commit();

    // Rest of your code.

Now from within your Fragments you can easily present and dismiss fragments using. All fragments that you would like to manager using the NavigationManager must extend NavigationFragment.

Navigation fragmentToPresent = SampleFragment.newInstance("Fragment added to Stack.", (mFragCount + 1));
presentFragment(fragmentToPresent);

Here is an example of the SampleFragment

// You Fragments must extend from NavigationFragment to have access to the helpers and Navigation Manager.
public class SampleFragment extends NavigationFragment {
    
    // ...
    // To perform basic presentations:
    Navigation fragmentToPresent = SampleFragment.newInstance("Fragment added to Stack.", (mFragCount + 1));
    presentFragment(fragmentToPresent);

    // For more advanced presentations use:
    beginPresentation()
        .setCustomAnimations(R.anim.slide_in_from_bottom, R.anim.slide_out_to_top, R.anim.slide_out_to_bottom, R.anim.slide_in_from_top)
        .presentFragment(fragmentToPresent);

    // To dismiss the current fragment call
    dismissFragment();

    // ... Rest of class
}

Upcoming Plans

See TODO

Change Log

2.0.2

  • Updated version for uploading to bintray

2.0.1

  • Added in missed default animation override in the non-support navigation manager

2.0.0

  • Package updated from com.dmcapps.navigationfragment to com.github.dmcapps.navigationfragment this is to prepare for the release to maven.
  • Added in Transition support
  • Removed default animations. I shouldn't be overriding the default implementation of android fragment navigation. Instead the programmer of the library should call NavigationManager.setDefaultPresentAnimations(int animIn, int animOut) and NavigationManager.setDefaultDismissAnimations(int animIn, int animOut) NOTE: If you would like to add them back in just call NavigationManager.setDefaultPresentAnim(int, int) and setDefaultDismissAnim(int, int) with your animations. The animations are still available under the dmcapp R file as well.
  • Major code refactoring to reduce duplicate implementations across support and non-support versions
  • Refactored code for future expandability for adding other paramters to each presentation

1.0.0

  • Added in non support fragment manager Git issue 1
  • Updated package names
  • Added in interfaces for all the micromanagers
  • Removed the RetainedChildFragmentManager requirements as the newest version of the support library fixes this

0.3.1

  • Marked the INavigationManager properties in the ManagerConfig as Transient per Git issue 26

0.3.0

  • Remove Serializable requirement from all classes. There is no need for it anymore and the Navigation Fragment shouldn't make that decision.
  • Updated the method for animations. Depreciated helper methods for present/dismiss that take in animIn and animOut values. Favoring setting the animation using overrideNextAnimation(int, int) much like the fragment manager does it. This is so that we can keep the method signature for preset/dismiss down now that we are adding in the bundle as well.
  • Fixed Git issue 6. You can now present and dismiss with a bundle attached using presentFragment(INavigationFragment fragment, Bundle bundle); and dimissFragment(Bundle bundle);. Bundle is retreived in the Dismissed/Presented Fragment using Bundle bundle = getNavBundle();

NOTE: The present and dismiss share the same bundle and hence setting a bundle on present/dismiss will override the current nav bundle for the specific fragment that is presented or the fragment that is returned to on dismiss.

See CHANGELOG for past implementation notes and current in progress items.

In Android Studio Terminal use:

./gradlew install

./gradlew bintrayUpload

License

Copyright (c) 2016 DMCApps MIT License

navigationfragment's People

Contributors

dman654 avatar dmcapps avatar jjhesk avatar ravidsrk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

navigationfragment's Issues

api or callback for the feature.

what is callback or api for retrieve the previous fragment title? in case im using it for custom api for renaming the actionbar for the custom actionbar. I hope that there is a listen callback from SingleStackNavigationManagerFragment

Issue with getActivity() and mHost not updating in Child Fragments on rotation

Noticed that when we rotate the device, the memory space of the returned Activity from getActivity() in any child fragment always returns the old reference. The mHost within the Activity also isn't updating to the new host.

I'm reporting this issue so that I can link it in the code of where to test for the fix. I was able to get around this with a little help from here https://code.google.com/p/android/issues/detail?id=74222#c45

I have implemented this and will release in the update tonight after some more testing. Please update to version 0.1.3.1 as this is a major bug and fix when trying to use the action bar in any way within a child fragment after a rotation.

On Permission state change and resume it force close app

I am facing very big issue in marshmallow, when i am going to change any permission state, and resume that app, it will force close by this error,
do you please help me to resolve it.

> E/AndroidRuntime: FATAL EXCEPTION: main
> Process: com.sa_projects, PID: 31201
> java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sa_projects/com.sa_projects.activity.NavigationDrawerActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.dmcapps.navigationfragment.manager.SingleStackNavigationManagerFragment: make sure class name exists, is public, and has an empty constructor that is public
>    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
>    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
>    at android.app.ActivityThread.-wrap11(ActivityThread.java)
>    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
>    at android.os.Handler.dispatchMessage(Handler.java:102)
>    at android.os.Looper.loop(Looper.java:148)
>    at android.app.ActivityThread.main(ActivityThread.java:5417)
>    at java.lang.reflect.Method.invoke(Native Method)
>    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
>    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
> Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.dmcapps.navigationfragment.manager.SingleStackNavigationManagerFragment: make sure class name exists, is public, and has an empty constructor that is public
>    at android.support.v4.app.Fragment.instantiate(Fragment.java:431)
>    at android.support.v4.app.FragmentState.instantiate(Fragment.java:102)
>    at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1952)
>    at android.support.v4.app.FragmentController.restoreAllState(FragmentController.java:144)
>    at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:307)
>    at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:81)
>    at com.sa_projects.activity.base.BaseNavigationDrawerActivity.onCreate(BaseNavigationDrawerActivity.java:80)
>    at com.sa_projects.activity.NavigationDrawerActivity.onCreate(NavigationDrawerActivity.java:56)
>    at android.app.Activity.performCreate(Activity.java:6237)
>    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
>    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
>    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
>    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
>    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
>    at android.os.Handler.dispatchMessage(Handler.java:102) 
>    at android.os.Looper.loop(Looper.java:148) 
>    at android.app.ActivityThread.main(ActivityThread.java:5417) 
>    at java.lang.reflect.Method.invoke(Native Method) 
>    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
>    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
> Caused by: java.lang.InstantiationException: java.lang.Class<com.dmcapps.navigationfragment.manager.SingleStackNavigationManagerFragment> has no zero argument constructor
>    at java.lang.Class.newInstance(Native Method)
>    at android.support.v4.app.Fragment.instantiate(Fragment.java:420)
>    at android.support.v4.app.FragmentState.instantiate(Fragment.java:102) 
>    at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1952) 
>    at android.support.v4.app.FragmentController.restoreAllState(FragmentController.java:144) 
>    at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:307) 
>    at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:81) 
>    at com.sa_projects.activity.base.BaseNavigationDrawerActivity.onCreate(BaseNavigationDrawerActivity.java:80) 
>    at com.sa_projects.activity.NavigationDrawerActivity.onCreate(NavigationDrawerActivity.java:56) 
>    at android.app.Activity.performCreate(Activity.java:6237) 
>    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
>    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
>    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
>    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
>    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
>    at android.os.Handler.dispatchMessage(Handler.java:102) 
>    at android.os.Looper.loop(Looper.java:148) 
>    at android.app.ActivityThread.main(ActivityThread.java:5417) 
>    at java.lang.reflect.Method.invoke(Native Method) 
>    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
>    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
> 

does it support switching between Fragment and NavigationFragment

good work! There is an issue happened from switching between Fragment and NavigationFragment. I was running my code like so

 /**
     * require android-support-v4 import and the regular android fragment
     *
     * @param fragment    the unknown typed fragment
     * @param title       the string in title
     * @param oldFragment the previous fragment
     * @param closeDrawer if it needs to close the drawer after the new fragment has been rendered
     */
    public void setFragment(F fragment, String title, @Nullable F oldFragment, boolean closeDrawer) {
        currentFragmentNow = fragment;
        setTitle(title);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            // before honeycomb there is not android.app.Fragment
            android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            if (oldFragment != null && oldFragment != fragment)
                ft.remove((android.support.v4.app.Fragment) oldFragment);

            ft.replace(targetHomeFrame(), (android.support.v4.app.Fragment) fragment).commit();
        } else if (fragment instanceof android.app.Fragment) {
            if (oldFragment instanceof android.support.v4.app.Fragment)
                throw new RuntimeException("You should use only one type of Fragment");

            android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
            if (oldFragment != null && fragment != oldFragment)
                ft.remove((android.app.Fragment) oldFragment);

            ft.replace(targetHomeFrame(), (android.app.Fragment) fragment).commit();
        } else if (fragment instanceof android.support.v4.app.Fragment) {
            if (oldFragment instanceof android.app.Fragment)
                throw new RuntimeException("You should use only one type of Fragment");

            android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            if (oldFragment != null && oldFragment != fragment)
                ft.remove((android.support.v4.app.Fragment) oldFragment);
            ft.replace(targetHomeFrame(), (android.support.v4.app.Fragment) fragment).commit();
        } else
            throw new RuntimeException("Fragment must be android.app.Fragment or android.support.v4.app.Fragment");

        //if (closeDrawer)
        // getSlidingMenu().toggle(true);

        notifyOnBodyFragmentChange(currentFragmentNow);
    }


  public void initialNavigationFragmentManager(F firstFragment, @Nullable String title) {
        if (title != null) {
            setTitle(title);
        }
        if (firstFragment instanceof NavigationFragment) {
            SingleStackNavigationManagerFragment navManager = SingleStackNavigationManagerFragment.newInstance((NavigationFragment) firstFragment);
            mSingleStackNavigationManagerFragmentTag = UUID.randomUUID().toString();
            android.support.v4.app.FragmentTransaction fm = getSupportFragmentManager().beginTransaction();
            currentFragmentNow = firstFragment;
            fm.replace(targetHomeFrame(), navManager, mSingleStackNavigationManagerFragmentTag);
            fm.commit();
        } else if (firstFragment instanceof android.support.v4.app.Fragment) {
            setFragment(firstFragment, title);
        } else if (firstFragment instanceof Fragment) {
            setFragment(firstFragment, title);
        } else
            throw new RuntimeException("Fragment must be NavigationFragment");

    }

at the end it doesnt seems to support switching between fragment and the navigationfragment at the same framelayout.

suggest better ways to handle presenting/dismissing

Thank you for your dedication and talent to tackle those issues for the library. I am proud of you! Here is another question. Do you have any planning for bringing input or data bundle into presenting/dismissing? I think this is a very important feature for the real world cases. The most common fashion to implement that would be using Bundle to parcel the needed data into the bundle object and past along with the fragment to be initiated for presenting.
Maybe start thinking about this with a list of possible calls for your INavigationFragment where i have found in your library section

void presenting(fragment, bundle, animation in, animation out)
void presenting(fragment, bundle)
void presenting(fragment)
void presenting(fragment, animation in, animation out)

void dismissFragment();
void dismissFragment(bundle);
void dismissFragment(bundle, int animationIn, int animationOut);
void dismissFragment(int animationIn, int animationOut);

When inside the INavigationFragment we can call getNavigationFragmentBundle from presenting or dismissing. thus we can trigger this call at onResume when the dismissed fragment bring back to the previous fragment. I think we need to plan it out more precisely for the naming to handle nested fragment routing handling. I dont mean to using another library to bring assistance for cross instance even handling but it would definitely help. I dont recommend calling another library because there is always a catch from the versioning issue or cause big confusion for unfriendly coding experience. But here we can take check that out for getting some ideas of how to handle the similar issue popular page or I have done this with other projects otto. It is a plus with the object passing support.

This feature maybe not be the most important thing to add but I would like to vote on this for later update! Thank you~

new bug on nextAnim

This is found from the MotoG3 machine

DEVICE
MotoG3
DEVICE
Portrait
ORIENTATION
Off
PROXIMITY
N/A
BATTERY
OPERATING SYSTEM
6.0
ANDROID VERSION
No
ROOTED
Portrait
UI ORIENTATION

@DMCApps

Fatal Exception: java.lang.NullPointerException: Attempt to write to field 'int android.support.v4.app.Fragment.mNextAnim' on a null object reference
       at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:726)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
       at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
       at android.os.Handler.handleCallback(Handler.java:746)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5443)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

access the top level or any level of navigation remotely

Thank you so much on your amazing code! Now I have an real world situation to deal with and I cant get to anywhere for this problem. Please let me know if i have explain it correctly. There is the main activity. this activity has one Framelayout and it initialized a navigation fragment (A) by using SingleStackNavigationManagerFragment. In the (A) I got it initialized a viewpager which carries 3 navigationfragments B, C, and D. There is a button E attached in the B.

What is the solution for me to click on button E and it navigate to a new navigation fragment on the (A) navigation level? assume i can use another method to call the superLevelPresent but I have no tag or nothing to indicator which one is the parent. I am sure there are alot of conflicts over the back buttons and other things. i start thinking if that is the case, would it better to add configuration policy for the SingleStackNavigationManagerFragment to receive events or clicks coming from the child navigation fragment or just fragment. I think this is far important to configure out before implement other small features. A huge thank you to your amazing work.

Fragment is Visiblity gone when it go in pause mode

I have try to open one dialog, when dialog is open fragment visibility is gone, why it happens ? once i will back from resume is work fine, but it reset all UI and Some Background task also.

Do you please help me to fix this isssue

childfragment manager are used for viewpager results crashes and unstable

First of all, thank you for the amazing work. Here I got another challenge from the crashes on using v0.0.4. I have an example that the childfragment manager inside the fragment is used for supply the works for mutifragment holder such as ViewPager and SmartTabLayout. In this case I got all other things flashing in the page. what can i do to make it work?

Noticed that I set pager.setOffscreenPageLimit(0); because i need to constraint memory for another activities. In this layout I had to init a viewpager for display use return new FragmentPagerItemAdapter(getFragmentManager(), itemCreator.create()); or using return new FragmentPagerItemAdapter(getChildFragmentManager(), itemCreator.create()); this adapter is weakReference to holding all the config for the viewpager private final SparseArrayCompat<WeakReference<Fragment>> holder; into the SparseArrayCompatthis.holder = new SparseArrayCompat<>(pages.size());

resulted IOexecption:
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name =

package com.hkm.hbstore.pages.homePage;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;

import com.dmcapps.navigationfragment.fragments.NavigationFragment;
import com.hkm.hbstore.R;
import com.hkm.hbstore.life.event.EBus;
import com.hkm.hbstore.life.event.ResponsiveBaring;
import com.hkm.hbstore.life.tB;
import com.hkm.hbstore.pages.testpage;
import com.hkm.layout.Module.Utils;
import com.hypebeast.sdk.api.model.symfony.Config;
import com.hypebeast.sdk.api.model.symfony.NavigationItem;
import com.hypebeast.sdk.application.hbx.ConfigurationSync;
import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;
import com.squareup.otto.Subscribe;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created by hesk on 22/12/15.
 */
@TargetApi(Build.VERSION_CODES.M)
public class main_three_tabs extends NavigationFragment
        implements
        View.OnScrollChangeListener,
        View.OnAttachStateChangeListener {

    private SmartTabLayout mTab;
    private ViewPager pager;
    private FragmentManager mChildFragmentManager;
    private int toolBarHeight, customBarHeight;
    //  private boolean remote_event_to_show, remote_event_to_force_hide;
    private ArrayList<String> tab_list = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.content_puzzle_v2, container, false);
    }


    @SuppressLint("ResourceAsColor")
    @TargetApi(Build.VERSION_CODES.M)
    @Override
    public void onViewCreated(View v, Bundle b) {
        mTab = (SmartTabLayout) v.findViewById(R.id.feature_puzzle_smarttab);
        pager = (ViewPager) v.findViewById(R.id.feature_puzzle_viewpager);
        pager.setAdapter(getAdapter());
        pager.setOffscreenPageLimit(0);
        pager.setOnScrollChangeListener(this);
        mTab.setViewPager(pager);
        mTab.addOnAttachStateChangeListener(this);
        toolBarHeight = Utils.getToolbarHeight(getActivity());
        customBarHeight = Utils.getTabsHeight(getActivity());
    }


    public FragmentPagerItemAdapter getAdapter() {
        final FragmentPagerItems.Creator itemCreator = FragmentPagerItems.with(getActivity());
        try {
            final Config overhead_data = ConfigurationSync.getInstance().getFoundation().data;
            tab_list.clear();
            if (overhead_data.navigation.size() > 0) {
                final Iterator<NavigationItem> nk = overhead_data.navigation.iterator();
                while (nk.hasNext()) {
                    final NavigationItem g = nk.next();
                    if (g.name.equalsIgnoreCase("Featured")) {
                        itemCreator.add(tB.home.getStringId(), tB.home.getClazz());
                    } else {
                       /* itemCreator.add(
                                g.name,
                                template_product_display.class,
                                template_product_display.con_general(g.link)
                        );*/
                        itemCreator.add(g.name, testpage.class);
                        tab_list.add(g.link);
                    }
                }
            }
        } catch (Exception e) {
        }
        return new FragmentPagerItemAdapter(getFragmentManager(), itemCreator.create());
    }

    @Override
    public void onStop() {
        super.onStop();
        EBus.getInstance().unregister(this);
    }

    @Override
    public void onStart() {
        super.onStart();
        EBus.getInstance().register(this);
    }


    @Subscribe
    public void onEvent(ResponsiveBaring.ScrollOnMove scroll) {
        if (scroll.isActionMove()) {
            mTab.setTranslationY(-scroll.getDistance() + toolBarHeight);
        }
        if (scroll.isActionShow()) {
            mTab.animate().translationY(toolBarHeight).setInterpolator(new DecelerateInterpolator(2)).start();
        }
        if (scroll.isActionHide()) {
            mTab.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
        }
    }

    boolean isFirstTab = true;

    @Override
    public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

        final int tab_width = 1080;
        if (scrollX < tab_width) {
            final int move = (tab_width - scrollX) / tab_width * toolBarHeight;
            if (!isFirstTab) {
                EBus.getInstance().post(new ResponsiveBaring.ScrollOnMove(ResponsiveBaring.ScrollOnMove.SHOW));
            }
            Log.d("smtab", move + " int");
            isFirstTab = true;
        } else {
            if (isFirstTab) {
                EBus.getInstance().post(new ResponsiveBaring.ScrollOnMove(ResponsiveBaring.ScrollOnMove.HIDE));
            }
            isFirstTab = false;
        }

    }

    @Override
    public void onViewAttachedToWindow(View v) {
        Log.d("smtab", "in");
        Log.d("smtab", v.getId() + ":" + v.toString());
    }

    @Override
    public void onViewDetachedFromWindow(View v) {
        Log.d("smtab", "out");
        Log.d("smtab", v.getId() + ":" + v.toString());
    }
}

not able to handle restorestate

This has been consistently triggered.

 java.lang.RuntimeException: Unable to start activity ComponentInfo{n18.a0.x5.debug.debug/hx520.hxhx.main.MainTabNew}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.dmcapps.navigationfragment.manager.SingleStackNavigationManagerFragment: make sure class name exists, is public, and has an empty constructor that is public

reproducing it:

  1. goto developer settings and turn on DONT KEEP ACTIVITY.
  2. trigger stateloss by minimizing it or open other apps.
  3. reopen this app.

resurface on:

  • 0.2.0.2
  • 0.2.0.1

StackManager.popFragment() Implementation Causing Back Button Issue

When the navigationFragment.dismissFragment() is called at the root stack, can I prevent it from calling getActivity().onBackPressed()?
It is related to cases that we will pop the fragment when the app fails to load data from server, and it is causing issue of exiting the app if the dismissFragment() call is triggered at the root.

animation overriding with xml stylings

If you let me to adding PR to your lib I will like to add default animation in/out for presenting and dismissing on the navigationfragment so that it doesnt need to explicitly call out at using the methos presenting and dismissing fragment. put that on the check box for later development as this is not important.

  • assign default animation by using style xml.

onMeasure() issue

Followed by #10. When the animation for the transition from navigation fragment A to B will constantly trigger the mehod onMeasure inside the SwipeRefreshLayout until it stop. And this happens when the previous navigation fragment contains SwipeRefreshLayout in the page. This will happen in both type of fragments navigationfragment or the singlestackfragmentmangerfragment. I will have to reproduce this issue exactly on the fork. Is there a way to cancel the animation for all the navigationfragments and try again?

Behavioral Difference for NavigationFragment 1.0.0 vs 2.0.2-alpha

I've spotted lifecycle behavioral differences for NavigationFragment 1.0.0 vs 2.0.2-alpha

On Fragments inherited NavigationFragment with 1.0.0 version, presenting another fragment will result in first fragment calling onPause() and onStop()
Whereas on 2.0.2-alpha, the onPause() method is not called. In addition, content for previous fragment is not cleared out.

My question is:
Is this expected, and how can I get the behavior of v1.0.0? (i.e. NavigationFragment calling onPause() and onStop() methods on presenting another NavigationFragment)?

attempted to write mNextAnim with nullpointerexception

There was a null pointer exception pops out from the system while i compile this library at the start.
baconlmy48yhesk02262016170032

which i cannot tell where it was coming from basically it was the last lines of code before it happens.

    /**
     * require android-support-v4 import and the regular android fragment
     *
     * @param fragment    the unknown typed fragment
     * @param title       the string in title
     * @param oldFragment the previous fragment
     * @param closeDrawer if it needs to close the drawer after the new fragment has been rendered
     */
    public void setFragment(F fragment, String title, @Nullable F oldFragment, boolean closeDrawer) {
        currentFragmentNow = fragment;
        setTitle(title);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            // before honeycomb there is not android.app.Fragment
            android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            if (oldFragment != null && oldFragment != fragment)
                ft.remove((android.support.v4.app.Fragment) oldFragment);

            ft.replace(targetHomeFrame(), (android.support.v4.app.Fragment) fragment).commit();
        } else if (fragment instanceof android.app.Fragment) {
            if (oldFragment instanceof android.support.v4.app.Fragment)
                throw new RuntimeException("You should use only one type of Fragment");

            android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
            if (oldFragment != null && fragment != oldFragment)
                ft.remove((android.app.Fragment) oldFragment);

            ft.replace(targetHomeFrame(), (android.app.Fragment) fragment).commit();
        } else if (fragment instanceof android.support.v4.app.Fragment) {
            if (oldFragment instanceof android.app.Fragment)
                throw new RuntimeException("You should use only one type of Fragment");

            android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            if (oldFragment != null && oldFragment != fragment)
                ft.remove((android.support.v4.app.Fragment) oldFragment);
            ft.replace(targetHomeFrame(), (android.support.v4.app.Fragment) fragment).commit();
        } else
            throw new RuntimeException("Fragment must be android.app.Fragment or android.support.v4.app.Fragment");

        //if (closeDrawer)
        // getSlidingMenu().toggle(true);

        notifyOnBodyFragmentChange(currentFragmentNow);
    }

the issue triggers at ft.replace(targetHomeFrame(), (android.support.v4.app.Fragment) fragment).commit(); but it was not constantly happening.

gradle 1.5

would you use classpath 'com.android.tools.build:gradle:1.5.0' instead of 1.3.0 ?

implement setnavigationmanager

i have noticed that the setnavigationmanager has been removed.

 @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Object item = super.instantiateItem(container, position);
        if (item instanceof NavigationFragment) {
            NavigationFragment nav = (NavigationFragment) item;
            nav.setNavigationManager(nmf);
        }
        return item;
    }

what do i need to do to fix it for the new version 0.2.0.3. As you have mentioned

No longer a need for the setNavigationManager(NavigationManagerFragment) method. The NavigationFragmentManager is now smart enough to look at it's parent (or parent's parent, etc.) until it finds a NavigationManagerFragment to use.

I still dont get it..

fragment was instantiated too soon in the transactions

I have noticed that in some situation when i start using navigationfragment it will trigger onMeasure too soon that caused crash from the initiation. However this bug is not constantly happening and that will occurs randomly. do you think it has anything to relate to this? I am trying to reproduce it and capture more information for this.

I captured onMeasure() illegalstate exception like so:

baconlmy48yhesk02262016112421

baconlmy48yhesk02262016112445

Currently there is an Fragment Adapter using like so:

package com.ogaclejapan.smarttablayout.utils.v4;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.util.SparseArrayCompat;
import android.view.ViewGroup;

import java.lang.ref.WeakReference;

public class FragmentPagerItemAdapter extends FragmentPagerAdapter {

  private final FragmentPagerItems pages;
  private final SparseArrayCompat<WeakReference<Fragment>> holder;

  public FragmentPagerItemAdapter(FragmentManager fm, FragmentPagerItems pages) {
    super(fm);
    this.pages = pages;
    this.holder = new SparseArrayCompat<>(pages.size());
  }

  @Override
  public int getCount() {
    return pages.size();
  }

  @Override
  public Fragment getItem(int position) {
    return getPagerItem(position).instantiate(pages.getContext(), position);
  }

  @Override
  public Object instantiateItem(ViewGroup container, int position) {
    Object item = super.instantiateItem(container, position);
    if (item instanceof Fragment) {
      holder.put(position, new WeakReference<Fragment>((Fragment) item));
    }
    return item;
  }

  @Override
  public void destroyItem(ViewGroup container, int position, Object object) {
    holder.remove(position);
    super.destroyItem(container, position, object);
  }

  @Override
  public CharSequence getPageTitle(int position) {
    return getPagerItem(position).getTitle();
  }

  @Override
  public float getPageWidth(int position) {
    return super.getPageWidth(position);
  }

  public Fragment getPage(int position) {
    final WeakReference<Fragment> weakRefItem = holder.get(position);
    return (weakRefItem != null) ? weakRefItem.get() : null;
  }

  protected FragmentPagerItem getPagerItem(int position) {
    return pages.get(position);
  }

}

ManagerConfig causes NotSerializableException

In NavigationManagerFragment.onSaveInstanceState(bundle) method, the outState.putSerializable(KEY_MANAGER_CONFIG, mConfig); call throws RuntimeException with the cause of NotSerializableException
Upon investigation, the exception was caused by serialization of INavigationFragment class members, as indicated in the cause:

Caused by java.io.NotSerializableException: com.class.name.RedactedFragment
       at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1344)
       at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
       at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
       at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
       at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
       at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
       at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
       at android.os.Parcel.writeSerializable(Parcel.java:1389)
       at android.os.Parcel.writeValue(Parcel.java:1341)
       at android.os.Parcel.writeArrayMapInternal(Parcel.java:644)
       at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
       at android.os.Bundle.writeToParcel(Bundle.java:1034)
       at android.os.Parcel.writeBundle(Parcel.java:669)
       at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:144)
       at android.os.Parcel.writeTypedArray(Parcel.java:1197)
       at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:396)
       at android.os.Parcel.writeParcelable(Parcel.java:1363)
       at android.os.Parcel.writeValue(Parcel.java:1268)
       at android.os.Parcel.writeArrayMapInternal(Parcel.java:644)
       at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
       at android.os.Bundle.writeToParcel(Bundle.java:1034)
       at android.os.Parcel.writeBundle(Parcel.java:669)
       at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3091)
       at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3692)
       at android.os.Handler.handleCallback(Handler.java:815)
       at android.os.Handler.dispatchMessage(Handler.java:104)
       at android.os.Looper.loop(Looper.java:194)
       at android.app.ActivityThread.main(ActivityThread.java:5824)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1010)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)

As according to the documentation of ObjectOutputStream.writeObject(obj) method:
http://docs.oracle.com/javase/7/docs/api/java/io/ObjectOutputStream.html#writeObject(java.lang.Object)

Write the specified object to the ObjectOutputStream. The class of the object, the signature of the class, and the values of the non-transient and non-static fields of the class and all of its supertypes are written. Default serialization for a class can be overridden using the writeObject and the readObject methods. Objects referenced by this object are written transitively so that a complete equivalent graph of objects can be reconstructed by an ObjectInputStream.

My suggestion is to add the keyword transient to the following lines:

    public INavigationFragment rootFragment;

    public INavigationFragment masterFragment;
    public INavigationFragment detailFragment;

animation shared element transition on api LOLLIPOP

There is a missing transition when callling shared element transition.
For example, when it is calling from another fragment or navigationfragment object when the followings:

     final Pair<View, String>[] pairs = TransitionHelper.createSafeTransitionParticipants(
                            getActivity(),
                            false,
                            new Pair<>(c, "transitionname"));
                    ActivityOptionsCompat transitionActivityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), pairs);
                    startActivity(target, transitionActivityOptions.toBundle());

with another fragment..

Transition transition = TransitionInflater.from(getContext()).inflateTransition(R.transition.my_transition);
        getActivity().getWindow().setSharedElementEnterTransition(transition);
        transition.addListener(new Transition.TransitionListener() {

...

Are there any plans to implement transition support this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.