Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // QUESTION SCORE TEXT VIEWS
- private TextView question1_score, question2_score, question3_score, question4_score, question5_score, finalScoreTextView, nameFinalScoreTextView;
- // TO STORE THE ANSWER AND MATCH VALUES FROM PREFERENCES FOR FINAL SCORE INT
- private int question1_answer_value, question2_answer_value, question3_answer_value, question4_answer_value, question5_answer_value, quizScoreInt, courtInt;
- public int finalInt = 0;
- // TO STORE THE NAME VALUE FROM PREFERENCES
- private String nameValue, playerNameToUse;
- // FOR DISPLAYING THE SCORES
- private TextView quizScoreView, courtScoreView, finalScoreView, endMsgView;
- // FOR EASIER ACCESS OF DATA
- private ArrayList<String> endMessages;
- // TRY AGAIN BUTTON
- private Button tryAgainBtn;
- SharedPreferences my_preferences;
- // METHOD FOR RESTARTING THE WHOLE APPLICATION
- private void restartApp() {
- Intent reloadMainActivity = new Intent(this, MainActivity.class);
- startActivity(reloadMainActivity);
- }
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.score_activity);
- // GETTING ACCESS TO WRITEN FILE VALUES FROM SHARED PREFERENCES
- my_preferences = PreferenceManager.getDefaultSharedPreferences(this);
- // GETTING THE STORED VALUES FROM SHARED PREFERENCES
- courtInt = my_preferences.getInt("set_value_a", 0);
- nameValue = my_preferences.getString("name_value", "");
- // FINDING THE TEXT VIEWVS TO DISPLAY THE SCORE
- question1_score = (TextView) findViewById(R.id.answer_value_1);
- question2_score = (TextView) findViewById(R.id.answer_value_2);
- question3_score = (TextView) findViewById(R.id.answer_value_3);
- question4_score = (TextView) findViewById(R.id.answer_value_4);
- question5_score = (TextView) findViewById(R.id.answer_value_5);
- finalScoreTextView = (TextView) findViewById(R.id.answer_value_final);
- // FINDING THE TEXT VIEW TO DISPLAY PLAYERS NAME
- nameFinalScoreTextView = (TextView) findViewById(R.id.name_final_score);
- // FINDING THE VIEWS TO DISPLAY SCORES AND MASSAGES
- quizScoreView = (TextView) findViewById(R.id.final_quiz_score_tV);
- courtScoreView = (TextView) findViewById(R.id.final_court_score_tV);
- finalScoreView = (TextView) findViewById(R.id.final_final_score_tv);
- endMsgView = (TextView) findViewById(R.id.end_msg_view);
- // GETTING THE VALUES FOR CORRECT ANSWERS
- question1_answer_value = my_preferences.getInt("value1", 2);
- question2_answer_value = my_preferences.getInt("value2", 2);
- question3_answer_value = my_preferences.getInt("value3", 2);
- question4_answer_value = my_preferences.getInt("value4", 2);
- question5_answer_value = my_preferences.getInt("value5", 2);
- // CALCULATING CORRECT AND INCORRECT ANSWERS
- quizScoreInt = question1_answer_value + question2_answer_value + question3_answer_value + question4_answer_value + question5_answer_value;
- // SETTING THE FINAL SCORE
- if (my_preferences != null) {
- finalInt = quizScoreInt + courtInt;
- } else {
- finalInt = 1;
- }
- // SETTING THE TEXT VALUES TO THE TEXT VIEWS
- quizScoreView.setText(quizScoreInt + "/5");
- courtScoreView.setText(courtInt + "/2");
- finalScoreView.setText(finalInt + "/7");
- // CHECKING THE ANSWER VALUES TO SET THE TEXT ON EACH QUESTION SCORE VIEW
- if (question1_answer_value == 1){
- question1_score.setText("Correct");
- } else {
- question1_score.setText("Incorrect");
- question1_score.setTextColor(Color.BLACK);
- }
- if (question2_answer_value == 1){
- question2_score.setText("Correct");
- } else {
- question2_score.setText("Incorrect");
- question2_score.setTextColor(Color.BLACK);
- }
- if (question3_answer_value == 1){
- question3_score.setText("Correct");
- } else {
- question3_score.setText("Incorrect");
- question3_score.setTextColor(Color.BLACK);
- }
- if (question4_answer_value == 1){
- question4_score.setText("Correct");
- } else {
- question4_score.setText("Incorrect");
- question4_score.setTextColor(Color.BLACK);
- }
- if (question5_answer_value == 1){
- question5_score.setText("Correct");
- } else {
- question5_score.setText("Incorrect");
- question5_score.setTextColor(Color.BLACK);
- }
- private QuestionAndAnswers questionAndAnswers;
- private TextView questionTextView;
- private RadioGroup buttonsGroup;
- private ArrayList<String> offeredAnswers;
- private int i = 0;
- public Question1() {
- // Required empty public constructor
- }
- @Override
- public void onResume() {
- super.onResume();
- setRetainInstance(true);
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- View rootView = inflater.inflate(R.layout.fragment_question1, container, false);
- // CREATING A LIST OF STRINGS (OFFERED ANSWERS)
- offeredAnswers = new ArrayList<String>();
- // ADDING THE STRINGS (ANSWERS)
- offeredAnswers.add("Ball sport");
- offeredAnswers.add("Combat sport");
- offeredAnswers.add("Team sport");
- // CREATING A CUSTOM OBJECT
- questionAndAnswers = new QuestionAndAnswers("1. Wrestling is a :", offeredAnswers);
- // FINDING THE TEXT VIEW TO DISPLAY THE ASSIGNED QUESTION
- questionTextView = (TextView) rootView.findViewById(R.id.question_text_view);
- questionTextView.setText(questionAndAnswers.getMyQuestion());
- // FINDING THE RADIO GROUP TO DISPLAY THE BUTTONS FOR CHOOSING THE ANSWER
- buttonsGroup = (RadioGroup) rootView.findViewById(R.id.radio_group);
- /* USING AN ARRAY LIST OF ANSWERS TO DISPLAY ALONGSIDE CREATED BUTTONS ADDED TO THE RADIO GROUP */
- ArrayList possibilities = (questionAndAnswers.getMyAnswers());
- for (int a = 0; a < possibilities.size(); a++){
- RadioButton buttons = new RadioButton(getContext());
- buttons.setText(possibilities.get(a).toString());
- buttons.setTextColor(Color.parseColor("#303F9F"));
- buttons.setTextSize(18);
- buttons.setPadding(20, 30, 20, 30);
- buttonsGroup.addView(buttons, a);
- }
- // USING PREFERENCE MANAGER TO WRITE TO THE FILE
- final SharedPreferences my_preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
- // FINDING THE VIEW PAGER FROM THE QUIZ APP ACTIVITY
- final ViewPager viewPager1 = (ViewPager) QuizApp.mInstance.childPager.findViewById(R.id.pager_quiz_app);
- // GETTING THE POSTITION OF THE NEST FRAGMENT (QUESTION5)
- final int nextFragment1 = viewPager1.getCurrentItem() + 1;
- // STORING THE VALUE IN CASE THE PLAYER HAVEN'T ANSWERED ANY QUESTIONS
- SharedPreferences.Editor lostValue = my_preferences.edit();
- lostValue.putInt("value1", 0);
- lostValue.apply();
- int count1 = buttonsGroup.getChildCount();
- for (int i = 0; i < count1; i++){
- buttonsGroup.getChildAt(i).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- final SharedPreferences.Editor sharedPrefEditor2 = my_preferences.edit();
- if (buttonsGroup.getChildAt(1).isPressed()) {
- sharedPrefEditor2.putInt("value1", 1);
- Toast toast = Toast.makeText(getContext(), "Mamu ti 100 puta", Toast.LENGTH_SHORT);
- toast.show();
- }
- sharedPrefEditor2.apply();
- // SETTING THE VIEW PAGER TO SWITCH TO NEXT FRAGMENT UPON CLICKING THE BUTTON
- viewPager1.setCurrentItem(nextFragment1);
- }
- });
- }
- return rootView;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement