@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.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    EditTextPreference videoStartPref = (EditTextPreference) findPreference(VIDEO_START_DELAY);
    videoStartPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);

    EditTextPreference emailAddressPref = (EditTextPreference) findPreference(SEND_EMAIL_ADDRESS);
    emailAddressPref.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
  }
  @SuppressWarnings("deprecation")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    EditTextPreference editTextPreference = (EditTextPreference) findPreference("update_interval");
    editTextPreference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);

    editTextPreference = (EditTextPreference) findPreference("password");
    editTextPreference
        .getEditText()
        .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
  }
  @Test
  public void setTextInEditTextShouldStoreText() {
    final EditText editText = preference.getEditText();
    editText.setText(SOME_TEXT);

    assertThat(editText.getText().toString()).isEqualTo(SOME_TEXT);
  }
Exemplo n.º 5
0
  @Override
  public void fillLayout(final SipProfile account) {
    super.fillLayout(account);

    accountUsername.setTitle(R.string.w_common_phone_number);
    accountUsername.setDialogTitle(R.string.w_common_phone_number);

    accountUsername.getEditText().setInputType(InputType.TYPE_CLASS_PHONE);

    // Allow to add suffix x11
    boolean recycle = true;
    accountSuffix = (EditTextPreference) findPreference(SUFFIX_KEY);
    if (accountSuffix == null) {
      accountSuffix = new EditTextPreference(parent);
      accountSuffix.setKey(SUFFIX_KEY);
      accountSuffix.getEditText().setInputType(InputType.TYPE_CLASS_PHONE);
      accountSuffix.setTitle("Suffix for account id");
      accountSuffix.setSummary("For multipresence usage (leave blank if not want)");
      recycle = false;
    }

    if (!recycle) {
      addPreference(accountSuffix);
    }

    String uName = account.getSipUserName();
    String[] uNames = uName.split("x");

    accountUsername.setText(uNames[0]);
    if (uNames.length > 1) {
      accountSuffix.setText(uNames[1]);
    }
  }
        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
          // Do not bind toggles.
          if (preference instanceof CheckBoxPreference
              || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
                  && preference instanceof TwoStatePreference)) {
            return true;
          }

          String stringValue = value.toString();

          if (preference instanceof ListPreference) {
            // For list preferences, look up the correct display value in
            // the preference's 'entries' list.
            ListPreference listPreference = (ListPreference) preference;
            int index = listPreference.findIndexOfValue(stringValue);

            // Set the summary to reflect the new value.
            preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

          } else if (preference instanceof RingtonePreference) {
            // For ringtone preferences, look up the correct display value
            // using RingtoneManager.
            if (TextUtils.isEmpty(stringValue)) {
              // Empty values correspond to 'silent' (no ringtone).
              preference.setSummary(R.string.ringtone_silent);
            } else {
              Ringtone ringtone =
                  RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue));

              if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
              } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
              }
            }

          } else if (preference instanceof EditTextPreference) {
            EditTextPreference textPreference = (EditTextPreference) preference;
            int inputType = textPreference.getEditText().getInputType();
            if (inputType == (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)) {
              preference.setSummary(stringValue.replaceAll(".", "*"));
            } else {
              preference.setSummary(stringValue);
            }
          } else {
            // For all other preferences, set the summary to the value's
            // simple string representation.
            preference.setSummary(stringValue);
          }
          return true;
        }
Exemplo n.º 7
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.task_preferences);

    // Set the time default to a numeric number only
    EditTextPreference timeDefault =
        (EditTextPreference) findPreference(getString(R.string.pref_default_time_from_now_key));
    timeDefault.getEditText().setKeyListener(DigitsKeyListener.getInstance());
  }
Exemplo n.º 8
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.addPreferencesFromResource(R.layout.layout_five_settings_activity);

    PreferenceScreen screen = this.getPreferenceScreen();

    ListPreference idList = new ListPreference(this);
    idList.setTitle(R.string.config_identifiers_title);
    idList.setDialogTitle(R.string.config_identifiers_title);
    idList.setKey("config_five_identifier");

    String[] identifiers = IdentifiersManager.fetchIdentifiers(this);

    idList.setEntries(identifiers);
    idList.setEntryValues(identifiers);

    screen.addPreference(idList);

    EditTextPreference editPreference =
        (EditTextPreference) screen.findPreference("config_five_one");
    EditText field = editPreference.getEditText();
    field.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);

    editPreference = (EditTextPreference) screen.findPreference("config_five_two");
    field = editPreference.getEditText();
    field.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);

    editPreference = (EditTextPreference) screen.findPreference("config_five_three");
    field = editPreference.getEditText();
    field.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);

    editPreference = (EditTextPreference) screen.findPreference("config_five_four");
    field = editPreference.getEditText();
    field.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);

    editPreference = (EditTextPreference) screen.findPreference("config_five_five");
    field = editPreference.getEditText();
    field.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
  }
