Java Code Examples for android.preference.EditTextPreference#setTitle()

The following examples show how to use android.preference.EditTextPreference#setTitle() . 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: DvachModule.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    addPasswordPreference(preferenceGroup);
    CheckBoxPreference onionPref = new LazyPreferences.CheckBoxPreference(context);
    onionPref.setTitle(R.string.pref_use_onion);
    onionPref.setSummary(R.string.pref_use_onion_summary);
    onionPref.setKey(getSharedKey(PREF_KEY_USE_ONION));
    onionPref.setDefaultValue(false);
    onionPref.setDisableDependentsState(true);
    preferenceGroup.addPreference(onionPref);
    EditTextPreference domainPref = new EditTextPreference(context);
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.getEditText().setHint(DEFAULT_DOMAIN);
    domainPref.getEditText().setSingleLine();
    domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    preferenceGroup.addPreference(domainPref);
    domainPref.setDependency(getSharedKey(PREF_KEY_USE_ONION));
    addProxyPreferences(preferenceGroup);
}
 
Example 2
Source File: KrautModule.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
public void addKompturcodePreference(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    EditTextPreference kompturcodePreference = new EditTextPreference(context);
    kompturcodePreference.setTitle(R.string.kraut_prefs_kompturcode);
    kompturcodePreference.setDialogTitle(R.string.kraut_prefs_kompturcode);
    kompturcodePreference.setSummary(R.string.kraut_prefs_kompturcode_summary);
    kompturcodePreference.setKey(getSharedKey(PREF_KEY_KOMPTURCODE_COOKIE));
    kompturcodePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            setKompturcodeCookie((String) newValue);
            return true;
        }
    });
    preferenceGroup.addPreference(kompturcodePreference);
}
 
Example 3
Source File: DobroModule.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
private void addDomainPreferences(PreferenceGroup group) {
    Context context = group.getContext();
    Preference.OnPreferenceChangeListener updateDomainListener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals(getSharedKey(PREF_KEY_DOMAIN))) {
                domain = (String) newValue;
                if (domain.length() == 0) domain = DEFAULT_DOMAIN;
                loadHanabiraCookie();
                return true;
            }
            return false;
        }
    };
    EditTextPreference domainPref = new EditTextPreference(context);
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.getEditText().setHint(DEFAULT_DOMAIN);
    domainPref.getEditText().setSingleLine();
    domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    domainPref.setOnPreferenceChangeListener(updateDomainListener);
    group.addPreference(domainPref);
}
 
Example 4
Source File: PreferencesActivity.java    From denominator with Apache License 2.0 6 votes vote down vote up
private PreferenceScreen createFromProvider() {
  PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
  if (provider.credentialTypeToParameterNames().isEmpty()) {
    return root;
  }
  String credentialType = provider.credentialTypeToParameterNames().keySet().iterator().next();
  root.setTitle(credentialType + " credentials for provider " + provider.name());
  for (String parameter : provider.credentialTypeToParameterNames().get(credentialType)) {
    EditTextPreference cred = new EditTextPreference(this);
    cred.setKey(parameter);
    cred.setTitle(parameter);
    cred.setDialogTitle(parameter);
    root.addPreference(cred);
  }
  return root;
}
 
Example 5
Source File: SettingsActivity.java    From WhereAreTheEyes with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    final EditTextPreference username = (EditTextPreference) getPreferenceManager().findPreference("username_preference");

    // Set the title to include the username if there is one
    if( username.getText().length() > 0 )
        username.setTitle("Username (" + username.getText() + ")");

    // This big block of code is equivalent to s/[^A-Za-z0-9_]//g
    InputFilter usernameFilter = new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end,
                                   Spanned dest, int dstart, int dend) {
            for (int i = start; i < end; i++) {
                if (!Character.isLetterOrDigit(source.charAt(i)) && source.charAt(i) != '_' ) {
                    return "";
                }
            }
            return null;
        }
    };
    username.getEditText().setFilters(new InputFilter[] { usernameFilter });

    // Set a callback so we can update the username text when user changes it
    username.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if( newValue.toString().length() > 0 )
                preference.setTitle("Username (" + newValue.toString() + ")");
            else
                preference.setTitle("Username");
            Log.d("PREFERENCES", "Updated username to: " + newValue.toString());
            return true; // Returning true commits the change
        }
    });

    Log.d("Settings", "Starting settings.");
}
 
Example 6
Source File: CirnoModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    final Context context = preferenceGroup.getContext();
    EditTextPreference passwordPref = new EditTextPreference(context);
    passwordPref.setTitle(R.string.iichan_prefs_report_thread);
    passwordPref.setDialogTitle(R.string.iichan_prefs_report_thread);
    passwordPref.setSummary(R.string.iichan_prefs_report_thread_summary);
    passwordPref.setKey(getSharedKey(PREF_KEY_REPORT_THREAD));
    passwordPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
    passwordPref.getEditText().setSingleLine();
    passwordPref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(255) });
    preferenceGroup.addPreference(passwordPref);
    
    super.addPreferencesOnScreen(preferenceGroup);
}
 
Example 7
Source File: Pref.java    From GeoLog with Apache License 2.0 5 votes vote down vote up
public static EditTextPreference Edit(Context context, PreferenceCategory category, int caption, int summary, int dialogCaption, String key, Object defaultValue, boolean enabled, Integer type) {
	EditTextPreference retval = new EditTextPreference(context);
	if (caption > 0) retval.setTitle(caption);
	if (summary > 0) retval.setSummary(summary);
	retval.setEnabled(enabled);
	retval.setKey(key);
	retval.setDefaultValue(defaultValue);
	if (dialogCaption > 0) retval.setDialogTitle(dialogCaption);
	if (type != null) {
		retval.getEditText().setInputType(type);
	}
	if (category != null) category.addPreference(retval);
	return retval;
}
 
Example 8
Source File: AbstractChanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Добавить в группу параметров (на экран/в категорию) новую категорию настроек прокси-сервера
 * @param group группа, на которую добавляются параметры
 */
protected void addProxyPreferences(PreferenceGroup group) {
    final Context context = group.getContext();
    PreferenceCategory proxyCat = new PreferenceCategory(context); //категория настроек прокси
    proxyCat.setTitle(R.string.pref_cat_proxy);
    group.addPreference(proxyCat);
    CheckBoxPreference useProxyPref = new LazyPreferences.CheckBoxPreference(context); //чекбокс "использовать ли прокси вообще"
    useProxyPref.setTitle(R.string.pref_use_proxy);
    useProxyPref.setSummary(R.string.pref_use_proxy_summary);
    useProxyPref.setKey(getSharedKey(PREF_KEY_USE_PROXY));
    useProxyPref.setDefaultValue(false);
    useProxyPref.setOnPreferenceChangeListener(updateHttpListener);
    proxyCat.addPreference(useProxyPref);
    EditTextPreference proxyHostPref = new LazyPreferences.EditTextPreference(context); //поле ввода адреса прокси-сервера
    proxyHostPref.setTitle(R.string.pref_proxy_host);
    proxyHostPref.setDialogTitle(R.string.pref_proxy_host);
    proxyHostPref.setSummary(R.string.pref_proxy_host_summary);
    proxyHostPref.setKey(getSharedKey(PREF_KEY_PROXY_HOST));
    proxyHostPref.setDefaultValue(DEFAULT_PROXY_HOST);
    proxyHostPref.getEditText().setSingleLine();
    proxyHostPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    proxyHostPref.setOnPreferenceChangeListener(updateHttpListener);
    proxyCat.addPreference(proxyHostPref);
    proxyHostPref.setDependency(getSharedKey(PREF_KEY_USE_PROXY));
    EditTextPreference proxyHostPort = new LazyPreferences.EditTextPreference(context); //поле ввода порта прокси-сервера
    proxyHostPort.setTitle(R.string.pref_proxy_port);
    proxyHostPort.setDialogTitle(R.string.pref_proxy_port);
    proxyHostPort.setSummary(R.string.pref_proxy_port_summary);
    proxyHostPort.setKey(getSharedKey(PREF_KEY_PROXY_PORT));
    proxyHostPort.setDefaultValue(DEFAULT_PROXY_PORT);
    proxyHostPort.getEditText().setSingleLine();
    proxyHostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
    proxyHostPort.setOnPreferenceChangeListener(updateHttpListener);
    proxyCat.addPreference(proxyHostPort);
    proxyHostPort.setDependency(getSharedKey(PREF_KEY_USE_PROXY));
}
 
Example 9
Source File: CastPreference.java    From cast-videos-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.application_preference);
    getPreferenceScreen().getSharedPreferences().
            registerOnSharedPreferenceChangeListener(this);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    EditTextPreference versionPref = (EditTextPreference) findPreference("app_version");
    versionPref.setTitle(getString(R.string.version, Utils.getAppVersionName(this)));
}
 
Example 10
Source File: CastPreference.java    From cast-videos-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.application_preference);
    getPreferenceScreen().getSharedPreferences().
            registerOnSharedPreferenceChangeListener(this);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    EditTextPreference versionPref = (EditTextPreference) findPreference("app_version");
    versionPref.setTitle(getString(R.string.version, Utils.getAppVersionName(this)));
}
 
Example 11
Source File: PADherderAccountsPreferenceFragment.java    From PADListener with GNU General Public License v2.0 5 votes vote down vote up
private void addPreferencesForOneAccount(int accountId) {
	MyLog.entry("accountId = " + accountId);

	final PreferenceCategory accountCategory = new PreferenceCategory(getActivity());
	accountCategory.setTitle(getString(R.string.settings_padherder_account_category, accountId));
	accountsByPosition.put(accountId, accountCategory);
	getPreferenceScreen().addPreference(accountCategory);

	final EditTextPreference accountName = new EditTextPreference(getActivity());
	accountName.setKey("padherder_name_" + accountId);
	accountName.setTitle(R.string.settings_padherder_name_title);
	accountName.setDialogTitle(R.string.settings_padherder_name_title);
	accountName.setSummary(R.string.settings_padherder_name_summary);
	accountCategory.addPreference(accountName);

	final EditTextPreference accountLogin = new EditTextPreference(getActivity());
	accountLogin.setKey("padherder_login_" + accountId);
	accountLogin.setTitle(R.string.settings_padherder_login_title);
	accountLogin.setDialogTitle(R.string.settings_padherder_login_title);
	accountLogin.setSummary(R.string.settings_padherder_login_summary);
	accountCategory.addPreference(accountLogin);

	final EditTextPreference accountPassword = new EditTextPreference(getActivity());
	accountPassword.setKey("padherder_password_" + accountId);
	accountPassword.setTitle(R.string.settings_padherder_password_title);
	accountPassword.setDialogTitle(R.string.settings_padherder_password_title);
	accountPassword.setSummary(R.string.settings_padherder_password_summary);
	accountPassword.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
	accountCategory.addPreference(accountPassword);

	MyLog.exit();
}
 
