Android Open Source - Calma About Preference Fragment






From Project

Back to project page Calma.

License

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.

Java Source Code

/*
 * Copyright (C) 2013 Thomas Schmid/*from  www  . java 2s  . co 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.preferences;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.util.Log;

import com.cyanogenmod.filemanager.FileManagerApplication;
import com.cyanogenmod.filemanager.R;
import com.cyanogenmod.filemanager.console.ConsoleBuilder;
import com.cyanogenmod.filemanager.preferences.AccessMode;
import com.cyanogenmod.filemanager.preferences.FileManagerSettings;
import com.cyanogenmod.filemanager.preferences.ObjectStringIdentifier;
import com.cyanogenmod.filemanager.preferences.Preferences;

/**
 * A class that manages the commons options of the application
 */
public class GeneralPreferenceFragment extends TitlePreferenceFragment {

    private static final String TAG = "GeneralPreferenceFragment"; //$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)));
            }

            // Filetime format mode
            if (FileManagerSettings.SETTINGS_FILETIME_FORMAT_MODE.
                    getId().compareTo(key) == 0) {
                String value = (String)newValue;
                int valueId = Integer.valueOf(value).intValue();
                String[] labels = getResources().getStringArray(
                        R.array.filetime_format_mode_labels);
                                    preference.setSummary(labels[valueId]);
            }

            // Disk usage warning level
            else if (FileManagerSettings.SETTINGS_DISK_USAGE_WARNING_LEVEL.
                    getId().compareTo(key) == 0) {
                String value = (String)newValue;
                preference.setSummary(
                        getResources().getString(
                                R.string.pref_disk_usage_warning_level_summary, value));
            }

            // Access mode
            else if (FileManagerSettings.SETTINGS_ACCESS_MODE.getId().compareTo(key) == 0) {
                Activity activity = GeneralPreferenceFragment.this.getActivity();

                String value = (String)newValue;
                AccessMode oldMode = FileManagerApplication.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 (GeneralPreferenceFragment.this.mLoaded && ret) {
                Intent intent = new Intent(FileManagerSettings.INTENT_SETTING_CHANGED);
                intent.putExtra(
                        FileManagerSettings.EXTRA_SETTING_CHANGED_KEY, preference.getKey());
                getActivity().sendBroadcast(intent);
            }

            return ret;
        }
    };

    /**
     * {@inheritDoc}
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Change the preference manager
        getPreferenceManager().setSharedPreferencesName(Preferences.SETTINGS_FILENAME);
        getPreferenceManager().setSharedPreferencesMode(Context.MODE_PRIVATE);

        // Add the preferences
        addPreferencesFromResource(R.xml.preferences_general);

        // Case sensitive sort
        this.mCaseSensitiveSort =
                (CheckBoxPreference)findPreference(
                        FileManagerSettings.SETTINGS_CASE_SENSITIVE_SORT.getId());
        this.mCaseSensitiveSort.setOnPreferenceChangeListener(this.mOnChangeListener);

        // Filetime format mode
        this.mFiletimeFormatMode =
                (ListPreference)findPreference(
                        FileManagerSettings.SETTINGS_FILETIME_FORMAT_MODE.getId());
        String defaultValue = ((ObjectStringIdentifier)FileManagerSettings.
                SETTINGS_FILETIME_FORMAT_MODE.getDefaultValue()).getId();
        String value = Preferences.getSharedPreferences().getString(
                            FileManagerSettings.SETTINGS_FILETIME_FORMAT_MODE.getId(),
                            defaultValue);
        this.mOnChangeListener.onPreferenceChange(this.mFiletimeFormatMode, value);
        this.mFiletimeFormatMode.setOnPreferenceChangeListener(this.mOnChangeListener);

        // Disk usage warning level
        this.mFreeDiskSpaceWarningLevel =
                (ListPreference)findPreference(
                        FileManagerSettings.SETTINGS_DISK_USAGE_WARNING_LEVEL.getId());
        defaultValue = ((String)FileManagerSettings.
                            SETTINGS_DISK_USAGE_WARNING_LEVEL.getDefaultValue());
        value = Preferences.getSharedPreferences().getString(
                            FileManagerSettings.SETTINGS_DISK_USAGE_WARNING_LEVEL.getId(),
                            defaultValue);
        this.mOnChangeListener.onPreferenceChange(this.mFreeDiskSpaceWarningLevel, value);
        this.mFreeDiskSpaceWarningLevel.setOnPreferenceChangeListener(this.mOnChangeListener);

        // Compute folder statistics
        this.mComputeFolderStatistics =
                (CheckBoxPreference)findPreference(
                        FileManagerSettings.SETTINGS_COMPUTE_FOLDER_STATISTICS.getId());
        this.mComputeFolderStatistics.setOnPreferenceChangeListener(this.mOnChangeListener);

        // Display thumbs
        this.mDisplayThumbs =
                (CheckBoxPreference)findPreference(
                        FileManagerSettings.SETTINGS_DISPLAY_THUMBS.getId());
        this.mDisplayThumbs.setOnPreferenceChangeListener(this.mOnChangeListener);

        // Use flinger
        this.mUseFlinger =
                (CheckBoxPreference)findPreference(
                        FileManagerSettings.SETTINGS_USE_FLINGER.getId());
        this.mUseFlinger.setOnPreferenceChangeListener(this.mOnChangeListener);

        // Access mode
        this.mAccessMode =
                (ListPreference)findPreference(
                        FileManagerSettings.SETTINGS_ACCESS_MODE.getId());
        this.mAccessMode.setOnPreferenceChangeListener(this.mOnChangeListener);
        defaultValue = ((ObjectStringIdentifier)FileManagerSettings.
                            SETTINGS_ACCESS_MODE.getDefaultValue()).getId();
        value = Preferences.getSharedPreferences().getString(
                            FileManagerSettings.SETTINGS_ACCESS_MODE.getId(),
                            defaultValue);
        this.mOnChangeListener.onPreferenceChange(this.mAccessMode, value);
        // If device is not rooted, this setting cannot be changed
        this.mAccessMode.setEnabled(FileManagerApplication.isDeviceRooted());

        // Capture Debug traces
        this.mDebugTraces =
                (CheckBoxPreference)findPreference(
                        FileManagerSettings.SETTINGS_SHOW_TRACES.getId());
        this.mDebugTraces.setOnPreferenceChangeListener(this.mOnChangeListener);

        // Loaded
        this.mLoaded = true;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public CharSequence getTitle() {
        return getString(R.string.pref_general);
    }
}




Java Source Code List

com.cyanogenmod.filemanager.activities.preferences.SettingsPreferences.java
com.espian.showcaseview.OnShowcaseEventListener.java
com.espian.showcaseview.ShowcaseViewBuilder.java
com.espian.showcaseview.ShowcaseView.java
com.espian.showcaseview.ShowcaseViews.java
com.espian.showcaseview.actionbar.ActionBarViewWrapper.java
com.espian.showcaseview.actionbar.reflection.ActionBarReflector.java
com.espian.showcaseview.actionbar.reflection.AppCompatReflector.java
com.espian.showcaseview.actionbar.reflection.BaseReflector.java
com.espian.showcaseview.actionbar.reflection.SherlockReflector.java
com.espian.showcaseview.anim.AnimationUtils.java
com.espian.showcaseview.drawing.ClingDrawerImpl.java
com.espian.showcaseview.drawing.ClingDrawer.java
com.espian.showcaseview.drawing.TextDrawerImpl.java
com.espian.showcaseview.drawing.TextDrawer.java
com.espian.showcaseview.targets.ActionItemTarget.java
com.espian.showcaseview.targets.ActionViewTarget.java
com.espian.showcaseview.targets.PointTarget.java
com.espian.showcaseview.targets.Target.java
com.espian.showcaseview.targets.ViewTarget.java
com.espian.showcaseview.utils.Calculator.java
com.espian.showcaseview.utils.PointAnimator.java
com.espian.showcaseview.utils.ShowcaseAreaCalculator.java
com.scto.android.calma.CalmaApp.java
com.scto.android.calma.activities.BaseActivity.java
com.scto.android.calma.activities.CalmaActivity.java
com.scto.android.calma.activities.SettingsActivity.java
com.scto.android.calma.activities.preferences.AboutPreferenceFragment.java
com.scto.android.calma.activities.preferences.DisplayPreferenceFragment.java
com.scto.android.calma.activities.preferences.GeneralPreferenceFragment.java
com.scto.android.calma.activities.preferences.NavigationPreferenceFragment.java
com.scto.android.calma.activities.preferences.SettingsActivity.java
com.scto.android.calma.activities.preferences.TitlePreferenceFragment.java
com.scto.android.calma.adapter.NavDrawerListAdapter.java
com.scto.android.calma.fragments.CommunityFragment.java
com.scto.android.calma.fragments.FindPeopleFragment.java
com.scto.android.calma.fragments.HomeFragment.java
com.scto.android.calma.fragments.PagesFragment.java
com.scto.android.calma.fragments.PhotosFragment.java
com.scto.android.calma.fragments.WhatsHotFragment.java
com.scto.android.calma.model.NavDrawerItem.java
com.scto.android.calma.preferences.AccessMode.java
com.scto.android.calma.preferences.CalmaSettings.java
com.scto.android.calma.preferences.ConfigurationListener.java
com.scto.android.calma.preferences.ObjectIdentifier.java
com.scto.android.calma.preferences.ObjectStringIdentifier.java
com.scto.android.calma.preferences.Preferences.java
com.scto.android.calma.ui.MyPrerference.java
com.scto.android.calma.utils.CalmaUtils.java
com.scto.android.calma.utils.Compress.java
com.scto.android.calma.utils.Decompress.java
com.scto.android.calma.utils.FileUtils.java
com.scto.android.calma.utils.LinuxShell.java
com.scto.android.calma.utils.PreferenceUtils.java
com.scto.android.calma.utils.SharedPreferencesCompat.java
com.scto.android.calma.utils.SortOrder.java
com.scto.android.calma.utils.Utils.java
com.stericson.RootTools.Constants.java
com.stericson.RootTools.RootTools.java
com.stericson.RootToolsTests.NativeJavaClass.java
com.stericson.RootToolsTests.SanityCheckRootTools.java
com.stericson.RootTools.containers.Mount.java
com.stericson.RootTools.containers.Permissions.java
com.stericson.RootTools.containers.RootClass.java
com.stericson.RootTools.containers.Symlink.java
com.stericson.RootTools.exceptions.RootDeniedException.java
com.stericson.RootTools.execution.CommandCapture.java
com.stericson.RootTools.execution.Command.java
com.stericson.RootTools.execution.JavaCommandCapture.java
com.stericson.RootTools.execution.Shell.java
com.stericson.RootTools.internal.Installer.java
com.stericson.RootTools.internal.InternalVariables.java
com.stericson.RootTools.internal.Remounter.java
com.stericson.RootTools.internal.RootToolsInternalMethods.java
com.stericson.RootTools.internal.Runner.java