Beispiel #1
0
  /**
   * Checks if there is a call in progress. If true then shows a warning toast and finishes the
   * activity.
   *
   * @param activity activity doing a check.
   * @return <tt>true</tt> if there is call in progress and <tt>Activity</tt> was finished.
   */
  public static boolean checkCallInProgress(Activity activity) {
    if (CallManager.getActiveCallsCount() > 0) {
      logger.warn("Call is in progress");

      Toast t =
          Toast.makeText(activity, R.string.service_gui_WARN_CALL_IN_PROGRESS, Toast.LENGTH_SHORT);
      t.show();

      activity.finish();
      return true;
    } else {
      return false;
    }
  }
  /** Checks if maintained view exists and removes if from the <tt>container</tt>. */
  protected void ensureViewDestroyed() {
    if (view != null) {
      final View viewToRemove = view;
      view = null;

      activity.runOnUiThread(
          new Runnable() {
            @Override
            public void run() {
              container.removeView(viewToRemove);
              container.setVisibility(View.GONE);
            }
          });
    }
  }
  /**
   * Checks if the view is currently created. If not creates new <tt>View</tt> and adds it to the
   * <tt>container</tt>.
   */
  protected void ensureViewCreated() {
    if (view == null) {
      activity.runOnUiThread(
          new Runnable() {
            @Override
            public void run() {
              view = createViewInstance();

              ViewGroup.LayoutParams params =
                  new ViewGroup.LayoutParams(
                      ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
              container.addView(view, params);

              container.setVisibility(View.VISIBLE);
            }
          });
    }
  }