Example 12
Source File: Pref.java    From GeoLog with Apache License 2.0 5 votes vote down vote up
public static EditTextPreference Edit(Context context, PreferenceCategory category, String caption, String summary, String dialogCaption, String key, Object defaultValue, boolean enabled, Integer type) {
	EditTextPreference retval = new EditTextPreference(context);
	retval.setTitle(caption);
	retval.setSummary(summary);
	retval.setEnabled(enabled);
	retval.setKey(key);
	retval.setDefaultValue(defaultValue);
	retval.setDialogTitle(dialogCaption);
	if (type != null) {
		retval.getEditText().setInputType(type);
	}
	if (category != null) category.addPreference(retval);
	return retval;
}
 
Example 13
Source File: CastPreference.java    From CastVideos-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.application_preference);
    getPreferenceScreen().getSharedPreferences().
            registerOnSharedPreferenceChangeListener(this);

    EditTextPreference versionPref = (EditTextPreference) findPreference("app_version");
    versionPref.setTitle(getString(R.string.version, Utils.getAppVersionName(this)));
}
 
Example 14
Source File: MakabaModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
/** Добавить категорию настроек домена (в т.ч. https) */
private void addDomainPreferences(PreferenceGroup group) {
    Context context = group.getContext();
    Preference.OnPreferenceChangeListener updateDomainListener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals(getSharedKey(PREF_KEY_DOMAIN))) {
                updateDomain((String) newValue, preferences.getBoolean(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA), true));
                return true;
            } else if (preference.getKey().equals(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA))) {
                updateDomain(preferences.getString(getSharedKey(PREF_KEY_DOMAIN), DEFAULT_DOMAIN), (boolean)newValue);
                return true;
            }
            return false;
        }
    };
    PreferenceCategory domainCat = new PreferenceCategory(context);
    domainCat.setTitle(R.string.makaba_prefs_domain_category);
    group.addPreference(domainCat);
    EditTextPreference domainPref = new EditTextPreference(context); //поле ввода домена
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.getEditText().setHint(DEFAULT_DOMAIN);
    domainPref.getEditText().setSingleLine();
    domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    domainPref.setOnPreferenceChangeListener(updateDomainListener);
    domainCat.addPreference(domainPref);
    CheckBoxPreference httpsPref = new LazyPreferences.CheckBoxPreference(context); //чекбокс "использовать https"
    httpsPref.setTitle(R.string.pref_use_https);
    httpsPref.setSummary(R.string.pref_use_https_summary);
    httpsPref.setKey(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA));
    httpsPref.setDefaultValue(true);
    httpsPref.setOnPreferenceChangeListener(updateDomainListener);
    domainCat.addPreference(httpsPref);
}
 
Example 15
Source File: SettingsActivity.java    From Paddle-Lite-Demo with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }

    // Face detector
    // Initialize pre-installed models
    fdtPreInstalledModelDirs = new ArrayList<String>();
    fdtPreInstalledCPUThreadNums = new ArrayList<String>();
    fdtPreInstalledCPUPowerModes = new ArrayList<String>();
    fdtPreInstalledInputScales = new ArrayList<String>();
    fdtPreInstalledInputMeans = new ArrayList<String>();
    fdtPreInstalledInputStds = new ArrayList<String>();
    fdtPreInstalledScoreThresholds = new ArrayList<String>();
    fdtPreInstalledModelDirs.add(getString(R.string.FDT_MODEL_DIR_DEFAULT));
    fdtPreInstalledCPUThreadNums.add(getString(R.string.FDT_CPU_THREAD_NUM_DEFAULT));
    fdtPreInstalledCPUPowerModes.add(getString(R.string.FDT_CPU_POWER_MODE_DEFAULT));
    fdtPreInstalledInputScales.add(getString(R.string.FDT_INPUT_SCALE_DEFAULT));
    fdtPreInstalledInputMeans.add(getString(R.string.FDT_INPUT_MEAN_DEFAULT));
    fdtPreInstalledInputStds.add(getString(R.string.FDT_INPUT_STD_DEFAULT));
    fdtPreInstalledScoreThresholds.add(getString(R.string.FDT_SCORE_THRESHOLD_DEFAULT));
    // Setup UI components
    lpFdtChoosePreInstalledModel =
            (ListPreference) findPreference(getString(R.string.FDT_CHOOSE_PRE_INSTALLED_MODEL_KEY));
    String[] fdtPreInstalledModelNames = new String[fdtPreInstalledModelDirs.size()];
    for (int i = 0; i < fdtPreInstalledModelDirs.size(); i++) {
        fdtPreInstalledModelNames[i] =
                fdtPreInstalledModelDirs.get(i).substring(fdtPreInstalledModelDirs.get(i).lastIndexOf("/") + 1);
    }
    lpFdtChoosePreInstalledModel.setEntries(fdtPreInstalledModelNames);
    lpFdtChoosePreInstalledModel.setEntryValues(fdtPreInstalledModelDirs.toArray(new String[fdtPreInstalledModelDirs.size()]));
    lpFdtCPUThreadNum =
            (ListPreference) findPreference(getString(R.string.FDT_CPU_THREAD_NUM_KEY));
    lpFdtCPUPowerMode =
            (ListPreference) findPreference(getString(R.string.FDT_CPU_POWER_MODE_KEY));
    etFdtModelDir = (EditTextPreference) findPreference(getString(R.string.FDT_MODEL_DIR_KEY));
    etFdtModelDir.setTitle("Model dir (SDCard: " + Utils.getSDCardDirectory() + ")");
    etFdtInputScale = (EditTextPreference) findPreference(getString(R.string.FDT_INPUT_SCALE_KEY));
    etFdtInputMean = (EditTextPreference) findPreference(getString(R.string.FDT_INPUT_MEAN_KEY));
    etFdtInputStd = (EditTextPreference) findPreference(getString(R.string.FDT_INPUT_STD_KEY));
    etFdtScoreThreshold = (EditTextPreference) findPreference(getString(R.string.FDT_SCORE_THRESHOLD_KEY));

    // Face keypoints detector
    // Initialize pre-installed models
    fkpPreInstalledModelDirs = new ArrayList<String>();
    fkpPreInstalledCPUThreadNums = new ArrayList<String>();
    fkpPreInstalledCPUPowerModes = new ArrayList<String>();
    fkpPreInstalledInputWidths = new ArrayList<String>();
    fkpPreInstalledInputHeights = new ArrayList<String>();
    fkpPreInstalledModelDirs.add(getString(R.string.FKP_MODEL_DIR_DEFAULT));
    fkpPreInstalledCPUThreadNums.add(getString(R.string.FKP_CPU_THREAD_NUM_DEFAULT));
    fkpPreInstalledCPUPowerModes.add(getString(R.string.FKP_CPU_POWER_MODE_DEFAULT));
    fkpPreInstalledInputWidths.add(getString(R.string.FKP_INPUT_WIDTH_DEFAULT));
    fkpPreInstalledInputHeights.add(getString(R.string.FKP_INPUT_HEIGHT_DEFAULT));
    // Setup UI components
    lpFkpChoosePreInstalledModel =
            (ListPreference) findPreference(getString(R.string.FKP_CHOOSE_PRE_INSTALLED_MODEL_KEY));
    String[] fkpPreInstalledModelNames = new String[fkpPreInstalledModelDirs.size()];
    for (int i = 0; i < fkpPreInstalledModelDirs.size(); i++) {
        fkpPreInstalledModelNames[i] =
                fkpPreInstalledModelDirs.get(i).substring(fkpPreInstalledModelDirs.get(i).lastIndexOf("/") + 1);
    }
    lpFkpChoosePreInstalledModel.setEntries(fkpPreInstalledModelNames);
    lpFkpChoosePreInstalledModel.setEntryValues(fkpPreInstalledModelDirs.toArray(new String[fkpPreInstalledModelDirs.size()]));
    lpFkpCPUThreadNum =
            (ListPreference) findPreference(getString(R.string.FKP_CPU_THREAD_NUM_KEY));
    lpFkpCPUPowerMode =
            (ListPreference) findPreference(getString(R.string.FKP_CPU_POWER_MODE_KEY));
    etFkpModelDir = (EditTextPreference) findPreference(getString(R.string.FKP_MODEL_DIR_KEY));
    etFkpModelDir.setTitle("Model dir (SDCard: " + Utils.getSDCardDirectory() + ")");
    etFkpInputWidth = (EditTextPreference) findPreference(getString(R.string.FKP_INPUT_WIDTH_KEY));
    etFkpInputHeight = (EditTextPreference) findPreference(getString(R.string.FKP_INPUT_HEIGHT_KEY));
}
 
Example 16
Source File: SettingsActivity.java    From Paddle-Lite-Demo with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }

    // Face detector
    // Initialize pre-installed models
    fdtPreInstalledModelDirs = new ArrayList<String>();
    fdtPreInstalledCPUThreadNums = new ArrayList<String>();
    fdtPreInstalledCPUPowerModes = new ArrayList<String>();
    fdtPreInstalledInputScales = new ArrayList<String>();
    fdtPreInstalledInputMeans = new ArrayList<String>();
    fdtPreInstalledInputStds = new ArrayList<String>();
    fdtPreInstalledScoreThresholds = new ArrayList<String>();
    fdtPreInstalledModelDirs.add(getString(R.string.FDT_MODEL_DIR_DEFAULT));
    fdtPreInstalledCPUThreadNums.add(getString(R.string.FDT_CPU_THREAD_NUM_DEFAULT));
    fdtPreInstalledCPUPowerModes.add(getString(R.string.FDT_CPU_POWER_MODE_DEFAULT));
    fdtPreInstalledInputScales.add(getString(R.string.FDT_INPUT_SCALE_DEFAULT));
    fdtPreInstalledInputMeans.add(getString(R.string.FDT_INPUT_MEAN_DEFAULT));
    fdtPreInstalledInputStds.add(getString(R.string.FDT_INPUT_STD_DEFAULT));
    fdtPreInstalledScoreThresholds.add(getString(R.string.FDT_SCORE_THRESHOLD_DEFAULT));
    // Setup UI components
    lpFdtChoosePreInstalledModel =
            (ListPreference) findPreference(getString(R.string.FDT_CHOOSE_PRE_INSTALLED_MODEL_KEY));
    String[] fdtPreInstalledModelNames = new String[fdtPreInstalledModelDirs.size()];
    for (int i = 0; i < fdtPreInstalledModelDirs.size(); i++) {
        fdtPreInstalledModelNames[i] =
                fdtPreInstalledModelDirs.get(i).substring(fdtPreInstalledModelDirs.get(i).lastIndexOf("/") + 1);
    }
    lpFdtChoosePreInstalledModel.setEntries(fdtPreInstalledModelNames);
    lpFdtChoosePreInstalledModel.setEntryValues(fdtPreInstalledModelDirs.toArray(new String[fdtPreInstalledModelDirs.size()]));
    lpFdtCPUThreadNum =
            (ListPreference) findPreference(getString(R.string.FDT_CPU_THREAD_NUM_KEY));
    lpFdtCPUPowerMode =
            (ListPreference) findPreference(getString(R.string.FDT_CPU_POWER_MODE_KEY));
    etFdtModelDir = (EditTextPreference) findPreference(getString(R.string.FDT_MODEL_DIR_KEY));
    etFdtModelDir.setTitle("Model dir (SDCard: " + Utils.getSDCardDirectory() + ")");
    etFdtInputScale = (EditTextPreference) findPreference(getString(R.string.FDT_INPUT_SCALE_KEY));
    etFdtInputMean = (EditTextPreference) findPreference(getString(R.string.FDT_INPUT_MEAN_KEY));
    etFdtInputStd = (EditTextPreference) findPreference(getString(R.string.FDT_INPUT_STD_KEY));
    etFdtScoreThreshold = (EditTextPreference) findPreference(getString(R.string.FDT_SCORE_THRESHOLD_KEY));

    // Mask classifier
    // Initialize pre-installed models
    mclPreInstalledModelDirs = new ArrayList<String>();
    mclPreInstalledCPUThreadNums = new ArrayList<String>();
    mclPreInstalledCPUPowerModes = new ArrayList<String>();
    mclPreInstalledInputWidths = new ArrayList<String>();
    mclPreInstalledInputHeights = new ArrayList<String>();
    mclPreInstalledInputMeans = new ArrayList<String>();
    mclPreInstalledInputStds = new ArrayList<String>();
    mclPreInstalledModelDirs.add(getString(R.string.MCL_MODEL_DIR_DEFAULT));
    mclPreInstalledCPUThreadNums.add(getString(R.string.MCL_CPU_THREAD_NUM_DEFAULT));
    mclPreInstalledCPUPowerModes.add(getString(R.string.MCL_CPU_POWER_MODE_DEFAULT));
    mclPreInstalledInputWidths.add(getString(R.string.MCL_INPUT_WIDTH_DEFAULT));
    mclPreInstalledInputHeights.add(getString(R.string.MCL_INPUT_HEIGHT_DEFAULT));
    mclPreInstalledInputMeans.add(getString(R.string.MCL_INPUT_MEAN_DEFAULT));
    mclPreInstalledInputStds.add(getString(R.string.MCL_INPUT_STD_DEFAULT));
    // Setup UI components
    lpMclChoosePreInstalledModel =
            (ListPreference) findPreference(getString(R.string.MCL_CHOOSE_PRE_INSTALLED_MODEL_KEY));
    String[] mclPreInstalledModelNames = new String[mclPreInstalledModelDirs.size()];
    for (int i = 0; i < mclPreInstalledModelDirs.size(); i++) {
        mclPreInstalledModelNames[i] =
                mclPreInstalledModelDirs.get(i).substring(mclPreInstalledModelDirs.get(i).lastIndexOf("/") + 1);
    }
    lpMclChoosePreInstalledModel.setEntries(mclPreInstalledModelNames);
    lpMclChoosePreInstalledModel.setEntryValues(mclPreInstalledModelDirs.toArray(new String[mclPreInstalledModelDirs.size()]));
    lpMclCPUThreadNum =
            (ListPreference) findPreference(getString(R.string.MCL_CPU_THREAD_NUM_KEY));
    lpMclCPUPowerMode =
            (ListPreference) findPreference(getString(R.string.MCL_CPU_POWER_MODE_KEY));
    etMclModelDir = (EditTextPreference) findPreference(getString(R.string.MCL_MODEL_DIR_KEY));
    etMclModelDir.setTitle("Model dir (SDCard: " + Utils.getSDCardDirectory() + ")");
    etMclInputWidth = (EditTextPreference) findPreference(getString(R.string.MCL_INPUT_WIDTH_KEY));
    etMclInputHeight = (EditTextPreference) findPreference(getString(R.string.MCL_INPUT_HEIGHT_KEY));
    etMclInputMean = (EditTextPreference) findPreference(getString(R.string.MCL_INPUT_MEAN_KEY));
    etMclInputStd = (EditTextPreference) findPreference(getString(R.string.MCL_INPUT_STD_KEY));
}
 
Example 17
Source File: SettingsActivity.java    From Paddle-Lite-Demo with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }

    // Initialized pre-installed models
    preInstalledModelPaths = new ArrayList<String>();
    preInstalledLabelPaths = new ArrayList<String>();
    preInstalledImagePaths = new ArrayList<String>();
    preInstalledInputShapes = new ArrayList<String>();
    preInstalledCPUThreadNums = new ArrayList<String>();
    preInstalledCPUPowerModes = new ArrayList<String>();
    preInstalledInputColorFormats = new ArrayList<String>();
    preInstalledInputMeans = new ArrayList<String>();
    preInstalledInputStds = new ArrayList<String>();
    // Add mobilenet_v1_for_cpu
    preInstalledModelPaths.add(getString(R.string.MODEL_PATH_DEFAULT));
    preInstalledLabelPaths.add(getString(R.string.LABEL_PATH_DEFAULT));
    preInstalledImagePaths.add(getString(R.string.IMAGE_PATH_DEFAULT));
    preInstalledCPUThreadNums.add(getString(R.string.CPU_THREAD_NUM_DEFAULT));
    preInstalledCPUPowerModes.add(getString(R.string.CPU_POWER_MODE_DEFAULT));
    preInstalledInputColorFormats.add(getString(R.string.INPUT_COLOR_FORMAT_DEFAULT));
    preInstalledInputShapes.add(getString(R.string.INPUT_SHAPE_DEFAULT));
    preInstalledInputMeans.add(getString(R.string.INPUT_MEAN_DEFAULT));
    preInstalledInputStds.add(getString(R.string.INPUT_STD_DEFAULT));
    // Add mobilenet_v1_for_npu if Soc is kirin 810 or 990
    if (Utils.isSupportedNPU()) {
        preInstalledModelPaths.add("models/mobilenet_v1_for_npu");
        preInstalledLabelPaths.add("labels/synset_words.txt");
        preInstalledImagePaths.add("images/tabby_cat.jpg");
        preInstalledCPUThreadNums.add("1"); // Useless for NPU
        preInstalledCPUPowerModes.add("LITE_POWER_HIGH");  // Useless for NPU
        preInstalledInputColorFormats.add("RGB");
        preInstalledInputShapes.add("1,3,224,224");
        preInstalledInputMeans.add("0.485,0.456,0.406");
        preInstalledInputStds.add("0.229,0.224,0.225");
    } else {
        Toast.makeText(this, "NPU model is not supported by your device.", Toast.LENGTH_LONG).show();
    }

    // Setup UI components
    lpChoosePreInstalledModel =
            (ListPreference) findPreference(getString(R.string.CHOOSE_PRE_INSTALLED_MODEL_KEY));
    String[] preInstalledModelNames = new String[preInstalledModelPaths.size()];
    for (int i = 0; i < preInstalledModelPaths.size(); i++) {
        preInstalledModelNames[i] =
                preInstalledModelPaths.get(i).substring(preInstalledModelPaths.get(i).lastIndexOf("/") + 1);
    }
    lpChoosePreInstalledModel.setEntries(preInstalledModelNames);
    lpChoosePreInstalledModel.setEntryValues(preInstalledModelPaths.toArray(new String[preInstalledModelPaths.size()]));
    lpCPUThreadNum =
            (ListPreference) findPreference(getString(R.string.CPU_THREAD_NUM_KEY));
    lpCPUPowerMode =
            (ListPreference) findPreference(getString(R.string.CPU_POWER_MODE_KEY));
    cbEnableCustomSettings =
            (CheckBoxPreference) findPreference(getString(R.string.ENABLE_CUSTOM_SETTINGS_KEY));
    etModelPath = (EditTextPreference) findPreference(getString(R.string.MODEL_PATH_KEY));
    etModelPath.setTitle("Model Path (SDCard: " + Utils.getSDCardDirectory() + ")");
    etLabelPath = (EditTextPreference) findPreference(getString(R.string.LABEL_PATH_KEY));
    etImagePath = (EditTextPreference) findPreference(getString(R.string.IMAGE_PATH_KEY));
    lpInputColorFormat =
            (ListPreference) findPreference(getString(R.string.INPUT_COLOR_FORMAT_KEY));
    etInputShape = (EditTextPreference) findPreference(getString(R.string.INPUT_SHAPE_KEY));
    etInputMean = (EditTextPreference) findPreference(getString(R.string.INPUT_MEAN_KEY));
    etInputStd = (EditTextPreference) findPreference(getString(R.string.INPUT_STD_KEY));
}
 
