Skip to content

Commit

Permalink
Icon animation transition - fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenumir committed Oct 5, 2017
1 parent 22a1962 commit 6868de8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.transition.Fade;
import android.transition.Transition;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
Expand Down Expand Up @@ -86,6 +88,7 @@ public void onChanged(final @Nullable ApplicationDetailsEntity productEntity) {
toolbar.setSubtitle(productEntity.getId());
toolbar.setNavigationIcon(productEntity.getIcon36dp());
mAppInfoAdapter.setData(productEntity);
supportStartPostponedEnterTransition();
shareMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
Expand Down Expand Up @@ -114,15 +117,21 @@ public boolean onMenuItemClick(MenuItem menuItem) {
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
supportFinishAfterTransition();
}
});
toolbar.setNavigationContentDescription(appId);
if (Build.VERSION.SDK_INT >= 21) {
supportPostponeEnterTransition();
View navIcon = ViewUtil.findViewWithContentDescription(toolbar, appId);
if (navIcon != null) {
navIcon.setTransitionName("transition_" + appId);
}
Transition fade = new Fade();
fade.excludeTarget(android.R.id.statusBarBackground, true);
fade.excludeTarget(android.R.id.navigationBarBackground, true);
getWindow().setExitTransition(fade);
getWindow().setEnterTransition(fade);
}

mAppInfoAdapter = new AppInfoAdapter(getResources(), new OnHeaderClick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.app.Fragment;
import android.support.v4.util.Pair;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand All @@ -23,6 +24,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
Expand All @@ -39,6 +41,7 @@
import com.wt.apkinfo.util.IntentHelper;
import com.wt.apkinfo.viewmodel.ApplicationListViewModel;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
Expand Down Expand Up @@ -149,8 +152,19 @@ public void onItemClick(View v, ApplicationEntity item, ApplicationsItemHolder h
Intent it = new Intent(getActivity(), ApplicationDetailsActivity.class);
it.putExtra(ApplicationDetailsActivity.KEY_APP_ID, item.getId());
if (Build.VERSION.SDK_INT >= 21) {
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(getActivity(), holder.icon1, "transition_" + item.id);
View decorView = getActivity().getWindow().getDecorView();
View statusBar = decorView.findViewById(android.R.id.statusBarBackground);
View navigationBar = decorView.findViewById(android.R.id.navigationBarBackground);

List<Pair<View, String>> el = new ArrayList<>();
el.add(Pair.create((View) holder.icon1, "transition_" + item.id));
if (statusBar != null) {
el.add(Pair.create(statusBar, Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME));
}
if (navigationBar != null) {
el.add(Pair.create(navigationBar, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME));
}
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), el.toArray(new Pair[el.size()]));
startActivity(it, options.toBundle());
} else {
startActivity(it);
Expand Down

0 comments on commit 6868de8

Please sign in to comment.