@Override
    protected void onCreate(Bundle icicle) {
      super.onCreate(icicle);
      if (DBG) log("Settings: onCreate()...");

      getPreferenceManager().setSharedPreferencesName(SHARED_PREFERENCES_NAME);

      // This preference screen is ultra-simple; it's just 4 plain
      // <EditTextPreference>s, one for each of the 4 "canned responses".
      //
      // The only nontrivial thing we do here is copy the text value of
      // each of those EditTextPreferences and use it as the preference's
      // "title" as well, so that the user will immediately see all 4
      // strings when they arrive here.
      //
      // Also, listen for change events (since we'll need to update the
      // title any time the user edits one of the strings.)

      addPreferencesFromResource(R.xml.respond_via_sms_settings);

      EditTextPreference pref;
      pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_1);
      pref.setTitle(pref.getText());
      pref.setOnPreferenceChangeListener(this);

      pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_2);
      pref.setTitle(pref.getText());
      pref.setOnPreferenceChangeListener(this);

      pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_3);
      pref.setTitle(pref.getText());
      pref.setOnPreferenceChangeListener(this);

      pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_4);
      pref.setTitle(pref.getText());
      pref.setOnPreferenceChangeListener(this);
      /* Begin: Modified by zxiaona for add_autosms 2012/07/27 */
      pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_5);
      pref.setTitle(pref.getText());
      pref.setOnPreferenceChangeListener(this);
      /* End: Modified by zxiaona for add_autosms 2012/07/27 */

      ActionBar actionBar = getActionBar();
      if (actionBar != null) {
        // android.R.id.home will be triggered in onOptionsItemSelected()
        actionBar.setDisplayHomeAsUpEnabled(true);
      }
    }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getPreferenceManager() != null) {
      addPreferencesFromResource(R.xml.operator_preferences);
      PreferenceScreen prefSet = getPreferenceScreen();

      mOperatorDisplayStyle = (ListPreference) prefSet.findPreference(OPERATOR_STYLE);
      mOperatorDisplayStyle.setOnPreferenceChangeListener(this);

      mOperatorDisplayText = (EditTextPreference) prefSet.findPreference(OPERATOR_TEXT);
      mOperatorDisplayText.setOnPreferenceChangeListener(this);

      if (mOperatorDisplayText != null) {
        String operLabel = mOperatorDisplayText.getText();
        if (TextUtils.isEmpty(operLabel)) {
          mOperatorDisplayText.setSummary(getString(R.string.operator_display_summary));
        } else {
          mOperatorDisplayText.setSummary(mOperatorDisplayText.getText());
        }
      }

      int index = Settings.System.getInt(getContentResolver(), CARRIER_LABEL_TYPE, 0);
      index = index > (mOperatorDisplayStyle.getEntries().length - 1) ? 0 : index;
      mOperatorDisplayStyle.setSummary(mOperatorDisplayStyle.getEntries()[index]);

      mOperatorDisplayText.setEnabled(index == 3);
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    PreferenceScreen ps = getPreferenceManager().createPreferenceScreen(getActivity());
    ps.setTitle(R.string.quick_response_settings_title);

    mResponses = Utils.getQuickResponses(getActivity());

    if (mResponses != null) {
      mEditTextPrefs = new EditTextPreference[mResponses.length];

      Arrays.sort(mResponses);
      int i = 0;
      for (String response : mResponses) {
        EditTextPreference et = new EditTextPreference(getActivity());
        et.setDialogTitle(R.string.quick_response_settings_edit_title);
        et.setTitle(response); // Display Text
        et.setText(response); // Value to edit
        et.setOnPreferenceChangeListener(this);
        mEditTextPrefs[i++] = et;
        ps.addPreference(et);
      }
    } else {
      Log.wtf(TAG, "No responses found");
    }
    setPreferenceScreen(ps);
    /// M:Toast to alarm @{
    mToast = Toast.makeText(getActivity(), "", Toast.LENGTH_SHORT);
    /// @}
  }
Exemplo n.º 4
0
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.pref_general);
      setHasOptionsMenu(true);

      ((PreferencesActivity) getActivity()).setBasePreferenceActivity(false);

      ((PreferencesActivity) getActivity())
          .getSupportActionBar()
          .setTitle(R.string.pref_header_general);
      ((PreferencesActivity) getActivity())
          .firebaseAnalytics.logEvent(getString(R.string.analytics_tap_general_prefs), null);

      final EditTextPreference p =
          (EditTextPreference) findPreference(getString(R.string.pref_device_name));
      bindPreferenceSummaryToValue(p);

      if (p.getTitle().toString().equals(getString(R.string.pref_default_device_name))
          || p.getTitle().toString().isEmpty()) {
        ((PreferencesActivity) getActivity())
            .firebaseAnalytics.logEvent(
                getString(R.string.analytics_event_empty_device_name), null);
        p.setText(Build.MANUFACTURER + " " + Build.MODEL);
      }

      p.setOnPreferenceChangeListener(
          new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
              p.setSummary(newValue.toString());

              Intent i = new Intent("com.texasgamer.zephyr.SOCKET_SERVICE");
              i.putExtra("type", "update-devices");
              getActivity().sendBroadcast(i);

              Bundle b = new Bundle();
              b.putString(getString(R.string.analytics_param_new_value), newValue.toString());
              ((PreferencesActivity) getActivity())
                  .firebaseAnalytics.logEvent(getString(R.string.analytics_tap_device_name), b);
              return true;
            }
          });

      findPreference(getString(R.string.pref_start_on_boot))
          .setOnPreferenceChangeListener(
              new Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                  Bundle b = new Bundle();
                  String newValueStr = newValue.toString().equals("true") ? "enabled" : "disabled";
                  b.putString(getString(R.string.analytics_param_new_value), newValueStr);
                  ((PreferencesActivity) getActivity())
                      .firebaseAnalytics.logEvent(
                          getString(R.string.analytics_tap_start_on_boot), b);
                  return true;
                }
              });
    }
Exemplo n.º 5
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    PreferenceManager.setDefaultValues(Settings.this, R.xml.preferences, false);
    settingPreference = this.getSharedPreferences(SHARED_PREF_FILE, MODE_PRIVATE);
    PreferenceScreen prefSet = getPreferenceScreen();

    mRemoteIP = (EditTextPreference) prefSet.findPreference(KEY_REMOTE_IP);
    mRemoteIP.setOnPreferenceChangeListener(this);

    mLocalPort = (EditTextPreference) prefSet.findPreference(KEY_LOCAL_PORT);
    mLocalPort.setOnPreferenceChangeListener(this);

    mRemotePort = (EditTextPreference) prefSet.findPreference(KEY_REMOTE_PORT);
    mRemotePort.setOnPreferenceChangeListener(this);

    mEnableAudio = (CheckBoxPreference) prefSet.findPreference(KEY_ENABLE_AUDIO);

    mEnableAudioViaCss = (CheckBoxPreference) prefSet.findPreference(KEY_ENABLE_AUDIO_VIA_CSS);

    mEnableVideo = (CheckBoxPreference) prefSet.findPreference(KEY_ENABLE_VIDEO);

    mEnableLog = (CheckBoxPreference) prefSet.findPreference(KEY_ENABLE_LOGGING);

    mEnableFullScreen = (CheckBoxPreference) prefSet.findPreference(KEY_FULL_SCREEN);

    mAudioEncoder = (ListPreference) prefSet.findPreference(KEY_AUDIO_CODECS);
    mAudioEncoder.setOnPreferenceChangeListener(this);

    /*   mAudioChannel = (ListPreference)prefSet.findPreference(KEY_AUDIO_CHANNEL);
      mAudioChannel.setOnPreferenceChangeListener(this);
    */

    mVideoEncoder = (ListPreference) prefSet.findPreference(KEY_VIDEO_CODECS);
    mVideoEncoder.setOnPreferenceChangeListener(this);

    /* TBD: Video resolution needs to be made dynamic */
    mVideoResolution = (ListPreference) prefSet.findPreference(KEY_RESOLUTION);
    mVideoResolution.setOnPreferenceChangeListener(this);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.propmodder);
    prefSet = getPreferenceScreen();

    mWifiScanPref = (ListPreference) prefSet.findPreference(WIFI_SCAN_PREF);
    mWifiScanPref.setOnPreferenceChangeListener(this);

    mMaxEventsPref = (ListPreference) prefSet.findPreference(MAX_EVENTS_PREF);
    mMaxEventsPref.setOnPreferenceChangeListener(this);

    mRingDelayPref = (ListPreference) prefSet.findPreference(RING_DELAY_PREF);
    mRingDelayPref.setOnPreferenceChangeListener(this);

    mVmHeapsizePref = (ListPreference) prefSet.findPreference(VM_HEAPSIZE_PREF);
    mVmHeapsizePref.setOnPreferenceChangeListener(this);

    mFastUpPref = (ListPreference) prefSet.findPreference(FAST_UP_PREF);
    mFastUpPref.setOnPreferenceChangeListener(this);

    mProxDelayPref = (ListPreference) prefSet.findPreference(PROX_DELAY_PREF);
    mProxDelayPref.setOnPreferenceChangeListener(this);

    mSleepPref = (ListPreference) prefSet.findPreference(SLEEP_PREF);
    mSleepPref.setOnPreferenceChangeListener(this);

    mTcpStackPref = (CheckBoxPreference) prefSet.findPreference(TCP_STACK_PREF);

    mJitPref = (CheckBoxPreference) prefSet.findPreference(JIT_PREF);

    mModVersionPref = (EditTextPreference) prefSet.findPreference(MOD_VERSION_PREF);
    String mod = Helpers.findBuildPropValueOf(MOD_VERSION_PROP);
    if (mModVersionPref != null) {
      EditText modET = mModVersionPref.getEditText();
      ModPrefHolder = mModVersionPref.getEditText().toString();
      if (modET != null) {
        InputFilter lengthFilter = new InputFilter.LengthFilter(32);
        modET.setFilters(new InputFilter[] {lengthFilter});
        modET.setSingleLine(true);
      }
      mModVersionPref.setSummary(
          String.format(getString(R.string.pref_mod_version_alt_summary), mod));
    }
    Log.d(TAG, String.format("ModPrefHoler = '%s' found build number = '%s'", ModPrefHolder, mod));
    mModVersionPref.setOnPreferenceChangeListener(this);

    m3gSpeedPref = (CheckBoxPreference) prefSet.findPreference(THREE_G_PREF);

    mGpuPref = (CheckBoxPreference) prefSet.findPreference(GPU_PREF);

    updateScreen();
  }
