Beispiel #1
0
 public static CityObj[] loadCitiesDataBase(Context c) {
   final Collator collator = Collator.getInstance();
   Resources r = c.getResources();
   // Read strings array of name,timezone, id
   // make sure the list are the same length
   String[] cities = r.getStringArray(R.array.cities_names);
   String[] timezones = r.getStringArray(R.array.cities_tz);
   String[] ids = r.getStringArray(R.array.cities_id);
   if (cities.length != timezones.length || ids.length != cities.length) {
     Log.wtf("City lists sizes are not the same, cannot use the data");
     return null;
   }
   CityObj[] tempList = new CityObj[cities.length];
   for (int i = 0; i < cities.length; i++) {
     tempList[i] = new CityObj(cities[i], timezones[i], ids[i]);
   }
   // Sort alphabetically
   Arrays.sort(
       tempList,
       new Comparator<CityObj>() {
         @Override
         public int compare(CityObj c1, CityObj c2) {
           Comparator<CityObj> mCollator;
           return collator.compare(c1.mCityName, c2.mCityName);
         }
       });
   return tempList;
 }
Beispiel #2
0
  /**
   * Adds two query parameters into the Uri, namely the language code and the version code of the
   * app's package as gotten via the context.
   *
   * @return the uri with added query parameters
   */
  private static Uri uriWithAddedParameters(Context context, Uri baseUri) {
    Uri.Builder builder = baseUri.buildUpon();

    // Add in the preferred language
    builder.appendQueryParameter(PARAM_LANGUAGE_CODE, Locale.getDefault().toString());

    // Add in the package version code
    if (sCachedVersionCode == null) {
      // There is no cached version code, so try to get it from the package manager.
      try {
        // cache the version code
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        sCachedVersionCode = Integer.toString(info.versionCode);

        // append the version code to the uri
        builder.appendQueryParameter(PARAM_VERSION, sCachedVersionCode);
      } catch (NameNotFoundException e) {
        // Cannot find the package name, so don't add in the version parameter
        // This shouldn't happen.
        Log.wtf("Invalid package name for context " + e);
      }
    } else {
      builder.appendQueryParameter(PARAM_VERSION, sCachedVersionCode);
    }

    // Build the full uri and return it
    return builder.build();
  }
