Advertisement
Guest User

Untitled

a guest
May 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.17 KB | None | 0 0
  1. package com.example.ja.kkkdsa;
  2. import android.util.Pair;
  3. import android.view.View;
  4. import android.widget.Button;
  5. import android.widget.TextView;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8.  
  9. import java.text.SimpleDateFormat;
  10. import java.util.Calendar;
  11. import java.util.Map;
  12. import java.util.HashMap;
  13. import java.util.Date;
  14.  
  15. public class MainActivity extends AppCompatActivity {
  16.  
  17.     private int Month() {
  18.         final Calendar cal = Calendar.getInstance();
  19.         cal.add(Calendar.DATE, -30);
  20.         return cal.get(Calendar.MONTH);
  21.     }
  22.  
  23.     private int Year() {
  24.         final Calendar cal = Calendar.getInstance();
  25.         cal.add(Calendar.DATE, -365);
  26.         return cal.get(Calendar.YEAR);
  27.     }
  28.  
  29.     private int stepsCounterOverall = 0;
  30.     private int stepsCounterDay = 0;
  31.     private int stepsCounterMonth = 0;
  32.     private int stepsCounterYear = 0;
  33.     Date today;
  34.     int month;
  35.     int year;
  36.     Map bazaDay = new HashMap<String,Integer>();
  37.     Map bazaMonth = new HashMap<Pair<Integer,Integer>,Integer>();
  38.     Map bazaYear = new HashMap<Integer,Integer>();
  39.  
  40.     @Override
  41.     protected void onCreate(Bundle savedInstanceState) {
  42.         super.onCreate(savedInstanceState);
  43.         setContentView(R.layout.activity_main);
  44.  
  45.         Button pus = (Button) findViewById(R.id.buttonPus);
  46.         pus.setOnClickListener(new View.OnClickListener() {
  47.             @Override
  48.             public void onClick(View v) {
  49.                 today = new Date();
  50.                 SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
  51.                 String todayString = dateFormat.format(today);
  52.  
  53.                 month = Month();
  54.                 year = Year();
  55.                 Pair<Integer,Integer> temp = new Pair<>(year,month);
  56.  
  57.                 if(!bazaDay.containsKey(todayString)) {
  58.                     stepsCounterDay = 0;
  59.                 }
  60.                 if(!bazaMonth.containsKey(temp)) {
  61.                     stepsCounterMonth = 0;
  62.                 }
  63.                 if(!bazaYear.containsKey(year)) {
  64.                     stepsCounterYear = 0;
  65.                 }
  66.  
  67.                 stepsCounterOverall++;
  68.                 stepsCounterDay++;
  69.                 stepsCounterMonth++;
  70.                 stepsCounterYear++;
  71.  
  72.                 bazaDay.put(todayString,stepsCounterDay);
  73.                 bazaMonth.put(temp,stepsCounterMonth);
  74.                 bazaYear.put(year,stepsCounterYear);
  75.  
  76.                 TextView kroki = (TextView) findViewById(R.id.textViewKroki);
  77.                 TextView krokid = (TextView) findViewById(R.id.textViewToday);
  78.                 TextView krokim = (TextView) findViewById(R.id.textViewMonth);
  79.                 TextView krokiy = (TextView) findViewById(R.id.textViewYear);
  80.                 kroki.setText(stepsCounterOverall+"");
  81.                 krokid.setText("Dziś: " + stepsCounterDay + " kroków, " + stepsCounterDay + " km");
  82.                 krokim.setText("W tym miesiącu: " + stepsCounterMonth + " kroków, " + stepsCounterDay + " km");
  83.                 krokiy.setText("W tym roku: " + stepsCounterYear + " kroków, " + stepsCounterDay + " km");
  84.             }
  85.         });
  86.  
  87.  
  88.  
  89.  
  90.  
  91.     }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement