Beispiel #1
0
 public Bundle convertToBundle() {
   Bundle bundle = new Bundle();
   Iterator<String> it = map.keySet().iterator();
   while (it.hasNext()) {
     String key = it.next();
     Object value = map.get(key);
     if (value instanceof Boolean) {
       bundle.putBoolean(key, (Boolean) value);
     } else if (value instanceof String) {
       bundle.putString(key, (String) value);
     } else if (value instanceof Serializable) {
       bundle.putSerializable(key, (Serializable) value);
     } else if (value instanceof Integer) {
       bundle.putInt(key, (Integer) value);
     } else if (value instanceof Float) {
       bundle.putFloat(key, (Float) value);
     } else if (value instanceof Double) {
       bundle.putDouble(key, (Double) value);
     } else if (value instanceof Short) {
       bundle.putShort(key, (Short) value);
     } else if (value instanceof Long) {
       bundle.putLong(key, (Long) value);
     } else if (value instanceof Parcelable) {
       bundle.putParcelable(key, (Parcelable) value);
     }
   }
   return bundle;
 }
 /**
  * Add extended data to the extra.
  *
  * @param name The name of the extra data, with package prefix.
  * @param value The short data value.
  * @return Returns the same extra object, for chaining multiple calls into a single statement.
  * @see #putExtras
  * @see #removeExtra
  * @see #getShortExtra(String, short)
  */
 public Request putExtra(String name, short value) {
   if (mExtras == null) {
     mExtras = new Bundle();
   }
   mExtras.putShort(name, value);
   return this;
 }
 /**
  * Create command with type bootstrap.
  *
  * @param defPrefix default prefix
  * @param defSender default sender
  * @return created command
  */
 public static ConnectorCommand bootstrap(final String defPrefix, final String defSender) {
   final Bundle b = new Bundle();
   b.putShort(TYPE, TYPE_BOOTSTRAP);
   b.putString(DEFPREFIX, defPrefix);
   b.putString(DEFSENDER, defSender);
   return new ConnectorCommand(b);
 }
 /**
  * Create command with type update.
  *
  * @param defPrefix default prefix
  * @param defSender default sender
  * @return created command
  */
 public static ConnectorCommand update(final String defPrefix, final String defSender) {
   final Bundle b = new Bundle();
   b.putShort(TYPE, TYPE_UPDATE);
   b.putString(DEFPREFIX, defPrefix);
   b.putString(DEFSENDER, defSender);
   return new ConnectorCommand(b);
 }
 /**
  * Create Command with type "send".
  *
  * @param selectedSubConnector selected SubConnectorSpec
  * @param defPrefix default prefix
  * @param defSender default sender
  * @param recipients recipients
  * @param text text
  * @param flashSMS flashsms
  * @return created command
  */
 public static ConnectorCommand send(
     final String selectedSubConnector,
     final String defPrefix,
     final String defSender,
     final String[] recipients,
     final String text, // .
     final boolean flashSMS) {
   final Bundle b = new Bundle();
   b.putShort(TYPE, TYPE_SEND);
   b.putString(SELECTEDSUBCONNECTOR, selectedSubConnector);
   b.putString(DEFPREFIX, defPrefix);
   b.putString(DEFSENDER, defSender);
   final int l = recipients.length;
   ArrayList<String> r = new ArrayList<String>(l);
   String s;
   for (int i = 0; i < l; i++) {
     s = recipients[i];
     if (s != null && s.trim().length() > 0) {
       r.add(s);
     }
   }
   s = null;
   b.putStringArray(RECIPIENTS, r.toArray(new String[0]));
   b.putString(TEXT, text);
   b.putBoolean(FLASHSMS, flashSMS);
   b.putLong(TIMESTAMP, -1);
   b.putString(CUSTOMSENDER, null);
   return new ConnectorCommand(b);
 }
 public NmsContact nmsGetContactInfoViaEngineId(int engineContactId) {
   Bundle param = new Bundle();
   param.putShort(FUNC_ID_nmsGetContactInfoViaEngineId + 1, (short) engineContactId);
   try {
     Bundle back =
         mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsGetContactInfoViaEngineId, null, param);
     if (back != null) {
       return (NmsContact) back.getSerializable(FUNC_ID_nmsGetContactInfoViaEngineId);
     }
   } catch (Exception e) {
     NmsLog.nmsPrintStackTrace(e);
   }
   return null;
 }
