Example #1
0
 // For outgoing messages
 public LocationMessage(GeocodableLocation l) {
   super();
   this.location = l;
   this.battery = Preferences.getPubLocationIncludeBattery() ? App.getBatteryLevel() : -1;
   ;
   this.waypoint = null;
   this.supressesTicker = false;
   this.trackerId = null;
   this.trigger = null;
   this.trackerId = Preferences.getTrackerId(true);
 }
    private void setServerPreferenceSummary(PreferenceFragment f, String s) {
      f.findPreference("connectionScreen")
          .setSummary(modesReadable[Preferences.getModeId()] + ": " + s);

      ((BaseAdapter) ((PreferenceScreen) f.findPreference("root")).getRootAdapter())
          .notifyDataSetChanged(); // Have to redraw the list to reflect summary change
    }
    public static void updateConnectButton() {
      Log.v("ActivityPreferencesCon", "updateConenctionbuttons");

      if (mMenu == null) return;

      MenuItem connectButton = mMenu.findItem(R.id.connect);

      if (connectButton == null) return;

      boolean canConnect = Preferences.canConnect();

      connectButton.setEnabled(canConnect);
      connectButton.getIcon().setAlpha(canConnect ? 255 : 130);
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      final Activity a = getActivity();
      PackageManager pm = a.getPackageManager();
      setHasOptionsMenu(true);

      Log.v(TAG, "Prepping preferences: " + Preferences.getModeId());

      if (Preferences.isModePrivate()) {
        this.getPreferenceManager().setSharedPreferencesName(Preferences.FILENAME_PRIVATE);
        addPreferencesFromResource(R.xml.preferences_private_connection);

        loadHostPreferences(a);
        loadSecurityPreferences(a);
        loadOptionsPreferences(a);
        loadIdentificationPreferences(a);

      } else if (Preferences.isModeHosted()) {
        Log.v(TAG, "Prepping hosted preferences");
        this.getPreferenceManager().setSharedPreferencesName(Preferences.FILENAME_HOSTED);
        addPreferencesFromResource(R.xml.preferences_hosted_connection);

        loadIdentificationPreferencesHosted(a);

      } else if (Preferences.isModePublic()) {
        this.getPreferenceManager().setSharedPreferencesName(Preferences.FILENAME_PUBLIC);
        addPreferencesFromResource(R.xml.preferences_public_connection);
      } else {
        throw new RuntimeException("Unknown application mode");
      }

      mode = findPreference(Preferences.getKey(R.string.keyModeId));
      String[] modesReadable = getResources().getStringArray(R.array.profileIds_readable);
      mode.setSummary(modesReadable[Preferences.getModeId()]);
      mode.setOnPreferenceChangeListener(
          new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
              Preferences.setMode(Integer.parseInt((String) newValue));
              ActivityPreferencesConnection.modeSwitch =
                  true; // signal that ConnectionPreferences should be shown again after fragment is
                        // restored
              getFragmentManager()
                  .beginTransaction()
                  .remove(getFragmentManager().findFragmentByTag("preferences"))
                  .add(R.id.content_frame, new FragmentPreferences(), "preferences")
                  .commit();
              return false; // Don't save, setMode already did
            }
          });
    }
