Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
Improve transition handling during sign in
Browse files Browse the repository at this point in the history
Change-Id: I60c521c89ad51b0dc80ddde507c74c35e40736a0
  • Loading branch information
keyboardsurfer committed Jun 21, 2016
1 parent 4290635 commit dcf3bd0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
Expand Up @@ -43,7 +43,6 @@
import com.google.samples.apps.topeka.helper.PreferencesHelper;
import com.google.samples.apps.topeka.model.Player;
import com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper;
import com.google.samples.apps.topeka.widget.AvatarView;

public class CategorySelectionActivity extends AppCompatActivity {

Expand Down Expand Up @@ -138,7 +137,7 @@ private void signOut() {
.inflateTransition(R.transition.category_enter));
}
SignInActivity.start(this, false);
ActivityCompat.finishAfterTransition(this);
finish();
}

private void attachCategoryGridFragment() {
Expand Down
Expand Up @@ -17,6 +17,7 @@
package com.google.samples.apps.topeka.fragment;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
Expand All @@ -27,6 +28,7 @@
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.text.Editable;
import android.text.TextWatcher;
import android.transition.Transition;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -37,10 +39,12 @@
import com.google.samples.apps.topeka.R;
import com.google.samples.apps.topeka.activity.CategorySelectionActivity;
import com.google.samples.apps.topeka.adapter.AvatarAdapter;
import com.google.samples.apps.topeka.helper.ApiLevelHelper;
import com.google.samples.apps.topeka.helper.PreferencesHelper;
import com.google.samples.apps.topeka.helper.TransitionHelper;
import com.google.samples.apps.topeka.model.Avatar;
import com.google.samples.apps.topeka.model.Player;
import com.google.samples.apps.topeka.widget.TransitionListenerAdapter;

/**
* Enable selection of an {@link Avatar} and user name.
Expand Down Expand Up @@ -217,18 +221,29 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)

private void performSignInWithTransition(View v) {
final Activity activity = getActivity();
if (v == null) {
if (v == null || ApiLevelHelper.isLowerThan(Build.VERSION_CODES.LOLLIPOP)) {
// Don't run a transition if the passed view is null
CategorySelectionActivity.start(activity, mPlayer);
activity.finish();
return;
}

final Pair[] pairs = TransitionHelper.createSafeTransitionParticipants(activity, true,
new Pair<>(v, activity.getString(R.string.transition_avatar)));
@SuppressWarnings("unchecked")
ActivityOptionsCompat activityOptions = ActivityOptionsCompat
.makeSceneTransitionAnimation(activity, pairs);
CategorySelectionActivity.start(activity, mPlayer, activityOptions);
if (ApiLevelHelper.isAtLeast(Build.VERSION_CODES.LOLLIPOP)) {
activity.getWindow().getSharedElementExitTransition().addListener(
new TransitionListenerAdapter() {
@Override
public void onTransitionEnd(Transition transition) {
activity.finish();
}
});

final Pair[] pairs = TransitionHelper.createSafeTransitionParticipants(activity, true,
new Pair<>(v, activity.getString(R.string.transition_avatar)));
@SuppressWarnings("unchecked")
ActivityOptionsCompat activityOptions = ActivityOptionsCompat
.makeSceneTransitionAnimation(activity, pairs);
CategorySelectionActivity.start(activity, mPlayer, activityOptions);
}
}

private void initContents() {
Expand Down
@@ -0,0 +1,44 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.samples.apps.topeka.widget;

import android.annotation.TargetApi;
import android.os.Build;
import android.transition.Transition;

/**
* Empty implementation of {@link Transition.TransitionListener}.
*/

@TargetApi(Build.VERSION_CODES.KITKAT)
public abstract class TransitionListenerAdapter implements Transition.TransitionListener {

@Override
public void onTransitionStart(Transition transition) { }

@Override
public void onTransitionEnd(Transition transition) { }

@Override
public void onTransitionCancel(Transition transition) { }

@Override
public void onTransitionPause(Transition transition) { }

@Override
public void onTransitionResume(Transition transition) { }
}

0 comments on commit dcf3bd0

Please sign in to comment.