├── .gitignore
├── .idea
└── codeStyles
│ └── codeStyleConfig.xml
├── LICENSE
├── README.md
├── README_CN.md
├── app
├── .gitignore
├── build.gradle
├── gradlew
├── gradlew.bat
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── us
│ │ └── pinguo
│ │ └── shareelementdemo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── us
│ │ │ └── pinguo
│ │ │ └── shareelementdemo
│ │ │ ├── MainActivity.java
│ │ │ ├── SecondActivity.java
│ │ │ ├── advanced
│ │ │ ├── AdvancedContentActivity.java
│ │ │ ├── AdvancedContentFragment.java
│ │ │ ├── AdvancedListActivity.java
│ │ │ ├── AdvancedListFragment.java
│ │ │ ├── BaseData.java
│ │ │ ├── FrescoViewStateSaver.java
│ │ │ ├── Image.java
│ │ │ ├── SpaceItemDecoration.java
│ │ │ ├── Video.java
│ │ │ ├── content
│ │ │ │ ├── BaseContentCell.java
│ │ │ │ ├── BitmapThumbnail.java
│ │ │ │ ├── ImageContentCell.java
│ │ │ │ ├── ImageFrescoContentCell.java
│ │ │ │ ├── SimpleVideoView.java
│ │ │ │ ├── VideoContentCell.java
│ │ │ │ └── viewpager
│ │ │ │ │ ├── BasePagerAdapter.java
│ │ │ │ │ ├── BasePagerCell.java
│ │ │ │ │ └── BasePagerViewHolder.java
│ │ │ └── list
│ │ │ │ ├── AdvancedDraweeTransition.java
│ │ │ │ ├── AdvancedListAdapter.java
│ │ │ │ ├── BaseListCell.java
│ │ │ │ ├── BaseRecyclerAdapter.java
│ │ │ │ ├── BaseRecyclerCell.java
│ │ │ │ ├── BaseViewHolder.java
│ │ │ │ ├── DeliveryControllerListener.java
│ │ │ │ ├── FrescoShareElementTransitionfactory.java
│ │ │ │ ├── ImageFrescoListCell.java
│ │ │ │ ├── ImageListCell.java
│ │ │ │ ├── ShareContentInfo.java
│ │ │ │ └── VideoListCell.java
│ │ │ ├── contacts
│ │ │ ├── Contacts.java
│ │ │ ├── ContactsActivity.java
│ │ │ └── DetailActivity.java
│ │ │ └── simple
│ │ │ ├── Simple1Fragment.java
│ │ │ ├── Simple2Fragment.java
│ │ │ ├── SimpleFragmentActivity.java
│ │ │ ├── SimpleFromActivity.java
│ │ │ └── SimpleToActivity.java
│ └── res
│ │ ├── drawable-nodpi
│ │ ├── simple.jpg
│ │ └── test.jpg
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xxhdpi
│ │ ├── american_shorthair.jpg
│ │ ├── british_shorthair.jpg
│ │ ├── dragon_li.jpg
│ │ ├── exotic_shorthair.jpg
│ │ ├── ragdoll.jpg
│ │ └── siamese.jpg
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_contact.xml
│ │ ├── activity_detail.xml
│ │ ├── activity_from.xml
│ │ ├── activity_main.xml
│ │ ├── activity_simple.xml
│ │ ├── activity_to.xml
│ │ ├── fragment_s1.xml
│ │ ├── fragment_s2.xml
│ │ ├── item_contacts.xml
│ │ ├── item_content_image.xml
│ │ ├── item_content_image_fresco.xml
│ │ ├── item_content_video.xml
│ │ ├── item_list_image.xml
│ │ ├── item_list_image_fresco.xml
│ │ └── item_list_video.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── us
│ └── pinguo
│ └── shareelementdemo
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── readme
├── ContactsAnim.gif
├── EnterTransition.png
├── ShareElement.png
├── c360.gif
├── contacts1.gif
├── contacts2.gif
├── dy.gif
└── se.gif
├── settings.gradle
└── ycshareelement
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── hw
│ └── ycshareelement
│ └── ExampleInstrumentedTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── hw
│ │ └── ycshareelement
│ │ ├── TransitionHelper.java
│ │ ├── YcShareElement.java
│ │ └── transition
│ │ ├── ChangeOnlineImageTransition.java
│ │ ├── ChangeTextTransition.java
│ │ ├── DefaultShareElementTransitionFactory.java
│ │ ├── IShareElementSelector.java
│ │ ├── IShareElementTransitionFactory.java
│ │ ├── IShareElements.java
│ │ ├── ShareElementInfo.java
│ │ ├── TextViewStateSaver.java
│ │ └── ViewStateSaver.java
└── res
│ └── values
│ ├── ids.xml
│ └── strings.xml
└── test
└── java
└── com
└── hw
└── ycshareelement
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # IntelliJ
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/assetWizardSettings.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 | .idea/caches
44 |
45 | # Keystore files
46 | # Uncomment the following line if you do not want to check your keystore files in.
47 | #*.jks
48 |
49 | # External native build folder generated in Android Studio 2.2 and later
50 | .externalNativeBuild
51 |
52 | # Google Services (e.g. APIs or Firebase)
53 | google-services.json
54 |
55 | # Freeline
56 | freeline.py
57 | freeline/
58 | freeline_project_description.json
59 |
60 | # fastlane
61 | fastlane/report.xml
62 | fastlane/Preview.html
63 | fastlane/screenshots
64 | fastlane/test_output
65 | fastlane/readme.md
66 |
67 | *.iml
68 | .gradle
69 | /local.properties
70 | /.idea/libraries
71 | /.idea/modules.xml
72 | /.idea/workspace.xml
73 | .DS_Store
74 | /build
75 | /captures
76 | .externalNativeBuild
77 |
78 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [原理分析](https://www.jianshu.com/p/fa1c8deeaa57)
2 |
3 | [README(中文)](https://github.com/yellowcath/YcShareElement/blob/master/README_CN.md)
4 | ## Gradle
5 |
6 | add Maven
7 | ``` groovy
8 | allprojects {
9 | repositories {
10 | ...
11 | maven { url 'https://www.jitpack.io' }
12 | }
13 | }
14 | ```
15 | add implementation
16 | ``` groovy
17 | dependencies {
18 | implementation 'com.github.yellowcath:YcShareElement:1.3.2'
19 | //for androidx
20 | implementation 'com.github.yellowcath:YcShareElement:1.3.2.x'
21 | }
22 | ```
23 |
24 | ## Usage
25 | >In demo,
26 | Show the videos with[GSYVideoPlayer](https://github.com/CarGuo/GSYVideoPlayer)
27 | Show the images with [Fresco](https://github.com/facebook/fresco) and [Glide](https://github.com/bumptech/glide)
28 |
29 | YcShareElement provides two demos, one is the contact demo above,another implements a complex ShareElement animation of images and video mixes,see image below
30 |
31 | 
32 |
33 | The key points here are as follows:
34 | 1、ShareElement animation of Glide pictures
35 | In the animation, imageView will go through the default background color -> small thumbnail -> big picture three stages. How to achieve a seamless switch in these three stages
36 | Reference:[ChangeOnlineImageTransition](https://github.com/yellowcath/YcShareElement/blob/master/ycshareelement/src/main/java/com/hw/ycshareelement/transition/ChangeOnlineImageTransition.java)
37 | 2、ShareElement animation of Fresco pictures
38 | Fresco provides the built-in DraweeTransition, but if you set the thumbnail, the image will be distorted, and must provide animation-starting ScaleType information in the constructor, which isn't very nice in complex situations.
39 | Reference:[AdvancedDraweeTransition](https://github.com/yellowcath/YcShareElement/blob/master/ycshareelement/src/main/java/com/hw/ycshareelement/transition/AdvancedDraweeTransition.java)
40 | 3、ShareElement animation of videos
41 | And this is actually pretty simple after we've done the first two points, we're actually animating the cover of video.
42 |
43 | ### Simple Usage
44 |
45 | #### 1、Turn on the switch of WindowContentTransition
46 | ``` java
47 | YcShareElement.enableContentTransition(getApplication());
48 | ```
49 | The switch is turned on by default
50 | #### 2、Generate a bundle, and then startActivity
51 | ``` java
52 | private void gotoDetailActivity(){
53 | Intent intent = new Intent(this, DetailActivity.class);
54 | Bundle bundle = YcShareElement.buildOptionsBundle(ContactActivity.this, new IShareElements() {
55 | @Override
56 | public ShareElementInfo[] getShareElements() {
57 | return new ShareElementInfo[]{new ShareElementInfo(mAvatarImg),
58 | new ShareElementInfo(mNameTxt, new TextViewStateSaver())};
59 | }
60 | });
61 | ActivityCompat.startActivity(ContactActivity.this, intent, bundle);
62 | }
63 | ```
64 | #### 3、Set up and start transition on the new page
65 | ``` java
66 | public class DetailActivity extends Activity {
67 | @Override
68 | protected void onCreate(@Nullable Bundle savedInstanceState) {
69 | ...
70 | YcShareElement.setEnterTransition(this, new IShareElements() {
71 | @Override
72 | public ShareElementInfo[] getShareElements() {
73 | return new ShareElementInfo[]{new ShareElementInfo(avatarImg),
74 | new ShareElementInfo(nameTxt, new TextViewStateSaver())};
75 | }
76 | });
77 | YcShareElement.startTransition(this);
78 | }
79 | }
80 | ```
81 | >YcShareElement.setEnterTransition() will suspend activity transtion animation by default,until the call of YcShareElement.startTransition(),in this simple page where you don't have to wait for ShareElement to load, you can pass the third parameter to false, without pausing ActivityB's transition animation
82 |
83 | ``` java
84 | protected void onCreate(@Nullable Bundle savedInstanceState) {
85 | ...
86 | YcShareElement.setEnterTransition(this, new IShareElements() {
87 | @Override
88 | public ShareElementInfo[] getShareElements() {
89 | return new ShareElementInfo[]{new ShareElementInfo(avatarImg),
90 | new ShareElementInfo(nameTxt, new TextViewStateSaver())};
91 | }
92 | },false);
93 | }
94 | ```
95 |
96 | Here's the result:
97 | 
98 |
99 | ### Advanced Usage(Complex page with pictures and videos)
100 |
101 | #### 1、Turn on the switch of WindowContentTransition
102 | ``` java
103 | YcShareElement.enableContentTransition(getApplication());
104 | ```
105 | #### 2、Generate a bundle, and then startActivity
106 | ``` java
107 | Bundle options = YcShareElement.buildOptionsBundle(getActivity(), this);
108 | startActivityForResult(intent, REQUEST_CONTENT, options);
109 | ```
110 | #### 3、Set up transition in Activity B
111 | ``` java
112 | protected void onCreate(@Nullable Bundle savedInstanceState) {
113 | YcShareElement.setEnterTransition(this, this);
114 | ...
115 | }
116 | ```
117 | #### 4、start transition after the ViewpPager is loaded
118 | ``` java
119 | @Override
120 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
121 | ...加载数据...
122 | YcShareElement.postStartTransition(getActivity());
123 | }
124 | ```
125 |
126 | The next step is to handle the return animation of the list page
127 |
128 | #### 5、Activity B实现finishAfterTransition()函数
129 | ``` java
130 | @Override
131 | public void finishAfterTransition() {
132 | YcShareElement.finishAfterTransition(this, this);
133 | super.finishAfterTransition();
134 | }
135 | ```
136 | #### 6、Activity B implements the finishAfterTransition() function
137 | ``` java
138 | @Override
139 | public void onActivityReenter(int resultCode, Intent data) {
140 | super.onActivityReenter(resultCode, data);
141 | YcShareElement.onActivityReenter(this, resultCode, data, new IShareElementSelector() {
142 | @Override
143 | public void selectShareElements(List list) {
144 | //Slide the list page to the location of the changed ShareElement
145 | mFragment.selectShareElement(list.get(0));
146 | }
147 | });
148 | }
149 | ```
150 |
151 | ### How to implement Transition animation that supports custom views
152 | Here is an example of how to extend Transition to support Fresco
153 |
154 | #### 1、Determine required parameters
155 | First, the parameters required for the Transtion animation, namely the ActualImageScaleType, are determined for SimpleDraweeView
156 | #### 2、Inherit the ViewStateSaver to get the required parameters
157 | ``` java
158 | public class FrescoViewStateSaver extends ViewStateSaver {
159 |
160 | @Override
161 | protected void captureViewInfo(View view, Bundle bundle) {
162 | if (view instanceof GenericDraweeView) {
163 | int actualScaleTypeInt = scaleTypeToInt(((GenericDraweeView)view).getHierarchy().getActualImageScaleType())
164 | bundle.putInt("scaleType",actualScaleTypeInt);
165 | }
166 | }
167 |
168 | public ScalingUtils.ScaleType getScaleType(Bundle bundle) {
169 | int scaleType = bundle.getInt("scaleType", 0);
170 | return intToScaleType(scaleType);
171 | }
172 | }
173 | ```
174 | #### 3、Customize the Transition
175 | ``` java
176 | public class AdvancedDraweeTransition extends Transition {
177 | private ScalingUtils.ScaleType mFromScale;
178 | private ScalingUtils.ScaleType mToScale;
179 |
180 | public AdvancedDraweeTransition() {
181 | addTarget(GenericDraweeView.class);
182 | }
183 |
184 | @Override
185 | public void captureStartValues(TransitionValues transitionValues) {
186 | ...
187 | ShareElementInfo shareElementInfo = ShareElementInfo.getFromView(transitionValues.view);
188 | mFromScale = ((FrescoViewStateSaver) shareElementInfo.getViewStateSaver()).getScaleType(viewInfo);
189 | ...
190 | }
191 |
192 | @Override
193 | public void captureEndValues(TransitionValues transitionValues) {
194 | ...
195 | ShareElementInfo shareElementInfo = ShareElementInfo.getFromView(transitionValues.view);
196 | mToScale = ((FrescoViewStateSaver) shareElementInfo.getViewStateSaver()).getScaleType(viewInfo);
197 | ...
198 | }
199 |
200 | @Override
201 | public Animator createAnimator(
202 | ViewGroup sceneRoot,
203 | TransitionValues startValues,
204 | TransitionValues endValues) {
205 | ..
206 | ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
207 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
208 | @Override
209 | public void onAnimationUpdate(ValueAnimator animation) {
210 | float fraction = (float) animation.getAnimatedValue();
211 | scaleType.setValue(fraction);
212 | if (draweeView.getHierarchy().getActualImageScaleType() != scaleType) {
213 | draweeView.getHierarchy().setActualImageScaleType(scaleType);
214 | }
215 | }
216 | });
217 | ...
218 | return animator;
219 | }
220 | }
221 | ```
222 | #### 4、Add the custom Transition to YcShareElement
223 | ``` java
224 | public class FrescoShareElementTransitionfactory extends DefaultShareElementTransitionFactory {
225 | @Override
226 | protected TransitionSet buildShareElementsTransition(List shareViewList) {
227 | TransitionSet transitionSet = super.buildShareElementsTransition(shareViewList);
228 | transitionSet.addTransition(new AdvancedDraweeTransition());
229 | return transitionSet;
230 | }
231 | }
232 | ```
233 | ``` java
234 | @Override
235 | protected void onCreate(@Nullable Bundle savedInstanceState) {
236 | ...
237 | YcShareElement.setShareElementTransitionFactory(new FrescoShareElementTransitionfactory());
238 | ...
239 | }
240 | ```
241 |
--------------------------------------------------------------------------------
/README_CN.md:
--------------------------------------------------------------------------------
1 | [原理分析](https://www.jianshu.com/p/fa1c8deeaa57)
2 |
3 | ## Gradle
4 |
5 | add Maven
6 | ``` groovy
7 | allprojects {
8 | repositories {
9 | ...
10 | maven { url 'https://www.jitpack.io' }
11 | }
12 | }
13 | ```
14 | add implementation
15 | ``` groovy
16 | dependencies {
17 | implementation 'com.github.yellowcath:YcShareElement:1.3.2'
18 | //for androidx
19 | implementation 'com.github.yellowcath:YcShareElement:1.3.2.x'
20 | }
21 | ```
22 |
23 | ## Usage
24 | >demo里用了
25 | [GSYVideoPlayer](https://github.com/CarGuo/GSYVideoPlayer)展示视频
26 | [Fresco](https://github.com/facebook/fresco)、[Glide](https://github.com/bumptech/glide)展示图片
27 |
28 | YcShareElement提供了两个demo,一个是上面的联系人demo,另一个实现了图片、视频混合的列表页与详情页之间的ShareElement动画,如下图
29 |
30 | 
31 |
32 | 这里面的关键点如下:
33 | 1、Glide图片的ShareElement动画
34 | ImageView在动画过程中要经历默认背景色->小缩略图->大图三个阶段,如何在这三个阶段里做到无缝切换
35 | 参考:[ChangeOnlineImageTransition](https://github.com/yellowcath/YcShareElement/blob/master/ycshareelement/src/main/java/com/hw/ycshareelement/transition/ChangeOnlineImageTransition.java)
36 | 2、Fresco图片的ShareElement动画
37 | Fresco提供了内置的DraweeTransition,但是如果设置了缩略图,图片就会变形,并且必须在构造函数里提供动画起始的ScaleType信息,简单的情况很好用,在复杂的情况下不太友好
38 | 参考:[AdvancedDraweeTransition](https://github.com/yellowcath/YcShareElement/blob/master/app/src/main/java/us/pinguo/shareelementdemo/advanced/list/AdvancedDraweeTransition.java)
39 | 3、从列表的Webp动图到详情页的视频ShareElement动画
40 | 这个在实现了以上两点之后其实就很简单了,实际上就是视频的封面图做动画
41 |
42 | ### 普通页面使用步骤
43 |
44 | #### 1、打开WindowContentTransition开关
45 | ``` java
46 | YcShareElement.enableContentTransition(getApplication());
47 | ```
48 | 由于这个开关默认是打开的,因此这一句是可选的,担心遇到奇葩手机关掉这个开关的可以调用
49 | #### 2、生成Bundle,然后startActivity
50 | ``` java
51 | private void gotoDetailActivity(){
52 | Intent intent = new Intent(this, DetailActivity.class);
53 | Bundle bundle = YcShareElement.buildOptionsBundle(ContactActivity.this, new IShareElements() {
54 | @Override
55 | public ShareElementInfo[] getShareElements() {
56 | return new ShareElementInfo[]{new ShareElementInfo(mAvatarImg),
57 | new ShareElementInfo(mNameTxt, new TextViewStateSaver())};
58 | }
59 | });
60 | ActivityCompat.startActivity(ContactActivity.this, intent, bundle);
61 | }
62 | ```
63 | #### 3、新的页面里设置并启动Transition
64 | ``` java
65 | public class DetailActivity extends Activity {
66 | @Override
67 | protected void onCreate(@Nullable Bundle savedInstanceState) {
68 | ...
69 | YcShareElement.setEnterTransition(this, new IShareElements() {
70 | @Override
71 | public ShareElementInfo[] getShareElements() {
72 | return new ShareElementInfo[]{new ShareElementInfo(avatarImg),
73 | new ShareElementInfo(nameTxt, new TextViewStateSaver())};
74 | }
75 | });
76 | YcShareElement.startTransition(this);
77 | }
78 | }
79 | ```
80 | >YcShareElement.setEnterTransition()默认会暂停Activity的Transtion动画,直到调用YcShareElement.startTransition(),
81 | 在这种不需要等待ShareElement加载的简单页面,可以将第三个参数传false,就不会暂停ActivityB的Transition动画了,如下
82 |
83 | ``` java
84 | protected void onCreate(@Nullable Bundle savedInstanceState) {
85 | ...
86 | YcShareElement.setEnterTransition(this, new IShareElements() {
87 | @Override
88 | public ShareElementInfo[] getShareElements() {
89 | return new ShareElementInfo[]{new ShareElementInfo(avatarImg),
90 | new ShareElementInfo(nameTxt, new TextViewStateSaver())};
91 | }
92 | },false);
93 | }
94 | ```
95 |
96 | 效果如下:
97 | 
98 |
99 | ### 图片&视频页面使用步骤
100 |
101 | #### 1、打开WindowContentTransition开关
102 | ``` java
103 | YcShareElement.enableContentTransition(getApplication());
104 | ```
105 | #### 2、生成Bundle,然后startActivity
106 | ``` java
107 | Bundle options = YcShareElement.buildOptionsBundle(getActivity(), this);
108 | startActivityForResult(intent, REQUEST_CONTENT, options);
109 | ```
110 | #### 3、Activity B设置Transtion动画
111 | ``` java
112 | protected void onCreate(@Nullable Bundle savedInstanceState) {
113 | YcShareElement.setEnterTransition(this, this);
114 | ...
115 | }
116 | ```
117 | #### 4、Activity B的ViewPager加载好之后启动Transition
118 | ``` java
119 | @Override
120 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
121 | ...加载数据...
122 | YcShareElement.postStartTransition(getActivity());
123 | }
124 | ```
125 | 这时候进入动画就执行完毕了,接下来要处理滑动若干页之后返回列表页的情况
126 |
127 | #### 5、Activity B实现finishAfterTransition()函数
128 | ``` java
129 | @Override
130 | public void finishAfterTransition() {
131 | YcShareElement.finishAfterTransition(this, this);
132 | super.finishAfterTransition();
133 | }
134 | ```
135 | #### 6、Activity A实现onActivityReenter()函数
136 | ``` java
137 | @Override
138 | public void onActivityReenter(int resultCode, Intent data) {
139 | super.onActivityReenter(resultCode, data);
140 | YcShareElement.onActivityReenter(this, resultCode, data, new IShareElementSelector() {
141 | @Override
142 | public void selectShareElements(List list) {
143 | //将列表页滑动到变更后的ShareElement的位置
144 | mFragment.selectShareElement(list.get(0));
145 | }
146 | });
147 | }
148 | ```
149 |
150 | ### 如何扩展支持自定义View的Transition动画
151 | 这里以Fresco为例介绍如何进行扩展
152 |
153 | #### 1、确定所需参数
154 | 首先确定SimpleDraweeView做Transtion动画需要的参数,即ActualImageScaleType
155 | #### 2、继承ViewStateSaver,获取所需参数
156 | ``` java
157 | public class FrescoViewStateSaver extends ViewStateSaver {
158 |
159 | @Override
160 | protected void captureViewInfo(View view, Bundle bundle) {
161 | if (view instanceof GenericDraweeView) {
162 | int actualScaleTypeInt = scaleTypeToInt(((GenericDraweeView)view).getHierarchy().getActualImageScaleType())
163 | bundle.putInt("scaleType",actualScaleTypeInt);
164 | }
165 | }
166 |
167 | public ScalingUtils.ScaleType getScaleType(Bundle bundle) {
168 | int scaleType = bundle.getInt("scaleType", 0);
169 | return intToScaleType(scaleType);
170 | }
171 | }
172 | ```
173 | #### 3、自定义Transition
174 | ``` java
175 | public class AdvancedDraweeTransition extends Transition {
176 | private ScalingUtils.ScaleType mFromScale;
177 | private ScalingUtils.ScaleType mToScale;
178 |
179 | public AdvancedDraweeTransition() {
180 | addTarget(GenericDraweeView.class);
181 | }
182 |
183 | @Override
184 | public void captureStartValues(TransitionValues transitionValues) {
185 | ...
186 | ShareElementInfo shareElementInfo = ShareElementInfo.getFromView(transitionValues.view);
187 | mFromScale = ((FrescoViewStateSaver) shareElementInfo.getViewStateSaver()).getScaleType(viewInfo);
188 | ...
189 | }
190 |
191 | @Override
192 | public void captureEndValues(TransitionValues transitionValues) {
193 | ...
194 | ShareElementInfo shareElementInfo = ShareElementInfo.getFromView(transitionValues.view);
195 | mToScale = ((FrescoViewStateSaver) shareElementInfo.getViewStateSaver()).getScaleType(viewInfo);
196 | ...
197 | }
198 |
199 | @Override
200 | public Animator createAnimator(
201 | ViewGroup sceneRoot,
202 | TransitionValues startValues,
203 | TransitionValues endValues) {
204 | ..
205 | ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
206 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
207 | @Override
208 | public void onAnimationUpdate(ValueAnimator animation) {
209 | float fraction = (float) animation.getAnimatedValue();
210 | scaleType.setValue(fraction);
211 | if (draweeView.getHierarchy().getActualImageScaleType() != scaleType) {
212 | draweeView.getHierarchy().setActualImageScaleType(scaleType);
213 | }
214 | }
215 | });
216 | ...
217 | return animator;
218 | }
219 | }
220 | ```
221 | #### 4、使用自定义的Transition
222 | ``` java
223 | public class FrescoShareElementTransitionfactory extends DefaultShareElementTransitionFactory {
224 | @Override
225 | protected TransitionSet buildShareElementsTransition(List shareViewList) {
226 | TransitionSet transitionSet = super.buildShareElementsTransition(shareViewList);
227 | transitionSet.addTransition(new AdvancedDraweeTransition());
228 | return transitionSet;
229 | }
230 | }
231 | ```
232 | ``` java
233 | @Override
234 | protected void onCreate(@Nullable Bundle savedInstanceState) {
235 | ...
236 | YcShareElement.setEnterTransitions(this, this,true,new FrescoShareElementTransitionfactory());
237 | ...
238 | }
239 | ```
240 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | defaultConfig {
6 | applicationId "us.pinguo.shareelementdemo"
7 | minSdkVersion 21
8 | targetSdkVersion 29
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | splits {
20 | abi {
21 | enable true
22 | reset()
23 | include 'x86', 'armeabi-v7a'
24 | universalApk false
25 | }
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(include: ['*.jar'], dir: 'libs')
31 | implementation 'androidx.appcompat:appcompat:1.0.0'
32 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
33 |
34 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
35 | testImplementation 'junit:junit:4.12'
36 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
37 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
38 | implementation 'androidx.recyclerview:recyclerview:1.0.0'
39 |
40 | implementation "com.facebook.fresco:fresco:1.4.0"
41 | implementation "com.facebook.fresco:webpsupport:1.4.0"
42 | implementation "com.facebook.fresco:animated-webp:1.4.0"
43 |
44 | implementation 'com.github.bumptech.glide:glide:4.11.0'
45 | annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
46 |
47 | implementation 'com.shuyu:gsyVideoPlayer-java:6.0.0-beta'
48 | implementation 'com.shuyu:gsyVideoPlayer-armv7a:6.0.0-beta'
49 | implementation 'com.shuyu:gsyVideoPlayer-x86:6.0.0-beta'
50 |
51 | implementation project(path: ':ycshareelement')
52 | }
53 |
--------------------------------------------------------------------------------
/app/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/us/pinguo/shareelementdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package us.pinguo.shareelementdemo;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("us.pinguo.shareelementdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/us/pinguo/shareelementdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package us.pinguo.shareelementdemo;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import androidx.appcompat.app.AppCompatActivity;
6 | import android.view.View;
7 | import com.hw.ycshareelement.YcShareElement;
8 | import us.pinguo.shareelementdemo.advanced.AdvancedListActivity;
9 | import us.pinguo.shareelementdemo.contacts.ContactsActivity;
10 |
11 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | YcShareElement.enableContentTransition(getApplication());
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 |
19 | // findViewById(R.id.simple_fragment_btn).setOnClickListener(this);
20 | findViewById(R.id.simple_activity_btn).setOnClickListener(this);
21 | findViewById(R.id.recyclerview_btn).setOnClickListener(this);
22 | }
23 |
24 |
25 | @Override
26 | public void onClick(View v) {
27 | switch (v.getId()) {
28 | // case R.id.simple_fragment_btn:
29 | // startActivity(new Intent(this, SimpleFragmentActivity.class));
30 | // break;
31 | case R.id.simple_activity_btn:
32 | startActivity(new Intent(this, ContactsActivity.class));
33 | break;
34 | case R.id.recyclerview_btn:
35 | startActivity(new Intent(this, AdvancedListActivity.class));
36 | break;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/us/pinguo/shareelementdemo/SecondActivity.java:
--------------------------------------------------------------------------------
1 | package us.pinguo.shareelementdemo;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | /**
6 | * Created by huangwei on 2018/9/18 0018.
7 | */
8 | public class SecondActivity extends AppCompatActivity {
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/java/us/pinguo/shareelementdemo/advanced/AdvancedContentActivity.java:
--------------------------------------------------------------------------------
1 | package us.pinguo.shareelementdemo.advanced;
2 |
3 | import android.graphics.drawable.ColorDrawable;
4 | import android.os.Bundle;
5 | import androidx.annotation.Nullable;
6 | import androidx.appcompat.app.AppCompatActivity;
7 | import com.hw.ycshareelement.YcShareElement;
8 | import com.hw.ycshareelement.transition.IShareElements;
9 | import com.hw.ycshareelement.transition.ShareElementInfo;
10 | import us.pinguo.shareelementdemo.R;
11 | import us.pinguo.shareelementdemo.advanced.list.FrescoShareElementTransitionfactory;
12 |
13 | /**
14 | * Created by huangwei on 2018/9/18 0018.
15 | */
16 | public class AdvancedContentActivity extends AppCompatActivity implements IShareElements {
17 |
18 | AdvancedContentFragment mFragment;
19 |
20 | @Override
21 | protected void onCreate(@Nullable Bundle savedInstanceState) {
22 | YcShareElement.setEnterTransitions(this, this,true,new FrescoShareElementTransitionfactory());
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_simple);
25 | getWindow().setBackgroundDrawable(new ColorDrawable(0xFF323232));
26 | mFragment = new AdvancedContentFragment();
27 | mFragment.setArguments(getIntent().getExtras());
28 | getSupportFragmentManager().beginTransaction().add(R.id.simple_container, mFragment).commit();
29 | }
30 |
31 | @Override
32 | public void finishAfterTransition() {
33 | YcShareElement.finishAfterTransition(this, this);
34 | super.finishAfterTransition();
35 | }
36 |
37 | @Override
38 | public ShareElementInfo[] getShareElements() {
39 | return mFragment.getShareElements();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/us/pinguo/shareelementdemo/advanced/AdvancedContentFragment.java:
--------------------------------------------------------------------------------
1 | package us.pinguo.shareelementdemo.advanced;
2 |
3 | import android.os.Bundle;
4 | import android.os.Parcelable;
5 | import androidx.annotation.NonNull;
6 | import androidx.annotation.Nullable;
7 | import androidx.fragment.app.Fragment;
8 | import androidx.viewpager.widget.ViewPager;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import com.hw.ycshareelement.YcShareElement;
13 | import com.shuyu.gsyvideoplayer.GSYVideoManager;
14 | import us.pinguo.shareelementdemo.advanced.content.BaseContentCell;
15 | import us.pinguo.shareelementdemo.advanced.content.BitmapThumbnail;
16 | import us.pinguo.shareelementdemo.advanced.content.ImageContentCell;
17 | import us.pinguo.shareelementdemo.advanced.content.ImageFrescoContentCell;
18 | import us.pinguo.shareelementdemo.advanced.content.VideoContentCell;
19 | import us.pinguo.shareelementdemo.advanced.content.viewpager.BasePagerAdapter;
20 | import com.hw.ycshareelement.transition.ShareElementInfo;
21 |
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | /**
26 | * Created by huangwei on 2018/9/18 0018.
27 | */
28 | public class AdvancedContentFragment extends Fragment implements ViewPager.OnPageChangeListener {
29 |
30 | private ViewPager mViewPager;
31 | private BasePagerAdapter mAdapter;
32 | private VideoContentCell mPlayingCell;
33 |
34 | @Nullable
35 | @Override
36 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
37 | return new ViewPager(container.getContext());
38 | }
39 |
40 | @Override
41 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
42 | super.onViewCreated(view, savedInstanceState);
43 | mViewPager = (ViewPager) view;
44 | mAdapter = new BasePagerAdapter();
45 | mViewPager.addOnPageChangeListener(this);
46 | initCells();
47 | YcShareElement.postStartTransition(getActivity());
48 | }
49 |
50 | private void initCells() {
51 | ArrayList dataList = getArguments().getParcelableArrayList(AdvancedListFragment.KEY_DATA);
52 | int select = getArguments().getInt(AdvancedListFragment.KEY_SELECT, 0);
53 | List cellList = new ArrayList<>(dataList.size());
54 | for (int i = 0; i < dataList.size(); i++) {
55 | Parcelable data = dataList.get(i);
56 | if (data instanceof Image) {
57 | BaseContentCell contentCell = ((Image) data).isShowInFresco() ? new ImageFrescoContentCell((Image) data) : new ImageContentCell((Image) data);
58 | cellList.add(contentCell);
59 | } else if (data instanceof Video) {
60 | cellList.add(new VideoContentCell((Video) data));
61 | }
62 | }
63 | mAdapter.addItems(cellList);
64 | mViewPager.setAdapter(mAdapter);
65 | mViewPager.setCurrentItem(select);
66 | }
67 |
68 | @Override
69 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
70 |
71 | }
72 |
73 | @Override
74 | public void onPageSelected(int position) {
75 | if (mPlayingCell != null) {
76 | try {
77 | GSYVideoManager.instance().stop();
78 | } catch (IllegalStateException e) {
79 | e.printStackTrace();
80 | }
81 | }
82 | if (mAdapter.getItem(position) instanceof VideoContentCell) {
83 | mPlayingCell = ((VideoContentCell) mAdapter.getItem(position));
84 | mPlayingCell.startPlay();
85 | } else {
86 | mPlayingCell = null;
87 | }
88 | }
89 |
90 | @Override
91 | public void onPageScrollStateChanged(int state) {
92 |
93 | }
94 |
95 | @Override
96 | public void onPause() {
97 | if (mPlayingCell != null) {
98 | GSYVideoManager.instance().pause();
99 | }
100 | super.onPause();
101 | }
102 |
103 | @Override
104 | public void onResume() {
105 | if (mPlayingCell != null) {
106 | GSYVideoManager.instance().start();
107 | }
108 | super.onResume();
109 | }
110 |
111 | @Override
112 | public void onDestroy() {
113 | super.onDestroy();
114 | }
115 |
116 | public ShareElementInfo[] getShareElements() {
117 | BaseContentCell item = (BaseContentCell) mAdapter.getItem(mViewPager.getCurrentItem());
118 | if (item != null) {
119 | BaseData baseData = (BaseData) item.getData();
120 | if (item instanceof ImageFrescoContentCell) {
121 | ShareElementInfo info = new ShareElementInfo(item.getShareElement(), baseData, new FrescoViewStateSaver());
122 | return new ShareElementInfo[]{info};
123 | } else {
124 | return new ShareElementInfo[]{new ShareElementInfo(item.getShareElement(), baseData)};
125 | }
126 | }
127 | return new ShareElementInfo[0];
128 | }
129 |
130 | @Override
131 | public void onDestroyView() {
132 | super.onDestroyView();
133 | BitmapThumbnail.clear();
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/app/src/main/java/us/pinguo/shareelementdemo/advanced/AdvancedListActivity.java:
--------------------------------------------------------------------------------
1 | package us.pinguo.shareelementdemo.advanced;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import androidx.annotation.Nullable;
6 | import androidx.appcompat.app.AppCompatActivity;
7 | import com.facebook.drawee.backends.pipeline.Fresco;
8 | import com.hw.ycshareelement.YcShareElement;
9 | import us.pinguo.shareelementdemo.R;
10 | import com.hw.ycshareelement.transition.IShareElementSelector;
11 | import com.hw.ycshareelement.transition.ShareElementInfo;
12 |
13 | import java.util.List;
14 |
15 | /**
16 | * Created by huangwei on 2018/9/18 0018.
17 | */
18 | public class AdvancedListActivity extends AppCompatActivity {
19 | private AdvancedListFragment mFragment;
20 |
21 | @Override
22 | protected void onCreate(@Nullable Bundle savedInstanceState) {
23 | YcShareElement.enableContentTransition(getApplication());
24 | super.onCreate(savedInstanceState);
25 | Fresco.initialize(getApplicationContext());
26 | setContentView(R.layout.activity_simple);
27 | mFragment = new AdvancedListFragment();
28 | getSupportFragmentManager().beginTransaction().add(R.id.simple_container, mFragment).commit();
29 | }
30 |
31 | @Override
32 | public void onActivityReenter(int resultCode, Intent data) {
33 | super.onActivityReenter(resultCode, data);
34 | YcShareElement.onActivityReenter(this, resultCode, data, new IShareElementSelector() {
35 | @Override
36 | public void selectShareElements(List list) {
37 | mFragment.selectShareElement(list.get(0));
38 | }
39 | });
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/us/pinguo/shareelementdemo/advanced/AdvancedListFragment.java:
--------------------------------------------------------------------------------
1 | package us.pinguo.shareelementdemo.advanced;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Bitmap;
5 | import android.os.Bundle;
6 | import android.os.Parcelable;
7 | import androidx.annotation.NonNull;
8 | import androidx.annotation.Nullable;
9 | import androidx.fragment.app.Fragment;
10 | import androidx.recyclerview.widget.GridLayoutManager;
11 | import androidx.recyclerview.widget.RecyclerView;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import com.hw.ycshareelement.YcShareElement;
16 | import us.pinguo.shareelementdemo.R;
17 | import us.pinguo.shareelementdemo.advanced.content.BitmapThumbnail;
18 | import us.pinguo.shareelementdemo.advanced.list.AdvancedListAdapter;
19 | import us.pinguo.shareelementdemo.advanced.list.BaseListCell;
20 | import us.pinguo.shareelementdemo.advanced.list.ImageFrescoListCell;
21 | import us.pinguo.shareelementdemo.advanced.list.ImageListCell;
22 | import us.pinguo.shareelementdemo.advanced.list.ShareContentInfo;
23 | import us.pinguo.shareelementdemo.advanced.list.VideoListCell;
24 | import com.hw.ycshareelement.transition.IShareElements;
25 | import com.hw.ycshareelement.transition.ShareElementInfo;
26 |
27 | import java.util.ArrayList;
28 | import java.util.LinkedList;
29 | import java.util.List;
30 |
31 | /**
32 | * Created by huangwei on 2018/9/18 0018.
33 | */
34 | public class AdvancedListFragment extends Fragment implements BaseListCell.OnCellClickListener, IShareElements {
35 | public static final String KEY_DATA = "data";
36 | public static final String KEY_SELECT = "select";
37 |
38 | static final int REQUEST_CONTENT = 223;
39 |
40 | private RecyclerView mRecyclerView;
41 | private AdvancedListAdapter mAdapter;
42 | private ArrayList mDataList = new ArrayList<>();
43 | private BaseListCell mTransitionCell;
44 |
45 | @Nullable
46 | @Override
47 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
48 | return new RecyclerView(container.getContext());
49 | }
50 |
51 | @Override
52 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
53 | super.onViewCreated(view, savedInstanceState);
54 | mRecyclerView = (RecyclerView) view;
55 | mRecyclerView.setBackgroundColor(0xFF323232);
56 | mAdapter = new AdvancedListAdapter();
57 | mRecyclerView.setAdapter(mAdapter);
58 | int divider = getResources().getDimensionPixelSize(R.dimen.divider);
59 | mRecyclerView.setPadding(divider/2,divider/2,divider/2,divider/2);
60 | RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getActivity(),2);
61 |
62 | mRecyclerView.setLayoutManager(layoutManager);
63 | mRecyclerView.addItemDecoration(new SpaceItemDecoration(divider));
64 | initCells();
65 | }
66 |
67 | private void initCells() {
68 | List cellList = new LinkedList<>();
69 | mDataList.add(new Image("https://phototask.c360dn.com/Fl-0qph8x14uLb2JwRzko8fOmfqw", 1024, 738).setShowInFresco(true));
70 | mDataList.add(new Image("https://phototask.c360dn.com/FuOUEYx1YLf9gUAykzueD9TzX8Lq", 1280, 800));
71 | mDataList.add(new Video("https://phototask.c360dn.com/lm7e8LQIsnHteaGlkv6Q6lu05ri8",
72 | "https://phototask.c360dn.com/lm7e8LQIsnHteaGlkv6Q6lu05ri8-2018081621-preview.webp",
73 | 720, 1280));
74 | mDataList.add(new Image("https://phototask.c360dn.com/Fo9D8NQqmbs3AAQASxnkPZRHF5Hv", 720, 1280));
75 | mDataList.add(new Video("https://phototask.c360dn.com/lm7F9EhP3DVTVtMqOD6rkx7w6TwW",
76 | "https://phototask.c360dn.com/lm7F9EhP3DVTVtMqOD6rkx7w6TwW-2018040715-preview.webp",
77 | 640, 1138));
78 | mDataList.add(new Image("https://phototask.c360dn.com/FhGeGKwB9Z6WvuaINQOuc7wm4vvj", 1600, 1280));
79 | mDataList.add(new Video("https://phototask.c360dn.com/lqYmdnp4cWoz35jp8BTSPXIXfq9s",
80 | "https://phototask.c360dn.com/lqYmdnp4cWoz35jp8BTSPXIXfq9s-2018082319-preview.webp",
81 | 640, 854));
82 | mDataList.add(new Image("https://phototask.c360dn.com/Fn8kpRh_rarrSMIoEnnEPadNOuWi", 720, 1280));
83 |
84 | mDataList.add(new Video("https://phototask.c360dn.com/lpNwvBcfABEhJVfEkUvPfPRvA7KF",
85 | "https://phototask.c360dn.com/lpNwvBcfABEhJVfEkUvPfPRvA7KF-2018082620-preview.webp",
86 | 640, 1138));
87 | mDataList.add(new Image("https://phototask.c360dn.com/Fn3915H5n7AhYKJdpdlNjSbfPC5e", 1024, 640));
88 | mDataList.add(new Video("https://phototask.c360dn.com/luqJVmntp51TIcdzGJviz0erj9l9",
89 | "https://phototask.c360dn.com/luqJVmntp51TIcdzGJviz0erj9l9-2018090108-preview.webp",
90 | 640, 1138));
91 | mDataList.add(new Image("https://phototask.c360dn.com/FsOmrix9LiKJXKqi4vOU7fbUmlbQ", 1080, 960));
92 |
93 | for (Parcelable data : mDataList) {
94 | BaseListCell cell = data instanceof Image ?
95 | (((Image) data).isShowInFresco()?new ImageFrescoListCell((Image)data):new ImageListCell((Image) data))
96 | : new VideoListCell((Video) data);
97 | cell.setOnCellClickListener(this);
98 | cellList.add(cell);
99 | }
100 | mAdapter.setList(cellList);
101 | }
102 |
103 | @Override
104 | public void onCellClick(BaseListCell cell) {
105 | mTransitionCell = cell;
106 | Intent intent = new Intent(getActivity(), AdvancedContentActivity.class);
107 | intent.putParcelableArrayListExtra(KEY_DATA, mDataList);
108 | intent.putExtra(KEY_SELECT, mDataList.indexOf(cell.getData()));
109 | Bitmap thumbnail = mTransitionCell.getThumbnail();
110 | if(thumbnail!=null) {
111 | BitmapThumbnail.sBitmap = thumbnail;
112 | BitmapThumbnail.sKey = mTransitionCell.getData().url;
113 | }
114 | Bundle options = YcShareElement.buildOptionsBundle(getActivity(), this);
115 | startActivityForResult(intent, REQUEST_CONTENT, options);
116 | }
117 |
118 | @Override
119 | public void onDestroyView() {
120 | super.onDestroyView();
121 | for (int i = 0; i < mAdapter.getItemCount(); i++) {
122 | BaseListCell cell = (BaseListCell) mAdapter.getItem(i);
123 | cell.setOnCellClickListener(null);
124 | }
125 | }
126 |
127 | @Override
128 | public ShareElementInfo[] getShareElements() {
129 | if (mTransitionCell instanceof VideoListCell) {
130 | BaseData data = mTransitionCell.getData();
131 | ShareElementInfo info = new ShareContentInfo(mTransitionCell.getShareElement(), data);
132 | return new ShareElementInfo[]{info};
133 | } else if (mTransitionCell instanceof ImageListCell) {
134 | BaseData data = mTransitionCell.getData();
135 | ShareElementInfo info;
136 | if(mTransitionCell instanceof ImageFrescoListCell){
137 | info = new ShareElementInfo(mTransitionCell.getShareElement(), data, new FrescoViewStateSaver());
138 | }else{
139 | info = new ShareContentInfo(mTransitionCell.getShareElement(), data);
140 | }
141 | return new ShareElementInfo[]{info};
142 | }
143 | return new ShareElementInfo[0];
144 | }
145 |
146 | public void selectShareElement(ShareElementInfo shareElementInfo) {
147 | BaseData data = (BaseData) shareElementInfo.getData();
148 | for (int i = 0; i < mAdapter.getItemCount(); i++) {
149 | BaseListCell cell = mAdapter.getItem(i);
150 | if (cell.getData().equals(data)) {
151 | mTransitionCell = cell;
152 | GridLayoutManager layoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager();
153 | layoutManager.scrollToPosition(i);
154 | return;
155 | }
156 | }
157 |
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/app/src/main/java/us/pinguo/shareelementdemo/advanced/BaseData.java:
--------------------------------------------------------------------------------
1 | package us.pinguo.shareelementdemo.advanced;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import java.util.Objects;
7 |
8 | /**
9 | * Created by huangwei on 2018/9/22.
10 | */
11 | public class BaseData implements Parcelable {
12 | public String url;
13 | public int width;
14 | public int height;
15 |
16 | public BaseData(String url, int width, int height) {
17 | this.url = url;
18 | this.width = width;
19 | this.height = height;
20 | }
21 |
22 |
23 | @Override
24 | public boolean equals(Object o) {
25 | if (this == o) {
26 | return true;
27 | }
28 | if (o == null || getClass() != o.getClass()) {
29 | return false;
30 | }
31 | BaseData baseData = (BaseData) o;
32 | return width == baseData.width &&
33 | height == baseData.height &&
34 | Objects.equals(url, baseData.url);
35 | }
36 |
37 | @Override
38 | public int hashCode() {
39 |
40 | return Objects.hash(url, width, height);
41 | }
42 |
43 | @Override
44 | public int describeContents() {
45 | return 0;
46 | }
47 |
48 | @Override
49 | public void writeToParcel(Parcel dest, int flags) {
50 | dest.writeString(this.url);
51 | dest.writeInt(this.width);
52 | dest.writeInt(this.height);
53 | }
54 |
55 | protected BaseData(Parcel in) {
56 | this.url = in.readString();
57 | this.width = in.readInt();
58 | this.height = in.readInt();
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/us/pinguo/shareelementdemo/advanced/FrescoViewStateSaver.java:
--------------------------------------------------------------------------------
1 | package us.pinguo.shareelementdemo.advanced;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import com.facebook.drawee.drawable.ScalingUtils;
6 | import com.facebook.drawee.view.GenericDraweeView;
7 | import com.hw.ycshareelement.transition.ViewStateSaver;
8 |
9 | /**
10 | * Created by huangwei on 2018/10/7.
11 | */
12 | public class FrescoViewStateSaver extends ViewStateSaver {
13 |
14 | public ScalingUtils.ScaleType getScaleType(Bundle bundle) {
15 | int scaleType = bundle.getInt("scaleType", 0);
16 | return intToScaleType(scaleType);
17 | }
18 |
19 | @Override
20 | protected void captureViewInfo(View view, Bundle bundle) {
21 | if (view instanceof GenericDraweeView) {
22 | bundle.putInt("scaleType", scaleTypeToInt(((GenericDraweeView) view).getHierarchy().getActualImageScaleType()));
23 | }
24 | }
25 |
26 | private ScalingUtils.ScaleType intToScaleType(int index) {
27 | switch (index) {
28 | case 0:
29 | return ScalingUtils.ScaleType.CENTER_CROP;
30 | case 1:
31 | return ScalingUtils.ScaleType.CENTER;
32 | case 2:
33 | return ScalingUtils.ScaleType.CENTER_INSIDE;
34 | case 3:
35 | return ScalingUtils.ScaleType.FIT_CENTER;
36 | case 4:
37 | return ScalingUtils.ScaleType.FIT_END;
38 | case 5:
39 | return ScalingUtils.ScaleType.FIT_START;
40 | case 6:
41 | return ScalingUtils.ScaleType.FIT_XY;
42 | case 7:
43 | return ScalingUtils.ScaleType.FOCUS_CROP;
44 | default:
45 | return ScalingUtils.ScaleType.CENTER;
46 | }
47 | }
48 |
49 | private int scaleTypeToInt(ScalingUtils.ScaleType scaleType) {
50 | if (scaleType == ScalingUtils.ScaleType.CENTER_CROP) {
51 | return 0;
52 | } else if (scaleType == ScalingUtils.ScaleType.CENTER) {
53 | return 1;
54 | } else if (scaleType == ScalingUtils.ScaleType.CENTER_INSIDE) {
55 | return 2;
56 | } else if (scaleType == ScalingUtils.ScaleType.FIT_CENTER) {
57 | return 3;
58 | } else if (scaleType == ScalingUtils.ScaleType.FIT_END) {
59 | return 4;
60 | } else if (scaleType == ScalingUtils.ScaleType.FIT_START) {
61 | return 5;
62 | } else if (scaleType == ScalingUtils.ScaleType.FIT_XY) {
63 | return 6;
64 | } else if (scaleType == ScalingUtils.ScaleType.FOCUS_CROP) {
65 | return 7;
66 | }
67 | return -1;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/us/pinguo/shareelementdemo/advanced/Image.java:
--------------------------------------------------------------------------------
1 | package us.pinguo.shareelementdemo.advanced;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * Created by huangwei on 2018/9/19 0019.
8 | */
9 | public class Image extends BaseData{
10 |
11 | private boolean mShowInFresco;
12 |
13 | public Image(String url, int width, int height) {
14 | super(url, width, height);
15 | }
16 |
17 | public boolean isShowInFresco() {
18 | return mShowInFresco;
19 | }
20 |
21 | public Image setShowInFresco(boolean showInFresco) {
22 | mShowInFresco = showInFresco;
23 | return this;
24 | }
25 |
26 | @Override
27 | public int describeContents() {
28 | return 0;
29 | }
30 |
31 | @Override
32 | public void writeToParcel(Parcel dest, int flags) {
33 | super.writeToParcel(dest, flags);
34 | dest.writeByte(this.mShowInFresco ? (byte) 1 : (byte) 0);
35 | }
36 |
37 | protected Image(Parcel in) {
38 | super(in);
39 | this.mShowInFresco = in.readByte() != 0;
40 | }
41 |
42 | public static final Creator CREATOR = new Creator() {
43 | @Override
44 | public Image createFromParcel(Parcel source) {
45 | return new Image(source);
46 | }
47 |
48 | @Override
49 | public Image[] newArray(int size) {
50 | return new Image[size];
51 | }
52 | };
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/us/pinguo/shareelementdemo/advanced/SpaceItemDecoration.java:
--------------------------------------------------------------------------------
1 | package us.pinguo.shareelementdemo.advanced;
2 |
3 | import android.graphics.Rect;
4 | import androidx.recyclerview.widget.GridLayoutManager;
5 | import androidx.recyclerview.widget.RecyclerView;
6 |
7 | import android.view.View;
8 |
9 | /**
10 | * Created by huangwei on 2018/9/19 0019.
11 | */
12 | public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
13 |
14 | private int mSpace;
15 |
16 | public SpaceItemDecoration(int space) {
17 | mSpace = space;
18 | }
19 |
20 | @Override
21 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
22 | super.getItemOffsets(outRect, view, parent, state);
23 | GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams) view.getLayoutParams();
24 | lp.topMargin = mSpace/2;
25 | lp.leftMargin = mSpace/2;
26 | lp.rightMargin = mSpace/2;
27 | lp.bottomMargin = mSpace/2;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/us/pinguo/shareelementdemo/advanced/Video.java:
--------------------------------------------------------------------------------
1 | package us.pinguo.shareelementdemo.advanced;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * Created by huangwei on 2018/9/19 0019.
8 | */
9 | public class Video extends BaseData {
10 | public String webpUrl;
11 |
12 | public Video(String url,String webpUrl, int width, int height) {
13 | super(url, width, height);
14 | this.webpUrl = webpUrl;
15 | }
16 |
17 |
18 | @Override
19 | public int describeContents() {
20 | return 0;
21 | }
22 |
23 | @Override
24 | public void writeToParcel(Parcel dest, int flags) {
25 | super.writeToParcel(dest, flags);
26 | dest.writeString(this.webpUrl);
27 | }
28 |
29 | protected Video(Parcel in) {
30 | super(in);
31 | this.webpUrl = in.readString();
32 | }
33 |
34 | public static final Creator