Example usage for java.lang CharSequence length

List of usage examples for java.lang CharSequence length

Introduction

In this page you can find the example usage for java.lang CharSequence length.

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:com.Beat.RingdroidEditActivity.java

private String makeRingtoneFilename(CharSequence title, String extension) {
    String parentdir;//  w  w  w  .  jav  a2  s  .  c o  m
    switch (mNewFileKind) {
    default:
    case FileSaveDialog.FILE_KIND_MUSIC:
        parentdir = "/sdcard/media/audio/music";
        break;
    case FileSaveDialog.FILE_KIND_ALARM:
        parentdir = "/sdcard/media/audio/alarms";
        break;
    case FileSaveDialog.FILE_KIND_NOTIFICATION:
        parentdir = "/sdcard/media/audio/notifications";
        break;
    case FileSaveDialog.FILE_KIND_RINGTONE:
        parentdir = "/sdcard/media/audio/ringtones";
        break;

    }

    // Create the parent directory
    File parentDirFile = new File(parentdir);
    parentDirFile.mkdirs();

    // If we can't write to that special path, try just writing
    // directly to the sdcard
    if (!parentDirFile.isDirectory()) {
        parentdir = "/sdcard";
    }

    // Turn the title into a filename
    String filename = "";
    for (int i = 0; i < title.length(); i++) {
        if (Character.isLetterOrDigit(title.charAt(i))) {
            filename += title.charAt(i);
        }
    }

    // Try to make the filename unique
    String path = null;
    for (int i = 0; i < 100; i++) {
        String testPath;
        if (i > 0)
            testPath = parentdir + "/" + filename + i + extension;
        else
            testPath = parentdir + "/" + filename + extension;

        try {
            RandomAccessFile f = new RandomAccessFile(new File(testPath), "r");
        } catch (Exception e) {
            // Good, the file didn't exist
            path = testPath;
            break;
        }
    }

    return path;
}

From source file:eu.webtoolkit.jwt.WApplication.java

/**
 * Adds an HTML meta header./*from w  w  w  .j ava 2  s  .  c  o m*/
 * <p>
 * This method sets either a &quot;name&quot; meta headers, which configures
 * a document property, or a &quot;http-equiv&quot; meta headers, which
 * defines a HTTP headers (but these latter headers are being deprecated).
 * <p>
 * A meta header can however only be added in the following situations:
 * <p>
 * <ul>
 * <li>when a plain HTML session is used (including when the user agent is a
 * bot), you can add meta headers at any time.</li>
 * <li>or, when DOCREF<a class="el"
 * href="overview.html#progressive_bootstrap">progressive bootstrap</a> is
 * used, you can set meta headers for any type of session, from within the
 * application constructor (which corresponds to the initial request).</li>
 * <li>but never for a {@link EntryPointType#WidgetSet} mode application
 * since then the application is hosted within a foreign HTML page.</li>
 * </ul>
 * <p>
 * These situations coincide with {@link WEnvironment#hasAjax()
 * WEnvironment#hasAjax()} returning <code>false</code> (see
 * {@link WApplication#getEnvironment() getEnvironment()}). The reason that
 * it other cases the HTML page has already been rendered, and will not be
 * rerendered since all updates are done dynamically.
 * <p>
 * As an alternative, you can use the &lt;meta-headers&gt; configuration
 * property in the configuration file, which will be applied in all
 * circumstances.
 * <p>
 * 
 * @see WApplication#removeMetaHeader(MetaHeaderType type, String name)
 */
public void addMetaHeader(MetaHeaderType type, final String name, final CharSequence content,
        final String lang) {
    if (this.getEnvironment().hasJavaScript()) {
        logger.warn(new StringWriter().append("WApplication::addMetaHeader() with no effect").toString());
    }
    for (int i = 0; i < this.metaHeaders_.size(); ++i) {
        final MetaHeader m = this.metaHeaders_.get(i);
        if (m.type == type && m.name.equals(name)) {
            if ((content.length() == 0)) {
                this.metaHeaders_.remove(0 + i);
            } else {
                m.content = WString.toWString(content);
            }
            return;
        }
    }
    if (!(content.length() == 0)) {
        this.metaHeaders_.add(new MetaHeader(type, name, content, lang, ""));
    }
}

From source file:net.oschina.app.v2.activity.zxing.CaptureActivity.java

private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {
    //- ------------------------------------------------------- //
    String text = rawResult.getText();
    if (text != null && StringUtils.isUrl(text)) {
        if (text.contains("scan_login")) {
            statusView.setVisibility(View.GONE);
            viewfinderView.setVisibility(View.GONE);
            showConfirmLogin(text);/*from w w  w  .j av a  2s  .c  o  m*/
            return;
        }
        if (text.contains("oschina.net")) {
            UIHelper.showUrlRedirect(CaptureActivity.this, text);
            finish();
            return;
        }
    }
    try {
        BarCode2 bc = BarCode2.parse(text);
        int type = bc.getType();
        switch (type) {
        case BarCode2.SIGN_IN:// 
            handleSignIn(bc);
            return;
        default:
            break;
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    //- ------------------------------------------------------- //
    CharSequence displayContents = resultHandler.getDisplayContents();

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
        ClipboardInterface.setText(displayContents, this);
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    if (resultHandler.getDefaultButtonID() != null
            && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) {
        resultHandler.handleButtonPress(resultHandler.getDefaultButtonID());
        return;
    }

    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
        barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.app_icon));
    } else {
        barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp())));

    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
        StringBuilder metadataText = new StringBuilder(20);
        for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
            if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
                metadataText.append(entry.getValue()).append('\n');
            }
        }
        if (metadataText.length() > 0) {
            metadataText.setLength(metadataText.length() - 1);
            metaTextView.setText(metadataText);
            metaTextView.setVisibility(View.VISIBLE);
            metaTextViewLabel.setVisibility(View.VISIBLE);
        }
    }

    TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    contentsTextView.setText(displayContents);
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
    supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL,
            true)) {
        //SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
        //        resultHandler.getResult(),
        //        historyManager,
        //        this);
    }

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
        TextView button = (TextView) buttonView.getChildAt(x);
        if (x < buttonCount) {
            button.setVisibility(View.VISIBLE);
            button.setText(resultHandler.getButtonText(x));
            button.setOnClickListener(new ResultButtonListener(resultHandler, x));
        } else {
            button.setVisibility(View.GONE);
        }
    }
}

From source file:android.content.pm.PackageParser.java

private static String buildClassName(String pkg, CharSequence clsSeq, String[] outError) {
    if (clsSeq == null || clsSeq.length() <= 0) {
        outError[0] = "Empty class name in package " + pkg;
        return null;
    }/*w  w w.  j av a2  s  .c  o m*/
    String cls = clsSeq.toString();
    char c = cls.charAt(0);
    if (c == '.') {
        return (pkg + cls).intern();
    }
    if (cls.indexOf('.') < 0) {
        StringBuilder b = new StringBuilder(pkg);
        b.append('.');
        b.append(cls);
        return b.toString().intern();
    }
    if (c >= 'a' && c <= 'z') {
        return cls.intern();
    }
    outError[0] = "Bad class name " + cls + " in package " + pkg;
    return null;
}

From source file:android.content.pm.PackageParser.java

private static String buildTaskAffinityName(String pkg, String defProc, CharSequence procSeq,
        String[] outError) {// w  w  w  .  j ava  2s.c  o  m
    if (procSeq == null) {
        return defProc;
    }
    if (procSeq.length() <= 0) {
        return null;
    }
    return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
}

From source file:com.kodemore.utility.Kmu.java

/**
 * Determine if s is either null or an empty string.
 *///  ww w.  j  a  v a2s. c  o m
public static boolean isEmpty(CharSequence s) {
    return s == null || s.length() == 0;
}

From source file:android.content.pm.PackageParser.java

private static String buildProcessName(String pkg, String defProc, CharSequence procSeq, int flags,
        String[] separateProcesses, String[] outError) {
    if ((flags & PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
        return defProc != null ? defProc : pkg;
    }// w  w w. j a v  a2  s  . com
    if (separateProcesses != null) {
        for (int i = separateProcesses.length - 1; i >= 0; i--) {
            String sp = separateProcesses[i];
            if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
                return pkg;
            }
        }
    }
    if (procSeq == null || procSeq.length() <= 0) {
        return defProc;
    }
    return buildCompoundName(pkg, procSeq, "process", outError);
}

From source file:com.cleverzone.zhizhi.capture.CaptureActivity.java

private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {

    final CharSequence displayContents = resultHandler.getDisplayContents();

    //        if (copyToClipboard && !resultHandler.areContentsSecure()) {
    //            ClipboardInterface.setText(displayContents, this);
    //        }//from ww  w .  j ava 2  s  .c om

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    //        if (resultHandler.getDefaultButtonID() != null && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) {
    //            resultHandler.handleButtonPress(resultHandler.getDefaultButtonID());
    //            return;
    //        }

    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
        barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
    } else {
        barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp())));

    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
        StringBuilder metadataText = new StringBuilder(20);
        for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
            if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
                metadataText.append(entry.getValue()).append('\n');
            }
        }
        if (metadataText.length() > 0) {
            metadataText.setLength(metadataText.length() - 1);
            metaTextView.setText(metadataText);
            metaTextView.setVisibility(View.VISIBLE);
            metaTextViewLabel.setVisibility(View.VISIBLE);
        }
    }

    final TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    final String baseUrl = "http://qrk.kuaipai.cn/loganal/base/scan/show-json-advert.action?code=";
    new Thread(new Runnable() {
        @Override
        public void run() {
            HttpGet get = new HttpGet(baseUrl + displayContents);
            Log.e(TAG, "full url = " + baseUrl + displayContents);
            HttpClient client = new DefaultHttpClient();
            try {
                HttpResponse response = client.execute(get);
                String json = EntityUtils.toString(response.getEntity(), "UTF-8");
                JSONObject jsonObject = new JSONObject(json);
                NetScanResult result = new NetScanResult();
                result.name = jsonObject.getString("name");
                result.url = jsonObject.getString("img");
                Message message = new Message();
                message.obj = result;
                message.what = 1;
                mNetHandler.sendMessage(message);

            } catch (Exception e) {
                mNetHandler.sendEmptyMessage(-1);
                e.printStackTrace();
            }
        }
    }).start();
    //        contentsTextView.setText(displayContents);
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
    supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
    //        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
    //                PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
    //            SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
    //                    resultHandler.getResult(),
    //                    historyManager,
    //                    this);
    //        }

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
        TextView button = (TextView) buttonView.getChildAt(x);
        if (x < buttonCount) {
            button.setVisibility(View.VISIBLE);
            button.setText(resultHandler.getButtonText(x));
            button.setOnClickListener(new ResultButtonListener(resultHandler, x));
        } else {
            button.setVisibility(View.GONE);
        }
    }

}

From source file:ths.commons.util.StringUtils.java

/**
 * <p>Checks if a CharSequence is whitespace, empty ("") or null.</p>
 *
 * <pre>/* www.ja v a2 s  .  co  m*/
 * StringUtils.isBlank(null)      = true
 * StringUtils.isBlank("")        = true
 * StringUtils.isBlank(" ")       = true
 * StringUtils.isBlank("bob")     = false
 * StringUtils.isBlank("  bob  ") = false
 * </pre>
 *
 * @param cs  the CharSequence to check, may be null
 * @return {@code true} if the CharSequence is null, empty or whitespace
 */
public static boolean isBlank(CharSequence cs) {
    int strLen;
    if (cs == null || (strLen = cs.length()) == 0) {
        return true;
    }
    for (int i = 0; i < strLen; i++) {
        if ((Character.isWhitespace(cs.charAt(i)) == false)) {
            return false;
        }
    }
    return true;
}

From source file:ths.commons.util.StringUtils.java

/**
 * <p>Checks if the CharSequence contains only Unicode letters and
 * space (' ').</p>//from w  ww . jav a  2s . co  m
 *
 * <p>{@code null} will return {@code false}
 * An empty CharSequence (length()=0) will return {@code true}.</p>
 *
 * <pre>
 * StringUtils.isAlphaSpace(null)   = false
 * StringUtils.isAlphaSpace("")     = true
 * StringUtils.isAlphaSpace("  ")   = true
 * StringUtils.isAlphaSpace("abc")  = true
 * StringUtils.isAlphaSpace("ab c") = true
 * StringUtils.isAlphaSpace("ab2c") = false
 * StringUtils.isAlphaSpace("ab-c") = false
 * </pre>
 *
 * @param cs  the CharSequence to check, may be null
 * @return {@code true} if only contains letters and space,
 *  and is non-null
 * @since 3.0 Changed signature from isAlphaSpace(String) to isAlphaSpace(CharSequence)
 */
public static boolean isAlphaSpace(CharSequence cs) {
    if (cs == null) {
        return false;
    }
    int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if ((Character.isLetter(cs.charAt(i)) == false) && (cs.charAt(i) != ' ')) {
            return false;
        }
    }
    return true;
}