Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.ja.kkkdsa;
- import android.util.Pair;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Map;
- import java.util.HashMap;
- import java.util.Date;
- public class MainActivity extends AppCompatActivity {
- private int Month() {
- final Calendar cal = Calendar.getInstance();
- cal.add(Calendar.DATE, -30);
- return cal.get(Calendar.MONTH);
- }
- private int Year() {
- final Calendar cal = Calendar.getInstance();
- cal.add(Calendar.DATE, -365);
- return cal.get(Calendar.YEAR);
- }
- private int stepsCounterOverall = 0;
- private int stepsCounterDay = 0;
- private int stepsCounterMonth = 0;
- private int stepsCounterYear = 0;
- Date today;
- int month;
- int year;
- Map bazaDay = new HashMap<String,Integer>();
- Map bazaMonth = new HashMap<Pair<Integer,Integer>,Integer>();
- Map bazaYear = new HashMap<Integer,Integer>();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Button pus = (Button) findViewById(R.id.buttonPus);
- pus.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- today = new Date();
- SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
- String todayString = dateFormat.format(today);
- month = Month();
- year = Year();
- Pair<Integer,Integer> temp = new Pair<>(year,month);
- if(!bazaDay.containsKey(todayString)) {
- stepsCounterDay = 0;
- }
- if(!bazaMonth.containsKey(temp)) {
- stepsCounterMonth = 0;
- }
- if(!bazaYear.containsKey(year)) {
- stepsCounterYear = 0;
- }
- stepsCounterOverall++;
- stepsCounterDay++;
- stepsCounterMonth++;
- stepsCounterYear++;
- bazaDay.put(todayString,stepsCounterDay);
- bazaMonth.put(temp,stepsCounterMonth);
- bazaYear.put(year,stepsCounterYear);
- TextView kroki = (TextView) findViewById(R.id.textViewKroki);
- TextView krokid = (TextView) findViewById(R.id.textViewToday);
- TextView krokim = (TextView) findViewById(R.id.textViewMonth);
- TextView krokiy = (TextView) findViewById(R.id.textViewYear);
- kroki.setText(stepsCounterOverall+"");
- krokid.setText("Dziś: " + stepsCounterDay + " kroków, " + stepsCounterDay + " km");
- krokim.setText("W tym miesiącu: " + stepsCounterMonth + " kroków, " + stepsCounterDay + " km");
- krokiy.setText("W tym roku: " + stepsCounterYear + " kroków, " + stepsCounterDay + " km");
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement