Exemplo n.º 1
0
  /**
   * Display the acronym expansions to the user.
   *
   * @param results List of acronym expansions to display.
   */
  public void displayResults(List<AcronymExpansion> results, String errorMessage) {
    Log.d(TAG, "results = " + results);
    if (results == null || results.size() == 0) Utils.showToast(this, errorMessage);
    else {
      Log.d(TAG, "displayResults() with number of acronyms = " + results.size());

      // Add the results to the Adapter and notify changes.
      mAdapter.clear();
      mAdapter.addAll(results);
      mAdapter.notifyDataSetChanged();
    }
  }
Exemplo n.º 2
0
  /** Initiate the synchronous acronym lookup when the user presses the "Look Up" button. */
  public void expandAcronym(View v) {
    // Get the acronym entered by the user and convert to so it's
    // consistent with what we get back from the Acronym web
    // service.
    final String acronym = mEditText.getText().toString().trim().toUpperCase(Locale.ENGLISH);

    if (acronym.isEmpty()) Utils.showToast(this, "no acronym provided");
    else {
      // Reset the display for the next acronym expansion.
      resetDisplay();

      // Expand the acronym.
      getOps().expandAcronym(acronym);
    }
  }
        /**
         * Implement the AIDL WeatherRequest expandWeather() method, which forwards to DownloadUtils
         * getResults() to obtain the results from the Weather Web service and then sends the
         * results back to the Activity via a callback.
         */
        @Override
        public void getCurrentWeather(String weather, vandy.mooc.aidl.WeatherResults callback)
            throws RemoteException {

          // Call the Weather Web service to get the list of
          // possible expansions of the designated weather.
          try {
            WeatherData weatherResults = Utils.getResults(weather);

            if (weatherResults != null) {
              Log.d(TAG, "Results for weather: " + weather);
              callback.sendResults(weatherResults);
            } else {
              Log.d(TAG, "No result for " + weather + " found");
              callback.sendError("No result for " + weather + " found");
            }
            // Invoke a one-way callback to send list of weather
            // expansions back to the WeatherActivity.

          } catch (IllegalArgumentException e) {
            Log.d(TAG, "Error on getting " + weather + ": " + e.getMessage());
            callback.sendError(e.getMessage());
          }
        }
Exemplo n.º 4
0
 /** Reset the display prior to attempting to expand a new acronym. */
 private void resetDisplay() {
   Utils.hideKeyboard(this, mEditText.getWindowToken());
   mAdapter.clear();
   mAdapter.notifyDataSetChanged();
 }