Exemplo n.º 7
0
 public EditTextPreference createEditTextPreference(
     OsmandPreference<String> b, int title, int summary) {
   EditTextPreference p = new EditTextPreference(this);
   p.setTitle(title);
   p.setKey(b.getId());
   p.setDialogTitle(title);
   p.setSummary(summary);
   p.setOnPreferenceChangeListener(this);
   screenPreferences.put(b.getId(), p);
   editTextPreferences.put(b.getId(), b);
   return p;
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.rcs_settings_presence_preferences);
    setTitle(R.string.rcs_settings_title_presence_settings);

    freetextEdit1 = (EditTextPreference) findPreference("edit_freetext1");
    freetextEdit1.setPersistent(false);
    freetextEdit1.setOnPreferenceChangeListener(this);
    String txt1 = RcsSettings.getInstance().getPredefinedFreetext1();
    freetextEdit1.setText(txt1);
    freetextEdit1.setTitle(txt1);

    freetextEdit2 = (EditTextPreference) findPreference("edit_freetext2");
    freetextEdit2.setPersistent(false);
    freetextEdit2.setOnPreferenceChangeListener(this);
    String txt2 = RcsSettings.getInstance().getPredefinedFreetext2();
    freetextEdit2.setText(txt2);
    freetextEdit2.setTitle(txt2);

    freetextEdit3 = (EditTextPreference) findPreference("edit_freetext3");
    freetextEdit3.setPersistent(false);
    freetextEdit3.setOnPreferenceChangeListener(this);
    String txt3 = RcsSettings.getInstance().getPredefinedFreetext3();
    freetextEdit3.setText(txt3);
    freetextEdit3.setTitle(txt3);

    freetextEdit4 = (EditTextPreference) findPreference("edit_freetext4");
    freetextEdit4.setPersistent(false);
    freetextEdit4.setOnPreferenceChangeListener(this);
    String txt4 = RcsSettings.getInstance().getPredefinedFreetext4();
    freetextEdit4.setText(txt4);
    freetextEdit4.setTitle(txt4);

    vibrateInvitation = (CheckBoxPreference) findPreference("presence_invitation_vibration");
    vibrateInvitation.setPersistent(false);
    vibrateInvitation.setOnPreferenceChangeListener(this);
    vibrateInvitation.setChecked(RcsSettings.getInstance().isPhoneVibrateForPresenceInvitation());
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.opengtssettings);

    CheckBoxPreference chkEnabled = (CheckBoxPreference) findPreference("autoopengts_enabled");
    EditTextPreference txtOpenGTSServer = (EditTextPreference) findPreference("opengts_server");
    EditTextPreference txtOpenGTSServerPort =
        (EditTextPreference) findPreference("opengts_server_port");
    ListPreference txtOpenGTSCommunicationMethod =
        (ListPreference) findPreference("opengts_server_communication_method");
    EditTextPreference txtOpenGTSServerPath =
        (EditTextPreference) findPreference("autoopengts_server_path");
    EditTextPreference txtOpenGTSDeviceId =
        (EditTextPreference) findPreference("opengts_device_id");

    chkEnabled.setOnPreferenceChangeListener(this);
    txtOpenGTSServer.setOnPreferenceChangeListener(this);
    txtOpenGTSServerPort.setOnPreferenceChangeListener(this);
    txtOpenGTSCommunicationMethod.setOnPreferenceChangeListener(this);
    txtOpenGTSServerPath.setOnPreferenceChangeListener(this);
    txtOpenGTSDeviceId.setOnPreferenceChangeListener(this);
  }
Exemplo n.º 10
0
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.preference);

      final EditTextPreference defaultValuePreference =
          (EditTextPreference) getPreferenceScreen().findPreference("defaultValue");
      defaultValuePreference.setSummary(defaultValuePreference.getText());

      defaultValuePreference.setOnPreferenceChangeListener(
          new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
              defaultValuePreference.setSummary((String) newValue);
              return true;
            }
          });
    }
Exemplo n.º 11
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    EditTextPreference key = (EditTextPreference) findPreference("key");
    key.setSummary(prefs.getString("cellId", "0"));

    key.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            preference.setSummary((String) newValue);
            prefs.edit().putString("key", (String) newValue).commit();
            return false;
          }
        });
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.prefs_weather);

    prefs = getActivity().getSharedPreferences("weather", Context.MODE_PRIVATE);

    mWeatherSyncInterval = (ListPreference) findPreference("refresh_interval");
    mWeatherSyncInterval.setOnPreferenceChangeListener(this);
    mWeatherSyncInterval.setSummary(
        Integer.toString(WeatherPrefs.getRefreshInterval(mContext)) + " minutes");

    mCustomWeatherLoc = (EditTextPreference) findPreference("custom_location");
    mCustomWeatherLoc.setOnPreferenceChangeListener(this);
    mCustomWeatherLoc.setSummary(WeatherPrefs.getCustomLocation(mContext));

    mEnableWeather = (CheckBoxPreference) findPreference("enable_weather");
    mEnableWeather.setChecked(
        Settings.System.getInt(getContentResolver(), Settings.System.USE_WEATHER, 0) == 1);

    mUseCustomLoc = (CheckBoxPreference) findPreference(WeatherPrefs.KEY_USE_CUSTOM_LOCATION);
    mUseCustomLoc.setChecked(WeatherPrefs.getUseCustomLocation(mContext));

    mShowLoc = (CheckBoxPreference) findPreference("show_location");
    mShowLoc.setChecked(
        Settings.System.getInt(getContentResolver(), Settings.System.WEATHER_SHOW_LOCATION, 0)
            == 1);

    mUseCelcius = (CheckBoxPreference) findPreference(WeatherPrefs.KEY_USE_CELCIUS);
    mUseCelcius.setChecked(WeatherPrefs.getUseCelcius(mContext));

    setHasOptionsMenu(true);

    if (!Settings.Secure.isLocationProviderEnabled(
            getContentResolver(), LocationManager.NETWORK_PROVIDER)
        && !mUseCustomLoc.isChecked()) {
      showDialog(LOC_WARNING);
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {

    settings = getSharedPreferences("preferences", 0);

    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preferences);

    EditTextPreference Audiorepetitiontime =
        (EditTextPreference) findPreference("Audio_repetition_time");
    Audiorepetitiontime.setSummary(Audiorepetitiontime.getText());

    Audiorepetitiontime.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object o) {
            preference.setSummary(o.toString());
            // GetApplicationSettings();
            return true;
          };
        });
  }
Exemplo n.º 14
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.preferences);

    PreferenceScreen preferences = getPreferenceScreen();
    preferences.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    checkBoxPrefs =
        findDecodePrefs(
            preferences,
            PreferencesActivity.KEY_DECODE_1D_PRODUCT,
            PreferencesActivity.KEY_DECODE_1D_INDUSTRIAL,
            PreferencesActivity.KEY_DECODE_QR,
            PreferencesActivity.KEY_DECODE_DATA_MATRIX,
            PreferencesActivity.KEY_DECODE_AZTEC,
            PreferencesActivity.KEY_DECODE_PDF417);
    disableLastCheckedPref();

    EditTextPreference customProductSearch =
        (EditTextPreference)
            preferences.findPreference(PreferencesActivity.KEY_CUSTOM_PRODUCT_SEARCH);
    customProductSearch.setOnPreferenceChangeListener(new CustomSearchURLValidator());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.rcs_settings_userprofile_preferences);

    displaynameEdit = (EditTextPreference) findPreference("edit_displayname");
    displaynameEdit.setPersistent(false);
    displaynameEdit.setOnPreferenceChangeListener(this);

    if (!isServiceConnected(RcsServiceName.FILE_TRANSFER)) {
      showMessage(R.string.label_service_not_available);
      return;
    }

    try {
      String name = getContactApi().getCommonConfiguration().getMyDisplayName();
      displaynameEdit.setText(name);
      displaynameEdit.setTitle(name);

    } catch (RcsServiceException e) {
      showExceptionThenExit(e);
    }
  }
