-
Notifications
You must be signed in to change notification settings - Fork 53
/
MainActivity.java
152 lines (130 loc) · 6.21 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.applikeysolutions.sample;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.util.DisplayMetrics;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.applikeysolutions.animation.BlurAnimation;
import com.applikeysolutions.animation.orionpreview.ScaleAnimation;
import com.applikeysolutions.animation.orionpreview.TranslationAnimation;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
//Views
@BindView(R.id.cv_product_details) CardView cvProductDetails;
@BindView(R.id.ll_product_details) LinearLayout llProductDetails;
@BindView(R.id.rl_container) RelativeLayout rlContainer;
@BindView(R.id.tv_product_title) TextView tvProductTitle;
@BindView(R.id.imgBackground) ImageView imgBackground;
//Animations
private ScaleAnimation increaseAnimationImage;
private ScaleAnimation decreaseAnimationImage;
private ScaleAnimation increaseAnimationText;
private ScaleAnimation decreaseAnimationText;
private TranslationAnimation upAnimationImageView;
private TranslationAnimation arcUpAnimationTv;
private TranslationAnimation downAnimationImageView;
private TranslationAnimation arcDownAnimationTv;
private BlurAnimation blurAnimation;
private float screenHeight;
private float screenWidth;
private Bitmap blurredBitmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
getScreenSize();
setProductBottomMargin();
}
@OnClick(R.id.cv_product_details)
void onProductDetailsClick() {
upAnimationImageView.showAnimation();
arcUpAnimationTv.showAnimation();
increaseAnimationImage.showAnimation();
increaseAnimationText.showAnimation();
cvProductDetails.setClickable(false);
rlContainer.setClickable(true);
addBlur();
}
@OnClick(R.id.rl_container)
void onContainerClick() {
downAnimationImageView.showAnimation();
arcDownAnimationTv.showAnimation();
decreaseAnimationImage.showAnimation();
decreaseAnimationText.showAnimation();
rlContainer.setClickable(false);
cvProductDetails.setClickable(true);
removeBlur();
}
private void getScreenSize(){
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
screenHeight = displaymetrics.heightPixels;
screenWidth = displaymetrics.widthPixels;
}
private void setProductBottomMargin(){
llProductDetails.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
llProductDetails.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
llProductDetails.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) cvProductDetails.getLayoutParams();
params.bottomMargin = llProductDetails.getMeasuredHeight() * -1;
cvProductDetails.setLayoutParams(params);
}
});
}
@Override
protected void onResume() {
super.onResume();
initAnimation();
}
private void initAnimation() {
tvProductTitle.post(() -> {
increaseAnimationImage = new ScaleAnimation.ScaleAnimationBuilder(imgBackground, 1.5f, 1.5f).build();
increaseAnimationText = new ScaleAnimation.ScaleAnimationBuilder(tvProductTitle, 2.25f, 2.25f).build();
decreaseAnimationImage = new ScaleAnimation.ScaleAnimationBuilder(imgBackground, 1f, 1f).build();
decreaseAnimationText = new ScaleAnimation.ScaleAnimationBuilder(tvProductTitle, 1f, 1f).build();
upAnimationImageView = new TranslationAnimation.TranslationAnimationBuilder(cvProductDetails,
TranslationAnimation.TranslationMode.TranslationY, 0, -(screenHeight / 2.2f))
.build();
arcUpAnimationTv = new TranslationAnimation.TranslationAnimationBuilder(tvProductTitle,
TranslationAnimation.TranslationMode.TranslationAll, 0, screenHeight / 10)
.arcMode(TranslationAnimation.ArcMode.ArcUpward)
.additionStartPoint(0)
.additionEndPoint(screenWidth / 2 - tvProductTitle.getWidth())
.build();
downAnimationImageView = new TranslationAnimation.TranslationAnimationBuilder(cvProductDetails,
TranslationAnimation.TranslationMode.TranslationY, -(screenHeight / 3), 0)
.build();
arcDownAnimationTv = new TranslationAnimation.TranslationAnimationBuilder(tvProductTitle,
TranslationAnimation.TranslationMode.TranslationAll, screenHeight / 7, 0)
.arcMode(TranslationAnimation.ArcMode.ArcDownard)
.additionStartPoint(screenWidth / 2 - tvProductTitle.getWidth())
.additionEndPoint(0)
.build();
blurAnimation = new BlurAnimation.BlurAnimationBuilder(0.4f, 7f).build();
Bitmap originalBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.sample_background);
blurredBitmap = blurAnimation.blur(MainActivity.this, originalBitmap);
});
}
private void addBlur() {
imgBackground.setImageBitmap(new BitmapDrawable(getResources(), blurredBitmap).getBitmap());
}
private void removeBlur() {
imgBackground.setImageResource(R.drawable.sample_background);
}
}