Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
262 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.ocnyang.stateanimation"/> | ||
package="com.ocnyang.stateanimation"> | ||
|
||
<application> | ||
<activity android:name=".StateAnimationActivity"> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
39 changes: 39 additions & 0 deletions
39
state-animation/src/main/java/com/ocnyang/stateanimation/StateAnimationActivity.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,39 @@ | ||
package com.ocnyang.stateanimation; | ||
|
||
import android.animation.AnimatorInflater; | ||
import android.animation.StateListAnimator; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.MenuItem; | ||
|
||
public class StateAnimationActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_state_animation); | ||
initToolbar(); | ||
setStateListAnimator(); | ||
} | ||
|
||
private void setStateListAnimator() { | ||
StateListAnimator stateListAnimator = AnimatorInflater.loadStateListAnimator(this, R.animator.anim_view_state_change_2); | ||
findViewById(R.id.view_puppet2).setStateListAnimator(stateListAnimator); | ||
} | ||
|
||
private void initToolbar() { | ||
Toolbar toolbar = ((Toolbar) findViewById(R.id.toolbar)); | ||
setSupportActionBar(toolbar); | ||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
int i = item.getItemId(); | ||
if (i == android.R.id.home) { | ||
finish(); | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
state-animation/src/main/res/anim/anim_view_state_change.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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:state_pressed="true"> | ||
<set> | ||
<objectAnimator | ||
android:duration="@android:integer/config_shortAnimTime" | ||
android:propertyName="translationZ" | ||
android:valueTo="7dp" | ||
android:valueType="floatType"/> | ||
</set> | ||
</item> | ||
|
||
<item | ||
android:state_pressed="false"> | ||
<set> | ||
<objectAnimator | ||
android:duration="100" | ||
android:propertyName="translationZ" | ||
android:valueTo="2dp" | ||
android:valueType="floatType"/> | ||
</set> | ||
</item> | ||
</selector> |
33 changes: 33 additions & 0 deletions
33
state-animation/src/main/res/animator/anim_view_state_change_2.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,33 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:state_pressed="true"> | ||
<set> | ||
<objectAnimator | ||
android:duration="@android:integer/config_shortAnimTime" | ||
android:propertyName="translationZ" | ||
android:valueTo="5dp" | ||
android:valueType="floatType"/> | ||
<objectAnimator | ||
android:duration="@android:integer/config_shortAnimTime" | ||
android:propertyName="rotationX" | ||
android:valueTo="10" | ||
android:valueType="floatType"/> | ||
</set> | ||
</item> | ||
|
||
<item | ||
android:state_pressed="false"> | ||
<set> | ||
<objectAnimator | ||
android:duration="100" | ||
android:propertyName="translationZ" | ||
android:valueTo="2dp" | ||
android:valueType="floatType"/> | ||
<objectAnimator | ||
android:duration="@android:integer/config_shortAnimTime" | ||
android:propertyName="rotationX" | ||
android:valueTo="0" | ||
android:valueType="floatType"/> | ||
</set> | ||
</item> | ||
</selector> |
100 changes: 100 additions & 0 deletions
100
state-animation/src/main/res/drawable/bg_animated_statelist_drawable.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,100 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<animated-selector | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<!-- provide a different drawable for each state --> | ||
<item | ||
android:id="@+id/pressed" | ||
android:drawable="@drawable/img29" | ||
android:state_pressed="true"/> | ||
<!-- <item | ||
android:id="@+id/focused" | ||
android:drawable="@drawable/btn_focused" | ||
android:state_focused="true"/> --> | ||
<item | ||
android:id="@id/default1" | ||
android:drawable="@drawable/img1"/> | ||
|
||
<!-- specify a transition --> | ||
<transition | ||
android:fromId="@+id/default1" | ||
android:toId="@+id/pressed"> | ||
<animation-list> | ||
<item | ||
android:drawable="@drawable/img2" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img3" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img4" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img5" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img6" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img7" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img8" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img9" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img10" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img13" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img14" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img15" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img17" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img18" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img19" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img20" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img21" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img22" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img23" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img24" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img25" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img26" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img27" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img28" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@drawable/img29" | ||
android:duration="100"/> | ||
</animation-list> | ||
</transition> | ||
</animated-selector> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
state-animation/src/main/res/layout/activity_state_animation.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,47 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context="com.ocnyang.stateanimation.StateAnimationActivity"> | ||
|
||
<android.support.v7.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:background="?attr/colorPrimary" | ||
android:minHeight="?attr/actionBarSize"/> | ||
|
||
<TextView | ||
android:id="@+id/view_puppet1" | ||
android:layout_width="200dp" | ||
android:layout_height="80dp" | ||
android:layout_gravity="center_horizontal" | ||
android:layout_margin="15dp" | ||
android:background="@android:color/white" | ||
android:clickable="true" | ||
android:stateListAnimator="@anim/anim_view_state_change"/> | ||
|
||
<TextView | ||
android:id="@+id/view_puppet2" | ||
android:layout_width="200dp" | ||
android:layout_height="80dp" | ||
android:layout_gravity="center_horizontal" | ||
android:layout_margin="15dp" | ||
android:background="@android:color/white" | ||
android:clickable="true"/> | ||
|
||
<View | ||
android:id="@+id/view_puppet3" | ||
android:layout_width="150dp" | ||
android:layout_height="150dp" | ||
android:layout_gravity="center_horizontal" | ||
android:layout_margin="15dp" | ||
android:background="@drawable/bg_animated_statelist_drawable" | ||
android:clickable="true"/> | ||
|
||
|
||
</LinearLayout> |