Skip to content

Commit 06437f2

Browse files
Allow onboarding font selection
1 parent ba89599 commit 06437f2

File tree

10 files changed

+307
-100
lines changed

10 files changed

+307
-100
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.d4rk.androidtutorials.java.ui.screens.onboarding;
2+
3+
import android.os.Bundle;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
8+
import androidx.annotation.NonNull;
9+
import androidx.annotation.Nullable;
10+
import androidx.fragment.app.Fragment;
11+
import androidx.lifecycle.ViewModelProvider;
12+
13+
import com.d4rk.androidtutorials.java.R;
14+
import com.d4rk.androidtutorials.java.databinding.FragmentOnboardingFontBinding;
15+
16+
public class FontFragment extends Fragment {
17+
18+
private FragmentOnboardingFontBinding binding;
19+
private OnboardingViewModel viewModel;
20+
21+
@Nullable
22+
@Override
23+
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
24+
binding = FragmentOnboardingFontBinding.inflate(inflater, container, false);
25+
return binding.getRoot();
26+
}
27+
28+
@Override
29+
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
30+
super.onViewCreated(view, savedInstanceState);
31+
viewModel = new ViewModelProvider(requireActivity()).get(OnboardingViewModel.class);
32+
}
33+
34+
public void saveSelection() {
35+
int checkedId = binding.fontGroup.getCheckedRadioButtonId();
36+
String[] values = getResources().getStringArray(R.array.code_font_values);
37+
String value = values[6];
38+
if (checkedId == R.id.radio_font_audiowide) {
39+
value = values[0];
40+
} else if (checkedId == R.id.radio_font_fira_code) {
41+
value = values[1];
42+
} else if (checkedId == R.id.radio_font_jetbrains_mono) {
43+
value = values[2];
44+
} else if (checkedId == R.id.radio_font_noto_sans_mono) {
45+
value = values[3];
46+
} else if (checkedId == R.id.radio_font_poppins) {
47+
value = values[4];
48+
} else if (checkedId == R.id.radio_font_roboto_mono) {
49+
value = values[5];
50+
}
51+
viewModel.setMonospaceFont(value);
52+
}
53+
54+
@Override
55+
public void onDestroyView() {
56+
super.onDestroyView();
57+
binding = null;
58+
}
59+
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public void onPageSelected(int position) {
5050
((StartPageFragment) fragment).saveSelection();
5151
} else if (fragment instanceof BottomLabelsFragment) {
5252
((BottomLabelsFragment) fragment).saveSelection();
53+
} else if (fragment instanceof FontFragment) {
54+
((FontFragment) fragment).saveSelection();
5355
}
5456
}
5557
currentPosition = position;
@@ -103,6 +105,8 @@ public void onTabReselected(TabLayout.Tab tab) { }
103105
((StartPageFragment) fragment).saveSelection();
104106
} else if (fragment instanceof BottomLabelsFragment) {
105107
((BottomLabelsFragment) fragment).saveSelection();
108+
} else if (fragment instanceof FontFragment) {
109+
((FontFragment) fragment).saveSelection();
106110
}
107111

108112
if (current < adapter.getItemCount() - 1) {
@@ -146,14 +150,16 @@ public Fragment createFragment(int position) {
146150
return new StartPageFragment();
147151
case 2:
148152
return new BottomLabelsFragment();
153+
case 3:
154+
return new FontFragment();
149155
default:
150156
return new DataFragment();
151157
}
152158
}
153159

154160
@Override
155161
public int getItemCount() {
156-
return 4;
162+
return 5;
157163
}
158164
}
159165
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public void setBottomNavLabels(String value) {
3737
prefs.edit().putString(context.getString(R.string.key_bottom_navigation_bar_labels), value).apply();
3838
}
3939

