Skip to content

Commit

Permalink
added demo app for global animations
Browse files Browse the repository at this point in the history
  • Loading branch information
-global committed Sep 22, 2017
1 parent 9b61a2d commit 29eb589
Show file tree
Hide file tree
Showing 14 changed files with 402 additions and 23 deletions.
4 changes: 3 additions & 1 deletion animations-simplified/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".AnimationActivity">
<activity android:name=".FirstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".SecondActivity">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.rohitss.animationssimplified;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;

/**
* Created by JayYogeshwar on 22-09-2017.
*/
public class BaseActivity extends AppCompatActivity {
@Override
public void finish() {
super.finish();
overridePendingTransitionExit();
}

@Override
public void startActivity(Intent intent) {
super.startActivity(intent);
overridePendingTransitionEnter();
}

/**
* Overrides the pending Activity transition by performing the "Enter" animation.
*/
protected void overridePendingTransitionEnter() {
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
}

/**
* Overrides the pending Activity transition by performing the "Exit" animation.
*/
protected void overridePendingTransitionExit() {
overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right);
}

@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransitionExit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.rohitss.animationssimplified;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class FirstActivity extends BaseActivity implements View.OnClickListener {
private TextView textViewRight;
private TextView textViewLeft;
private TextView textViewTop;
private Button buttonActivity;
private Button buttonAddRight;
private Button buttonRemoveLeft;
private Button buttonAddLeft;
private Button buttonRemoveRight;
private Button buttonAddTop;
private Button buttonRemoveBottom;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
textViewRight = (TextView) findViewById(R.id.textViewRight);
textViewLeft = (TextView) findViewById(R.id.textViewLeft);
textViewTop = (TextView) findViewById(R.id.textViewTop);
buttonActivity = (Button) findViewById(R.id.buttonActivity);
buttonAddRight = (Button) findViewById(R.id.buttonAddRight);
buttonRemoveLeft = (Button) findViewById(R.id.buttonRemoveLeft);
buttonAddLeft = (Button) findViewById(R.id.buttonAddLeft);
buttonRemoveRight = (Button) findViewById(R.id.buttonRemoveRight);
buttonAddTop = (Button) findViewById(R.id.buttonAddTop);
buttonRemoveBottom = (Button) findViewById(R.id.buttonRemoveBottom);
buttonActivity.setOnClickListener(this);
buttonAddRight.setOnClickListener(this);
buttonAddLeft.setOnClickListener(this);
buttonAddTop.setOnClickListener(this);
buttonRemoveRight.setOnClickListener(this);
buttonRemoveLeft.setOnClickListener(this);
buttonRemoveBottom.setOnClickListener(this);
textViewRight.setVisibility(View.INVISIBLE);
textViewLeft.setVisibility(View.INVISIBLE);
textViewTop.setVisibility(View.INVISIBLE);
}

@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.buttonActivity:
startActivity(new Intent(FirstActivity.this, SecondActivity.class));
break;
case R.id.buttonAddRight:
textViewRight.setVisibility(View.VISIBLE);
SlideAnimationUtil.slideInFromRight(this, textViewRight);
break;
case R.id.buttonRemoveLeft:
textViewRight.setVisibility(View.INVISIBLE);
SlideAnimationUtil.slideOutToLeft(this, textViewRight);
break;
case R.id.buttonAddLeft:
textViewLeft.setVisibility(View.VISIBLE);
SlideAnimationUtil.slideInFromLeft(this, textViewLeft);
break;
case R.id.buttonRemoveRight:
textViewLeft.setVisibility(View.INVISIBLE);
SlideAnimationUtil.slideOutToRight(this, textViewLeft);
break;
case R.id.buttonAddTop:
textViewTop.setVisibility(View.VISIBLE);
SlideAnimationUtil.slideInFromTop(this, textViewTop);
break;
case R.id.buttonRemoveBottom:
textViewTop.setVisibility(View.INVISIBLE);
SlideAnimationUtil.slideOutToBottom(this, textViewTop);
break;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.rohitss.animationssimplified;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class AnimationActivity extends AppCompatActivity {
public class SecondActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation);
setContentView(R.layout.activity_second);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.rohitss.animationssimplified;

import android.content.Context;
import android.view.View;
import android.view.animation.AnimationUtils;

/**
* <b></b>
* <p>This class is used to </p>
* Animate any view using "SlideAnimationUtil.slideInFromLeft(context, view);"
* Created by Rohit.
*/
public class SlideAnimationUtil {
/**
* Animates a view so that it slides in from the left of it's container.
*
* @param context
* @param view
*/
public static void slideInFromLeft(Context context, View view) {
runSimpleAnimation(context, view, R.anim.slide_from_left);
}

/**
* Animates a view so that it slides from its current position, out of view to the left.
*
* @param context
* @param view
*/
public static void slideOutToLeft(Context context, View view) {
runSimpleAnimation(context, view, R.anim.slide_to_left);
}

/**
* Animates a view so that it slides in the from the right of it's container.
*
* @param context
* @param view
*/
public static void slideInFromRight(Context context, View view) {
runSimpleAnimation(context, view, R.anim.slide_from_right);
}

/**
* Animates a view so that it slides from its current position, out of view to the right.
*
* @param context
* @param view
*/
public static void slideOutToRight(Context context, View view) {
runSimpleAnimation(context, view, R.anim.slide_to_right);
}

/**
* Animates a view so that it slides in the from the right of it's container.
*
* @param context
* @param view
*/
public static void slideInFromTop(Context context, View view) {
runSimpleAnimation(context, view, R.anim.slide_from_top);
}

/**
* Animates a view so that it slides from its current position, out of view to the right.
*
* @param context
* @param view
*/
public static void slideOutToBottom(Context context, View view) {
runSimpleAnimation(context, view, R.anim.slide_to_bottom);
}

/**
* Runs a simple animation on a View with no extra parameters.
*
* @param context
* @param view
* @param animationId
*/
private static void runSimpleAnimation(Context context, View view, int animationId) {
view.startAnimation(AnimationUtils.loadAnimation(
context, animationId
));
}
}

8 changes: 8 additions & 0 deletions animations-simplified/src/main/res/anim/slide_from_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromXDelta="-100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXDelta="0"/>
</set>
8 changes: 8 additions & 0 deletions animations-simplified/src/main/res/anim/slide_from_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromXDelta="100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXDelta="0"/>
</set>
8 changes: 8 additions & 0 deletions animations-simplified/src/main/res/anim/slide_from_top.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="-100%"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="0"/>
</set>
8 changes: 8 additions & 0 deletions animations-simplified/src/main/res/anim/slide_to_bottom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="-100%p"/>
</set>
8 changes: 8 additions & 0 deletions animations-simplified/src/main/res/anim/slide_to_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromXDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXDelta="-100%p"/>
</set>
8 changes: 8 additions & 0 deletions animations-simplified/src/main/res/anim/slide_to_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromXDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXDelta="100%p"/>
</set>
19 changes: 0 additions & 19 deletions animations-simplified/src/main/res/layout/activity_animation.xml

This file was deleted.

Loading

0 comments on commit 29eb589

Please sign in to comment.