Example 18
Source File: SettingsActivity.java    From Paddle-Lite-Demo with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }

    // Initialize pre-installed models
    preInstalledModelDirs = new ArrayList<String>();
    preInstalledLabelPaths = new ArrayList<String>();
    preInstalledCPUThreadNums = new ArrayList<String>();
    preInstalledCPUPowerModes = new ArrayList<String>();
    preInstalledInputWidths = new ArrayList<String>();
    preInstalledInputHeights = new ArrayList<String>();
    preInstalledInputMeans = new ArrayList<String>();
    preInstalledInputStds = new ArrayList<String>();
    preInstalledScoreThresholds = new ArrayList<String>();
    preInstalledModelDirs.add(getString(R.string.MODEL_DIR_DEFAULT));
    preInstalledLabelPaths.add(getString(R.string.LABEL_PATH_DEFAULT));
    preInstalledCPUThreadNums.add(getString(R.string.CPU_THREAD_NUM_DEFAULT));
    preInstalledCPUPowerModes.add(getString(R.string.CPU_POWER_MODE_DEFAULT));
    preInstalledInputWidths.add(getString(R.string.INPUT_WIDTH_DEFAULT));
    preInstalledInputHeights.add(getString(R.string.INPUT_HEIGHT_DEFAULT));
    preInstalledInputMeans.add(getString(R.string.INPUT_MEAN_DEFAULT));
    preInstalledInputStds.add(getString(R.string.INPUT_STD_DEFAULT));
    preInstalledScoreThresholds.add(getString(R.string.SCORE_THRESHOLD_DEFAULT));
    // Add yolov3_mobilenet_v3_for_hybrid_cpu_npu for CPU and huawei NPU
    if (Utils.isSupportedNPU()) {
        preInstalledModelDirs.add("models/yolov3_mobilenet_v3_for_hybrid_cpu_npu");
        preInstalledLabelPaths.add("labels/coco-labels-2014_2017.txt");
        preInstalledCPUThreadNums.add("1"); // Useless for NPU
        preInstalledCPUPowerModes.add("LITE_POWER_HIGH");  // Useless for NPU
        preInstalledInputWidths.add("320");
        preInstalledInputHeights.add("320");
        preInstalledInputMeans.add("0.485,0.456,0.406");
        preInstalledInputStds.add("0.229,0.224,0.225");
        preInstalledScoreThresholds.add("0.2");
    } else {
        Toast.makeText(this, "NPU model is not supported by your device.", Toast.LENGTH_LONG).show();
    }
    // Setup UI components
    lpChoosePreInstalledModel =
            (ListPreference) findPreference(getString(R.string.CHOOSE_PRE_INSTALLED_MODEL_KEY));
    String[] preInstalledModelNames = new String[preInstalledModelDirs.size()];
    for (int i = 0; i < preInstalledModelDirs.size(); i++) {
        preInstalledModelNames[i] = preInstalledModelDirs.get(i).substring(preInstalledModelDirs.get(i).lastIndexOf("/") + 1);
    }
    lpChoosePreInstalledModel.setEntries(preInstalledModelNames);
    lpChoosePreInstalledModel.setEntryValues(preInstalledModelDirs.toArray(new String[preInstalledModelDirs.size()]));
    lpCPUThreadNum = (ListPreference) findPreference(getString(R.string.CPU_THREAD_NUM_KEY));
    lpCPUPowerMode = (ListPreference) findPreference(getString(R.string.CPU_POWER_MODE_KEY));
    etModelDir = (EditTextPreference) findPreference(getString(R.string.MODEL_DIR_KEY));
    etModelDir.setTitle("Model dir (SDCard: " + Utils.getSDCardDirectory() + ")");
    etLabelPath = (EditTextPreference) findPreference(getString(R.string.LABEL_PATH_KEY));
    etLabelPath.setTitle("Label path (SDCard: " + Utils.getSDCardDirectory() + ")");
    etInputWidth = (EditTextPreference) findPreference(getString(R.string.INPUT_WIDTH_KEY));
    etInputHeight = (EditTextPreference) findPreference(getString(R.string.INPUT_HEIGHT_KEY));
    etInputMean = (EditTextPreference) findPreference(getString(R.string.INPUT_MEAN_KEY));
    etInputStd = (EditTextPreference) findPreference(getString(R.string.INPUT_STD_KEY));
    etScoreThreshold = (EditTextPreference) findPreference(getString(R.string.SCORE_THRESHOLD_KEY));
}
 
Example 19
Source File: SettingsActivity.java    From Paddle-Lite-Demo with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }

    // Initialize pre-installed models
    preInstalledModelDirs = new ArrayList<String>();
    preInstalledLabelPaths = new ArrayList<String>();
    preInstalledCPUThreadNums = new ArrayList<String>();
    preInstalledCPUPowerModes = new ArrayList<String>();
    preInstalledInputWidths = new ArrayList<String>();
    preInstalledInputHeights = new ArrayList<String>();
    preInstalledInputMeans = new ArrayList<String>();
    preInstalledInputStds = new ArrayList<String>();
    preInstalledModelDirs.add(getString(R.string.MODEL_DIR_DEFAULT));
    preInstalledLabelPaths.add(getString(R.string.LABEL_PATH_DEFAULT));
    preInstalledCPUThreadNums.add(getString(R.string.CPU_THREAD_NUM_DEFAULT));
    preInstalledCPUPowerModes.add(getString(R.string.CPU_POWER_MODE_DEFAULT));
    preInstalledInputWidths.add(getString(R.string.INPUT_WIDTH_DEFAULT));
    preInstalledInputHeights.add(getString(R.string.INPUT_HEIGHT_DEFAULT));
    preInstalledInputMeans.add(getString(R.string.INPUT_MEAN_DEFAULT));
    preInstalledInputStds.add(getString(R.string.INPUT_STD_DEFAULT));
    // Add mobilenet_v1_for_npu if Soc is kirin 810 or 990
    if (Utils.isSupportedNPU()) {
        preInstalledModelDirs.add("models/mobilenet_v1_for_npu");
        preInstalledLabelPaths.add("labels/synset_words.txt");
        preInstalledCPUThreadNums.add("1"); // Useless for NPU
        preInstalledCPUPowerModes.add("LITE_POWER_HIGH");  // Useless for NPU
        preInstalledInputWidths.add("224");
        preInstalledInputHeights.add("224");
        preInstalledInputMeans.add("0.485,0.456,0.406");
        preInstalledInputStds.add("0.229,0.224,0.225");
    } else {
        Toast.makeText(this, "NPU model is not supported by your device.", Toast.LENGTH_LONG).show();
    }
    // Setup UI components
    lpChoosePreInstalledModel =
            (ListPreference) findPreference(getString(R.string.CHOOSE_PRE_INSTALLED_MODEL_KEY));
    String[] preInstalledModelNames = new String[preInstalledModelDirs.size()];
    for (int i = 0; i < preInstalledModelDirs.size(); i++) {
        preInstalledModelNames[i] = preInstalledModelDirs.get(i).substring(preInstalledModelDirs.get(i).lastIndexOf("/") + 1);
    }
    lpChoosePreInstalledModel.setEntries(preInstalledModelNames);
    lpChoosePreInstalledModel.setEntryValues(preInstalledModelDirs.toArray(new String[preInstalledModelDirs.size()]));
    lpCPUThreadNum = (ListPreference) findPreference(getString(R.string.CPU_THREAD_NUM_KEY));
    lpCPUPowerMode = (ListPreference) findPreference(getString(R.string.CPU_POWER_MODE_KEY));
    etModelDir = (EditTextPreference) findPreference(getString(R.string.MODEL_DIR_KEY));
    etModelDir.setTitle("Model dir (SDCard: " + Utils.getSDCardDirectory() + ")");
    etLabelPath = (EditTextPreference) findPreference(getString(R.string.LABEL_PATH_KEY));
    etLabelPath.setTitle("Label path (SDCard: " + Utils.getSDCardDirectory() + ")");
    etInputWidth = (EditTextPreference) findPreference(getString(R.string.INPUT_WIDTH_KEY));
    etInputHeight = (EditTextPreference) findPreference(getString(R.string.INPUT_HEIGHT_KEY));
    etInputMean = (EditTextPreference) findPreference(getString(R.string.INPUT_MEAN_KEY));
    etInputStd = (EditTextPreference) findPreference(getString(R.string.INPUT_STD_KEY));
}
 
