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.borqs.browser.combo.BookmarksPageCallbacks.java

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

From source file:com.orange.ocara.ui.activity.EditAuditActivity.java

@AfterViews
void setUpSite() {
    siteItemListAdapter = new SiteItemListAdapter();

    site.setThreshold(1);/*from ww  w.ja  v a2 s .  c om*/
    site.setAdapter(siteItemListAdapter);
    site.setValidator(new AutoCompleteTextView.Validator() {
        SiteAutoCompleteView current;

        @Override
        public boolean isValid(CharSequence text) {
            Timber.v("Check is Valid : " + text);
            Timber.v("Check : " + current.format(currentSite, true));
            if (text.toString().equals(current.format(currentSite, true).toString())) {
                return true;
            }

            return false;
        }

        @Override
        public CharSequence fixText(CharSequence invalidText) {
            Timber.v("Returning fixed text");
            displayErrorBox(com.orange.ocara.R.string.edit_audit_site_unknown_title,
                    com.orange.ocara.R.string.edit_audit_site_unknown);
            return "";
        }
    });
    site.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (v.getId() == com.orange.ocara.R.id.site && !hasFocus) {
                ((AutoCompleteTextView) v).performValidation();
            }
        }
    });

    site.addTextChangedListener(new CheckTextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            currentSite = null;
            siteItemListAdapter.getFilter().filter(s);
            super.onTextChanged(s, start, before, count);
        }
    });

    createSite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Timber.v("create site");
            OcaraConfiguration.get().getCreateSite().createSite(EditAuditActivity.this);
        }
    });
}

From source file:com.example.cuisoap.agrimac.homePage.machineDetail.machineInfoFragment.java

public void addTextWatcher() {
    machine_name.addTextChangedListener(new TextWatcher() {
        @Override/*from ww w . ja  v a 2s .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) {
            machineDetailData.machine_name = s.toString();
        }
    });
    passenger_num.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) {
            machineDetailData.machine_maxpassenger = s.toString();
        }
    });
    power.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) {
            machineDetailData.machine_power = s.toString();
        }
    });
    wheel_distance.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) {
            machineDetailData.machine_wheeldistance = s.toString();
        }
    });
    check_time.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) {
            machineDetailData.machine_checktime = s.toString();
        }
    });
}

From source file:org.deviceconnect.android.uiapp.fragment.profile.ExtraProfileFragment.java

/**
 * ??.//from  w w  w .  ja v  a 2  s  .  co m
 * @param view ?
 */
protected void onClickSend(final View view) {
    // 
    final CharSequence inter = ((TextView) getView().findViewById(R.id.fragment_extra_interface)).getText();
    // 
    final CharSequence attr = ((TextView) getView().findViewById(R.id.fragment_extra_attribute)).getText();
    // 
    final String accessToken = getAccessToken();
    // 
    final CharSequence query = ((TextView) getView().findViewById(R.id.fragment_extra_query)).getText();

    final URIBuilder builder = new URIBuilder();
    builder.setProfile(mProfile);
    if (inter != null && inter.length() > 0) {
        builder.setInterface(inter.toString());
    }
    if (attr != null && attr.length() > 0) {
        builder.setAttribute(attr.toString());
    }
    builder.addParameter(DConnectMessage.EXTRA_DEVICE_ID, getSmartDevice().getId());
    if (accessToken != null) {
        builder.addParameter(DConnectMessage.EXTRA_ACCESS_TOKEN, accessToken);
    }
    if (query != null) {
        String path = query.toString();
        if (path.length() > 0) {
            String[] keyvalues = path.split("&");
            for (int i = 0; i < keyvalues.length; i++) {
                String[] kv = keyvalues[i].split("=");
                if (kv.length == 1) {
                    builder.addParameter(kv[0], "");
                } else if (kv.length == 2) {
                    builder.addParameter(kv[0], kv[1]);
                }
            }
        }
    }

    HttpRequest request = null;
    try {
        Spinner spinner = (Spinner) getView().findViewById(R.id.spinner);
        String method = (String) spinner.getSelectedItem();
        if (method.equals("GET")) {
            request = new HttpGet(builder.build());
        } else if (method.equals("POST")) {
            request = new HttpPost(builder.build());
        } else if (method.equals("PUT")) {
            request = new HttpPut(builder.build());
        } else if (method.equals("DELETE")) {
            request = new HttpDelete(builder.build());
        }
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                TextView tv = (TextView) getView().findViewById(R.id.fragment_extra_request);
                try {
                    String uri = builder.build().toASCIIString();
                    tv.setText(uri);
                } catch (URISyntaxException e) {
                    tv.setText("");
                }
            }
        });
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    (new AsyncTask<HttpRequest, Void, DConnectMessage>() {
        public DConnectMessage doInBackground(final HttpRequest... args) {
            if (args == null || args.length <= 0) {
                return new DConnectResponseMessage(DConnectMessage.RESULT_ERROR);
            }

            DConnectMessage message = new DConnectResponseMessage(DConnectMessage.RESULT_ERROR);
            try {
                HttpRequest request = args[0];
                HttpResponse response = getDConnectClient().execute(getDefaultHost(), request);
                message = (new HttpMessageFactory()).newDConnectMessage(response);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return message;
        }

        @Override
        protected void onPostExecute(final DConnectMessage result) {

            if (getActivity().isFinishing()) {
                return;
            }

            if (result == null) {
                return;
            }
            View view = getView();
            if (view != null) {
                TextView tv = (TextView) view.findViewById(R.id.fragment_extra_response);
                tv.setText(result.toString());
            }
        }
    }).execute(request);
}

From source file:com.android.screenspeak.eventprocessor.ProcessorPhoneticLetters.java

/**
 * Handle an event that indicates a key is held on the soft keyboard.
 *///  w ww.ja  v  a  2s . com
private void processKeyboardKeyEvent(AccessibilityEvent event) {
    final CharSequence text = AccessibilityEventUtils.getEventTextOrDescription(event);
    if (TextUtils.isEmpty(text)) {
        return;
    }

    String localeString = FALLBACK_LOCALE;
    InputMethodManager inputMethodManager = (InputMethodManager) mService
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    InputMethodSubtype inputMethod = inputMethodManager.getCurrentInputMethodSubtype();
    if (inputMethod != null) {
        localeString = inputMethod.getLocale();
    }

    String phoneticLetter = getPhoneticLetter(localeString, text.toString());
    if (phoneticLetter != null) {
        postPhoneticLetterRunnable(phoneticLetter);
    }
}

From source file:eu.edisonproject.training.wsd.BabelNet.java

private String getFromEdgesDB(CharSequence id) throws IOException {
    try (Admin admin = DBTools.getConn().getAdmin()) {
        if (admin.tableExists(EDGES_TBL_NAME)) {
            try (Table tbl = DBTools.getConn().getTable(EDGES_TBL_NAME)) {
                Get get = new Get(Bytes.toBytes(id.toString()));
                get.addFamily(Bytes.toBytes("jsonString"));
                Result r = tbl.get(get);
                return Bytes.toString(r.getValue(Bytes.toBytes("jsonString"), Bytes.toBytes("jsonString")));
            }// w  w w  .  j ava 2  s  .  c o  m
        }
    }
    return null;
}

From source file:com.google.visualization.datasource.DataSourceHelper.java

/**
 * Generates a string response for the given <code>DataTable</code>.
 *
 * @param dataTable The data table.//from w ww  . jav  a  2  s  .  com
 * @param dataSourceRequest The data source request.
 *
 * @return The response string.
 */
public static String generateResponse(DataTable dataTable, DataSourceRequest dataSourceRequest) {
    CharSequence response;
    ResponseStatus responseStatus = null;
    if (!dataTable.getWarnings().isEmpty()) {
        responseStatus = new ResponseStatus(StatusType.WARNING);
    }
    switch (dataSourceRequest.getDataSourceParameters().getOutputType()) {
    case CSV:
        response = CsvRenderer.renderDataTable(dataTable, dataSourceRequest.getUserLocale(), ",");
        break;
    case TSV_EXCEL:
        response = CsvRenderer.renderDataTable(dataTable, dataSourceRequest.getUserLocale(), "\t");
        break;
    case HTML:
        response = HtmlRenderer.renderDataTable(dataTable, dataSourceRequest.getUserLocale());
        break;
    case JSONP:
        // Appending a comment to the response to prevent the first characters to be the
        // response handler which is not controlled by the server.
        response = "// Data table response\n" + JsonRenderer
                .renderJsonResponse(dataSourceRequest.getDataSourceParameters(), responseStatus, dataTable);
        break;
    case JSON:
        response = JsonRenderer.renderJsonResponse(dataSourceRequest.getDataSourceParameters(), responseStatus,
                dataTable);
        break;
    default:
        // This should never happen.
        throw new RuntimeException("Unhandled output type.");
    }

    return response.toString();
}

From source file:de.schildbach.pte.AbstractTsiProvider.java

private NearbyLocationsResult jsonCoordRequest(final int lat, final int lon, final int maxDistance,
        final int maxStations) throws IOException {
    final HttpUrl.Builder url = stopFinderEndpoint.newBuilder().addPathSegments("SearchTripPoint/json");
    appendCommonRequestParams(url);//from  w  w w. j a  va2  s  .  c o  m
    url.addQueryParameter("Latitude", String.format(Locale.FRENCH, "%2.6f", latLonToDouble(lat)));
    url.addQueryParameter("Longitude", String.format(Locale.FRENCH, "%2.6f", latLonToDouble(lon)));
    url.addQueryParameter("MaxItems", Integer.toString(maxStations != 0 ? maxStations : 50));
    url.addQueryParameter("Perimeter", Integer.toString(maxDistance != 0 ? maxDistance : 1320));
    url.addQueryParameter("PointTypes", "Stop_Place");

    final CharSequence page = httpClient.get(url.build());
    try {
        final List<Location> stations = new ArrayList<>();
        final JSONObject head = new JSONObject(page.toString());

        final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);

        final int status = head.getInt("StatusCode");

        if (status != 200) {
            return new NearbyLocationsResult(header, status == 300 ? NearbyLocationsResult.Status.INVALID_ID
                    : NearbyLocationsResult.Status.SERVICE_DOWN);
        }

        JSONArray dataArray = head.getJSONArray("Data");
        for (int i = 0; i < dataArray.length(); i++) {
            JSONObject data = dataArray.getJSONObject(i);
            stations.add(parseJsonTransportLocation(data));
        }

        return new NearbyLocationsResult(header, stations);
    } catch (final JSONException x) {
        throw new ParserException(x);
    }
}

From source file:it.unimi.dsi.util.ImmutableExternalPrefixMap.java

/** Sets the dump stream of this external prefix map to a given filename.
 *
 * <P>This method sets the dump file used by this map, and should be only
 * called after deserialisation, providing exactly the file generated at
 * creation time. Essentially anything can happen if you do not follow the rules.
 *
 * <P>Note that this method will attempt to close the old stream, if present.
 *   //from  ww w  .j a  v  a 2s.  c o  m
 * @param dumpStreamFilename the name of the dump file.
 * @see #setDumpStream(InputBitStream)
 */

public void setDumpStream(final CharSequence dumpStreamFilename) throws FileNotFoundException {
    ensureNotSelfContained();
    safelyCloseDumpStream();
    iteratorIsUsable = false;
    final long newLength = new File(dumpStreamFilename.toString()).length();
    if (newLength != dumpStreamLength)
        throw new IllegalArgumentException("The size of the new dump file (" + newLength
                + ") does not match the original length (" + dumpStreamLength + ")");
    dumpStream = new InputBitStream(dumpStreamFilename.toString(), (int) (blockSize / 8));
}

From source file:de.schildbach.pte.AbstractTsiProvider.java

protected QueryTripsResult queryTripsFromContext(final Context context, final Date date, final boolean dep)
        throws IOException {
    final String mode;
    if (context.products != null) {
        final StringBuilder modeBuilder = new StringBuilder();
        for (Product p : context.products) {
            final String productName = translateToLocalProduct(p);
            if (productName != null)
                modeBuilder.append(productName).append("|");
        }/*  w w w  . j  a v  a  2 s. com*/
        mode = modeBuilder.substring(0, modeBuilder.length() - 1);
    } else {
        mode = null;
    }

    final HttpUrl.Builder url = tripEndpoint.newBuilder().addPathSegments("PlanTrip/json");
    appendCommonRequestParams(url);
    url.addQueryParameter("Disruptions", "0"); // XXX what does this even mean?
    url.addQueryParameter("Algorithm", "FASTEST");
    url.addQueryParameter("MaxWalkDist", "1000"); // XXX good value? (in meters)

    if (context.from.type == LocationType.STATION) {
        url.addQueryParameter("DepType", "STOP_PLACE");
        url.addQueryParameter("DepId", context.from.id + "$0");
    } else if (context.from.type == LocationType.POI) {
        url.addQueryParameter("DepType", "POI");
        url.addQueryParameter("DepId", context.from.id + "$0");
    } else {
        url.addQueryParameter("DepLat", Double.toString(latLonToDouble(context.from.lat)));
        url.addQueryParameter("DepLon", Double.toString(latLonToDouble(context.from.lon)));
    }

    if (context.to.type == LocationType.STATION) {
        url.addQueryParameter("ArrType", "STOP_PLACE");
        url.addQueryParameter("ArrId", context.to.id + "$0");
    } else if (context.to.type == LocationType.POI) {
        url.addQueryParameter("ArrType", "POI");
        url.addQueryParameter("ArrId", context.to.id + "$0");
    } else {
        url.addQueryParameter("ArrLat", Double.toString(latLonToDouble(context.to.lat)));
        url.addQueryParameter("ArrLon", Double.toString(latLonToDouble(context.to.lon)));
    }

    if (context.via != null) {
        if (context.via.type == LocationType.STATION) {
            url.addQueryParameter("ViaType", "STOP_PLACE");
            url.addQueryParameter("ViaId", context.via.id + "$0");
        } else if (context.via.type == LocationType.POI) {
            url.addQueryParameter("ViaType", "POI");
            url.addQueryParameter("ViaId", context.via.id + "$0");
        } else {
            url.addQueryParameter("ViaLat", Double.toString(latLonToDouble(context.via.lat)));
            url.addQueryParameter("ViaLon", Double.toString(latLonToDouble(context.via.lon)));
        }
    }

    final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    url.addQueryParameter("date", dateFormat.format(date));

    final DateFormat timeFormat = new SimpleDateFormat("HH-mm", Locale.US);
    url.addQueryParameter(dep ? "DepartureTime" : "ArrivalTime", timeFormat.format(date));

    url.addQueryParameter("WalkSpeed", translateWalkSpeed(context.walkSpeed));

    if (mode != null)
        url.addQueryParameter("Modes", mode);

    final CharSequence page = httpClient.get(url.build());
    try {
        final JSONObject head = new JSONObject(page.toString());

        final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);

        final JSONObject statusObj = head.optJSONObject("Status");

        if (statusObj == null) {
            return new QueryTripsResult(header, QueryTripsResult.Status.SERVICE_DOWN);
        }

        final String statusStr = statusObj.optString("Code");

        if ("NO_SOLUTION_FOR_REQUEST".equals(statusStr)) {
            return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS);
        }

        if (!"OK".equals(statusStr)) {
            return new QueryTripsResult(header, QueryTripsResult.Status.SERVICE_DOWN);
        }

        final JSONArray tripArray = head.getJSONObject("trips").getJSONArray("Trip");
        final List<Trip> trips = new ArrayList<>(tripArray.length());

        for (int i = 0; i < tripArray.length(); i++) {
            final JSONObject tripObject = tripArray.getJSONObject(i);
            trips.add(parseJsonJourneyplannerTrip(tripObject));
        }

        if (trips.size() > 0) {
            context.updateEarliestArrival(trips.get(0).getLastArrivalTime());
            context.updateLatestDeparture(trips.get(trips.size() - 1).getFirstDepartureTime());
        }

        return new QueryTripsResult(header, url.build().toString(), context.from, context.via, context.to,
                context, trips);
    } catch (final JSONException x) {
        throw new ParserException(x);
    }
}