Skip to content

Commit fad08b4

Browse files
committed
Remove default settings entries
1 parent 613c555 commit fad08b4

File tree

11 files changed

+22
-435
lines changed

11 files changed

+22
-435
lines changed

app/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ dependencies {
2727
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
2828
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
2929
implementation 'com.github.kenglxn.QRGen:android:2.4.0'
30-
implementation 'com.android.support:support-v4:27.1.0'
3130
}
Lines changed: 16 additions & 232 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
package tk.superl2.xwifi
22

3-
import android.annotation.TargetApi
4-
import android.content.Context
5-
import android.content.Intent
6-
import android.content.res.Configuration
7-
import android.media.RingtoneManager
8-
import android.net.Uri
9-
import android.os.Build
103
import android.os.Bundle
11-
import android.preference.ListPreference
12-
import android.preference.Preference
134
import android.preference.PreferenceActivity
5+
import android.R.xml
146
import android.preference.PreferenceFragment
15-
import android.preference.PreferenceManager
16-
import android.preference.RingtonePreference
17-
import android.text.TextUtils
18-
import android.view.MenuItem
19-
import android.support.v4.app.NavUtils
7+
8+
209

2110
/**
2211
* A [PreferenceActivity] that presents a set of application settings. On
@@ -29,224 +18,19 @@ import android.support.v4.app.NavUtils
2918
* for more information on developing a Settings UI.
3019
*/
3120
class SettingsActivity : PreferenceActivity() {
21+
override fun onCreate(savedInstanceState: Bundle?) {
22+
super.onCreate(savedInstanceState)
3223

33-
override fun onCreate(savedInstanceState: Bundle?) {
34-
super.onCreate(savedInstanceState)
35-
setupActionBar()
36-
}
37-
38-
/**
39-
* Set up the [android.app.ActionBar], if the API is available.
40-
*/
41-
private fun setupActionBar() {
42-
actionBar?.setDisplayHomeAsUpEnabled(true)
43-
}
44-
45-
override fun onMenuItemSelected(featureId: Int, item: MenuItem): Boolean {
46-
val id = item.itemId
47-
if (id == android.R.id.home) {
48-
if (!super.onMenuItemSelected(featureId, item)) {
49-
NavUtils.navigateUpFromSameTask(this)
50-
}
51-
return true
52-
}
53-
return super.onMenuItemSelected(featureId, item)
54-
}
55-
56-
/**
57-
* {@inheritDoc}
58-
*/
59-
override fun onIsMultiPane(): Boolean {
60-
return isXLargeTablet(this)
61-
}
62-
63-
/**
64-
* {@inheritDoc}
65-
*/
66-
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
67-
override fun onBuildHeaders(target: List<PreferenceActivity.Header>) {
68-
loadHeadersFromResource(R.xml.pref_headers, target)
69-
}
70-
71-
/**
72-
* This method stops fragment injection in malicious applications.
73-
* Make sure to deny any unknown fragments here.
74-
*/
75-
override fun isValidFragment(fragmentName: String): Boolean {
76-
return PreferenceFragment::class.java.name == fragmentName
77-
|| GeneralPreferenceFragment::class.java.name == fragmentName
78-
|| DataSyncPreferenceFragment::class.java.name == fragmentName
79-
|| NotificationPreferenceFragment::class.java.name == fragmentName
80-
}
81-
82-
/**
83-
* This fragment shows general preferences only. It is used when the
84-
* activity is showing a two-pane settings UI.
85-
*/
86-
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
87-
class GeneralPreferenceFragment : PreferenceFragment() {
88-
override fun onCreate(savedInstanceState: Bundle?) {
89-
super.onCreate(savedInstanceState)
90-
addPreferencesFromResource(R.xml.pref_general)
91-
setHasOptionsMenu(true)
92-
93-
// Bind the summaries of EditText/List/Dialog/Ringtone preferences
94-
// to their values. When their values change, their summaries are
95-
// updated to reflect the new value, per the Android Design
96-
// guidelines.
97-
bindPreferenceSummaryToValue(findPreference("example_text"))
98-
bindPreferenceSummaryToValue(findPreference("example_list"))
99-
}
100-
101-
override fun onOptionsItemSelected(item: MenuItem): Boolean {
102-
val id = item.itemId
103-
if (id == android.R.id.home) {
104-
startActivity(Intent(activity, SettingsActivity::class.java))
105-
return true
106-
}
107-
return super.onOptionsItemSelected(item)
108-
}
109-
}
110-
111-
/**
112-
* This fragment shows notification preferences only. It is used when the
113-
* activity is showing a two-pane settings UI.
114-
*/
115-
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
116-
class NotificationPreferenceFragment : PreferenceFragment() {
117-
override fun onCreate(savedInstanceState: Bundle?) {
118-
super.onCreate(savedInstanceState)
119-
addPreferencesFromResource(R.xml.pref_notification)
120-
setHasOptionsMenu(true)
121-
122-
// Bind the summaries of EditText/List/Dialog/Ringtone preferences
123-
// to their values. When their values change, their summaries are
124-
// updated to reflect the new value, per the Android Design
125-
// guidelines.
126-
bindPreferenceSummaryToValue(findPreference("notifications_new_message_ringtone"))
127-
}
128-
129-
override fun onOptionsItemSelected(item: MenuItem): Boolean {
130-
val id = item.itemId
131-
if (id == android.R.id.home) {
132-
startActivity(Intent(activity, SettingsActivity::class.java))
133-
return true
134-
}
135-
return super.onOptionsItemSelected(item)
136-
}
137-
}
138-
139-
/**
140-
* This fragment shows data and sync preferences only. It is used when the
141-
* activity is showing a two-pane settings UI.
142-
*/
143-
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
144-
class DataSyncPreferenceFragment : PreferenceFragment() {
145-
override fun onCreate(savedInstanceState: Bundle?) {
146-
super.onCreate(savedInstanceState)
147-
addPreferencesFromResource(R.xml.pref_data_sync)
148-
setHasOptionsMenu(true)
149-
150-
// Bind the summaries of EditText/List/Dialog/Ringtone preferences
151-
// to their values. When their values change, their summaries are
152-
// updated to reflect the new value, per the Android Design
153-
// guidelines.
154-
bindPreferenceSummaryToValue(findPreference("sync_frequency"))
155-
}
156-
157-
override fun onOptionsItemSelected(item: MenuItem): Boolean {
158-
val id = item.itemId
159-
if (id == android.R.id.home) {
160-
startActivity(Intent(activity, SettingsActivity::class.java))
161-
return true
162-
}
163-
return super.onOptionsItemSelected(item)
164-
}
165-
}
166-
167-
companion object {
168-
169-
/**
170-
* A preference value change listener that updates the preference's summary
171-
* to reflect its new value.
172-
*/
173-
private val sBindPreferenceSummaryToValueListener = Preference.OnPreferenceChangeListener { preference, value ->
174-
val stringValue = value.toString()
175-
176-
if (preference is ListPreference) {
177-
// For list preferences, look up the correct display value in
178-
// the preference's 'entries' list.
179-
val listPreference = preference
180-
val index = listPreference.findIndexOfValue(stringValue)
181-
182-
// Set the summary to reflect the new value.
183-
preference.setSummary(
184-
if (index >= 0)
185-
listPreference.entries[index]
186-
else
187-
null
188-
)
189-
190-
} else if (preference is RingtonePreference) {
191-
// For ringtone preferences, look up the correct display value
192-
// using RingtoneManager.
193-
if (TextUtils.isEmpty(stringValue)) {
194-
// Empty values correspond to 'silent' (no ringtone).
195-
preference.setSummary(R.string.pref_ringtone_silent)
196-
197-
} else {
198-
val ringtone = RingtoneManager.getRingtone(
199-
preference.getContext(), Uri.parse(stringValue)
200-
)
201-
202-
if (ringtone == null) {
203-
// Clear the summary if there was a lookup error.
204-
preference.setSummary(null)
205-
} else {
206-
// Set the summary to reflect the new ringtone display
207-
// name.
208-
val name = ringtone.getTitle(preference.getContext())
209-
preference.setSummary(name)
210-
}
211-
}
212-
213-
} else {
214-
// For all other preferences, set the summary to the value's
215-
// simple string representation.
216-
preference.summary = stringValue
217-
}
218-
true
219-
}
220-
221-
/**
222-
* Helper method to determine if the device has an extra-large screen. For
223-
* example, 10" tablets are extra-large.
224-
*/
225-
private fun isXLargeTablet(context: Context): Boolean {
226-
return context.resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK >= Configuration.SCREENLAYOUT_SIZE_XLARGE
227-
}
228-
229-
/**
230-
* Binds a preference's summary to its value. More specifically, when the
231-
* preference's value is changed, its summary (line of text below the
232-
* preference title) is updated to reflect the value. The summary is also
233-
* immediately updated upon calling this method. The exact display format is
234-
* dependent on the type of preference.
24+
// Display the fragment as the main context
25+
fragmentManager.beginTransaction().replace(android.R.id.content, SettingsFragment()).commit()
26+
}
27+
}
23528

236-
* @see .sBindPreferenceSummaryToValueListener
237-
*/
238-
private fun bindPreferenceSummaryToValue(preference: Preference) {
239-
// Set the listener to watch for value changes.
240-
preference.onPreferenceChangeListener = sBindPreferenceSummaryToValueListener
29+
class SettingsFragment : PreferenceFragment() {
30+
override fun onCreate(savedInstanceState: Bundle?) {
31+
super.onCreate(savedInstanceState)
24132

242-
// Trigger the listener immediately with the preference's
243-
// current value.
244-
sBindPreferenceSummaryToValueListener.onPreferenceChange(
245-
preference,
246-
PreferenceManager
247-
.getDefaultSharedPreferences(preference.context)
248-
.getString(preference.key, "")
249-
)
250-
}
251-
}
252-
}
33+
// Load the preferences from an XML resource
34+
addPreferencesFromResource(R.xml.preferences)
35+
}
36+
}

app/src/main/res/drawable/ic_info_black_24dp.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/src/main/res/drawable/ic_notifications_black_24dp.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/src/main/res/drawable/ic_sync_black_24dp.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,79 +4,7 @@
44
<string name="error_dialog_message">Is this device rooted? This can fail if the app can\'t obtain root access.\n\nIf
55
you\'re running a non-AOSP ROM, it\'s possible the wifi information is saved in a non-standard location.
66
</string>
7-
<string name="wifi_loading_message">Loading wifi entries...</string>
8-
<string name="title_activity_settings">Settings</string>
9-
10-
<!-- Strings related to Settings -->
11-
12-
<!-- Example General settings -->
13-
<string name="pref_header_general">General</string>
14-
15-
<string name="pref_title_social_recommendations">Enable social recommendations</string>
16-
<string name="pref_description_social_recommendations">Recommendations for people to contact based on your message
17-
history
18-
</string>
19-
20-
<string name="pref_title_display_name">Display name</string>
21-
<string name="pref_default_display_name">John Smith</string>
22-
23-
<string name="pref_title_add_friends_to_messages">Add friends to messages</string>
24-
<string-array name="pref_example_list_titles">
25-
<item>Always</item>
26-
<item>When possible</item>
27-
<item>Never</item>
28-
</string-array>
29-
<string-array name="pref_example_list_values">
30-
<item>1</item>
31-
<item>0</item>
32-
<item>-1</item>
33-
</string-array>
34-
35-
<!-- Example settings for Data & Sync -->
36-
<string name="pref_header_data_sync">Data &amp; sync</string>
37-
38-
<string name="pref_title_sync_frequency">Sync frequency</string>
39-
<string-array name="pref_sync_frequency_titles">
40-
<item>15 minutes</item>
41-
<item>30 minutes</item>
42-
<item>1 hour</item>
43-
<item>3 hours</item>
44-
<item>6 hours</item>
45-
<item>Never</item>
46-
</string-array>
47-
<string-array name="pref_sync_frequency_values">
48-
<item>15</item>
49-
<item>30</item>
50-
<item>60</item>
51-
<item>180</item>
52-
<item>360</item>
53-
<item>-1</item>
54-
</string-array>
55-
56-
<string-array name="list_preference_entries">
57-
<item>Entry 1</item>
58-
<item>Entry 2</item>
59-
<item>Entry 3</item>
60-
</string-array>
61-
62-
<string-array name="list_preference_entry_values">
63-
<item>1</item>
64-
<item>2</item>
65-
<item>3</item>
66-
</string-array>
67-
68-
<string-array name="multi_select_list_preference_default_value"/>
69-
70-
<string name="pref_title_system_sync_settings">System sync settings</string>
71-
72-
<!-- Example settings for Notifications -->
73-
<string name="pref_header_notifications">Notifications</string>
74-
75-
<string name="pref_title_new_message_notifications">New message notifications</string>
76-
77-
<string name="pref_title_ringtone">Ringtone</string>
78-
<string name="pref_ringtone_silent">Silent</string>
79-
80-
<string name="pref_title_vibrate">Vibrate</string>
7+
<string name="wifi_loading_message">Loading wifi entries…</string>
818
<string name="item_settings_menu_activity_main">Settings</string>
9+
<string name="title_activity_settings">Settings</string>
8210
</resources>

0 commit comments

Comments
 (0)