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:Main.java

public static void registerNewSourceSinkConnection(int counter, Bundle bundle) {
    Log.i("PEP", "in registerNewSourceSinkConnection(int counter, Bundle bundle)" + counter + " "
            + bundle.toString());//from   www . j  av a  2  s .c om
    int taintInfoKeyCounter = 0;

    if (bundle != null) {
        for (String intentKey : bundle.keySet()) {
            if (intentKey.startsWith(keyBaseName)) {
                String possibleNumber = intentKey.substring(keyBaseName.length());
                if (possibleNumber.length() > 0 && TextUtils.isDigitsOnly(possibleNumber)) {
                    int currentCounter = Integer.parseInt(possibleNumber);
                    if (taintInfoKeyCounter < currentCounter)
                        taintInfoKeyCounter = currentCounter;
                }
            }
        }

        if (taintInfoKeyCounter == 0) {
            Log.i("PEP", "bundle:" + bundle.toString());
            if (bundle.containsKey(keyBaseName)) {
                String taintSourceCats = bundle.getString(keyBaseName);
                String[] allCats = taintSourceCats.split(",");
                sourceSinkConnection.put(counter, new HashSet<String>(Arrays.asList(allCats)));
            }
        } else {
            if (bundle.containsKey(keyBaseName + taintInfoKeyCounter)) {
                String taintSourceCats = bundle.getString(keyBaseName + taintInfoKeyCounter);
                String[] allCats = taintSourceCats.split(",");
                sourceSinkConnection.put(counter, new HashSet<String>(Arrays.asList(allCats)));
            }
        }
    }
}

From source file:info.papdt.blacklight.api.statuses.QueryIdApi.java

public static String queryId(String mid, int type) {
    WeiboParameters params = new WeiboParameters();
    params.put("mid", mid);
    params.put("type", type);
    params.put("isBase62", TextUtils.isDigitsOnly(mid) ? 0 : 1);

    try {//from  ww  w . j  ava 2s .co  m
        JSONObject json = request(Constants.QUERY_ID, params, HTTP_GET);
        return json.optString("id", null);
    } catch (Exception e) {
    }
    return null;
}

From source file:Main.java

/**
 *
 * @param baseURL/*from   ww w.  ja va2  s . c o m*/
 * @param key
 * @return the soundcloud track id
 */
public static String parseSoundCloud(String baseURL) {

    Uri parsed = Uri.parse(baseURL);
    String authority = parsed.getAuthority();
    String trackURL = null;
    if (TextUtils.isEmpty(authority)) {
        return null;
    }
    if (authority.indexOf("api.soundcloud") >= 0) {
        trackURL = baseURL;
    } else if (authority.indexOf("soundcloud") >= 0) {
        Uri parsedURI = Uri.parse(baseURL);
        try {
            trackURL = parsedURI.getQueryParameter("url");
        } catch (Exception exc) {

        }
    }

    if (TextUtils.isEmpty(trackURL) == true) {
        return null;
    }

    Uri base = Uri.parse(trackURL);

    List<String> segments = base.getPathSegments();
    for (String segment : segments) {
        if (TextUtils.isDigitsOnly(segment) == true) {
            return segment;// String.format("https://api.soundcloud.com/tracks/%1$s/stream?consumer_key=%2$s",segment,key);
        }
    }

    return "";
}

From source file:info.papdt.blacklight.api.statuses.QueryIdApi.java

public static MessageModel fetchStatus(String mid) {
    String id = mid;//from w w  w. ja  va  2  s. c o m
    if (!TextUtils.isDigitsOnly(mid)) {
        id = queryId(mid);
    }
    if (TextUtils.isEmpty(id)) {
        return null;
    }

    WeiboParameters params = new WeiboParameters();
    params.put("id", id);

    try {
        JSONObject json = request(Constants.SHOW, params, HTTP_GET);
        return new Gson().fromJson(json.toString(), MessageModel.class);
    } catch (Exception e) {
    }
    return null;
}

From source file:com.activiti.android.ui.fragments.task.filter.TaskAssignmentDialogFragment.java

public static String getAssignmentTitle(Context context, String assignment, long accountId) {
    String value = context.getString(R.string.task_filter_assignment_involved);
    try {//from  w ww.  j a va 2s  .  c om
        // Do nothing
        if (assignment != null && assignment.startsWith(PREFIX_GROUP)) {
            String groupId = assignment.replace(PREFIX_GROUP, "");
            if (TextUtils.isDigitsOnly(groupId)) {
                GroupInstance group = GroupInstanceManager.getInstance(context).getById(Long.parseLong(groupId),
                        accountId);
                return String.format(context.getString(R.string.task_filter_assignment_group), group.getName());
            }
        }

        switch (TaskAssignment.fromValue(assignment)) {
        case INVOLVED:
            value = context.getString(R.string.task_filter_assignment_involved);
            break;
        case ASSIGNEE:
            value = context.getString(R.string.task_filter_assignment_assignee);
            break;
        case CANDIDATE:
            value = context.getString(R.string.task_filter_assignment_candidate);
            break;
        }
    } catch (Exception e) {
        // Do Nothing
    }
    return value;
}

From source file:com.example.nitish.welcomapp.activitypt.ElementDetailsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    final boolean darkTheme = PreferenceUtils.getPrefDarkTheme();
    setTheme(darkTheme ? R.style.DarkTheme : R.style.LightTheme);

    super.onCreate(savedInstanceState);

    ActionBarCompat.setDisplayHomeAsUpEnabled(this, true);

    if (savedInstanceState == null) {
        final Intent intent = getIntent();
        Fragment fragment = null;/* w ww  .  jav a2s  .  c o m*/
        if (intent.hasExtra(EXTRA_ATOMIC_NUMBER)) {
            fragment = ElementDetailsFragment.getInstance(intent.getIntExtra(EXTRA_ATOMIC_NUMBER, 0));
        } else if (getIntent().getData() != null) {
            final Uri uri = getIntent().getData();
            if (uri.getHost().equals("element")) {
                final String path = uri.getPathSegments().get(0);
                if (TextUtils.isDigitsOnly(path)) {
                    try {
                        fragment = ElementDetailsFragment
                                .getInstance(Integer.parseInt(uri.getPathSegments().get(0)));
                    } catch (NumberFormatException e) {
                        Log.w(TAG, "Invalid atomic number");
                    }
                } else {
                    fragment = ElementDetailsFragment.getInstance(path);
                }
            }
        }
        if (fragment != null) {
            getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();
        }
    }
}

From source file:com.deliciousdroid.fragment.MainSearchResultsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    base = (FragmentBaseActivity) getActivity();
    base.setTitle(R.string.main_search_results_title);

    String[] MENU_ITEMS = new String[] { getString(R.string.search_results_bookmark),
            getString(R.string.search_results_tag), getString(R.string.search_results_global_tag) };

    setListAdapter(new ArrayAdapter<String>(base, R.layout.main_view, MENU_ITEMS));

    final Intent intent = base.getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (intent.hasExtra(SearchManager.QUERY)) {
            Intent i = new Intent(base, MainSearchResultsFragment.class);
            i.putExtras(intent.getExtras());
            startActivity(i);//from   w  ww  .  j a v a  2  s .com
            base.finish();
        } else {
            base.onSearchRequested();
        }
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        Uri data = intent.getData();
        String path = null;
        String tagname = null;

        if (data != null) {
            path = data.getPath();
            tagname = data.getQueryParameter("tagname");
        }

        if (data.getScheme() == null || !data.getScheme().equals("content")) {
            Intent i = new Intent(Intent.ACTION_VIEW, data);

            startActivity(i);
            base.finish();
        } else if (path.contains("bookmarks") && TextUtils.isDigitsOnly(data.getLastPathSegment())) {
            Intent viewBookmark = new Intent(base, ViewBookmark.class);
            viewBookmark.setData(data);

            Log.d("View Bookmark Uri", data.toString());
            startActivity(viewBookmark);
            base.finish();
        } else if (tagname != null) {
            Intent viewTags = new Intent(base, BrowseBookmarks.class);
            viewTags.setData(data);

            Log.d("View Tags Uri", data.toString());
            startActivity(viewTags);
            base.finish();
        }
    }

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                searchActionListener.onBookmarkSearch();
            } else if (position == 1) {
                searchActionListener.onTagSearch();
            } else if (position == 2) {
                searchActionListener.onGlobalTagSearch();
            }
        }
    });
}

From source file:org.wso2.emm.agent.api.RuntimeInfo.java

