<file_sep># First App

## Release notes
### 0.0.1-1
- Первая версия приложения
### 0.1.0-2
- Добавлена кнопка для перехода в активити, предоставляющую информацию о типах пива
### 0.2.1-1
- Добавлена кнопка для перехода в активити с секундомером
- Поправлено отображение Рикардо с текстом
### 0.3.0-1
- Добавлена кнопка для перехода в активити с картами из игры "Берсерк"
- Мелкие правки
### x.x.x-x
- Coming soon...

## Downloads
- Версия 0.0.1-1 - <a href="https://github.com/sk1ly/first_app/raw/master/apks/first_app_debug_0.0.1-1.apk" download>скачать</a>
- Версия 0.1.0-2 - <a href="https://github.com/sk1ly/first_app/raw/master/apks/first_app_debug_0.1.0-2.apk" download>скачать</a>
- Версия 0.2.1-1 - <a href="https://github.com/sk1ly/first_app/raw/master/apks/first_app_debug_0.2.1-1.apk" download>скачать</a>
- Версия 0.3.0-1 - <a href="https://github.com/sk1ly/first_app/raw/master/apks/first_app_debug_0.3.0-1.apk" download>скачать</a>
- Coming soon...
<file_sep>package ru.sk1ly.firstapp;

/**
 * Инкапсулирует сущность карты
 */
public class BerserkCard {

    /**
     * Тестовый набор карт
     */
    public final static BerserkCard[] TEST_BERSERK_CARDS = {
            new BerserkCard("Анкаб", 3, R.drawable.berserk_card_1),
            new BerserkCard("Агатервол", 5, R.drawable.berserk_card_2),
            new BerserkCard("Акванит", 3, R.drawable.berserk_card_3)
    };

    private final String name;
    private final int cost;
    private final int imageResourceId;

    public BerserkCard(String name, int cost, int imageResourceId) {
        this.name = name;
        this.cost = cost;
        this.imageResourceId = imageResourceId;
    }

    public String getName() {
        return name;
    }

    public int getCost() {
        return cost;
    }

    public int getImageResourceId() {
        return imageResourceId;
    }

}
<file_sep>package ru.sk1ly.firstapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class BeerInfoActivity extends Activity {

    private Spinner mBeerGlobalTypeSpinner;
    private Spinner mBeerSubtypeSpinner;
    private TextView mBeerInfoTextOnPaper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_beer_info);

        mBeerGlobalTypeSpinner = findViewById(R.id.beer_global_type_spinner);
        mBeerSubtypeSpinner = findViewById(R.id.beer_subtype_spinner);
        mBeerInfoTextOnPaper = findViewById(R.id.beer_info_text_on_paper);

        mBeerGlobalTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
                String itemText = (String) ((TextView) selectedItemView).getText();
                ArrayAdapter<CharSequence> adapter;
                if (itemText.equals("Эль")) {
                    adapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.ale_beer_types, android.R.layout.simple_spinner_item);
                } else if (itemText.equals("Лагер")) {
                    adapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.lager_beer_types, android.R.layout.simple_spinner_item);
                } else {
                    adapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.mixed_beer_types, android.R.layout.simple_spinner_item);
                }
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                mBeerSubtypeSpinner.setAdapter(adapter);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parentView) {
                // nothing to do
            }

        });
    }

    public void onClickShowBeerInfoButton(View view) {
        String selectedBeerGlobalType = String.valueOf(mBeerGlobalTypeSpinner.getSelectedItem());
        String selectedBeerSubtype = String.valueOf(mBeerSubtypeSpinner.getSelectedItem());
        if (selectedBeerGlobalType.equals("Эль")) {
            setAleBeerInfo(selectedBeerSubtype);
        } else if (selectedBeerGlobalType.equals("Лагер")) {
            setLagerBeerInfo(selectedBeerSubtype);
        } else {
            setMixedBeerInfo(selectedBeerSubtype);
        }
    }

    private void setAleBeerInfo(String selectedBeerSubtype) {
        switch (selectedBeerSubtype) {
            case "Пшеничное пиво":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_witbier);
                break;
            case "Берлинское белое":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_berliner_weisse);
                break;
            case "Блонд эль":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_belgian_blond_ale);
                break;
            case "Светлый эль":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_pale_ale);
                break;
            case "Кёльш":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_kolsch);
                break;
            case "Золотой эль":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_golden_ale);
                break;
            case "Трипель":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_tripel_ale);
                break;
            case "Индийский светлый эль":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_india_pale_ale);
                break;
            case "Старый эль":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_old_ale);
                break;
            case "Янтарный эль":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_amber_ale);
                break;
            case "Квадрупель":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_quadrupel);
                break;
            case "Мягкий эль":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_mild_ale);
                break;
            case "Старое коричневое":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_flanders_brown_ale);
                break;
            case "Коричневый эль":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_brown_ale);
                break;
            case "Портер":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_porter);
                break;
            case "Стаут":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_ale_stout);
                break;
        }
    }

    private void setLagerBeerInfo(String selectedBeerSubtype) {
        switch (selectedBeerSubtype) {
            case "Мюнхенское светлое":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_lager_munchner_helles_lager);
                break;
            case "Пильзнер":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_lager_pilsner);
                break;
            case "Экспорт (дортмундер)":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_lager_export);
                break;
            case "Венский лагер":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_lager_vienna_lager);
                break;
            case "Келлербир":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_lager_kellerbier);
                break;
            case "Бок":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_lager_bockbier);
                break;
            case "Темный лагер":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_lager_dark_lager);
                break;
            case "Черное пиво":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_lager_schwarzbier);
                break;
        }
    }

    private void setMixedBeerInfo(String selectedBeerSubtype) {
        switch (selectedBeerSubtype) {
            case "Сливочный эль":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_mixed_cream_ale);
                break;
            case "Ламбик":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_mixed_lambic);
                break;
            case "Мартовское пиво":
                getStringResourceAndSetHisToBeerInfoTextView(R.string.beer_info_mixed_marzen);
                break;
        }
    }

    private void getStringResourceAndSetHisToBeerInfoTextView(int stringResource) {
        mBeerInfoTextOnPaper.setText(getString(stringResource));
    }
}
<file_sep>package ru.sk1ly.firstapp;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import static ru.sk1ly.firstapp.Constants.*;

