Skip to content

Commit

Permalink
Change Animation
Browse files Browse the repository at this point in the history
  • Loading branch information
CPstudy committed Aug 3, 2018
1 parent 05e2c2f commit a7135ac
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 50 deletions.
17 changes: 10 additions & 7 deletions sandwich/src/main/java/com/guk2zzada/sandwich/Sandwich.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public static Sandwich makeText(Context context, String message, @Duration int d
}

public void show() {
final FrameLayout layoutRoot = mLayout.findViewById(R.id.layoutRoot);
final RelativeLayout layoutFront = mLayout.findViewById(R.id.layoutFront);
final RelativeLayout layoutBack = mLayout.findViewById(R.id.layoutBack);
//final ImageView imgBack = mLayout.findViewById(R.id.imgBack);
Expand All @@ -96,10 +95,8 @@ public void show() {
txtText2.setText(mMessage);

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
layoutFront.setBackgroundDrawable(drawable);
layoutBack.setBackgroundDrawable(drawable);
} else {
layoutFront.setBackground(drawable);
layoutBack.setBackground(drawable);
}

Expand All @@ -108,31 +105,37 @@ public void show() {
@Override
public void onGlobalLayout() {
int height = layoutBack.getHeight();
layoutFront.setTranslationY(-height);

final ObjectAnimator scaleBounceX = ObjectAnimator.ofFloat(layoutRoot, View.SCALE_X, 0.5f, 1.0f);
final ObjectAnimator alphaInvisible = ObjectAnimator.ofFloat(layoutFront, View.ALPHA, 1.0f, 0.0f);
alphaInvisible.setDuration(0);

final ObjectAnimator alphaVisible = ObjectAnimator.ofFloat(layoutFront, View.ALPHA, 0.0f, 1.0f);
alphaVisible.setDuration(0);

final ObjectAnimator scaleBounceX = ObjectAnimator.ofFloat(layoutBack, View.SCALE_X, 0.5f, 1.0f);
scaleBounceX.setInterpolator(new BounceInterpolator());
scaleBounceX.setDuration(DURATION_ICON);

final ObjectAnimator scaleBounceY = ObjectAnimator.ofFloat(layoutRoot, View.SCALE_Y, 0.5f, 1.0f);
final ObjectAnimator scaleBounceY = ObjectAnimator.ofFloat(layoutBack, View.SCALE_Y, 0.5f, 1.0f);
scaleBounceY.setInterpolator(new BounceInterpolator());
scaleBounceY.setDuration(DURATION_ICON);

final ObjectAnimator slideUp = ObjectAnimator.ofFloat(layoutFront, View.TRANSLATION_Y, -height, 0);
slideUp.setDuration(DURATION_BOX);
slideUp.setInterpolator(new DecelerateInterpolator());

scaleBounceX.addListener(new AnimatorListenerAdapter() {

@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
alphaVisible.start();
slideUp.start();
}
});

AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(
alphaInvisible,
scaleBounceX,
scaleBounceY
);
Expand Down
88 changes: 45 additions & 43 deletions sandwich/src/main/res/layout/layout_sandwich.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,60 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:clipChildren="false">
android:layout_height="match_parent">

<RelativeLayout
android:id="@+id/layoutBack"
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/sandwichMarginDefault"
android:background="@drawable/bg_sandwich_iconbox"
android:clipToPadding="false"
android:clipChildren="false">
android:layout_margin="@dimen/sandwichMarginDefault">

<TextView
android:id="@+id/txtText"
<RelativeLayout
android:id="@+id/layoutBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/sandwichMarginTiny"
android:padding="@dimen/sandwichMarginSmall"
android:background="@drawable/bg_sandwich_textbox"
android:text="이것은 샌드위치입니다."
android:textSize="@dimen/sandwichTextSize"/>

</RelativeLayout>

<RelativeLayout
android:id="@+id/layoutFront"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/sandwichMarginDefault"
android:clipToPadding="false"
android:clipChildren="false">

<ImageView
android:id="@+id/imgIcon"
android:layout_width="@dimen/sandwichIconSize"
android:layout_height="@dimen/sandwichIconSize"
android:layout_centerInParent="true"
android:src="@drawable/icon_sandwich_message"/>

<TextView
android:id="@+id/txtText2"
android:layout_gravity="center"
android:background="@drawable/bg_sandwich_iconbox">

<ImageView
android:id="@+id/imgIcon"
android:layout_width="@dimen/sandwichIconSize"
android:layout_height="@dimen/sandwichIconSize"
android:layout_centerInParent="true"
android:src="@drawable/icon_sandwich_message"/>

<TextView
android:id="@+id/txtText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/sandwichMarginTiny"
android:padding="@dimen/sandwichMarginSmall"
android:background="@drawable/bg_sandwich_textbox"
android:text="이것은 샌드위치입니다."
android:textSize="@dimen/sandwichTextSize"
android:visibility="invisible"/>

</RelativeLayout>

<RelativeLayout
android:id="@+id/layoutFront"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/sandwichMarginTiny"
android:padding="@dimen/sandwichMarginSmall"
android:background="@drawable/bg_sandwich_textbox"
android:text="이것은 샌드위치입니다."
android:textSize="@dimen/sandwichTextSize"/>
android:layout_gravity="center">

<TextView
android:id="@+id/txtText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/sandwichMarginTiny"
android:padding="@dimen/sandwichMarginSmall"
android:background="@drawable/bg_sandwich_textbox"
android:text="이것은 샌드위치입니다."
android:textSize="@dimen/sandwichTextSize"/>

</RelativeLayout>


</RelativeLayout>
</FrameLayout>

</FrameLayout>

0 comments on commit a7135ac

Please sign in to comment.