예제 #1
0
  @Override
  protected void onDestroy() {
    super.onDestroy();
    String deviceId = settings.getDeviceIdentifier();
    String manualDeviceId = settings.getManualDeviceIdentifier().toLowerCase();

    if (!deviceId.equals(manualDeviceId)) {
      settings.setDeviceIdentifier(manualDeviceId);
    }
  }
예제 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    settings = new Settings(this);
    String registrationId = settings.getRegistrationIdentifier();

    preferenceAlert1 = this.findPreference(getString(R.string.ringtonePref1));
    preferenceAlert2 = this.findPreference(getString(R.string.ringtonePref2));
    preferenceAlert3 = this.findPreference(getString(R.string.ringtonePref3));
    preferenceAlert4 = this.findPreference(getString(R.string.ringtonePref4));
    preferenceAlert5 = this.findPreference(getString(R.string.ringtonePref5));
    preferenceManualDeviceIdentifier = this.findPreference(getString(R.string.manualDeviceIdPref));

    preferenceManualDeviceIdentifier.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            Boolean result = false;
            String deviceId = newValue.toString().toLowerCase();

            if (deviceId.equals("") || deviceId.matches("[[a-z]\\d]{12}")) {
              result = true;
            } else {
              Toast.makeText(
                      preference.getContext(),
                      getString(R.string.manual_device_id_error),
                      Toast.LENGTH_LONG)
                  .show();
            }

            return result;
          }
        });

    String deviceIdentifier = settings.getDeviceIdentifier();

    if (deviceIdentifier.equals("")) {
      deviceIdentifier = settings.scrambleIDS();
      Toast.makeText(this, getString(R.string.generated_id) + deviceIdentifier, Toast.LENGTH_SHORT)
          .show();
    }

    Preference deviceIDPref = this.findPreference(getString(R.string.deviceIdPref));
    deviceIDPref.setTitle(deviceIdentifier);

    if (!registrationId.equals("")) {
      // Already registered: disable manual setting of Device Identifier

      preferenceManualDeviceIdentifier.setSummary("Unregister first");
      preferenceManualDeviceIdentifier.setEnabled(false);
    }
  }