Example usage for android.text TextUtils join

List of usage examples for android.text TextUtils join

Introduction

In this page you can find the example usage for android.text TextUtils join.

Prototype

public static String join(@NonNull CharSequence delimiter, @NonNull Iterable tokens) 

Source Link

Document

Returns a string containing the tokens joined by delimiters.

Usage

From source file:com.facebook.internal.Utility.java

private static GraphObject getAppSettingsQueryResponse(String applicationId) {
    Bundle appSettingsParams = new Bundle();
    appSettingsParams.putString(APPLICATION_FIELDS, TextUtils.join(",", APP_SETTING_FIELDS));

    Request request = Request.newGraphPathRequest(null, applicationId, null);
    request.setSkipClientToken(true);//from  ww w  . j a v a 2  s .co m
    request.setParameters(appSettingsParams);

    GraphObject response = request.executeAndWait().getGraphObject();
    return response;
}

From source file:org.alfresco.mobile.android.api.services.impl.onpremise.OnPremiseWorkflowServiceImpl.java

/**
 * @param task//from   ww w.  jav a2s. c om
 * @param items
 * @param isAddition
 */
private void updateDocuments(Task task, List<Document> items, boolean isAddition) {
    try {
        String variableKey = OnPremiseConstant.ASSOC_PACKAGEITEMS_REMOVED_VALUE;
        if (isAddition) {
            variableKey = OnPremiseConstant.ASSOC_PACKAGEITEMS_ADDED_VALUE;
        }
        List<String> variablesItems = new ArrayList<String>(items.size());
        for (Node node : items) {
            variablesItems.add(NodeRefUtils.getCleanIdentifier(node.getIdentifier()));
        }
        Map<String, Serializable> variables = new HashMap<String, Serializable>();
        variables.put(variableKey, TextUtils.join(",", variablesItems.toArray(new String[0])));
        updateVariables(task, variables);
    } catch (Exception e) {
        convertException(e);
    }
}

From source file:com.master.metehan.filtereagle.ActivitySettings.java

@Override
@TargetApi(Build.VERSION_CODES.M)/*  w  w  w .  ja v a  2  s. c  o m*/
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
    // Pro features
    if ("theme".equals(name)) {
        if (!"teal".equals(prefs.getString(name, "teal")) && !IAB.isPurchased(ActivityPro.SKU_THEME, this)) {
            prefs.edit().putString(name, "teal").apply();
            ((ListPreference) getPreferenceScreen().findPreference(name)).setValue("teal");
            startActivity(new Intent(this, ActivityPro.class));
            return;
        }
    } else if ("show_stats".equals(name)) {
        if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_SPEED, this)) {
            prefs.edit().putBoolean(name, false).apply();
            ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false);
            startActivity(new Intent(this, ActivityPro.class));
            return;
        }
    } else if ("install".equals(name)) {
        if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_NOTIFY, this)) {
            prefs.edit().putBoolean(name, false).apply();
            ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false);
            startActivity(new Intent(this, ActivityPro.class));
            return;
        }
    }

    Object value = prefs.getAll().get(name);
    if (value instanceof String && "".equals(value))
        prefs.edit().remove(name).apply();

    // Dependencies
    if ("whitelist_wifi".equals(name) || "screen_wifi".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("whitelist_other".equals(name) || "screen_other".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("whitelist_roaming".equals(name)) {
        if (prefs.getBoolean(name, false)) {
            if (Util.hasPhoneStatePermission(this))
                ServiceSinkhole.reload("changed " + name, this);
            else
                requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE },
                        REQUEST_ROAMING_INTERNATIONAL);
        } else
            ServiceSinkhole.reload("changed " + name, this);

    } else if ("auto_enable".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_auto, prefs.getString(name, "0")));

    else if ("screen_delay".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_delay, prefs.getString(name, "0")));

    else if ("theme".equals(name) || "dark_theme".equals(name))
        recreate();

    else if ("subnet".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("tethering".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("lan".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("ip6".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("wifi_homes".equals(name)) {
        MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) getPreferenceScreen()
                .findPreference(name);
        Set<String> ssid = prefs.getStringSet(name, new HashSet<String>());
        if (ssid.size() > 0)
            pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssid)));
        else
            pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-"));
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("use_metered".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("unmetered_2g".equals(name) || "unmetered_3g".equals(name) || "unmetered_4g".equals(name)) {
        if (prefs.getBoolean(name, false)) {
            if (Util.hasPhoneStatePermission(this))
                ServiceSinkhole.reload("changed " + name, this);
            else {
                if ("unmetered_2g".equals(name))
                    requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED2);
                else if ("unmetered_3g".equals(name))
                    requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED3);
                else if ("unmetered_4g".equals(name))
                    requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED4);
            }
        } else
            ServiceSinkhole.reload("changed " + name, this);

    } else if ("national_roaming".equals(name)) {
        if (prefs.getBoolean(name, false)) {
            if (Util.hasPhoneStatePermission(this))
                ServiceSinkhole.reload("changed " + name, this);
            else
                requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE },
                        REQUEST_ROAMING_NATIONAL);
        } else
            ServiceSinkhole.reload("changed " + name, this);

    } else if ("manage_system".equals(name)) {
        boolean manage = prefs.getBoolean(name, false);
        if (!manage)
            prefs.edit().putBoolean("show_user", true).apply();
        prefs.edit().putBoolean("show_system", manage).apply();
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("log_app".equals(name)) {
        Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED);
        LocalBroadcastManager.getInstance(this).sendBroadcast(ruleset);

    } else if ("filter".equals(name)) {
        ServiceSinkhole.reload("changed " + name, this);

        // Show dialog
        if (prefs.getBoolean(name, false)) {
            LayoutInflater inflater = LayoutInflater.from(ActivitySettings.this);
            View view = inflater.inflate(R.layout.filter, null, false);
            dialogFilter = new AlertDialog.Builder(ActivitySettings.this).setView(view).setCancelable(false)
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing
                        }
                    }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialogInterface) {
                            dialogFilter = null;
                        }
                    }).create();
            dialogFilter.show();
        }

    } else if ("adblock".equals(name)) {
        boolean manage = prefs.getBoolean(name, false);
        String server_url = this.getString(R.string.serverurl);
        String uid = prefs.getString("uid", "");
        if (manage) { // log in
            if (prefs.getBoolean("registered", false)) {
                // Login app
                System.out.println("uid: " + uid);
                Login login = new Login(server_url, uid, this);
                login.loginUser();
            } else {
                // Register app
                String key = this.getString(R.string.app_key);
                Register register = new Register(server_url, key, getApplicationContext());
                register.registerApp();

                SharedPreferences.Editor editor = prefs.edit();
                editor.putBoolean("registered", true).commit();
                Login login = new Login(server_url, uid, this);
                login.loginUser();
            }
        } else { // log out
            SharedPreferences.Editor editor = prefs.edit();
            editor.putBoolean("logged", false).commit();
        }
    } else if ("use_hosts".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("vpn4".equals(name)) {
        String vpn4 = prefs.getString("vpn4", null);
        try {
            checkAddress(vpn4);
        } catch (Throwable ex) {
            prefs.edit().remove("vpn4").apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(vpn4))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        ServiceSinkhole.reload("changed " + name, this);
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_vpn4, prefs.getString("vpn4", "10.1.10.1")));

    } else if ("vpn6".equals(name)) {
        String vpn6 = prefs.getString("vpn6", null);
        try {
            checkAddress(vpn6);
        } catch (Throwable ex) {
            prefs.edit().remove("vpn6").apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(vpn6))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        ServiceSinkhole.reload("changed " + name, this);
        getPreferenceScreen().findPreference(name).setTitle(
                getString(R.string.setting_vpn6, prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")));

    } else if ("dns".equals(name)) {
        String dns = prefs.getString("dns", null);
        try {
            checkAddress(dns);
        } catch (Throwable ex) {
            prefs.edit().remove("dns").apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(dns))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        ServiceSinkhole.reload("changed " + name, this);
        getPreferenceScreen().findPreference(name).setTitle(
                getString(R.string.setting_dns, prefs.getString("dns", Util.getDefaultDNS(this).get(0))));

    } else if ("pcap_record_size".equals(name) || "pcap_file_size".equals(name)) {
        if ("pcap_record_size".equals(name))
            getPreferenceScreen().findPreference(name)
                    .setTitle(getString(R.string.setting_pcap_record_size, prefs.getString(name, "64")));
        else
            getPreferenceScreen().findPreference(name)
                    .setTitle(getString(R.string.setting_pcap_file_size, prefs.getString(name, "2")));

        ServiceSinkhole.setPcap(false, this);

        File pcap_file = new File(getCacheDir(), "netguard.pcap");
        if (pcap_file.exists() && !pcap_file.delete())
            Log.w(TAG, "Delete PCAP failed");

        if (prefs.getBoolean("pcap", false))
            ServiceSinkhole.setPcap(true, this);

    } else if ("show_stats".equals(name))
        ServiceSinkhole.reloadStats("changed " + name, this);

    else if ("stats_frequency".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_stats_frequency, prefs.getString(name, "1000")));

    else if ("stats_samples".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_stats_samples, prefs.getString(name, "90")));

    else if ("hosts_url".equals(name))
        getPreferenceScreen().findPreference(name)
                .setSummary(prefs.getString(name, "http://www.netguard.me/hosts"));

    else if ("loglevel".equals(name))
        ServiceSinkhole.reload("changed " + name, this);
}

From source file:dev.drsoran.moloko.fragments.AbstractTaskEditFragment.java

