Example usage for android.text TextUtils split

List of usage examples for android.text TextUtils split

Introduction

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

Prototype

public static String[] split(String text, Pattern pattern) 

Source Link

Document

Splits a string on a pattern.

Usage

From source file:Main.java

public static String getLastwords(String srcText, String p) {
    try {//w  ww .  ja  v  a2s.c o  m
        String[] array = TextUtils.split(srcText, p);
        int index = (array.length - 1 < 0) ? 0 : array.length - 1;
        return array[index];
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static List<String> getValues(String prop) {
    List<String> values = new ArrayList<>();
    String[] split = TextUtils.split(prop, ":");
    if (split.length > 1) {
        for (int i = 1; i < split.length; i++) {
            values.add(split[i]);//from w  ww . j  ava2 s  .  c o m
        }
    }
    return values;
}

From source file:it.polimi.spf.framework.proximity.FieldContainerMarshaller.java

public static String[] unmarshallIdentifierList(String value) {
    return TextUtils.split(value, SEPARATOR);
}

From source file:com.google.android.vending.licensing.ResponseData.java

/**
 * Parses response string into ResponseData.
 *
 * @param responseData response data string
 * @throws IllegalArgumentException upon parsing error
 * @return ResponseData object/*from ww  w  .j a  va2s  .c o m*/
 */
public static ResponseData parse(String responseData) {
    // Must parse out main response data and response-specific data.
    int index = responseData.indexOf(':');
    String mainData, extraData;
    if (-1 == index) {
        mainData = responseData;
        extraData = "";
    } else {
        mainData = responseData.substring(0, index);
        extraData = index >= responseData.length() ? "" : responseData.substring(index + 1);
    }

    String[] fields = TextUtils.split(mainData, Pattern.quote("|"));
    if (fields.length < 6) {
        throw new IllegalArgumentException("Wrong number of fields.");
    }

    ResponseData data = new ResponseData();
    data.responseCode = Integer.parseInt(fields[0]);
    data.nonce = Integer.parseInt(fields[1]);
    data.packageName = fields[2];
    data.versionCode = fields[3];
    // Application-specific user identifier.
    data.userId = fields[4];
    data.timestamp = Long.parseLong(fields[5]);

    data.extras = decodeExtras(extraData);

    return data;
}

From source file:com.kerkr.edu.cache.CookieUtils.java

/**
 * Construct a persistent cookie store.//  ww w.  ja  va  2 s.co m
 */
public CookieUtils(Context context) {
    cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, Context.MODE_PRIVATE);
    cookies = new ConcurrentHashMap<String, Cookie>();

    // Load any previously stored cookies into the store
    String storedCookieNames = cookiePrefs.getString(COOKIE_NAME_STORE, null);
    if (storedCookieNames != null) {
        String[] cookieNames = TextUtils.split(storedCookieNames, ",");
        for (String name : cookieNames) {
            String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null);
            if (encodedCookie != null) {
                Cookie decodedCookie = decodeCookie(encodedCookie);
                if (decodedCookie != null) {
                    cookies.put(name, decodedCookie);
                }
            }
        }

        // Clear out expired cookies
        clearExpired(new Date());
    }
}

From source file:net.kjmaster.cookiemom.settings.SettingsActivity.java

@AfterViews
void afterViews() {
    if (iSettings.CookieList().get() == null) {
        iSettings.CookieList()/*from w ww  .j a v  a  2  s .  c o m*/
                .put(TextUtils.join(",", getResources().getStringArray(R.array.cookie_names_array)));
    } else {
        cookieList = iSettings.CookieList().get();
        String[] cookies = TextUtils.split(cookieList, ",");
        if (cookies.length != getResources().getStringArray(R.array.cookie_names_array).length) {
            cookieList = TextUtils.join(",", getResources().getStringArray(R.array.cookie_names_array));
        }
    }
    settingsFragment = SettingsFragment_.builder().build();
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.content, settingsFragment);
    ft.commit();

}

From source file:org.mobiletrial.license.ServerLicensingService.java

@Override
public void checkLicense(int nonce, String packageName, String versionCode, String userId,
        final ILicenseResultListener listener) {

    RestClient client = new RestClient(mContext, mWebserviceUrl);
    JSONObject body = new JSONObject();
    try {/*from ww  w  .  ja  va2s. c  o m*/
        long timestamp = new Date().getTime();
        body.put(PARAM_NONCE, nonce);
        body.put(PARAM_VERSIONCODE, versionCode);
        body.put(PARAM_TIMESTAMP, timestamp);
    } catch (JSONException e) {
        Log.w(TAG, "Error on creating server response");
        listener.verifyLicense(ERROR_SERVER_FAILURE, null, null);
    }

    String path = "/authorize/" + URLEncoder.encode(packageName) + "/customer/" + URLEncoder.encode(userId);

    client.post(path, body, new RestClient.OnRequestFinishedListener() {
        @Override
        public void gotResponse(String response) {
            try {
                if (response == null) {
                    // Incorrect response
                    listener.verifyLicense(ERROR_SERVER_FAILURE, null, null);
                    return;
                }

                response = response.replace("\"", "");
                String data[] = TextUtils.split(response, "--");
                if (data.length != 3) {
                    // Incorrect response
                    listener.verifyLicense(ERROR_SERVER_FAILURE, null, null);
                    return;
                }

                int responseCode = Integer.parseInt(data[0]);
                String signedData = data[1];
                String signature = data[2];

                listener.verifyLicense(responseCode, signedData, signature);
            } catch (NumberFormatException e) {
                // Incorrect response
                listener.verifyLicense(ERROR_SERVER_FAILURE, null, null);
            } catch (Exception e) {
                // Unknown error
                e.printStackTrace();
                listener.verifyLicense(ERROR_SERVER_FAILURE, null, null);
            }
        }

        @Override
        public void gotError(int errorCode) {
            // Error on contacting server .. no connection or server error (404, 500) 
            listener.verifyLicense(ERROR_SERVER_FAILURE, null, null);
        }
    });
}

From source file:cn.com.dfc.pl.afinal.http.PreferencesCookieStore.java

/**
 * Construct a persistent cookie store.//w w  w  .j  a v  a 2  s  . c o  m
 */
public PreferencesCookieStore(Context context) {
    cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, 0);
    cookies = new ConcurrentHashMap<String, Cookie>();

    // Load any previously stored cookies into the store
    String storedCookieNames = cookiePrefs.getString(COOKIE_NAME_STORE, null);
    if (storedCookieNames != null) {
        String[] cookieNames = TextUtils.split(storedCookieNames, ",");
        for (String name : cookieNames) {
            String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null);
            if (encodedCookie != null) {
                Cookie decodedCookie = decodeCookie(encodedCookie);
                if (decodedCookie != null) {
                    cookies.put(name, decodedCookie);
                }
            }
        }

        // Clear out expired cookies
        clearExpired(new Date());
    }
}

From source file:com.drive.student.xutils.util.CookieUtils.java

/**
 * Construct a persistent cookie store.//  w  w w.ja  v  a2  s  .c  o m
 */
public CookieUtils(Context context) {
    cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, Context.MODE_PRIVATE);
    cookies = new ConcurrentHashMap<String, Cookie>();

    // Load any previously stored cookies into the store
    String storedCookieNames = cookiePrefs.getString(COOKIE_NAME_STORE, null);
    if (storedCookieNames != null) {
        String[] cookieNames = TextUtils.split(storedCookieNames, ",");
        for (String name : cookieNames) {
            String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null);
            if (encodedCookie != null) {
                Cookie decodedCookie = decodeCookie(encodedCookie);
                if (decodedCookie != null) {
                    cookies.put(name, decodedCookie);
                }
            }
        }

        // Clear out expired cookies
        // clearExpired(new Date());
    }
}

From source file:cn.isif.util_plus.util.PreferencesCookieStore.java

/**
 * Construct a persistent cookie store./*from   ww  w.  j a  v a  2  s  .  c om*/
 */
public PreferencesCookieStore(Context context) {
    cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, Context.MODE_PRIVATE);
    cookies = new ConcurrentHashMap<String, Cookie>();

    // Load any previously stored cookies into the store
    String storedCookieNames = cookiePrefs.getString(COOKIE_NAME_STORE, null);
    if (storedCookieNames != null) {
        String[] cookieNames = TextUtils.split(storedCookieNames, ",");
        for (String name : cookieNames) {
            String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null);
            if (encodedCookie != null) {
                Cookie decodedCookie = decodeCookie(encodedCookie);
                if (decodedCookie != null) {
                    cookies.put(name, decodedCookie);
                }
            }
        }

        // Clear out expired cookies
        clearExpired(new Date());
    }
}