Skip to content

Commit

Permalink
Icon animation transition (first try).
Browse files Browse the repository at this point in the history
  • Loading branch information
kenumir committed Oct 4, 2017
1 parent 42c153c commit 22a1962
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
Expand All @@ -31,6 +32,7 @@
import com.wt.apkinfo.entity.ApplicationDetailsEntity;
import com.wt.apkinfo.entity.ComponentInfo;
import com.wt.apkinfo.util.DateTime;
import com.wt.apkinfo.util.ViewUtil;
import com.wt.apkinfo.viewmodel.ApplicationDetailsViewModel;

import java.io.File;
Expand Down Expand Up @@ -108,12 +110,20 @@ public boolean onMenuItemClick(MenuItem menuItem) {
}
}
});
toolbar.setNavigationIcon(R.drawable.theme_round_icon);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
toolbar.setNavigationContentDescription(appId);
if (Build.VERSION.SDK_INT >= 21) {
View navIcon = ViewUtil.findViewWithContentDescription(toolbar, appId);
if (navIcon != null) {
navIcon.setTransitionName("transition_" + appId);
}
}

mAppInfoAdapter = new AppInfoAdapter(getResources(), new OnHeaderClick() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
Expand Down Expand Up @@ -142,10 +145,16 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
if (adapter == null) {
adapter = new ApplicationsListAdapter(new OnItemClick() {
@Override
public void onItemClick(View v, ApplicationEntity item) {
public void onItemClick(View v, ApplicationEntity item, ApplicationsItemHolder holder) {
Intent it = new Intent(getActivity(), ApplicationDetailsActivity.class);
it.putExtra(ApplicationDetailsActivity.KEY_APP_ID, item.getId());
startActivity(it);
if (Build.VERSION.SDK_INT >= 21) {
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(getActivity(), holder.icon1, "transition_" + item.id);
startActivity(it, options.toBundle());
} else {
startActivity(it);
}
}
});
}
Expand All @@ -168,7 +177,7 @@ public void onChanged(@Nullable List<ApplicationEntity> apps) {
}

private interface OnItemClick {
void onItemClick(View v, ApplicationEntity item);
void onItemClick(View v, ApplicationEntity item, ApplicationsItemHolder holder);
}

private static class ApplicationsListAdapter extends RecyclerView.Adapter<ApplicationsItemHolder> {
Expand All @@ -191,7 +200,7 @@ public ApplicationsItemHolder onCreateViewHolder(ViewGroup parent, int viewType)
}

@Override
public void onBindViewHolder(ApplicationsItemHolder holder, int position) {
public void onBindViewHolder(final ApplicationsItemHolder holder, int position) {
final ApplicationEntity entry = mData.get(position);
holder.text1.setText(entry.getName());
holder.text2.setText(entry.getId());
Expand All @@ -200,10 +209,11 @@ public void onBindViewHolder(ApplicationsItemHolder holder, int position) {
@Override
public void onClick(View view) {
if (mOnItemClick != null) {
mOnItemClick.onItemClick(view, entry);
mOnItemClick.onItemClick(view, entry, holder);
}
}
});
holder.update(entry);
}

@Override
Expand All @@ -222,5 +232,10 @@ public ApplicationsItemHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}

public void update(ApplicationEntity entry) {
ViewCompat.setTransitionName(icon1, "transition_" + entry.id);
//icon1.setTransitionName("transition_" + entry.id);
}
}
}
26 changes: 26 additions & 0 deletions app/src/main/java/com/wt/apkinfo/util/ViewUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.wt.apkinfo.util;

import android.support.annotation.Nullable;
import android.view.View;

import java.util.ArrayList;

/**
* Created by kenumir on 04.10.2017.
*
*/

public class ViewUtil {

@Nullable
public static View findViewWithContentDescription(View src, String contentDescription) {
ArrayList<View> potentialViews = new ArrayList<View>();
src.findViewsWithText(potentialViews, contentDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
View res = null;
if (potentialViews.size() > 0){
res = potentialViews.get(0);
}
return res;
}

}
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/theme_round_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<size android:height="36dp" android:width="36dp" />
<solid android:color="@color/colorPrimary" />

</shape>
7 changes: 7 additions & 0 deletions app/src/main/res/values-v21/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<resources>

<style name="AppTheme" parent="AppThemeBase">
<item name="android:windowContentTransitions">true</item>
</style>

</resources>
5 changes: 3 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme" parent="AppThemeBase">
</style>

<style name="StartTheme" parent="AppTheme">
<item name="android:windowBackground">@drawable/app_start_logo</item>
Expand Down

0 comments on commit 22a1962

Please sign in to comment.