Ejemplo n.º 1
0
  @Start
  public void start() {
    layout = new LinearLayout(UIServiceHandler.getUIService().getRootActivity());
    btnEnvoie = new Button(UIServiceHandler.getUIService().getRootActivity());
    numero = new EditText(UIServiceHandler.getUIService().getRootActivity());
    numero.setWidth(100);
    message.setWidth(200);
    message.setHeight(500);
    message = new EditText(UIServiceHandler.getUIService().getRootActivity());

    layout.addView(numero);
    layout.addView(message);
    layout.addView(btnEnvoie);

    btnEnvoie.setOnClickListener(
        new OnClickListener() {

          @SuppressWarnings("deprecation")
          public void onClick(View v) {
            // On récupère ce qui a été entré dans les EditText
            String num = numero.getText().toString();
            String msg = message.getText().toString();
            // Si le numéro est supérieur à 4 charactère et que le message n'est pas vide on lance
            // la procédure d'envoi
            if (num.length() >= 4 && msg.length() > 0) {

              SmsManager.getDefault().sendTextMessage(num, null, msg, null, null);
              SMS t = new SMS();
              t.setNumber(num);
              t.setMsg(msg);

              getPortByName("message", MessagePort.class).process(t);
            } else {
              // On affiche un petit message d'erreur dans un Toast
              Toast.makeText(
                      UIServiceHandler.getUIService().getRootActivity(),
                      "Enter le numero et/ou le message",
                      Toast.LENGTH_SHORT)
                  .show();
            }
          }
        });
    UIServiceHandler.getUIService().addToGroup("Sms", layout);
  }
  @Start
  public void start() {

    mLimit = Float.parseFloat(getDictionary().get("sensitivity").toString());
    int h = 480; // TODO: remove this constant
    mYOffset = h * 0.5f;
    mScale[0] = -(h * 0.5f * (1.0f / (SensorManager.STANDARD_GRAVITY * 2)));
    mScale[1] = -(h * 0.5f * (1.0f / (SensorManager.MAGNETIC_FIELD_EARTH_MAX)));
    mSensorManager =
        (SensorManager)
            UIServiceHandler.getUIService()
                .getRootActivity()
                .getSystemService(Context.SENSOR_SERVICE);
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

    mSensorListener =
        new SensorEventListener() {
          public void onSensorChanged(SensorEvent se) {
            Sensor sensor = se.sensor;
            synchronized (this) {
              float x = se.values[0];
              float y = se.values[1];
              float z = se.values[2];
              Motion motion = new Motion();
              motion.setX(x);
              motion.setY(y);
              motion.setZ(z);

              getPortByName("motion", MessagePort.class).process(motion);

              if (sensor.getType() == Sensor.TYPE_ORIENTATION) {
              } else {
                int j = (sensor.getType() == Sensor.TYPE_ACCELEROMETER) ? 1 : 0;
                if (j == 1) {
                  float vSum = 0;
                  for (int i = 0; i < 3; i++) {
                    final float v = mYOffset + se.values[i] * mScale[j];
                    vSum += v;
                  }
                  int k = 0;
                  float v = vSum / 3;

                  float direction = (v > mLastValues[k] ? 1 : (v < mLastValues[k] ? -1 : 0));
                  if (direction == -mLastDirections[k]) {
                    // Direction changed
                    int extType = (direction > 0 ? 0 : 1); // minumum or maximum?
                    mLastExtremes[extType][k] = mLastValues[k];
                    float diff =
                        Math.abs(mLastExtremes[extType][k] - mLastExtremes[1 - extType][k]);

                    if (diff > mLimit) {

                      boolean isAlmostAsLargeAsPrevious = diff > (mLastDiff[k] * 2 / 3);
                      boolean isPreviousLargeEnough = mLastDiff[k] > (diff / 3);
                      boolean isNotContra = (mLastMatch != 1 - extType);

                      if (isAlmostAsLargeAsPrevious && isPreviousLargeEnough && isNotContra) {
                        Log.i(TAG, "step");

                        getPortByName("step", MessagePort.class).process("step");

                        mLastMatch = extType;
                      } else {
                        mLastMatch = -1;
                      }
                    }
                    mLastDiff[k] = diff;
                  }
                  mLastDirections[k] = direction;
                  mLastValues[k] = v;
                }
              }
            }
          }

          @Override
          public void onAccuracyChanged(Sensor sensor, int i) {
            // To change body of implemented methods use File | Settings | File Templates.
          }
        };
    mSensorManager.registerListener(mSensorListener, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
  }
Ejemplo n.º 3
0
 @Stop
 public void stop() {
   if (layout != null) {
     UIServiceHandler.getUIService().remove(layout);
   }
 }