Exemplo n.º 9
0
  /** Sets the default values for the the preferences */
  private void initPreferences() {

    // Phone name
    String phoneNum =
        ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
    Log.d(TAG, "Phone number of this phone: " + phoneNum);
    if (TextUtils.isEmpty(phoneNum)) phoneNum = Constants.DEFAULT_PHONE_NUMBER;
    EditTextPreference prefPhoneName =
        (EditTextPreference) findPreference(Constants.PREFERENCE_PHONE_NAME);
    if (TextUtils.isEmpty(prefPhoneName.getText())) {
      prefPhoneName.setText(phoneNum);
    }

    // Health worker username for OpenMRS
    EditTextPreference prefEmrUsername =
        (EditTextPreference) findPreference(Constants.PREFERENCE_EMR_USERNAME);
    if (TextUtils.isEmpty(prefEmrUsername.getText())) {
      prefEmrUsername.setText(Constants.DEFAULT_USERNAME);
    }

    // Health worker password for OpenMRS
    EditTextPreference prefEmrPassword =
        (EditTextPreference) findPreference(Constants.PREFERENCE_EMR_PASSWORD);
    prefEmrPassword.getEditText().setTransformationMethod(new PasswordTransformationMethod());
    if (TextUtils.isEmpty(prefEmrPassword.getText())) {
      prefEmrPassword.setText(Constants.DEFAULT_PASSWORD);
    }

    // Whether barcode reading is enabled on the phone
    /*
     * CheckBoxPreference barcodeEnabled = new CheckBoxPreference(this);
     * barcodeEnabled.setKey(Constants.PREFERENCE_BARCODE_ENABLED);
     * barcodeEnabled.setTitle("Enable barcode reading");
     * barcodeEnabled.setSummary
     * ("Enable barcode reading of patient and physician ids");
     * barcodeEnabled.setDefaultValue(false);
     * dialogBasedPrefCat.addPreference(barcodeEnabled);
     */

    // Launches network preferences
    PreferenceScreen prefNetwork = (PreferenceScreen) findPreference("s_network_settings");
    if (prefNetwork != null) {
      prefNetwork.setIntent(new Intent(this, NetworkSettings.class));
    }

    // Launches resource preferences
    PreferenceScreen prefResource = (PreferenceScreen) findPreference("s_resource_settings");
    if (prefResource != null) {
      prefResource.setIntent(new Intent(this, ResourceSettings.class));
    }
  }
Exemplo n.º 10
0
  @SuppressWarnings("deprecation")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    // 指定保存文件名字
    getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
    addPreferencesFromResource(R.xml.tts_setting);
    mSpeedPreference = (EditTextPreference) findPreference("speed_preference");
    mSpeedPreference
        .getEditText()
        .addTextChangedListener(new SettingTextWatcher(TtsSettings.this, mSpeedPreference, 0, 200));

    mPitchPreference = (EditTextPreference) findPreference("pitch_preference");
    mPitchPreference
        .getEditText()
        .addTextChangedListener(new SettingTextWatcher(TtsSettings.this, mPitchPreference, 0, 100));

    mVolumePreference = (EditTextPreference) findPreference("volume_preference");
    mVolumePreference
        .getEditText()
        .addTextChangedListener(
            new SettingTextWatcher(TtsSettings.this, mVolumePreference, 0, 100));
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.licensing_service_preferences);
    mLicensingMode = (ListPreference) getPreferenceScreen().findPreference(LICENSING_MODE);
    mServerAddress =
        (EditTextPreference) getPreferenceScreen().findPreference(LICENSING_SERVER_ADDRESS);
    //		mServerAddress.getEditText().setFilters(new InputFilter[] {new IPInputFilter()});
    mServerPort = (EditTextPreference) getPreferenceScreen().findPreference(LICENSING_SERVER_PORT);
    mServerPort.getEditText().setFilters(new InputFilter[] {new PortInputFilter()});

    Preference resetDefaults = (Preference) findPreference(SET_DEFAULT_PREFERENCES);
    resetDefaults.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          public boolean onPreferenceClick(Preference preference) {
            resetPreferences();
            showToast(R.string.msg_settings_reset);
            return true;
          }
        });
  }
