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;
10import android.widget.ListView;
11
12import eu.siacs.conversations.Config;
13import eu.siacs.conversations.R;
14import eu.siacs.conversations.utils.Compatibility;
15
16public class SettingsFragment extends PreferenceFragment {
17
18	private String page = null;
19
20	@Override
21	public void onCreate(Bundle savedInstanceState) {
22		super.onCreate(savedInstanceState);
23
24		addPreferencesFromResource(R.xml.preferences);
25
26		// Remove from standard preferences if the flag ONLY_INTERNAL_STORAGE is false
27		if (!Config.ONLY_INTERNAL_STORAGE) {
28			PreferenceCategory mCategory = (PreferenceCategory) findPreference("security_options");
29			if (mCategory != null) {
30				Preference cleanCache = findPreference("clean_cache");
31				Preference cleanPrivateStorage = findPreference("clean_private_storage");
32				mCategory.removePreference(cleanCache);
33				mCategory.removePreference(cleanPrivateStorage);
34			}
35		}
36		Compatibility.removeUnusedPreferences(this);
37
38		if (!TextUtils.isEmpty(page)) {
39			openPreferenceScreen(page);
40		}
41
42	}
43
44	@Override
45	public void onActivityCreated(Bundle bundle) {
46		super.onActivityCreated(bundle);
47
48		final ListView listView = getActivity().findViewById(android.R.id.list);
49		if (listView != null) {
50			listView.setDivider(null);
51		}
52	}
53
54	public void setActivityIntent(final Intent intent) {
55		boolean wasEmpty = TextUtils.isEmpty(page);
56		if (intent != null) {
57			if (Intent.ACTION_VIEW.equals(intent.getAction())) {
58				if (intent.getExtras() != null) {
59					this.page = intent.getExtras().getString("page");
60					if (wasEmpty) {
61						openPreferenceScreen(page);
62					}
63				}
64			}
65		}
66	}
67
68	private void openPreferenceScreen(final String screenName) {
69		final Preference pref = findPreference(screenName);
70		if (pref instanceof PreferenceScreen) {
71			final PreferenceScreen preferenceScreen = (PreferenceScreen) pref;
72			getActivity().setTitle(preferenceScreen.getTitle());
73			preferenceScreen.setDependency("");
74			setPreferenceScreen((PreferenceScreen) pref);
75		}
76	}
77}