conversations-classic/src/main/java/eu/siacs/conversations/ui/SettingsFragment.java

66 lines
2 KiB
Java
Raw Normal View History

2014-10-22 16:38:44 +00:00
package eu.siacs.conversations.ui;
2014-12-03 11:33:32 +00:00
import android.app.Dialog;
2014-10-22 16:38:44 +00:00
import android.os.Bundle;
2014-12-03 11:33:32 +00:00
import android.preference.Preference;
2014-10-22 16:38:44 +00:00
import android.preference.PreferenceFragment;
2014-12-03 11:33:32 +00:00
import android.preference.PreferenceScreen;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import eu.siacs.conversations.R;
2014-10-22 16:38:44 +00:00
public class SettingsFragment extends PreferenceFragment {
2014-12-03 11:33:32 +00:00
//http://stackoverflow.com/questions/16374820/action-bar-home-button-not-functional-with-nested-preferencescreen/16800527#16800527
private void initializeActionBar(PreferenceScreen preferenceScreen) {
final Dialog dialog = preferenceScreen.getDialog();
if (dialog != null) {
View homeBtn = dialog.findViewById(android.R.id.home);
if (homeBtn != null) {
View.OnClickListener dismissDialogClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
};
ViewParent homeBtnContainer = homeBtn.getParent();
if (homeBtnContainer instanceof FrameLayout) {
ViewGroup containerParent = (ViewGroup) homeBtnContainer.getParent();
if (containerParent instanceof LinearLayout) {
((LinearLayout) containerParent).setOnClickListener(dismissDialogClickListener);
} else {
((FrameLayout) homeBtnContainer).setOnClickListener(dismissDialogClickListener);
}
} else {
homeBtn.setOnClickListener(dismissDialogClickListener);
}
}
}
}
2014-10-22 16:38:44 +00:00
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
2014-12-03 11:33:32 +00:00
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
super.onPreferenceTreeClick(preferenceScreen, preference);
if (preference instanceof PreferenceScreen) {
initializeActionBar((PreferenceScreen) preference);
}
return false;
}
2014-10-22 16:38:44 +00:00
}