<commit_before>package com.njackson;

import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;

/**
 * Created with IntelliJ IDEA.
 * User: njackson
 * Date: 31/07/2013
 * Time: 22:43
 * To change this template use File | Settings | File Templates.
 */
public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
	
	private static final String TAG = "PB-SettingsActivity";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);

        OnPreferenceClickListener pref_install_click_listener = new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                // TODO Auto-generated method stub
                Log.d(TAG, "onPreferenceClick:" + preference.getKey());
                if (preference.getKey().equals("pref_install")) {
                    install_watchface(1);
                }
                if (preference.getKey().equals("pref_install_sdk2")) {
                    install_watchface(2);
                }
                if (preference.getKey().equals("PREF_HRM")) {
                    final Intent intent = new Intent(getApplicationContext(), HRMScanActivity.class);
                    startActivity(intent);                    
                }
                return false;
            }
        };
        
        Preference pref;
        Preference pref2 = findPreference("pref_install_sdk2");
        pref2.setOnPreferenceClickListener(pref_install_click_listener);
        if (MainActivity.pebbleFirmwareVersion == 2) {
            pref2.setTitle(pref2.getTitle() + " [your version]");
            pref2.setSummary(pref2.getSummary() + " This is the version compatible with your current Pebble firmware.");
        }

        pref = findPreference("PREF_PRESSURE_INFO");
        SensorManager mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        if (mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE) != null){
            pref.setSummary("Pressure sensor available");
        } else {
            pref.setSummary("No pressure sensor");
        }

        pref = findPreference("PREF_GEOID_HEIGHT_INFO");
        if (MainActivity.geoidHeight != 0) {
            pref.setSummary("Correction: " + MainActivity.geoidHeight + "m");
        } else {
            pref.setSummary("No correction");
        }

        _setHrmSummary();

        // check to determine whether BLE is supported on the device.
        if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
            Preference pref_hrm = findPreference("PREF_HRM");
            pref_hrm.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    if (preference.getKey().equals("PREF_HRM")) {
                        final Intent intent = new Intent(getApplicationContext(), HRMScanActivity.class);
                        startActivityForResult(intent, 1);
                    }
                    return false;
                }
            });
        }
    }
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1) {
           String hrm_name = "";
           String hrm_address = "";
           if(resultCode == RESULT_OK) {
               hrm_name = data.getStringExtra("hrm_name");
               hrm_address = data.getStringExtra("hrm_address");
           }

           SharedPreferences settings = getSharedPreferences(Constants.PREFS_NAME,0);
           SharedPreferences.Editor editor = settings.edit();
           editor.putString("hrm_name", hrm_name);
           editor.putString("hrm_address", hrm_address);
           editor.commit();

           // reload prefs
           MainActivity.getInstance().loadPreferences();

           _setHrmSummary();

           if (!hrm_address.equals("")) {
               if (MainActivity.getInstance().checkServiceRunning()) {
                   Toast.makeText(getApplicationContext(), "Please restart GPS to display heart rate", Toast.LENGTH_LONG).show();
               } else {
                   // only one toast message...
                   Toast.makeText(getApplicationContext(), "Beta version: heart rate will be sent to Pebble instead of instant speed", Toast.LENGTH_LONG).show();
               }
           }
        }
    }
    private boolean install_watchface(int sdkVersion) {
        int versionCode;
    
        // Get current version code and version name
        try {
            PackageInfo packageInfo = getApplicationContext().getPackageManager().getPackageInfo(
                    getApplicationContext().getPackageName(), 0);
    
            versionCode = packageInfo.versionCode;<commit_msg>Remove beta message<commit_after>package com.njackson;

import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;

/**
 * Created with IntelliJ IDEA.
 * User: njackson
 * Date: 31/07/2013
 * Time: 22:43
 * To change this template use File | Settings | File Templates.
 */
public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
	
	private static final String TAG = "PB-SettingsActivity";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);

        OnPreferenceClickListener pref_install_click_listener = new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                // TODO Auto-generated method stub
                Log.d(TAG, "onPreferenceClick:" + preference.getKey());
                if (preference.getKey().equals("pref_install")) {
                    install_watchface(1);
                }
                if (preference.getKey().equals("pref_install_sdk2")) {
                    install_watchface(2);
                }
                if (preference.getKey().equals("PREF_HRM")) {
                    final Intent intent = new Intent(getApplicationContext(), HRMScanActivity.class);
                    startActivity(intent);                    
                }
                return false;
            }
        };
        
        Preference pref;
        Preference pref2 = findPreference("pref_install_sdk2");
        pref2.setOnPreferenceClickListener(pref_install_click_listener);
        if (MainActivity.pebbleFirmwareVersion == 2) {
            pref2.setTitle(pref2.getTitle() + " [your version]");
            pref2.setSummary(pref2.getSummary() + " This is the version compatible with your current Pebble firmware.");
        }

        pref = findPreference("PREF_PRESSURE_INFO");
        SensorManager mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        if (mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE) != null){
            pref.setSummary("Pressure sensor available");
        } else {
            pref.setSummary("No pressure sensor");
        }

        pref = findPreference("PREF_GEOID_HEIGHT_INFO");
        if (MainActivity.geoidHeight != 0) {
            pref.setSummary("Correction: " + MainActivity.geoidHeight + "m");
        } else {
            pref.setSummary("No correction");
        }

        _setHrmSummary();

        // check to determine whether BLE is supported on the device.
        if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
            Preference pref_hrm = findPreference("PREF_HRM");
            pref_hrm.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    if (preference.getKey().equals("PREF_HRM")) {
                        final Intent intent = new Intent(getApplicationContext(), HRMScanActivity.class);
                        startActivityForResult(intent, 1);
                    }
                    return false;
                }
            });
        }
    }
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1) {
           String hrm_name = "";
           String hrm_address = "";
           if(resultCode == RESULT_OK) {
               hrm_name = data.getStringExtra("hrm_name");
               hrm_address = data.getStringExtra("hrm_address");
           }

           SharedPreferences settings = getSharedPreferences(Constants.PREFS_NAME,0);
           SharedPreferences.Editor editor = settings.edit();
           editor.putString("hrm_name", hrm_name);
           editor.putString("hrm_address", hrm_address);
           editor.commit();

           // reload prefs
           MainActivity.getInstance().loadPreferences();

           _setHrmSummary();

           if (!hrm_address.equals("")) {
               if (MainActivity.getInstance().checkServiceRunning()) {
                   Toast.makeText(getApplicationContext(), "Please restart GPS to display heart rate", Toast.LENGTH_LONG).show();
               }
           }
        }
    }
    private boolean install_watchface(int sdkVersion) {
        int versionCode;
    
        // Get current version code and version name
        try {
            PackageInfo packageInfo = getApplicationContext().getPackageManager().getPackageInfo(
                    getApplicationContext().getPackageName(), 0);
    
            versionCode = packageInfo.versionCode;
{'fraction_non_alphanumeric': 0.09215686274509804, 'fraction_numerical': 0.004991087344028521, 'mean_word_length': 2.464340845940105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '116016', 'n_tokens_mistral': 2856, 'n_tokens_neox': 2761, 'n_words': 559}