Exemplo n.º 16
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.repository_manager_prefs);

    repoInfo = getArguments().getParcelable(REPO_INFO);
    repoRequestDTO = getArguments().getParcelable(REQUEST_DTO);

    final EditTextPreference pref_repo_name = (EditTextPreference) findPreference("pref_repo_name");
    pref_repo_name.setTitle(repoRequestDTO.name);
    pref_repo_name.setText(repoRequestDTO.name);
    pref_repo_name.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            repoRequestDTO.name = (String) newValue;
            pref_repo_name.setTitle(repoRequestDTO.name);
            return true;
          }
        });

    Preference pref_repo_description = findPreference("pref_repo_description");
    pref_repo_description.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            Intent intent =
                ContentEditorActivity.createLauncherIntent(
                    getActivity(), repoInfo, 0, null, repoRequestDTO.description, true, true);
            startActivityForResult(intent, DESCRIPTION_EDIT);
            return false;
          }
        });

    final Preference pref_repo_url = findPreference("pref_repo_url");
    pref_repo_url.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            repoRequestDTO.homepage = (String) newValue;
            return false;
          }
        });

    CheckBoxPreference pref_repo_has_issues =
        (CheckBoxPreference) findPreference("pref_repo_has_issues");
    pref_repo_has_issues.setChecked(repoRequestDTO.has_issues);
    pref_repo_has_issues.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            repoRequestDTO.has_issues = (Boolean) newValue;
            return true;
          }
        });

    CheckBoxPreference pref_repo_has_wiki =
        (CheckBoxPreference) findPreference("pref_repo_has_wiki");
    pref_repo_has_wiki.setChecked(repoRequestDTO.has_wiki);
    pref_repo_has_wiki.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            repoRequestDTO.has_wiki = (Boolean) newValue;
            return true;
          }
        });

    CheckBoxPreference pref_repo_has_downloads =
        (CheckBoxPreference) findPreference("pref_repo_has_downloads");
    pref_repo_has_downloads.setChecked(repoRequestDTO.has_downloads);
    pref_repo_has_downloads.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            repoRequestDTO.has_downloads = (Boolean) newValue;
            return true;
          }
        });

    //        CheckBoxPreference pref_repo_is_private = (CheckBoxPreference)
    // findPreference("pref_repo_is_private");
    //        pref_repo_is_private.setChecked(repoRequestDTO.isPrivate);
    //        pref_repo_is_private.setOnPreferenceChangeListener(new
    // Preference.OnPreferenceChangeListener() {
    //            @Override
    //            public boolean onPreferenceChange(Preference preference, Object newValue) {
    //                repoRequestDTO.isPrivate = (Boolean) newValue;
    //                return true;
    //            }
    //        });

    pref_repo_default_branch = (ListPreference) findPreference("pref_repo_default_branch");
    pref_repo_default_branch.setTitle(repoRequestDTO.default_branch);
    pref_repo_default_branch.setEnabled(false);
    pref_repo_default_branch.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            repoRequestDTO.default_branch = (String) newValue;
            pref_repo_default_branch.setTitle((String) newValue);
            return true;
          }
        });

    getBranches();

    Preference pref_repo_delete = findPreference("pref_repo_delete");
    pref_repo_delete.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            checkDeleteRepository();
            return false;
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    setTitle(getString(R.string.app_name) + " > " + getString(R.string.general_preferences));

    // not super safe, but we're just putting in this mode to help administrate
    // would require code to access it
    boolean adminMode = getIntent().getBooleanExtra("adminMode", false);

    SharedPreferences adminPreferences =
        getSharedPreferences(AdminPreferencesActivity.ADMIN_PREFERENCES, 0);

    boolean serverAvailable =
        adminPreferences.getBoolean(AdminPreferencesActivity.KEY_CHANGE_SERVER, true);

    PreferenceCategory serverCategory =
        (PreferenceCategory) findPreference(getString(R.string.server_preferences));

    mServerUrlPreference = (EditTextPreference) findPreference(KEY_SERVER_URL);
    mServerUrlPreference.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            String url = newValue.toString();

            // remove all trailing "/"s
            while (url.endsWith("/")) {
              url = url.substring(0, url.length() - 1);
            }

            if (UrlUtils.isValidUrl(url)) {
              preference.setSummary(newValue.toString());
              return true;
            } else {
              Toast.makeText(getApplicationContext(), R.string.url_error, Toast.LENGTH_SHORT)
                  .show();
              return false;
            }
          }
        });
    mServerUrlPreference.setSummary(mServerUrlPreference.getText());
    mServerUrlPreference.getEditText().setFilters(new InputFilter[] {getReturnFilter()});

    if (!(serverAvailable || adminMode)) {
      Preference protocol = findPreference(KEY_PROTOCOL);
      serverCategory.removePreference(protocol);
      serverCategory.removePreference(mServerUrlPreference);

    } else {
      // this just removes the value from protocol, but protocol doesn't
      // exist if we take away access
      disableFeaturesInDevelopment();
    }

    mUsernamePreference = (EditTextPreference) findPreference(KEY_USERNAME);
    mUsernamePreference.setOnPreferenceChangeListener(this);
    mUsernamePreference.setSummary(mUsernamePreference.getText());
    mUsernamePreference.getEditText().setFilters(new InputFilter[] {getReturnFilter()});

    boolean usernameAvailable =
        adminPreferences.getBoolean(AdminPreferencesActivity.KEY_CHANGE_USERNAME, true);
    if (!(usernameAvailable || adminMode)) {
      serverCategory.removePreference(mUsernamePreference);
    }

    mPasswordPreference = (EditTextPreference) findPreference(KEY_PASSWORD);
    mPasswordPreference.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            String pw = newValue.toString();

            if (pw.length() > 0) {
              mPasswordPreference.setSummary("********");
            } else {
              mPasswordPreference.setSummary("");
            }
            return true;
          }
        });
    if (mPasswordPreference.getText() != null && mPasswordPreference.getText().length() > 0) {
      mPasswordPreference.setSummary("********");
    }
    mUsernamePreference.getEditText().setFilters(new InputFilter[] {getReturnFilter()});

    boolean passwordAvailable =
        adminPreferences.getBoolean(AdminPreferencesActivity.KEY_CHANGE_PASSWORD, true);
    if (!(passwordAvailable || adminMode)) {
      serverCategory.removePreference(mPasswordPreference);
    }

    //        mSelectedGoogleAccountPreference = (PreferenceScreen)
    // findPreference(KEY_SELECTED_GOOGLE_ACCOUNT);
    //        mSelectedGoogleAccountPreference
    //                .setOnPreferenceClickListener(new OnPreferenceClickListener() {
    //                    @Override
    //                    public boolean onPreferenceClick(Preference preference) {
    //                        Intent i = new Intent(getApplicationContext(), AccountList.class);
    //                        startActivity(i);
    //                        return true;
    //                    }
    //                });
    //        mSelectedGoogleAccountPreference.setSummary(mSelectedGoogleAccountPreference
    //                .getSharedPreferences().getString(KEY_ACCOUNT, ""));
    //        boolean googleAccounAvailable = adminPreferences.getBoolean(
    //                AdminPreferencesActivity.KEY_CHANGE_GOOGLE_ACCOUNT, true);
    //        if (!(googleAccounAvailable || adminMode)) {
    //            serverCategory.removePreference(mSelectedGoogleAccountPreference);
    //        }

    //        mFormListUrlPreference = (EditTextPreference) findPreference(KEY_FORMLIST_URL);
    //        mFormListUrlPreference.setOnPreferenceChangeListener(this);
    //        mFormListUrlPreference.setSummary(mFormListUrlPreference.getText());
    //        mServerUrlPreference.getEditText().setFilters(
    //                new InputFilter[] {
    //                        getReturnFilter(), getWhitespaceFilter()
    //                });
    //        if (!(serverAvailable || adminMode)) {
    //            serverCategory.removePreference(mFormListUrlPreference);
    //        }

    //        mSubmissionUrlPreference = (EditTextPreference) findPreference(KEY_SUBMISSION_URL);
    //        mSubmissionUrlPreference.setOnPreferenceChangeListener(this);
    //        mSubmissionUrlPreference.setSummary(mSubmissionUrlPreference.getText());
    //        mServerUrlPreference.getEditText().setFilters(
    //                new InputFilter[] {
    //                        getReturnFilter(), getWhitespaceFilter()
    //                });
    //        if (!(serverAvailable || adminMode)) {
    //            serverCategory.removePreference(mSubmissionUrlPreference);
    //        }
    //
    //        if (!(serverAvailable || usernameAvailable || passwordAvailable || adminMode)) {
    //            getPreferenceScreen().removePreference(serverCategory);
    //        }

    PreferenceCategory clientCategory =
        (PreferenceCategory) findPreference(getString(R.string.client));

    boolean fontAvailable =
        adminPreferences.getBoolean(AdminPreferencesActivity.KEY_CHANGE_FONT_SIZE, true);
    mFontSizePreference = (ListPreference) findPreference(KEY_FONT_SIZE);
    mFontSizePreference.setSummary(mFontSizePreference.getEntry());
    mFontSizePreference.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            int index = ((ListPreference) preference).findIndexOfValue(newValue.toString());
            String entry = (String) ((ListPreference) preference).getEntries()[index];
            ((ListPreference) preference).setSummary(entry);
            return true;
          }
        });
    if (!(fontAvailable || adminMode)) {
      clientCategory.removePreference(mFontSizePreference);
    }

    boolean defaultAvailable =
        adminPreferences.getBoolean(AdminPreferencesActivity.KEY_DEFAULT_TO_FINALIZED, true);

    Preference defaultFinalized = findPreference(KEY_COMPLETED_DEFAULT);
    if (!(defaultAvailable || adminMode)) {
      clientCategory.removePreference(defaultFinalized);
    }

    boolean splashAvailable =
        adminPreferences.getBoolean(AdminPreferencesActivity.KEY_SELECT_SPLASH_SCREEN, true);
    mSplashPathPreference = (PreferenceScreen) findPreference(KEY_SPLASH_PATH);
    mSplashPathPreference.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {

          private void launchImageChooser() {
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.setType("image/*");
            startActivityForResult(i, PreferencesActivity.IMAGE_CHOOSER);
          }

          @Override
          public boolean onPreferenceClick(Preference preference) {
            // if you have a value, you can clear it or select new.
            CharSequence cs = mSplashPathPreference.getSummary();
            if (cs != null && cs.toString().contains("/")) {

              final CharSequence[] items = {
                getString(R.string.select_another_image), getString(R.string.use_odk_default)
              };

              AlertDialog.Builder builder = new AlertDialog.Builder(PreferencesActivity.this);
              builder.setTitle(getString(R.string.change_splash_path));
              builder.setNeutralButton(
                  getString(R.string.cancel),
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                      dialog.dismiss();
                    }
                  });
              builder.setItems(
                  items,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int item) {
                      if (items[item].equals(getString(R.string.select_another_image))) {
                        launchImageChooser();
                      } else {
                        setSplashPath(getString(R.string.default_splash_path));
                      }
                    }
                  });
              AlertDialog alert = builder.create();
              alert.show();

            } else {
              launchImageChooser();
            }

            return true;
          }
        });

    if (!(splashAvailable || adminMode)) {
      clientCategory.removePreference(mSplashPathPreference);
    }

    boolean showSplashAvailable =
        adminPreferences.getBoolean(AdminPreferencesActivity.KEY_SHOW_SPLASH_SCREEN, true);

    CheckBoxPreference showSplashPreference = (CheckBoxPreference) findPreference(KEY_SHOW_SPLASH);

    if (!(showSplashAvailable || adminMode)) {
      clientCategory.removePreference(showSplashPreference);
    }

    if (!(fontAvailable
        || defaultAvailable
        || splashAvailable
        || showSplashAvailable
        || adminMode)) {
      getPreferenceScreen().removePreference(clientCategory);
    }
  }