private ModificationSet createModificationSet(List<Task> tasks) {
    final ModificationSet modifications = new ModificationSet();

    for (Task task : tasks) {
        boolean anyChanges = false;

        // Task name
        if (hasChange(Tasks.TASKSERIES_NAME)) {
            final String taskName = getCurrentValue(Tasks.TASKSERIES_NAME, String.class);

            if (SyncUtils.hasChanged(task.getName(), taskName)) {
                modifications.add(Modification.newModification(
                        Queries.contentUriWithId(TaskSeries.CONTENT_URI, task.getTaskSeriesId()),
                        TaskSeries.TASKSERIES_NAME, taskName));
                anyChanges = true;//ww w .jav  a2 s  . c o  m
            }
        }

        // List
        if (hasChange(Tasks.LIST_ID)) {
            final String selectedListId = getCurrentValue(Tasks.LIST_ID, String.class);

            if (SyncUtils.hasChanged(task.getListId(), selectedListId)) {
                modifications.add(Modification.newModification(
                        Queries.contentUriWithId(TaskSeries.CONTENT_URI, task.getTaskSeriesId()),
                        TaskSeries.LIST_ID, selectedListId));
                anyChanges = true;
            }
        }

        // Priority
        if (hasChange(Tasks.PRIORITY)) {
            final String selectedPriority = getCurrentValue(Tasks.PRIORITY, String.class);

            if (SyncUtils.hasChanged(RtmTask.convertPriority(task.getPriority()), selectedPriority)) {
                modifications.add(Modification.newModification(
                        Queries.contentUriWithId(RawTasks.CONTENT_URI, task.getId()), RawTasks.PRIORITY,
                        selectedPriority));
                anyChanges = true;
            }
        }

        // Tags
        if (hasChange(Tasks.TAGS)) {
            final String tags = getCurrentValue(Tasks.TAGS, String.class);

            if (SyncUtils.hasChanged(tags, TextUtils.join(Tags.TAGS_SEPARATOR, task.getTags()))) {
                modifications.add(Modification.newModification(
                        Queries.contentUriWithId(TaskSeries.CONTENT_URI, task.getTaskSeriesId()),
                        TaskSeries.TAGS, tags));
                anyChanges = true;
            }
        }

        // Due
        if (hasChange(Tasks.DUE_DATE)) {
            Long newDue = getCurrentValue(Tasks.DUE_DATE, Long.class);

            if (newDue == -1)
                newDue = null;

            if (SyncUtils.hasChanged(MolokoDateUtils.getTime(task.getDue()), newDue)) {
                modifications.add(Modification.newModification(
                        Queries.contentUriWithId(RawTasks.CONTENT_URI, task.getId()), RawTasks.DUE_DATE,
                        newDue));
                anyChanges = true;
            }
        }

        if (hasChange(Tasks.HAS_DUE_TIME)) {
            final boolean newHasDueTime = getCurrentValue(Tasks.HAS_DUE_TIME, Boolean.class);

            if (SyncUtils.hasChanged(task.hasDueTime(), newHasDueTime)) {
                modifications.add(Modification.newModification(
                        Queries.contentUriWithId(RawTasks.CONTENT_URI, task.getId()), RawTasks.HAS_DUE_TIME,
                        newHasDueTime ? 1 : 0));
                anyChanges = true;
            }
        }

        // Recurrence
        if (hasChange(Tasks.RECURRENCE) || hasChange(Tasks.RECURRENCE_EVERY)) {
            final String recurrence = getCurrentValue(Tasks.RECURRENCE, String.class);

            if (SyncUtils.hasChanged(task.getRecurrence(), recurrence)) {
                modifications.add(Modification.newModification(
                        Queries.contentUriWithId(TaskSeries.CONTENT_URI, task.getTaskSeriesId()),
                        TaskSeries.RECURRENCE, recurrence));
                anyChanges = true;
            }

            final boolean isEveryRecurrence = getCurrentValue(Tasks.RECURRENCE_EVERY, Boolean.class);

            if (SyncUtils.hasChanged(task.isEveryRecurrence(), isEveryRecurrence)) {
                // The flag RECURRENCE_EVERY will not be synced out. RTM parses only the recurrence sentence.
                modifications.add(Modification.newNonPersistentModification(
                        Queries.contentUriWithId(TaskSeries.CONTENT_URI, task.getTaskSeriesId()),
                        TaskSeries.RECURRENCE_EVERY, isEveryRecurrence));
                anyChanges = true;
            }
        }

        // Estimate
        if (hasChange(Tasks.ESTIMATE_MILLIS)) {
            final long estimateMillis = getCurrentValue(Tasks.ESTIMATE_MILLIS, Long.class);

            if (SyncUtils.hasChanged(task.getEstimateMillis(), estimateMillis)) {
                modifications.add(Modification.newModification(
                        Queries.contentUriWithId(RawTasks.CONTENT_URI, task.getId()), RawTasks.ESTIMATE,
                        getCurrentValue(RawTasks.ESTIMATE, String.class)));

                modifications.add(Modification.newModification(
                        Queries.contentUriWithId(RawTasks.CONTENT_URI, task.getId()), RawTasks.ESTIMATE_MILLIS,
                        estimateMillis));
                anyChanges = true;
            }
        }

        // Location
        if (hasChange(Tasks.LOCATION_ID)) {
            final String selectedLocation = getCurrentValue(Tasks.LOCATION_ID, String.class);

            if (SyncUtils.hasChanged(task.getLocationId(), selectedLocation)) {
                modifications.add(Modification.newModification(
                        Queries.contentUriWithId(TaskSeries.CONTENT_URI, task.getTaskSeriesId()),
                        TaskSeries.LOCATION_ID, selectedLocation));
                anyChanges = true;
            }
        }

        // URL
        if (hasChange(Tasks.URL)) {
            final String newUrl = Strings.nullIfEmpty(getCurrentValue(Tasks.URL, String.class));

            if (SyncUtils.hasChanged(task.getUrl(), newUrl)) {
                modifications.add(Modification.newModification(
                        Queries.contentUriWithId(TaskSeries.CONTENT_URI, task.getTaskSeriesId()),
                        TaskSeries.URL, newUrl));
                anyChanges = true;
            }
        }

        // set the taskseries modification time to now
        if (anyChanges)
            modifications.add(Modification.newTaskModified(task.getTaskSeriesId()));
    }

    return modifications;
}

From source file:eu.faircode.adblocker.ActivitySettings.java

@Override
@TargetApi(Build.VERSION_CODES.M)/*ww w  .  j av  a  2s .com*/
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
    // Pro features
    if ("theme".equals(name)) {
        if (!"teal".equals(prefs.getString(name, "teal")) && !IAB.isPurchased(ActivityPro.SKU_THEME, this)) {
            prefs.edit().putString(name, "teal").apply();
            ((ListPreference) getPreferenceScreen().findPreference(name)).setValue("teal");
            startActivity(new Intent(this, ActivityPro.class));
            return;
        }
    } else if ("show_stats".equals(name)) {
        if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_SPEED, this)) {
            prefs.edit().putBoolean(name, false).apply();
            ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false);
            startActivity(new Intent(this, ActivityPro.class));
            return;
        }
    }

    Object value = prefs.getAll().get(name);
    if (value instanceof String && "".equals(value))
        prefs.edit().remove(name).apply();

    // Dependencies
    if ("whitelist_wifi".equals(name) || "screen_wifi".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("whitelist_other".equals(name) || "screen_other".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("whitelist_roaming".equals(name)) {
        if (prefs.getBoolean(name, false)) {
            if (Util.hasPhoneStatePermission(this))
                ServiceSinkhole.reload("changed " + name, this);
            else
                requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE },
                        REQUEST_ROAMING_INTERNATIONAL);
        } else
            ServiceSinkhole.reload("changed " + name, this);

    } else if ("auto_enable".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_auto, prefs.getString(name, "0")));

    else if ("screen_delay".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_delay, prefs.getString(name, "0")));

    else if ("theme".equals(name) || "dark_theme".equals(name))
        recreate();

    else if ("tethering".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("wifi_homes".equals(name)) {
        MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) getPreferenceScreen()
                .findPreference(name);
        Set<String> ssid = prefs.getStringSet(name, new HashSet<String>());
        if (ssid.size() > 0)
            pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssid)));
        else
            pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-"));
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("use_metered".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("unmetered_2g".equals(name) || "unmetered_3g".equals(name) || "unmetered_4g".equals(name)) {
        if (prefs.getBoolean(name, false)) {
            if (Util.hasPhoneStatePermission(this))
                ServiceSinkhole.reload("changed " + name, this);
            else {
                if ("unmetered_2g".equals(name))
                    requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED2);
                else if ("unmetered_3g".equals(name))
                    requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED3);
                else if ("unmetered_4g".equals(name))
                    requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED4);
            }
        } else
            ServiceSinkhole.reload("changed " + name, this);

    } else if ("national_roaming".equals(name)) {
        if (prefs.getBoolean(name, false)) {
            if (Util.hasPhoneStatePermission(this))
                ServiceSinkhole.reload("changed " + name, this);
            else
                requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE },
                        REQUEST_ROAMING_NATIONAL);
        } else
            ServiceSinkhole.reload("changed " + name, this);

    } else if ("manage_system".equals(name)) {
        boolean manage = prefs.getBoolean(name, false);
        if (!manage)
            prefs.edit().putBoolean("show_user", true).apply();
        prefs.edit().putBoolean("show_system", manage).apply();
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("log_app".equals(name)) {
        Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED);
        LocalBroadcastManager.getInstance(this).sendBroadcast(ruleset);

    } else if ("filter".equals(name)) {
        ServiceSinkhole.reload("changed " + name, this);

        // Show dialog
        if (prefs.getBoolean(name, false)) {
            LayoutInflater inflater = LayoutInflater.from(ActivitySettings.this);
            View view = inflater.inflate(R.layout.filter, null, false);
            dialogFilter = new AlertDialog.Builder(ActivitySettings.this).setView(view).setCancelable(false)
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing
                        }
                    }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialogInterface) {
                            dialogFilter = null;
                        }
                    }).create();
            dialogFilter.show();
        }

    } else if ("use_hosts".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("vpn4".equals(name)) {
        String vpn4 = prefs.getString("vpn4", null);
        try {
            checkAddress(vpn4);
        } catch (Throwable ex) {
            prefs.edit().remove("vpn4").apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(vpn4))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        ServiceSinkhole.reload("changed " + name, this);
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_vpn4, prefs.getString("vpn4", "10.1.10.1")));

    } else if ("vpn6".equals(name)) {
        String vpn6 = prefs.getString("vpn6", null);
        try {
            checkAddress(vpn6);
        } catch (Throwable ex) {
            prefs.edit().remove("vpn6").apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(vpn6))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        ServiceSinkhole.reload("changed " + name, this);
        getPreferenceScreen().findPreference(name).setTitle(
                getString(R.string.setting_vpn6, prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")));

    } else if ("dns".equals(name)) {
        String dns = prefs.getString("dns", null);
        try {
            checkAddress(dns);
        } catch (Throwable ex) {
            prefs.edit().remove("dns").apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(dns))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        ServiceSinkhole.reload("changed " + name, this);
        getPreferenceScreen().findPreference(name).setTitle(
                getString(R.string.setting_dns, prefs.getString("dns", Util.getDefaultDNS(this).get(0))));

    } else if ("pcap_record_size".equals(name) || "pcap_file_size".equals(name)) {
        if ("pcap_record_size".equals(name))
            getPreferenceScreen().findPreference(name)
                    .setTitle(getString(R.string.setting_pcap_record_size, prefs.getString(name, "64")));
        else
            getPreferenceScreen().findPreference(name)
                    .setTitle(getString(R.string.setting_pcap_file_size, prefs.getString(name, "2")));

        ServiceSinkhole.setPcap(false, this);

        File pcap_file = new File(getCacheDir(), "adblocker.pcap");
        if (pcap_file.exists() && !pcap_file.delete())
            Log.w(TAG, "Delete PCAP failed");

        if (prefs.getBoolean("pcap", false))
            ServiceSinkhole.setPcap(true, this);

    } else if ("show_stats".equals(name))
        ServiceSinkhole.reloadStats("changed " + name, this);

    else if ("stats_frequency".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_stats_frequency, prefs.getString(name, "1000")));

    else if ("stats_samples".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_stats_samples, prefs.getString(name, "90")));

    else if ("hosts_url".equals(name))
        getPreferenceScreen().findPreference(name)
                .setSummary(prefs.getString(name, "http://www.adblocker.me/hosts"));

    else if ("loglevel".equals(name))
        ServiceSinkhole.reload("changed " + name, this);
}

