Example usage for java.lang CharSequence toString

List of usage examples for java.lang CharSequence toString

Introduction

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

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

From source file:io.github.sunggu.searchimage.ui.ImageGridFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View v = inflater.inflate(R.layout.image_search_fragment, container, false);

    edtSearchKeyword = (EditText) v.findViewById(R.id.search_keyword);
    edtSearchKeyword.addTextChangedListener(new TextWatcher() {
        @Override/* www  .j a v  a 2 s  .  c o m*/
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            OpenApi.getInstance().requestSearchImage(s.toString(), mResponseListener, mErrorListener);
        }
    });

    final GridView mGridView = (GridView) v.findViewById(R.id.search_result_grid);
    mGridView.setAdapter(mAdapter);
    mGridView.setOnItemClickListener(this);
    mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            // Pause fetcher to ensure smoother scrolling when flinging
            if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
                // Before Honeycomb pause image loading on scroll to help with performance
                if (!Utils.hasHoneycomb()) {
                    mImageFetcher.setPauseWork(true);
                }
            } else {
                mImageFetcher.setPauseWork(false);
            }
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
        }
    });

    // This listener is used to get the final width of the GridView and then calculate the
    // number of columns and the width of each column. The width of each column is variable
    // as the GridView has stretchMode=columnWidth. The column width is used to set the height
    // of each view so we get nice square thumbnails.
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @TargetApi(VERSION_CODES.JELLY_BEAN)
        @Override
        public void onGlobalLayout() {
            if (mAdapter.getNumColumns() == 0) {
                final int numColumns = (int) Math
                        .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
                if (numColumns > 0) {
                    final int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing;
                    mAdapter.setNumColumns(numColumns);
                    mAdapter.setItemHeight(columnWidth);
                    if (BuildConfig.DEBUG) {
                        Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
                    }
                    if (Utils.hasJellyBean()) {
                        mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }
            }
        }
    });

    return v;
}

From source file:gsn.storage.SQLUtils.java

/**
 * Table renaming, note that the renameMapping should be a tree map. This
 * method gets a sql query and changes the table names using the mappings
 * provided in the second argument.<br>
 * /*  w w w .j a v a  2s . co  m*/
 * @param query
 * @param renameMapping
 * @return
 */
public static StringBuilder newRewrite(CharSequence query, TreeMap<CharSequence, CharSequence> renameMapping) {
    // Selecting strings between pair of "" : (\"[^\"]*\")
    // Selecting tableID.tableName or tableID.* : (\\w+(\\.(\w+)|\\*))
    // The combined pattern is : (\"[^\"]*\")|(\\w+\\.((\\w+)|\\*))
    Pattern pattern = Pattern.compile("(\"[^\"]*\")|((\\w+)(\\.((\\w+)|\\*)))", Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(query);
    StringBuffer result = new StringBuffer();
    if (!(renameMapping.comparator() instanceof CaseInsensitiveComparator))
        throw new RuntimeException("Query rename needs case insensitive treemap.");
    while (matcher.find()) {
        if (matcher.group(2) == null)
            continue;
        String tableName = matcher.group(3);
        CharSequence replacement = renameMapping.get(tableName);
        // $4 means that the 4th group of the match should be appended to the
        // string (the forth group contains the field name).
        if (replacement != null)
            matcher.appendReplacement(result, new StringBuilder(replacement).append("$4").toString());
    }
    String toReturn = matcher.appendTail(result).toString().toLowerCase();

    //TODO " from " has to use regular expressions because now from is separated through space which is not always the case, for instance if the user uses \t(tab) for separating "from" from the rest of the query, then we get exception. The same issue with other sql keywords in this method.

    int indexOfFrom = toReturn.indexOf(" from ") >= 0 ? toReturn.indexOf(" from ") + " from ".length() : 0;
    int indexOfWhere = (toReturn.lastIndexOf(" where ") > 0 ? (toReturn.lastIndexOf(" where "))
            : toReturn.length());
    String selection = toReturn.substring(indexOfFrom, indexOfWhere);
    Pattern fromClausePattern = Pattern.compile("\\s*(\\w+)\\s*", Pattern.CASE_INSENSITIVE);
    Matcher fromClauseMather = fromClausePattern.matcher(selection);
    result = new StringBuffer();
    while (fromClauseMather.find()) {
        if (fromClauseMather.group(1) == null)
            continue;
        String tableName = fromClauseMather.group(1);
        CharSequence replacement = renameMapping.get(tableName);
        if (replacement != null)
            fromClauseMather.appendReplacement(result, replacement.toString() + " ");
    }
    String cleanFromClause = fromClauseMather.appendTail(result).toString();
    String finalResult = StringUtils.replace(toReturn, selection, cleanFromClause);
    return new StringBuilder(finalResult);
}

From source file:it.unimi.di.big.mg4j.document.SimpleCompressedDocumentCollection.java

@Override
public void filename(CharSequence filename) throws IOException {
    if (!fileMappingOk)
        initMappings(new File(new File(filename.toString()).getParentFile(), basename).toString(), true);
    if (!fileOpenOk) {
        loadOffsets(new File(new File(filename.toString()).getParentFile(), basename).toString(), true);
        initFiles(new File(new File(filename.toString()).getParentFile(), basename).toString(), true);
    }/*from   w w  w .  j  ava 2s  .  c o  m*/
}

From source file:com.example.hbranciforte.trafficclient.DataTraffic.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_data_traffic);
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }/*ww w.  j av  a2s.c  om*/
    try {
        zone_info = new JSONObject((String) getIntent().getSerializableExtra("zone_info"));
    } catch (JSONException e) {
        e.printStackTrace();
    }
    EditText ed_fichas = (EditText) findViewById(R.id.fichas);
    ed_fichas.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            //float price = (float) 0.0;
            Integer time = 0;
            TextView txtvalor = (TextView) findViewById(R.id.valor);
            TextView txttiempo = (TextView) findViewById(R.id.txtTime);
            if (s.toString() != "") {
                try {
                    price = (float) zone_info.getDouble("unit_price") * Float.valueOf(s.toString());
                    time = zone_info.getInt("unit_time") * Integer.parseInt(s.toString());
                    txtvalor.setText("$ ".concat(Float.toString(price)));
                    txttiempo.setText(time.toString().concat(" min"));
                } catch (Exception e) {
                    Log.e("getting data0:", e.getMessage());
                    txttiempo.setText("0 min");
                    txtvalor.setText("$ 0.0");

                }
            }
        }
    });
}