Exemplo n.º 12
0
 public static EditTextPreference Edit(
     Context paramContext,
     PreferenceCategory paramPreferenceCategory,
     String paramString1,
     String paramString2,
     String paramString3,
     String paramString4,
     Object paramObject,
     boolean paramBoolean,
     Integer paramInteger) {
   EditTextPreference localEditTextPreference = new EditTextPreference(paramContext);
   localEditTextPreference.setTitle(paramString1);
   localEditTextPreference.setSummary(paramString2);
   localEditTextPreference.setEnabled(paramBoolean);
   localEditTextPreference.setKey(paramString4);
   localEditTextPreference.setDefaultValue(paramObject);
   localEditTextPreference.setDialogTitle(paramString3);
   if (paramInteger != null)
     localEditTextPreference.getEditText().setInputType(paramInteger.intValue());
   paramPreferenceCategory.addPreference(localEditTextPreference);
   return localEditTextPreference;
 }
  @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.º 14
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;
          }
        });
  }
  /**
   * This method initialize the default values for the UI <br>
   * objects in parallel to inflating the same on the screen
   *
   * @param savedInstanceState If the activity is being re-initialized after previously being shut
   *     down then this Bundle contains the data it most recently supplied in
   *     onSaveInstanceState(Bundle)
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.basic_wireless_settings);
    mainMenuStngs = MainMenu.mMainMenuRef;
    mSoftAPCfg = MainMenu.mSoftAPCfg;
    MainMenu.basicWirelessEvent = this;

    // Edit default and orgSharPref preference
    defSharPref = PreferenceManager.getDefaultSharedPreferences(this);
    orgSharPref = getSharedPreferences(L10NConstants.CONFIG_FILE_NAME, MODE_PRIVATE);
    defPrefEditor = defSharPref.edit();
    orgPrefEditor = orgSharPref.edit();

    // Get the reference to the preferences defined in the UI
    configLst = (CheckBoxPreference) findPreference("wpsstate");
    networkLst = (ListPreference) findPreference(L10NConstants.HW_MODE_KEY);
    freqLst = (ListPreference) findPreference(L10NConstants.CHNL_KEY);
    authLst = (ListPreference) findPreference(L10NConstants.AUTH_MODE_KEY);
    broadChk = (CheckBoxPreference) findPreference("broadcast_ssid");
    wpsEnrollLst = (ListPreference) findPreference(L10NConstants.CONFIG_KEY);
    wpsEnrollLst.setSummary(getString(R.string.str_bws_enroll));
    ssidEdit = (EditTextPreference) findPreference("ssid");
    sKeys = getResources().getStringArray(R.array.bws_keys);

    // set preference change listener to SSID Broadcast,WPS, WPS Enroll Method
    wpsEnrollLst.setOnPreferenceChangeListener(this);
    broadChk.setOnPreferenceChangeListener(this);
    configLst.setOnPreferenceChangeListener(this);

    prefLst = new ArrayList<Preference>();
    prefLst.add(networkLst);
    prefLst.add(ssidEdit);
    prefLst.add(freqLst);
    prefLst.add(authLst);

    // set WPS enroll method 'true' based on WPS check value in the preference
    String sWpsChk = defSharPref.getString(L10NConstants.WPS_KEY, "");
    if (sWpsChk.equals(L10NConstants.VAL_ONE)) {
      configLst.setChecked(true);
    } else {
      configLst.setChecked(false);
    }
    // set SSID broadcast check 'true' based on SSID Broadcast value in the preference
    String sBroadChk = defSharPref.getString(L10NConstants.IGNORE_BROAD_SSID_KEY, "");
    if (sBroadChk.equals(L10NConstants.VAL_ONE)) {
      broadChk.setChecked(false);
    } else broadChk.setChecked(true);

    String sCountryCode = defSharPref.getString(L10NConstants.COUNTRY_KEY, "");
    String cCode = sCountryCode;
    if (!sCountryCode.equals("")) {
      Log.d("Basic Wireless", "Country Code Settings :" + sCountryCode + ":");
      // Extract country code value(eg:US) and regulatory domain(eg: REGDOMAIN_FCC) from pref
      // file((eg: US,REGDOMAIN_FCC)
      if (sCountryCode.contains(",")) {
        Log.d("Basic Wireless", "Country Code Settings if Contains ,");
        sCountryCode = sCountryCode.substring(0, sCountryCode.indexOf(","));
        sRegulatoryDomain = cCode.substring(cCode.indexOf(",") + 1, cCode.length());
      }
      // Set the channel freqency based on the regulatory domain associated with the country code
      // eg. US->Channel's=11, JP->Channel's=14
      if (sRegulatoryDomain.equals("REGDOMAIN_FCC")
          || sRegulatoryDomain.equals("REGDOMAIN_WORLD")
          || sRegulatoryDomain.equals("REGDOMAIN_N_AMER_EXC_FCC")) {
        sFreqArray = getResources().getStringArray(R.array.freqeleven);
        sFreqArrayValues = getResources().getStringArray(R.array.freqelevenValues);
        freqLst.setEntries(sFreqArray);
        freqLst.setEntryValues(sFreqArrayValues);
        Log.d("Basic Wireless", "Country Code Settings Setting Channal Frequency");
      } else if (sRegulatoryDomain.equals("REGDOMAIN_ETSI")
          || sRegulatoryDomain.equals("REGDOMAIN_APAC")
          || sRegulatoryDomain.equals("REGDOMAIN_KOREA")
          || sRegulatoryDomain.equals("REGDOMAIN_HI_5GHZ")
          || sRegulatoryDomain.equals("REGDOMAIN_NO_5GHZ")) {
        sFreqArray = getResources().getStringArray(R.array.freqthirteen);
        sFreqArrayValues = getResources().getStringArray(R.array.freqthirteenValues);
        freqLst.setEntries(sFreqArray);
        freqLst.setEntryValues(sFreqArrayValues);
        Log.d("Basic Wireless", "Country Code Settings Setting Channal Frequency");
      } else if (sRegulatoryDomain.equals("REGDOMAIN_JAPAN")) {
        sFreqArray = getResources().getStringArray(R.array.freqfourteen);
        sFreqArrayValues = getResources().getStringArray(R.array.freqfourteenValues);
        freqLst.setEntries(sFreqArray);
        freqLst.setEntryValues(sFreqArrayValues);
        Log.d("Basic Wireless", "Country Code Settings Setting Channal Frequency");
      } else {
        sFreqArray[0] = "Auto";
        sFreqArrayValues[0] = "0";
      }
      freqLst.setEntries(sFreqArray);
      freqLst.setEntryValues(sFreqArrayValues);
    }
    // set the default value for Network mode, SSID, Channel, authentication mode
    Log.d(
        L10NConstants.TAG_BWS,
        "Channel After the change "
            + defSharPref.getString(L10NConstants.CHNL_KEY, L10NConstants.VAL_ZERO));
    int keyCt = 0;
    for (Preference pref : prefLst) {
      pref.setOnPreferenceChangeListener(this);
      Log.d("Basic Wireless", "Setting Preference Change Listener and Summary");
      String sGetMode = defSharPref.getString(sKeys[keyCt], L10NConstants.VAL_ZERO);

      if (pref instanceof ListPreference) {
        ListPreference lstPref = (ListPreference) pref;
        lstPref.setSummary(lstPref.getEntry());
        if (!sGetMode.equals("")) {
          if (sGetMode.equals(L10NConstants.VAL_ZERO)) {
            String sAutoChannel = defSharPref.getString("autoChannel", "");
            if (!sAutoChannel.equals("")) {
              pref.setSummary(lstPref.getEntry() + "-Current Channel " + sAutoChannel);
            } else {
              pref.setSummary(lstPref.getEntry());
            }
          } else if (sKeys[keyCt].equals(L10NConstants.CHNL_KEY)) pref.setSummary(sGetMode);
        }
      } else if (pref instanceof EditTextPreference) {
        Log.d("Basic Wireless", "Setting Summary For EditBox");
        pref.setSummary(sGetMode);
      }
      keyCt++;
    }

    // ssid editText is validated not to allow empty string
    final EditText editText = ssidEdit.getEditText();
    editText.setOnKeyListener(
        new View.OnKeyListener() {
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            sSsidVal = editText.getText().toString();
            if (sSsidVal.equals("")) {
              editText.setError("Value cannot be null");
            }
            return false;
          }
        });
    ssidEdit.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          public boolean onPreferenceClick(Preference preference) {
            ssidEdit.getEditText().setError(null);
            return true;
          }
        });
  }
 @Test
 public void testConstructor() {
   preference = new EditTextPreference(context);
   assertNotNull(preference.getEditText());
 }
Exemplo n.º 17
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.º 18
0
 public void testGetEditText() {
   EditText editText = mEditTextPref.getEditText();
   assertNotNull(editText);
 }