Skip to content

Commit acb1ef9

Browse files
committed
Update settings to AndroidX
1 parent ac1c9f9 commit acb1ef9

4 files changed

Lines changed: 70 additions & 51 deletions

File tree

Hyperrail/build.gradle

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,23 @@ dependencies {
4949
implementation 'com.google.android.gms:play-services-maps:18.1.0'
5050
implementation fileTree(include: ['*.jar'], dir: 'libs')
5151

52-
5352
implementation 'com.android.volley:volley:1.2.1@aar'
5453
implementation 'joda-time:joda-time:2.11.0'
55-
implementation 'androidx.appcompat:appcompat:1.5.0'
54+
implementation 'com.squareup.picasso:picasso:2.71828'
55+
56+
def lifecycle_version = "2.5.1"
57+
// Force the same lifecycle-viewmodel for kotlin and java.
58+
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
59+
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
60+
61+
implementation 'androidx.appcompat:appcompat:1.5.1'
5662
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
5763
implementation 'androidx.cardview:cardview:1.0.0'
5864
implementation 'androidx.recyclerview:recyclerview:1.2.1'
65+
implementation 'androidx.preference:preference:1.2.0'
5966
implementation 'com.google.android.material:material:1.6.1'
6067
implementation 'com.google.android.gms:play-services-location:20.0.0'
61-
implementation 'com.squareup.picasso:picasso:2.71828'
62-
implementation 'com.google.firebase:firebase-crashlytics:18.2.12'
68+
implementation 'com.google.firebase:firebase-crashlytics:18.2.13'
6369

6470
testImplementation 'junit:junit:4.13.2'
6571
testImplementation 'org.json:json:20220320'

Hyperrail/src/main/java/be/hyperrail/android/activities/MainActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import android.net.Uri;
3434
import android.os.Build;
3535
import android.os.Bundle;
36-
import android.preference.PreferenceManager;
36+
3737
import android.view.Menu;
3838
import android.view.MenuInflater;
3939
import android.view.MenuItem;
@@ -50,6 +50,7 @@
5050
import androidx.core.view.GravityCompat;
5151
import androidx.drawerlayout.widget.DrawerLayout;
5252
import androidx.fragment.app.Fragment;
53+
import androidx.preference.PreferenceManager;
5354

5455
import com.google.android.material.navigation.NavigationView;
5556

Hyperrail/src/main/java/be/hyperrail/android/activities/SettingsActivity.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,15 @@
1919
package be.hyperrail.android.activities;
2020

2121
import android.os.Bundle;
22-
import android.preference.PreferenceActivity;
23-
import android.preference.PreferenceFragment;
22+
23+
import androidx.annotation.Nullable;
2424

2525
import androidx.appcompat.app.AppCompatActivity;
2626
import androidx.appcompat.widget.Toolbar;
27+
import androidx.preference.PreferenceFragmentCompat;
2728

2829
import be.hyperrail.android.R;
2930

30-
/**
31-
* A {@link PreferenceActivity} that presents a set of application settings. On
32-
* handset devices, settings are presented as a single list. On tablets,
33-
* settings are split by category, with category headers shown to the left of
34-
* the list of settings.
35-
* <p>
36-
* See <a href="http://developer.android.com/design/patterns/settings.html">
37-
* Android Design: Settings</a> for design guidelines and the <a
38-
* href="http://developer.android.com/guide/topics/ui/settings.html">Settings
39-
* API Guide</a> for more information on developing a Settings UI.
40-
*/
4131
public class SettingsActivity extends AppCompatActivity {
4232

4333
@Override
@@ -54,23 +44,19 @@ protected void onCreate(Bundle savedInstanceState) {
5444
setTitle(R.string.title_activity_settings);
5545

5646
// Display the fragment as the main content.
57-
getFragmentManager().beginTransaction()
47+
getSupportFragmentManager().beginTransaction()
5848
.replace(R.id.preferences_content, new SettingsFragment())
5949
.commit();
6050

6151
}
6252

63-
public static class SettingsFragment extends PreferenceFragment {
53+
public static class SettingsFragment extends PreferenceFragmentCompat {
6454

6555
@Override
66-
public void onCreate(Bundle savedInstanceState) {
67-
super.onCreate(savedInstanceState);
68-
56+
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
6957
// Load the preferences from an XML resource
70-
71-
addPreferencesFromResource(R.xml.pref_general);
58+
setPreferencesFromResource(R.xml.pref_general, rootKey);
7259
}
73-
7460
}
7561

7662
}
Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
1+
<androidx.preference.PreferenceScreen
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
>
25
<PreferenceCategory
36
android:key="pref_cat_general"
4-
android:title="@string/pref_header_general">
7+
android:title="@string/pref_header_general"
8+
app:iconSpaceReserved="false">
59

610
<ListPreference
711
android:defaultValue="10"
@@ -11,7 +15,8 @@
1115
android:negativeButtonText="@null"
1216
android:positiveButtonText="@null"
1317
android:summary="%s"
14-
android:title="@string/pref_startup_screen"/>
18+
android:title="@string/pref_startup_screen"
19+
app:iconSpaceReserved="false"/>
1520

1621
<ListPreference
1722
android:entries="@array/pref_list_languages"
@@ -20,18 +25,21 @@
2025
android:negativeButtonText="@null"
2126
android:positiveButtonText="@null"
2227
android:summary="%s"
23-
android:title="@string/pref_stations_language"/>
28+
android:title="@string/pref_stations_language"
29+
app:iconSpaceReserved="false"/>
2430

2531
<SwitchPreference
2632
android:defaultValue="false"
2733
android:key="use_card_layout"
2834
android:summary="@string/pref_description_cards"
29-
android:title="@string/pref_title_cards"/>
35+
android:title="@string/pref_title_cards"
36+
app:iconSpaceReserved="false"/>
3037
</PreferenceCategory>
3138

3239
<PreferenceCategory
3340
android:key="pref_cat_stations"
34-
android:title="@string/pref_header_stations">
41+
android:title="@string/pref_header_stations"
42+
app:iconSpaceReserved="false">
3543

3644
<ListPreference
3745
android:defaultValue="3"
@@ -41,12 +49,14 @@
4149
android:negativeButtonText="@null"
4250
android:positiveButtonText="@null"
4351
android:summary="%s"
44-
android:title="@string/number_recent_searches"/>
52+
android:title="@string/number_recent_searches"
53+
app:iconSpaceReserved="false"/>
4554

4655
<SwitchPreference
4756
android:defaultValue="true"
4857
android:key="stations_enable_nearby"
49-
android:title="@string/show_nearby_stations"/>
58+
android:title="@string/show_nearby_stations"
59+
app:iconSpaceReserved="false"/>
5060

5161
<ListPreference
5262
android:defaultValue="3"
@@ -57,7 +67,8 @@
5767
android:negativeButtonText="@null"
5868
android:positiveButtonText="@null"
5969
android:summary="%s"
60-
android:title="@string/number_nearby_stations"/>
70+
android:title="@string/number_nearby_stations"
71+
app:iconSpaceReserved="false"/>
6172

6273
<ListPreference
6374
android:defaultValue="0"
@@ -67,13 +78,15 @@
6778
android:negativeButtonText="@null"
6879
android:positiveButtonText="@null"
6980
android:summary="%s"
70-
android:title="@string/order_of_stations"/>
81+
android:title="@string/order_of_stations"
82+
app:iconSpaceReserved="false"/>
7183

7284
</PreferenceCategory>
7385

7486
<PreferenceCategory
7587
android:key="pref_cat_routes"
76-
android:title="@string/pref_header_routes">
88+
android:title="@string/pref_header_routes"
89+
app:iconSpaceReserved="false">
7790

7891
<ListPreference
7992
android:defaultValue="3"
@@ -83,7 +96,8 @@
8396
android:negativeButtonText="@null"
8497
android:positiveButtonText="@null"
8598
android:summary="%s"
86-
android:title="@string/number_recent_searches"/>
99+
android:title="@string/number_recent_searches"
100+
app:iconSpaceReserved="false"/>
87101

88102
<ListPreference
89103
android:defaultValue="0"
@@ -93,19 +107,22 @@
93107
android:negativeButtonText="@null"
94108
android:positiveButtonText="@null"
95109
android:summary="%s"
96-
android:title="@string/order_of_routes"/>
110+
android:title="@string/order_of_routes"
111+
app:iconSpaceReserved="false"/>
97112

98113
<SwitchPreference
99114
android:defaultValue="false"
100115
android:key="routes_always_new_activity"
101116
android:summary="@string/pref_short_tap_route_detail_summary"
102-
android:title="@string/pref_short_tap_route_detail"/>
117+
android:title="@string/pref_short_tap_route_detail"
118+
app:iconSpaceReserved="false"/>
103119

104120
</PreferenceCategory>
105121

106122
<PreferenceCategory
107123
android:key="pref_cat_vehicles"
108-
android:title="@string/pref_header_trains">
124+
android:title="@string/pref_header_trains"
125+
app:iconSpaceReserved="false">
109126

110127
<ListPreference
111128
android:defaultValue="3"
@@ -115,7 +132,8 @@
115132
android:negativeButtonText="@null"
116133
android:positiveButtonText="@null"
117134
android:summary="%s"
118-
android:title="@string/number_recent_searches"/>
135+
android:title="@string/number_recent_searches"
136+
app:iconSpaceReserved="false"/>
119137

120138
<ListPreference
121139
android:defaultValue="0"
@@ -125,48 +143,56 @@
125143
android:negativeButtonText="@null"
126144
android:positiveButtonText="@null"
127145
android:summary="%s"
128-
android:title="@string/order_of_trains"/>
146+
android:title="@string/order_of_trains"
147+
app:iconSpaceReserved="false"/>
129148

130149
<SwitchPreference
131150
android:defaultValue="true"
132151
android:key="trains_map"
133152
android:summary="@string/pref_display_vehicle_on_map_summary"
134-
android:title="@string/pref_display_vehicle_on_map"/>
153+
android:title="@string/pref_display_vehicle_on_map"
154+
app:iconSpaceReserved="false"/>
135155

136156
<SwitchPreference
137157
android:defaultValue="true"
138158
android:key="vehicle_composition"
139159
android:summary="@string/pref_display_vehicle_composition_summary"
140-
android:title="@string/pref_display_vehicle_composition"/>
160+
android:title="@string/pref_display_vehicle_composition"
161+
app:iconSpaceReserved="false"/>
141162

142163
<SwitchPreference
143164
android:defaultValue="true"
144165
android:key="vehicle_composition_show_type"
145166
android:summary="@string/pref_vehicle_composition_display_type_summary"
146-
android:title="@string/pref_vehicle_composition_display_type"/>
167+
android:title="@string/pref_vehicle_composition_display_type"
168+
app:iconSpaceReserved="false"/>
147169

148170
<SwitchPreference
149171
android:defaultValue="false"
150172
android:key="vehicle_composition_show_number"
151173
android:summary="@string/pref_vehicle_composition_display_number_summary"
152-
android:title="@string/pref_vehicle_composition_display_number"/>
174+
android:title="@string/pref_vehicle_composition_display_number"
175+
app:iconSpaceReserved="false"/>
153176

154177
</PreferenceCategory>
155178

156179
<PreferenceCategory
157180
android:key="pref_links"
158-
android:title="@string/pref_header_links">
181+
android:title="@string/pref_header_links"
182+
app:iconSpaceReserved="false">
159183

160184
<Preference android:title="@string/pref_github">
161185
<intent
162186
android:action="android.intent.action.VIEW"
163-
android:data="https://www.github.com/hyperrail/hyperrail-for-android/"/>
187+
android:data="https://www.github.com/hyperrail/hyperrail-for-android/"
188+
app:iconSpaceReserved="false"/>
164189
</Preference>
165190

166191
<Preference android:title="@string/pref_mlgtraffic">
167192
<intent
168193
android:action="android.intent.action.VIEW"
169-
android:data="http://www.mlgtraffic.net/"/>
194+
android:data="http://www.mlgtraffic.net/"
195+
app:iconSpaceReserved="false"/>
170196
</Preference>
171197
</PreferenceCategory>
172-
</PreferenceScreen>
198+
</androidx.preference.PreferenceScreen>

0 commit comments

Comments
 (0)