Android Open Source - faster-gps Advanced Settings Activity






From Project

Back to project page faster-gps.

License

The source code is released under:

GNU General Public License

If you think the Android project faster-gps 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) 2012 Dominik Schrmann <dominik@dominikschuermann.de>
 *//  ww w .j av  a2s. c om
 * This file is part of FasterGPS.
 * 
 * FasterGPS 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 3 of the License, or
 * (at your option) any later version.
 *
 * FasterGPS 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 FasterGPS.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package org.fastergps.ui;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;

import org.fastergps.R;
import org.fastergps.util.Constants;
import org.fastergps.util.Log;
import org.fastergps.util.Utils;

import android.app.Activity;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;

public class AdvancedSettingsActivity extends PreferenceActivity {

    private Activity mActivity;
    private HashMap<String, String> config;
    private HashMap<String, String> configCopy;

    /**
     * Called when the activity is first created.
     */
    @SuppressWarnings({ "unchecked", "deprecation" })
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mActivity = this;

        // load config from /system/etc/gps.conf
        config = Utils.getConfig(Constants.GPS_CONF_PATH);
        Utils.debugLogConfig(config);

        // add possible other config options
        HashMap<String, String> possibleConfig = Utils.getPossibleConfig();
        possibleConfig.putAll(config);
        // swap
        config = possibleConfig;

        // copy to remove from while building
        configCopy = (HashMap<String, String>) config.clone();

        // build preference screen using the method below
        setPreferenceScreen(createPreferenceHierarchy());
    }

    /**
     * Set summary of preference based on key to get String from strings.xml and current value
     * 
     * @param preference
     * @param key
     * @param value
     */
    private void setSummary(Preference preference, String key, String value) {
        String summary = "";
        try {
            summary = Utils.getResourceString(key, mActivity);
        } catch (IllegalArgumentException e) {
            Log.d(Constants.TAG, "No summary in strings.xml for " + key);
        }

        if (summary.equals("")) {
            preference.setSummary(getString(R.string.pref_current_value) + " " + value);
        } else {
            preference.setSummary(summary + "\n" + getString(R.string.pref_current_value) + " "
                    + value);
        }
    }

    /**
     * Adds all keys that contain keyContains to the category
     * 
     * @param category
     * @param keyContains
     */
    private void addPreferencesToCategory(PreferenceCategory category, String keyContains) {
        Iterator<Entry<String, String>> it = configCopy.entrySet().iterator();
        while (it.hasNext()) {
            HashMap.Entry<String, String> pairs = it.next();

            Log.d(Constants.TAG, pairs.getKey() + " = " + pairs.getValue());

            // add preference only for those who contain String keyContains
            if ((pairs.getKey().contains(keyContains) || keyContains.equals(""))) {
                // add edit text preference
                EditTextPreference preference = new EditTextPreference(this);
                preference.setPersistent(false);
                preference.setDialogTitle(pairs.getKey());
                preference.setKey(pairs.getKey());
                preference.setTitle(pairs.getKey());

                setSummary(preference, pairs.getKey(), pairs.getValue());
                preference.setDefaultValue(pairs.getValue());

                preference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        Log.d(Constants.TAG, preference.getKey() + " changed!");

                        config.put(preference.getKey(), (String) newValue);
                        Log.d(Constants.TAG, "Following config will now be written:");
                        Utils.debugLogConfig(config);
                        Utils.writeConfig(mActivity, config);
                        setSummary(preference, preference.getKey(), (String) newValue);

                        return true;
                    }
                });
                category.addPreference(preference);
                // remove from configCopy
                it.remove();
            }
        }
    }

    /**
     * Build preferences with categories
     * 
     * @return
     */
    @SuppressWarnings("deprecation")
    private PreferenceScreen createPreferenceHierarchy() {
        // Root
        PreferenceScreen root = getPreferenceManager().createPreferenceScreen(mActivity);

        // General
        PreferenceCategory generalCat = new PreferenceCategory(mActivity);
        generalCat.setTitle(R.string.pref_category_general);
        root.addPreference(generalCat);

        addPreferencesToCategory(generalCat, "DEBUG_LEVEL");
        addPreferencesToCategory(generalCat, "INTERMEDIATE_POS");
        addPreferencesToCategory(generalCat, "ACCURACY_THRES");
        addPreferencesToCategory(generalCat, "REPORT_POSITION_USE_SUPL_REFLOC");
        addPreferencesToCategory(generalCat, "ENABLE_WIPER");

        // NTP
        PreferenceCategory ntpCat = new PreferenceCategory(mActivity);
        ntpCat.setTitle(R.string.pref_ntp);
        root.addPreference(ntpCat);

        addPreferencesToCategory(ntpCat, "NTP_SERVER");

        // XTRA
        PreferenceCategory xtraCat = new PreferenceCategory(mActivity);
        xtraCat.setTitle(R.string.pref_category_xtra);
        root.addPreference(xtraCat);

        addPreferencesToCategory(xtraCat, "XTRA");

        // AGPS SUPL
        PreferenceCategory suplCat = new PreferenceCategory(mActivity);
        suplCat.setTitle(R.string.pref_category_supl);
        root.addPreference(suplCat);

        addPreferencesToCategory(suplCat, "SUPL");

        // AGPS C2K
        PreferenceCategory c2kCat = new PreferenceCategory(mActivity);
        c2kCat.setTitle(R.string.pref_category_c2k);
        root.addPreference(c2kCat);

        addPreferencesToCategory(c2kCat, "C2K");

        // AGPS Carrier
        PreferenceCategory agpsCat = new PreferenceCategory(mActivity);
        agpsCat.setTitle(R.string.pref_category_carrier);
        root.addPreference(agpsCat);

        addPreferencesToCategory(agpsCat, "CURRENT_CARRIER");
        addPreferencesToCategory(agpsCat, "DEFAULT_AGPS_ENABLE");
        addPreferencesToCategory(agpsCat, "DEFAULT_SSL_ENABLE");

        // Other
        PreferenceCategory otherCat = new PreferenceCategory(mActivity);
        otherCat.setTitle(R.string.pref_category_other);
        root.addPreference(otherCat);

        addPreferencesToCategory(otherCat, "");

        return root;
    }
}