Exemplo n.º 18
0
  /**
   * Set an alarm. Requires an Alarms.ALARM_ID to be passed in as an extra. FIXME: Pass an Alarm
   * object like every other Activity.
   */
  @Override
  protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Override the default content view.
    setContentView(R.layout.set_alarm);

    addPreferencesFromResource(R.xml.alarm_prefs);

    // Get each preference so we can retrieve the value later.
    mLabel = (EditTextPreference) findPreference("label");
    mLabel.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference p, Object newValue) {
            String val = (String) newValue;
            // Set the summary based on the new label.
            p.setSummary(val);
            if (val != null && !val.equals(mLabel.getText())) {
              // Call through to the generic listener.
              return SetAlarm.this.onPreferenceChange(p, newValue);
            }
            return true;
          }
        });
    mEnabledPref = (CheckBoxPreference) findPreference("enabled");
    mEnabledPref.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference p, Object newValue) {
            // Pop a toast when enabling alarms.
            if (!mEnabledPref.isChecked()) {
              popAlarmSetToast(SetAlarm.this, mHour, mMinutes, mRepeatPref.getDaysOfWeek());
            }
            return SetAlarm.this.onPreferenceChange(p, newValue);
          }
        });
    mTimePref = findPreference("time");
    mAlarmPref = (AlarmPreference) findPreference("alarm");
    mAlarmPref.setOnPreferenceChangeListener(this);
    mVibratePref = (CheckBoxPreference) findPreference("vibrate");
    mVibratePref.setOnPreferenceChangeListener(this);
    mRepeatPref = (RepeatPreference) findPreference("setRepeat");
    mRepeatPref.setOnPreferenceChangeListener(this);

    Intent i = getIntent();
    mId = i.getIntExtra(Alarms.ALARM_ID, -1);
    if (true) {
      Log.v("wangxianming", "In SetAlarm, alarm id = " + mId);
    }

    Alarm alarm = null;
    if (mId == -1) {
      // No alarm id means create a new alarm.
      alarm = new Alarm();
    } else {
      /* load alarm details from database */
      alarm = Alarms.getAlarm(getContentResolver(), mId);
      // Bad alarm, bail to avoid a NPE.
      if (alarm == null) {
        finish();
        return;
      }
    }
    mOriginalAlarm = alarm;

    updatePrefs(mOriginalAlarm);

    // We have to do this to get the save/cancel buttons to highlight on
    // their own.
    getListView().setItemsCanFocus(true);

    // Attach actions to each button.
    Button b = (Button) findViewById(R.id.alarm_save);
    b.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            saveAlarm();
            finish();
          }
        });
    final Button revert = (Button) findViewById(R.id.alarm_revert);
    revert.setEnabled(false);
    revert.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            int newId = mId;
            updatePrefs(mOriginalAlarm);
            // "Revert" on a newly created alarm should delete it.
            if (mOriginalAlarm.id == -1) {
              Alarms.deleteAlarm(SetAlarm.this, newId);
            } else {
              saveAlarm();
            }
            revert.setEnabled(false);
          }
        });
    b = (Button) findViewById(R.id.alarm_delete);
    if (mId == -1) {
      b.setEnabled(false);
    } else {
      b.setOnClickListener(
          new View.OnClickListener() {
            public void onClick(View v) {
              deleteAlarm();
            }
          });
    }

    // The last thing we do is pop the time picker if this is a new alarm.
    if (mId == -1) {
      // Assume the user hit cancel
      mTimePickerCancelled = true;
      showTimePicker();
    }
  }
 @Override
 protected void setUp() {
   final AccountManager accountManager = AccountManager.get(getActivity());
   final AccountMirakel accountMirakel = mItem;
   final Account account = accountMirakel.getAndroidAccount();
   // Preference Fields
   final Preference syncUsername = findPreference("syncUsername");
   final EditTextPreference syncServer = (EditTextPreference) findPreference("syncServer");
   final SwitchPreference syncUse = (SwitchPreference) findPreference("syncUse");
   final Preference syncType = findPreference("sync_type");
   final SwitchPreference defaultAccount = (SwitchPreference) findPreference("defaultAccount");
   final Preference syncInterval = findPreference("syncFrequency");
   // Set Preferences
   syncUsername.setEnabled(false);
   syncUsername.setSummary(accountMirakel.getName());
   // sync Server
   if (AccountMirakel.ACCOUNT_TYPES.TASKWARRIOR == accountMirakel.getType()) {
     syncServer.setEnabled(false);
     syncServer.setSummary(accountManager.getUserData(account, SyncAdapter.BUNDLE_SERVER_URL));
     syncServer.setText(accountManager.getUserData(account, SyncAdapter.BUNDLE_SERVER_URL));
     syncServer.setOnPreferenceChangeListener(
         new Preference.OnPreferenceChangeListener() {
           @Override
           public boolean onPreferenceChange(final Preference preference, final Object newValue) {
             accountManager.setUserData(account, SyncAdapter.BUNDLE_SERVER_URL, (String) newValue);
             syncServer.setSummary((String) newValue);
             syncServer.setText((String) newValue);
             return false;
           }
         });
   } else {
     syncServer.setEnabled(false);
     syncServer.setSummary("");
   }
   // sync use
   syncUse.setChecked(accountMirakel.isEnabled());
   syncUse.setOnPreferenceChangeListener(
       new Preference.OnPreferenceChangeListener() {
         @Override
         public boolean onPreferenceChange(final Preference preference, final Object newValue) {
           accountMirakel.setEnabled((Boolean) newValue);
           accountMirakel.save();
           return true;
         }
       });
   if (accountMirakel.getType() == AccountMirakel.ACCOUNT_TYPES.LOCAL) {
     removePreference("syncUse");
     removePreference("syncServer");
     removePreference("syncUsername");
   }
   // Sync type
   syncType.setSummary(accountMirakel.getType().typeName(getActivity()));
   // Default Account
   defaultAccount.setChecked(
       MirakelModelPreferences.getDefaultAccount().getId() == accountMirakel.getId());
   defaultAccount.setOnPreferenceChangeListener(
       new Preference.OnPreferenceChangeListener() {
         @Override
         public boolean onPreferenceChange(final Preference preference, final Object newValue) {
           if ((Boolean) newValue) {
             MirakelModelPreferences.setDefaultAccount(accountMirakel);
           } else {
             MirakelModelPreferences.setDefaultAccount(AccountMirakel.getLocal());
           }
           defaultAccount.setChecked((Boolean) newValue);
           return false;
         }
       });
   // Interval
   syncInterval.setEnabled(false);
   if (MirakelModelPreferences.getSyncFrequency(accountMirakel) == -1) {
     syncInterval.setSummary(R.string.sync_frequency_summary_man);
   } else {
     syncInterval.setSummary(
         this.getString(
             R.string.sync_frequency_summary,
             MirakelModelPreferences.getSyncFrequency(accountMirakel)));
   }
   syncInterval.setOnPreferenceClickListener(
       new Preference.OnPreferenceClickListener() {
         @Override
         public boolean onPreferenceClick(final Preference preference) {
           int hours = MirakelModelPreferences.getSyncFrequency(accountMirakel);
           if (hours == -1) {
             hours = 0;
           }
           final int minutes = hours % 60;
           hours = (int) Math.floor(hours / 60.);
           final TimePicker timePicker = new TimePicker(getActivity());
           timePicker.setIs24HourView(true);
           timePicker.setCurrentHour(hours);
           timePicker.setCurrentMinute(minutes);
           final AlertDialog.Builder dialog =
               new AlertDialog.Builder(getActivity())
                   .setTitle(R.string.sync_frequency)
                   .setView(timePicker)
                   .setPositiveButton(
                       android.R.string.ok,
                       new DialogInterface.OnClickListener() {
                         @Override
                         public void onClick(final DialogInterface dialog, final int which) {
                           int newValue =
                               timePicker.getCurrentHour() * 60 + timePicker.getCurrentMinute();
                           if (newValue == 0) {
                             newValue = -1;
                           }
                           final Bundle bundle = new Bundle();
                           if (newValue == -1) {
                             syncInterval.setSummary(R.string.sync_frequency_summary_man);
                           } else {
                             syncInterval.setSummary(
                                 getActivity()
                                     .getString(R.string.sync_frequency_summary, newValue));
                           }
                           if (accountMirakel != null) {
                             ContentResolver.removePeriodicSync(
                                 account, DefinitionsHelper.AUTHORITY_TYP, bundle);
                             if (newValue != -1) {
                               ContentResolver.setSyncAutomatically(
                                   account, DefinitionsHelper.AUTHORITY_TYP, true);
                               ContentResolver.setIsSyncable(
                                   account, DefinitionsHelper.AUTHORITY_TYP, 1);
                               ContentResolver.addPeriodicSync(
                                   account,
                                   DefinitionsHelper.AUTHORITY_TYP,
                                   bundle,
                                   newValue * 60);
                             }
                           } else {
                             Log.d(TAG, "account does not exsist");
                           }
                           MirakelModelPreferences.setSyncFrequency(accountMirakel, newValue);
                         }
                       });
           dialog.show();
           return false;
         }
       });
   if (accountMirakel.getType() != AccountMirakel.ACCOUNT_TYPES.TASKWARRIOR) {
     // we can control this only for tw
     removePreference("syncFrequency");
   } else {
     syncInterval.setEnabled(true);
   }
 }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    mPreferencePort =
        (EditTextPreference) findPreference(getResources().getString(R.string.pref_port_key));

    mPreferenceMaxClients =
        (EditTextPreference)
            findPreference(getResources().getString(R.string.pref_max_clients_key));
    mPreferenceExpirationCache =
        (EditTextPreference)
            findPreference(getResources().getString(R.string.pref_expiration_cache_key));

    mPreferenceWwwPath =
        (EditTextPreference) findPreference(getResources().getString(R.string.pref_www_path_key));

    mPreferenceErrorPath =
        (EditTextPreference) findPreference(getResources().getString(R.string.pref_error_path_key));

    mPreferenceLogPath =
        (EditTextPreference) findPreference(getResources().getString(R.string.pref_log_path_key));

    mPreferenceResetPref =
        (Preference) findPreference(getResources().getString(R.string.pref_reset_config_key));

    mPreferenceVibrate =
        (CheckBoxPreference) findPreference(getResources().getString(R.string.pref_vibrate_key));

    mPreferenceFileIndexing =
        (CheckBoxPreference) findPreference(getResources().getString(R.string.pref_vibrate_key));

    mPreferenceAutostartBoot =
        (CheckBoxPreference)
            findPreference(getResources().getString(R.string.pref_autostart_boot_key));

    mPreferenceAutostartWifi =
        (CheckBoxPreference)
            findPreference(getResources().getString(R.string.pref_autostart_wifi_key));
    mPreferenceAutostopWifi =
        (CheckBoxPreference)
            findPreference(getResources().getString(R.string.pref_autostop_wifi_key));

    mPreferenceShowNotification =
        (CheckBoxPreference)
            findPreference(getResources().getString(R.string.pref_show_notification_key));
    mPreferenceShowAds =
        (CheckBoxPreference) findPreference(getResources().getString(R.string.pref_show_ads_key));

    mPreferenceLogEntries =
        (ListPreference) findPreference(getResources().getString(R.string.pref_log_entries_key));

    mPreferenceAbout =
        (Preference) findPreference(getResources().getString(R.string.pref_about_key));

    mPreferenceFileIndexingGetTemplate =
        (Preference)
            findPreference(
                getResources().getString(R.string.pref_directory_indexing_get_template_key));

    mPreferenceReleaseNotes =
        (Preference) findPreference(getResources().getString(R.string.pref_release_notes_key));

    mPreferenceWwwPath.setText(AccessPreferences.getWwwPath());
    mPreferenceErrorPath.setText(AccessPreferences.getErrorPath());
    mPreferenceLogPath.setText(AccessPreferences.getLogPath());

    mPreferenceAutostartWifi.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {

            if (newValue instanceof Boolean) {
              boolean value = ((Boolean) newValue).booleanValue();
              if (value) {
                mPreferenceAutostartBoot.setEnabled(false);
                mPreferenceAutostopWifi.setEnabled(true);
              } else {
                mPreferenceAutostartBoot.setEnabled(true);
                // mPreferenceAutostopWifi.setChecked(false);
              }
            }
            return true;
          }
        });

    mPreferenceAutostartBoot.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {

            if (newValue instanceof Boolean) {
              boolean value = ((Boolean) newValue).booleanValue();
              if (value) {
                mPreferenceAutostartWifi.setEnabled(false);
                mPreferenceAutostopWifi.setEnabled(false);
              } else {
                mPreferenceAutostartWifi.setEnabled(true);
              }
            }
            return true;
          }
        });

    // Check the port
    mPreferencePort.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {

            try {
              int port = Integer.parseInt((String) newValue);
              if (port >= 65535 || port < 1) { // If you are not
                // root, you only
                // can until 1024
                return false;
              }
              if (port > 1 && port < 1024) { // check if it is
                // rooted
                if (ShellCommands.isIptablesExist()) {
                  if (!ShellCommands.isDeviceRooted()) {
                    Toast.makeText(
                            PreferencesActivity.this, R.string.no_su_permissions, Toast.LENGTH_LONG)
                        .show();
                    ;
                    return false;
                  }
                } else {
                  Toast.makeText(PreferencesActivity.this, R.string.no_iptables, Toast.LENGTH_LONG)
                      .show();
                  ;
                  return false;
                }
              }

            } catch (NumberFormatException e) {
              return false;
            }

            return true;
          }
        });

    // Check the max clients
    mPreferenceMaxClients.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          public boolean onPreferenceChange(Preference preference, Object newValue) {

            try {
              Integer.parseInt((String) newValue);

            } catch (NumberFormatException e) {
              return false;
            }

            return true;
          }
        });

    mPreferenceExpirationCache.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          public boolean onPreferenceChange(Preference preference, Object newValue) {

            try {
              Integer.parseInt((String) newValue);

            } catch (NumberFormatException e) {
              return false;
            }

            return true;
          }
        });

    // We check the path and create it if it does not exist
    mPreferenceWwwPath.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          public boolean onPreferenceChange(Preference preference, Object newValue) {

            return AccessPreferences.checkWwwPath((String) newValue);
          }
        });

    // We check the path and create it if it does not exist
    mPreferenceErrorPath.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          public boolean onPreferenceChange(Preference preference, Object newValue) {
            return AccessPreferences.checkErrorPath((String) newValue);
          }
        });

    // We check the path and create it if it does not exist
    mPreferenceLogPath.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          public boolean onPreferenceChange(Preference preference, Object newValue) {
            return AccessPreferences.checkLogPath((String) newValue);
          }
        });

    // Reset to default preferences
    mPreferenceResetPref.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {

          public boolean onPreferenceClick(Preference preference) {

            showResetDialog();

            return true;
          }
        });

    mPreferenceAbout.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {

          public boolean onPreferenceClick(Preference preference) {

            showAboutDialog();

            return true;
          }
        });

    mPreferenceFileIndexingGetTemplate.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {

          public boolean onPreferenceClick(Preference preference) {

            showDownloadTemplateDialog();

            return true;
          }
        });

    mPreferenceReleaseNotes.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {

          public boolean onPreferenceClick(Preference preference) {

            showReleaseNotesDialog();

            return true;
          }
        });

    mPreferenceShowAds.setEnabled(false);
  }
