コード例 #1
0
 /**
  * Add extended data to the extra.
  *
  * @param name The name of the extra data, with package prefix.
  * @param value The short array data value.
  * @return Returns the same extra object, for chaining multiple calls into a single statement.
  * @see #putExtras
  * @see #removeExtra
  * @see #getShortArrayExtra(String)
  */
 public Request putExtra(String name, short[] value) {
   if (mExtras == null) {
     mExtras = new Bundle();
   }
   mExtras.putShortArray(name, value);
   return this;
 }
 private static void putShortArray(String key, Bundle bundle) {
   int length = random.nextInt(50);
   short[] array = new short[length];
   for (int i = 0; i < length; i++) {
     array[i] = (short) random.nextInt();
   }
   bundle.putShortArray(key, array);
 }
コード例 #3
0
 private void sendUIMessage(short[] buffer, int length) {
   Bundle bundle = new Bundle();
   bundle.putInt("message", MSG_RECORD);
   bundle.putShortArray("buffer", buffer);
   bundle.putInt("length", length);
   Message msg = uiHandler.obtainMessage();
   msg.setData(bundle);
   uiHandler.sendMessage(msg);
 }
コード例 #4
0
  public boolean nmsDeleteContactFromSpamList(int[] engineContactIds) {
    Bundle param = new Bundle();
    if (engineContactIds == null || engineContactIds.length <= 0) {
      NmsLog.error(HissageTag.api, "The engineContactIds is null or the length is 0");
      return false;
    }
    short[] s = new short[engineContactIds.length];

    for (int i = 0; i < engineContactIds.length; i++) {
      s[i] = (short) engineContactIds[i];
    }
    param.putShortArray(FUNC_ID_nmsDeleteContactFromSpamList + 1, s);

    Bundle back =
        mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsDeleteContactFromSpamList, null, param);
    if (back != null) {
      return back.getBoolean(FUNC_ID_nmsDeleteContactFromSpamList);
    } else {
      NmsLog.error(HissageTag.api, "failed to delete contact from spam list, return false");
      return false;
    }
  }
  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) {
      }
    }
  }