Java Code Examples for android.preference.ListPreference#setEntryValues()

The following examples show how to use android.preference.ListPreference#setEntryValues() . 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: SettingsFragment.java    From sms-ticket with Apache License 2.0 7 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private void fillDualSimList(PreferenceScreen preferenceScreen) {
    PreferenceCategory category = (PreferenceCategory) preferenceScreen.findPreference("sms_category");
    ListPreference preference = (ListPreference) category.findPreference(Preferences.DUALSIM_SIM);
    List<String> simIds = new ArrayList<>();
    List<String> simNames = new ArrayList<>();
    simIds.add(String.valueOf(Preferences.VALUE_DEFAULT_SIM));
    simNames.add(getString(R.string.sim_default));
    SubscriptionManager subscriptionManager = SubscriptionManager.from(getActivity());
    for (SubscriptionInfo subscriptionInfo : subscriptionManager.getActiveSubscriptionInfoList()) {
        simIds.add(String.valueOf(subscriptionInfo.getSubscriptionId()));
        simNames.add(getString(R.string.sim_name, subscriptionInfo.getSimSlotIndex() + 1, subscriptionInfo
            .getDisplayName()));
    }
    preference.setEntries(simNames.toArray(new String[simNames.size()]));
    preference.setEntryValues(simIds.toArray(new String[simIds.size()]));
    preference.setDefaultValue(String.valueOf(Preferences.VALUE_DEFAULT_SIM));
    preference.setSummary(preference.getEntry());
}
 
Example 2
Source File: SettingsFragment.java    From 600SeriesAndroidUploader with MIT License 6 votes vote down vote up
private void urchinStatusLayout(ListPreference listPref) {

        if (values == null || entries == null) {
            List<String> items = UrchinService.getListPreferenceItems();

            int size = items.size() / 2;
            values = new String[size];
            entries = new String[size];

            for (int i = 0, p = 0; i < size; i++) {
                values[i] = items.get(p++);
                entries[i] = items.get(p++);
            }
        }

        listPref.setEntryValues(values);
        listPref.setEntries(entries);
    }
 
Example 3
Source File: PluggableCalibration.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void setListPreferenceData(ListPreference p) {
    final Type[] types = Type.values();
    final CharSequence[] entries = new CharSequence[types.length];
    final CharSequence[] entryValues = new CharSequence[types.length];

    for (int i = 0; i < types.length; i++) {
        // Not sure exactly of what the overhead of this will be
        // perhaps we should save it to a cache...
        final CalibrationAbstract plugin = getCalibrationPlugin(types[i]);

        entries[i] = (plugin != null) ? plugin.getNiceNameAndDescription() : "None";
        entryValues[i] = types[i].toString();
    }
    p.setEntries(entries);
    p.setEntryValues(entryValues);
}
 
Example 4
Source File: DobroModule.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
private void addRatingPreference(PreferenceGroup group) {
    Context context = group.getContext();
    Preference.OnPreferenceChangeListener updateRatingListener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals(getSharedKey(PREF_KEY_MAX_RATING))) {
                setMaxRating((String) newValue);
                return true;
            }
            return false;
        }
    };
    ListPreference ratingPref = new LazyPreferences.ListPreference(context);
    ratingPref.setTitle(R.string.dobrochan_prefs_max_rating);
    ratingPref.setSummary(preferences.getString(getSharedKey(PREF_KEY_MAX_RATING), "R-15"));
    ratingPref.setEntries(RATINGS);
    ratingPref.setEntryValues(RATINGS);
    ratingPref.setDefaultValue("R-15");
    ratingPref.setKey(getSharedKey(PREF_KEY_MAX_RATING));
    ratingPref.setOnPreferenceChangeListener(updateRatingListener);
    group.addPreference(ratingPref);
}
 
Example 5
Source File: SettingsActivity.java    From AndrOBD with GNU General Public License v3.0 6 votes vote down vote up
/**
 * set up protocol selection
 */
void setupProtoSelection()
{
	ListPreference pref = (ListPreference) findPreference(KEY_PROT_SELECT);
	ElmProt.PROT[] values = ElmProt.PROT.values();
	CharSequence[] titles = new CharSequence[values.length];
	CharSequence[] keys = new CharSequence[values.length];
	int i = 0;
	for (ElmProt.PROT proto : values)
	{
		titles[i] = proto.toString();
		keys[i] = String.valueOf(proto.ordinal());
		i++;
	}
	// set enries and keys
	pref.setEntries(titles);
	pref.setEntryValues(keys);
	pref.setDefaultValue(titles[0]);
	// show current selection
	pref.setSummary(pref.getEntry());
}
 
Example 6
Source File: PluggableCalibration.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static void setListPreferenceData(ListPreference p) {
    final Type[] types = Type.values();
    final CharSequence[] entries = new CharSequence[types.length];
    final CharSequence[] entryValues = new CharSequence[types.length];

    for (int i = 0; i < types.length; i++) {
        // Not sure exactly of what the overhead of this will be
        // perhaps we should save it to a cache...
        final CalibrationAbstract plugin = getCalibrationPlugin(types[i]);

        entries[i] = (plugin != null) ? plugin.getNiceNameAndDescription() : "None";
        entryValues[i] = types[i].toString();
    }
    p.setEntries(entries);
    p.setEntryValues(entryValues);
}
 
Example 7
Source File: FetchingPrefFragment.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
private void addPrefetchMedia () {
	final ListPreference pref = new ListPreference(getActivity());
	pref.setKey(KEY_PREFETCH_MEDIA);
	pref.setTitle("Prefetch media"); //ES
	pref.setSummary("Fetch new pictures during background updates: %s"); //ES
	pref.setEntries(PrefetchMode.prefEntries());
	pref.setEntryValues(PrefetchMode.prefEntryValues());
	pref.setDefaultValue(PrefetchMode.NO.getValue());
	getPreferenceScreen().addPreference(pref);
}
 
Example 8
Source File: DeviceAdminSample.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.device_admin_quality);

    mQualityCategory = (PreferenceCategory) findPreference(KEY_CATEGORY_QUALITY);
    mPasswordQuality = (ListPreference) findPreference(KEY_QUALITY);
    mMinLength = (EditTextPreference) findPreference(KEY_MIN_LENGTH);
    mMinLetters = (EditTextPreference) findPreference(KEY_MIN_LETTERS);
    mMinNumeric = (EditTextPreference) findPreference(KEY_MIN_NUMERIC);
    mMinLowerCase = (EditTextPreference) findPreference(KEY_MIN_LOWER_CASE);
    mMinUpperCase = (EditTextPreference) findPreference(KEY_MIN_UPPER_CASE);
    mMinSymbols = (EditTextPreference) findPreference(KEY_MIN_SYMBOLS);
    mMinNonLetter = (EditTextPreference) findPreference(KEY_MIN_NON_LETTER);

    mPasswordQuality.setOnPreferenceChangeListener(this);
    mMinLength.setOnPreferenceChangeListener(this);
    mMinLetters.setOnPreferenceChangeListener(this);
    mMinNumeric.setOnPreferenceChangeListener(this);
    mMinLowerCase.setOnPreferenceChangeListener(this);
    mMinUpperCase.setOnPreferenceChangeListener(this);
    mMinSymbols.setOnPreferenceChangeListener(this);
    mMinNonLetter.setOnPreferenceChangeListener(this);

    // Finish setup of the quality dropdown
    mPasswordQuality.setEntryValues(mPasswordQualityValueStrings);
}
 
Example 9
Source File: SettingsActivity.java    From mOrgAnd with GNU General Public License v2.0 5 votes vote down vote up
private void populateCalendarNames() {
    try {
        ListPreference calendarName = (ListPreference) findPreference("calendar_name");

        CharSequence[] calendars = CalendarWrapper
                .getCalendars(getActivity());

        calendarName.setEntries(calendars);
        calendarName.setEntryValues(calendars);
    } catch (Exception e) {
        e.printStackTrace();
        // Don't crash because of anything in calendar
    }
}
 
Example 10
Source File: SynchModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    ListPreference domainPref = new LazyPreferences.ListPreference(context);
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setEntries(DOMAINS);
    domainPref.setEntryValues(DOMAINS);
    domainPref.setDefaultValue(DOMAINS[0]);
    preferenceGroup.addPreference(domainPref);
    super.addPreferencesOnScreen(preferenceGroup);
}
 
Example 11
Source File: SuntimesSettingsActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private static void initPref_locale(Activity activity, ListPreference localePref)
{
    final String[] localeDisplay = activity.getResources().getStringArray(R.array.locale_display);
    final String[] localeDisplayNative = activity.getResources().getStringArray(R.array.locale_display_native);
    final String[] localeValues = activity.getResources().getStringArray(R.array.locale_values);

    Integer[] index = getSortedOrder(localeDisplayNative);
    CharSequence[] entries = new CharSequence[localeValues.length];
    CharSequence[] values = new CharSequence[localeValues.length];
    for (int i=0; i<index.length; i++)
    {
        int j = index[i];
        CharSequence formattedDisplayString;
        CharSequence localeDisplay_j = (localeDisplay.length > j ? localeDisplay[j] : localeValues[j]);
        CharSequence localeDisplayNative_j = (localeDisplayNative.length > j ? localeDisplayNative[j] : localeValues[j]);

        if (localeDisplay_j.equals(localeDisplayNative_j)) {
            formattedDisplayString = localeDisplayNative_j;

        } else {
            String localizedName = "(" + localeDisplay_j + ")";
            String displayString = localeDisplayNative_j + " " + localizedName;
            formattedDisplayString = SuntimesUtils.createRelativeSpan(null, displayString, localizedName, 0.7f);
        }

        entries[i] = formattedDisplayString;
        values[i] = localeValues[j];
    }

    localePref.setEntries(entries);
    localePref.setEntryValues(values);

    AppSettings.LocaleMode localeMode = AppSettings.loadLocaleModePref(activity);
    localePref.setEnabled(localeMode == AppSettings.LocaleMode.CUSTOM_LOCALE);
}
 
Example 12
Source File: MyPreferencesActivity.java    From EasyVPN-Free with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    DBHelper dbHelper = new DBHelper(getActivity().getApplicationContext());
    List<Server> countryList = dbHelper.getUniqueCountries();
    CharSequence entriesValues[] = new CharSequence[countryList.size()];
    CharSequence entries[] = new CharSequence[countryList.size()];

    for (int i = 0; i < countryList.size(); i++) {
        entriesValues[i] = countryList.get(i).getCountryLong();
        String localeCountryName = CountriesNames.getCountries().get(countryList.get(i).getCountryShort()) != null ?
                CountriesNames.getCountries().get(countryList.get(i).getCountryShort()) :
                countryList.get(i).getCountryLong();
        entries[i] = localeCountryName;
    }

    ListPreference listPreference = (ListPreference) findPreference("selectedCountry");
    if (entries.length == 0) {
        PreferenceCategory countryPriorityCategory = (PreferenceCategory) findPreference("countryPriorityCategory");
        getPreferenceScreen().removePreference(countryPriorityCategory);
    } else {
        listPreference.setEntries(entries);
        listPreference.setEntryValues(entriesValues);
        if (PropertiesService.getSelectedCountry() == null)
            listPreference.setValueIndex(0);
    }
}
 
Example 13
Source File: BasePreferenceFragment.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public ListPreference makeList(PreferenceGroup parent, String key, CharSequence[] values,
		String defaultValue, int titleResId, CharSequence[] entries) {
	ListPreference preference = new ListPreference(getActivity());
	preference.setKey(key);
	preference.setTitle(titleResId);
	preference.setDialogTitle(titleResId);
	preference.setEntries(entries);
	preference.setEntryValues(values);
	if (defaultValue != null) {
		preference.setDefaultValue(defaultValue);
	}
	addPreference(parent, preference);
	updateListSummary(preference);
	return preference;
}
 
Example 14
Source File: TaskerQuickActionsActivity.java    From SecondScreen with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Close notification drawer
    Intent closeDrawer = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    sendBroadcast(closeDrawer);

    String key = "Null";
    String value = "Null";

    // Handle intents
    Intent quickLaunchIntent = getIntent();
    if((quickLaunchIntent.getStringExtra(U.KEY) != null) && (quickLaunchIntent.getStringExtra(U.VALUE) != null)) {
        key = quickLaunchIntent.getStringExtra(U.KEY);
        value = quickLaunchIntent.getStringExtra(U.VALUE);
        launchShortcut = true;
    }

    if(quickLaunchIntent.getBooleanExtra("launched-from-app", false))
        launchedFromApp = true;

    SharedPreferences prefMain = U.getPrefMain(this);
    if(!prefMain.getBoolean("first-run", false))
        finish();
    else if(launchShortcut) {
        if(key.equals("lock_device")) {
            Intent intent = new Intent(this, LockDeviceService.class);
            U.startService(this, intent);
            finish();
        } else if(key.equals("turn_off"))
            runResetSettings();
        else if(!key.equals("Null") && !value.equals("Null"))
            runQuickAction(key, value);
        else
            finish();
    } else {
        setTitle(getResources().getStringArray(R.array.pref_notification_action_list)[1]);

        if(launchedFromApp) {
            // Show dialog on first start
            if(!prefMain.getBoolean("quick_actions_dialog", false)) {
                SharedPreferences.Editor editor = prefMain.edit();
                editor.putBoolean("quick_actions_dialog", true);
                editor.apply();

                if(getFragmentManager().findFragmentByTag("quick_actions") == null) {
                    DialogFragment quickActionsFragment = new QuickActionsDialogFragment();
                    quickActionsFragment.show(getFragmentManager(), "quick_actions");
                }
            }

            SharedPreferences prefSaved = U.getPrefQuickActions(this);
            SharedPreferences prefCurrent = U.getPrefCurrent(this);
            loadCurrentProfile(prefSaved, prefCurrent);
        }

        // Add preferences
        addPreferencesFromResource(R.xml.quick_actions_preferences);

        // Modifications for certain scenarios
        if(prefMain.getBoolean("landscape", false)) {
            ListPreference size = (ListPreference) findPreference("temp_size");
            size.setEntryValues(R.array.pref_resolution_list_values_landscape);
        }

        // Set title and OnClickListener for "Lock Device"
        findPreference("lock_device").setTitle(getResources().getStringArray(R.array.pref_notification_action_list)[2]);
        findPreference("lock_device").setOnPreferenceClickListener(this);

        // Set OnClickListener for "Reset settings"
        findPreference("turn_off").setOnPreferenceClickListener(this);

        // Disable unsupported preferences
        if(!U.canEnableOverscan())
            disablePreference("temp_overscan");

        if(!U.canEnableImmersiveMode())
            disablePreference("temp_immersive_new");

        if(!U.canEnableFreeform(this))
            disablePreference("temp_freeform");

        if(U.getChromePackageName(this) == null)
            disablePreference("temp_chrome");

        if(U.isInNonRootMode(this)) {
            disablePreference("temp_hdmi_rotation");
            disablePreference("temp_chrome");
            disablePreference("temp_freeform");
        }

        // Set active state of "Reset settings" button
        if(launchedFromApp)
            resetSettingsButton();
    }
}
 
Example 15
Source File: SingleWebsitePreferences.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize a ListPreference with a certain value.
 * @param preference The ListPreference to initialize.
 * @param value The value to initialize it to.
 */
private void setUpListPreference(Preference preference, ContentSetting value) {
    if (value == null) {
        getPreferenceScreen().removePreference(preference);
        return;
    }

    ListPreference listPreference = (ListPreference) preference;

    int contentType = getContentSettingsTypeFromPreferenceKey(preference.getKey());
    CharSequence[] keys = new String[2];
    CharSequence[] descriptions = new String[2];
    keys[0] = ContentSetting.ALLOW.toString();
    keys[1] = ContentSetting.BLOCK.toString();
    descriptions[0] = getResources().getString(
            ContentSettingsResources.getSiteSummary(ContentSetting.ALLOW));
    descriptions[1] = getResources().getString(
            ContentSettingsResources.getSiteSummary(ContentSetting.BLOCK));
    listPreference.setEntryValues(keys);
    listPreference.setEntries(descriptions);
    int index = (value == ContentSetting.ALLOW ? 0 : 1);
    listPreference.setValueIndex(index);
    int explanationResourceId = ContentSettingsResources.getExplanation(contentType);
    if (explanationResourceId != 0) {
        listPreference.setTitle(explanationResourceId);
    }

    if (listPreference.isEnabled()) {
        SiteSettingsCategory category =
                SiteSettingsCategory.fromContentSettingsType(contentType);
        if (category != null && !category.enabledInAndroid(getActivity())) {
            listPreference.setIcon(category.getDisabledInAndroidIcon(getActivity()));
            listPreference.setEnabled(false);
        } else {
            listPreference.setIcon(ContentSettingsResources.getIcon(contentType));
        }
    } else {
        listPreference.setIcon(
                ContentSettingsResources.getDisabledIcon(contentType, getResources()));
    }

    preference.setSummary("%s");
    listPreference.setOnPreferenceChangeListener(this);
}
 
Example 16
Source File: SettingsActivity.java    From padland with Apache License 2.0 4 votes vote down vote up
private void setDefaultServerPreferenceValues() {
    String[] entries = (String[]) getArguments().get("server_name_list");
    final ListPreference defaultServer = (ListPreference) findPreference("padland_default_server");
    defaultServer.setEntries(entries);
    defaultServer.setEntryValues(entries);
}
 
Example 17
Source File: AdvancedSettingsFragment.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.prefs_screen_advanced);

    final Resources res = getResources();
    final Context context = getActivity();

    // When we are called from the Settings application but we are not already running, some
    // singleton and utility classes may not have been initialized.  We have to call
    // initialization method of these classes here. See {@link LatinIME#onCreate()}.
    AudioAndHapticFeedbackManager.init(context);

    final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();

    if (!Settings.isInternal(prefs)) {
        removePreference(Settings.SCREEN_DEBUG);
    }

    if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
        removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS);
    }

    // TODO: consolidate key preview dismiss delay with the key preview animation parameters.
    if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupOption(res)) {
        removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
    } else {
        // TODO: Cleanup this setup.
        final ListPreference keyPreviewPopupDismissDelay =
                (ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
        final String popupDismissDelayDefaultValue = Integer.toString(res.getInteger(
                R.integer.config_key_preview_linger_timeout));
        keyPreviewPopupDismissDelay.setEntries(new String[] {
                res.getString(R.string.key_preview_popup_dismiss_no_delay),
                res.getString(R.string.key_preview_popup_dismiss_default_delay),
        });
        keyPreviewPopupDismissDelay.setEntryValues(new String[] {
                "0",
                popupDismissDelayDefaultValue
        });
        if (null == keyPreviewPopupDismissDelay.getValue()) {
            keyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
        }
        keyPreviewPopupDismissDelay.setEnabled(
                Settings.readKeyPreviewPopupEnabled(prefs, res));
    }

    setupKeypressVibrationDurationSettings();
    setupKeypressSoundVolumeSettings();
    setupKeyLongpressTimeoutSettings();
    refreshEnablingsOfKeypressSoundAndVibrationSettings();
}
 
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);
    }

    // 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 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);
    }

    // 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>();
    preInstalledScoreThresholds = new ArrayList<String>();
    // Add ssd_mobilenet_v1_pascalvoc_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));
    preInstalledScoreThresholds.add(getString(R.string.SCORE_THRESHOLD_DEFAULT));
    // Add ssd_mobilenet_v1_pascalvoc_for_hybrid_cpu_npu if Soc is kirin 810 or 990
    if (Utils.isSupportedNPU()) {
        preInstalledModelPaths.add("models/ssd_mobilenet_v1_pascalvoc_for_hybrid_cpu_npu");
        preInstalledLabelPaths.add("labels/pascalvoc_label_list");
        preInstalledImagePaths.add("images/dog.jpg");
        preInstalledCPUThreadNums.add("1"); // Useless for NPU
        preInstalledCPUPowerModes.add("LITE_POWER_HIGH");  // Useless for NPU
        preInstalledInputColorFormats.add("RGB");
        preInstalledInputShapes.add("1,3,300,300");
        preInstalledInputMeans.add("0.5,0.5,0.5");
        preInstalledInputStds.add("0.5,0.5,0.5");
        preInstalledScoreThresholds.add("0.5");
    } 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()]));
    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));
    lpCPUThreadNum =
            (ListPreference) findPreference(getString(R.string.CPU_THREAD_NUM_KEY));
    lpCPUPowerMode =
            (ListPreference) findPreference(getString(R.string.CPU_POWER_MODE_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));
    etScoreThreshold = (EditTextPreference) findPreference(getString(R.string.SCORE_THRESHOLD_KEY));
}
 
Example 20
Source File: SettingsActivity.java    From Easycam with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
private void populateDeviceListPreference(ArrayList<DeviceEntry> validStreamingDeviceList,
									  ListPreference selectDevice) {

CharSequence[] entries;
CharSequence[] entryValues;

   if (validStreamingDeviceList.isEmpty()) {

    Log.i(TAG, "No V4L2 compatible streaming devices found on system");
	entries = new CharSequence[1];
	entryValues = new CharSequence[1];

	entries[0]  = "No devices found";
	entryValues[0] = "NO_DEVICE";

	selectDevice.setSummary(entries[0]);

   }
   else {

    entries = new CharSequence[validStreamingDeviceList.size()];
    entryValues = new CharSequence[validStreamingDeviceList.size()];

    for (int i = 0; i < validStreamingDeviceList.size(); i++) {

	    entries[i] = validStreamingDeviceList.get(i).deviceDescription;
	    entryValues[i] = validStreamingDeviceList.get(i).deviceName;

    }
   }

selectDevice.setEntries(entries);
selectDevice.setEntryValues(entryValues);
  }