Example 20
Source File: SettingsActivity.java    From javainstaller with GNU General Public License v3.0 4 votes vote down vote up
private PreferenceScreen createPreferenceHierarchy() {

       CharSequence[] cs = new String[] { "Terminal Emulator", "Run Activity", "auto" };
       CharSequence[] cs2 = new String[] { "off", "on" };

       // Root
       PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
       PreferenceCategory dialogBasedPrefCat = new PreferenceCategory(this);
       dialogBasedPrefCat.setTitle("install");
       root.addPreference(dialogBasedPrefCat); // Adding a category

       // List preference under the category
       ListPreference listPref = new ListPreference(this);
       listPref.setKey("runmode");
       listPref.setDefaultValue(cs[2]);
       listPref.setEntries(cs);
       listPref.setEntryValues(cs);
       listPref.setDialogTitle("run install.sh in");
       listPref.setTitle("run install.sh in");
       listPref.setSummary("run install.sh in");
       dialogBasedPrefCat.addPreference(listPref);
       ListPreference rootmode = new ListPreference(this);
       rootmode.setKey("rootmode");
       rootmode.setDefaultValue(cs2[0]);
       rootmode.setEntries(cs2);
       rootmode.setEntryValues(cs2);
       rootmode.setDialogTitle("run install.sh as superuser");
       rootmode.setTitle("run install.sh as superuser");
       rootmode.setSummary("root required");
       dialogBasedPrefCat.addPreference(rootmode);
       
       PreferenceCategory dialogBasedPrefCat2 = new PreferenceCategory(this);
       dialogBasedPrefCat2.setTitle("run");
       root.addPreference(dialogBasedPrefCat2); // Adding a category

       // List preference under the category
       CharSequence[] csjar = new String[] { "Terminal Emulator", "Run Activity" };
       ListPreference listPref2 = new ListPreference(this);
       listPref2.setKey("runmode2");
       listPref2.setDefaultValue(csjar[1]);
       listPref2.setEntries(csjar);
       listPref2.setEntryValues(csjar);
       listPref2.setDialogTitle("run jar file in");
       listPref2.setTitle("run jar file in");
       listPref2.setSummary("run jar file in");
       dialogBasedPrefCat2.addPreference(listPref2);
       ListPreference rootmode2 = new ListPreference(this);
       rootmode2.setKey("rootmode2");
       rootmode2.setDefaultValue(cs2[0]);
       rootmode2.setEntries(cs2);
       rootmode2.setEntryValues(cs2);
       rootmode2.setDialogTitle("run jar file as superuser");
       rootmode2.setTitle("run jar file as superuser");
       rootmode2.setSummary("root required");
       dialogBasedPrefCat2.addPreference(rootmode2);
       
       PreferenceCategory dialogBasedPrefCat3 = new PreferenceCategory(this);
       dialogBasedPrefCat3.setTitle("path broadcast");
       root.addPreference(dialogBasedPrefCat3); // Adding a category

       // List preference under the category
       CharSequence[] cspath = new String[] { "on", "off", "if jamvm is installed" };
       ListPreference listPref3 = new ListPreference(this);
       listPref3.setKey("broadcast");
       listPref3.setDefaultValue(cspath[2]);
       listPref3.setEntries(cspath);
       listPref3.setEntryValues(cspath);
       listPref3.setDialogTitle("broadcast path to terminal emulator");
       listPref3.setTitle("broadcast path to terminal emulator");
       listPref3.setSummary("broadcast path to terminal emulator");
       dialogBasedPrefCat3.addPreference(listPref3);
       EditTextPreference path = new EditTextPreference(this);
       path.setKey("broadcastpath");
       path.setDefaultValue("/data/data/julianwi.javainstaller");
       path.setDialogTitle("path to broadcast");
       path.setTitle("path to broadcast");
       path.setSummary("path to broadcast");
       dialogBasedPrefCat3.addPreference(path);

       return root;
   }