Skip to content

Commit

Permalink
fix dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
VivekThazhathattil committed Oct 3, 2022
1 parent c28670a commit 9542cb4
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 136 deletions.
8 changes: 5 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.example.spokennumbers"
minSdkVersion 16
targetSdkVersion 29
versionCode 9
versionName "1.8"
versionCode 10
versionName "1.8.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
54 changes: 51 additions & 3 deletions app/src/main/java/com/example/spokennumbers/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import java.time.Instant;
import java.util.ArrayList;
Expand All @@ -26,14 +32,13 @@ public class MainActivity extends AppCompatActivity {
private static final int CONTENT_VIEW_ID = 10101010;

private FragmentManager fragmentManager;
/* when I started out with this project, spoken numbers
* was the only game that I intended to add to this app.
* So mainFragment is for the Spoken numbers module */
private spoken_numbers_main_fragment mainFragment;
private spoken_numbers_ingame_fragment ingameFragment;
private spoken_numbers_recall_fragment recallFragment;
private EvaluationFragment evaluationFragment;

private Boolean is_night_mode = false;

private FlashAnzan flashAnzanFragment;
private GamesMenu gamesMenuFragment;

Expand Down Expand Up @@ -128,12 +133,46 @@ public void switchToMainFragment(String mode){
}
fragmentTransaction.commit();
}

@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.dekadico_menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem menuItem){
switch(menuItem.getItemId()){
case R.id.toggle_dark_mode:
if(!is_night_mode){
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
is_night_mode = true;
}
else{
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
is_night_mode = false;
}
return true;
case R.id.github_link:
Intent viewIntent =
new Intent("android.intent.action.VIEW",
Uri.parse("https://github.com/VivekThazhathattil/dekadico"));
startActivity(viewIntent);
return true;
default:
return super.onOptionsItemSelected(menuItem);
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout frame = new FrameLayout(this);
frame.setId(CONTENT_VIEW_ID);

is_night_mode = AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES;

// setContentView(R.layout.activity_main);
setContentView(frame, new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
Expand Down Expand Up @@ -172,4 +211,13 @@ public void onBackPressed() {
}
super.onBackPressed();
}

@Override
public void recreate(){
finish();
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

startActivity(getIntent());
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
}
13 changes: 1 addition & 12 deletions app/src/main/java/com/example/spokennumbers/PrefConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class PrefConfig {
public static final String SHARED_PREFS = "sharedPrefs";

/* Spoken numbers module */
private static final String NIGHT_MODE = "is_night_mode";
public static final String DELAYTIME = "delayTime";
public static final String INCTIME = "incTime";
public static final String ISFEMALE = "isFemale";
Expand Down Expand Up @@ -39,14 +38,13 @@ public PrefConfig(Context context){
}

public void saveData(String delayTimeText, String incTimeText, boolean femaleChecked,
boolean decimalChecked, boolean isEvalMode, boolean isNightMode){
boolean decimalChecked, boolean isEvalMode){
editor = sharedPreferences.edit();
editor.putString(DELAYTIME, delayTimeText);
editor.putString(INCTIME, incTimeText);
editor.putBoolean(ISFEMALE, femaleChecked);
editor.putBoolean(ISDECIMAL, decimalChecked);
editor.putBoolean(EVALMODE, isEvalMode);
editor.putBoolean(NIGHT_MODE, isNightMode);
editor.apply();
}

Expand Down Expand Up @@ -128,13 +126,4 @@ public void saveHighScore(int newScore){
public int loadHighScore(){
return (int)sharedPreferences.getInt(HIGHSCORE, 0);
}

public boolean loadNightModeChecked(){
return (boolean)sharedPreferences.getBoolean(NIGHT_MODE, false);
}
public void saveNightModeChecked(boolean isNightMode){
editor = sharedPreferences.edit();
editor.putBoolean(NIGHT_MODE, isNightMode);
editor.apply();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState){
final Button incrementButton = getView().findViewById(R.id.time_increment);
final TextView currentTimeTextView = getView().findViewById(R.id.current_time_control_text);

String currTimeText = timeDelay + "s";
String currTimeText = String.format("%.3f", timeDelay) + "s";
currentTimeTextView.setText(currTimeText);

String timeIncStr = "+" + timeInc;
Expand All @@ -117,7 +117,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState){

incrementButton.setOnClickListener(v -> {
timeDelay += timeInc;
String currTimeText12 = timeDelay + "s";
String currTimeText12 = String.format("%.3f", timeDelay) + "s";
currentTimeTextView.setText(currTimeText12);
timer.cancel();
timer = setupTimer(defaultMillisLeft, timeDelay);
Expand All @@ -129,7 +129,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState){
return;
}
timeDelay -= timeInc;
String currTimeText1 = timeDelay + "s";
String currTimeText1 = String.format("%.3f", timeDelay) + "s";
currentTimeTextView.setText(currTimeText1);
timer.cancel();
timer = setupTimer(defaultMillisLeft, timeDelay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,6 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
boolean evalState = MainActivity.prefConfig.loadEvalModeChecked();
evalSwitch.setChecked(evalState);

Switch nightSwitch = Objects.requireNonNull(getView()).findViewById(R.id.night_mode_switch);
boolean isNightModeOn = MainActivity.prefConfig.loadNightModeChecked();
nightSwitch.setChecked(isNightModeOn);
if(isNightModeOn)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
else
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

nightSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
// @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// //AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
// if(isChecked){
// //AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
// }
// else {
// MainActivity.this.recreate();
// }
MainActivity.prefConfig.saveNightModeChecked(isChecked);
Toast toast = Toast.makeText(getContext(), "Restart app to apply theme changes.", Toast.LENGTH_SHORT);
toast.setMargin(50, 50);
toast.show();
}
});


TextView highScoreText = getView().findViewById(R.id.high_score_view);
int highScoreInt = MainActivity.prefConfig.loadHighScore();
String highScoreStr = "High Score: " + highScoreInt;
Expand Down Expand Up @@ -167,7 +141,7 @@ else if(binaryButton.isChecked()){
MainActivity.evaluationMode = evalSwitch.isChecked();

MainActivity.prefConfig.saveData(Float.toString(timeDelayNum),
Float.toString(timeIncNum), isFemaleVoice, isDecimal, MainActivity.evaluationMode, false);
Float.toString(timeIncNum), isFemaleVoice, isDecimal, MainActivity.evaluationMode);
((MainActivity) Objects.requireNonNull(getActivity())).switchToInGameFragment(timeDelayNum, timeIncNum, isFemaleVoice, isDecimal);
}
});
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_dark_mode_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M6.76,4.84l-1.8,-1.79 -1.41,1.41 1.79,1.79 1.42,-1.41zM4,10.5L1,10.5v2h3v-2zM13,0.55h-2L11,3.5h2L13,0.55zM20.45,4.46l-1.41,-1.41 -1.79,1.79 1.41,1.41 1.79,-1.79zM17.24,18.16l1.79,1.8 1.41,-1.41 -1.8,-1.79 -1.4,1.4zM20,10.5v2h3v-2h-3zM12,5.5c-3.31,0 -6,2.69 -6,6s2.69,6 6,6 6,-2.69 6,-6 -2.69,-6 -6,-6zM11,22.45h2L13,19.5h-2v2.95zM3.55,18.54l1.41,1.41 1.79,-1.8 -1.41,-1.41 -1.79,1.8z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_info_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
</vector>
11 changes: 0 additions & 11 deletions app/src/main/res/drawable/ic_speaker.xml

This file was deleted.

12 changes: 0 additions & 12 deletions app/src/main/res/drawable/ic_speaker_stop.xml

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/time_delay_input"
app:srcCompat="@drawable/ic_speaker" />
/>

<Button
android:id="@+id/recall_button"
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/fragment_flash_anzan.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
android:ems="10"
android:hint="Default: 3"
android:inputType="number"
android:textColor="#000"
android:textColor="@color/colorAccent"
android:textSize="20sp" />
</TableRow>

Expand All @@ -58,7 +58,7 @@
android:ems="10"
android:hint="Default: 5"
android:inputType="number"
android:textColor="#000"
android:textColor="@color/colorAccent"
android:textSize="20sp" />
</TableRow>

Expand All @@ -81,7 +81,7 @@
android:ems="10"
android:hint="Default: 1000"
android:inputType="number"
android:textColor="#000"
android:textColor="@color/colorAccent"
android:textSize="20sp" />
</TableRow>

Expand All @@ -104,7 +104,7 @@
android:ems="10"
android:hint="Default: 1000 ms"
android:inputType="number"
android:textColor="#000"
android:textColor="@color/colorAccent"
android:textSize="20sp" />
</TableRow>

Expand Down
20 changes: 12 additions & 8 deletions app/src/main/res/layout/fragment_games_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/spoken_numbers_game_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:textColor="@color/textColor"
android:layout_margin="5dp"
android:text="Spoken Numbers" />
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/round_button_with_states"
android:text="Spoken Numbers"
android:textColor="@color/textColor" />

<Button
android:id="@+id/flash_anzan_game_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:textColor="@color/textColor"
android:layout_margin="5dp"
android:text="Flash Anzan" />
android:layout_margin="10dp"
android:background="@drawable/round_button_with_states"
android:text="Flash Anzan"
android:textColor="@color/textColor" />
</LinearLayout>
</FrameLayout>
Loading

0 comments on commit 9542cb4

Please sign in to comment.