public class AuthorizeActivity extends AppCompatActivity {

    public EditText mUserFirstName;
    public EditText mUserSecondName;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_authorize);
        mUserFirstName = findViewById(R.id.input_first_user_name);
        mUserSecondName = findViewById(R.id.input_second_user_name);
    }

    public void onClickAuthorizeCompleteButton(View view) {
        Intent answerIntent = new Intent();
        if (mUserFirstName.getText().toString().isEmpty() ||
                mUserSecondName.getText().toString().isEmpty()) {
            Toast.makeText(getApplicationContext(),
                    "Необходимо заполнить два поля! Вы не были авторизованы", Toast.LENGTH_LONG).show();
            setResult(RESULT_CANCELED, answerIntent);
        } else {
            answerIntent.putExtra(Keys.USER_FIRST_NAME_ANSWER, mUserFirstName.getText().toString());
            answerIntent.putExtra(Keys.USER_SECOND_NAME_ANSWER, mUserSecondName.getText().toString());
            setResult(RESULT_OK, answerIntent);
        }
        finish();
    }

}
<file_sep>package ru.sk1ly.firstapp;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import static ru.sk1ly.firstapp.Constants.*;

public class MainActivity extends AppCompatActivity {

    private static final int AUTHORIZE_USER = 0;
    private static final String KEK_WORD = "Kek";
    private static final String PORTRAIT_ORIENTATION_WORD_RUS = "портретная";
    private static final String LANDSCAPE_ORIENTATION_WORD_RUS = "альбомная";
    private static final String UNKNOWN_ORIENTATION_WORD_RUS = "неизвестная";

    private TextView mUserFirstName;
    private TextView mUserSecondName;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setTitle(R.string.activity_main_label);
        mUserFirstName = findViewById(R.id.user_first_name);
        mUserSecondName = findViewById(R.id.user_second_name);

        if (savedInstanceState != null) {
            mUserFirstName.setText(savedInstanceState.getCharSequence(Keys.USER_FIRST_NAME));
            mUserSecondName.setText(savedInstanceState.getCharSequence(Keys.USER_SECOND_NAME));
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    public void onAuthorizeMenuClick(MenuItem item) {
        Toast.makeText(getApplicationContext(), "Скоро тут будет авторизация!", Toast.LENGTH_SHORT).show();
    }


    public void onSettingsMenuClick(MenuItem item) {
        Toast.makeText(getApplicationContext(), "Скоро тут будут настройки!", Toast.LENGTH_SHORT).show();
    }

    public void onAboutAppMenuClick(MenuItem item) {
        Intent aboutAppIntent = new Intent(MainActivity.this, AboutActivity.class);
        startActivity(aboutAppIntent);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == AUTHORIZE_USER && resultCode == RESULT_OK) {
            mUserFirstName.setText(data.getStringExtra(Keys.USER_FIRST_NAME_ANSWER));
            mUserSecondName.setText(data.getStringExtra(Keys.USER_SECOND_NAME_ANSWER));
        }  // TODO AUTHORIZE CODE? И правильно ли использовать RESULT_CODE CANCELED?

    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putCharSequence(Keys.USER_FIRST_NAME, mUserFirstName.getText());
        outState.putCharSequence(Keys.USER_SECOND_NAME, mUserSecondName.getText());
    }