From source file:eu.faircode.netguard.ActivitySettings.java

@Override
@TargetApi(Build.VERSION_CODES.M)/*www.j a v  a 2s.  c  o  m*/
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
    // Pro features
    if ("theme".equals(name)) {
        if (!"teal".equals(prefs.getString(name, "teal")) && !IAB.isPurchased(ActivityPro.SKU_THEME, this)) {
            prefs.edit().putString(name, "teal").apply();
            ((ListPreference) getPreferenceScreen().findPreference(name)).setValue("teal");
            startActivity(new Intent(this, ActivityPro.class));
            return;
        }
    } else if ("install".equals(name)) {
        if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_NOTIFY, this)) {
            prefs.edit().putBoolean(name, false).apply();
            ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false);
            startActivity(new Intent(this, ActivityPro.class));
            return;
        }
    } else if ("show_stats".equals(name)) {
        if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_SPEED, this)) {
            prefs.edit().putBoolean(name, false).apply();
            startActivity(new Intent(this, ActivityPro.class));
            return;
        }
        ((TwoStatePreference) getPreferenceScreen().findPreference(name))
                .setChecked(prefs.getBoolean(name, false));
    }

    Object value = prefs.getAll().get(name);
    if (value instanceof String && "".equals(value))
        prefs.edit().remove(name).apply();

    // Dependencies
    if ("screen_on".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("whitelist_wifi".equals(name) || "screen_wifi".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("whitelist_other".equals(name) || "screen_other".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("whitelist_roaming".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("auto_enable".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_auto, prefs.getString(name, "0")));

    else if ("screen_delay".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_delay, prefs.getString(name, "0")));

    else if ("theme".equals(name) || "dark_theme".equals(name))
        recreate();

    else if ("subnet".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("tethering".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("lan".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("ip6".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("wifi_homes".equals(name)) {
        MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) getPreferenceScreen()
                .findPreference(name);
        Set<String> ssid = prefs.getStringSet(name, new HashSet<String>());
        if (ssid.size() > 0)
            pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssid)));
        else
            pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-"));
        ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("use_metered".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("unmetered_2g".equals(name) || "unmetered_3g".equals(name) || "unmetered_4g".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("national_roaming".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("eu_roaming".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("disable_on_call".equals(name)) {
        if (prefs.getBoolean(name, false)) {
            if (checkPermissions(name))
                ServiceSinkhole.reload("changed " + name, this, false);
        } else
            ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("lockdown_wifi".equals(name) || "lockdown_other".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("manage_system".equals(name)) {
        boolean manage = prefs.getBoolean(name, false);
        if (!manage)
            prefs.edit().putBoolean("show_user", true).apply();
        prefs.edit().putBoolean("show_system", manage).apply();
        ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("log_app".equals(name)) {
        Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED);
        LocalBroadcastManager.getInstance(this).sendBroadcast(ruleset);

    } else if ("filter".equals(name)) {
        // Show dialog
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && prefs.getBoolean(name, false)) {
            LayoutInflater inflater = LayoutInflater.from(ActivitySettings.this);
            View view = inflater.inflate(R.layout.filter, null, false);
            dialogFilter = new AlertDialog.Builder(ActivitySettings.this).setView(view).setCancelable(false)
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing
                        }
                    }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialogInterface) {
                            dialogFilter = null;
                        }
                    }).create();
            dialogFilter.show();
        } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && !prefs.getBoolean(name, false)) {
            prefs.edit().putBoolean(name, true).apply();
            Toast.makeText(ActivitySettings.this, R.string.msg_filter4, Toast.LENGTH_SHORT).show();
        }

        ((TwoStatePreference) getPreferenceScreen().findPreference(name))
                .setChecked(prefs.getBoolean(name, false));

        ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("use_hosts".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("vpn4".equals(name)) {
        String vpn4 = prefs.getString(name, null);
        try {
            checkAddress(vpn4);
        } catch (Throwable ex) {
            prefs.edit().remove(name).apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(vpn4))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_vpn4, prefs.getString(name, "10.1.10.1")));
        ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("vpn6".equals(name)) {
        String vpn6 = prefs.getString(name, null);
        try {
            checkAddress(vpn6);
        } catch (Throwable ex) {
            prefs.edit().remove(name).apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(vpn6))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        getPreferenceScreen().findPreference(name).setTitle(
                getString(R.string.setting_vpn6, prefs.getString(name, "fd00:1:fd00:1:fd00:1:fd00:1")));
        ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("dns".equals(name) || "dns2".equals(name)) {
        String dns = prefs.getString(name, null);
        try {
            checkAddress(dns);
        } catch (Throwable ex) {
            prefs.edit().remove(name).apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(dns))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_dns,
                prefs.getString(name, Util.getDefaultDNS(this).get("dns".equals(name) ? 0 : 1))));
        ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("ttl".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_ttl, prefs.getString(name, "259200")));

    else if ("rcode".equals(name)) {
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_rcode, prefs.getString(name, "3")));
        ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("socks5_enabled".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);

    else if ("socks5_addr".equals(name)) {
        String socks5_addr = prefs.getString(name, null);
        try {
            if (!TextUtils.isEmpty(socks5_addr) && !Util.isNumericAddress(socks5_addr))
                throw new IllegalArgumentException("Bad address");
        } catch (Throwable ex) {
            prefs.edit().remove(name).apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(socks5_addr))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_socks5_addr, prefs.getString(name, "-")));
        ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("socks5_port".equals(name)) {
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_socks5_port, prefs.getString(name, "-")));
        ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("socks5_username".equals(name)) {
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_socks5_username, prefs.getString(name, "-")));
        ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("socks5_password".equals(name)) {
        getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_password,
                TextUtils.isEmpty(prefs.getString(name, "")) ? "-" : "*****"));
        ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("pcap_record_size".equals(name) || "pcap_file_size".equals(name)) {
        if ("pcap_record_size".equals(name))
            getPreferenceScreen().findPreference(name)
                    .setTitle(getString(R.string.setting_pcap_record_size, prefs.getString(name, "64")));
        else
            getPreferenceScreen().findPreference(name)
                    .setTitle(getString(R.string.setting_pcap_file_size, prefs.getString(name, "2")));

        ServiceSinkhole.setPcap(false, this);

        File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap");
        if (pcap_file.exists() && !pcap_file.delete())
            Log.w(TAG, "Delete PCAP failed");

        if (prefs.getBoolean("pcap", false))
            ServiceSinkhole.setPcap(true, this);

    } else if ("watchdog".equals(name)) {
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_watchdog, prefs.getString(name, "0")));
        ServiceSinkhole.reload("changed " + name, this, false);

    } else if ("show_stats".equals(name))
        ServiceSinkhole.reloadStats("changed " + name, this);

    else if ("stats_frequency".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_stats_frequency, prefs.getString(name, "1000")));

    else if ("stats_samples".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_stats_samples, prefs.getString(name, "90")));

    else if ("hosts_url".equals(name))
        getPreferenceScreen().findPreference(name)
                .setSummary(prefs.getString(name, "http://www.netguard.me/hosts"));

    else if ("loglevel".equals(name))
        ServiceSinkhole.reload("changed " + name, this, false);
}

From source file:android_network.hetnet.vpn_service.ActivitySettings.java

@Override
@TargetApi(Build.VERSION_CODES.M)/* w  ww  .  j a  va  2 s.  c om*/
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
    // Pro features
    if ("theme".equals(name)) {
        if (!"teal".equals(prefs.getString(name, "teal"))) {
            prefs.edit().putString(name, "teal").apply();
            ((ListPreference) getPreferenceScreen().findPreference(name)).setValue("teal");
            return;
        }
    } else if ("install".equals(name)) {
        if (prefs.getBoolean(name, false)) {
            prefs.edit().putBoolean(name, false).apply();
            ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false);
            return;
        }
    } else if ("show_stats".equals(name)) {
        if (prefs.getBoolean(name, false)) {
            prefs.edit().putBoolean(name, false).apply();
            return;
        }
        ((TwoStatePreference) getPreferenceScreen().findPreference(name))
                .setChecked(prefs.getBoolean(name, false));
    }

    Object value = prefs.getAll().get(name);
    if (value instanceof String && "".equals(value))
        prefs.edit().remove(name).apply();

    // Dependencies
    if ("screen_on".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("whitelist_wifi".equals(name) || "screen_wifi".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("whitelist_other".equals(name) || "screen_other".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("whitelist_roaming".equals(name)) {
        if (prefs.getBoolean(name, false)) {
            if (Util.hasPhoneStatePermission(this))
                ServiceSinkhole.reload("changed " + name, this);
            else
                requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE },
                        REQUEST_ROAMING_INTERNATIONAL);
        } else
            ServiceSinkhole.reload("changed " + name, this);

    } else if ("auto_enable".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_auto, prefs.getString(name, "0")));

    else if ("screen_delay".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_delay, prefs.getString(name, "0")));

    else if ("theme".equals(name) || "dark_theme".equals(name))
        recreate();

    else if ("subnet".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("tethering".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("lan".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("ip6".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("wifi_homes".equals(name)) {
        MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) getPreferenceScreen()
                .findPreference(name);
        Set<String> ssid = prefs.getStringSet(name, new HashSet<String>());
        if (ssid.size() > 0)
            pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssid)));
        else
            pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-"));
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("use_metered".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("unmetered_2g".equals(name) || "unmetered_3g".equals(name) || "unmetered_4g".equals(name)) {
        if (prefs.getBoolean(name, false)) {
            if (Util.hasPhoneStatePermission(this))
                ServiceSinkhole.reload("changed " + name, this);
            else {
                if ("unmetered_2g".equals(name))
                    requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED2);
                else if ("unmetered_3g".equals(name))
                    requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED3);
                else if ("unmetered_4g".equals(name))
                    requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED4);
            }
        } else
            ServiceSinkhole.reload("changed " + name, this);

    } else if ("national_roaming".equals(name)) {
        if (prefs.getBoolean(name, false)) {
            if (Util.hasPhoneStatePermission(this))
                ServiceSinkhole.reload("changed " + name, this);
            else
                requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE },
                        REQUEST_ROAMING_NATIONAL);
        } else
            ServiceSinkhole.reload("changed " + name, this);

    } else if ("manage_system".equals(name)) {
        boolean manage = prefs.getBoolean(name, true);
        if (!manage)
            prefs.edit().putBoolean("show_user", true).apply();
        prefs.edit().putBoolean("show_system", manage).apply();
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("log_app".equals(name)) {
        Intent ruleset = new Intent(MainActivity.ACTION_RULES_CHANGED);
        LocalBroadcastManager.getInstance(this).sendBroadcast(ruleset);

    } else if ("filter".equals(name)) {
        // Show dialog
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && prefs.getBoolean(name, false)) {
            LayoutInflater inflater = LayoutInflater.from(ActivitySettings.this);
            View view = inflater.inflate(R.layout.filter, null, false);
            dialogFilter = new AlertDialog.Builder(ActivitySettings.this).setView(view).setCancelable(false)
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing
                        }
                    }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialogInterface) {
                            dialogFilter = null;
                        }
                    }).create();
            dialogFilter.show();
        } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && !prefs.getBoolean(name, false)) {
            prefs.edit().putBoolean(name, true).apply();
            Toast.makeText(ActivitySettings.this, R.string.msg_filter4, Toast.LENGTH_SHORT).show();
        }

        ((TwoStatePreference) getPreferenceScreen().findPreference(name))
                .setChecked(prefs.getBoolean(name, false));

        ServiceSinkhole.reload("changed " + name, this);

    } else if ("use_hosts".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("vpn4".equals(name)) {
        String vpn4 = prefs.getString(name, null);
        try {
            checkAddress(vpn4);
        } catch (Throwable ex) {
            prefs.edit().remove(name).apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(vpn4))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_vpn4, prefs.getString(name, "10.1.10.1")));
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("vpn6".equals(name)) {
        String vpn6 = prefs.getString(name, null);
        try {
            checkAddress(vpn6);
        } catch (Throwable ex) {
            prefs.edit().remove(name).apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(vpn6))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        getPreferenceScreen().findPreference(name).setTitle(
                getString(R.string.setting_vpn6, prefs.getString(name, "fd00:1:fd00:1:fd00:1:fd00:1")));
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("dns".equals(name) || "dns2".equals(name)) {
        String dns = prefs.getString(name, null);
        try {
            checkAddress(dns);
        } catch (Throwable ex) {
            prefs.edit().remove(name).apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(dns))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_dns,
                prefs.getString(name, Util.getDefaultDNS(this).get("dns".equals(name) ? 0 : 1))));
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("ttl".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_ttl, prefs.getString(name, "259200")));

    else if ("rcode".equals(name)) {
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_rcode, prefs.getString(name, "3")));
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("socks5_enabled".equals(name))
        ServiceSinkhole.reload("changed " + name, this);

    else if ("socks5_addr".equals(name)) {
        String socks5_addr = prefs.getString(name, null);
        try {
            if (!TextUtils.isEmpty(socks5_addr) && !Util.isNumericAddress(socks5_addr))
                throw new IllegalArgumentException("Bad address");
        } catch (Throwable ex) {
            prefs.edit().remove(name).apply();
            ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
            if (!TextUtils.isEmpty(socks5_addr))
                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_socks5_addr, prefs.getString(name, "-")));
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("socks5_port".equals(name)) {
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_socks5_port, prefs.getString(name, "-")));
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("socks5_username".equals(name)) {
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_socks5_username, prefs.getString(name, "-")));
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("socks5_password".equals(name)) {
        getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_password,
                TextUtils.isEmpty(prefs.getString(name, "")) ? "-" : "*****"));
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("pcap_record_size".equals(name) || "pcap_file_size".equals(name)) {
        if ("pcap_record_size".equals(name))
            getPreferenceScreen().findPreference(name)
                    .setTitle(getString(R.string.setting_pcap_record_size, prefs.getString(name, "64")));
        else
            getPreferenceScreen().findPreference(name)
                    .setTitle(getString(R.string.setting_pcap_file_size, prefs.getString(name, "2")));

        ServiceSinkhole.setPcap(false, this);

        File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap");
        if (pcap_file.exists() && !pcap_file.delete())
            Log.w(TAG, "Delete PCAP failed");

        if (prefs.getBoolean("pcap", false))
            ServiceSinkhole.setPcap(true, this);

    } else if ("watchdog".equals(name)) {
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_watchdog, prefs.getString(name, "0")));
        ServiceSinkhole.reload("changed " + name, this);

    } else if ("show_stats".equals(name))
        ServiceSinkhole.reloadStats("changed " + name, this);

    else if ("stats_frequency".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_stats_frequency, prefs.getString(name, "1000")));

    else if ("stats_samples".equals(name))
        getPreferenceScreen().findPreference(name)
                .setTitle(getString(R.string.setting_stats_samples, prefs.getString(name, "90")));

    else if ("hosts_url".equals(name))
        getPreferenceScreen().findPreference(name)
                .setSummary(prefs.getString(name, "http://www.netguard.me/hosts"));

    else if ("loglevel".equals(name))
        ServiceSinkhole.reload("changed " + name, this);
}

