/** * Return an uppercase version of the input or null if user gave no input. If user gave no input * and @a showToast is true a toast is displayed to this effect. */ public static String uppercaseInput(Context context, String input, boolean showToast) { if (input.isEmpty()) { if (showToast) Utils.showToast(context, "no input provided"); return null; } else // Convert the input entered by the user so it's in // uppercase. return input.toUpperCase(Locale.ENGLISH); }
/** * Initiate the synchronous acronym lookup when the user presses the "Lookup Acronym Sync" button. */ public void expandAcronymSync(View v) { // Try to get an acronym entered by the user. final String acronym = Utils.uppercaseInput(this, mEditText.getText().toString().trim(), true); if (acronym != null) { Log.d(TAG, "calling expandAcronymSync() for " + acronym); // Synchronously expand the acronym. if (getOps().expandAcronymSync(acronym) == false) // Show error message to user. Utils.showToast(this, "Call already in progress"); // Return focus to edit box and select all text in it // after query. mEditText.requestFocus(); mEditText.selectAll(); } }
/** * Start a new Activity that displays the Acronym Expansions to the user. * * @param results List of AcronymExpansions to display. */ @Override public void displayResults(List<AcronymExpansion> results, String errorMessage) { if (results == null) Utils.showToast(this, errorMessage); else { Log.d(TAG, "displayResults() with number of acronyms = " + results.size()); // Create an intent that will start an Activity to display // the Acronym Expansions to the user. final Intent intent = DisplayAcronymActivity.makeIntent(results); // Verify that the intent will resolve to an Activity. if (intent.resolveActivity(getPackageManager()) != null) // Start the DisplayAcronymExpansionsActivity with // this implicit intent. startActivity(intent); else // Show error message to user. Utils.showToast(this, "No Activity found to display Acronym Expansions"); } }
/** Initialize the Google account. */ private void initializeAccount() { // Get Account information. Must have a Google account // configured on the device. mAccountList = AccountManager.get(mActivity.get().getApplicationContext()).getAccountsByType("com.google"); if (mAccountList == null) Utils.showToast(mActivity.get(), "google account not configured"); else { try { mAccountType = mAccountList[0].type; mAccountName = mAccountList[0].name; } catch (Exception e) { Log.d(TAG, "google account not configured" + e); } } }