Skip to content

Instantly share code, notes, and snippets.

@abusoid
Last active January 23, 2018 06:31
Show Gist options
  • Save abusoid/1d5ef4cafec8c81e44c35171a41dc485 to your computer and use it in GitHub Desktop.
Save abusoid/1d5ef4cafec8c81e44c35171a41dc485 to your computer and use it in GitHub Desktop.
Викторина по охране труда при работе на высоте
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.viktorina.MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/quest_one"
android:textColor="@color/colorPrimaryText"
android:textStyle="bold" />
<CheckBox
android:id="@+id/answer_one_true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/answer_one_true"
android:textColor="@color/colorPrimaryText" />
<CheckBox
android:id="@+id/answer_two_false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/answer_two_false"
android:textColor="@color/colorPrimaryText" />
<CheckBox
android:id="@+id/answer_three_false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/answer_three_false"
android:textColor="@color/colorPrimaryText" />
<CheckBox
android:id="@+id/answer_four_true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/answer_four_true"
android:textColor="@color/colorPrimaryText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/quest_two"
android:textColor="@color/colorPrimaryText"
android:textStyle="bold" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radio_answer_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/quest_two_answer_one" />
<RadioButton
android:id="@+id/radio_answer_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/quest_two_answer_two" />
<RadioButton
android:id="@+id/radio_answer_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/quest_two_answer_three" />
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/quest_three"
android:textColor="@color/colorPrimaryText"
android:textStyle="bold" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radio_two_answer_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/quest_three_answer_one" />
<RadioButton
android:id="@+id/radio_two_answer_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/quest_three_answer_two" />
<RadioButton
android:id="@+id/radio_two_answer_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/quest_three_answer_three" />
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/quest_four"
android:textColor="@color/colorPrimaryText"
android:textStyle="bold" />
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="@string/hint_edit_text" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="calculateScore"
android:text="@string/push_the_button" />
</LinearLayout>
</ScrollView>
package com.example.android.viktorina;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
int score = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/*
* Нажатие на кнопку вызывает этот метод в котором ведется подсчет и который вызывает остальные
* методы
*/
public void calculateScore(View view) {
score = oneQuest(score);
score = twoQuest(score);
score = threeQuest(score);
score = fourQuest(score);
if (score >= 4) {
Toast.makeText(this, getString(R.string.your_score) + score + getString(R.string.score) + getString(R.string.good_boy), Toast.LENGTH_LONG).show();
}
if (score >= 0 && score <= 3) {
Toast.makeText(this, getString(R.string.your_score) + score + getString(R.string.score) + getString(R.string.not_bad), Toast.LENGTH_LONG).show();
}
if (score < 0) {
Toast.makeText(this, getString(R.string.your_score) + score + getString(R.string.score) + getString(R.string.bad), Toast.LENGTH_LONG).show();
}
score = 0;
}
/*
Метод подсчета очков за первый вопрос
*/
private int oneQuest(int score) {
CheckBox answerOne = (CheckBox) findViewById(R.id.answer_one_true);
boolean hasAnswerOne = answerOne.isChecked();
if (hasAnswerOne) {
score++;
} else {
score--;
}
CheckBox answerTwo = (CheckBox) findViewById(R.id.answer_two_false);
boolean hasAnswerTwo = answerTwo.isChecked();
if (hasAnswerTwo) {
score--;
}
CheckBox answerThree = (CheckBox) findViewById(R.id.answer_three_false);
boolean hasAnswerThree = answerThree.isChecked();
if (hasAnswerThree) {
score--;
}
CheckBox answerFour = (CheckBox) findViewById(R.id.answer_four_true);
boolean hasAnswerFour = answerFour.isChecked();
if (hasAnswerFour) {
score++;
} else {
score--;
}
return score;
}
/*
Метод подсчета очков за второй вопрос
*/
private int twoQuest(int score) {
RadioButton radioOne = (RadioButton) findViewById(R.id.radio_answer_one);
boolean hasAnswerOne = radioOne.isChecked();
if (hasAnswerOne) {
score++;
}
RadioButton radioTwo = (RadioButton) findViewById(R.id.radio_answer_two);
boolean hasAnswerTwo = radioTwo.isChecked();
if (hasAnswerTwo) {
score--;
}
RadioButton radioThree = (RadioButton) findViewById(R.id.radio_answer_three);
boolean hasAnswerThree = radioThree.isChecked();
if (hasAnswerThree) {
score--;
}
return score;
}
/*
Метод подсчета очков за третий вопрос
*/
private int threeQuest(int score) {
RadioButton radioOne = (RadioButton) findViewById(R.id.radio_two_answer_one);
boolean hasAnswerOne = radioOne.isChecked();
if (hasAnswerOne) {
score--;
}
RadioButton radioTwo = (RadioButton) findViewById(R.id.radio_two_answer_two);
boolean hasAnswerTwo = radioTwo.isChecked();
if (hasAnswerTwo) {
score++;
}
RadioButton radioThree = (RadioButton) findViewById(R.id.radio_two_answer_three);
boolean hasAnswerThree = radioThree.isChecked();
if (hasAnswerThree) {
score--;
}
return score;
}
/*
Метод подсчета очков за четвертый вопрос
*/
private int fourQuest(int score) {
EditText editText = (EditText) findViewById(R.id.edit_text);
String nameOfBestCompany = editText.getText().toString();
switch (nameOfBestCompany) {
case "Вертикаль-М":
score++;
break;
case "Вертикаль-м":
score++;
break;
case "вертикаль-м":
score++;
break;
case "вертикаль-М":
score++;
break;
case "Вертикаль М":
score++;
break;
case "вертикаль м":
score++;
break;
case "Вертикаль м":
score++;
break;
case "вертикаль М":
score++;
break;
}
return score;
}
}
<resources>
<string name="app_name">Охрана труда в промышленном альпинизме</string>
<string name="quest_one">1) К работам на высоте относятся работы, когда:</string>
<string name="answer_one_true">Cуществуют риски, связанные с возможным падением работника с высоты 1,8 м и более</string>
<string name="answer_two_false">Работы производятся на площадках на расстоянии дальше 2 м от неогражденных перепадов по высоте более 1,8 м</string>
<string name="answer_three_false">Работник осуществляет подъем, превышающий по высоте 3 м или спуск, превышающий по высоте 3 м, по вертикальной лестнице, угол наклона которой к горизонтальной поверхности 75 градусов</string>
<string name="answer_four_true">Существуют риски, связанные с возможным падением работника с высоты менее 1,8 м, если работа проводится над машинами или механизмами, водной поверхностью или выступающими предметами</string>
<string name="push_the_button">Нажми на кнопку</string>
<string name="quest_two">2) Не допускается выполнение работ на высоте:</string>
<string name="quest_two_answer_one">В открытых местах при скорости воздушного потока (ветра) 20 м/с</string>
<string name="quest_two_answer_two">При монтаже (демонтаже) конструкций с большой парусностью при скорости ветра 7 м/с</string>
<string name="quest_two_answer_three">Во время дождя</string>
<string name="quest_three">3) Сколько должны храниться наряды-допуски на работы которые полностью закончены?</string>
<string name="quest_three_answer_one">180 дней</string>
<string name="quest_three_answer_two">30 дней</string>
<string name="quest_three_answer_three">365 дней</string>
<string name="quest_four">4) Лучшая в мире фирма по промышленному Альпинизму?</string>
<string name="hint_edit_text">Введите имя фирмы без ООО</string>
<string name="your_score">Ты набрал </string>
<string name="score">Очка(-ов)</string>
<string name="good_boy">Можешь спокойно лезть на высоту!</string>
<string name="not_bad">Эх, надо бы подучить!</string>
<string name="bad">Ты умудрился уйти в минус... Иди учи!</string>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment