SettingsFragment.java

 1package eu.siacs.conversations.ui;
 2
 3import android.content.Intent;
 4import android.os.Bundle;
 5import android.preference.Preference;
 6import android.preference.PreferenceCategory;
 7import android.preference.PreferenceFragment;
 8import android.preference.PreferenceScreen;
 9import android.text.TextUtils;
10
11import eu.siacs.conversations.Config;
12import eu.siacs.conversations.R;
13
14public class SettingsFragment extends PreferenceFragment {
15
16	private String page = null;
17
18	@Override
19	public void onCreate(Bundle savedInstanceState) {
20		super.onCreate(savedInstanceState);
21
22		addPreferencesFromResource(R.xml.preferences);
23
24		// Remove from standard preferences if the flag ONLY_INTERNAL_STORAGE is false
25		if (!Config.ONLY_INTERNAL_STORAGE) {
26			PreferenceCategory mCategory = (PreferenceCategory) findPreference("security_options");
27			if (mCategory != null) {
28				Preference cleanCache = findPreference("clean_cache");
29				Preference cleanPrivateStorage = findPreference("clean_private_storage");
30				mCategory.removePreference(cleanCache);
31				mCategory.removePreference(cleanPrivateStorage);
32			}
33		}
34
35		if (!TextUtils.isEmpty(page)) {
36			openPreferenceScreen(page);
37		}
38
39	}
40
41	public void setActivityIntent(final Intent intent) {
42		boolean wasEmpty = TextUtils.isEmpty(page);
43		if (intent != null) {
44			if (Intent.ACTION_VIEW.equals(intent.getAction())) {
45				if (intent.getExtras() != null) {
46					this.page = intent.getExtras().getString("page");
47					if (wasEmpty) {
48						openPreferenceScreen(page);
49					}
50				}
51			}
52		}
53	}
54
55	private void openPreferenceScreen(final String screenName) {
56		final Preference pref = findPreference(screenName);
57		if (pref instanceof PreferenceScreen) {
58			final PreferenceScreen preferenceScreen = (PreferenceScreen) pref;
59			getActivity().setTitle(preferenceScreen.getTitle());
60			preferenceScreen.setDependency("");
61			setPreferenceScreen((PreferenceScreen) pref);
62		}
63	}
64}