Example #5
0
        @Override
        public boolean onPreferenceClick(Preference preference) {
          String exportStr;
          try {
            exportStr = Parser.serializeSync(Preferences.exportToMessage());
          } catch (JsonProcessingException e) {
            Toast.makeText(context, R.string.preferencesExportFailed, Toast.LENGTH_SHORT).show();
            e.printStackTrace();
            return false;
          }

          if (exportStr == null) return false;

          Log.v("Export", "Config: \n" + exportStr);
          File cDir = App.getInstance().getBaseContext().getCacheDir();
          File tempFile = new File(cDir.getPath() + "/" + TEMP_FILE_NAME);

          try {
            FileWriter writer = new FileWriter(tempFile);

            writer.write(exportStr);
            writer.close();

            Log.v(TAG, "Saved temporary config file for exportToMessage to " + tempFile.getPath());

          } catch (IOException e) {
            e.printStackTrace();
          }
          Uri configUri =
              FileProvider.getUriForFile(
                  App.getInstance(), "org.owntracks.android.fileprovider", tempFile);

          Intent sendIntent = new Intent();
          sendIntent.setAction(Intent.ACTION_SEND);
          sendIntent.putExtra(Intent.EXTRA_STREAM, configUri);
          sendIntent.setType("text/plain");

          context.startActivity(
              Intent.createChooser(sendIntent, context.getString(R.string.exportConfiguration)));
          Toast.makeText(context, R.string.preferencesExportSuccess, Toast.LENGTH_SHORT).show();

          return false;
        }
    private void loadOptionsPreferences(final Activity a) {

      Preference.OnPreferenceClickListener optionsClickListener =
          new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
              new MaterialDialog.Builder(a)
                  .customView(R.layout.preferences_options, true)
                  .title(R.string.preferencesOptions)
                  .positiveText(R.string.accept)
                  .negativeText(R.string.cancel)
                  .showListener(
                      new DialogInterface.OnShowListener() {
                        @Override
                        public void onShow(DialogInterface dialog) {
                          MaterialDialog d = MaterialDialog.class.cast(dialog);
                          Switch cleansession = (Switch) d.findViewById(R.id.cleanSession);
                          final MaterialEditText keepalive =
                              (MaterialEditText) d.findViewById(R.id.keepalive);
                          cleansession.setChecked(cleansessionVal);
                          cleansession.setOnCheckedChangeListener(
                              new CompoundButton.OnCheckedChangeListener() {
                                @Override
                                public void onCheckedChanged(
                                    CompoundButton buttonView, boolean isChecked) {
                                  cleansessionVal = isChecked;
                                }
                              });

                          keepalive.setText(Preferences.getKeepaliveWithHintSupport());
                        }
                      })
                  .callback(
                      new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(MaterialDialog dialog) {
                          Log.v(TAG, "saving parameters");
                          MaterialDialog d = MaterialDialog.class.cast(dialog);
                          final MaterialEditText keepalive =
                              (MaterialEditText) d.findViewById(R.id.keepalive);

                          Preferences.setCleanSession(cleansessionVal);
                          try {
                            Preferences.setKeepalive(
                                Integer.parseInt(keepalive.getText().toString()));

                          } catch (NumberFormatException e) {
                            Preferences.clearKey(R.string.keyKeepalive);
                          }

                          updateConnectButton();
                        }
                      })
                  .show();

              return true;
            }
          };

      cleansessionVal = Preferences.getCleanSession();
      optionsPreference = findPreference(getString(R.string.keyOptions));
      optionsPreference.setOnPreferenceClickListener(optionsClickListener);
    }
    private void loadSecurityPreferences(final Activity a) {

      Preference.OnPreferenceClickListener securityListener =
          new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
              securityDialog =
                  new MaterialDialog.Builder(a)
                      .customView(R.layout.preferences_security, true)
                      .title(R.string.preferencesSecurity)
                      .positiveText(R.string.accept)
                      .negativeText(R.string.cancel)
                      .showListener(
                          new DialogInterface.OnShowListener() {
                            @Override
                            public void onShow(DialogInterface dialog) {
                              tlsCaCrtFullPath = Preferences.getTlsCaCrtPath();
                              tlsClientCrtFullPath = Preferences.getTlsClientCrtPath();

                              MaterialDialog d = MaterialDialog.class.cast(dialog);
                              Switch tls = (Switch) d.findViewById(R.id.tls);

                              final MaterialEditText tlsCaCrt =
                                  (MaterialEditText) d.findViewById(R.id.tlsCaCrt);
                              final MaterialEditText tlsClientCrt =
                                  (MaterialEditText) d.findViewById(R.id.tlsClientCrt);
                              final MaterialEditText tlsClientCrtPassword =
                                  (MaterialEditText) d.findViewById(R.id.tlsClientCrtPassword);

                              setTlsCaCrtPath(tlsCaCrtFullPath, tlsCaCrt);
                              setTlsClientCrtPath(tlsClientCrtFullPath, tlsClientCrt);

                              tls.setChecked(tlsVal);
                              tls.setOnCheckedChangeListener(
                                  new CompoundButton.OnCheckedChangeListener() {
                                    @Override
                                    public void onCheckedChanged(
                                        CompoundButton buttonView, boolean isChecked) {
                                      tlsVal = isChecked;
                                      tlsCaCrt.setVisibility(tlsVal ? View.VISIBLE : View.GONE);
                                      tlsClientCrt.setVisibility(tlsVal ? View.VISIBLE : View.GONE);
                                      tlsClientCrtPassword.setVisibility(
                                          tlsVal && !"".equals(tlsClientCrt.getText().toString())
                                              ? View.VISIBLE
                                              : View.GONE);
                                    }
                                  });

                              tlsCaCrt.setVisibility(tlsVal ? View.VISIBLE : View.GONE);
                              tlsClientCrt.setVisibility(tlsVal ? View.VISIBLE : View.GONE);
                              tlsCaCrt.setOnClickListener(
                                  new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                      tlsCaCrt.setFocusable(true);
                                      tlsCaCrt.setFocusableInTouchMode(true);
                                      tlsCaCrt.requestFocus();
                                      PopupMenu popup =
                                          new PopupMenu(
                                              FragmentPreferences.this.getActivity(), tlsCaCrt);
                                      popup
                                          .getMenuInflater()
                                          .inflate(R.menu.picker, popup.getMenu());
                                      popup.setOnMenuItemClickListener(
                                          new PopupMenu.OnMenuItemClickListener() {
                                            public boolean onMenuItemClick(MenuItem item) {
                                              if (item.getItemId() == R.id.clear) {
                                                setTlsCaCrtPath("", tlsCaCrt);
                                              } else if (item.getItemId() == R.id.select)
                                                showFileChooser(
                                                    getActivity(),
                                                    FILE_SELECT_CODE_TLS_CA_CRT_PATH);
                                              tlsCaCrt.setFocusable(false);
                                              tlsCaCrt.setFocusableInTouchMode(false);

                                              return true;
                                            }
                                          });
                                      popup.setOnDismissListener(
                                          new PopupMenu.OnDismissListener() {
                                            @Override
                                            public void onDismiss(PopupMenu menu) {
                                              tlsCaCrt.setFocusable(false);
                                              tlsCaCrt.setFocusableInTouchMode(false);
                                            }
                                          });

                                      popup.show(); // showing popup menu
                                    }
                                  });

                              tlsClientCrt.setVisibility(tlsVal ? View.VISIBLE : View.GONE);
                              tlsClientCrt.setOnClickListener(
                                  new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                      tlsClientCrt.setFocusable(true);
                                      tlsClientCrt.setFocusableInTouchMode(true);
                                      tlsClientCrt.requestFocus();
                                      PopupMenu popup =
                                          new PopupMenu(
                                              FragmentPreferences.this.getActivity(), tlsClientCrt);
                                      popup
                                          .getMenuInflater()
                                          .inflate(R.menu.picker, popup.getMenu());
                                      popup.setOnMenuItemClickListener(
                                          new PopupMenu.OnMenuItemClickListener() {
                                            public boolean onMenuItemClick(MenuItem item) {
                                              if (item.getItemId() == R.id.clear) {
                                                setTlsClientCrtPath("", tlsClientCrt);
                                              } else if (item.getItemId() == R.id.select)
                                                showFileChooser(
                                                    getActivity(),
                                                    FILE_SELECT_CODE_TLS_CLIENT_CRT_PATH);
                                              tlsClientCrt.setFocusable(false);
                                              tlsClientCrt.setFocusableInTouchMode(false);

                                              return true;
                                            }
                                          });
                                      popup.setOnDismissListener(
                                          new PopupMenu.OnDismissListener() {
                                            @Override
                                            public void onDismiss(PopupMenu menu) {
                                              tlsClientCrt.setFocusable(false);
                                              tlsClientCrt.setFocusableInTouchMode(false);
                                            }
                                          });

                                      popup.show(); // showing popup menu
                                    }
                                  });
                              tlsClientCrt.addTextChangedListener(
                                  new TextWatcher() {
                                    @Override
                                    public void beforeTextChanged(
                                        CharSequence s, int start, int count, int after) {}

                                    @Override
                                    public void onTextChanged(
                                        CharSequence s, int start, int before, int count) {}

                                    @Override
                                    public void afterTextChanged(Editable s) {
                                      tlsClientCrtPassword.setVisibility(
                                          "".equals(s.toString()) ? View.GONE : View.VISIBLE);
                                    }
                                  });

                              tlsClientCrtPassword.setVisibility(
                                  tlsVal && !"".equals(tlsClientCrt.getText().toString())
                                      ? View.VISIBLE
                                      : View.GONE);
                              tlsClientCrtPassword.setText(Preferences.getTlsClientCrtPassword());
                            }
                          })
                      .callback(
                          new MaterialDialog.ButtonCallback() {
                            @Override
                            public void onPositive(MaterialDialog dialog) {
                              MaterialDialog d = MaterialDialog.class.cast(dialog);

                              Preferences.setTls(tlsVal);
                              Preferences.setTlsCaCrtPath(tlsCaCrtFullPath);
                              Preferences.setTlsClientCrtPath(tlsClientCrtFullPath);
                              Preferences.setTlsClientCrtPassword(
                                  ((MaterialEditText) d.findViewById(R.id.tlsClientCrtPassword))
                                      .getText()
                                      .toString());
                              updateConnectButton();
                              securityDialog = null;
                            }
                          })
                      .show();

              return true;
            }
          };
      tlsVal = Preferences.getTls();
      securityPreference = findPreference(getString(R.string.keySecurity));
      securityPreference.setOnPreferenceClickListener(securityListener);
    }
    private void loadIdentificationPreferencesHosted(final Activity a) {
      Preference.OnPreferenceClickListener identificationClickListener =
          new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
              new MaterialDialog.Builder(a)
                  .customView(R.layout.preferences_identification_hosted, true)
                  .title(R.string.preferencesIdentification)
                  .positiveText(R.string.accept)
                  .negativeText(R.string.cancel)
                  .showListener(
                      new DialogInterface.OnShowListener() {
                        @Override
                        public void onShow(DialogInterface dialog) {
                          MaterialDialog d = MaterialDialog.class.cast(dialog);
                          final MaterialEditText username =
                              (MaterialEditText) d.findViewById(R.id.usernameHosted);
                          final MaterialEditText password =
                              (MaterialEditText) d.findViewById(R.id.passwordHosted);
                          final MaterialEditText deviceId =
                              (MaterialEditText) d.findViewById(R.id.deviceIdHosted);
                          final MaterialEditText trackerId =
                              (MaterialEditText) d.findViewById(R.id.trackerId);

                          username.setText(Preferences.getUsername());
                          password.setText(Preferences.getPassword());
                          deviceId.setText(Preferences.getDeviceId(false));
                          trackerId.setText(Preferences.getTrackerId(false));
                          trackerId.setHint(Preferences.getTrackerIdDefault());

                          deviceId.addTextChangedListener(
                              new TextWatcher() {
                                @Override
                                public void beforeTextChanged(
                                    CharSequence s, int start, int count, int after) {}

                                @Override
                                public void onTextChanged(
                                    CharSequence s, int start, int before, int count) {
                                  if (s.length() >= 2)
                                    trackerId.setHint(
                                        s.toString().substring(deviceId.length() - 2));
                                  else trackerId.setHint(Preferences.getTrackerIdDefault());
                                }

                                @Override
                                public void afterTextChanged(Editable s) {}
                              });
                        }
                      })
                  .callback(
                      new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(MaterialDialog dialog) {
                          MaterialDialog d = MaterialDialog.class.cast(dialog);
                          final MaterialEditText username =
                              (MaterialEditText) d.findViewById(R.id.usernameHosted);
                          final MaterialEditText password =
                              (MaterialEditText) d.findViewById(R.id.passwordHosted);
                          final MaterialEditText deviceId =
                              (MaterialEditText) d.findViewById(R.id.deviceIdHosted);
                          final MaterialEditText trackerId =
                              (MaterialEditText) d.findViewById(R.id.trackerId);

                          Preferences.setUsername(username.getText().toString());
                          Preferences.setPassword(password.getText().toString());
                          Preferences.setDeviceId(deviceId.getText().toString());
                          Preferences.setTrackerId(trackerId.getText().toString());

                          updateConnectButton();
                        }
                      })
                  .show();

              return true;
            }
          };

      authenticationVal = Preferences.getAuth();
      identificationPreference = findPreference(getString(R.string.keyIdentification));
      identificationPreference.setOnPreferenceClickListener(identificationClickListener);
    }
    private void loadSecurityPreferences(final Activity a) {
      Preference.OnPreferenceClickListener securityListener =
          new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
              new MaterialDialog.Builder(a)
                  .customView(R.layout.preferences_security, true)
                  .title(R.string.preferencesSecurity)
                  .positiveText(R.string.accept)
                  .negativeText(R.string.cancel)
                  .showListener(
                      new DialogInterface.OnShowListener() {
                        @Override
                        public void onShow(DialogInterface dialog) {
                          MaterialDialog d = MaterialDialog.class.cast(dialog);
                          Switch tls = (Switch) d.findViewById(R.id.tls);
                          final MaterialEditText tlsCaCrt =
                              (MaterialEditText) d.findViewById(R.id.tlsCaCrt);
                          final MaterialEditText tlsClientCrt =
                              (MaterialEditText) d.findViewById(R.id.tlsClientCrt);

                          tls.setChecked(tlsVal);
                          tlsCaCrt.setVisibility(tlsVal ? View.VISIBLE : View.GONE);
                          tlsCaCrt.setText(Preferences.getTlsCaCrtPath());

                          tlsClientCrt.setVisibility(tlsVal ? View.VISIBLE : View.GONE);
                          tlsClientCrt.setText(Preferences.getTlsClientCrtPath());

                          tls.setOnCheckedChangeListener(
                              new CompoundButton.OnCheckedChangeListener() {
                                @Override
                                public void onCheckedChanged(
                                    CompoundButton buttonView, boolean isChecked) {
                                  tlsVal = isChecked;
                                  tlsCaCrt.setVisibility(tlsVal ? View.VISIBLE : View.GONE);
                                  tlsClientCrt.setVisibility(tlsVal ? View.VISIBLE : View.GONE);
                                }
                              });
                        }
                      })
                  .callback(
                      new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(MaterialDialog dialog) {
                          MaterialDialog d = MaterialDialog.class.cast(dialog);
                          MaterialEditText tlsCaCrt =
                              (MaterialEditText) d.findViewById(R.id.tlsCaCrt);
                          MaterialEditText tlsClientCrt =
                              (MaterialEditText) d.findViewById(R.id.tlsClientCrt);

                          Preferences.setTls(tlsVal);
                          Preferences.setTlsCaCrtPath(tlsCaCrt.getText().toString());
                          Preferences.setTlsClientCrtPath(tlsClientCrt.getText().toString());

                          updateConnectButton();
                        }
                      })
                  .show();

              return true;
            }
          };
      tlsVal = Preferences.getTls();
      securityPreference = findPreference(getString(R.string.keySecurity));
      securityPreference.setOnPreferenceClickListener(securityListener);
    }
    private void loadIdentificationPreferencesFreeform(final Activity a) {
      Preference.OnPreferenceClickListener identificationClickListener =
          new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
              new MaterialDialog.Builder(a)
                  .customView(R.layout.preferences_identification_freeform, true)
                  .title(R.string.preferencesIdentification)
                  .positiveText(R.string.accept)
                  .negativeText(R.string.cancel)
                  .showListener(
                      new DialogInterface.OnShowListener() {
                        @Override
                        public void onShow(DialogInterface dialog) {
                          MaterialDialog d = MaterialDialog.class.cast(dialog);
                          Switch authentication = (Switch) d.findViewById(R.id.authentication);
                          final MaterialEditText username =
                              (MaterialEditText) d.findViewById(R.id.username);
                          final MaterialEditText password =
                              (MaterialEditText) d.findViewById(R.id.password);
                          final MaterialEditText clientId =
                              (MaterialEditText) d.findViewById(R.id.clientId);
                          final MaterialEditText deviceTopic =
                              (MaterialEditText) d.findViewById(R.id.deviceTopic);

                          authentication.setOnCheckedChangeListener(
                              new CompoundButton.OnCheckedChangeListener() {
                                @Override
                                public void onCheckedChanged(
                                    CompoundButton buttonView, boolean isChecked) {
                                  authenticationVal = isChecked;
                                  password.setVisibility(
                                      authenticationVal ? View.VISIBLE : View.GONE);
                                }
                              });

                          authentication.setChecked(authenticationVal);
                          username.setText(Preferences.getUsername());
                          password.setText(Preferences.getPassword());
                          password.setVisibility(authenticationVal ? View.VISIBLE : View.GONE);
                          clientId.setText(Preferences.getClientId(false));
                          clientId.setHint(Preferences.getClientIdDefault());
                          deviceTopic.setText(Preferences.getDeviceTopic(false));
                          deviceTopic.setHint(Preferences.getDeviceTopicDefault());
                        }
                      })
                  .callback(
                      new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(MaterialDialog dialog) {
                          MaterialDialog d = MaterialDialog.class.cast(dialog);
                          final MaterialEditText username =
                              (MaterialEditText) d.findViewById(R.id.username);
                          final MaterialEditText password =
                              (MaterialEditText) d.findViewById(R.id.password);
                          final MaterialEditText clientId =
                              (MaterialEditText) d.findViewById(R.id.clientId);
                          final MaterialEditText deviceTopic =
                              (MaterialEditText) d.findViewById(R.id.deviceTopic);

                          Preferences.setAuth(authenticationVal);
                          Preferences.setUsername(username.getText().toString());
                          Preferences.setPassword(password.getText().toString());
                          Preferences.setClientId(clientId.getText().toString());
                          Preferences.setDeviceTopic(deviceTopic.getText().toString());

                          updateConnectButton();
                        }
                      })
                  .show();

              return true;
            }
          };

      authenticationVal = Preferences.getAuth();
      identificationPreference = findPreference(getString(R.string.keyIdentification));
      identificationPreference.setOnPreferenceClickListener(identificationClickListener);
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      final Activity a = getActivity();
      PackageManager pm = a.getPackageManager();
      modesReadable = getResources().getStringArray(R.array.profileIds_readable);

      Log.v(TAG, "Prepping preferences: " + Preferences.getModeId());

      if (Preferences.isModeFreeform()) {
        this.getPreferenceManager().setSharedPreferencesName(Preferences.FILENAME_FREEFORM);
        addPreferencesFromResource(R.xml.preferences_private);
      } else if (Preferences.isModePrivate()) {
        this.getPreferenceManager().setSharedPreferencesName(Preferences.FILENAME_PRIVATE);
        addPreferencesFromResource(R.xml.preferences_private);
      } else if (Preferences.isModeHosted()) {
        this.getPreferenceManager().setSharedPreferencesName(Preferences.FILENAME_HOSTED);
        addPreferencesFromResource(R.xml.preferences_hosted);
      } else if (Preferences.isModePublic()) {
        this.getPreferenceManager().setSharedPreferencesName(Preferences.FILENAME_PUBLIC);
        addPreferencesFromResource(R.xml.preferences_public);
      } else {
        throw new RuntimeException("Unknown application mode");
      }

      repo = findPreference("repo");
      mail = findPreference("mail");
      twitter = findPreference("twitter");
      version = findPreference("versionReadOnly");

      locatorDisplacement =
          (EditIntegerPreference)
              findPreference(Preferences.getKey(R.string.keyLocatorDisplacement));
      locatorDisplacement.setHint(
          Integer.toString(Preferences.getIntResource(R.integer.valLocatorDisplacement)));

      locatorInterval =
          (EditIntegerPreference) findPreference(Preferences.getKey(R.string.keyLocatorInterval));
      locatorInterval.setHint(
          Integer.toString(Preferences.getIntResource(R.integer.valLocatorInterval)));

      try {
        ver = pm.getPackageInfo(a.getPackageName(), 0).versionName;
      } catch (PackageManager.NameNotFoundException e) {
        ver = a.getString(R.string.na);
      }
      version.setSummary(ver);

      repo.setOnPreferenceClickListener(
          new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
              Intent intent = new Intent(Intent.ACTION_VIEW);
              intent.setData(Uri.parse(Preferences.getRepoUrl()));
              a.startActivity(intent);
              return false;
            }
          });

      mail.setOnPreferenceClickListener(
          new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
              Intent intent = new Intent(Intent.ACTION_SEND);
              intent.setType("message/rfc822");
              intent.putExtra(Intent.EXTRA_EMAIL, new String[] {Preferences.getIssuesMail()});
              intent.putExtra(Intent.EXTRA_SUBJECT, "OwnTracks (Version: " + ver + ")");
              a.startActivity(Intent.createChooser(intent, "Send Email"));
              return false;
            }
          });

      twitter.setOnPreferenceClickListener(
          new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
              Intent intent = new Intent(Intent.ACTION_VIEW);
              intent.setData(Uri.parse(Preferences.getTwitterUrl()));
              a.startActivity(intent);
              return false;
            }
          });

      setServerPreferenceSummary(this);

      Preference.OnPreferenceClickListener connectionListener =
          new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
              Log.v(TAG, "startActivityForResult ActivityPreferencesConnection");
              Intent intent = new Intent(getActivity(), ActivityPreferencesConnection.class);
              intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
              getActivity().startActivityForResult(intent, REQUEST_CODE_CONNECTION);
              return true;
            }
          };

      // Fix toolbars for PreferenceScreens on demand
      Preference.OnPreferenceClickListener genericListener =
          new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(final android.preference.Preference preference) {
              if (!(preference instanceof PreferenceScreen)) return false;

              final Dialog dialog = ((PreferenceScreen) preference).getDialog();

              LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent();
              final Toolbar bar =
                  (Toolbar)
                      LayoutInflater.from(preference.getContext())
                          .inflate(R.layout.toolbar, root, false);
              root.addView(bar, 0); // insert at top

              bar.setTitle(preference.getTitle());
              bar.setNavigationOnClickListener(
                  new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                      dialog.dismiss();
                    }
                  });

              return false;
            }
          };
      findPreference("connectionScreen").setOnPreferenceClickListener(connectionListener);
      findPreference("reportingScreen").setOnPreferenceClickListener(genericListener);
      findPreference("notificationScreen").setOnPreferenceClickListener(genericListener);
      findPreference("advancedScreen").setOnPreferenceClickListener(genericListener);
      findPreference("informationScreen").setOnPreferenceClickListener(genericListener);
    }