Back to project page Calma.
The source code is released under:
Apache License
If you think the Android project Calma listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright (C) 2013 Thomas Schmid/*from w w w. j a v a2 s . c o m*/ * * 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; either version 2 * of the License, or (at your option) any later version. * * 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., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ package com.scto.android.calma.activities; import android.content.Intent; import android.os.Bundle; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.util.Log; import android.view.MenuItem; import com.scto.android.calma.R; import com.scto.android.calma.preferences.CalmaSettings; import com.scto.android.calma.utils.CalmaUtils; import com.scto.android.calma.utils.PreferenceUtils; import java.util.List; public class SettingsActivity extends PreferenceActivity { private static final String TAG = "SettingsActivity"; //$NON-NLS-1$ private static final boolean DEBUG = false; private CheckBoxPreference mCaseSensitiveSort; private ListPreference mFiletimeFormatMode; private ListPreference mFreeDiskSpaceWarningLevel; private CheckBoxPreference mComputeFolderStatistics; private CheckBoxPreference mDisplayThumbs; private CheckBoxPreference mUseFlinger; private ListPreference mAccessMode; private CheckBoxPreference mDebugTraces; /** * @hide */ boolean mLoaded = false; private final OnPreferenceChangeListener mOnChangeListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, Object newValue) { boolean ret = true; String key = preference.getKey(); if (DEBUG) { Log.d(TAG, String.format("New value for %s: %s", //$NON-NLS-1$ key, String.valueOf(newValue))); } // Access mode if (CalmaSettings.SETTINGS_ACCESS_MODE.getId().compareTo(key) == 0) { String value = (String)newValue; AccessMode oldMode = CalmaApp.getAccessMode(); AccessMode newMode = AccessMode.fromId(value); if (oldMode.compareTo(newMode) != 0) { // The mode was changes. Change the console if (newMode.compareTo(AccessMode.ROOT) == 0) { /* if (!ConsoleBuilder.changeToPrivilegedConsole( activity.getApplicationContext())) { value = String.valueOf(oldMode.ordinal()); ret = false; } */ } else { /* if (!ConsoleBuilder.changeToNonPrivilegedConsole( activity.getApplicationContext())) { value = String.valueOf(oldMode.ordinal()); ret = false; } */ } } int valueId = Integer.valueOf(value).intValue(); String[] summary = getResources().getStringArray( R.array.access_mode_summaries); preference.setSummary(summary[valueId]); } // Notify the change (only if fragment is loaded. Default values are loaded // while not in loaded mode) if (SettingsActivity.this.mLoaded && ret) { Intent intent = new Intent(CalmaSettings.INTENT_SETTING_CHANGED); intent.putExtra( CalmaSettings.EXTRA_SETTING_CHANGED_KEY, preference.getKey()); sendBroadcast(intent); } return ret; } }; @Override protected void onCreate(Bundle savedInstanceState) { setTheme(new PreferenceUtils(this).getTheme()); super.onCreate(savedInstanceState); // Fade it in overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); getActionBar().setDisplayHomeAsUpEnabled(true); } @Override public boolean onOptionsItemSelected(MenuItem item) { if(item.getItemId()== android.R.id.home) { onBackPressed(); return true; } else { return false; } } /** * Populate the activity with the top-level headers. */ @Override public void onBuildHeaders(List<Header> target) { loadHeadersFromResource(R.xml.prefs, target); } public static class NavigationPreferences extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.nav_prefs); } } public static class GeekyPreferences extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.geeky_prefs); // Access mode this.mAccessMode = (ListPreference)findPreference(CalmaSettings.SETTINGS_ACCESS_MODE.getId()); this.mAccessMode.setOnPreferenceChangeListener(this.mOnChangeListener); defaultValue = ((ObjectStringIdentifier)CalmaSettings.SETTINGS_ACCESS_MODE.getDefaultValue()).getId(); value = Preferences.getSharedPreferences().getString(CalmaSettings.SETTINGS_ACCESS_MODE.getId(),defaultValue); this.mOnChangeListener.onPreferenceChange(this.mAccessMode, value); // If device is not rooted, this setting cannot be changed this.mAccessMode.setEnabled(CalmaApp.isDeviceRooted()); // Capture Debug traces this.mDebugTraces = (CheckBoxPreference)findPreference(CalmaSettings.SETTINGS_SHOW_TRACES.getId()); this.mDebugTraces.setOnPreferenceChangeListener(this.mOnChangeListener); // Loaded this.mLoaded = true; // Access mode final Preference mRootMode = findPreference("root_mode"); mRootMode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, Object newValue) { return true; } }); } } public static class ViewPreferences extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.view_prefs); } } public static class AboutPreferences extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.about_prefs); // About final Preference mOpenSourceLicenses = findPreference("open_source"); mOpenSourceLicenses.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { CalmaUtils.createOpenSourceDialog(getActivity()).show(); return true; } }); try { final PackageInfo packageInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); findPreference("version").setSummary(packageInfo.versionName); } catch (final NameNotFoundException e) { findPreference("version").setSummary("?"); } Preference share = findPreference("pref_opt_share"); share.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); String text = getString(R.string.share_text); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra(Intent.EXTRA_SUBJECT, "Calma"); startActivity(Intent.createChooser(intent,getString(R.string.share_via))); return true; } }); } } }