Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.90 KB | None | 0 0
  1. public class HomeFragment extends Fragment {
  2.  
  3. ViewPager viewPager;
  4. ViewPagerAdapter adapter;
  5. LinearLayout sliderDotsPanel;
  6. private int dotsCount;
  7. private ImageView[] dots;
  8. Drawable active_dots;
  9. Drawable nonactive_dots;
  10.  
  11.  
  12. public HomeFragment() {
  13. // Required empty public constructor
  14. }
  15.  
  16. @Override
  17. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  18. Bundle savedInstanceState) {
  19. // Inflate the layout for this fragment
  20. View view = inflater.inflate(R.layout.fragment_home, container, false);
  21. viewPager = (ViewPager) view.findViewById(R.id.view_pager);
  22. sliderDotsPanel = (LinearLayout) view.findViewById(R.id.SliderDots);
  23. active_dots = getDrawable(getActivity().getApplicationContext(), R.drawable.active_dot);
  24. nonactive_dots = getDrawable(getActivity().getApplicationContext(), R.drawable.nonactive_dot);
  25.  
  26.  
  27.  
  28.  
  29. adapter = new ViewPagerAdapter(this.getActivity());
  30. viewPager.setAdapter(adapter);
  31.  
  32. dotsCount = adapter.getCount();
  33. dots = new ImageView[dotsCount];
  34.  
  35. for (int i = 0; i < dotsCount; i++) {
  36.  
  37. dots[i] = new ImageView(getActivity());
  38. dots[i].setImageDrawable(nonactive_dots);
  39.  
  40. LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  41.  
  42. params.setMargins(8, 0, 8, 0);
  43. sliderDotsPanel.addView(dots[i], params);
  44.  
  45.  
  46. }
  47.  
  48. dots[0].setImageDrawable(active_dots);
  49.  
  50. viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  51. @Override
  52. public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  53.  
  54. }
  55.  
  56. @Override
  57. public void onPageSelected(int position) {
  58.  
  59. for (int i = 0; i < dotsCount; i++) {
  60. dots[i].setImageDrawable(nonactive_dots);
  61. }
  62.  
  63. dots[position].setImageDrawable(active_dots);
  64.  
  65. }
  66.  
  67. @Override
  68. public void onPageScrollStateChanged(int state) {
  69.  
  70. }
  71. });
  72.  
  73. Timer timer = new Timer();
  74. timer.scheduleAtFixedRate(new myTimerTask(), 4000, 2000);
  75. return view;
  76.  
  77.  
  78. }
  79.  
  80.  
  81. public class myTimerTask extends TimerTask {
  82.  
  83. @Override
  84. public void run() {
  85.  
  86. getActivity().runOnUiThread(new Runnable() {
  87. @Override
  88. public void run() {
  89.  
  90.  
  91. while (true) {
  92.  
  93. if (viewPager.getCurrentItem() == 0) {
  94. viewPager.setCurrentItem(1);
  95. } else if (viewPager.getCurrentItem() == 1) {
  96. viewPager.setCurrentItem(2);
  97. } else if (viewPager.getCurrentItem() == 2) {
  98. viewPager.setCurrentItem(1);
  99. } else if (viewPager.getCurrentItem() == 1) {
  100. viewPager.setCurrentItem(0);
  101.  
  102. }
  103.  
  104. }
  105.  
  106. }
  107.  
  108.  
  109. });
  110. }
  111. }
  112. }
  113.  
  114. 07-26 14:19:44.486 2873-2873/com.example.aids.a09application W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
  115. 07-26 14:19:44.565 2873-2873/com.example.aids.a09application I/Choreographer: Skipped 117 frames! The application may be doing too much work on its main thread.
  116. 07-26 14:19:46.622 2873-2884/com.example.aids.a09application I/art: Background sticky concurrent mark sweep GC freed 787(89KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 198MB/198MB, paused 18.992ms total 102.229ms
  117. 07-26 14:19:46.952 2873-2884/com.example.aids.a09application I/art: Background partial concurrent mark sweep GC freed 997(40KB) AllocSpace objects, 0(0B) LOS objects, 1% free, 198MB/202MB, paused 15.431ms total 173.177ms
  118. 07-26 14:19:47.181 2873-2878/com.example.aids.a09application I/art: Do partial code cache collection, code=30KB, data=27KB
  119. 07-26 14:19:47.194 2873-2878/com.example.aids.a09application I/art: After code cache collection, code=21KB, data=23KB
  120. 07-26 14:19:47.194 2873-2878/com.example.aids.a09application I/art: Increasing code cache capacity to 128KB
  121. 07-26 14:19:49.800 2873-2884/com.example.aids.a09application I/art: Background partial concurrent mark sweep GC freed 37941(1634KB) AllocSpace objects, 0(0B) LOS objects, 1% free, 201MB/205MB, paused 12.622ms total 296.630ms
  122. 07-26 14:19:52.394 2873-2884/com.example.aids.a09application I/art: Background sticky concurrent mark sweep GC freed 36700(1551KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 203MB/205MB, paused 13.130ms total 169.524ms
  123. 07-26 14:19:52.639 2873-2884/com.example.aids.a09application I/art: Background partial concurrent mark sweep GC freed 54270(3MB) AllocSpace objects, 0(0B) LOS objects, 1% free, 200MB/204MB, paused 18.500ms total 234.230ms
  124. 07-26 14:19:54.910 2873-2884/com.example.aids.a09application I/art: Background partial concurrent mark sweep GC freed 66332(3MB) AllocSpace objects, 0(0B) LOS objects, 1% free, 201MB/205MB, paused 14.535ms total 197.841ms
  125. 07-26 14:19:57.531 2873-2884/com.example.aids.a09application I/art: Background partial concurrent mark sweep GC freed 75191(4MB) AllocSpace objects, 0(0B) LOS objects, 1% free, 201MB/205MB, paused 14.242ms total 205.903ms
  126. 07-26 14:19:59.749 2873-2884/com.example.aids.a09application I/art: Background sticky concurrent mark sweep GC freed 35759(1500KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 203MB/205MB, paused 12.808ms total 147.647ms
  127. 07-26 14:20:00.920 2873-2884/com.example.aids.a09application I/art: Background sticky concurrent mark sweep GC freed 12875(540KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 204MB/205MB, paused 13.586ms total 113.208ms
  128. 07-26 14:20:01.340 2873-2884/com.example.aids.a09application I/art: Background partial concurrent mark sweep GC freed 95614(6MB) AllocSpace objects, 0(0B) LOS objects, 1% free, 198MB/202MB, paused 16.117ms total 152.367ms
  129. 07-26 14:20:01.403 2873-2879/com.example.aids.a09application I/art: Thread[3,tid=2879,WaitingInMainSignalCatcherLoop,Thread*=0x9de8de00,peer=0x12c2a8b0,"Signal Catcher"]: reacting to signal 3
  130. 07-26 14:20:01.882 2873-2879/com.example.aids.a09application I/art: Wrote stack traces to '/data/anr/traces.txt'
  131. 07-26 14:20:05.687 2873-2884/com.example.aids.a09application I/art: Background partial concurrent mark sweep GC freed 45945(2MB) AllocSpace objects, 0(0B) LOS objects, 1% free, 201MB/205MB, paused 47.723ms total 976.583ms
  132. 07-26 14:20:09.410 2873-2884/com.example.aids.a09application I/art: Background sticky concurrent mark sweep GC freed 33212(1393KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 203MB/205MB, paused 18.694ms total 163.982ms
  133. 07-26 14:20:10.980 2873-2884/com.example.aids.a09application I/art: Background partial concurrent mark sweep GC freed 93472(5MB) AllocSpace objects, 0(0B) LOS objects, 1% free, 199MB/203MB, paused 17.361ms total 219.162ms
  134. 07-26 14:20:13.670 2873-2880/com.example.aids.a09application W/art: Suspending all threads took: 10.526ms
  135. 07-26 14:20:13.771 2873-2884/com.example.aids.a09application I/art: Background partial concurrent mark sweep GC freed 52852(2MB) AllocSpace objects, 0(0B) LOS objects, 1% free, 201MB/205MB, paused 15.208ms total 196.607ms
  136. 07-26 14:20:17.211 2873-2880/com.example.aids.a09application W/art: Suspending all threads took: 44.452ms
  137. 07-26 14:20:17.421 2873-2884/com.example.aids.a09application I/art: Background sticky concurrent mark sweep GC freed 35062(1470KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 203MB/205MB, paused 15.334ms total 273.230ms
  138. 07-26 14:20:19.082 2873-2884/com.example.aids.a09application I/art: Background partial concurrent mark sweep GC freed 89559(5MB) AllocSpace objects, 0(0B) LOS objects, 1% free, 199MB/203MB, paused 21.820ms total 251.707ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement