Skip to content

Commit e9a128e

Browse files
Improve onboarding typography and theme selection
1 parent d7b6a47 commit e9a128e

File tree

6 files changed

+31
-7
lines changed

6 files changed

+31
-7
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/onboarding/ThemeFragment.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import androidx.core.content.ContextCompat;
1111
import androidx.fragment.app.Fragment;
1212
import androidx.lifecycle.ViewModelProvider;
13+
import androidx.appcompat.app.AppCompatDelegate;
1314

1415
import com.d4rk.androidtutorials.java.R;
1516
import com.d4rk.androidtutorials.java.databinding.FragmentOnboardingSelectionBinding;
@@ -26,13 +27,13 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
2627

2728
binding.setTitle(getString(R.string.choose_your_style));
2829
binding.setDescription(getString(R.string.select_how_you_d_like_the_app_to_look));
29-
binding.setFirstIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_theme));
30+
binding.setFirstIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_light_mode));
3031
binding.setFirstTitle(getString(R.string.light_mode));
3132
binding.setFirstDescription(getString(R.string.light_mode_description));
32-
binding.setSecondIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_about));
33+
binding.setSecondIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_dark_mode));
3334
binding.setSecondTitle(getString(R.string.dark_mode));
3435
binding.setSecondDescription(getString(R.string.dark_mode_description));
35-
binding.setThirdIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_android));
36+
binding.setThirdIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_system_mode));
3637
binding.setThirdTitle(getString(R.string.follow_system));
3738
binding.setThirdDescription(getString(R.string.follow_system_mode_description));
3839

@@ -63,15 +64,27 @@ private void selectOption(int index) {
6364
binding.optionFirst.radioButton.setChecked(index == 0);
6465
binding.optionSecond.radioButton.setChecked(index == 1);
6566
binding.optionThird.radioButton.setChecked(index == 2);
67+
68+
int mode;
69+
if (index == 0) {
70+
mode = AppCompatDelegate.MODE_NIGHT_NO;
71+
} else if (index == 1) {
72+
mode = AppCompatDelegate.MODE_NIGHT_YES;
73+
} else {
74+
mode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
75+
}
76+
AppCompatDelegate.setDefaultNightMode(mode);
6677
}
6778

6879
public void saveSelection() {
6980
String[] values = getResources().getStringArray(R.array.preference_theme_values);
70-
String value = values[0];
81+
String value;
7182
if (binding.optionFirst.radioButton.isChecked()) {
7283
value = values[1];
7384
} else if (binding.optionSecond.radioButton.isChecked()) {
7485
value = values[2];
86+
} else {
87+
value = values[0];
7588
}
7689
viewModel.setTheme(value);
7790
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
2+
<path android:fillColor="#FF000000" android:pathData="M9.37 5.51A7 7 0 0 0 12 19a7 7 0 0 0 6.49-4.5 6.5 6.5 0 0 1 -9.12-9z"/>
3+
</vector>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
2+
<path android:fillColor="#FF000000" android:pathData="M6.76,4.84l-1.8,-1.79 -1.41,1.41 1.79,1.8 1.42,-1.42zM1,11h3v2H1v-2zm10,-9h2v3h-2V2zm7.66,3.05l1.79,-1.8 -1.41,-1.41 -1.8,1.79 1.42,1.42zM17,11h3v2h-3v-2zm-5,5a4,4 0 1,1 0,-8 4,4 0 0,1 0,8zm5.24,1.16l1.8,1.79 1.41,-1.41 -1.79,-1.8 -1.42,1.42zM13,22h-2v-3h2v3zm-7.66,-3.05l-1.79,1.8 1.41,1.41 1.8,-1.79 -1.42,-1.42z"/>
3+
</vector>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
2+
<path android:fillColor="#FF000000" android:pathData="M17,1H7C5.9,1 5,1.9 5,3v18c0,1.1 0.9,2 2,2h10c1.1,0 2-0.9 2-2V3c0-1.1-0.9-2-2-2zm0,18H7V5h10v14z"/>
3+
</vector>

app/src/main/res/layout/activity_onboarding.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
app:layout_constraintBottom_toTopOf="@+id/bottomBar"
2525
app:layout_constraintEnd_toEndOf="parent"
2626
app:layout_constraintStart_toStartOf="parent"
27-
app:layout_constraintTop_toTopOf="parent" />
27+
app:layout_constraintTop_toBottomOf="@id/buttonSkip" />
2828

2929
<LinearLayout
3030
android:id="@+id/bottomBar"

app/src/main/res/layout/fragment_onboarding_selection.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,25 @@
5656

5757
<com.google.android.material.textview.MaterialTextView
5858
android:id="@+id/title"
59-
android:layout_width="wrap_content"
59+
android:layout_width="0dp"
6060
android:layout_height="wrap_content"
6161
android:layout_marginTop="32dp"
6262
android:text="@{title}"
6363
android:textAppearance="?attr/textAppearanceHeadlineMedium"
64+
android:textAlignment="center"
6465
app:layout_constraintEnd_toEndOf="parent"
6566
app:layout_constraintStart_toStartOf="parent"
6667
app:layout_constraintTop_toTopOf="parent" />
6768

6869
<com.google.android.material.textview.MaterialTextView
6970
android:id="@+id/description"
70-
android:layout_width="wrap_content"
71+
android:layout_width="0dp"
7172
android:layout_height="wrap_content"
7273
android:layout_marginTop="8dp"
7374
android:text="@{description}"
7475
android:textAppearance="?attr/textAppearanceBodyMedium"
7576
android:textColor="?attr/colorOnSurfaceVariant"
77+
android:textAlignment="center"
7678
app:layout_constraintEnd_toEndOf="parent"
7779
app:layout_constraintStart_toStartOf="parent"
7880
app:layout_constraintTop_toBottomOf="@id/title" />

0 commit comments

Comments
 (0)