forked from nickbutcher/plaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created StaggeredDistanceSlide transition & used where appropriate.
- Loading branch information
1 parent
f98b876
commit 0371370
Showing
6 changed files
with
133 additions
and
17 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
app/src/main/java/io/plaidapp/ui/transitions/StaggeredDistanceSlide.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2016 Google Inc. | ||
* | ||
* 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 io.plaidapp.ui.transitions; | ||
|
||
import android.animation.Animator; | ||
import android.animation.ObjectAnimator; | ||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.transition.TransitionValues; | ||
import android.transition.Visibility; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import io.plaidapp.R; | ||
|
||
/** | ||
* An alternative to {@link android.transition.Slide} which staggers elements by <b>distance</b> | ||
* rather than using start delays. That is elements start from/end at a progressively increasing | ||
* displacement such that they come together/move apart over the same duration as they enter/exit. | ||
* This can produce more cohesive choreography. The displacement factor can be controlled by the | ||
* {@code spread} attribute. | ||
* <p> | ||
* Currently only supports entering/exiting from the bottom edge. | ||
*/ | ||
public class StaggeredDistanceSlide extends Visibility { | ||
|
||
private static final String PROPNAME_SCREEN_LOCATION = "android:visibility:screenLocation"; | ||
|
||
private int spread = 1; | ||
|
||
public StaggeredDistanceSlide() { } | ||
|
||
public StaggeredDistanceSlide(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
final TypedArray a = | ||
context.obtainStyledAttributes(attrs, R.styleable.StaggeredDistanceSlide); | ||
spread = a.getInteger(R.styleable.StaggeredDistanceSlide_spread, spread); | ||
a.recycle(); | ||
} | ||
|
||
public int getSpread() { | ||
return spread; | ||
} | ||
|
||
public void setSpread(int spread) { | ||
this.spread = spread; | ||
} | ||
|
||
@Override | ||
public Animator onAppear(ViewGroup sceneRoot, View view, | ||
TransitionValues startValues, TransitionValues endValues) { | ||
int[] position = (int[]) endValues.values.get(PROPNAME_SCREEN_LOCATION); | ||
view.setTranslationY(sceneRoot.getHeight() + (position[1] * spread)); | ||
return ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, 0f); | ||
} | ||
|
||
@Override | ||
public Animator onDisappear(ViewGroup sceneRoot, View view, | ||
TransitionValues startValues, TransitionValues endValues) { | ||
int[] position = (int[]) endValues.values.get(PROPNAME_SCREEN_LOCATION); | ||
return ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, | ||
sceneRoot.getHeight() + (position[1] * spread)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/main/res/values/attrs_staggered_distance_slide.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2016 Google Inc. | ||
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. | ||
--> | ||
|
||
<resources> | ||
|
||
<declare-styleable name="StaggeredDistanceSlide"> | ||
<attr name="spread" format="integer" /> | ||
</declare-styleable> | ||
|
||
</resources> |