androidx.preference.EditTextPreference Java Examples

The following examples show how to use androidx.preference.EditTextPreference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RtspPreferenceActivity.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences, rootKey);

    EditTextPreference url = findPreference(getString(R.string.key_server_url));
    if (url != null) {
        url.setText(getServerUrl());
    }

    ListPreference videoResolution = findPreference(getString(R.string.key_video_resolution));
    if (videoResolution != null) {
        String[] entries = createCameraResolutions(getContext());
        videoResolution.setEntries(entries);
        videoResolution.setEntryValues(entries);
    }

    setInputTypeNumber(R.string.key_server_port);
    setInputTypeNumber(R.string.key_video_bit_rate);
    setInputTypeNumber(R.string.key_video_frame_rate);
    setInputTypeNumber(R.string.key_video_iframe_interval);
    setInputTypeNumber(R.string.key_audio_bit_rate);
}
 
Example #2
Source File: SettingsFragment.java    From haven with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK && data != null) {
        String onionHost = data.getStringExtra("hs_host");

        if (checkValidString(onionHost)) {
            preferences.setRemoteAccessOnion(onionHost.trim());
            ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_ONION)).setText(preferences.getRemoteAccessOnion().trim() + ":" + WebServer.LOCAL_PORT);
            if (checkValidString(preferences.getRemoteAccessOnion())) {
                findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(preferences.getRemoteAccessOnion().trim() + ":" + WebServer.LOCAL_PORT);
            } else {
                findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(R.string.remote_access_hint);
            }
        }
    }
}
 
Example #3
Source File: SettingsPreferenceActivity.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
private void createEncoderBitRatePreference() {
    EditTextPreference pref = findPreference("encoder_bit_rate");
    if (pref != null) {
        pref.setSummaryProvider((Preference preference) ->
                pref.getText() + " Mbps"
        );
        // 0以上の実数値以外の入力を禁止する
        pref.setOnBindEditTextListener((@NonNull EditText editText) ->
                editText.setInputType(InputType.TYPE_CLASS_NUMBER
                        | InputType.TYPE_NUMBER_FLAG_DECIMAL));
        String value = pref.getText();
        if (value == null) {
            pref.setText(Settings.DEFAULT_ENCODER_BITRATE_BASE);
        }
    }
}
 
Example #4
Source File: SettingsPreferenceActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
private void setInputTypeNumber(String key) {
    EditTextPreference editTextPreference = findPreference(key);
    if (editTextPreference != null) {
        editTextPreference.setOnBindEditTextListener((editText) ->
                editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED));
        editTextPreference.setOnPreferenceChangeListener(mOnPreferenceChangeListener);
    }
}
 
Example #5
Source File: RtspPreferenceActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
private void setInputTypeNumber(int resId) {
    EditTextPreference editTextPreference = findPreference(getString(resId));
    if (editTextPreference != null) {
        editTextPreference.setOnBindEditTextListener((editText) ->
                editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED));
        editTextPreference.setOnPreferenceChangeListener(mOnPreferenceChangeListener);
    }
}
 
Example #6
Source File: RtspPreferenceActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
private String getStringFromEditText(int resId, int defaultId) {
    EditTextPreference editTextPreference = findPreference(getString(resId));
    if (editTextPreference != null) {
        return editTextPreference.getText();
    }
    return getString(defaultId);
}
 
Example #7
Source File: HostRecorderSRTSettingFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.settings_host_preview_srt);

    EditTextPreference inputBwPref = findPreference(getString(R.string.pref_key_settings_srt_inputbw));
    if (inputBwPref != null) {
        inputBwPref.setSummaryProvider(summaryOptionAuto);
    }
    EditTextPreference oHeadBwPref = findPreference(getString(R.string.pref_key_settings_srt_oheadbw));
    if (oHeadBwPref != null) {
        oHeadBwPref.setSummaryProvider(summaryOptionAuto);
    }
}
 
Example #8
Source File: RuleConfigFragment.java    From Daedalus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
    if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        if (resultData != null) {
            Uri uri = resultData.getData();
            try {
                getActivity().getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);

                String file = System.currentTimeMillis() + ".dr";//Daedalus Rule
                InputStream inputStream = getActivity().getContentResolver().openInputStream(uri);
                OutputStream outputStream = new FileOutputStream(Daedalus.rulePath + file);
                byte[] b = new byte[1024];
                while ((inputStream.read(b)) != -1) {
                    outputStream.write(b);
                }
                inputStream.close();
                outputStream.close();

                ((EditTextPreference) findPreference("ruleFilename")).setText(file);
                findPreference("ruleFilename").setSummary(file);
                ((EditTextPreference) findPreference("ruleDownloadUrl")).setText(uri.toString());
                findPreference("ruleDownloadUrl").setSummary(uri.toString());

                Snackbar.make(getView(), R.string.notice_importing_rule, Snackbar.LENGTH_LONG).show();
            } catch (Exception e) {
                Logger.logException(e);
            }
        }
    }
}
 
Example #9
Source File: SettingsPreferenceActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
private void createEncoderFrameRatePreference() {
    EditTextPreference pref = findPreference("encoder_frame_rate");
    if (pref != null) {
        pref.setSummaryProvider((Preference preference) ->
                pref.getText() + " fps"
        );
        // 0以上の整数値以外の入力を禁止する
        pref.setOnBindEditTextListener((@NonNull EditText editText) ->
                editText.setInputType(InputType.TYPE_CLASS_NUMBER));
        String value = pref.getText();
        if (value == null) {
            pref.setText(Integer.toString(Settings.DEFAULT_ENCODER_FPS));
        }
    }
}
 
Example #10
Source File: SettingsFragment.java    From haven with GNU General Public License v3.0 5 votes vote down vote up
private void checkSignalUsername() {
    if (checkValidString(preferences.getSignalUsername())) {
        findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(preferences.getSignalUsername().trim());
        ((EditTextPreference) findPreference(PreferenceManager.REGISTER_SIGNAL)).setText(preferences.getSignalUsername().trim());
    } else {
        findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(R.string.signal_dialog_summary);
    }
}
 
Example #11
Source File: SettingsFragment.java    From haven with GNU General Public License v3.0 5 votes vote down vote up
private void setPhoneNumber() {
    String phoneNumber = ((EditTextPreference) findPreference(PreferenceManager.REMOTE_PHONE_NUMBER)).getText();

    if (checkValidString(phoneNumber) && !getCountryCode().equalsIgnoreCase(phoneNumber)) {
        preferences.setRemotePhoneNumber(phoneNumber.trim());
        findPreference(PreferenceManager.REMOTE_PHONE_NUMBER).setSummary(phoneNumber.trim());
    } else if (!getCountryCode().equalsIgnoreCase(phoneNumber)){
        preferences.setRemotePhoneNumber("");
        findPreference(PreferenceManager.REMOTE_PHONE_NUMBER).setSummary(R.string.sms_dialog_message);
    }
}
 
Example #12
Source File: SRTSettingPreferenceActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
private void setInputTypeNumber(String key) {
    EditTextPreference editTextPreference = findPreference(key);
    if (editTextPreference != null) {
        editTextPreference.setOnBindEditTextListener((editText) ->
                editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED));
        editTextPreference.setOnPreferenceChangeListener(mOnPreferenceChangeListener);
    }
}
 
Example #13
Source File: LockScreenPolicyFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
/**
 * Set an initial value. Updates the summary to match.
 */
private void setup(String key, Object adminSetting) {
    final Preference pref = findPreference(key);
    final DpcPreferenceBase dpcPref = (DpcPreferenceBase) pref;

    // Disable preferences that don't apply to the parent profile
    dpcPref.setCustomConstraint(
            () -> Keys.NOT_APPLICABLE_TO_PARENT.contains(key) && isParentProfileInstance()
                    ? R.string.not_for_parent_profile
                    : NO_CUSTOM_CONSTRIANT
    );

    // We do not allow user to add trust agent config in pre-N devices in managed profile.
    if (Util.SDK_INT < VERSION_CODES.N && key.equals(Keys.SET_TRUST_AGENT_CONFIG)) {
        dpcPref.setAdminConstraint(DpcPreferenceHelper.ADMIN_DEVICE_OWNER);
        return;
    }

    // Set up initial state and possibly a descriptive summary of said state.
    if (pref instanceof EditTextPreference) {
        String stringValue = (adminSetting != null ? adminSetting.toString() : null);
        if (adminSetting instanceof Number && "0".equals(stringValue)) {
            stringValue = null;
        }
        ((EditTextPreference) pref).setText(stringValue);
        pref.setSummary(stringValue);
    } else if (pref instanceof TwoStatePreference) {
        ((TwoStatePreference) pref).setChecked((Boolean) adminSetting);
    }

    // Start listening for change events.
    pref.setOnPreferenceChangeListener(this);
    pref.setOnPreferenceClickListener(this);
}
 
Example #14
Source File: SettingsActivity.java    From Hauk with Apache License 2.0 5 votes vote down vote up
private static void setTextEditParams(PreferenceManager manager, info.varden.hauk.system.preferences.Preference<?> preference, EditTextPreference.OnBindEditTextListener... listeners) {
    EditTextPreference pref = manager.findPreference(preference.getKey());
    if (pref != null) {
        pref.setOnBindEditTextListener(new CascadeBindListener(listeners));
    } else {
        Log.wtf("Could not find setting for preference %s setting OnBindEditTextListener", preference); //NON-NLS
    }
}
 
Example #15
Source File: DeveloperPreferences.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private void setSessionEditText() {
    if (isSessionSavingEnabled()) {
        getPreferenceScreen().addPreference(savedSessionEditTextPreference);
        ((EditTextPreference)savedSessionEditTextPreference).setText(getSavedSessionStateAsString());
    } else {
        if (savedSessionEditTextPreference != null) {
            getPreferenceScreen().removePreference(savedSessionEditTextPreference);
        }
    }
}
 
Example #16
Source File: SettingsPreferenceActivity.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
private void createSrtServerPreference() {
    EditTextPreference pref = findPreference("server_url");
    if (pref != null) {
        pref.setText("srt://" + getIpAddress() + ":12345");
    }
}
 
Example #17
Source File: SettingsFragment.java    From c3nav-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences, rootKey);

    useWifiLocating = (CheckBoxPreference)this.findPreference(getString(R.string.use_wifi_locating_key));
    sharePrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    if (sharePrefs.getBoolean(getString(R.string.use_wifi_locating_key), true) && !checkLocationPermisson()) {
        useWifiLocating.setChecked(false);
    }
    useWifiLocating.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (!(boolean)newValue) {
                // always let user disable wifi locating
                return true;
            }

            boolean permissionAsked = false;
            while (permissionAsked == false) {
                if (checkLocationPermisson()) {
                    return true;
                }
                permissionAsked = true;
                ActivityCompat.requestPermissions(getActivity(),
                        new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                        MainActivity.PERM_REQUEST);
            }
            return false;
        }
    });

    developerSettings = (PreferenceCategory)findPreference(getString(R.string.developer_settings_key));
    developerModeEnabled = (SwitchPreference)findPreference(getString(R.string.developer_mode_enabled_key));
    developerInstanceUrl = (EditTextPreference)findPreference(getString(R.string.developer_instance_url_key));
    developerHttpUser = (EditTextPreference)findPreference(getString(R.string.developer_http_user_key));
    developerHttpPassword = (EditTextPreference)findPreference(getString(R.string.developer_http_password_key));

    developerSettings.setVisible(BuildConfig.DEBUG);
    developerModeEnabled.setVisible(BuildConfig.DEBUG);
    developerInstanceUrl.setVisible(BuildConfig.DEBUG);
    developerHttpUser.setVisible(BuildConfig.DEBUG);
    developerHttpPassword.setVisible(BuildConfig.DEBUG);
}
 
