Advertisement
Guest User

Untitled

a guest
May 27th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. package com.example.source_it_android_c;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import butterknife.BindView;
  5. import butterknife.ButterKnife;
  6.  
  7. import android.os.Bundle;
  8. import android.widget.TextView;
  9.  
  10. import java.util.Date;
  11. import java.util.Timer;
  12. import java.util.TimerTask;
  13.  
  14. public class StatisticsActivity extends AppCompatActivity {
  15.  
  16. @BindView(R.id.s_statisticsAfterBirth)
  17. TextView textViewStatistics;
  18. @BindView(R.id.s_secondsAfterStatisticsOpened)
  19. TextView textViewSeconds;
  20.  
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.statistics);
  25. ButterKnife.bind(this);
  26. setStatistics();
  27. setSeconds();
  28.  
  29. }
  30.  
  31. private void setStatistics() {
  32. long timeOfBirth = getIntent().getLongExtra(MainActivity.TIMEINMILLIS, 0);
  33. long timeOfLife = System.currentTimeMillis() - timeOfBirth;
  34. double days = timeOfLife / (24 * 60 * 60 * 1000);
  35. double years = days / 365.25;
  36. String name = getIntent().getStringExtra(MainActivity.NAME);
  37. String zodiak = getIntent().getStringExtra(MainActivity.ZODIAK);
  38. textViewStatistics.setText(name + "\nyears - " + years + "\ndays - " + days + "\nzodiak - " + zodiak);
  39. }
  40.  
  41. private void setSeconds() {
  42. Thread thread = new Thread(new Runnable() {
  43. @Override
  44. public void run() {
  45. int x = 0;
  46. while (true) {
  47. textViewSeconds.setText(x++);
  48. try {
  49. Thread.sleep(1000);
  50. } catch (InterruptedException e) {
  51. e.printStackTrace();
  52. }
  53. }
  54. }
  55. });
  56. thread.run();
  57.  
  58. }
  59.  
  60.  
  61. }
  62.  
  63.  
  64.  
  65.  
  66. --------------------------------------------------------------------------------------------------------------------------------
  67. package com.example.source_it_android_c;
  68.  
  69. import androidx.appcompat.app.AppCompatActivity;
  70. import butterknife.BindView;
  71. import butterknife.ButterKnife;
  72. import butterknife.OnClick;
  73. import butterknife.OnTextChanged;
  74.  
  75. import android.app.Activity;
  76. import android.content.Intent;
  77. import android.os.Bundle;
  78. import android.widget.Button;
  79. import android.widget.CalendarView;
  80. import android.widget.EditText;
  81.  
  82. import java.util.Date;
  83.  
  84. public class MainActivity extends AppCompatActivity {
  85.  
  86. @BindView(R.id.buttonOk)
  87. Button buttonOk;
  88. @BindView(R.id.inputDate)
  89. CalendarView inputDateByCalendarView;
  90. @BindView(R.id.inputText)
  91. EditText inputText;
  92.  
  93. public final static String TIMEINMILLIS = "timeInMillis";
  94. public final static String NAME = "name";
  95. public final static String ZODIAK = "zodiak";
  96.  
  97. @Override
  98. protected void onCreate(Bundle savedInstanceState) {
  99. super.onCreate(savedInstanceState);
  100. setContentView(R.layout.activity_main);
  101. ButterKnife.bind(this);
  102. buttonOk.setEnabled(false);
  103. }
  104.  
  105. @OnTextChanged(R.id.inputText)
  106. public void continueActionIfNameIsValid(CharSequence s) {
  107. if (s.toString().length() > 2) {
  108. buttonOk.setEnabled(true);
  109. }
  110. }
  111.  
  112.  
  113. @OnClick(R.id.buttonOk)
  114. public void OnButtonClick() {
  115. Intent intent = new Intent(this, StatisticsActivity.class);
  116. Date date = new Date(inputDateByCalendarView.getDate());
  117. int month = date.getMonth();
  118. int day = date.getDay();
  119. String name = inputText.getText().toString();
  120. long timeInMillis = date.getTime();
  121. intent.putExtra(TIMEINMILLIS, timeInMillis);
  122. intent.putExtra(ZODIAK, getZodiak(month, day));
  123. intent.putExtra(NAME, name);
  124. startActivity(intent);
  125. }
  126.  
  127.  
  128. private String getZodiak(int month, int day) {
  129. switch (month) {
  130. case 1:
  131. if (day < 20) {
  132. return "Capricorn";
  133. } else {
  134. return "Aquarius";
  135. }
  136. case 2:
  137. if (day < 18) {
  138. return "Aquarius";
  139. } else {
  140. return "Pisces";
  141. }
  142.  
  143. case 3:
  144. if (day < 21) {
  145. return "Pisces";
  146. } else {
  147. return "Aries";
  148. }
  149.  
  150. case 4:
  151. if (day < 20) {
  152. return "Aries";
  153. } else {
  154. return "Taurus";
  155. }
  156.  
  157. case 5:
  158. if (day < 21) {
  159. return "Taurus";
  160. } else {
  161. return "Gemini";
  162. }
  163.  
  164. case 6:
  165. if (day < 21) {
  166. return "Gemini";
  167. } else {
  168. return "Cancer";
  169. }
  170.  
  171. case 7:
  172. if (day < 23) {
  173. return "Cancer";
  174. } else {
  175. return "Leo";
  176. }
  177.  
  178. case 8:
  179. if (day < 23) {
  180. return "Leo";
  181. } else {
  182. return "Virgo";
  183. }
  184.  
  185. case 9:
  186. if (day < 23) {
  187. return "Virgo";
  188. } else {
  189. return "Libra";
  190. }
  191.  
  192. case 10:
  193. if (day < 23) {
  194. return "Libra";
  195. } else {
  196. return "Scorpio";
  197. }
  198.  
  199. case 11:
  200. if (day < 22) {
  201. return "Scorpio";
  202. } else {
  203. return "Sagittarius";
  204. }
  205.  
  206. case 12:
  207. if (day < 22) {
  208. return "Sagittarius";
  209. } else {
  210. return "Capricorn";
  211. }
  212.  
  213. }
  214. return null;
  215. }
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement