@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    // Set the global application version string
    Utils.setAppVersion(this);

    PreferenceManager.setDefaultValues(this, R.xml.settings, false);

    mHandler = new SplashHandler(this);

    mHandler.sendEmptyMessage(LICENSE_CHECK);
  }
 @Override
 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
   if (key.equals(Prefs.KEY_DIST_UNIT)) {
     distUnitPref.setSummary(
         Utils.getDistUnit(
             this, Integer.parseInt(sharedPreferences.getString(Prefs.KEY_DIST_UNIT, "0"))));
   } else if (key.equals(Prefs.KEY_DEFAULT_LOCATION)) {
     locationPref.setSummary(sharedPreferences.getString(key, ""));
   } else if (key.equals(Prefs.KEY_STATUS_FILTER)) {
     filterPref.setSummary(
         BreweryStatusFilterPreference.toString(
             this, sharedPreferences.getInt(key, BreweryStatusFilterPreference.DEFAULT_VALUE)));
   } else if (key.equals(Prefs.KEY_NEARBY_DISPLAY_MAP)) {
     String[] values = SettingsActivity.this.getResources().getStringArray(R.array.nearby_display);
     int index = Integer.parseInt(sharedPreferences.getString(key, Prefs.KEY_NEARBY_DISPLAY_LIST));
     nearbyDisplayPref.setSummary(values[index]);
   }
 }
    @Override
    public void handleMessage(Message msg) {
      Splash instance = mRef.get();

      switch (msg.what) {
          /*
                      case NETWORK_CHECK:
          				// Online?
          				if (!Utils.isOnline(instance)) {
          					ErrLog.log(instance, "Splash.onCreate()", null, R.string.No_network_connection);
          					DialogFrag.newInstance(DialogFrag.Mode.OFFLINE).show(instance.getSupportFragmentManager(),
          							"offline");
          				} else {
          					this.sendEmptyMessage(NETWORK_DONE);
          				}
          				break;
          			case NETWORK_DONE:
                          mHandler.sendEmptyMessage(LICENSE_CHECK);
          				break;
          */
        case LICENSE_CHECK:
          // Check the license status, if it hasn't previously been approved
          //                    SharedPreferences settings = Prefs.getSettings(instance);
          //                    if (Version.FREE) {
          //                        instance.onLicenseChecked(true);
          //                    } else if (settings.getBoolean(Prefs.KEY_LICENSED, false)) {
          //                        instance.onLicenseChecked(true);
          //                    } else {
          //                        if (Utils.getPlatformVersion().startsWith("5")) {
          //                            // Known bug:
          // https://code.google.com/p/android/issues/detail?id=78505
          //                            Log.w(Utils.APPTAG, "SKIPPING LICENSE CHECK <" +
          // Utils.getPlatformVersion() + ">");
          //                            instance.mLicensed = true;
          //                            mHandler.sendEmptyMessage(LICENSE_OK);
          //                        } else if (Utils.isOnline(instance)) {
          //                            mProgressDialog = ProgressDialog.show(instance,
          // instance.getString(R.string.Checking_license), "",
          //                                    true);
          //                            new Thread(new CheckLicenseTask(instance),
          // "CheckLicenseTask").start();
          //                        } else {
          //                            ErrLog.log(instance, "Splash.onCreate()", null,
          // R.string.Requires_network_access_to_check_license);
          //
          // DialogFrag.newInstance(DialogFrag.Mode.LICENSE_OFFLINE).show(instance
          //                                            .getSupportFragmentManager(),
          //                                    "offline");
          //                        }
          //                    }

          // Known bug: https://code.google.com/p/android/issues/detail?id=78505
          Log.w(Utils.APPTAG, "SKIPPING LICENSE CHECK <" + Utils.getPlatformVersion() + ">");
          instance.mLicensed = true;
          mHandler.sendEmptyMessage(LICENSE_OK);
          break;
        case LICENSE_OK:
          mHandler.sendEmptyMessage(LICENSE_DONE);
          break;
        case NOT_LICENSED:
          if (mProgressDialog != null) {
            mProgressDialog.dismiss();
          }

          DialogFrag.newInstance(DialogFrag.Mode.UNLICENSED)
              .show(instance.getSupportFragmentManager(), "unlicensed");
          mHandler.sendEmptyMessage(LICENSE_DONE);
          break;
        case LICENSE_DONE:
          if (mProgressDialog != null) {
            mProgressDialog.dismiss();
          }
          if (instance.mLicensed) {
            instance.checkDatabase();
          }
          break;
        case DATABASE_CHECK:
          if (mProgressDialog != null) {
            mProgressDialog.dismiss();
          }

          if (Utils.isOnline(instance)) {
            mProgressDialog =
                ProgressDialog.show(
                    instance, instance.getString(R.string.Database_update), "", true);
            if (DbOpenHelper.isUpdating(instance)) {
              if (Prefs.getSettings(instance)
                  .getBoolean(DatabaseUpdateAlert.SHOW_DB_UPDATE_ALERT_PREF, true)) {
                new DatabaseUpdateAlert()
                    .show(instance.getSupportFragmentManager(), "databaseUpdateAlert");
              } else {
                mHandler.sendEmptyMessage(DATABASE_DONE);
              }
            } else {
              DbOpenHelper helper = DbOpenHelper.getInstance(instance);
              mDb = helper.getWritableDatabase();
            }
          } else {
            ErrLog.log(
                instance,
                "Splash.onCreate()",
                null,
                R.string.Requires_network_access_to_update_database);
            mHandler.sendEmptyMessage(DATABASE_DONE);
          }
          break;
        case DATABASE_DONE:
          if (mProgressDialog != null) {
            mProgressDialog.dismiss();
          }

          if (mDb != null) {
            mDb.close();
          }

          try {
            Thread.sleep(1250);
          } catch (InterruptedException e) {
            // Ignore
          } finally {
            instance.startActivity(new Intent(instance, MainActivity.class));
            instance.finish();
          }
          break;
      }
    }
 @Override
 public void onStop() {
   super.onStop();
   Utils.trackActivityStop(this);
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.settings);
    mPrefs = Prefs.getSettings(this);
    mEditor = Prefs.getSettingsEditor(this);
    mSaver = Prefs.getSettingsSaver(this);

    distUnitPref = findPreference(Prefs.KEY_DIST_UNIT);
    distUnitPref.setSummary(
        Utils.getDistUnit(this, Integer.parseInt(mPrefs.getString(Prefs.KEY_DIST_UNIT, "0"))));
    distUnitPref.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            distUnitPref.setSummary(
                Utils.getDistUnit(SettingsActivity.this, Integer.parseInt((String) newValue)));
            return true;
          }
        });

    locationPref = findPreference(Prefs.KEY_DEFAULT_LOCATION);
    locationPref.setSummary(
        mPrefs.getString(Prefs.KEY_DEFAULT_LOCATION, getString(R.string.defaultLocationSummary)));
    locationPref.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            String newLoc = newValue.toString();

            return setupLocationList(newLoc);
          }
        });

    filterPref = findPreference(Prefs.KEY_STATUS_FILTER);
    int filter =
        mPrefs.getInt(Prefs.KEY_STATUS_FILTER, BreweryStatusFilterPreference.DEFAULT_VALUE);
    filterPref.setSummary(BreweryStatusFilterPreference.toString(getApplicationContext(), filter));
    filterPref.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            return true;
          }
        });

    nearbyDisplayPref = findPreference(Prefs.KEY_NEARBY_DISPLAY);
    if (Utils.checkPlayServices(this) && (Utils.checkOpenGLVersion(this) >= 2)) {
      nearbyDisplayPref.setOnPreferenceChangeListener(
          new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
              String[] values =
                  SettingsActivity.this.getResources().getStringArray(R.array.nearby_display);
              int index = Integer.parseInt((String) newValue);
              nearbyDisplayPref.setSummary(values[index]);
              return true;
            }
          });
    } else {
      // Device doesn't support maps.
      mEditor.putString(Prefs.KEY_NEARBY_DISPLAY, Prefs.KEY_NEARBY_DISPLAY_LIST);
      mSaver.savePreferences(mEditor, false);

      nearbyDisplayPref.setEnabled(false);
    }

    String[] values = SettingsActivity.this.getResources().getStringArray(R.array.nearby_display);
    int index = Integer.parseInt(mPrefs.getString(Prefs.KEY_NEARBY_DISPLAY, "error"));
    nearbyDisplayPref.setSummary(values[index]);
  }