Exemplo n.º 21
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    CustomTitleBar titleBar =
        new CustomTitleBar(this, R.string.settings_activity, R.drawable.tab_settings_screen_icon);
    setTheme(R.style.CustomTitleTheme_Preference);
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings_pref);
    titleBar.afterSetContentView();

    String[] entries;
    String[] entrieValues;
    PreferenceScreen screen = getPreferenceScreen();
    osmandSettings = getMyApplication().getSettings();

    PreferenceCategory cat = (PreferenceCategory) screen.findPreference("global_app_settings");
    if (!Version.isBlackberry(this)) {
      CheckBoxPreference nativeCheckbox =
          createCheckBoxPreference(
              osmandSettings.SAFE_MODE, R.string.safe_mode, R.string.safe_mode_description);
      // disable the checkbox if the library cannot be used
      if ((NativeOsmandLibrary.isLoaded() && !NativeOsmandLibrary.isSupported())
          || osmandSettings.NATIVE_RENDERING_FAILED.get()) {
        nativeCheckbox.setEnabled(false);
        nativeCheckbox.setChecked(true);
      }
      cat.addPreference(nativeCheckbox);

      applicationDir = new EditTextPreference(this);
      applicationDir.setTitle(R.string.application_dir);
      applicationDir.setKey("external_storage_dir");
      applicationDir.setDialogTitle(R.string.application_dir);
      applicationDir.setOnPreferenceChangeListener(this);
      cat.addPreference(applicationDir);
    }

    //		BidForFixHelper bidForFixHelper = getMyApplication().getBidForFix();
    //		bidForFixHelper.generatePreferenceList(screen, getString(R.string.support_new_features),
    // this);
    OsmandPlugin.onSettingsActivityCreate(this, screen);

    registerBooleanPreference(osmandSettings.USE_ENGLISH_NAMES, screen);
    registerBooleanPreference(osmandSettings.AUTO_ZOOM_MAP, screen);
    registerBooleanPreference(osmandSettings.FAST_ROUTE_MODE, screen);
    registerBooleanPreference(osmandSettings.SNAP_TO_ROAD, screen);
    registerBooleanPreference(osmandSettings.USE_COMPASS_IN_NAVIGATION, screen);
    registerBooleanPreference(osmandSettings.LEFT_SIDE_NAVIGATION, screen);

    // List preferences
    //		registerListPreference(osmandSettings.ROTATE_MAP, screen,
    //				new String[]{getString(R.string.rotate_map_none_opt),
    // getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)},
    //				new Integer[]{OsmandSettings.ROTATE_MAP_NONE, OsmandSettings.ROTATE_MAP_BEARING,
    // OsmandSettings.ROTATE_MAP_COMPASS});

    registerListPreference(
        osmandSettings.MAP_SCREEN_ORIENTATION,
        screen,
        new String[] {
          getString(R.string.map_orientation_portrait),
          getString(R.string.map_orientation_landscape),
          getString(R.string.map_orientation_default)
        },
        new Integer[] {
          ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
          ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
          ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
        });

    MetricsConstants[] mvls =
        new MetricsConstants[] {
          MetricsConstants.KILOMETERS_AND_METERS,
          MetricsConstants.MILES_AND_FOOTS,
          MetricsConstants.MILES_AND_YARDS
        }; // MetricsConstants.values();
    entries = new String[mvls.length];
    for (int i = 0; i < entries.length; i++) {
      entries[i] = mvls[i].toHumanString(this);
    }
    registerListPreference(osmandSettings.METRIC_SYSTEM, screen, entries, mvls);

    // getResources().getAssets().getLocales();
    entrieValues =
        new String[] {
          "", "en", "af", "hy", "eu", "bs", "bg", "ca", "cs", "nl", "fi", "fr", "ka", "de", "el",
          "he", "hi", "hu", "id", "it", "ja", "ko", "lv", "lt", "mr", "no", "pl", "pt", "ro", "ru",
          "sk", "sl", "es", "sv", "uk", "vi"
        };
    entries =
        new String[] {
          getString(R.string.system_locale),
          "English",
          "Afrikaans",
          "Armenian",
          "Basque",
          "Bosnian",
          "Bulgarian",
          "Catalan",
          "Czech",
          "Dutch",
          "Finnish",
          "French",
          "Georgian",
          "German",
          "Greek",
          "Hebrew",
          "Hindi",
          "Hungarian",
          "Indonesian",
          "Italian",
          "Japanese",
          "Korean",
          "Latvian",
          "Lithuanian",
          "Marathi",
          "Norwegian",
          "Polish",
          "Portuguese",
          "Romanian",
          "Russian",
          "Slovak",
          "Slovenian",
          "Spanish",
          "Swedish",
          "Ukrainian",
          "Vietnamese"
        };
    registerListPreference(osmandSettings.PREFERRED_LOCALE, screen, entries, entrieValues);

    Integer[] intValues = new Integer[] {0, 5, 10, 15, 20, 25, 30, 45, 60, 90};
    entries = new String[intValues.length];
    entries[0] = getString(R.string.auto_follow_route_never);
    for (int i = 1; i < intValues.length; i++) {
      entries[i] = (int) intValues[i] + " " + getString(R.string.int_seconds);
    }
    registerListPreference(osmandSettings.AUTO_FOLLOW_ROUTE, screen, entries, intValues);

    entries = new String[RouteService.values().length];
    for (int i = 0; i < entries.length; i++) {
      entries[i] = RouteService.values()[i].getName();
    }
    registerListPreference(osmandSettings.ROUTER_SERVICE, screen, entries, RouteService.values());

    //		entries = new String[ApplicationMode.values().length];
    //		for(int i=0; i<entries.length; i++){
    //			entries[i] = ApplicationMode.values()[i].toHumanString(this);
    //		}
    //		registerListPreference(osmandSettings.APPLICATION_MODE, screen, entries,
    // ApplicationMode.values());
    //
    //		applicationModePreference = (ListPreference)
    // screen.findPreference(osmandSettings.APPLICATION_MODE.getId());
    //		applicationModePreference.setOnPreferenceChangeListener(this);

    routerServicePreference =
        (ListPreference) screen.findPreference(osmandSettings.ROUTER_SERVICE.getId());
    routerServicePreference.setOnPreferenceChangeListener(this);

    Preference localIndexes = (Preference) screen.findPreference(OsmandSettings.LOCAL_INDEXES);
    localIndexes.setOnPreferenceClickListener(this);
    bidforfix = (Preference) screen.findPreference("bidforfix");
    bidforfix.setOnPreferenceClickListener(this);
    plugins = (Preference) screen.findPreference("plugins");
    plugins.setOnPreferenceClickListener(this);
    avoidRouting = (Preference) screen.findPreference("avoid_in_routing");
    avoidRouting.setOnPreferenceClickListener(this);
    showAlarms = (Preference) screen.findPreference("show_routing_alarms");
    showAlarms.setOnPreferenceClickListener(this);

    Intent intent = getIntent();
    if (intent != null && intent.getIntExtra(INTENT_KEY_SETTINGS_SCREEN, 0) != 0) {
      int s = intent.getIntExtra(INTENT_KEY_SETTINGS_SCREEN, 0);
      String pref = null;
      if (s == SCREEN_GENERAL_SETTINGS) {
        pref = SCREEN_ID_GENERAL_SETTINGS;
      } else if (s == SCREEN_NAVIGATION_SETTINGS) {
        pref = SCREEN_ID_NAVIGATION_SETTINGS;
      }
      if (pref != null) {
        Preference toOpen = screen.findPreference(pref);
        if (toOpen instanceof PreferenceScreen) {
          setPreferenceScreen((PreferenceScreen) toOpen);
        }
      }
    }
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    sharedPreferences = getPreferenceScreen().getSharedPreferences();

    hostPref = (EditTextPreference) getPreferenceScreen().findPreference("host");
    portPref = (EditTextPreference) getPreferenceScreen().findPreference("port");
    passPref = (EditTextPreference) getPreferenceScreen().findPreference("password");
    textSizePref = (EditTextPreference) getPreferenceScreen().findPreference("text_size");
    timestampformatPref =
        (EditTextPreference) getPreferenceScreen().findPreference("timestamp_format");
    timestampformatPref.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object pattern) {
            try {
              new SimpleDateFormat((String) pattern);
            } catch (IllegalArgumentException e) {
              Toast.makeText(
                      WeechatPreferencesActivity.this,
                      R.string.pref_timestamp_invalid,
                      Toast.LENGTH_SHORT)
                  .show();
              return false;
            }

            return true;
          }
        });
    stunnelCert = (EditTextPreference) getPreferenceScreen().findPreference("stunnel_cert");
    stunnelPass = (EditTextPreference) getPreferenceScreen().findPreference("stunnel_pass");

    sshHostPref = (EditTextPreference) getPreferenceScreen().findPreference("ssh_host");
    sshUserPref = (EditTextPreference) getPreferenceScreen().findPreference("ssh_user");
    sshPortPref = (EditTextPreference) getPreferenceScreen().findPreference("ssh_port");
    sshPassPref = (EditTextPreference) getPreferenceScreen().findPreference("ssh_pass");
    sshKeyFilePref = (EditTextPreference) getPreferenceScreen().findPreference("ssh_keyfile");

    prefixPref = (ListPreference) getPreferenceScreen().findPreference("prefix_align");
    Preference prefixWidthPref = getPreferenceScreen().findPreference("prefix_max_width");
    prefixWidthPref.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            try {
              Integer.parseInt((String) newValue);
            } catch (IllegalArgumentException e) {
              Toast.makeText(
                      WeechatPreferencesActivity.this,
                      R.string.pref_prefix_width_invalid,
                      Toast.LENGTH_SHORT)
                  .show();
              return false;
            }

            return true;
          }
        });
    connectionTypePref = (ListPreference) getPreferenceScreen().findPreference("connection_type");
    setTitle(R.string.preferences);
  }
Exemplo n.º 23
0
 public void registerEditTextPreference(OsmandPreference<String> b, PreferenceScreen screen) {
   EditTextPreference p = (EditTextPreference) screen.findPreference(b.getId());
   p.setOnPreferenceChangeListener(this);
   screenPreferences.put(b.getId(), p);
   editTextPreferences.put(b.getId(), b);
 }
Exemplo n.º 24
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settingsactivity);
    addPreferencesFromResource(R.xml.preferences);
    AnalyticsApplication application = (AnalyticsApplication) getApplication();
    tracker = application.getDefaultTracker();
    tracker.setScreenName("Settings");
    tracker.send(new HitBuilders.ScreenViewBuilder().build());
    final SharedPreferences sharedpreferences =
        getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
    final ListPreference columns = (ListPreference) findPreference("columns");
    final ListPreference background = (ListPreference) findPreference("backgroundpreference");
    final EditTextPreference editTextPreference = (EditTextPreference) findPreference("rows");
    editTextPreference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
    editTextPreference.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object o) {
            MainActivity.m_size_changed = true;
            return true;
          }
        });
    if (sharedpreferences.getString("adpreference", "Full").equals("None")) {
      Log.v("adpreference", "destroy");
      View adfragment = findViewById(R.id.ad_fragmentsettings);
      adfragment.setVisibility(View.INVISIBLE);
    } else {
      Log.v("adpreference", "Not destroy" + sharedpreferences.getString("adpreference", "Full"));
      AdView adView = (AdView) findViewById(R.id.adView);
      AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
      adView.loadAd(adRequestBuilder.build());
    }

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);

    int maxcolumns = Math.max(Math.round(Math.min(size.x, size.y) / 154) - 2, 2);

    String[] entries = new String[maxcolumns];
    for (int i = 0; i < maxcolumns; i++) entries[i] = Integer.toString(i + 3);
    columns.setEntries(entries);
    columns.setDefaultValue(entries[0]);
    columns.setEntryValues(entries);
    columns.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object o) {
            MainActivity.m_size_changed = true;
            return true;
          }
        });
    background.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object o) {
            MainActivity.m_background_changed = true;
            return true;
          }
        });
    ListPreference ads = (ListPreference) findPreference("adpreference");
    defaultvalue = sharedpreferences.getString("adpreference", "Full");
    ads.setDefaultValue(defaultvalue);
    ads.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object o) {
            MainActivity.m_ads_changed = true;
            String status = sharedpreferences.getString("adpreference", "Full");
            SharedPreferences.Editor mEdit1 = sharedpreferences.edit();
            mEdit1.putString("adpreference", (String) o);
            mEdit1.apply();
            String statusafter = sharedpreferences.getString("adpreference", "Full");
            if (statusafter.equals("None") && !(status.equals("None"))) {
              View adfragment = findViewById(R.id.ad_fragmentsettings);
              adfragment.setVisibility(View.INVISIBLE);
            }
            if (!(statusafter.equals("None")) && status.equals("None")) {
              AdView adView = (AdView) findViewById(R.id.adView);
              View adfragment = findViewById(R.id.ad_fragmentsettings);
              adfragment.setVisibility(View.VISIBLE);
              AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
              adView.loadAd(adRequestBuilder.build());
            }
            Log.v("adpreference", statusafter);
            return true;
          }
        });
  }
Exemplo n.º 25
0
  private void initUI() {
    mLanguagePref = (ListPreference) findPreference(SpeechConstant.LANGUAGE);
    mCategoryPref = (ListPreference) findPreference(SpeechConstant.ISE_CATEGORY);
    mResultLevelPref = (ListPreference) findPreference(SpeechConstant.RESULT_LEVEL);
    mVadBosPref = (EditTextPreference) findPreference(SpeechConstant.VAD_BOS);
    mVadEosPref = (EditTextPreference) findPreference(SpeechConstant.VAD_EOS);
    mSpeechTimeoutPref = (EditTextPreference) findPreference(SpeechConstant.KEY_SPEECH_TIMEOUT);

    mToast = Toast.makeText(IseSettings.this, "", Toast.LENGTH_LONG);

    mLanguagePref.setSummary("当前:" + mLanguagePref.getEntry());
    mCategoryPref.setSummary("当前:" + mCategoryPref.getEntry());
    mResultLevelPref.setSummary("当前:" + mResultLevelPref.getEntry());
    mVadBosPref.setSummary("当前:" + mVadBosPref.getText() + "ms");
    mVadEosPref.setSummary("当前:" + mVadEosPref.getText() + "ms");

    String speech_timeout = mSpeechTimeoutPref.getText();
    String summary = "当前:" + speech_timeout;
    if (!"-1".equals(speech_timeout)) {
      summary += "ms";
    }
    mSpeechTimeoutPref.setSummary(summary);

    mLanguagePref.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            if ("zh_cn".equals(newValue.toString())) {
              if ("plain".equals(mResultLevelPref.getValue())) {
                showTip("汉语评测结果格式不支持plain设置");
                return false;
              }
            } else {
              if ("read_syllable".equals(mCategoryPref.getValue())) {
                showTip("英语评测不支持单字");
                return false;
              }
            }

            int newValueIndex = mLanguagePref.findIndexOfValue(newValue.toString());
            String newEntry = (String) mLanguagePref.getEntries()[newValueIndex];
            mLanguagePref.setSummary("当前:" + newEntry);
            return true;
          }
        });

    mCategoryPref.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            if ("en_us".equals(mLanguagePref.getValue())
                && "read_syllable".equals(newValue.toString())) {
              showTip("英语评测不支持单字,请选其他项");
              return false;
            }

            int newValueIndex = mCategoryPref.findIndexOfValue(newValue.toString());
            String newEntry = (String) mCategoryPref.getEntries()[newValueIndex];
            mCategoryPref.setSummary("当前:" + newEntry);
            return true;
          }
        });

    mResultLevelPref.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            if ("zh_cn".equals(mLanguagePref.getValue()) && "plain".equals(newValue.toString())) {
              showTip("汉语评测不支持plain,请选其他项");
              return false;
            }

            mResultLevelPref.setSummary("当前:" + newValue.toString());
            return true;
          }
        });

    mVadBosPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
    mVadBosPref.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            int bos;
            try {
              bos = Integer.parseInt(newValue.toString());
            } catch (Exception e) {
              showTip("无效输入!");
              return false;
            }
            if (bos < 0 || bos > 30000) {
              showTip("取值范围为0~30000");
              return false;
            }

            mVadBosPref.setSummary("当前:" + bos + "ms");
            return true;
          }
        });

    mVadEosPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
    mVadEosPref.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            int eos;
            try {
              eos = Integer.parseInt(newValue.toString());
            } catch (Exception e) {
              showTip("无效输入!");
              return false;
            }
            if (eos < 0 || eos > 30000) {
              showTip("取值范围为0~30000");
              return false;
            }

            mVadEosPref.setSummary("当前:" + eos + "ms");
            return true;
          }
        });

    mSpeechTimeoutPref
        .getEditText()
        .setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_CLASS_NUMBER);
    mSpeechTimeoutPref.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            int speech_timeout;
            try {
              speech_timeout = Integer.parseInt(newValue.toString());
            } catch (Exception e) {
              showTip("无效输入!");
              return false;
            }

            if (speech_timeout < -1) {
              showTip("必须大于等于-1");
              return false;
            }

            if (speech_timeout == -1) {
              mSpeechTimeoutPref.setSummary("当前:-1");
            } else {
              mSpeechTimeoutPref.setSummary("当前:" + speech_timeout + "ms");
            }

            return true;
          }
        });
  }
