public void onSensorChanged(SensorEvent event) {
          // use the event timestamp as reference
          // so the manager precision won't depends
          // on the AccelerometerListener implementation
          // processing time
          now = event.timestamp;

          x = event.values[0];
          y = event.values[1];
          z = event.values[2];

          // if not interesting in shake events
          // just remove the whole if then else block
          if (lastUpdate == 0) {
            lastUpdate = now;
            lastShake = now;
            lastX = x;
            lastY = y;
            lastZ = z;
            Toast.makeText(aContext, "No Motion detected", Toast.LENGTH_SHORT).show();

          } else {
            timeDiff = now - lastUpdate;

            if (timeDiff > 0) {

              /*force = Math.abs(x + y + z - lastX - lastY - lastZ)
              / timeDiff;*/
              force = Math.abs(x + y + z - lastX - lastY - lastZ);

              if (Float.compare(force, threshold) > 0) {
                // Toast.makeText(Accelerometer.getContext(),
                // (now-lastShake)+"  >= "+interval, 1000).show();

                if (now - lastShake >= interval) {

                  // trigger shake event
                  listener.onShake(force);
                } else {
                  Toast.makeText(aContext, "No Motion detected", Toast.LENGTH_SHORT).show();
                }
                lastShake = now;
              }
              lastX = x;
              lastY = y;
              lastZ = z;
              lastUpdate = now;
            } else {
              Toast.makeText(aContext, "No Motion detected", Toast.LENGTH_SHORT).show();
            }
          }
          // trigger change event
          listener.onAccelerationChanged(x, y, z);
        }
  /**
   * Called when there is a change to the call list. Sets the In-Call state for the entire in-call
   * app based on the information it gets from CallList. Dispatches the in-call state to all
   * listeners. Can trigger the creation or destruction of the UI based on the states that is
   * calculates.
   */
  @Override
  public void onCallListChange(CallList callList) {
    if (callList == null) {
      return;
    }
    InCallState newState = getPotentialStateFromCallList(callList);
    newState = startOrFinishUi(newState);

    // Renable notification shade and soft navigation buttons, if we are no longer in the
    // incoming call screen
    if (!newState.isIncoming()) {
      if (mAccelerometerListener != null) {
        mAccelerometerListener.enableSensor(false);
      }
      CallCommandClient.getInstance().setSystemBarNavigationEnabled(true);
    }

    // Set the new state before announcing it to the world
    Log.i(this, "Phone switching state: " + mInCallState + " -> " + newState);
    mInCallState = newState;

    // notify listeners of new state
    for (InCallStateListener listener : mListeners) {
      Log.d(this, "Notify " + listener + " of state " + mInCallState.toString());
      listener.onStateChange(mInCallState, callList);
    }

    if (isActivityStarted()) {
      final boolean hasCall =
          callList.getActiveOrBackgroundCall() != null || callList.getOutgoingCall() != null;
      mInCallActivity.dismissKeyguard(hasCall);
    }
  }
Пример #3
0
        public void onSensorChanged(SensorEvent event) {

          now = event.timestamp;

          if (now - lastUpdate > pauze_ns) {
            x = event.values[0];
            y = event.values[1];
            z = event.values[2];

            // trigger change event
            listener.onAccelerationChanged(x, y, z);
            lastUpdate = now;
          }
        }
  /**
   * Called when there is a new incoming call.
   *
   * @param call
   */
  @Override
  public void onIncomingCall(Call call) {
    InCallState newState = startOrFinishUi(InCallState.INCOMING);

    Log.i(this, "Phone switching state: " + mInCallState + " -> " + newState);
    mInCallState = newState;

    // Disable notification shade and soft navigation buttons
    if (newState.isIncoming()) {
      CallCommandClient.getInstance().setSystemBarNavigationEnabled(false);
      if (mAccelerometerListener != null) {
        mAccelerometerListener.enableSensor(true);
      }
    }

    for (IncomingCallListener listener : mIncomingCallListeners) {
      listener.onIncomingCall(mInCallState, call);
    }
  }
  /**
   * Handles the green CALL key while in-call.
   *
   * @return true if we consumed the event.
   */
  public boolean handleCallKey() {
    Log.v(this, "handleCallKey");

    // The green CALL button means either "Answer", "Unhold", or
    // "Swap calls", or can be a no-op, depending on the current state
    // of the Phone.

    /** INCOMING CALL */
    final CallList calls = CallList.getInstance();
    final Call incomingCall = calls.getIncomingCall();
    Log.v(this, "incomingCall: " + incomingCall);

    // (1) Attempt to answer a call
    if (incomingCall != null) {
      CallCommandClient.getInstance().answerCall(incomingCall.getCallId());
      if (mAccelerometerListener != null) {
        mAccelerometerListener.enableSensor(false);
      }
      return true;
    }

    /** ACTIVE CALL */
    final Call activeCall = calls.getActiveCall();
    if (activeCall != null) {
      // TODO: This logic is repeated from CallButtonPresenter.java. We should
      // consolidate this logic.
      final boolean isGeneric = activeCall.can(Capabilities.GENERIC_CONFERENCE);
      final boolean canMerge = activeCall.can(Capabilities.MERGE_CALLS);
      final boolean canSwap = activeCall.can(Capabilities.SWAP_CALLS);

      Log.v(
          this,
          "activeCall: "
              + activeCall
              + ", isGeneric: "
              + isGeneric
              + ", canMerge: "
              + canMerge
              + ", canSwap: "
              + canSwap);

      // (2) Attempt actions on Generic conference calls
      if (activeCall.isConferenceCall() && isGeneric) {
        if (canMerge) {
          CallCommandClient.getInstance().merge();
          return true;
        } else if (canSwap) {
          CallCommandClient.getInstance().swap();
          return true;
        }
      }

      // (3) Swap calls
      if (canSwap) {
        CallCommandClient.getInstance().swap();
        return true;
      }
    }

    /** BACKGROUND CALL */
    final Call heldCall = calls.getBackgroundCall();
    if (heldCall != null) {
      // We have a hold call so presumeable it will always support HOLD...but
      // there is no harm in double checking.
      final boolean canHold = heldCall.can(Capabilities.HOLD);

      Log.v(this, "heldCall: " + heldCall + ", canHold: " + canHold);

      // (4) unhold call
      if (heldCall.getState() == Call.State.ONHOLD && canHold) {
        CallCommandClient.getInstance().hold(heldCall.getCallId(), false);
        return true;
      }
    }

    // Always consume hard keys
    return true;
  }