From source file:org.proninyaroslav.libretorrent.fragments.DetailTorrentFragment.java

@Override
public void onShow(final AlertDialog dialog) {
    if (dialog == null) {
        return;//from   w  w  w  . j  a  va2s. c o  m
    }

    if (getFragmentManager().findFragmentByTag(TAG_ADD_TRACKERS_DIALOG) != null) {
        final TextInputEditText field = (TextInputEditText) dialog
                .findViewById(R.id.multiline_text_input_dialog);
        final TextInputLayout fieldLayout = (TextInputLayout) dialog
                .findViewById(R.id.layout_multiline_text_input_dialog);

        /* Dismiss error label if user has changed the text */
        if (field != null && fieldLayout != null) {
            field.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    /* Nothing */
                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    fieldLayout.setErrorEnabled(false);
                    fieldLayout.setError(null);

                    /* Clear selection of invalid url */
                    Spannable text = field.getText();
                    ForegroundColorSpan[] errorSpans = text.getSpans(0, text.length(),
                            ForegroundColorSpan.class);
                    for (ForegroundColorSpan span : errorSpans) {
                        text.removeSpan(span);
                    }
                }

                @Override
                public void afterTextChanged(Editable s) {
                    /* Nothing */
                }
            });
        }

        /*
         * It is necessary in order to the dialog is not closed by
         * pressing add/replace button if the text checker gave a false result
         */
        Button addButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
        Button replaceButton = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);

        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (field != null && fieldLayout != null) {
                    String text = field.getText().toString();
                    List<String> urls = Arrays.asList(text.split(Utils.getLineSeparator()));

                    if (checkEditTextField(urls, fieldLayout, field)) {
                        addTrackersRequest(new ArrayList<>(urls), false);

                        dialog.dismiss();
                    }
                }
            }
        });

        replaceButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (field != null && fieldLayout != null) {
                    String text = field.getText().toString();
                    List<String> urls = Arrays.asList(text.split(Utils.getLineSeparator()));

                    if (checkEditTextField(urls, fieldLayout, field)) {
                        addTrackersRequest(new ArrayList<>(urls), true);

                        dialog.dismiss();
                    }
                }
            }
        });

        /* Inserting links from the clipboard */
        String clipboard = Utils.getClipboard(activity.getApplicationContext());

        if (clipboard != null && field != null) {
            List<String> urls = Arrays.asList(clipboard.split(Utils.getLineSeparator()));
            ArrayList<String> validUrls = new ArrayList<>();

            for (String url : urls) {
                if (Utils.isValidTrackerUrl(url)) {
                    validUrls.add(url);
                }
            }

            field.setText(TextUtils.join(Utils.getLineSeparator(), validUrls));
        }

    } else if (getFragmentManager().findFragmentByTag(TAG_SPEED_LIMIT_DIALOG) != null) {
        TextInputEditText upload = (TextInputEditText) dialog.findViewById(R.id.upload_limit);
        TextInputEditText download = (TextInputEditText) dialog.findViewById(R.id.download_limit);

        if (upload != null && download != null) {
            int minSpeedLimit = 0;
            int maxSpeedLimit = Integer.MAX_VALUE;
            InputFilter[] filter = new InputFilter[] { new InputFilterMinMax(minSpeedLimit, maxSpeedLimit) };

            upload.setFilters(filter);
            if (TextUtils.isEmpty(upload.getText())) {
                upload.setText((uploadSpeedLimit != -1 ? Integer.toString(uploadSpeedLimit / 1024)
                        : Integer.toString(minSpeedLimit)));
            }

            download.setFilters(filter);
            if (TextUtils.isEmpty(download.getText())) {
                download.setText((downloadSpeedLimit != -1 ? Integer.toString(downloadSpeedLimit / 1024)
                        : Integer.toString(minSpeedLimit)));
            }
        }
    }
}

From source file:illab.nabal.proxy.WeiboProxy.java

/**
 * Get Weibo users' friend count.// w ww .ja va2  s . co m
 * 
 * @param userUids
 * @return JSONArray
 * @throws Exception
 */
private JSONArray getFriendCount(String[] userUids) throws Exception {

    String apiUri = "/users/counts.json";

    // throw an exception if no user UID is given 
    if (userUids == null || userUids.length == 0) {
        throw new SystemException("Invalid user UIDs.");
    }

    // join user UIDs and make a CSV
    String commaSeparatedUids = TextUtils.join(",", userUids);

    return getJsonArray(getResponseString(
            getHttpGet(apiUri, new BasicNameValuePair("access_token", mWeiboContext.getAccessToken()),
                    new BasicNameValuePair("uids", commaSeparatedUids))));
}

From source file:illab.nabal.proxy.FacebookProxy.java

@Override
public void postStatus(final Operation<FacebookDelegate, FacebookPost> operation, final String message,
        final String placeId, final String[] tags, final Locale locale) {
    requestJob(new ProxyJob() {
        public void onFail(Exception e) {
            operation.onFail(e);//from   w  w  w.j a va 2  s.  c o m
        }

        public void run() {
            try {
                // check message
                if (StringHelper.isEmpty(message) == true) {
                    throw new SystemException("Invalid message.");
                }
                // generate tag CSV 
                String tagString = null;
                if (tags != null && tags.length > 0) {
                    tagString = TextUtils.join(",", tags);
                }
                operation.onResult(publishPost(ME, message, null, null, null, null, null, null, placeId,
                        tagString, locale));
            } catch (Exception e) {
                onFail(e);
            }
        }
    });
}