diff --git a/.idea/clicker_java.iml b/.idea/clicker_java.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/clicker_java.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1e4a201 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7311b32..a1c28ac 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,12 @@ - - + + + + + + diff --git a/app/src/main/java/com/example/clicker/MainActivity.java b/app/src/main/java/com/example/clicker/MainActivity.java index 8e398be..f639875 100644 --- a/app/src/main/java/com/example/clicker/MainActivity.java +++ b/app/src/main/java/com/example/clicker/MainActivity.java @@ -1,39 +1,43 @@ package com.example.clicker; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; -import android.view.View; import android.widget.Button; -import android.widget.TextClock; +import android.widget.EditText; +import android.widget.ImageView; import android.widget.TextView; +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + + + public class MainActivity extends AppCompatActivity { - TextView mainText; - Button mainBtn; - - private long score = 0; + Button drop_btn, minus_btn; + ImageView mainBtn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); setContentView(R.layout.activity_main); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); - mainText = (TextView) findViewById(R.id.mainText); - mainBtn = (Button) findViewById(R.id.button); - - - View.OnClickListener clickListener = new View.OnClickListener() { - @Override - public void onClick(View v) { - score ++; - String s = "Кликов: " + score; - mainText.setText(s.toCharArray(),0, s.length()); - } - }; + mainText = findViewById(R.id.mainText); + mainBtn = findViewById(R.id.main_btn); + drop_btn = findViewById(R.id.drop_btn); + minus_btn = findViewById(R.id.minus_btn); + Click clickListener = new Click(mainText); mainBtn.setOnClickListener(clickListener); - + drop_btn.setOnClickListener(clickListener); + minus_btn.setOnClickListener(clickListener); } -} - +} \ No newline at end of file diff --git a/app/src/main/java/com/example/clicker/click.java b/app/src/main/java/com/example/clicker/click.java new file mode 100644 index 0000000..66df2f8 --- /dev/null +++ b/app/src/main/java/com/example/clicker/click.java @@ -0,0 +1,71 @@ +package com.example.clicker; + +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +public class Click implements View.OnClickListener { + TextView mainText; + String letter; + long score = 0; + + public Click(TextView mainTxt){ + this.mainText=mainTxt; + } + String primer=""; + @Override + public void onClick(View v) { + int id = v.getId(); + + if (id==R.id.main_btn) + { + score++; + if (score % 100 >= 11 && score % 100 <= 14) { + letter = " раз"; + } else { + switch ((int) (score % 10)) { + case 1: + letter = " раз"; + break; + case 2: + case 3: + case 4: + letter = " раза"; + break; + default: + letter = " раз"; + } + } + String s = "Кнопка нажата: " + score + letter; + mainText.setText(s); + } + else if (id==R.id.minus_btn){ + score--; + if (score % 100 >= 11 && score % 100 <= 14) { + letter = " раз"; + } else { + switch ((int) (score % 10)) { + case 1: + letter = " раз"; + break; + case 2: + case 3: + case 4: + letter = " раза"; + break; + default: + letter = " раз"; + } + } + String s = "Кнопка нажата: " + score + letter; + mainText.setText(s); + } + else if (id==R.id.drop_btn){ + score=0; + String s = "Кнопка нажата " + score + " раз"; + mainText.setText(s); + } + + } +}