|
@@ -0,0 +1,91 @@
|
|
|
+package de.tudarmstadt.informatik.hostage.ui2.fragment;
|
|
|
+
|
|
|
+import android.app.ActionBar;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.SharedPreferences;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.preference.PreferenceFragment;
|
|
|
+import android.preference.PreferenceManager;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+
|
|
|
+import de.tudarmstadt.informatik.hostage.R;
|
|
|
+import de.tudarmstadt.informatik.hostage.dao.ProfileManager;
|
|
|
+import de.tudarmstadt.informatik.hostage.model.Profile;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Alexander Brakowski
|
|
|
+ * @created 08.02.14 23:39
|
|
|
+ */
|
|
|
+public class ProfileEditFragment extends PreferenceFragment implements
|
|
|
+ SharedPreferences.OnSharedPreferenceChangeListener {
|
|
|
+
|
|
|
+ private LayoutInflater mInflater;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCreate(Bundle savedInstanceState){
|
|
|
+ getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+
|
|
|
+ mInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
+
|
|
|
+ View actionBarButtons = mInflater.inflate(R.layout.actionbar_donebar, new LinearLayout(getActivity()), false);
|
|
|
+ getActivity().getActionBar().setCustomView(actionBarButtons);
|
|
|
+
|
|
|
+ Profile profile = getProfile();
|
|
|
+ SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();
|
|
|
+
|
|
|
+ if(profile != null){
|
|
|
+
|
|
|
+ prefs.putString("pref_profile_general_name", profile.text);
|
|
|
+ prefs.commit();
|
|
|
+ }
|
|
|
+
|
|
|
+ addPreferencesFromResource(R.xml.profile_preferences);
|
|
|
+
|
|
|
+ findPreference("pref_profile_general_name").setSummary(profile.text);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Profile getProfile(){
|
|
|
+ ProfileManager pmanager = ProfileManager.getInstance();
|
|
|
+
|
|
|
+ Intent intent = getActivity().getIntent();
|
|
|
+ int profile_id = intent.getIntExtra("profile_id", -1);
|
|
|
+
|
|
|
+ if(profile_id != -1){
|
|
|
+ return pmanager.getProfile(profile_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPause() {
|
|
|
+ getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
|
|
+ super.onPause();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Called when a shared preference is changed, added, or removed. This
|
|
|
+ * may be called even if a preference is set to its existing value.
|
|
|
+ *
|
|
|
+ * <p>This callback will be run on your main thread.
|
|
|
+ *
|
|
|
+ * @param sharedPreferences The {@link android.content.SharedPreferences} that received
|
|
|
+ * the change.
|
|
|
+ * @param key The key of the preference that was changed, added, or
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
|
+ Log.i("settings", "preference changed: " + key);
|
|
|
+ }
|
|
|
+}
|