Exemplo n.º 26
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings_pref);
    String[] entries;
    String[] entrieValues;
    PreferenceScreen screen = getPreferenceScreen();
    osmandSettings = OsmandSettings.getOsmandSettings(this);

    registerBooleanPreference(osmandSettings.SHOW_VIEW_ANGLE, screen);
    registerBooleanPreference(osmandSettings.USE_TRACKBALL_FOR_MOVEMENTS, screen);
    registerBooleanPreference(osmandSettings.USE_HIGH_RES_MAPS, screen);
    registerBooleanPreference(osmandSettings.USE_ENGLISH_NAMES, screen);
    registerBooleanPreference(osmandSettings.SHOW_MORE_MAP_DETAIL, screen);
    registerBooleanPreference(osmandSettings.AUTO_ZOOM_MAP, screen);
    registerBooleanPreference(osmandSettings.SAVE_TRACK_TO_GPX, screen);
    registerBooleanPreference(osmandSettings.DEBUG_RENDERING_INFO, screen);
    registerBooleanPreference(osmandSettings.USE_STEP_BY_STEP_RENDERING, screen);
    registerBooleanPreference(osmandSettings.FAST_ROUTE_MODE, screen);
    registerBooleanPreference(osmandSettings.USE_OSMAND_ROUTING_SERVICE_ALWAYS, screen);
    registerBooleanPreference(osmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, screen);
    registerBooleanPreference(osmandSettings.MAP_VECTOR_DATA, screen);

    registerEditTextPreference(osmandSettings.USER_NAME, screen);
    registerEditTextPreference(osmandSettings.USER_PASSWORD, screen);

    registerSeekBarPreference(osmandSettings.MAP_OVERLAY_TRANSPARENCY, screen);
    registerSeekBarPreference(osmandSettings.MAP_TRANSPARENCY, screen);

    // List preferences
    registerListPreference(
        osmandSettings.ROTATE_MAP,
        screen,
        new String[] {
          getString(R.string.rotate_map_none_opt),
          getString(R.string.rotate_map_bearing_opt),
          getString(R.string.rotate_map_compass_opt)
        },
        new Integer[] {
          OsmandSettings.ROTATE_MAP_NONE,
          OsmandSettings.ROTATE_MAP_BEARING,
          OsmandSettings.ROTATE_MAP_COMPASS
        });

    registerListPreference(
        osmandSettings.MAP_SCREEN_ORIENTATION,
        screen,
        new String[] {
          getString(R.string.map_orientation_portrait),
          getString(R.string.map_orientation_landscape),
          getString(R.string.map_orientation_default)
        },
        new Integer[] {
          ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
          ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
          ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
        });

    registerListPreference(
        osmandSettings.POSITION_ON_MAP,
        screen,
        new String[] {
          getString(R.string.position_on_map_center), getString(R.string.position_on_map_bottom)
        },
        new Integer[] {OsmandSettings.CENTER_CONSTANT, OsmandSettings.BOTTOM_CONSTANT});

    registerListPreference(
        osmandSettings.AUDIO_STREAM_GUIDANCE,
        screen,
        new String[] {
          getString(R.string.voice_stream_music),
          getString(R.string.voice_stream_notification),
          getString(R.string.voice_stream_voice_call)
        },
        new Integer[] {
          AudioManager.STREAM_MUSIC,
          AudioManager.STREAM_NOTIFICATION,
          AudioManager.STREAM_VOICE_CALL
        });

    entries = new String[DayNightMode.values().length];
    for (int i = 0; i < entries.length; i++) {
      entries[i] = DayNightMode.values()[i].toHumanString(this);
    }
    registerListPreference(osmandSettings.DAYNIGHT_MODE, screen, entries, DayNightMode.values());

    entries = new String[MetricsConstants.values().length];
    for (int i = 0; i < entries.length; i++) {
      entries[i] = MetricsConstants.values()[i].toHumanString(this);
    }
    registerListPreference(
        osmandSettings.METRIC_SYSTEM, screen, entries, MetricsConstants.values());

    // getResources().getAssets().getLocales();
    entrieValues = new String[] {"", "en", "cs", "de", "es", "fr", "hu", "it", "pt", "ru", "sk"};
    entries = new String[entrieValues.length];
    entries[0] = getString(R.string.system_locale);
    for (int i = 1; i < entries.length; i++) {
      entries[i] = entrieValues[i];
    }
    registerListPreference(osmandSettings.PREFERRED_LOCALE, screen, entries, entrieValues);

    int startZoom = 12;
    int endZoom = 19;
    entries = new String[endZoom - startZoom + 1];
    Integer[] intValues = new Integer[endZoom - startZoom + 1];
    for (int i = startZoom; i <= endZoom; i++) {
      entries[i - startZoom] = i + ""; // $NON-NLS-1$
      intValues[i - startZoom] = i;
    }
    registerListPreference(osmandSettings.MAX_LEVEL_TO_DOWNLOAD_TILE, screen, entries, intValues);

    Float[] floatValues = new Float[] {0.6f, 0.8f, 1.0f, 1.2f, 1.5f};
    entries = new String[floatValues.length];
    for (int i = 0; i < floatValues.length; i++) {
      entries[i] = (int) (floatValues[i] * 100) + " %";
    }
    registerListPreference(osmandSettings.MAP_TEXT_SIZE, screen, entries, floatValues);

    startZoom = 1;
    endZoom = 18;
    entries = new String[endZoom - startZoom + 1];
    intValues = new Integer[endZoom - startZoom + 1];
    for (int i = startZoom; i <= endZoom; i++) {
      entries[i - startZoom] = i + ""; // $NON-NLS-1$
      intValues[i - startZoom] = i;
    }
    registerListPreference(
        osmandSettings.LEVEL_TO_SWITCH_VECTOR_RASTER, screen, entries, intValues);

    entries = new String[RouteService.values().length];
    for (int i = 0; i < entries.length; i++) {
      entries[i] = RouteService.values()[i].getName();
    }
    registerListPreference(osmandSettings.ROUTER_SERVICE, screen, entries, RouteService.values());

    entries = new String[] {getString(R.string.gps_provider), getString(R.string.network_provider)};
    entrieValues = new String[] {LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER};
    registerListPreference(osmandSettings.SERVICE_OFF_PROVIDER, screen, entries, entrieValues);

    registerTimeListPreference(
        osmandSettings.SAVE_TRACK_INTERVAL,
        screen,
        new int[] {1, 2, 3, 5, 10, 15, 20, 30},
        new int[] {1, 2, 3, 5},
        1);
    registerTimeListPreference(
        osmandSettings.SERVICE_OFF_INTERVAL,
        screen,
        new int[] {0, 30, 45, 60},
        new int[] {2, 3, 5, 8, 10, 15, 20, 30, 40, 50, 70, 90},
        1000);
    registerTimeListPreference(
        osmandSettings.SERVICE_OFF_WAIT_INTERVAL,
        screen,
        new int[] {15, 30, 45, 60, 90},
        new int[] {2, 3, 5, 10},
        1000);

    entries = new String[ApplicationMode.values().length];
    for (int i = 0; i < entries.length; i++) {
      entries[i] = ApplicationMode.toHumanString(ApplicationMode.values()[i], this);
    }
    registerListPreference(
        osmandSettings.APPLICATION_MODE, screen, entries, ApplicationMode.values());

    Collection<String> rendererNames = getMyApplication().getRendererRegistry().getRendererNames();
    entries = (String[]) rendererNames.toArray(new String[rendererNames.size()]);
    registerListPreference(osmandSettings.RENDERER, screen, entries, entries);

    tileSourcePreference =
        (ListPreference) screen.findPreference(osmandSettings.MAP_TILE_SOURCES.getId());
    tileSourcePreference.setOnPreferenceChangeListener(this);
    overlayPreference = (ListPreference) screen.findPreference(osmandSettings.MAP_OVERLAY.getId());
    overlayPreference.setOnPreferenceChangeListener(this);
    underlayPreference =
        (ListPreference) screen.findPreference(osmandSettings.MAP_UNDERLAY.getId());
    underlayPreference.setOnPreferenceChangeListener(this);

    Preference localIndexes = (Preference) screen.findPreference(OsmandSettings.LOCAL_INDEXES);
    localIndexes.setOnPreferenceClickListener(this);
    saveCurrentTrack = (Preference) screen.findPreference(OsmandSettings.SAVE_CURRENT_TRACK);
    saveCurrentTrack.setOnPreferenceClickListener(this);
    routeServiceEnabled =
        (CheckBoxPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_ENABLED);
    routeServiceEnabled.setOnPreferenceChangeListener(this);
    applicationDir =
        (EditTextPreference) screen.findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR);
    applicationDir.setOnPreferenceChangeListener(this);

    broadcastReceiver =
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            routeServiceEnabled.setChecked(false);
          }
        };
    registerReceiver(
        broadcastReceiver, new IntentFilter(NavigationService.OSMAND_STOP_SERVICE_ACTION));

    Intent intent = getIntent();
    if (intent != null && intent.getIntExtra(INTENT_KEY_SETTINGS_SCREEN, 0) != 0) {
      int s = intent.getIntExtra(INTENT_KEY_SETTINGS_SCREEN, 0);
      String pref = null;
      if (s == SCREEN_GENERAL_SETTINGS) {
        pref = "general_settings";
      } else if (s == SCREEN_NAVIGATION_SETTINGS) {
        pref = "routing_settings";
      } else if (s == SCREEN_MONITORING_SETTINGS) {
        pref = "monitor_settings";
      }
      if (pref != null) {
        Preference toOpen = screen.findPreference(pref);
        if (toOpen instanceof PreferenceScreen) {
          setPreferenceScreen((PreferenceScreen) toOpen);
        }
      }
    }
  }
  private void getPreference() {
    try {
      mchk_autostart.setChecked(UAVPreferenceManager.GetAutoStart(getApplication()));
    } catch (Exception e) {
      return;
    }
    mchk_autostart.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference arg0) {
            // TODO Auto-generated method stub
            UAVPreferenceManager.SetAutoStart(
                getApplication(), ((CheckBoxPreference) arg0).isChecked());
            return false;
          }
        });

    mtxt_VehicleName.setText(UAVPreferenceManager.GetVehicleName(getApplication()));
    mtxt_VehicleName.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference arg0, Object newValue) {
            // TODO Auto-generated method stub

            if (((String) newValue).length() > 0) {
              UAVPreferenceManager.SetVehicleName(getApplication(), (String) newValue);

              return true;
            } else {

              return false;
            }
          }
        });

    mtxt_UAVProtocolPort.setText(UAVPreferenceManager.GetUAVProtocolPort(getApplication()));
    mtxt_UAVProtocolPort.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference arg0, Object newValue) {
            // TODO Auto-generated method stub
            try {
              Integer.parseInt((String) newValue);
              UAVPreferenceManager.SetUAVProtocolPort(getApplication(), (String) newValue);

              return true;
            } catch (NumberFormatException nfe) {
              return false;
            }
          }
        });

    mtxt_ProtocolPort.setText(UAVPreferenceManager.GetIDProtocolPort(getApplication()));
    mtxt_ProtocolPort.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference arg0, Object newValue) {
            // TODO Auto-generated method stub
            try {
              Integer.parseInt((String) newValue);
              UAVPreferenceManager.SetIDProtocolPort(getApplication(), (String) newValue);

              return true;
            } catch (NumberFormatException nfe) {
              return false;
            }
          }
        });

    mtxtFlightGearPort_In.setText(UAVPreferenceManager.GetFlightGearPort_In(getApplication()));
    mtxtFlightGearPort_In.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference arg0, Object newValue) {
            // TODO Auto-generated method stub
            try {
              Integer.parseInt((String) newValue);
              UAVPreferenceManager.SetFlightGearPort_In(getApplication(), (String) newValue);

              return true;
            } catch (NumberFormatException nfe) {
              return false;
            }
          }
        });

    mtxtFlightGearPort_Out.setText(UAVPreferenceManager.GetFlightGearPort_Out(getApplication()));
    mtxtFlightGearPort_Out.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference arg0, Object newValue) {
            // TODO Auto-generated method stub
            try {
              Integer.parseInt((String) newValue);
              UAVPreferenceManager.SetFlightGearPort_Out(getApplication(), (String) newValue);

              return true;
            } catch (NumberFormatException nfe) {
              return false;
            }
          }
        });
  }
