Skip to content

Commit

Permalink
Fix move back issue #12 and hotfix for #9 by disabling orientation ch…
Browse files Browse the repository at this point in the history
…ange
  • Loading branch information
VivekThazhathattil committed Oct 12, 2021
1 parent 1c1b9b1 commit 060909e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
android:roundIcon="@mipmap/icon"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:screenOrientation="nosensor"
android:configChanges="orientation|keyboardHidden|keyboard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

public class EvaluationFragment extends Fragment {
private ArrayList<Integer> solutionList;
public static final String TAG = "EVAL";

public EvaluationFragment(ArrayList<Integer> solutionList) {
this.solutionList = solutionList;
Expand Down
16 changes: 11 additions & 5 deletions app/src/main/java/com/example/spokennumbers/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@ public void switchToInGameFragment(float timeDelay, float timeInc, boolean isFem
ingameFragment = new spoken_numbers_ingame_fragment(timeDelay, timeInc, isFemale, isDec);
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_right);
//fragmentTransaction.addToBackStack(null);
fragmentTransaction.replace(mainFragment.getId(), ingameFragment);
fragmentTransaction.commit();
fragmentTransaction.addToBackStack(null).commit();
}
public void switchToRecallFragment(ArrayList<Integer> al){
recallFragment = new spoken_numbers_recall_fragment(al);
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_right);
//fragmentTransaction.addToBackStack(null);
fragmentTransaction.replace(ingameFragment.getId(), recallFragment);
fragmentTransaction.commit();
fragmentTransaction.addToBackStack(null).commit();
}

public void switchToEvalFragment(ArrayList<Integer> al){
Expand All @@ -54,7 +52,7 @@ public void switchToEvalFragment(ArrayList<Integer> al){
fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_right);
//fragmentTransaction.addToBackStack(null);
fragmentTransaction.replace(ingameFragment.getId(), evaluationFragment);
fragmentTransaction.commit();
fragmentTransaction.addToBackStack(null).commit();
}

public void switchToMainFragment(String mode){
Expand Down Expand Up @@ -95,6 +93,7 @@ protected void onCreate(Bundle savedInstanceState) {
fragmentTransaction.add(CONTENT_VIEW_ID, mainFragment);
fragmentTransaction.commit();
}

public void saveData(String delayTimeText, String incTimeText, boolean femaleChecked, boolean decimalChecked, boolean isEvalMode){
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
Expand Down Expand Up @@ -140,4 +139,11 @@ public int loadHighScore(){
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
return (int)sharedPreferences.getInt(HIGHSCORE, 0);
}
@Override
public void onBackPressed() {
if (ingameFragment != null) {
ingameFragment.stopCountDownTimer();
}
super.onBackPressed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class spoken_numbers_ingame_fragment extends Fragment {
private long defaultMillisLeft;
private long millisLeft;
private CountDownTimer timer;
public static final String TAG = "INGAME";

public spoken_numbers_ingame_fragment(float td, float ti, boolean isFemale, boolean isDecimal) {
this.timeDelay = td;
Expand Down Expand Up @@ -157,4 +158,9 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState){
}
});
}

public void stopCountDownTimer() {
if(timer != null)
timer.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class spoken_numbers_main_fragment extends Fragment {
private RadioButton binaryButton;
private String defaultTimeDelay;
private String defaultTimeInc;
public static final String TAG = "MAIN";

public spoken_numbers_main_fragment() {
// Required empty public constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
Expand All @@ -19,15 +20,15 @@ public class spoken_numbers_recall_fragment extends Fragment {
private int counter;
private TextView answerView;
private String recallString;
public static final String TAG = "RECALL";

public spoken_numbers_recall_fragment(ArrayList<Integer> al) {
num_list = al;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
}
}

@Override
Expand All @@ -36,8 +37,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return inflater.inflate(R.layout.spoken_numbers_recall_fragment, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
final ImageButton oneSolnButton = getView().findViewById(R.id.one_soln_button);
public void onViewCreated(@NonNull View view, Bundle savedInstanceState){
final ImageButton oneSolnButton = Objects.requireNonNull(getView()).findViewById(R.id.one_soln_button);
final ImageButton allSolnButton = getView().findViewById(R.id.all_soln_button);
final ImageButton noSolnButton = getView().findViewById(R.id.no_soln_button);
final ImageButton returnButton = getView().findViewById(R.id.exit_to_menu_button);
Expand Down

0 comments on commit 060909e

Please sign in to comment.