notecipher / app / src / info / guardianproject / notepadbot / Settings.java @ 7018009a
History | View | Annotate | Download (2.75 KB)
| 1 |
package info.guardianproject.notepadbot; |
|---|---|
| 2 |
|
| 3 |
|
| 4 |
import info.guardianproject.cacheword.Constants; |
| 5 |
|
| 6 |
import android.annotation.SuppressLint; |
| 7 |
import android.content.Context; |
| 8 |
import android.os.Build; |
| 9 |
import android.os.Bundle; |
| 10 |
import android.preference.Preference; |
| 11 |
import android.preference.PreferenceFragment; |
| 12 |
import android.preference.PreferenceManager; |
| 13 |
import android.support.v4.app.NavUtils; |
| 14 |
|
| 15 |
import com.actionbarsherlock.app.SherlockPreferenceActivity; |
| 16 |
import com.actionbarsherlock.view.MenuItem; |
| 17 |
|
| 18 |
@SuppressLint("NewApi") |
| 19 |
@SuppressWarnings("deprecation") |
| 20 |
public class Settings extends SherlockPreferenceActivity { |
| 21 |
|
| 22 |
public static final String LANG_SEL_KEY = "langSelected"; |
| 23 |
|
| 24 |
@Override
|
| 25 |
public void onCreate(Bundle savedInstanceState) { |
| 26 |
super.onCreate(savedInstanceState);
|
| 27 |
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
| 28 |
|
| 29 |
// If in android 3+ use a preference fragment which is the new recommended way
|
| 30 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
| 31 |
getFragmentManager().beginTransaction() |
| 32 |
.replace(android.R.id.content, new PreferenceFragment() {
|
| 33 |
@Override
|
| 34 |
public void onCreate(final Bundle savedInstanceState) { |
| 35 |
super.onCreate(savedInstanceState);
|
| 36 |
addPreferencesFromResource(R.xml.settings); |
| 37 |
findPreference(Constants.SHARED_PREFS_TIMEOUT) |
| 38 |
.setOnPreferenceClickListener(changeLockTimeoutListener); |
| 39 |
} |
| 40 |
}) |
| 41 |
.commit(); |
| 42 |
} else {
|
| 43 |
// Otherwise load the preferences.xml in the Activity like in previous android versions
|
| 44 |
addPreferencesFromResource(R.xml.settings); |
| 45 |
findPreference(Constants.SHARED_PREFS_TIMEOUT).setOnPreferenceClickListener(changeLockTimeoutListener); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
@Override
|
| 50 |
public boolean onOptionsItemSelected(MenuItem item) { |
| 51 |
switch (item.getItemId()) {
|
| 52 |
case android.R.id.home:
|
| 53 |
NavUtils.navigateUpFromSameTask(this);
|
| 54 |
return true; |
| 55 |
} |
| 56 |
return super.onOptionsItemSelected(item); |
| 57 |
} |
| 58 |
|
| 59 |
@Override
|
| 60 |
public void onDestroy() { |
| 61 |
// reload preferences on exit from settings screen
|
| 62 |
Context context = getApplicationContext();
|
| 63 |
loadSettings(context); |
| 64 |
super.onDestroy();
|
| 65 |
} |
| 66 |
|
| 67 |
/** Loads user settings to app. Called when settings change and users exits from
|
| 68 |
* settings screen or when the app first starts.
|
| 69 |
* */
|
| 70 |
public static void loadSettings(Context context) { |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
private Preference.OnPreferenceClickListener changeLockTimeoutListener =
|
| 75 |
new Preference.OnPreferenceClickListener() {
|
| 76 |
@Override
|
| 77 |
public boolean onPreferenceClick(Preference pref) { |
| 78 |
|
| 79 |
return true; |
| 80 |
} |
| 81 |
}; |
| 82 |
|
| 83 |
public static final boolean getNoteLinesOption(Context context) { |
| 84 |
boolean defValue = context.getResources().getBoolean(R.bool.notecipher_uselines_default);
|
| 85 |
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(NConstants.SHARED_PREFS_NOTELINES, defValue);
|
| 86 |
} |
| 87 |
} |