示例#1
0
    @Override
    protected Boolean doInBackground(Void... parameters) {

      if (isCancelled()) return null;

      try {

        String response = "";

        Map<String, String> params = new HashMap<String, String>();

        response = ConsumerService.getInstance().login(mUsuario, mPassword);
        JSONObject o = new JSONObject(response);
        int retorno = Integer.parseInt(o.get("retorno").toString());

        // Senha invalida:
        if (retorno < 0) {
          return false;
        }

        idMotorista = Integer.parseInt(o.get("id_motorista").toString());
        nomeMotorista = o.get("nome").toString();

        getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
            .edit()
            .putString(PREF_USERNAME, mUsuario)
            .putString(PREF_PASSWORD, mPassword)
            .putString(PREF_ID, o.get("id_motorista").toString())
            .commit();

        dados = ConsumerService.getInstance().buscaDadosEntregas(String.valueOf(idMotorista));

      } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      return true;
    }