public Map<String, Application> getAppMemory() throws AndroidAgentException {
    Map<String, Application> applications = new HashMap<>();
    Application appData;// w ww . j  a  v a2 s. c o m

    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for (String topCommandRow : topCommandRows) {
        if (topCommandRow != null && !topCommandRow.isEmpty() && !topCommandRow.contains(" root ")) {
            String[] columns = topCommandRow.replaceFirst("^\\s*", "").split(" ");
            String pidColumnValue = columns[0].trim();

            if (!pidColumnValue.isEmpty() && TextUtils.isDigitsOnly(pidColumnValue)) {

                appData = new Application();
                appData.setPackageName(columns[columns.length - 1]);

                int pid = Integer.parseInt(pidColumnValue);
                appData.setPid(Integer.parseInt(columns[0]));

                int totalPSS = activityManager.getProcessMemoryInfo(new int[] { pid })[0].getTotalPss();
                appData.setPss(totalPSS);

                int totalPrivateDirty = activityManager.getProcessMemoryInfo(new int[] { pid })[0]
                        .getTotalPrivateDirty();
                appData.setUss(totalPrivateDirty);

                int totalSharedDirty = activityManager.getProcessMemoryInfo(new int[] { pid })[0]
                        .getTotalSharedDirty();
                appData.setSharedDirty(totalSharedDirty);

                applications.put(appData.getPackageName(), appData);
            }
        }
    }
    return applications;
}

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

public void sendRegistration() {
    Timber.i("sendRegistration()");
    try {// w ww  .java  2 s .  com
        String deviceId = ServerHelper.getInstance().getDeviceId();
        JSONObject jsonObject = new JSONObject();
        jsonObject.accumulate("first_name", PrefHelper.getInstance().getFirstName());
        jsonObject.accumulate("last_name", PrefHelper.getInstance().getLastName());
        jsonObject.accumulate("device_id", deviceId);
        String result = post(REGISTER, jsonObject);
        if (TextUtils.isDigitsOnly(result)) {
            int tech_id = Integer.parseInt(result);
            PrefHelper.getInstance().setTechID(tech_id);
            PrefHelper.getInstance().setRegistrationChanged(false);
            Timber.i("TECH ID=" + tech_id);
        } else {
            Timber.i("sendRegistration() failed");
        }
    } catch (Exception ex) {
        Timber.e(ex);
    }
}

From source file:com.deliciousdroid.activity.FragmentBaseActivity.java

@Override
@TargetApi(14)//from ww w  . j  a v a 2  s. co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mContext = this;
    mAccountManager = AccountManager.get(this);
    settings = PreferenceManager.getDefaultSharedPreferences(this);

    loadSettings();
    init();

    if (android.os.Build.VERSION.SDK_INT >= 14) {
        getActionBar().setHomeButtonEnabled(true);
    }

    Intent intent = getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction()) && !intent.hasExtra("MainSearchResults")) {
        if (intent.hasExtra(SearchManager.QUERY)) {
            Intent i = new Intent(this, MainSearchResults.class);
            i.putExtras(intent.getExtras());
            startActivity(i);
            finish();
        } else {
            onSearchRequested();
        }
    } else if (Constants.ACTION_SEARCH_SUGGESTION.equals(intent.getAction())) {
        Uri data = intent.getData();
        String path = null;
        String tagname = null;

        if (data != null) {
            path = data.getPath();
            tagname = data.getQueryParameter("tagname");
        }

        if (data.getScheme() == null || !data.getScheme().equals("content")) {
            Intent i = new Intent(Intent.ACTION_VIEW, data);
            startActivity(i);
            finish();
        } else if (path.contains("bookmarks") && TextUtils.isDigitsOnly(data.getLastPathSegment())
                && intent.hasExtra(SearchManager.USER_QUERY)) {
            Intent viewBookmark = new Intent(this, ViewBookmark.class);
            viewBookmark.setAction(Intent.ACTION_VIEW);
            viewBookmark.setData(data);
            viewBookmark.removeExtra(SearchManager.USER_QUERY);
            Log.d("View Bookmark Uri", data.toString());
            startActivity(viewBookmark);
            finish();
        } else if (tagname != null) {
            Intent viewTags = new Intent(this, BrowseBookmarks.class);
            viewTags.setData(data);

            Log.d("View Tags Uri", data.toString());
            startActivity(viewTags);
            finish();
        }
    }
}