    public void onClickAuthorizeButton(View view) {
        Intent authorizeIntent = new Intent(MainActivity.this, AuthorizeActivity.class);
        startActivityForResult(authorizeIntent, AUTHORIZE_USER);
    }

    public void onClickSayKekButton(View view) {
        Toast.makeText(getApplicationContext(), KEK_WORD, Toast.LENGTH_LONG).show();
    }

    public void onClickSayKekWithRicardoButton(View view) {
        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.ricardo_with_kek_toast,
                (ViewGroup) findViewById(R.id.ricardo_with_kek_toast_container));

        TextView text = layout.findViewById(R.id.kek_word);
        text.setText(KEK_WORD);

        Toast toast = new Toast(getApplicationContext());
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(layout);
        toast.show();
    }

    public void onClickGetOrientationButton(View view) {
        int currentOrientation = getResources().getConfiguration().orientation;
        if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
            makeOrientationToastText(PORTRAIT_ORIENTATION_WORD_RUS);
        } else if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
            makeOrientationToastText(LANDSCAPE_ORIENTATION_WORD_RUS);
        } else {
            makeOrientationToastText(UNKNOWN_ORIENTATION_WORD_RUS);
        }
    }

    public void onClickWorkWithDisplayButton(View view) {
        Intent workWithDisplayIntent = new Intent(MainActivity.this, WorkWithDisplayActivity.class);
        startActivity(workWithDisplayIntent);
    }

    public void onClickBeerInfoButton(View view) {
        Intent beerInfoIntent = new Intent(MainActivity.this, BeerInfoActivity.class);
        startActivity(beerInfoIntent);
    }

    public void onClickStopwatchButton(View view) {
        Intent stopwatchIntent = new Intent(MainActivity.this, StopwatchActivity.class);
        startActivity(stopwatchIntent);
    }

    public void onClickBerserkCardsInfoButton(View view) {
        Intent berserkCardsMainIntent = new Intent(MainActivity.this, BerserkCardsInfoMainActivity.class);
        startActivity(berserkCardsMainIntent);
    }

    private void makeOrientationToastText(String orientationType) {
        Toast.makeText(getApplicationContext(), "В данный момент " + orientationType + " ориентация", Toast.LENGTH_LONG).show();
    }
}
<file_sep>package ru.sk1ly.firstapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

/**
 * Активность с подробным описанием карты.
 * Если приложение запущено на планшете, то активность не используется.
 */
public class BerserkCardsInfoDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_berserk_cards_info_detail);
        BerserkCardsInfoDetailFragment frag = (BerserkCardsInfoDetailFragment)
                getSupportFragmentManager().findFragmentById(R.id.berserk_cards_info_detail_fragment);
        int cardId = (int) getIntent().getExtras().get(Constants.Keys.BERSERK_CARD_ID);
        frag.setCardId(cardId);
    }
}<file_sep>package ru.sk1ly.firstapp;

public class Constants {

    public static class Keys {
        public static final String USER_FIRST_NAME = "ru.sk1ly.firstapp.USER_FIRST_NAME";
        public static final String USER_SECOND_NAME = "ru.sk1ly.firstapp.USER_SECOND_NAME";
        public static final String USER_FIRST_NAME_ANSWER = "ru.sk1ly.firstapp.USER_FIRST_NAME_ANSWER";
        public static final String USER_SECOND_NAME_ANSWER = "ru.sk1ly.firstapp.USER_SECOND_NAME_ANSWER";
        public static final String STOPWATCH_STATUS = "ru.sk1ly.firstapp.STOPWATCH_STATUS";
        public static final String STOPWATCH_SECONDS = "ru.sk1ly.firstapp.SECONDS";
        public static final String BERSERK_CARD_ID = "ru.sk1ly.firstapp.BERSERK_CARD_ID";
    }
}
