/**
  * Construct a JSONArray from a Collection.
  *
  * @param collection A Collection.
  */
 public JSONArray(Collection<?> collection) {
   this.myArrayList = new ArrayList<Object>();
   if (collection != null) {
     for (Object o : collection) {
       this.myArrayList.add(JSONObject.wrap(o));
     }
   }
 }
Пример #2
0
 /**
  * Construct a JSONArray from a Collection.
  *
  * @param collection A Collection.
  */
 public JSONArray(Collection<?> collection) {
   this.myArrayList = new ArrayList<Object>();
   if (collection != null) {
     Iterator<?> iter = collection.iterator();
     while (iter.hasNext()) {
       this.myArrayList.add(JSONObject.wrap(iter.next()));
     }
   }
 }
Пример #3
0
 /**
  * Construct a JSONArray from an array
  *
  * @throws JSONException If not an array.
  */
 public JSONArray(Object array) throws JSONException {
   this();
   if (array.getClass().isArray()) {
     int length = Array.getLength(array);
     for (int i = 0; i < length; i += 1) {
       this.put(JSONObject.wrap(Array.get(array, i)));
     }
   } else {
     throw new JSONException("JSONArray initial value should be a string or collection or array.");
   }
 }
Пример #4
0
 /**
  * Construct a JSONObject from a Map.
  *
  * @param map A map object that can be used to initialize the contents of the JSONObject.
  * @throws JSONException
  */
 public JSONObject(Map map) {
   this.map = new HashMap();
   if (map != null) {
     final Iterator i = map.entrySet().iterator();
     while (i.hasNext()) {
       final Map.Entry e = (Map.Entry) i.next();
       final Object value = e.getValue();
       if (value != null) {
         this.map.put(e.getKey(), JSONObject.wrap(value));
       }
     }
   }
 }
 private String convertJSON(Bundle bundle) {
   JSONObject json = new JSONObject();
   Set<String> keys = bundle.keySet();
   for (String key : keys) {
     try {
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
         json.put(key, JSONObject.wrap(bundle.get(key)));
       } else {
         json.put(key, bundle.get(key));
       }
     } catch (JSONException e) {
       return null;
     }
   }
   return json.toString();
 }
Пример #6
0
  private void populateMap(Object bean) {
    final Class klass = bean.getClass();

    // If klass is a System class then set includeSuperClass to false.

    final boolean includeSuperClass = klass.getClassLoader() != null;

    final Method[] methods = (includeSuperClass) ? klass.getMethods() : klass.getDeclaredMethods();
    for (final Method method : methods) {
      try {
        if (Modifier.isPublic(method.getModifiers())) {
          final String name = method.getName();
          String key = "";
          if (name.startsWith("get")) {
            if (name.equals("getClass") || name.equals("getDeclaringClass")) {
              key = "";
            } else {
              key = name.substring(3);
            }
          } else if (name.startsWith("is")) {
            key = name.substring(2);
          }
          if ((key.length() > 0)
              && Character.isUpperCase(key.charAt(0))
              && (method.getParameterTypes().length == 0)) {
            if (key.length() == 1) {
              key = key.toLowerCase();
            } else if (!Character.isUpperCase(key.charAt(1))) {
              key = key.substring(0, 1).toLowerCase() + key.substring(1);
            }

            final Object result = method.invoke(bean, (Object[]) null);
            if (result != null) {
              this.map.put(key, JSONObject.wrap(result));
            }
          }
        }
      } catch (final Exception ignore) {
      }
    }
  }
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    hash = data.getString(Provider.HASH_COLUMN);

    JSONObject json;
    if (state == null) {
      json = pedirInfo();
    } else {
      json = new JSONObject();
      Set<String> keys = state.keySet();
      for (String key : keys) {
        try {

          json.put(key, JSONObject.wrap(state.get(key)));
        } catch (Exception e) {

        }
      }
    }

    Button btnCelular = (Button) vista.findViewById(R.id.btn_celular_configuracion);

    Button btnWhat = (Button) vista.findViewById(R.id.btn_whatsapp_configuracion);

    Button btnMail = (Button) vista.findViewById(R.id.btn_mail_configuracion);

    try {

      // Botones
      if (json.getBoolean("concel")) {

        btnCelular.setBackgroundColor(getResources().getColor(R.color.orange));

        celular = true;
        mail = false;
        whatsapp = false;
      } else if (json.getBoolean("wa")) {

        btnWhat.setBackgroundColor(getResources().getColor(R.color.orange));

        celular = false;
        mail = false;
        whatsapp = true;
      } else {

        btnMail.setBackgroundColor(getResources().getColor(R.color.orange));
        celular = false;
        mail = true;
        whatsapp = false;
      }
      // checkBox

      ((CheckBox) vista.findViewById(R.id.check_mostrarInfo_configuracion))
          .setChecked(json.getBoolean("moscel"));
      ((CheckBox) vista.findViewById(R.id.check_ofertaNueva_configuracion))
          .setChecked(json.getBoolean("ofertas"));
      ((CheckBox) vista.findViewById(R.id.check_viajeCancelado_configuracion))
          .setChecked(json.getBoolean("vcancelado"));
      ((CheckBox) vista.findViewById(R.id.check_ofertaCancelada_configuracion))
          .setChecked(json.getBoolean("ocancelado"));
      ((CheckBox) vista.findViewById(R.id.check_calificacionPendiente_configuracion))
          .setChecked(json.getBoolean("cal"));
      ((CheckBox) vista.findViewById(R.id.check_ofertaAceptada_configuracion))
          .setChecked(json.getBoolean("aceptado"));

      // numero

      ((EditText) vista.findViewById(R.id.numero_configuracion)).setText(json.getString("cel"));

    } catch (Exception e) {
      Log.v("prueba", "Error leyendo el json");
    }

    // Botones

    btnCelular.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            celular = true;
            mail = false;
            whatsapp = false;

            ((Button) vista.findViewById(R.id.btn_celular_configuracion))
                .setBackgroundColor(getResources().getColor(R.color.orange));

            ((Button) vista.findViewById(R.id.btn_whatsapp_configuracion))
                .setBackgroundColor(getResources().getColor(R.color.white));

            ((Button) vista.findViewById(R.id.btn_mail_configuracion))
                .setBackgroundColor(getResources().getColor(R.color.white));
          }
        });

    btnMail.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            celular = false;
            mail = true;
            whatsapp = false;

            ((Button) vista.findViewById(R.id.btn_celular_configuracion))
                .setBackgroundColor(getResources().getColor(R.color.white));

            ((Button) vista.findViewById(R.id.btn_whatsapp_configuracion))
                .setBackgroundColor(getResources().getColor(R.color.white));

            ((Button) vista.findViewById(R.id.btn_mail_configuracion))
                .setBackgroundColor(getResources().getColor(R.color.orange));
          }
        });

    btnWhat.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            celular = false;
            mail = false;
            whatsapp = true;

            ((Button) vista.findViewById(R.id.btn_celular_configuracion))
                .setBackgroundColor(getResources().getColor(R.color.white));

            ((Button) vista.findViewById(R.id.btn_whatsapp_configuracion))
                .setBackgroundColor(getResources().getColor(R.color.orange));

            ((Button) vista.findViewById(R.id.btn_mail_configuracion))
                .setBackgroundColor(getResources().getColor(R.color.white));
          }
        });

    ((Button) vista.findViewById(R.id.btn_guardar_configuracion))
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                enviarInfo();
              }
            });
  }