Exemplo n.º 28
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*
     * Read preferences resources available at res/xml/preferences.xml
     */
    addPreferencesFromResource(R.xml.preferences);

    checkGps();

    ArrayList<CharSequence> pairedDeviceStrings = new ArrayList<>();
    ArrayList<CharSequence> vals = new ArrayList<>();
    ListPreference listBtDevices =
        (ListPreference) getPreferenceScreen().findPreference(BLUETOOTH_LIST_KEY);
    ArrayList<CharSequence> protocolStrings = new ArrayList<>();
    ListPreference listProtocols =
        (ListPreference) getPreferenceScreen().findPreference(PROTOCOLS_LIST_KEY);
    String[] prefKeys =
        new String[] {
          ENGINE_DISPLACEMENT_KEY,
          VOLUMETRIC_EFFICIENCY_KEY,
          OBD_UPDATE_PERIOD_KEY,
          MAX_FUEL_ECON_KEY
        };
    for (String prefKey : prefKeys) {
      EditTextPreference txtPref =
          (EditTextPreference) getPreferenceScreen().findPreference(prefKey);
      txtPref.setOnPreferenceChangeListener(this);
    }

    /*
     * Available OBD commands
     *
     * TODO This should be read from preferences database
     */
    ArrayList<ObdCommand> cmds = ObdConfig.getCommands();
    PreferenceScreen cmdScr =
        (PreferenceScreen) getPreferenceScreen().findPreference(COMMANDS_SCREEN_KEY);
    for (ObdCommand cmd : cmds) {
      CheckBoxPreference cpref = new CheckBoxPreference(this);
      cpref.setTitle(cmd.getName());
      cpref.setKey(cmd.getName());
      cpref.setChecked(true);
      cmdScr.addPreference(cpref);
    }

    /*
     * Available OBD protocols
     *
     */
    for (ObdProtocols protocol : ObdProtocols.values()) {
      protocolStrings.add(protocol.name());
    }
    listProtocols.setEntries(protocolStrings.toArray(new CharSequence[0]));
    listProtocols.setEntryValues(protocolStrings.toArray(new CharSequence[0]));

    /*
     * Let's use this device Bluetooth adapter to select which paired OBD-II
     * compliant device we'll use.
     */
    final BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBtAdapter == null) {
      listBtDevices.setEntries(pairedDeviceStrings.toArray(new CharSequence[0]));
      listBtDevices.setEntryValues(vals.toArray(new CharSequence[0]));

      // we shouldn't get here, still warn user
      Toast.makeText(this, "This device does not support Bluetooth.", Toast.LENGTH_LONG).show();

      return;
    }

    /*
     * Listen for preferences click.
     *
     * TODO there are so many repeated validations :-/
     */
    final Activity thisActivity = this;
    listBtDevices.setEntries(new CharSequence[1]);
    listBtDevices.setEntryValues(new CharSequence[1]);
    listBtDevices.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          public boolean onPreferenceClick(Preference preference) {
            // see what I mean in the previous comment?
            if (mBtAdapter == null || !mBtAdapter.isEnabled()) {
              Toast.makeText(
                      thisActivity,
                      "This device does not support Bluetooth or it is disabled.",
                      Toast.LENGTH_LONG)
                  .show();
              return false;
            }
            return true;
          }
        });

    /*
     * Get paired devices and populate preference list.
     */
    Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();
    if (pairedDevices.size() > 0) {
      for (BluetoothDevice device : pairedDevices) {
        pairedDeviceStrings.add(device.getName() + "\n" + device.getAddress());
        vals.add(device.getAddress());
      }
    }
    listBtDevices.setEntries(pairedDeviceStrings.toArray(new CharSequence[0]));
    listBtDevices.setEntryValues(vals.toArray(new CharSequence[0]));
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    sharedPreferences = getPreferenceScreen().getSharedPreferences();

    connectionSettings =
        (PreferenceScreen) getPreferenceScreen().findPreference("connection_group");
    hostPref = (EditTextPreference) getPreferenceScreen().findPreference("host");
    portPref = (EditTextPreference) getPreferenceScreen().findPreference("port");
    passPref = (EditTextPreference) getPreferenceScreen().findPreference("password");
    textSizePref = (EditTextPreference) getPreferenceScreen().findPreference("text_size");
    bufferFontPref = (FontPreference) getPreferenceScreen().findPreference("buffer_font");
    timestampformatPref =
        (EditTextPreference) getPreferenceScreen().findPreference("timestamp_format");
    timestampformatPref.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object pattern) {
            try {
              new SimpleDateFormat((String) pattern);
            } catch (IllegalArgumentException e) {
              Toast.makeText(
                      WeechatPreferencesActivity.this,
                      R.string.pref_timestamp_invalid,
                      Toast.LENGTH_SHORT)
                  .show();
              return false;
            }

            return true;
          }
        });
    stunnelCert = (EditTextPreference) getPreferenceScreen().findPreference("stunnel_cert");
    stunnelPass = (EditTextPreference) getPreferenceScreen().findPreference("stunnel_pass");

    sshHostPref = (EditTextPreference) getPreferenceScreen().findPreference("ssh_host");
    sshUserPref = (EditTextPreference) getPreferenceScreen().findPreference("ssh_user");
    sshPortPref = (EditTextPreference) getPreferenceScreen().findPreference("ssh_port");
    sshPassPref = (EditTextPreference) getPreferenceScreen().findPreference("ssh_pass");
    sshKeyFilePref = (EditTextPreference) getPreferenceScreen().findPreference("ssh_keyfile");

    prefixPref = (ListPreference) getPreferenceScreen().findPreference("prefix_align");
    Preference prefixWidthPref = getPreferenceScreen().findPreference("prefix_max_width");
    prefixWidthPref.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            try {
              Integer.parseInt((String) newValue);
            } catch (IllegalArgumentException e) {
              Toast.makeText(
                      WeechatPreferencesActivity.this,
                      R.string.pref_prefix_width_invalid,
                      Toast.LENGTH_SHORT)
                  .show();
              return false;
            }

            return true;
          }
        });
    connectionTypePref = (ListPreference) getPreferenceScreen().findPreference("connection_type");
    pingPreferences = (PreferenceScreen) getPreferenceScreen().findPreference("ping_group");
    pingEnabledPref = (CheckBoxPreference) getPreferenceScreen().findPreference("ping_enabled");
    setTitle(R.string.preferences);

    // Really simple validation to make sure they don't have a space in the hostname(common when
    // using android's autocomplete
    hostPref.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            String val = (String) newValue;
            if (val.contains(" ")) {
              Toast.makeText(
                      WeechatPreferencesActivity.this,
                      R.string.pref_hostname_invalid,
                      Toast.LENGTH_SHORT)
                  .show();
              return false;
            }
            return true;
          }
        });
    sshHostPref.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            String val = (String) newValue;
            if (val.contains(" ")) {
              Toast.makeText(
                      WeechatPreferencesActivity.this,
                      R.string.pref_hostname_invalid,
                      Toast.LENGTH_SHORT)
                  .show();
              return false;
            }
            return true;
          }
        });
  }
Exemplo n.º 30
0
  protected void addPreferences() {
    addPreferencesFromResource(R.xml.fxaccount_status_prefscreen);

    accountCategory = (PreferenceCategory) ensureFindPreference("signed_in_as_category");
    profilePreference = ensureFindPreference("profile");
    emailPreference = ensureFindPreference("email");
    if (AppConstants.MOZ_ANDROID_FIREFOX_ACCOUNT_PROFILES) {
      accountCategory.removePreference(emailPreference);
    } else {
      accountCategory.removePreference(profilePreference);
    }
    authServerPreference = ensureFindPreference("auth_server");

    needsPasswordPreference = ensureFindPreference("needs_credentials");
    needsUpgradePreference = ensureFindPreference("needs_upgrade");
    needsVerificationPreference = ensureFindPreference("needs_verification");
    needsMasterSyncAutomaticallyEnabledPreference =
        ensureFindPreference("needs_master_sync_automatically_enabled");
    needsFinishMigratingPreference = ensureFindPreference("needs_finish_migrating");

    syncCategory = (PreferenceCategory) ensureFindPreference("sync_category");

    bookmarksPreference = (CheckBoxPreference) ensureFindPreference("bookmarks");
    historyPreference = (CheckBoxPreference) ensureFindPreference("history");
    tabsPreference = (CheckBoxPreference) ensureFindPreference("tabs");
    passwordsPreference = (CheckBoxPreference) ensureFindPreference("passwords");

    if (!FxAccountUtils.LOG_PERSONAL_INFORMATION) {
      removeDebugButtons();
    } else {
      connectDebugButtons();
      ALWAYS_SHOW_AUTH_SERVER = true;
      ALWAYS_SHOW_SYNC_SERVER = true;
    }

    if (AppConstants.MOZ_ANDROID_FIREFOX_ACCOUNT_PROFILES) {
      profilePreference.setOnPreferenceClickListener(this);
    } else {
      emailPreference.setOnPreferenceClickListener(this);
    }

    needsPasswordPreference.setOnPreferenceClickListener(this);
    needsVerificationPreference.setOnPreferenceClickListener(this);
    needsFinishMigratingPreference.setOnPreferenceClickListener(this);

    bookmarksPreference.setOnPreferenceClickListener(this);
    historyPreference.setOnPreferenceClickListener(this);
    tabsPreference.setOnPreferenceClickListener(this);
    passwordsPreference.setOnPreferenceClickListener(this);

    deviceNamePreference = (EditTextPreference) ensureFindPreference("device_name");
    deviceNamePreference.setOnPreferenceChangeListener(this);

    syncServerPreference = ensureFindPreference("sync_server");
    morePreference = ensureFindPreference("more");
    morePreference.setOnPreferenceClickListener(this);

    syncNowPreference = ensureFindPreference("sync_now");
    syncNowPreference.setEnabled(true);
    syncNowPreference.setOnPreferenceClickListener(this);

    if (HardwareUtils.hasMenuButton()) {
      syncCategory.removePreference(morePreference);
    }
  }