Java Code Examples for android.text.TextUtils#SimpleStringSplitter

The following examples show how to use android.text.TextUtils#SimpleStringSplitter . 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: Utils.java    From Noyze with Apache License 2.0 6 votes vote down vote up
/**
 * API 4+, check if the given {@link AccessibilityService} is enabled.
 *
 * @return True if id is an enabled {@link AccessibilityService}.
 */
public static boolean isSettingsServiceEnabled(Context context, String setting, String[] ids) {
    // Check the list of system settings to see if a service is running.
    String eServices = Settings.Secure.getString(context.getContentResolver(), setting);
    if (!TextUtils.isEmpty(eServices) && null != ids) {
        TextUtils.SimpleStringSplitter splitter = COLON_SPLITTER;
        splitter.setString(eServices);
        while (splitter.hasNext()) {
            String aService = splitter.next();
            if (contains(ids, aService)) {
                return true;
            }
        }
    }

    return false;
}
 
Example 2
Source File: NotificationListenerService.java    From heads-up with GNU General Public License v3.0 6 votes vote down vote up
boolean isAccessibilityEnabled(){
    int accessibilityEnabled = 0;
    try {
        accessibilityEnabled = Settings.Secure.getInt(this.getContentResolver(),android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
    } catch (Settings.SettingNotFoundException e) {
        Mlog.w(logTag, "Error finding accessibility setting: " + e.getMessage());
    }

    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

    if (accessibilityEnabled==1){
        String settingValue = Settings.Secure.getString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
        if (settingValue != null) {
            mStringColonSplitter.setString(settingValue);
            while (mStringColonSplitter.hasNext()) {
                String accessibilityService = mStringColonSplitter.next();
                Mlog.d(logTag, "Setting: " + accessibilityService);
                if (accessibilityService.equalsIgnoreCase(WelcomeActivity.ACCESSIBILITY_SERVICE_NAME)){
                    return true;
                }
            }
        }

    }
    return false;
}
 
Example 3
Source File: AccessibilityServiceHelper.java    From ViewDebugHelper with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static boolean isAccessibilitySettingsOn(Context context, String serviceName) {
    int accessibilityEnabled = 0;
    boolean accessibilityFound = false;
    try {
        accessibilityEnabled = Settings.Secure.getInt(context.getApplicationContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED);
    } catch (SettingNotFoundException e) {
    }
    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
    if (accessibilityEnabled == 1) {
        String settingValue = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
        if (settingValue != null) {
            TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
            splitter.setString(settingValue);
            while (splitter.hasNext()) {
                String accessabilityService = splitter.next();
                if (accessabilityService.equalsIgnoreCase(serviceName)) {
                    return true;
                }
            }
        }
    } else {
        // Log.v(TAG, "***ACCESSIBILIY IS DISABLED***");
    }

    return accessibilityFound;
}
 
Example 4
Source File: USSDController.java    From VoIpUSSD with Apache License 2.0 6 votes vote down vote up
protected static boolean isAccessibilitySettingsOn(Context context, final String service) {
    int accessibilityEnabled = 0;
    try {
        accessibilityEnabled = Settings.Secure.getInt(
                context.getApplicationContext().getContentResolver(),
                android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
    } catch (Settings.SettingNotFoundException e) {
        //
    }
    if (accessibilityEnabled == 1) {
        String settingValue = Settings.Secure.getString(
                context.getApplicationContext().getContentResolver(),
                Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
        if (settingValue != null) {
            TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter(':');
            splitter.setString(settingValue);
            while (splitter.hasNext()) {
                String accessabilityService = splitter.next();
                if (accessabilityService.equalsIgnoreCase(service)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 5
Source File: AccessibilityServicesCheckUtil.java    From EasyProtector with Apache License 2.0 6 votes vote down vote up
public boolean checkAccessibilityEnabled(Context context, String packageName) {
    int hasSetSetting;
    try {
        hasSetSetting = Settings.Secure.getInt(context.getApplicationContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED);
        TextUtils.SimpleStringSplitter simpleStringSplitter = new TextUtils.SimpleStringSplitter(':');
        if (hasSetSetting == 1) {
            String settingValue = Settings.Secure.getString(context.getApplicationContext().getContentResolver(),
                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
            if (settingValue != null) {
                simpleStringSplitter.setString(settingValue);
                while (simpleStringSplitter.hasNext()) {
                    String accessibilityService = simpleStringSplitter.next();
                    if (accessibilityService.contains(packageName)) {
                        return true;
                    }
                }
            }
        }
    } catch (Settings.SettingNotFoundException e) {

    }
    return false;
}
 
Example 6
Source File: MainActivity.java    From loco-answers with GNU General Public License v3.0 6 votes vote down vote up
public boolean isAccessibilityEnabled() {
    int accessibilityEnabled = 0;
    final String ACCESSIBILITY_SERVICE = "ai.loko.hk.ui/ai.loko.hk.ui.Accessibility";
    try {
        accessibilityEnabled = Settings.Secure.getInt(this.getContentResolver(), android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
    } catch (Settings.SettingNotFoundException e) {
        //setting not found so your phone is not supported
    }
    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
    if (accessibilityEnabled == 1) {
        String settingValue = Settings.Secure.getString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
        if (settingValue != null) {
            mStringColonSplitter.setString(settingValue);
            while (mStringColonSplitter.hasNext()) {
                String accessabilityService = mStringColonSplitter.next();
                if (accessabilityService.equalsIgnoreCase(ACCESSIBILITY_SERVICE)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 7
Source File: TamicInstallService.java    From Autoinstall with Apache License 2.0 5 votes vote down vote up
/**
 * isAccessibilitySettingsOn
 */
public static boolean isAccessibilitySettingsOn(Context mContext) {
    int accessibilityEnabled = 0;
    final String service = mContext.getPackageName() + "/" + TamicInstallService.class.getCanonicalName();
    try {
        accessibilityEnabled = Settings.Secure.getInt(
                mContext.getApplicationContext().getContentResolver(),
                android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
        Log.v(LOG_TAG, "accessibilityEnabled = " + accessibilityEnabled);
    } catch (Settings.SettingNotFoundException e) {
        Log.e(LOG_TAG, "Error finding setting, default accessibility to not found: "
                + e.getMessage());
    }
    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

    if (accessibilityEnabled == 1) {
        Log.v(LOG_TAG, "***ACCESSIBILITY IS ENABLED*** -");
        String settingValue = Settings.Secure.getString(
                mContext.getApplicationContext().getContentResolver(),
                Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
        if (settingValue != null) {
            mStringColonSplitter.setString(settingValue);
            while (mStringColonSplitter.hasNext()) {
                String accessibilityService = mStringColonSplitter.next();

                Log.v(LOG_TAG, " accessibilityService :: " + accessibilityService + " " + service);
                if (accessibilityService.equalsIgnoreCase(service)) {
                    Log.v(LOG_TAG, "We've found the correct setting - accessibility is switched on!");
                    return true;
                }
            }
        }
    } else {
        Log.v(LOG_TAG, "---ACCESSIBILITY IS DISABLED--");
    }

    return false;
}
 
Example 8
Source File: HdmiControlService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static List<Integer> getIntList(String string) {
    ArrayList<Integer> list = new ArrayList<>();
    TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(string);
    for (String item : splitter) {
        try {
            list.add(Integer.parseInt(item));
        } catch (NumberFormatException e) {
            Slog.w(TAG, "Can't parseInt: " + item);
        }
    }
    return Collections.unmodifiableList(list);
}
 
Example 9
Source File: URMUtils.java    From rebootmenu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 检查辅助服务是否打开
 *
 * @param mContext 1
 * @return boolean
 */
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public static boolean isAccessibilitySettingsOn(@NonNull Context mContext) {
    //注意:不要使用以下注释掉的代码取无障碍服务开启状态!disableSelf()之后仍返回true
    //return ((AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled();
    new DebugLog("isAccessibilitySettingsOn", DebugLog.LogLevel.V);
    int accessibilityEnabled = 0;
    final String service = mContext.getPackageName() + "/" + UnRootAccessibility.class.getCanonicalName();
    try {
        accessibilityEnabled = Settings.Secure.getInt(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED);
    } catch (Settings.SettingNotFoundException ignored) {
    }
    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
    if (accessibilityEnabled == 1) {
        String settingValue = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
        if (settingValue != null) {
            mStringColonSplitter.setString(settingValue);
            while (mStringColonSplitter.hasNext()) {
                String accessibilityService = mStringColonSplitter.next();
                if (accessibilityService.equalsIgnoreCase(service)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 10
Source File: PackageChooserPreference.java    From Noyze with Apache License 2.0 5 votes vote down vote up
public Set<String> getPackages(String value, String defaultValue) {
    String listVal = value;
    if (TextUtils.isEmpty(value)) {
        listVal = defaultValue;
    }

    Set<String> packages = new HashSet<String>();
    TextUtils.SimpleStringSplitter splitter = COLON_SPLITTER;
    splitter.setString(listVal);
    while (splitter.hasNext()) {
        packages.add(splitter.next());
    }

    return packages;
}
 
Example 11
Source File: TimeCatMonitorService.java    From timecat with Apache License 2.0 5 votes vote down vote up
public static boolean isAccessibilitySettingsOn(Context mContext) {
    int accessibilityEnabled = 0;
    final String service = TimeCatApp.getInstance().getPackageName() + "/" + TimeCatMonitorService.class.getCanonicalName();
    try {
        accessibilityEnabled = Settings.Secure.getInt(mContext.getApplicationContext().getContentResolver(), android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
        LogUtil.v(TAG, "accessibilityEnabled = " + accessibilityEnabled);
    } catch (Settings.SettingNotFoundException e) {
        LogUtil.d(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage());
    }
    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

    if (accessibilityEnabled == 1) {
        LogUtil.v(TAG, "***ACCESSIBILITY IS ENABLED*** -----------------");
        String settingValue = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
        if (settingValue != null) {
            mStringColonSplitter.setString(settingValue);
            while (mStringColonSplitter.hasNext()) {
                String accessibilityService = mStringColonSplitter.next();

                LogUtil.v(TAG, "-------------- > accessibilityService :: " + accessibilityService + " " + service);
                if (accessibilityService.equalsIgnoreCase(service)) {
                    LogUtil.v(TAG, "We've found the correct setting - accessibility is switched on!");
                    return true;
                }
            }
        }
    } else {
        LogUtil.v(TAG, "***ACCESSIBILITY IS DISABLED***");
    }

    return false;
}
 
Example 12
Source File: Camera.java    From VideoRecorder with Apache License 2.0 5 votes vote down vote up
private ArrayList<String> split(String str) {
    if (str == null) return null;

    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(str);
    ArrayList<String> substrings = new ArrayList<String>();
    for (String s : splitter) {
        substrings.add(s);
    }
    return substrings;
}
 
Example 13
Source File: VolumeAccessibilityService.java    From Noyze with Apache License 2.0 5 votes vote down vote up
void updateBlacklist() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String packs = prefs.getString(Constants.PREF_BLACKLIST, "");
    TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter(':');
    splitter.setString(packs);
    blacklist.clear();
    while (splitter.hasNext()) {
        blacklist.add(splitter.next());
    }
    LOGI(TAG, "updateBlacklist(" + blacklist.size() + ')');
}
 
Example 14
Source File: Camera.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void splitFloat(String str, float[] output) {
    if (str == null) return;

    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(str);
    int index = 0;
    for (String s : splitter) {
        output[index++] = Float.parseFloat(s);
    }
}
 
Example 15
Source File: Camera.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void splitInt(String str, int[] output) {
    if (str == null) return;

    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(str);
    int index = 0;
    for (String s : splitter) {
        output[index++] = Integer.parseInt(s);
    }
}
 
Example 16
Source File: Camera.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private ArrayList<Integer> splitInt(String str) {
    if (str == null) return null;

    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(str);
    ArrayList<Integer> substrings = new ArrayList<Integer>();
    for (String s : splitter) {
        substrings.add(Integer.parseInt(s));
    }
    if (substrings.size() == 0) return null;
    return substrings;
}
 
Example 17
Source File: Camera.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private ArrayList<String> split(String str) {
    if (str == null) return null;

    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(str);
    ArrayList<String> substrings = new ArrayList<String>();
    for (String s : splitter) {
        substrings.add(s);
    }
    return substrings;
}
 
Example 18
Source File: UtteranceRewriter.java    From speechutils with Apache License 2.0 5 votes vote down vote up
public CommandHolder(String inputHeader, List<Command> commands) {
    boolean hasColumnUtterance = false;
    SortedMap<Integer, String> header = new TreeMap<>();
    List<String> fields = new ArrayList<>();
    if (inputHeader != null && !inputHeader.isEmpty()) {
        final TextUtils.StringSplitter COLUMN_SPLITTER = new TextUtils.SimpleStringSplitter('\t');
        COLUMN_SPLITTER.setString(inputHeader);
        int fieldCounter = 0;
        for (String columnName : COLUMN_SPLITTER) {
            fields.add(columnName);
            if (COLUMNS.contains(columnName)) {
                header.put(fieldCounter, columnName);
                if (HEADER_UTTERANCE.equals(columnName)) {
                    hasColumnUtterance = true;
                }
            }
            fieldCounter++;
        }
    }
    mCommands = commands;
    // If the Utterance column is missing then assume that the
    // input was without a header and interpret it as a one or two column table.
    if (!hasColumnUtterance) {
        if (fields.size() > 1) {
            mHeader = DEFAULT_HEADER_2;
            mCommands.add(0, new Command(fields.get(0), fields.get(1)));
        } else if (fields.size() > 0) {
            mHeader = DEFAULT_HEADER_1;
            mCommands.add(0, new Command(fields.get(0), ""));
        } else {
            mHeader = DEFAULT_HEADER_1;
        }
    } else {
        mHeader = header;
    }
}
 
Example 19
Source File: KeyValueListParser.java    From Doze-Settings-Editor with MIT License 2 votes vote down vote up
/**
 * Constructs a new KeyValueListParser. This can be reused for different strings
 * by calling {@link #setString(String)}.
 * @param delim The delimiter that separates key=value pairs.
 */
public KeyValueListParser(char delim) {
    mSplitter = new TextUtils.SimpleStringSplitter(delim);
}
 
Example 20
Source File: KeyValueListParser.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a new KeyValueListParser. This can be reused for different strings
 * by calling {@link #setString(String)}.
 * @param delim The delimiter that separates key=value pairs.
 */
public KeyValueListParser(char delim) {
    mSplitter = new TextUtils.SimpleStringSplitter(delim);
}