Skip to content

Simple tool which help you to implement activity and fragment transition for pre-Lollipop devices.

Notifications You must be signed in to change notification settings

albinmathew/PreLollipopTransition

 
 

Repository files navigation

PreLollipopTransition

Simple tool which help you to implement activity and fragment transition for pre-Lollipop devices.

Build Status Download Download

prelollipopanimation

Download

In your app build.gradle add

	repositories {
	    maven {
	        url "https://jitpack.io"
	    }
	}
dependencies {
	        compile 'com.github.albinmathew:PreLollipopTransition:1.1.2'
	}

or using bintray and jcenter

repositories {
    maven {
        url  "http://dl.bintray.com/albinmathew/maven"
    }
}
dependencies {
	        compile 'com.albinmathew:PreLollipopTransition:1.1.2'
	}

Code

Actvity

Start Activity in first activity.

findViewById(R.id.imageView).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        final Intent intent = new Intent(MainActivity.this, SubActivity.class);
        ActivityTransitionLauncher.with(MainActivity.this).from(v).launch(intent);
    }
});

Receive intent in second activity.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sub);
        ActivityTransition.with(getIntent()).to(findViewById(R.id.sub_imageView)).start(savedInstanceState);
    }

If you want the exit animation, you can do like this.

    private ExitActivityTransition exitTransition;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sub2);
        exitTransition = ActivityTransition.with(getIntent()).to(findViewById(R.id.sub_imageView)).start(savedInstanceState);
    }
    @Override
    public void onBackPressed() {
        exitTransition.exit(this);
    }

Fragment

Start fragment transition in first activity.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.support_fragment_start, container, false);
        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final EndFragment toFragment = new EndFragment();
                FragmentTransitionLauncher
                        .with(view.getContext())
                        .image(BitmapFactory.decodeResource(getResources(), R.drawable.photo))
                        .from(view.findViewById(R.id.imageView)).prepare(toFragment);
                getFragmentManager().beginTransaction().replace(R.id.content, toFragment).addToBackStack(null).commit();
            }
        });
        return v;
    }

Start animation in second fragment.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.support_fragment_end, container, false);
        final ExitFragmentTransition exitFragmentTransition = FragmentTransition.with(this).to(v.findViewById(R.id.fragment_imageView)).start(savedInstanceState);
        exitFragmentTransition.startExitListening();
        return v;
    }

Thanks

Sample Photo Luke Ma https://www.flickr.com/photos/lukema/12499338274/in/photostream/

DevBytes: Custom Activity Animations https://www.youtube.com/watch?v=CPxkoe2MraA

License

This project is released under the Apache License, Version 2.0.

About

Simple tool which help you to implement activity and fragment transition for pre-Lollipop devices.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%