com.albedinsky.android.ui.examples.fragment.animation.TransitionFragmentsA.java Source code

Java tutorial

Introduction

Here is the source code for com.albedinsky.android.ui.examples.fragment.animation.TransitionFragmentsA.java

Source

/*
 * =================================================================================================
 *                             Copyright (C) 2015 Martin Albedinsky
 * =================================================================================================
 *         Licensed under the Apache License, Version 2.0 or later (further "License" only).
 * -------------------------------------------------------------------------------------------------
 * You may use this file only in compliance with the License. More details and copy of this License
 * you may obtain at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * You can redistribute, modify or publish any part of the code written within this file but as it
 * is described in the License, the software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES or CONDITIONS OF ANY KIND.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 * =================================================================================================
 */
package com.albedinsky.android.ui.examples.fragment.animation;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import com.albedinsky.android.support.fragment.annotation.FactoryFragments;
import com.albedinsky.android.support.fragment.manage.BaseFragmentFactory;
import com.albedinsky.android.support.fragment.manage.FragmentTransactionOptions;
import com.albedinsky.android.ui.examples.content.Extras;
import com.albedinsky.android.ui.examples.model.TransitionExample;

/**
 * @author Martin Albedinsky
 */
@FactoryFragments({ TransitionFragmentsA.SCALE_1, TransitionFragmentsA.REVEAL_1 })
public final class TransitionFragmentsA extends BaseFragmentFactory {

    @SuppressWarnings("unused")
    private static final String TAG = "TransitionsFragmentsA";

    /**
     * Scale transitions fragments -----------------------------------------------------------------
     */

    public static final int SCALE_1 = 0x10000001;

    /**
     * Reveal transitions fragments -----------------------------------------------------------------
     */

    public static final int REVEAL_1 = 0x20000001;

    public static Bundle argsWithTransitionExample(TransitionExample example) {
        final Bundle args = new Bundle();
        args.putParcelable(Extras.EXTRA_TRANSITION_EXAMPLE, example);
        return args;
    }

    static TransitionExample transitionExampleFromArgs(Bundle args) {
        return args != null ? (TransitionExample) args.getParcelable(Extras.EXTRA_TRANSITION_EXAMPLE) : null;
    }

    @Nullable
    @Override
    protected Fragment onCreateFragmentInstance(@NonNull FragmentTransactionOptions options) {
        final TransitionExample example = transitionExampleFromArgs(options.arguments());
        if (example == null)
            return null;

        Fragment fragment = null;
        switch (options.incomingFragmentId) {
        case SCALE_1:
            fragment = new TransitionFragmentA();
            break;
        case REVEAL_1:
            fragment = new RevealFabTransitionFragment();
            break;
        }

        if (fragment != null) {
            fragment.setArguments(options.arguments());
            return fragment;
        }

        return super.onCreateFragmentInstance(options);
    }
}