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:com.jaspersoft.android.jaspermobile.activities.profile.ServerProfileActivity.java

@TextChange(R.id.serverUrlEdit)
void onServerUrlTextChanges(CharSequence text) {
    serverUrl = text.toString();
    serverUrlEdit.setError(null);
    setSubmitActionState();
}

From source file:com.jaspersoft.android.jaspermobile.activities.profile.ServerProfileActivity.java

@TextChange(R.id.organizationEdit)
void onOrganizationTextChanges(CharSequence text) {
    organization = text.toString();
}

From source file:org.tradex.jdbc.JDBCHelper.java

/**
 * Issues a query for an Object/*from  ww w. jav  a2 s.  c om*/
 * @param <T> The expected return type
 * @param sql The SQL
 * @param clazz The expected return type
 * @param binds The bind values
 * @return an Object
 */
public <T> T templateQueryForObject(CharSequence sql, Class<T> clazz, Object... binds) {
    NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(ds);
    return template.queryForObject(sql.toString(), getBinds(sql.toString().trim().toUpperCase(), binds), clazz);
}

From source file:fr.cph.chicago.core.fragment.BusFragment.java

private void addView() {
    busAdapter = new BusAdapter(listView);
    listView.setAdapter(busAdapter);/*from www  .java  2 s.  c  om*/
    textFilter.setVisibility(TextView.VISIBLE);
    textFilter.addTextChangedListener(new TextWatcher() {

        final BusData busData = DataHolder.getInstance().getBusData();
        List<BusRoute> busRoutes = null;

        @Override
        public void beforeTextChanged(final CharSequence c, final int start, final int count, final int after) {
            busRoutes = new ArrayList<>();
        }

        @Override
        public void onTextChanged(final CharSequence c, final int start, final int before, final int count) {
            final List<BusRoute> busRoutes = busData.getBusRoutes();
            final CharSequence trimmed = c.toString().trim();
            this.busRoutes.addAll(Stream.of(busRoutes)
                    .filter(busRoute -> StringUtils.containsIgnoreCase(busRoute.getId(), trimmed)
                            || StringUtils.containsIgnoreCase(busRoute.getName(), trimmed))
                    .collect(Collectors.toList()));
        }

        @Override
        public void afterTextChanged(final Editable s) {
            busAdapter.setRoutes(busRoutes);
            busAdapter.notifyDataSetChanged();
        }
    });
}

From source file:org.tradex.jdbc.JDBCHelper.java

/**
 * Issues a named parameter query using numerical binds, starting at 0.
 * @param sql The SQL/* w ww.  j  a  v a  2  s  .  c om*/
 * @param binds The bind values
 * @return an Object array of the results
 */
public Object[][] templateQuery(CharSequence sql, Object... binds) {
    NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(ds);
    final List<Object[]> results = template.query(sql.toString(),
            getBinds(sql.toString().trim().toUpperCase(), binds), new RowMapper<Object[]>() {
                int columnCount = -1;

                @Override
                public Object[] mapRow(ResultSet rs, int rowNum) throws SQLException {
                    if (columnCount == -1)
                        columnCount = rs.getMetaData().getColumnCount();
                    Object[] row = new Object[columnCount];
                    for (int i = 0; i < columnCount; i++) {
                        row[i] = rs.getObject(i + 1);
                    }
                    return row;
                }
            });
    Object[][] ret = new Object[results.size()][];
    int cnt = 0;
    for (Object[] arr : results) {
        ret[cnt] = arr;
        cnt++;
    }
    return ret;
}

From source file:id.zelory.tanipedia.activity.TanyaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tanya);
    toolbar = (Toolbar) findViewById(R.id.anim_toolbar);
    setSupportActionBar(toolbar);//w w w  .j a va  2 s . co  m
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle("Tanya Tani");

    animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);
    fabMargin = getResources().getDimensionPixelSize(R.dimen.fab_margin);

    drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer);
    setUpNavDrawer();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.getMenu().getItem(2).setChecked(true);
    TextView nama = (TextView) navigationView.findViewById(R.id.nama);
    nama.setText(PrefUtils.ambilString(this, "nama"));
    TextView email = (TextView) navigationView.findViewById(R.id.email);
    email.setText(PrefUtils.ambilString(this, "email"));
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            Intent intent;
            switch (menuItem.getItemId()) {
            case R.id.cuaca:
                intent = new Intent(TanyaActivity.this, CuacaActivity.class);
                break;
            case R.id.berita:
                intent = new Intent(TanyaActivity.this, BeritaActivity.class);
                break;
            case R.id.tanya:
                return true;
            case R.id.harga:
                intent = new Intent(TanyaActivity.this, KomoditasActivity.class);
                break;
            case R.id.logout:
                PrefUtils.simpanString(TanyaActivity.this, "nama", null);
                intent = new Intent(TanyaActivity.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                return true;
            case R.id.tentang:
                intent = new Intent(TanyaActivity.this, TentangActivity.class);
                startActivity(intent);
                return true;
            default:
                return true;
            }
            startActivity(intent);
            finish();
            return true;
        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.scrollableview);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.addOnScrollListener(new MyRecyclerScroll() {
        @Override
        public void show() {
            fab.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
        }

        @Override
        public void hide() {
            fab.animate().translationY(fab.getHeight() + fabMargin)
                    .setInterpolator(new AccelerateInterpolator(2)).start();
        }
    });

    tanyaGambar = (ImageView) findViewById(R.id.tanya_gambar);
    tanyaGambar.setVisibility(View.GONE);
    fab = (FrameLayout) findViewById(R.id.myfab_main);
    fab.setVisibility(View.GONE);
    fabBtn = (ImageButton) findViewById(R.id.myfab_main_btn);
    View fabShadow = findViewById(R.id.myfab_shadow);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        fabShadow.setVisibility(View.GONE);
        fabBtn.setBackground(getDrawable(R.drawable.ripple_accent));
    }

    fabBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new MaterialDialog.Builder(TanyaActivity.this).title("TaniPedia").content("Kirim Pertanyaan")
                    .inputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_CLASS_TEXT)
                    .input("Ketik pertanyaan anda disini!", null, false, new MaterialDialog.InputCallback() {
                        @Override
                        public void onInput(MaterialDialog dialog, CharSequence input) {
                            try {
                                pertanyaan = URLEncoder.encode(input.toString(), "UTF-8");
                                new KirimSoal().execute();
                            } catch (UnsupportedEncodingException e) {
                                Snackbar.make(fabBtn, "Terjadi kesalahan, silahkan coba lagi!",
                                        Snackbar.LENGTH_LONG).show();
                                e.printStackTrace();
                            }
                        }
                    }).positiveColorRes(R.color.primary_dark).positiveText("Kirim")
                    .cancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {

                        }
                    }).negativeColorRes(R.color.primary_dark).negativeText("Batal").show();
        }
    });

    fabButton = (FabButton) findViewById(R.id.determinate);
    fabButton.showProgress(true);
    new DownloadData().execute();
    fabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fabButton.showProgress(true);
            new DownloadData().execute();
        }
    });
}

From source file:org.tradex.jdbc.JDBCHelper.java

/**
 * Executes the passed SQL as an update and returns the result code
 * @param sql The update SQL/*  w w  w.j a  v  a  2 s . co m*/
 * @return the result code
 */
public int executeUpdate(CharSequence sql) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = ds.getConnection();
        ps = conn.prepareStatement(sql.toString());
        conn.commit();
        return ps.executeUpdate();
    } catch (Exception e) {
        throw new RuntimeException("Update for [" + sql + "] failed", e);
    } finally {
        try {
            ps.close();
        } catch (Exception e) {
        }
        try {
            conn.close();
        } catch (Exception e) {
        }
    }
}

From source file:at.ait.dme.yuma.suite.apps.map.server.geo.GeocoderServiceImpl.java

private SemanticTag[] parseGeonamesResponse(CharSequence xml) throws Exception {
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.parse(new ByteArrayInputStream(xml.toString().getBytes("UTF-8")));

    ArrayList<SemanticTag> tags = new ArrayList<SemanticTag>();
    NodeList nodes = doc.getElementsByTagName("geoname");

    NodeList children;/*from  w  ww . j a v a2  s.c om*/
    ArrayList<String> countries = new ArrayList<String>();
    for (int i = 0; i < nodes.getLength(); i++) {
        String toponymName = null;
        String geonameId = null;
        String country = null;
        String lat = null;
        String lon = null;
        children = nodes.item(i).getChildNodes();
        for (int j = 0; j < children.getLength(); j++) {
            Node child = children.item(j);
            if (child.getNodeName().equals("toponymName")) {
                toponymName = child.getTextContent();
            } else if (child.getNodeName().equals("geonameId")) {
                geonameId = child.getTextContent();
            } else if (child.getNodeName().equals("countryName")) {
                // Store country --> we'll retrieve their geonameIds later, too!
                country = child.getTextContent();
                if (!countries.contains(country))
                    countries.add(country);
            } else if (child.getNodeName().equals("lat")) {
                lat = child.getTextContent();
            } else if (child.getNodeName().equals("lng")) {
                lon = child.getTextContent();
            }
        }
        if (toponymName != null && country != null && geonameId != null && lat != null && lon != null)
            tags.add(new SemanticTag(toponymName, getAlternativePlacenames(toponymName), "Place", "en",
                    toponymName + ", " + country + " (city) \nLatitude: " + lat + " \nLongitude: " + lon,
                    GEONAMES_URI_TEMPLATE.replace("@id@", geonameId)));
    }

    for (SemanticTag countryTag : getCountries(countries)) {
        tags.add(0, countryTag);
    }

    return tags.toArray(new SemanticTag[tags.size()]);
}

From source file:com.google.zxing.client.android.result.supplement.BookResultInfoRetriever.java

@Override
void retrieveSupplementalInfo() throws IOException {

    CharSequence contents = HttpHelper.downloadViaHttp(
            "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn, HttpHelper.ContentType.JSON);

    if (contents.length() == 0) {
        return;//w w w. j a  v a  2 s.  co m
    }

    String title;
    String pages;
    Collection<String> authors = null;

    try {

        JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue();
        JSONArray items = topLevel.optJSONArray("items");
        if (items == null || items.isNull(0)) {
            return;
        }

        JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo");
        if (volumeInfo == null) {
            return;
        }

        title = volumeInfo.optString("title");
        pages = volumeInfo.optString("pageCount");

        JSONArray authorsArray = volumeInfo.optJSONArray("authors");
        if (authorsArray != null && !authorsArray.isNull(0)) {
            authors = new ArrayList<String>(authorsArray.length());
            for (int i = 0; i < authorsArray.length(); i++) {
                authors.add(authorsArray.getString(i));
            }
        }

    } catch (JSONException e) {
        throw new IOException(e.toString());
    }

    Collection<String> newTexts = new ArrayList<String>();

    if (title != null && title.length() > 0) {
        newTexts.add(title);
    }

    if (authors != null && !authors.isEmpty()) {
        boolean first = true;
        StringBuilder authorsText = new StringBuilder();
        for (String author : authors) {
            if (first) {
                first = false;
            } else {
                authorsText.append(", ");
            }
            authorsText.append(author);
        }
        newTexts.add(authorsText.toString());
    }

    if (pages != null && pages.length() > 0) {
        newTexts.add(pages + "pp.");
    }

    String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
            + "/search?tbm=bks&source=zxing&q=";

    append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
}

From source file:edu.cornell.med.icb.pca.RotationReaderWriter.java

/**
 * Given the specified identifiers, save the rotation matrix to the cache.
 *
 * @param datasetEndpointName the dataset to find a table for
 * @param pathwayId          the pathwayId to find a table for
 * @param rowIds             the row ideas to save
 * @param rotation           the rotation table to save
 *///from  w ww .j  a v a 2  s.  c o  m
public void saveRotationMatrix(final CharSequence datasetEndpointName, final MutableString pathwayId,
        final List<CharSequence> rowIds, final double[][] rotation) {

    final int numColumns = rotation.length;
    final int numRows = rowIds.size();
    //    System.out.println(String.format("numColumns: %d numRows: %d", numColumns, numRows));
    for (final double[] column : rotation) {
        assert column.length == rowIds
                .size() : "number of rows of rotation matrix must match number of row identifiers.";
    }

    final String cachedTableFile = getRotationFile(datasetEndpointName, pathwayId);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Saving " + pathwayId + " to rotation file " + cachedTableFile);
    }
    CompoundDataOutput dataOutput = null;
    try {
        dataOutput = cfw.addFile(cachedTableFile);

        // Write the number of columns
        dataOutput.writeInt(numColumns);
        // Write the number of rows
        dataOutput.writeInt(numRows);

        for (final CharSequence rowId : rowIds) {
            dataOutput.writeUTF(rowId.toString());
        }

        for (int c = 0; c < numColumns; c++) {
            // write each column:

            final double[] doubleColumnData = rotation[c];
            final int numDoubles = doubleColumnData.length;
            dataOutput.writeInt(numDoubles);
            for (final double doubleColumnItem : doubleColumnData) {
                // Each double
                dataOutput.writeDouble(doubleColumnItem);
            }
        }

        LOG.trace("Rotation saved to cache.");
    } catch (Exception e) {
        LOG.error("Cannot cache table. ", e);
    } finally {
        if (dataOutput != null) {
            try {

                dataOutput.close();
            } catch (IOException e) {
                LOG.error("Error closing CompoundDataOutput", e);
            }
        }
    }
}