Example #18
Source File: MainPreferenceFragment.java    From kcanotify with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (sHandler != null) {
        JsonObject dmpData = new JsonObject();
        String kca_url = "";
        Bundle bundle = new Bundle();
        switch (key) {
            case PREF_KCA_SEEK_CN:
                kca_url = KCA_API_PREF_CN_CHANGED;
                break;
            case PREF_KCA_EXP_VIEW:
                kca_url = KCA_API_PREF_EXPVIEW_CHANGED;
                break;
            case PREF_KCA_SET_PRIORITY:
                kca_url = KCA_API_PREF_PRIORITY_CHANGED;
                break;
            case PREF_FAIRY_SIZE:
                kca_url = KCA_API_PREF_FAIRYSIZE_CHANGED;
                break;
            default:
                break;
        }
        if (kca_url.length() > 0) {
            bundle.putString("url", kca_url);
            bundle.putString("data", gson.toJson(dmpData));
            Message sMsg = sHandler.obtainMessage();
            sMsg.setData(bundle);
            sHandler.sendMessage(sMsg);
        }
    }

    Preference preference = findPreference(key);
    if (preference instanceof ListPreference) {
        ListPreference lp = (ListPreference) preference;
        preference.setSummary(lp.getEntry());
    }

    if (preference instanceof EditTextPreference) {
        EditTextPreference etp = (EditTextPreference) preference;
        preference.setSummary(getEditTextSummary(key, etp.getText()));
    }
}
 
Example #19
Source File: StoragePreferenceFragment.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
TrimLengthValidationListener() {
  EditTextPreference preference = (EditTextPreference)findPreference(TextSecurePreferences.THREAD_TRIM_LENGTH);
  onPreferenceChange(preference, preference.getText());
}
 
Example #20
Source File: DnsServerConfigFragment.java    From Daedalus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem item) {
    int id = item.getItemId();

    switch (id) {
        case R.id.action_apply:
            String serverName = ((EditTextPreference) findPreference("serverName")).getText();
            String serverAddress = ((EditTextPreference) findPreference("serverAddress")).getText();
            String serverPort = ((EditTextPreference) findPreference("serverPort")).getText();

            if (serverName.equals("") | serverAddress.equals("") | serverPort.equals("")) {
                Snackbar.make(getView(), R.string.notice_fill_in_all, Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
                break;
            }

            if (index == ConfigActivity.ID_NONE) {
                Daedalus.configurations.getCustomDNSServers().add(new CustomDnsServer(serverName, serverAddress, Integer.parseInt(serverPort)));
            } else {
                CustomDnsServer server = Daedalus.configurations.getCustomDNSServers().get(index);
                server.setName(serverName);
                server.setAddress(serverAddress);
                server.setPort(Integer.parseInt(serverPort));
            }
            Daedalus.setRulesChanged();
            getActivity().finish();
            break;
        case R.id.action_delete:
            if (index != ConfigActivity.ID_NONE) {
                new AlertDialog.Builder(getActivity())
                        .setTitle(R.string.notice_delete_confirm_prompt)
                        .setPositiveButton(android.R.string.yes, (dialog, which) -> {
                            Daedalus.configurations.getCustomDNSServers().remove(index);
                            getActivity().finish();
                        })
                        .setNegativeButton(android.R.string.no, null)
                        .create()
                        .show();
            } else {
                Daedalus.setRulesChanged();
                getActivity().finish();
            }
            break;
    }

    return true;
}
 
Example #21
Source File: DnsServerConfigFragment.java    From Daedalus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);

    EditTextPreference serverName = findPreference("serverName");
    serverName.setOnPreferenceChangeListener((preference, newValue) -> {
        preference.setSummary((String) newValue);
        return true;
    });

    EditTextPreference serverAddress = findPreference("serverAddress");
    serverAddress.setOnPreferenceChangeListener((preference, newValue) -> {
        preference.setSummary((String) newValue);
        return true;
    });

    EditTextPreference serverPort = findPreference("serverPort");
    serverPort.setOnPreferenceChangeListener((preference, newValue) -> {
        preference.setSummary((String) newValue);
        return true;
    });


    index = intent.getIntExtra(ConfigActivity.LAUNCH_ACTION_ID, ConfigActivity.ID_NONE);
    if (index != ConfigActivity.ID_NONE) {
        CustomDnsServer server = Daedalus.configurations.getCustomDNSServers().get(index);
        serverName.setText(server.getName());
        serverName.setSummary(server.getName());
        serverAddress.setText(server.getAddress());
        serverAddress.setSummary(server.getAddress());
        serverPort.setText(String.valueOf(server.getPort()));
        serverPort.setSummary(String.valueOf(server.getPort()));
    } else {
        serverName.setText("");
        serverAddress.setText("");
        String port = String.valueOf(DnsServer.DNS_SERVER_DEFAULT_PORT);
        serverPort.setText(port);
        serverPort.setSummary(port);
    }
    return view;
}
 