Beispiel #7
0
  public void Storage(TransportPacket p, String i) {
    try {
      packet =
          new CommandPacket(); // !!!!!!!!!!!! Sinon on peut surement en valeur les arguments des
                               // command précédantes !
      packet.parse(p.getData());

      Message mess = new Message();
      Bundle b = new Bundle();
      b.putShort("command", packet.getCommand());
      b.putByteArray("arguments", packet.getArguments());
      b.putInt("chan", packet.getTargetChannel());
      mess.setData(b);
      handler.sendMessage(mess);
    } catch (Exception e) {
      System.out.println("Androrat.Client.storage : pas une commande");
    }
  }
 private static void putShort(String key, Bundle bundle) {
   bundle.putShort(key, (short) random.nextInt());
 }
  private void deserializeKey(String key, Bundle bundle) throws JSONException {
    String jsonString = cache.getString(key, "{}");
    JSONObject json = new JSONObject(jsonString);

    String valueType = json.getString(JSON_VALUE_TYPE);

    if (valueType.equals(TYPE_BOOLEAN)) {
      bundle.putBoolean(key, json.getBoolean(JSON_VALUE));
    } else if (valueType.equals(TYPE_BOOLEAN_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      boolean[] array = new boolean[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = jsonArray.getBoolean(i);
      }
      bundle.putBooleanArray(key, array);
    } else if (valueType.equals(TYPE_BYTE)) {
      bundle.putByte(key, (byte) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_BYTE_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      byte[] array = new byte[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = (byte) jsonArray.getInt(i);
      }
      bundle.putByteArray(key, array);
    } else if (valueType.equals(TYPE_SHORT)) {
      bundle.putShort(key, (short) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_SHORT_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      short[] array = new short[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = (short) jsonArray.getInt(i);
      }
      bundle.putShortArray(key, array);
    } else if (valueType.equals(TYPE_INTEGER)) {
      bundle.putInt(key, json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_INTEGER_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      int[] array = new int[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = jsonArray.getInt(i);
      }
      bundle.putIntArray(key, array);
    } else if (valueType.equals(TYPE_LONG)) {
      bundle.putLong(key, json.getLong(JSON_VALUE));
    } else if (valueType.equals(TYPE_LONG_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      long[] array = new long[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = jsonArray.getLong(i);
      }
      bundle.putLongArray(key, array);
    } else if (valueType.equals(TYPE_FLOAT)) {
      bundle.putFloat(key, (float) json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_FLOAT_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      float[] array = new float[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = (float) jsonArray.getDouble(i);
      }
      bundle.putFloatArray(key, array);
    } else if (valueType.equals(TYPE_DOUBLE)) {
      bundle.putDouble(key, json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_DOUBLE_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      double[] array = new double[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = jsonArray.getDouble(i);
      }
      bundle.putDoubleArray(key, array);
    } else if (valueType.equals(TYPE_CHAR)) {
      String charString = json.getString(JSON_VALUE);
      if (charString != null && charString.length() == 1) {
        bundle.putChar(key, charString.charAt(0));
      }
    } else if (valueType.equals(TYPE_CHAR_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      char[] array = new char[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        String charString = jsonArray.getString(i);
        if (charString != null && charString.length() == 1) {
          array[i] = charString.charAt(0);
        }
      }
      bundle.putCharArray(key, array);
    } else if (valueType.equals(TYPE_STRING)) {
      bundle.putString(key, json.getString(JSON_VALUE));
    } else if (valueType.equals(TYPE_STRING_LIST)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      int numStrings = jsonArray.length();
      ArrayList<String> stringList = new ArrayList<String>(numStrings);
      for (int i = 0; i < numStrings; i++) {
        Object jsonStringValue = jsonArray.get(i);
        stringList.add(i, jsonStringValue == JSONObject.NULL ? null : (String) jsonStringValue);
      }
      bundle.putStringArrayList(key, stringList);
    } else if (valueType.equals(TYPE_ENUM)) {
      try {
        String enumType = json.getString(JSON_VALUE_ENUM_TYPE);
        @SuppressWarnings({"unchecked", "rawtypes"})
        Class<? extends Enum> enumClass = (Class<? extends Enum>) Class.forName(enumType);
        @SuppressWarnings("unchecked")
        Enum<?> enumValue = Enum.valueOf(enumClass, json.getString(JSON_VALUE));
        bundle.putSerializable(key, enumValue);
      } catch (ClassNotFoundException e) {
      } catch (IllegalArgumentException e) {
      }
    }
  }
  public void nmsSetIpMsgAsViewed(long msgId) {
    Bundle param = new Bundle();
    param.putShort(FUNC_ID_nmsSetIpMsgAsViewed + 1, (short) msgId);

    mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsSetIpMsgAsViewed, null, param);
  };
  @Override
  public Bundle[] getTechExtras() {
    synchronized (this) {
      if (mTechExtras != null) return mTechExtras;
      mTechExtras = new Bundle[mTechList.length];
      for (int i = 0; i < mTechList.length; i++) {
        Bundle extras = new Bundle();
        switch (mTechList[i]) {
          case TagTechnology.NFC_A:
            {
              byte[] actBytes = mTechActBytes[i];
              if ((actBytes != null) && (actBytes.length > 0)) {
                extras.putShort(NfcA.EXTRA_SAK, (short) (actBytes[0] & (short) 0xFF));
              } else {
                // Unfortunately Jewel doesn't have act bytes,
                // ignore this case.
              }
              extras.putByteArray(NfcA.EXTRA_ATQA, mTechPollBytes[i]);
              break;
            }

          case TagTechnology.NFC_B:
            {
              // What's returned from the PN544 is actually:
              // 4 bytes app data
              // 3 bytes prot info
              byte[] appData = new byte[4];
              byte[] protInfo = new byte[3];
              if (mTechPollBytes[i].length >= 7) {
                System.arraycopy(mTechPollBytes[i], 0, appData, 0, 4);
                System.arraycopy(mTechPollBytes[i], 4, protInfo, 0, 3);

                extras.putByteArray(NfcB.EXTRA_APPDATA, appData);
                extras.putByteArray(NfcB.EXTRA_PROTINFO, protInfo);
              }
              break;
            }

          case TagTechnology.NFC_F:
            {
              byte[] pmm = new byte[8];
              byte[] sc = new byte[2];
              if (mTechPollBytes[i].length >= 8) {
                // At least pmm is present
                System.arraycopy(mTechPollBytes[i], 0, pmm, 0, 8);
                extras.putByteArray(NfcF.EXTRA_PMM, pmm);
              }
              if (mTechPollBytes[i].length == 10) {
                System.arraycopy(mTechPollBytes[i], 8, sc, 0, 2);
                extras.putByteArray(NfcF.EXTRA_SC, sc);
              }
              break;
            }

          case TagTechnology.ISO_DEP:
            {
              if (hasTech(TagTechnology.NFC_A)) {
                extras.putByteArray(IsoDep.EXTRA_HIST_BYTES, mTechActBytes[i]);
              } else {
                extras.putByteArray(IsoDep.EXTRA_HI_LAYER_RESP, mTechActBytes[i]);
              }
              break;
            }

          case TagTechnology.NFC_V:
            {
              // First byte response flags, second byte DSFID
              if (mTechPollBytes[i] != null && mTechPollBytes[i].length >= 2) {
                extras.putByte(NfcV.EXTRA_RESP_FLAGS, mTechPollBytes[i][0]);
                extras.putByte(NfcV.EXTRA_DSFID, mTechPollBytes[i][1]);
              }
              break;
            }

          case TagTechnology.MIFARE_ULTRALIGHT:
            {
              boolean isUlc = isUltralightC();
              extras.putBoolean(MifareUltralight.EXTRA_IS_UL_C, isUlc);
              break;
            }

          default:
            {
              // Leave the entry in the array null
              continue;
            }
        }
        mTechExtras[i] = extras;
      }
      return mTechExtras;
    }
  }