Beispiel #3
0
 /** Setup to find out when the quarter-hour changes (e.g. Kathmandu is GMT+5:45) * */
 private static long getAlarmOnQuarterHour() {
   Calendar nextQuarter = Calendar.getInstance();
   //  Set 1 second to ensure quarter-hour threshold passed.
   nextQuarter.set(Calendar.SECOND, 1);
   int minute = nextQuarter.get(Calendar.MINUTE);
   nextQuarter.add(Calendar.MINUTE, 15 - (minute % 15));
   long alarmOnQuarterHour = nextQuarter.getTimeInMillis();
   if (0 >= (alarmOnQuarterHour - System.currentTimeMillis())
       || (alarmOnQuarterHour - System.currentTimeMillis()) > 901000) {
     Log.wtf("quarterly alarm calculation error");
   }
   return alarmOnQuarterHour;
 }
  private void conference(String callId1, String callId2) {
    Log.d(this, "conference %s, %s", callId1, callId2);

    // Attempt to get second connection or conference.
    Connection connection2 = findConnectionForAction(callId2, "conference");
    Conference conference2 = getNullConference();
    if (connection2 == getNullConnection()) {
      conference2 = findConferenceForAction(callId2, "conference");
      if (conference2 == getNullConference()) {
        Log.w(this, "Connection2 or Conference2 missing in conference request %s.", callId2);
        return;
      }
    }

    // Attempt to get first connection or conference and perform merge.
    Connection connection1 = findConnectionForAction(callId1, "conference");
    if (connection1 == getNullConnection()) {
      Conference conference1 = findConferenceForAction(callId1, "addConnection");
      if (conference1 == getNullConference()) {
        Log.w(this, "Connection1 or Conference1 missing in conference request %s.", callId1);
      } else {
        // Call 1 is a conference.
        if (connection2 != getNullConnection()) {
          // Call 2 is a connection so merge via call 1 (conference).
          conference1.onMerge(connection2);
        } else {
          // Call 2 is ALSO a conference; this should never happen.
          Log.wtf(
              this,
              "There can only be one conference and an attempt was made to "
                  + "merge two conferences.");
          return;
        }
      }
    } else {
      // Call 1 is a connection.
      if (conference2 != getNullConference()) {
        // Call 2 is a conference, so merge via call 2.
        conference2.onMerge(connection1);
      } else {
        // Call 2 is a connection, so merge together.
        onConference(connection1, connection2);
      }
    }
  }
  /** Gets the call state label based on the state of the call and cause of disconnect */
  private String getCallStateLabelFromState(int state, Call.DisconnectCause cause) {
    final Context context = getView().getContext();
    String callStateLabel = null; // Label to display as part of the call banner

    if (Call.State.IDLE == state) {
      // "Call state" is meaningless in this state.

    } else if (Call.State.ACTIVE == state) {
      // We normally don't show a "call state label" at all in
      // this state (but see below for some special cases).

    } else if (Call.State.ONHOLD == state) {
      callStateLabel = context.getString(R.string.card_title_on_hold);
    } else if (Call.State.DIALING == state) {
      callStateLabel = context.getString(R.string.card_title_dialing);
    } else if (Call.State.REDIALING == state) {
      callStateLabel = context.getString(R.string.card_title_redialing);
    } else if (Call.State.INCOMING == state || Call.State.CALL_WAITING == state) {
      callStateLabel = context.getString(R.string.card_title_incoming_call);

    } else if (Call.State.DISCONNECTING == state) {
      // While in the DISCONNECTING state we display a "Hanging up"
      // message in order to make the UI feel more responsive.  (In
      // GSM it's normal to see a delay of a couple of seconds while
      // negotiating the disconnect with the network, so the "Hanging
      // up" state at least lets the user know that we're doing
      // something.  This state is currently not used with CDMA.)
      callStateLabel = context.getString(R.string.card_title_hanging_up);

    } else if (Call.State.DISCONNECTED == state) {
      callStateLabel = getCallFailedString(cause);

    } else {
      Log.wtf(this, "updateCallStateWidgets: unexpected call: " + state);
    }

    return callStateLabel;
  }
  /**
   * Called when the UI begins or ends. Starts the callstate callbacks if the UI just began.
   * Attempts to tear down everything if the UI just ended. See #tearDown for more insight on the
   * tear-down process.
   */
  public void setActivity(InCallActivity inCallActivity) {
    boolean updateListeners = false;
    boolean doAttemptCleanup = false;

    if (inCallActivity != null) {
      if (mInCallActivity == null) {
        updateListeners = true;
        Log.i(this, "UI Initialized");
      } else if (mInCallActivity != inCallActivity) {
        Log.wtf(this, "Setting a second activity before destroying the first.");
      } else {
        // since setActivity is called onStart(), it can be called multiple times.
        // This is fine and ignorable, but we do not want to update the world every time
        // this happens (like going to/from background) so we do not set updateListeners.
      }

      mInCallActivity = inCallActivity;

      // By the time the UI finally comes up, the call may already be disconnected.
      // If that's the case, we may need to show an error dialog.
      if (mCallList != null && mCallList.getDisconnectedCall() != null) {
        maybeShowErrorDialogOnDisconnect(mCallList.getDisconnectedCall());
      }

      // When the UI comes up, we need to first check the in-call state.
      // If we are showing NO_CALLS, that means that a call probably connected and
      // then immediately disconnected before the UI was able to come up.
      // If we dont have any calls, start tearing down the UI instead.
      // NOTE: This code relies on {@link #mInCallActivity} being set so we run it after
      // it has been set.
      if (mInCallState == InCallState.NO_CALLS) {
        Log.i(this, "UI Intialized, but no calls left.  shut down.");
        attemptFinishActivity();
        return;
      }
    } else {
      Log.i(this, "UI Destroyed)");
      updateListeners = true;
      mInCallActivity = null;

      // We attempt cleanup for the destroy case but only after we recalculate the state
      // to see if we need to come back up or stay shut down. This is why we do the cleanup
      // after the call to onCallListChange() instead of directly here.
      doAttemptCleanup = true;
    }

    // Messages can come from the telephony layer while the activity is coming up
    // and while the activity is going down.  So in both cases we need to recalculate what
    // state we should be in after they complete.
    // Examples: (1) A new incoming call could come in and then get disconnected before
    //               the activity is created.
    //           (2) All calls could disconnect and then get a new incoming call before the
    //               activity is destroyed.
    //
    // b/1122139 - We previously had a check for mServiceConnected here as well, but there are
    // cases where we need to recalculate the current state even if the service in not
    // connected.  In particular the case where startOrFinish() is called while the app is
    // already finish()ing. In that case, we skip updating the state with the knowledge that
    // we will check again once the activity has finished. That means we have to recalculate the
    // state here even if the service is disconnected since we may not have finished a state
    // transition while finish()ing.
    if (updateListeners) {
      onCallListChange(mCallList);
    }

    if (doAttemptCleanup) {
      attemptCleanup();
    }
  }