Example #22
Source File: SettingsFragment.java    From haven with GNU General Public License v3.0 4 votes vote down vote up
private void setDefaultStoragePath () {
    String defaultStoragePath = ((EditTextPreference) findPreference(PreferenceManager.CONFIG_BASE_STORAGE)).getText();
    preferences.setDefaultMediaStoragePath(defaultStoragePath);
}
 
Example #23
Source File: CascadeBindListener.java    From Hauk with Apache License 2.0 4 votes vote down vote up
@Override
public void onBindEditText(@NonNull EditText editText) {
    for (EditTextPreference.OnBindEditTextListener listener : this.listeners) {
        listener.onBindEditText(editText);
    }
}
 
Example #24
Source File: CascadeBindListener.java    From Hauk with Apache License 2.0 4 votes vote down vote up
public CascadeBindListener(EditTextPreference.OnBindEditTextListener[] listeners) {
    this.listeners = listeners.clone();
}
 
Example #25
Source File: SettingsFragment.java    From haven with GNU General Public License v3.0 3 votes vote down vote up
protected void save() {
    preferences.activateAccelerometer(true);

    preferences.activateCamera(true);

    preferences.activateMicrophone(true);

    setPhoneNumber();

    boolean videoMonitoringActive = ((SwitchPreference) findPreference(mActivity.getResources().getString(R.string.video_active_preference_key))).isChecked();

    preferences.setActivateVideoMonitoring(videoMonitoringActive);

    boolean remoteNotificationActive =
            ((SwitchPreference) findPreference(PreferenceManager.REMOTE_NOTIFICATION_ACTIVE)).isChecked();
    preferences.setRemoteNotificationActive(remoteNotificationActive);

    boolean remoteAccessActive = ((SwitchPreference) findPreference(PreferenceManager.REMOTE_ACCESS_ACTIVE)).isChecked();

    preferences.activateRemoteAccess(remoteAccessActive);
    String password = ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_CRED)).getText();

    if (checkValidStrings(password, preferences.getRemoteAccessCredential()) && (TextUtils.isEmpty(preferences.getRemoteAccessCredential()) || !password.trim().equals(preferences.getRemoteAccessCredential().trim()))) {
        preferences.setRemoteAccessCredential(password.trim());
        app.stopServer();
        app.startServer();
    }

    preferences.setVoiceVerification(false);

    boolean heartbeatMonitorActive = ((SwitchPreference) findPreference(PreferenceManager.HEARTBEAT_MONITOR_ACTIVE)).isChecked();

    preferences.activateHeartbeat(heartbeatMonitorActive);

    mActivity.setResult(AppCompatActivity.RESULT_OK);
    mActivity.finish();
}