-
Notifications
You must be signed in to change notification settings - Fork 38
/
MainActivity.java
76 lines (58 loc) · 2.24 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
package com.goka.sample;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.goka.kenburnsview.KenBurnsView;
import com.goka.kenburnsview.LoopViewPager;
import java.util.Arrays;
import java.util.List;
public class MainActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
initializeKenBurnsView();
}
private void initializeKenBurnsView() {
// KenBurnsView
final KenBurnsView kenBurnsView = (KenBurnsView) findViewById(R.id.ken_burns_view);
kenBurnsView.setScaleType(ImageView.ScaleType.CENTER_CROP);
kenBurnsView.setSwapMs(3750);
kenBurnsView.setFadeInOutMs(750);
// ResourceIDs
List<Integer> resourceIDs = Arrays.asList(SampleImages.IMAGES_RESOURCE);
kenBurnsView.loadResourceIDs(resourceIDs);
// LoopViewListener
LoopViewPager.LoopViewPagerListener listener = new LoopViewPager.LoopViewPagerListener() {
@Override
public View OnInstantiateItem(int page) {
TextView counterText = new TextView(getApplicationContext());
counterText.setText(String.valueOf(page));
return counterText;
}
@Override
public void onPageScroll(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
kenBurnsView.forceSelected(position);
}
@Override
public void onPageScrollChanged(int page) {
}
};
// LoopView
LoopViewPager loopViewPager = new LoopViewPager(this, resourceIDs.size(), listener);
FrameLayout viewPagerFrame = (FrameLayout) findViewById(R.id.view_pager_frame);
viewPagerFrame.addView(loopViewPager);
kenBurnsView.setPager(loopViewPager);
}
}