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:com.example.angelina.travelapp.map.MapFragment.java

/**
 * Populate the place detail contained//from  www . j ava 2 s  . co m
 * within the bottom sheet
 * @param place - Place item selected by user
 */
@Override
public final void showDetail(final Place place) {
    final TextView txtName = (TextView) mBottomSheet.findViewById(R.id.placeName);
    txtName.setText(place.getName());
    String address = place.getAddress();
    final String[] splitStrs = TextUtils.split(address, ",");
    if (splitStrs.length > 0) {
        address = splitStrs[0];
    }
    final TextView txtAddress = (TextView) mBottomSheet.findViewById(R.id.placeAddress);
    txtAddress.setText(address);
    final TextView txtPhone = (TextView) mBottomSheet.findViewById(R.id.placePhone);
    txtPhone.setText(place.getPhone());

    final LinearLayout linkLayout = (LinearLayout) mBottomSheet.findViewById(R.id.linkLayout);
    // Hide the link placeholder if no link is found
    if (place.getURL().isEmpty()) {
        linkLayout.setLayoutParams(new LinearLayoutCompat.LayoutParams(0, 0));
        linkLayout.requestLayout();
    } else {
        final int height = (int) (48 * Resources.getSystem().getDisplayMetrics().density);
        linkLayout.setLayoutParams(
                new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, height));
        linkLayout.requestLayout();
        final TextView txtUrl = (TextView) mBottomSheet.findViewById(R.id.placeUrl);
        txtUrl.setText(place.getURL());
    }

    final TextView txtType = (TextView) mBottomSheet.findViewById(R.id.placeType);
    txtType.setText(place.getType());

    // Assign the appropriate icon
    final Drawable d = CategoryHelper.getDrawableForPlace(place, getActivity());
    txtType.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

    // Center map on selected place
    mPresenter.centerOnPlace(place);
    mShowSnackbar = false;
    centeredPlaceName = place.getName();
}

From source file:com.crte.sipstackhome.ui.preferences.PreferencesWrapper.java

/**
 * Get list of audio codecs registered in preference system
 *
 * @return List of possible audio codecs
 * @see PreferencesProviderWrapper#setCodecList(java.util.List)
 *//*from   w ww  .j a va 2 s  .com*/
public String[] getCodecList() {
    return TextUtils.split(prefs.getString(CODECS_LIST, ""), Pattern.quote(CODECS_SEPARATOR));
}

From source file:com.crte.sipstackhome.ui.preferences.PreferencesWrapper.java

/**
 * Get list of video codecs registered in preference system by
 *
 * @return List of possible video codecs
 * @see PreferencesProviderWrapper#setVideoCodecList(java.util.List)
 *//*from   w w w  .  j  a  v  a  2s .  c  o  m*/
public String[] getVideoCodecList() {
    return TextUtils.split(prefs.getString(CODECS_VIDEO_LIST, ""), Pattern.quote(CODECS_SEPARATOR));
}

From source file:eu.chainfire.opendelta.UpdateService.java

private String findInitialFile(List<DeltaInfo> deltas, String possibleMatch, boolean[] needsProcessing) {
    // Find the currently flashed ZIP, or a newer one

    DeltaInfo firstDelta = deltas.get(0);

    updateState(STATE_ACTION_SEARCHING, null, null, null, null, null);

    String initialFile = null;//from  w  w  w.j  av a 2s . co  m

    // Check if an original flashable ZIP is in our preferred location
    String expectedLocation = config.getPathBase() + firstDelta.getIn().getName();
    DeltaInfo.FileSizeMD5 match = null;
    if (expectedLocation.equals(possibleMatch)) {
        match = firstDelta.getIn().match(new File(expectedLocation), false, null);
        if (match != null) {
            initialFile = possibleMatch;
        }
    }

    if (match == null) {
        match = firstDelta.getIn().match(new File(expectedLocation), true,
                getMD5Progress(STATE_ACTION_SEARCHING_MD5, firstDelta.getIn().getName()));
        if (match != null) {
            initialFile = expectedLocation;
        }
    }
    updateState(STATE_ACTION_SEARCHING, null, null, null, null, null);

    // If the user flashed manually, the file is probably not in our
    // preferred location (assuming it wasn't sideloaded), so search
    // the storages for it.
    if (initialFile == null) {
        // Primary external storage ( == internal storage)
        initialFile = findZIPOnSD(firstDelta.getIn(), Environment.getExternalStorageDirectory());

        if (initialFile == null) {
            // Search secondary external storages ( == sdcards, OTG drives, etc)                 
            String secondaryStorages = System.getenv("SECONDARY_STORAGE");
            if ((secondaryStorages != null) && (secondaryStorages.length() > 0)) {
                String[] storages = TextUtils.split(secondaryStorages, File.pathSeparator);
                for (String storage : storages) {
                    initialFile = findZIPOnSD(firstDelta.getIn(), new File(storage));
                    if (initialFile != null) {
                        break;
                    }
                }
            }
        }

        if (initialFile != null) {
            match = firstDelta.getIn().match(new File(initialFile), false, null);
        }
    }

    if ((needsProcessing != null) && (needsProcessing.length > 0)) {
        needsProcessing[0] = (initialFile != null) && (match != firstDelta.getIn().getStore());
    }

    return initialFile;
}

From source file:android.database.DatabaseUtils.java

/**
 * Creates a db and populates it with the sql statements in sqlStatements.
 *
 * @param context the context to use to create the db
 * @param dbName the name of the db to create
 * @param dbVersion the version to set on the db
 * @param sqlStatements the statements to use to populate the db. This should be a single string
 *   of the form returned by sqlite3's <tt>.dump</tt> command (statements separated by
 *   semicolons)//ww w  .j  av  a2  s.  c  o  m
 */
static public void createDbFromSqlStatements(Context context, String dbName, int dbVersion,
        String sqlStatements) {
    SQLiteDatabase db = context.openOrCreateDatabase(dbName, 0, null);
    // TODO: this is not quite safe since it assumes that all semicolons at the end of a line
    // terminate statements. It is possible that a text field contains ;\n. We will have to fix
    // this if that turns out to be a problem.
    String[] statements = TextUtils.split(sqlStatements, ";\n");
    for (String statement : statements) {
        if (TextUtils.isEmpty(statement))
            continue;
        db.execSQL(statement);
    }
    db.setVersion(dbVersion);
    db.close();
}

From source file:com.silentcircle.silenttext.application.SilentTextApplication.java

public List<String> getDeletedUsers() {
    if (deletedUsers.size() > 0) {
        return deletedUsers;
    }/*from  ww w  . j  ava2 s.  c  o m*/
    SharedPreferences prefs = getSharedPreferences(ChatsFragment.DELETED_USER_FROM_CONVERSATION_LIST,
            Context.MODE_PRIVATE);
    String serialized = prefs.getString(ChatsFragment.DELETED_USER_FROM_CONVERSATION_LIST, null);
    if (serialized != null) {
        deletedUsers = new ArrayList<String>(Arrays.asList(TextUtils.split(serialized, ",")));
    }
    return deletedUsers;
}

From source file:com.android.mail.compose.ComposeActivity.java

private void initFromRefMessage(int action) {
    setFieldsFromRefMessage(action);//from www . ja v  a2s . com

    // Check if To: address and email body needs to be prefilled based on extras.
    // This is used for reporting rendering feedback.
    if (MessageHeaderView.ENABLE_REPORT_RENDERING_PROBLEM) {
        Intent intent = getIntent();
        if (intent.getExtras() != null) {
            String toAddresses = intent.getStringExtra(EXTRA_TO);
            if (toAddresses != null) {
                addToAddresses(Arrays.asList(TextUtils.split(toAddresses, ",")));
            }
            String body = intent.getStringExtra(EXTRA_BODY);
            if (body != null) {
                setBody(body, false /* withSignature */);
            }
        }
    }
}

From source file:com.android.mail.compose.ComposeActivity.java

/**
 * Fill all the widgets with the content found in the Intent Extra, if any.
 * Also apply the same style to all widgets. Note: if initFromExtras is
 * called as a result of switching between reply, reply all, and forward per
 * the latest revision of Gmail, and the user has already made changes to
 * attachments on a previous incarnation of the message (as a reply, reply
 * all, or forward), the original attachments from the message will not be
 * re-instantiated. The user's changes will be respected. This follows the
 * web gmail interaction.//w ww. j  a  v a  2  s.c  om
 * @return {@code true} if the activity should not call {@link #finishSetup}.
 */
public boolean initFromExtras(Intent intent) {
    // If we were invoked with a SENDTO intent, the value
    // should take precedence
    final Uri dataUri = intent.getData();
    if (dataUri != null) {
        if (MAIL_TO.equals(dataUri.getScheme())) {
            initFromMailTo(dataUri.toString());
        } else {
            if (!mAccount.composeIntentUri.equals(dataUri)) {
                String toText = dataUri.getSchemeSpecificPart();
                if (toText != null) {
                    mTo.setText("");
                    addToAddresses(Arrays.asList(TextUtils.split(toText, ",")));
                }
            }
        }
    }

    String[] extraStrings = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
    if (extraStrings != null) {
        addToAddresses(Arrays.asList(extraStrings));
    }
    extraStrings = intent.getStringArrayExtra(Intent.EXTRA_CC);
    if (extraStrings != null) {
        addCcAddresses(Arrays.asList(extraStrings), null);
    }
    extraStrings = intent.getStringArrayExtra(Intent.EXTRA_BCC);
    if (extraStrings != null) {
        addBccAddresses(Arrays.asList(extraStrings));
    }

    String extraString = intent.getStringExtra(Intent.EXTRA_SUBJECT);
    if (extraString != null) {
        mSubject.setText(extraString);
    }

    for (String extra : ALL_EXTRAS) {
        if (intent.hasExtra(extra)) {
            String value = intent.getStringExtra(extra);
            if (EXTRA_TO.equals(extra)) {
                addToAddresses(Arrays.asList(TextUtils.split(value, ",")));
            } else if (EXTRA_CC.equals(extra)) {
                addCcAddresses(Arrays.asList(TextUtils.split(value, ",")), null);
            } else if (EXTRA_BCC.equals(extra)) {
                addBccAddresses(Arrays.asList(TextUtils.split(value, ",")));
            } else if (EXTRA_SUBJECT.equals(extra)) {
                mSubject.setText(value);
            } else if (EXTRA_BODY.equals(extra)) {
                setBody(value, true /* with signature */);
            } else if (EXTRA_QUOTED_TEXT.equals(extra)) {
                initQuotedText(value, true /* shouldQuoteText */);
            }
        }
    }

    Bundle extras = intent.getExtras();
    if (extras != null) {
        CharSequence text = extras.getCharSequence(Intent.EXTRA_TEXT);
        setBody((text != null) ? text : "", true /* with signature */);

        // TODO - support EXTRA_HTML_TEXT
    }

    mExtraValues = intent.getParcelableExtra(EXTRA_VALUES);
    if (mExtraValues != null) {
        LogUtils.d(LOG_TAG, "Launched with extra values: %s", mExtraValues.toString());
        initExtraValues(mExtraValues);
        return true;
    }

    return false;
}

From source file:com.android.mail.compose.ComposeActivity.java

/**
 * Initialize the compose view from a String representing a mailTo uri.
 * @param mailToString The uri as a string.
 *///w  ww  .  j  a  v a  2  s .  co  m
public void initFromMailTo(String mailToString) {
    // We need to disguise this string as a URI in order to parse it
    // TODO:  Remove this hack when http://b/issue?id=1445295 gets fixed
    Uri uri = Uri.parse("foo://" + mailToString);
    int index = mailToString.indexOf("?");
    int length = "mailto".length() + 1;
    String to;
    try {
        // Extract the recipient after mailto:
        if (index == -1) {
            to = decodeEmailInUri(mailToString.substring(length));
        } else {
            to = decodeEmailInUri(mailToString.substring(length, index));
        }
        if (!TextUtils.isEmpty(to)) {
            addToAddresses(Arrays.asList(TextUtils.split(to, ",")));
        }
    } catch (UnsupportedEncodingException e) {
        if (LogUtils.isLoggable(LOG_TAG, LogUtils.VERBOSE)) {
            LogUtils.e(LOG_TAG, "%s while decoding '%s'", e.getMessage(), mailToString);
        } else {
            LogUtils.e(LOG_TAG, e, "Exception  while decoding mailto address");
        }
    }

    List<String> cc = uri.getQueryParameters("cc");
    addCcAddresses(Arrays.asList(cc.toArray(new String[cc.size()])), null);

    List<String> otherTo = uri.getQueryParameters("to");
    addToAddresses(Arrays.asList(otherTo.toArray(new String[otherTo.size()])));

    List<String> bcc = uri.getQueryParameters("bcc");
    addBccAddresses(Arrays.asList(bcc.toArray(new String[bcc.size()])));

    // NOTE: Uri.getQueryParameters already decodes % encoded characters
    List<String> subject = uri.getQueryParameters("subject");
    if (subject.size() > 0) {
        mSubject.setText(decodeContentFromQueryParam(subject.get(0)));
    }

    List<String> body = uri.getQueryParameters("body");
    if (body.size() > 0) {
        setBody(decodeContentFromQueryParam(body.get(0)), true /* with signature */);
    }
}

From source file:com.tct.mail.compose.ComposeActivity.java

/**
 * Fill all the widgets with the content found in the Intent Extra, if any.
 * Also apply the same style to all widgets. Note: if initFromExtras is
 * called as a result of switching between reply, reply all, and forward per
 * the latest revision of Gmail, and the user has already made changes to
 * attachments on a previous incarnation of the message (as a reply, reply
 * all, or forward), the original attachments from the message will not be
 * re-instantiated. The user's changes will be respected. This follows the
 * web gmail interaction.//from w w  w .  j  ava 2s .c  om
 * @return {@code true} if the activity should not call {@link #finishSetup}.
 */
public boolean initFromExtras(Intent intent) {
    // If we were invoked with a SENDTO intent, the value
    // should take precedence
    final Uri dataUri = intent.getData();
    if (dataUri != null) {
        if (MAIL_TO.equals(dataUri.getScheme())) {
            initFromMailTo(dataUri.toString());
        } else {
            if (!mAccount.composeIntentUri.equals(dataUri)) {
                String toText = dataUri.getSchemeSpecificPart();
                // TS: junwei-xu 2015-03-23 EMAIL BUGFIX_980239 MOD_S
                //if (toText != null) {
                if (Address.isAllValid(toText)) {
                    // TS: junwei-xu 2015-04-23 EMAIL BUGFIX_980239 MOD_E
                    mTo.setText("");
                    addToAddresses(Arrays.asList(TextUtils.split(toText, ",")));
                }
            }
        }
    }

    String[] extraStrings = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
    if (extraStrings != null) {
        addToAddresses(Arrays.asList(extraStrings));
    }
    extraStrings = intent.getStringArrayExtra(Intent.EXTRA_CC);
    if (extraStrings != null) {
        addCcAddresses(Arrays.asList(extraStrings), null);
    }
    extraStrings = intent.getStringArrayExtra(Intent.EXTRA_BCC);
    if (extraStrings != null) {
        addBccAddresses(Arrays.asList(extraStrings));
    }

    String extraString = intent.getStringExtra(Intent.EXTRA_SUBJECT);
    if (extraString != null) {
        mSubject.setText(extraString);
    }

    for (String extra : ALL_EXTRAS) {
        if (intent.hasExtra(extra)) {
            String value = intent.getStringExtra(extra);
            if (EXTRA_TO.equals(extra)) {
                addToAddresses(Arrays.asList(TextUtils.split(value, ",")));
            } else if (EXTRA_CC.equals(extra)) {
                addCcAddresses(Arrays.asList(TextUtils.split(value, ",")), null);
            } else if (EXTRA_BCC.equals(extra)) {
                addBccAddresses(Arrays.asList(TextUtils.split(value, ",")));
            } else if (EXTRA_SUBJECT.equals(extra)) {
                mSubject.setText(value);
            } else if (EXTRA_BODY.equals(extra)) {
                //[BUGFIX]-Add-BEGINbySCDTABLET.yafang.wei,07/21/2016,2565329
                // Modifytofixsignatureshowsbeforebodyissuewhensharewebsitebyemail
                if (mBodyView.getText().toString().trim()
                        .equals(convertToPrintableSignature(mSignature).trim())) {
                    mBodyView.setText("");
                    setBody(value, true /* with signature */);
                    appendSignature();
                } else {
                    setBody(value, true /* with signature */);
                }
                //[BUGFIX]-Add-ENDbySCDTABLET.yafang.wei
            } else if (EXTRA_QUOTED_TEXT.equals(extra)) {
                initQuotedText(value, true /* shouldQuoteText */);
            }
        }
    }

    Bundle extras = intent.getExtras();
    //[BUGFIX]-MOD-BEGIN by TSNJ,wenlu.wu,10/20/2014,FR-739335
    if (extras != null && !mBodyAlreadySet) {
        //[BUGFIX]-MOD-END by TSNJ,wenlu.wu,10/20/2014,FR-739335
        CharSequence text = extras.getCharSequence(Intent.EXTRA_TEXT);
        //[BUGFIX]-Add-BEGINbySCDTABLET.yafang.wei,07/21/2016,2565329
        // Modifytofixsignatureshowsbeforebodyissuewhensharewebsitebyemail
        if (mBodyView.getText().toString().trim().equals(convertToPrintableSignature(mSignature).trim())) {
            mBodyView.setText("");
            setBody((text != null) ? text : "", true /* with signature */);
            appendSignature();
        } else {
            setBody((text != null) ? text : "", true /* with signature */);
        }
        //[BUGFIX]-Add-ENDbySCDTABLET.yafang.wei

        // TODO - support EXTRA_HTML_TEXT
    }

    mExtraValues = intent.getParcelableExtra(EXTRA_VALUES);
    if (mExtraValues != null) {
        LogUtils.d(LOG_TAG, "Launched with extra values: %s", mExtraValues.toString());
        initExtraValues(mExtraValues);
        return true;
    }

    return false;
}