Java Source Code List

org.fastergps.FasterGPSApplication.java
org.fastergps.ui.AdvancedSettingsActivity.java
org.fastergps.ui.BaseActivity.java
org.fastergps.ui.HelpAboutFragment.java
org.fastergps.ui.HelpActivity.java
org.fastergps.ui.HelpHtmlFragment.java
org.fastergps.util.Constants.java
org.fastergps.util.Log.java
org.fastergps.util.Utils.java
org.sufficientlysecure.donations.DonationsFragment.java
org.sufficientlysecure.donations.google.util.Base64DecoderException.java
org.sufficientlysecure.donations.google.util.Base64.java
org.sufficientlysecure.donations.google.util.IabException.java
org.sufficientlysecure.donations.google.util.IabHelper.java
org.sufficientlysecure.donations.google.util.IabResult.java
org.sufficientlysecure.donations.google.util.Inventory.java
org.sufficientlysecure.donations.google.util.Purchase.java
org.sufficientlysecure.donations.google.util.Security.java
org.sufficientlysecure.donations.google.util.SkuDetails.java
org.sufficientlysecure.htmltextview.HtmlTagHandler.java
org.sufficientlysecure.htmltextview.HtmlTextView.java
org.sufficientlysecure.htmltextview.JellyBeanSpanFixTextView.java
org.sufficientlysecure.htmltextview.UrlImageGetter.java
org.sufficientlysecure.rootcommands.Mount.java
org.sufficientlysecure.rootcommands.Remounter.java
org.sufficientlysecure.rootcommands.RootCommands.java
org.sufficientlysecure.rootcommands.Shell.java
org.sufficientlysecure.rootcommands.SystemCommands.java
org.sufficientlysecure.rootcommands.Toolbox.java
org.sufficientlysecure.rootcommands.command.Command.java
org.sufficientlysecure.rootcommands.command.ExecutableCommand.java
org.sufficientlysecure.rootcommands.command.SimpleCommand.java
org.sufficientlysecure.rootcommands.command.SimpleExecutableCommand.java
org.sufficientlysecure.rootcommands.util.BrokenBusyboxException.java
org.sufficientlysecure.rootcommands.util.Log.java
org.sufficientlysecure.rootcommands.util.RootAccessDeniedException.java
org.sufficientlysecure.rootcommands.util.UnsupportedArchitectureException.java
org.sufficientlysecure.rootcommands.util.Utils.java