Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. package com.example.liseandersen.moodtrackerproject;
  2.  
  3. import android.app.ActionBar;
  4. import android.content.Intent;
  5. import android.media.Image;
  6. import android.os.CountDownTimer;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.Toast;
  12.  
  13. import java.util.ArrayList;
  14. import java.util.Calendar;
  15. import java.util.Dictionary;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.logging.Handler;
  20.  
  21. public class MainActivity extends AppCompatActivity {
  22.  
  23. Button history;
  24. Button moods[] = new Button[6];
  25. int i = 0;
  26. static List<Mood> moodHistory = new ArrayList<Mood>();
  27. MyDBHandler dbHandler;
  28.  
  29. @Override
  30. protected void onCreate(Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. setContentView(R.layout.activity_main);
  33.  
  34. moods[0] = (Button) findViewById(R.id.happyButton);
  35. moods[1] = (Button) findViewById(R.id.indifferentButton);
  36. moods[2] = (Button) findViewById(R.id.tiredButton);
  37. moods[3] = (Button) findViewById(R.id.nervousButton);
  38. moods[4] = (Button) findViewById(R.id.sadButton);
  39. moods[5] = (Button) findViewById(R.id.angryButton);
  40. for (i = 0; i<moods.length; i++){
  41. setButtons(moods[i]);
  42. }
  43. history = (Button) findViewById(R.id.historyButton);
  44. history.setOnClickListener(new View.OnClickListener() {
  45. @Override
  46. public void onClick(View v) {
  47. startActivity(new Intent(getApplicationContext(), DataHistory.class));
  48. }
  49. });
  50.  
  51. dbHandler = new MyDBHandler(this, null, null, 1);
  52. }
  53.  
  54. public void setButtons(final Button button){
  55. button.setOnClickListener(new View.OnClickListener() {
  56. @Override
  57. public void onClick(View v) {
  58. Calendar c = Calendar.getInstance();
  59. CharSequence buttonName = button.getText();
  60. CharSequence text = "\"" + buttonName + "\" registered " + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE);
  61. final Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT);
  62. toast.show();
  63. new CountDownTimer(800,800){
  64. public void onTick(long millisUntilFinished) {toast.show();}
  65. public void onFinish() {toast.cancel();}
  66. }.start();
  67. moodHistory.add(new Mood(c.getTime(),buttonName));
  68. }
  69. });
  70. }
  71.  
  72.  
  73.  
  74. public List<Mood> getMoodHistory(){
  75. return moodHistory;
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement