Example usage for android.text TextUtils isDigitsOnly

List of usage examples for android.text TextUtils isDigitsOnly

Introduction

In this page you can find the example usage for android.text TextUtils isDigitsOnly.

Prototype

public static boolean isDigitsOnly(CharSequence str) 

Source Link

Document

Returns whether the given CharSequence contains only digits.

Usage

From source file:com.dgsd.android.ShiftTracker.Fragment.EditShiftFragment.java

private String validateBreakDuration() {
    final CharSequence breakDurationAsStr = mUnpaidBreak.getText();
    if (TextUtils.isEmpty(breakDurationAsStr))
        return null;

    if (!TextUtils.isDigitsOnly(breakDurationAsStr)) {
        String error = "Invalid break time";
        mUnpaidBreak.setError(error);/*from   ww w . j  a v  a  2s  . co  m*/
        return error;
    }

    final Shift shift = getShift();
    if (((shift.getEndTime() - shift.getStartTime()) / TimeUtils.InMillis.MINUTE) < shift.breakDuration) {
        String error = "Break duration longer than shift";
        mUnpaidBreak.setError(error);
        return error;
    }

    return null;
}

From source file:com.money.manager.ex.transactions.EditTransactionCommonFunctions.java

public void initTransactionNumberControls() {
    // Transaction number

    if (!TextUtils.isEmpty(transactionEntity.getTransactionNumber())) {
        viewHolder.edtTransNumber.setText(transactionEntity.getTransactionNumber());
    }/*  w ww  . j a v  a  2s . com*/

    viewHolder.edtTransNumber.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            setDirty(true);

            transactionEntity.setTransactionNumber(editable.toString());
        }
    });

    viewHolder.btnTransNumber.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AccountTransactionRepository repo = new AccountTransactionRepository(getContext());

            String sql = "SELECT MAX(CAST(" + ITransactionEntity.TRANSACTIONNUMBER + " AS INTEGER)) FROM "
                    + repo.getSource() + " WHERE " + ITransactionEntity.ACCOUNTID + "=?";

            String accountId = transactionEntity.getAccountId().toString();
            Cursor cursor = mDatabase.query(sql, accountId);
            if (cursor == null)
                return;

            if (cursor.moveToFirst()) {
                String transNumber = cursor.getString(0);
                if (TextUtils.isEmpty(transNumber)) {
                    transNumber = "0";
                }
                if ((!TextUtils.isEmpty(transNumber)) && TextUtils.isDigitsOnly(transNumber)) {
                    try {
                        // Use Money type to support very large numbers.
                        Money transactionNumber = MoneyFactory.fromString(transNumber);
                        viewHolder.edtTransNumber
                                .setText(transactionNumber.add(MoneyFactory.fromString("1")).toString());
                    } catch (Exception e) {
                        Timber.e(e, "increasing transaction number");
                    }
                }
            }
            cursor.close();
        }
    });
}

From source file:com.cartlc.tracker.server.DCPing.java

boolean sendEntry(DataEntry entry) {
    boolean success = false;
    Timber.i("sendEntry(" + entry.id + ")");
    try {//from  w  ww.  j a v  a  2 s  .  c  om
        JSONObject jsonObject = new JSONObject();
        jsonObject.accumulate("tech_id", PrefHelper.getInstance().getTechID());
        jsonObject.accumulate("date", entry.date);
        jsonObject.accumulate("server_id", entry.serverId);
        DataTruck truck = entry.getTruck();
        if (truck.truckNumber > 0) {
            jsonObject.accumulate("truck_number", truck.truckNumber);
        }
        if (truck.licensePlateNumber != null) {
            jsonObject.accumulate("license_plate", truck.licensePlateNumber);
        }
        DataProject project = entry.getProject();
        if (project == null) {
            Timber.e("No project name for entry -- abort");
            return false;
        }
        if (project.serverId > 0) {
            jsonObject.accumulate("project_id", project.serverId);
        } else {
            jsonObject.accumulate("project_name", project.name);
        }
        DataAddress address = entry.getAddress();
        if (address == null) {
            Timber.e("No address for entry -- abort");
            return false;
        }
        if (address.serverId > 0) {
            jsonObject.accumulate("address_id", address.serverId);
        } else {
            jsonObject.accumulate("address", address.getLine());
        }
        if (entry.status != null && entry.status != TruckStatus.UNKNOWN) {
            jsonObject.accumulate("status", entry.status.toString());
        }
        List<DataEquipment> equipments = entry.getEquipment();
        if (equipments.size() > 0) {
            JSONArray jarray = new JSONArray();
            for (DataEquipment equipment : equipments) {
                JSONObject jobj = new JSONObject();
                if (equipment.serverId > 0) {
                    jobj.accumulate("equipment_id", equipment.serverId);
                } else {
                    jobj.accumulate("equipment_name", equipment.name);
                }
                jarray.put(jobj);
            }
            jsonObject.put("equipment", jarray);
        }
        List<DataPicture> pictures = entry.getPictures();
        if (pictures.size() > 0) {
            JSONArray jarray = new JSONArray();
            for (DataPicture picture : pictures) {
                JSONObject jobj = new JSONObject();
                jobj.put("filename", picture.getTailname());
                if (!TextUtils.isEmpty(picture.note)) {
                    jobj.put("note", picture.note);
                }
                jarray.put(jobj);
            }
            jsonObject.put("picture", jarray);
        }
        List<DataNote> notes = entry.getNotesWithValuesOnly();
        if (notes.size() > 0) {
            JSONArray jarray = new JSONArray();
            for (DataNote note : notes) {
                JSONObject jobj = new JSONObject();
                if (note.serverId > 0) {
                    jobj.put("id", note.serverId);
                } else {
                    jobj.put("name", note.name);
                }
                jobj.put("value", note.value);
                jarray.put(jobj);
            }
            jsonObject.put("notes", jarray);
        }
        Timber.i("SENDING " + jsonObject.toString());
        String result = post(ENTER, jsonObject);
        if (TextUtils.isDigitsOnly(result)) {
            entry.uploadedMaster = true;
            entry.serverId = Integer.parseInt(result);
            TableEntry.getInstance().save(entry);
            success = true;
            Timber.i("SUCCESS, ENTRY SERVER ID is " + entry.serverId);
        } else {
            Timber.e("While trying to send entry " + entry.id + ": " + result);
        }
    } catch (Exception ex) {
        Timber.e(ex);
        return false;
    }
    return success;
}

From source file:com.dish.browser.activity.BrowserActivity.java

/**
 * searches the web for the query fixing any and all problems with the input
 * checks if it is a search, url, etc./*from w  w w .  j  a v  a 2 s.co m*/
 */
void searchTheWeb(String query) {
    if (query.equals("")) {
        return;
    }
    String SEARCH = mSearchText;
    query = query.trim();
    mCurrentView.stopLoading();

    if (query.startsWith("www.")) {
        query = Constants.HTTP + query;
    } else if (query.startsWith("ftp.")) {
        query = "ftp://" + query;
    }

    boolean containsPeriod = query.contains(".");
    boolean isIPAddress = (TextUtils.isDigitsOnly(query.replace(".", ""))
            && (query.replace(".", "").length() >= 4) && query.contains("."));
    boolean aboutScheme = query.contains("about:");
    boolean validURL = (query.startsWith("ftp://") || query.startsWith(Constants.HTTP)
            || query.startsWith(Constants.FILE) || query.startsWith(Constants.HTTPS)) || isIPAddress;
    boolean isSearch = ((query.contains(" ") || !containsPeriod) && !aboutScheme);

    if (isIPAddress && (!query.startsWith(Constants.HTTP) || !query.startsWith(Constants.HTTPS))) {
        query = Constants.HTTP + query;
    }

    if (isSearch) {
        try {
            query = URLEncoder.encode(query, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        mCurrentView.loadUrl(SEARCH + query);
    } else if (!validURL) {
        mCurrentView.loadUrl(Constants.HTTP + query);
    } else {
        mCurrentView.loadUrl(query);
    }
}

From source file:com.roiland.crm.sm.ui.view.ScOppoInfoFragment.java

/**
 * ?// w w w  .j a  v  a2 s  .c  o m
 * @return result ?
 */
public PurchaseCarIntention getUpdatedPurchaseCar() {
    PurchaseCarIntention result = new PurchaseCarIntention();
    if (project != null && project.getPurchaseCarIntention() != null) {
        result = project.getPurchaseCarIntention();
    }
    for (BasicInfoListAdapter.Info info : carInfo) {
        if (info.key.equals(getString(R.string.brand_1)) && info.pairKey != null) {
            result.setBrand(info.value);
            result.setBrandCode(info.pairKey);
        } else if (info.key.equals(getString(R.string.model)) && info.pairKey != null) {
            result.setModel(info.value);
            result.setModelCode(info.pairKey);
        } else if (info.key.equals(getString(R.string.outsideColor)) && info.pairKey != null) {
            result.setOutsideColor(info.value);
            result.setOutsideColorCode(info.pairKey);
        } else if (info.key.equals(getString(R.string.insideColor)) && info.pairKey != null) {
            result.setInsideColorCode(info.pairKey);
            result.setInsideColor(info.value);
        } else if (info.key.equals(getString(R.string.insideColorCheck))) {
            result.setInsideColorCheck(Boolean.parseBoolean(info.value));
        } else if (info.key.equals(getString(R.string.carConfiguration)) && info.pairKey != null) {
            result.setCarConfigurationCode(info.pairKey);
            result.setCarConfiguration(info.value);
        } else if (info.key.equals(getString(R.string.salesQuote))) {
            result.setSalesQuote((info.value));
        } else if (info.key.equals(getString(R.string.dealPriceInterval)) && info.pairKey != null) {
            result.setDealPriceInterval(info.value);
            result.setDealPriceIntervalCode(info.pairKey);
        } else if (info.key.equals(getString(R.string.payment)) && info.pairKey != null) {
            result.setPayment(info.value);
            result.setPaymentCode(info.pairKey);
        } else if (info.key.equals(getString(R.string.preorderCount))) {
            result.setPreorderCount(info.value);
        } else if (info.key.equals(getString(R.string.preorderDate))
                || info.key.equals(getString(R.string.finish_preorderDate))) {
            if (!StringUtils.isEmpty(info.value)) {
                if (TextUtils.isDigitsOnly(info.value)) {
                    result.setPreorderDate(StringUtils.getDateTrimNullLong(info.value));
                } else {
                    result.setPreorderDate(DateFormatUtils.parseDateToLong(info.value));
                }
            }
        } else if (info.key.equals(getString(R.string.flowStatus)) && info.pairKey != null) {
            result.setFlowStatus(info.value);
            result.setFlowStatusCode(info.pairKey);
        } else if (info.key.equals(getString(R.string.dealPossibility))) {
            result.setDealPossibility(info.value);
        } else if (info.key.equals(getString(R.string.purchMotivation)) && info.pairKey != null) {
            result.setPurchMotivation(info.value);
            result.setPurchMotivationCode(info.pairKey);
        } else if (info.key.equals(getString(R.string.chassisNo))) {
            result.setChassisNo(info.value);
        } else if (info.key.equals(getString(R.string.engineNo))) {
            result.setEngineNo(info.value);
        } else if (info.key.equals(getString(R.string.licensePlate))) {
            result.setLicensePlate(info.value);
        } else if (info.key.equals(getString(R.string.licenseProp)) && info.pairKey != null) {
            result.setLicenseProp(info.value);
            result.setLicensePropCode(info.pairKey);
        } else if (info.key.equals(getString(R.string.pickupDate)))
            result.setPickupDate(info.value);
        else if (info.key.equals(getString(R.string.preorderTag)))
            result.setPreorderTag(info.value);
        else if (info.key.equals(getString(R.string.giveupTag))) {
            result.setGiveupTag(("true").equals(info.value));
        } else if (info.key.equals(getString(R.string.giveupReason)) && info.pairKey != null) {
            result.setGiveupReasonCode(info.pairKey);
            result.setGiveupReason(info.value);
        } else if (info.key.equals(getString(R.string.invoiceTitle)))
            result.setInvoiceTitle(info.value);
        else if (info.key.equals(getString(R.string.comment))) {
            result.setProjectComment(info.value);
        }
    }

    return result;
}

From source file:com.miz.functions.MizLib.java

public static boolean isNumber(String runtime) {
    return TextUtils.isDigitsOnly(runtime);
}