android.transition.Scene Java Examples

The following examples show how to use android.transition.Scene. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FloatyManager.java    From Floaty with Apache License 2.0 6 votes vote down vote up
public void show(Scene scene, int duration, Callback callback) {
    synchronized (lock) {
        if (isCurrentLocked(callback)) {
            current.duration = duration;
            handler.removeCallbacksAndMessages(current);
            scheduleTimeoutLocked(current);
            return;
        } else if (isNextLocked(callback)) {
            next.duration = duration;
        } else {
            next = new FloatyRecord(scene, duration, callback);
        }

        if (current != null && cancelLocked(current, Floaty.Callback.DISMISS_EVENT_CONSECUTIVE)) {
            return;
        } else {
            current = null;
            showNextLocked();
        }
    }
}
 
Example #2
Source File: FloatyManager.java    From Floaty with Apache License 2.0 6 votes vote down vote up
public void replace(Scene scene, int duration, Callback callback) {
    synchronized (lock) {
        if (isCurrentLocked(callback)) {
            current.duration = duration;
            handler.removeCallbacksAndMessages(current);
            scheduleTimeoutLocked(current);
        } else {
            next = new FloatyRecord(scene, duration, callback);
        }

        if (current != null) {
            handler.removeCallbacksAndMessages(current);
            replaceToNextLocked();
        } else if (!cancelLocked(current, Floaty.Callback.DISMISS_EVENT_CONSECUTIVE)) {
            showNextLocked();
        }
    }
}
 
Example #3
Source File: CustomTransitionFragment.java    From animation-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    Context context = getActivity();
    FrameLayout container = (FrameLayout) view.findViewById(R.id.container);
    view.findViewById(R.id.show_next_scene).setOnClickListener(this);
    if (null != savedInstanceState) {
        mCurrentScene = savedInstanceState.getInt(STATE_CURRENT_SCENE);
    }
    // We set up the Scenes here.
    mScenes = new Scene[] {
            Scene.getSceneForLayout(container, R.layout.scene1, context),
            Scene.getSceneForLayout(container, R.layout.scene2, context),
            Scene.getSceneForLayout(container, R.layout.scene3, context),
    };
    // This is the custom Transition.
    mTransition = new ChangeColor();
    // Show the initial Scene.
    TransitionManager.go(mScenes[mCurrentScene % mScenes.length]);
}
 
Example #4
Source File: MainActivity.java    From auid2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mSceneRoot = (ViewGroup) findViewById(R.id.scene_root);

    mScene1 = Scene.getSceneForLayout(mSceneRoot, R.layout.scene1, this);
    mScene2 = Scene.getSceneForLayout(mSceneRoot, R.layout.scene2, this);

    mTransition = new ChangeBounds();
    mTransition.setDuration(DateUtils.SECOND_IN_MILLIS);
    mTransition.setInterpolator(new AccelerateDecelerateInterpolator());
    TransitionManager.go(mScene1);
    mCurrentScene = mScene1;

    findViewById(R.id.button).setOnClickListener(this);
}
 
Example #5
Source File: MainActivity.java    From cogitolearning-examples with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main_activity);

  container = (ViewGroup) findViewById(R.id.main_container);
  webSiteForm = Scene.getSceneForLayout(container, R.layout.scene_link, this);
  pictureForm = Scene.getSceneForLayout(container, R.layout.scene_picture, this);
  contactForm = Scene.getSceneForLayout(container, R.layout.scene_contact, this);
  eventForm   = Scene.getSceneForLayout(container, R.layout.scene_event, this);
}
 
Example #6
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 5 votes vote down vote up
public void goAnimate(View view) {
        //Resource file solution
        ViewGroup root = findViewById(R.id.layout);
        Scene scene = Scene.getSceneForLayout(root, R.layout.activity_main_end, this);
        Transition transition = TransitionInflater.from(this)
                .inflateTransition(R.transition.transition_move);
        TransitionManager.go(scene, transition);

        //Code only solution
//        ViewGroup root = findViewById(R.id.layout);
//        Scene scene = new Scene(root);
//
//        Transition transition = new ChangeBounds();
//        TransitionManager.beginDelayedTransition(root,transition);
//
//        TextView textViewTop = findViewById(R.id.textViewTop);
//        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)textViewTop.getLayoutParams();
//        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,1);
//        params.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
//        textViewTop.setLayoutParams(params);
//
//        TextView textViewBottom = findViewById(R.id.textViewBottom);
//        params = (RelativeLayout.LayoutParams) textViewBottom.getLayoutParams();
//        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,0);
//        params.addRule(RelativeLayout.ALIGN_PARENT_TOP, 1);
//        textViewBottom.setLayoutParams(params);
//
//        TransitionManager.go(scene);
    }
 
