Use preference headers in settings (prep for identity support)
This commit is contained in:
@ -1,31 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<Preference android:title="@string/pref_title_change_password" >
|
||||
<intent
|
||||
android:targetClass="i2p.bote.SetPasswordActivity"
|
||||
android:targetPackage="i2p.bote" />
|
||||
</Preference>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="autoMailCheckEnabled"
|
||||
android:title="@string/pref_title_autoMail" />
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_title_general" >
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="autoMailCheckEnabled"
|
||||
android:title="@string/pref_title_autoMail" />
|
||||
<i2p.bote.util.IntEditTextPreference
|
||||
android:defaultValue="30"
|
||||
android:dependency="autoMailCheckEnabled"
|
||||
android:key="mailCheckInterval"
|
||||
android:summary="@string/pref_summ_checkInterval"
|
||||
android:title="@string/pref_title_checkInterval" />
|
||||
|
||||
<i2p.bote.util.IntEditTextPreference
|
||||
android:defaultValue="30"
|
||||
android:dependency="autoMailCheckEnabled"
|
||||
android:key="mailCheckInterval"
|
||||
android:summary="@string/pref_summ_checkInterval"
|
||||
android:title="@string/pref_title_checkInterval" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="deliveryCheckEnabled"
|
||||
android:summary="@string/pref_summ_delivery"
|
||||
android:title="@string/pref_title_delivery" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="deliveryCheckEnabled"
|
||||
android:summary="@string/pref_summ_delivery"
|
||||
android:title="@string/pref_title_delivery" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_title_privacy" >
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
17
res/xml/settings_headers.xml
Normal file
17
res/xml/settings_headers.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<header
|
||||
android:fragment="i2p.bote.SettingsActivity$SettingsFragment"
|
||||
android:title="@string/pref_title_general" >
|
||||
<extra
|
||||
android:name="settings"
|
||||
android:value="general" />
|
||||
</header>
|
||||
<header android:title="@string/pref_title_change_password" >
|
||||
<intent
|
||||
android:targetClass="i2p.bote.SetPasswordActivity"
|
||||
android:targetPackage="i2p.bote" />
|
||||
</header>
|
||||
|
||||
</preference-headers>
|
16
res/xml/settings_headers_legacy.xml
Normal file
16
res/xml/settings_headers_legacy.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<Preference android:title="@string/pref_title_general" >
|
||||
<intent
|
||||
android:action="i2p.bote.PREFS_GENERAL"
|
||||
android:targetClass="i2p.bote.SettingsActivity"
|
||||
android:targetPackage="i2p.bote" />
|
||||
</Preference>
|
||||
<Preference android:title="@string/pref_title_change_password" >
|
||||
<intent
|
||||
android:targetClass="i2p.bote.SetPasswordActivity"
|
||||
android:targetPackage="i2p.bote" />
|
||||
</Preference>
|
||||
|
||||
</PreferenceScreen>
|
@ -1,9 +1,9 @@
|
||||
package i2p.bote;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
@ -13,30 +13,45 @@ import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class SettingsActivity extends PreferenceActivity {
|
||||
// Actions for legacy settings
|
||||
private static final String ACTION_PREFS_GENERAL = "i2p.bote.PREFS_GENERAL";
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
||||
addPreferencesFromResource(R.xml.settings);
|
||||
} else {
|
||||
// Display the fragment as the main content.
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(android.R.id.content, new SettingsFragment())
|
||||
.commit();
|
||||
String action = getIntent().getAction();
|
||||
if (action != null) {
|
||||
if (ACTION_PREFS_GENERAL.equals(action)) {
|
||||
addPreferencesFromResource(R.xml.settings_general);
|
||||
}
|
||||
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
||||
// Load the legacy preferences headers
|
||||
addPreferencesFromResource(R.xml.settings_headers_legacy);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
@Override
|
||||
public void onBuildHeaders(List<Header> target) {
|
||||
// The resource com.android.internal.R.bool.preferences_prefer_dual_pane
|
||||
// has different definitions based upon screen size. At present, it will
|
||||
// be true for -sw720dp devices, false otherwise. For your curiosity, in
|
||||
// Nexus 7 it is false.
|
||||
loadHeadersFromResource(R.xml.settings_headers, target);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public static class SettingsFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.settings);
|
||||
String settings = getArguments().getString("settings");
|
||||
if ("general".equals(settings)) {
|
||||
addPreferencesFromResource(R.xml.settings_general);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user