android/app/src/main/java/org/openlp/android2/activities/SettingsActivity.java

91 lines
4.2 KiB
Java

/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
* Copyright (c) 2011-2014 Raoul Snyman *
* Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt *
* *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., 59 *
* Temple Place, Suite 330, Boston, MA 02111-1307 USA *
*******************************************************************************/
package org.openlp.android2.activities;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import org.openlp.android2.R;
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//todo fix this code to work with fragments but not now!
//getFragmentManager().beginTransaction()
// .replace(android.R.id.content, new SettingsFragment())
// .commit();
getPreferenceManager()
.setSharedPreferencesName(getString(R.string.keySharedPreferences));
addPreferencesFromResource(R.xml.pref_general);
final SharedPreferences sharedPreferences = getPreferenceManager()
.getSharedPreferences();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(sharedPreferences.getString(
getString(R.string.keyHost),
getString(R.string.not_set)));
stringBuilder.append(":");
Boolean useSsl = sharedPreferences.getBoolean(
getString(R.string.key_ssl_use), false);
stringBuilder.append(
String.format("%s %s",
sharedPreferences.getString(
getString(R.string.keyPort),
getString(R.string.not_set)), useSsl ? "(SSL)" : ""));
final Preference hostPreference = findPreference(getString(R.string.keyHost));
hostPreference.setTitle(
getPreferenceManager().getSharedPreferences()
.getString(
getString(R.string.key_profile_selected_title),
getString(R.string.url)
)
);
hostPreference.setSummary(stringBuilder.toString());
Preference preference = findPreference(getString(R.string.keyHost));
preference.setIntent(new Intent(this, ConnectionActivity.class));
}
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesName(getString(R.string.keySharedPreferences));
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.pref_general);
}
}
}