From source file:com.googlecode.android_scripting.facade.AndroidFacade.java

@Rpc(description = "Read text from the clipboard.", returns = "The text in the clipboard.")
public String getClipboard() {
    CharSequence text = getClipboardManager().getText();
    return text == null ? null : text.toString();
}

From source file:com.stratelia.silverpeas.silverstatistics.control.SilverStatisticsManager.java

private void sendStatistic(StatType type, CharSequence stat) {
    if (isAsynchronStats(type)) {
        SilverStatisticsSender mySilverStatisticsSender = new SilverStatisticsSender();
        try {/*from w  w w.  ja  v a2 s .  c  om*/
            SilverTrace.info("silverstatistics", "SilverStatisticsManager.sendStatistic",
                    "root.MSG_GEN_PARAM_VALUE", "stat=" + type + ' ' + stat.toString());
            mySilverStatisticsSender.send(type, stat.toString());
            SilverTrace.debug("silverstatistics", "SilverStatisticsManager.sendStatistic", "after send");
        } catch (Exception e) {
            SilverTrace.error("silverstatistics", "SilverStatisticsManager.sendStatistic",
                    "SilverStatisticsSender ", e);
        } finally {
            IOUtils.closeQuietly(mySilverStatisticsSender);
        }
    } // synchrone
    else {
        SilverTrace.info("silverstatistics", "SilverStatisticsManager.sendStatistic",
                "root.MSG_GEN_PARAM_VALUE", "stat=" + type + ' ' + stat.toString());
        getSilverStatistics().putStats(type, stat.toString());
        SilverTrace.debug("silverstatistics", "SilverStatisticsManager.sendStatistic", "after putStats");
    }
}

From source file:com.android.browser.BookmarksPageCallbacks.java

private void copy(CharSequence text) {
    ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    cm.setPrimaryClip(ClipData.newRawUri(null, Uri.parse(text.toString())));
}

From source file:com.twosigma.beaker.scala.util.ScalaEvaluator.java

public List<String> autocomplete(String code, int caretPosition) {
    if (acshell != null) {
        String[] sv = code.substring(0, caretPosition).split("\n");
        for (int i = 0; i < sv.length - 1; i++) {
            acshell.evaluate2(sv[i]);//from w  w w.ja v a  2  s.c o m
            caretPosition -= sv[i].length() + 1;
        }
        ArrayList<CharSequence> ret = acshell.autocomplete(sv[sv.length - 1], caretPosition);
        ArrayList<String> r2 = new ArrayList<String>();
        for (CharSequence c : ret)
            r2.add(c.toString());
        logger.debug("return: {}", r2);
        return r2;
    }
    return null;
}

From source file:com.twosigma.beaker.scala.evaluator.ScalaEvaluator.java

@Override
public AutocompleteResult autocomplete(String code, int caretPosition) {
    if (acshell != null) {
        String[] sv = code.substring(0, caretPosition).split("\n");
        for (int i = 0; i < sv.length - 1; i++) {
            acshell.evaluate2(sv[i]);//  www.  j ava2  s . c om
            caretPosition -= sv[i].length() + 1;
        }
        ArrayList<CharSequence> ret = acshell.autocomplete(sv[sv.length - 1], caretPosition);
        ArrayList<String> r2 = new ArrayList<String>();
        for (CharSequence c : ret)
            r2.add(c.toString());
        logger.debug("return: {}", r2);
        return new AutocompleteResult(r2, caretPosition);
    }
    return null;
}