-
Notifications
You must be signed in to change notification settings - Fork 0
/
FourthActivity.java
239 lines (206 loc) · 8.24 KB
/
FourthActivity.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package net.fengg.dagger2mvpsample.ui.view.activity;
import android.animation.ArgbEvaluator;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Build;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.OnApplyWindowInsetsListener;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.support.v4.view.WindowInsetsCompat;
import android.support.v7.widget.Toolbar;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.widget.TextView;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.flaviofaria.kenburnsview.KenBurnsView;
import com.jaeger.library.StatusBarUtil;
import net.fengg.dagger2mvpsample.R;
import net.fengg.dagger2mvpsample.ui.contract.IFourContract;
import net.fengg.dagger2mvpsample.ui.fragment.FourthFragment;
import net.fengg.dagger2mvpsample.ui.listener.AppBarStateChangeListener;
import net.fengg.dagger2mvpsample.ui.router.Path;
import butterknife.BindView;
@Route(path = Path.FOURTH_ACTIVITY)
public class FourthActivity extends BaseSwipeActivity implements IFourContract.View {
@BindView(R.id.tb_fourth)
Toolbar tb_fourth;
@BindView(R.id.ctl_fourth)
CollapsingToolbarLayout ctl_fourth;
@BindView(R.id.abl_fourth)
AppBarLayout abl_fourth;
@BindView(R.id.tl_fourth)
TabLayout tl_fourth;
@BindView(R.id.tv_title)
TextView tv_title;
@BindView(R.id.ctm_kbv_iamge)
KenBurnsView ctm_kbv_iamge;
@BindView(R.id.fl_container)
View fl_container;
@BindView(R.id.vp_fourth)
ViewPager vp_fourth;
ViewPagerAdapter mAdapter;
@Override
public void onCancel(DialogInterface dialog) {
}
@Override
public void initContentView(Bundle savedInstanceState) {
setContentView(R.layout.activity_fourth);
}
@Override
public void initView() {
initToolbar();
// StatusBarUtil.setColorForSwipeBack(this, ContextCompat.getColor(this, R.color.colorFourthTrans), 60);
StatusBarUtil.setTranslucentForImageView(this, 40, findViewById(R.id.tb_fourth));
ctl_fourth.setTitleEnabled(false);
ctl_fourth.getLayoutParams().height =
(isLand(this) ? getDisplayDimen(this).y :
getDisplayDimen(this).x) * 9 / 16 +
getStatusBarHeightPixel(this);
ctl_fourth.requestLayout();
tv_title.setText("Demo");
actionBarResponsive();
abl_fourth.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (verticalOffset == 0) {
if (Build.VERSION.SDK_INT >= 11) {
tv_title.setAlpha(0);
} else {
setAlphaForView(tv_title, 0);
}
ctl_fourth.setContentScrimColor(ContextCompat
.getColor(FourthActivity.this, android.R.color.transparent));
} else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
if (Build.VERSION.SDK_INT >= 11) {
tv_title.setAlpha(1);
} else {
setAlphaForView(tv_title, 1);
}
ctl_fourth.setContentScrimColor(ContextCompat
.getColor(FourthActivity.this, R.color.colorPrimary));
} else {
float offset = Math.abs(verticalOffset / (float) appBarLayout.getTotalScrollRange());
if (Build.VERSION.SDK_INT >= 11) {
tv_title.setAlpha(offset);
} else {
setAlphaForView(tv_title, offset);
}
ctl_fourth.setContentScrimColor(
(int) new ArgbEvaluator().evaluate(offset,
ContextCompat.getColor(FourthActivity.this,
android.R.color.transparent), ContextCompat
.getColor(FourthActivity.this,
R.color.colorPrimary)));
}
}
});
mAdapter = new ViewPagerAdapter(getSupportFragmentManager());
vp_fourth.setOffscreenPageLimit(mAdapter.getCount());
vp_fourth.setAdapter(mAdapter);
tl_fourth.setupWithViewPager(vp_fourth);
// If your CollapsingToolbarLayout too complex (e.g. ImageView into FrameLayout), then
// your status bar may looks so buggy.
// You can hotfix by this code when you need to use some 24.2.0's features,
// or you can wait for Google fix this (24.2.1), or downgrade to 24.1.1.
// The issue: http://goo.gl/FMWs37
// ViewCompat
// .setOnApplyWindowInsetsListener(fl_container, new OnApplyWindowInsetsListener() {
//
// @Override
// public WindowInsetsCompat onApplyWindowInsets(View v,
// WindowInsetsCompat insets) {
// return insets.consumeSystemWindowInsets();
// }
// });
}
private void initToolbar() {
setSupportActionBar(tb_fourth);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
ctl_fourth.setTitleEnabled(false);
}
@Override
public void initPresenter() {
}
@Override
public void initListener() {
}
@Override
public void setupComponent() {
}
@Override
protected void onResume() {
super.onResume();
if (ctm_kbv_iamge != null) {
ctm_kbv_iamge.resume();
}
}
@Override
protected void onPause() {
super.onPause();
if (ctm_kbv_iamge != null) {
ctm_kbv_iamge.pause();
}
}
private void setAlphaForView(View v, float alpha) {
AlphaAnimation alphaAnimation = new AlphaAnimation(alpha, alpha);
alphaAnimation.setDuration(0);
alphaAnimation.setFillAfter(true);
v.startAnimation(alphaAnimation);
}
private void actionBarResponsive() {
int actionBarHeight = getActionBarHeightPixel(this);
int tabHeight = getResources().getDimensionPixelSize(R.dimen.tab_height);
if (actionBarHeight > 0) {
tb_fourth.getLayoutParams().height = actionBarHeight + tabHeight;
tb_fourth.requestLayout();
}
}
public static Point getDisplayDimen(Context context) {
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
Point size = new Point();
if (Build.VERSION.SDK_INT >= 13) {
display.getSize(size);
} else {
size.x = display.getWidth();
size.y = display.getHeight();
}
return size;
}
public static boolean isLand(Context context) {
return context.getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE;
}
private class ViewPagerAdapter extends FragmentPagerAdapter {
public ViewPagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
@Override
public Fragment getItem(int position) {
return new FourthFragment();
}
@Override
public int getCount() {
return 4;
}
@Override
public CharSequence getPageTitle(int position) {
return "Demo " + position;
}
}
}