40+
public void setMonospaceFont(String value) {
41+
prefs.edit().putString(context.getString(R.string.key_monospace_font), value).apply();
42+
}
43+
4044
public void markOnboardingComplete() {
4145
prefs.edit().putBoolean(context.getString(R.string.key_onboarding_complete), true).apply();
4246
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
5+
android:layout_height="match_parent"
6+
android:fitsSystemWindows="true">
67

78
<androidx.viewpager2.widget.ViewPager2
89
android:id="@+id/viewPager"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
5+
android:layout_height="match_parent"
6+
android:fitsSystemWindows="true">
67

78
<me.zhanghai.android.fastscroll.FastScrollScrollView
89
android:id="@+id/scroll_view"
Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,59 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
android:layout_width="match_parent"
45
android:layout_height="match_parent">
56

67
<LinearLayout
78
android:orientation="vertical"
8-
android:padding="16dp"
9+
android:padding="24dp"
910
android:layout_width="match_parent"
1011
android:layout_height="wrap_content">
1112

12-
<TextView
13-
android:layout_width="wrap_content"
13+
<com.google.android.material.card.MaterialCardView
14+
android:layout_width="match_parent"
1415
android:layout_height="wrap_content"
15-
android:text="@string/bottom_navigation_labels"
16-
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6" />
16+
app:cardElevation="0dp"
17+
android:padding="16dp">
1718

18-
<RadioGroup
19-
android:id="@+id/labels_group"
20-
android:layout_width="match_parent"
21-
android:layout_height="wrap_content">
22-
23-
<RadioButton
24-
android:id="@+id/radio_labeled"
25-
android:layout_width="wrap_content"
26-
android:layout_height="wrap_content"
27-
android:checked="true"
28-
android:text="@string/labeled" />
29-
30-
<RadioButton
31-
android:id="@+id/radio_selected"
32-
android:layout_width="wrap_content"
33-
android:layout_height="wrap_content"
34-
android:text="@string/selected" />
35-
36-
<RadioButton
37-
android:id="@+id/radio_unlabeled"
38-
android:layout_width="wrap_content"
39-
android:layout_height="wrap_content"
40-
android:text="@string/unlabeled" />
41-
</RadioGroup>
19+
<LinearLayout
20+
android:orientation="vertical"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content">
23+
24+
<com.google.android.material.textview.MaterialTextView
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:text="@string/bottom_navigation_labels"
28+
android:layout_marginBottom="16dp"
29+
style="@style/TextAppearance.Material3.TitleLarge" />
30+
31+
<RadioGroup
32+
android:id="@+id/labels_group"
33+
android:layout_width="match_parent"
34+
android:layout_height="wrap_content">
35+
36+
<com.google.android.material.radiobutton.MaterialRadioButton
37+
android:id="@+id/radio_labeled"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:checked="true"
41+
android:text="@string/labeled" />
42+
43+
<com.google.android.material.radiobutton.MaterialRadioButton
44+
android:id="@+id/radio_selected"
45+
android:layout_width="wrap_content"
46+
android:layout_height="wrap_content"
47+
android:text="@string/selected" />
48+
49+
<com.google.android.material.radiobutton.MaterialRadioButton
50+
android:id="@+id/radio_unlabeled"
51+
android:layout_width="wrap_content"
52+
android:layout_height="wrap_content"
53+
android:text="@string/unlabeled" />
54+
</RadioGroup>
55+
</LinearLayout>
56+
</com.google.android.material.card.MaterialCardView>
4257

4358
</LinearLayout>
4459
</ScrollView>
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
android:layout_width="match_parent"
45
android:layout_height="match_parent">
56

67
<LinearLayout
78
android:orientation="vertical"
8-
android:padding="16dp"
9+
android:padding="24dp"
910
android:layout_width="match_parent"
1011
android:layout_height="wrap_content">
1112

12-
<TextView
13-
android:layout_width="wrap_content"
13+
<com.google.android.material.card.MaterialCardView
14+
android:layout_width="match_parent"
1415
android:layout_height="wrap_content"
15-
android:text="@string/data_dialog_message" />
16+
app:cardElevation="0dp"
17+
android:padding="16dp">
18+
19+
<com.google.android.material.textview.MaterialTextView
20+
android:layout_width="wrap_content"
21+
android:layout_height="wrap_content"
22+
android:text="@string/data_dialog_message" />
23+
</com.google.android.material.card.MaterialCardView>
1624
</LinearLayout>
1725
</ScrollView>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<LinearLayout
8+
android:orientation="vertical"
9+
android:padding="24dp"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content">
12+
13+
<com.google.android.material.card.MaterialCardView
14+
android:layout_width="match_parent"
15+
android:layout_height="wrap_content"
16+
app:cardElevation="0dp"
17+
android:padding="16dp">
18+
19+
<LinearLayout
20+
android:orientation="vertical"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content">
23+
24+
<com.google.android.material.textview.MaterialTextView
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:text="@string/code_font"
28+
android:layout_marginBottom="16dp"
29+
style="@style/TextAppearance.Material3.TitleLarge" />
30+
31+
<RadioGroup
32+
android:id="@+id/font_group"
33+
android:layout_width="match_parent"
34+
android:layout_height="wrap_content">
35+
36+
<com.google.android.material.radiobutton.MaterialRadioButton
37+
android:id="@+id/radio_font_audiowide"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:text="@string/audiowide" />
41+
42+
<com.google.android.material.radiobutton.MaterialRadioButton
43+
android:id="@+id/radio_font_fira_code"
44+
android:layout_width="wrap_content"
45+
android:layout_height="wrap_content"
46+
android:text="@string/fira_code" />
47+
48+
<com.google.android.material.radiobutton.MaterialRadioButton
49+
android:id="@+id/radio_font_jetbrains_mono"
50+
android:layout_width="wrap_content"
51+
android:layout_height="wrap_content"
52+
android:text="@string/jetbrains_mono" />
53+
54+
<com.google.android.material.radiobutton.MaterialRadioButton
55+
android:id="@+id/radio_font_noto_sans_mono"
56+
android:layout_width="wrap_content"
57+
android:layout_height="wrap_content"
58+
android:text="@string/noto_sans_mono" />
59+
60+
<com.google.android.material.radiobutton.MaterialRadioButton
61+
android:id="@+id/radio_font_poppins"
62+
android:layout_width="wrap_content"
63+
android:layout_height="wrap_content"
64+
android:text="@string/poppins" />
65+
66+
<com.google.android.material.radiobutton.MaterialRadioButton
67+
android:id="@+id/radio_font_roboto_mono"
68+
android:layout_width="wrap_content"
69+
android:layout_height="wrap_content"
70+
android:text="@string/roboto_mono" />
71+
72+
<com.google.android.material.radiobutton.MaterialRadioButton
73+
android:id="@+id/radio_font_google_sans_code"
74+
android:layout_width="wrap_content"
75+
android:layout_height="wrap_content"
76+
android:checked="true"
77+
android:text="@string/google_sans_code" />
78+
</RadioGroup>
79+
</LinearLayout>
80+
</com.google.android.material.card.MaterialCardView>
81+
82+
</LinearLayout>
83+
</ScrollView>

0 commit comments

Comments
 (0)