Guest User

Untitled

a guest
May 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. public Object instantiateItem(ViewGroup collection, int position) {
  2.  
  3. RelativeLayout wholeView = new RelativeLayout(collection.getContext());
  4.  
  5. // images
  6. final ImageView workoutWidget = new ImageView(collection.getContext());
  7. workoutWidget.setImageResource(R.drawable.workout_widget_master);
  8.  
  9. final ImageButton resetButton = new ImageButton(collection.getContext());
  10. resetButton.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.reset_button_master));
  11. RelativeLayout.LayoutParams resetButtonParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
  12. resetButtonParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
  13. resetButtonParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  14. resetButtonParams.height = 150;
  15. resetButtonParams.width = 150;
  16. resetButton.setLayoutParams(resetButtonParams);
  17. resetButton.setVisibility(View.GONE);
  18.  
  19. final ImageButton startButton = new ImageButton(collection.getContext());
  20. startButton.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.start_button_master));
  21. startButton.setTag(context.getString(R.string.wtrStartButtonTag));
  22. RelativeLayout.LayoutParams startButtonParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
  23. startButtonParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  24. startButtonParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  25. startButtonParams.height = 150;
  26. startButtonParams.width = 150;
  27. startButton.setLayoutParams(startButtonParams);
  28. startButton.setOnClickListener(new View.OnClickListener() {
  29. @Override
  30. public void onClick(View view) {
  31. startButton.setAlpha(1.0f);
  32.  
  33. if (startButton.getTag() == context.getString(R.string.wtrStartButtonTag)) {
  34. startButton.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.pause_button_master));
  35. startButton.setTag(context.getString(R.string.wtrPauseButtonTag));
  36. resetButton.setVisibility(View.VISIBLE);
  37. }
  38. else if (startButton.getTag() == context.getString(R.string.wtrPauseButtonTag)) {
  39. startButton.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.start_button_master));
  40. startButton.setTag(context.getString(R.string.wtrStartButtonTag));
  41. }
  42. }
  43. });
  44.  
  45. // text labels view
  46. LinearLayout textLabels = new LinearLayout(collection.getContext());
  47. textLabels.setOrientation(LinearLayout.VERTICAL);
  48.  
  49. TextView activityDescription = new TextView(collection.getContext());
  50. activityDescription.setText("Warm-up");
  51. activityDescription.setPadding(200, 200, 0, 0);
  52. activityDescription.setTextSize(30);
  53. textLabels.addView(activityDescription);
  54.  
  55. TextView timeLeftForThisActivity = new TextView(collection.getContext());
  56. timeLeftForThisActivity.setText("00:00");
  57. timeLeftForThisActivity.setPadding(200, 0, 0, 0);
  58. timeLeftForThisActivity.setTextSize(60);
  59. textLabels.addView(timeLeftForThisActivity);
  60.  
  61. LinearLayout elapsedLabels = new LinearLayout(collection.getContext());
  62. elapsedLabels.setOrientation(LinearLayout.HORIZONTAL);
  63.  
  64. TextView elapsedTimeStatic = new TextView(collection.getContext());
  65. elapsedTimeStatic.setText("Elapsed Time: ");
  66. elapsedTimeStatic.setPadding(200, 0, 0, 0);
  67. elapsedTimeStatic.setTextSize(20);
  68.  
  69. TextView elapsedTimeDynamic = new TextView(collection.getContext());
  70. elapsedTimeDynamic.setText("00:00");
  71. elapsedTimeDynamic.setPadding(0, 0, 0, 0);
  72. elapsedTimeDynamic.setTextSize(20);
  73.  
  74. elapsedLabels.addView(elapsedTimeStatic);
  75. elapsedLabels.addView(elapsedTimeDynamic);
  76.  
  77. textLabels.addView(elapsedLabels);
  78.  
  79. // adding images and text to overall view
  80. wholeView.addView(workoutWidget);
  81. wholeView.addView(startButton);
  82. wholeView.addView(resetButton);
  83. wholeView.addView(textLabels);
  84.  
  85. collection.addView(wholeView, 0);
  86.  
  87. return wholeView;
  88. }
  89.  
  90. viewPager.setOffscreenPageLimit(2); to your code.
Add Comment
Please, Sign In to add comment