Example #7
Source File: FloatyManager.java    From Floaty with Apache License 2.0 5 votes vote down vote up
private void replaceToNextLocked() {
    if (next != null) {
        final Scene scene = current.scene.get();

        final Callback callback = next.callback.get();
        if (callback != null) {
            callback.replace(scene);
            current = next;
            next = null;
        } else {
            next = null;
        }
    }
}
 
Example #8
Source File: Floaty.java    From Floaty with Apache License 2.0 5 votes vote down vote up
private Floaty(ViewGroup parent, View content) {
    if (parent == null) {
        throw new IllegalArgumentException("Transient bottom bar must have non-null parent");
    }
    if (content == null) {
        throw new IllegalArgumentException("Transient bottom bar must have non-null content");
    }

    targetParent = parent;
    context = parent.getContext();
    view = (FloatyContentLayout) content;

    stage = Stage.of(targetParent);

    ViewCompat.setAccessibilityLiveRegion(stage, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);
    ViewCompat.setImportantForAccessibility(stage, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

    // Make sure that we fit system windows and have a listener to apply any insets
    stage.setFitsSystemWindows(true);
    ViewCompat.setOnApplyWindowInsetsListener(stage,
            new android.support.v4.view.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    // Copy over the bottom inset as padding so that we're displayed
                    // above the navigation bar
                    v.setPadding(v.getPaddingLeft(), v.getPaddingTop(), v.getPaddingRight(),
                            insets.getSystemWindowInsetBottom());
                    return insets;
                }
            });

    accessibilityManager =
            (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

    scene = new Scene(stage, view);
}
 
Example #9
Source File: SceneCompat.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
public SceneCompat(ViewGroup parent, ViewGroup view) {
    if (Device.hasKitKatApi()) {
        mScene = new Scene(parent, view);
    }
    mParent = parent;
    mView = view;
}
 
Example #10
Source File: AlbumDetailActivity.java    From android-animations-transitions with MIT License 4 votes vote down vote up
private void setupTransitions() {
//        Slide slide = new Slide(Gravity.BOTTOM);
//        slide.excludeTarget(android.R.id.statusBarBackground, true);
//        getWindow().setEnterTransition(slide);
//        getWindow().setSharedElementsUseOverlay(false);

        mTransitionManager = new TransitionManager();
        ViewGroup transitionRoot = detailContainer;

        // Expanded scene
        mExpandedScene = Scene.getSceneForLayout(transitionRoot,
                R.layout.activity_album_detail_expanded, this);

        mExpandedScene.setEnterAction(new Runnable() {
            @Override
            public void run() {
                ButterKnife.bind(AlbumDetailActivity.this);
                populate();
                mCurrentScene = mExpandedScene;
            }
        });

        TransitionSet expandTransitionSet = new TransitionSet();
        expandTransitionSet.setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
        ChangeBounds changeBounds = new ChangeBounds();
        changeBounds.setDuration(200);
        expandTransitionSet.addTransition(changeBounds);

        Fade fadeLyrics = new Fade();
        fadeLyrics.addTarget(R.id.lyrics);
        fadeLyrics.setDuration(150);
        expandTransitionSet.addTransition(fadeLyrics);

        // Collapsed scene
        mCollapsedScene = Scene.getSceneForLayout(transitionRoot,
                R.layout.activity_album_detail, this);

        mCollapsedScene.setEnterAction(new Runnable() {
            @Override
            public void run() {
                ButterKnife.bind(AlbumDetailActivity.this);
                populate();
                mCurrentScene = mCollapsedScene;
            }
        });

        TransitionSet collapseTransitionSet = new TransitionSet();
        collapseTransitionSet.setOrdering(TransitionSet.ORDERING_SEQUENTIAL);

        Fade fadeOutLyrics = new Fade();
        fadeOutLyrics.addTarget(R.id.lyrics);
        fadeOutLyrics.setDuration(150);
        collapseTransitionSet.addTransition(fadeOutLyrics);

        ChangeBounds resetBounds = new ChangeBounds();
        resetBounds.setDuration(200);
        collapseTransitionSet.addTransition(resetBounds);

        mTransitionManager.setTransition(mExpandedScene, mCollapsedScene, collapseTransitionSet);
        mTransitionManager.setTransition(mCollapsedScene, mExpandedScene, expandTransitionSet);
        mCollapsedScene.enter();

//        postponeEnterTransition();
    }
 
Example #11
Source File: AcDisplayFragment.java    From AcDisplay with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Changes current scene to given one.
 *
 * @see #showWidget(com.achep.acdisplay.ui.components.Widget)
 */
@SuppressLint("NewApi")
protected synchronized final void goScene(@NonNull SceneCompat sceneCompat, boolean animate) {
    if (mCurrentScene == sceneCompat) return;
    mCurrentScene = sceneCompat;
    if (DEBUG) Log.d(TAG, "Going to " + sceneCompat);

    if (Device.hasKitKatApi()) animate &= mSceneContainer.isLaidOut();
    if (!animate) {
        sceneCompat.enter();
        return;
    }

    if (Device.hasKitKatApi()) {
        final Scene scene = sceneCompat.getScene();
        try {
            // This must be a synchronization problem with Android's Scene or TransitionManager,
            // but those were declared as final classes, so I have no idea how to fix it.
            TransitionManager.go(scene, mTransitionSwitchScene);
        } catch (IllegalStateException e) {
            Log.w(TAG, "TransitionManager has failed switching scenes!");

            ViewGroup viewGroup = (ViewGroup) getSceneView().getParent();
            viewGroup.removeView(getSceneView());

            try {
                // Reset internal scene's tag to make it work again.
                int id = Resources.getSystem().getIdentifier("current_scene", "id", "android");
                Method method = View.class.getMethod("setTagInternal", int.class, Object.class);
                method.setAccessible(true);
                method.invoke(viewGroup, id, null);
            } catch (NoSuchMethodException
                    | IllegalAccessException
                    | InvocationTargetException e2) {
                throw new RuntimeException("An attempt to fix the TransitionManager has failed.");
            }

            TransitionManager.go(scene, mTransitionSwitchScene);
        }
    } else {
        sceneCompat.enter();

        if (getActivity() != null) {
            // TODO: Better animation for Jelly Bean users.
            float density = getResources().getDisplayMetrics().density;
            getSceneView().setAlpha(0.6f);
            getSceneView().setRotationX(6f);
            getSceneView().setTranslationY(6f * density);
            getSceneView().animate().alpha(1).rotationX(0).translationY(0);
        }
    }
}
 
Example #12
Source File: SceneCompat.java    From AcDisplay with GNU General Public License v2.0 4 votes vote down vote up
public Scene getScene() {
    return mScene;
}
 
Example #13
Source File: TransitionHelperKitkat.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
static void runTransition(Object scene, Object transition) {
    TransitionManager.go((Scene) scene, (Transition) transition);
}
 
Example #14
Source File: TransitionHelperKitkat.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
static Object createScene(ViewGroup sceneRoot, Runnable enterAction) {
    Scene scene = new Scene(sceneRoot);
    scene.setEnterAction(enterAction);
    return scene;
}
 
Example #15
Source File: Floaty.java    From Floaty with Apache License 2.0 4 votes vote down vote up
@Override
public void replace(Scene before) {
    Floaty.this.beforeScene = before;
    fHandler.sendMessage(fHandler.obtainMessage(MSG_REPLACE, Floaty.this));
}
 
Example #16
Source File: FloatyManager.java    From Floaty with Apache License 2.0 4 votes vote down vote up
public FloatyRecord(Scene scene, int duration, Callback callback) {
    this.scene = new WeakReference<>(scene);
    this.duration = duration;
    this.callback = new WeakReference<>(callback);
}
 
Example #17
Source File: OrderDialogFragment.java    From From-design-to-Android-part1 with Apache License 2.0 3 votes vote down vote up
private void changeToConfirmScene() {
    final LayoutOrderConfirmationBinding confBinding = prepareConfirmationBinding();

    final Scene scene = new Scene(binding.content,
        ((ViewGroup) confBinding.getRoot()));

    scene.setEnterAction(onEnterConfirmScene(confBinding));

    final Transition transition = TransitionInflater.from(getContext())
        .inflateTransition(R.transition.transition_confirmation_view);

    TransitionManager.go(scene, transition);
}
 
Example #18
Source File: BlueprintActivity.java    From CompositeAndroid with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieve the {@link Scene} representing this window's current content.
 * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}.
 *
 * <p>This method will return null if the current content is not represented by a Scene.</p>
 *
 * @return Current Scene being shown or null
 */
@Override
public Scene getContentScene() {
    return super.getContentScene();
}
 
Example #19
Source File: Window.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieve the {@link Scene} representing this window's current content.
 * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
 *
 * <p>This method will return null if the current content is not represented by a Scene.</p>
 *
 * @return Current Scene being shown or null
 */
public Scene getContentScene() {
    return null;
}
 
Example #20
Source File: ICompositeActivity.java    From CompositeAndroid with Apache License 2.0 votes vote down vote up
Scene super_getContentScene(); 
Example #21
Source File: ICompositeActivity.java    From CompositeAndroid with Apache License 2.0 votes vote down vote up
Scene getContentScene(); 
Example #22
Source File: FloatyManager.java    From Floaty with Apache License 2.0 votes vote down vote up
void replace(Scene before);