Example #1
0
 public static void insertCollect(Context ctx, MSArticle article, MSPlayer player, Message msg) {
   MSResponse response = new MSResponse(msg);
   String collectId = (String) response.getResponseField("favoriteId");
   DBHelper db = DBHelper.getInstance(ctx);
   int time = XTimeUtils.str2time(XTimeUtils.getTime());
   db.insertCollect(article, player.id, time, collectId);
 }
 public NoticeDaoDBManager(Context context) {
   try {
     this.context = context;
     dbHelper = DBHelper.getInstance(context);
     dataBase = dbHelper.getWritableDatabase();
   } catch (Exception e) {
   }
 }
Example #3
0
 public static void syncCollectionSuc(Context ctx, MSResponse msResponse) {
   JSONArray articlesArray = (JSONArray) msResponse.getResponseField("articlesList");
   MSPlayer msPlayer = MSPlayer.currentMSPlayer(ctx);
   DBHelper dbHelper = DBHelper.getInstance(ctx);
   for (int i = 0; i < articlesArray.length(); i++) {
     JSONObject articleObj = articlesArray.optJSONObject(i);
     dbHelper.checkCollection(articleObj, msPlayer.id);
   }
 }
  /**
   * Actionbar is loaded and setup, the database is queried for a list of restaurants, a basic
   * ArrayAdapter is constructed to display names of restaurants in a ListView, and an on click
   * listener for the ListView takes the user to the next activity which can be either
   * BudgetActivity or BudgetAcitivity2.
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Load layout
    setContentView(R.layout.activity_restaurant);

    // Enable home button and manually set title
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setDisplayShowTitleEnabled(false);
    getActionBar().setDisplayShowCustomEnabled(true);
    getActionBar().setCustomView(R.layout.ab_title);
    TextView title = (TextView) findViewById(android.R.id.text1);
    title.setText("Restaurants");

    // Get DBHelper instance and grab restaurant list
    db = DBHelper.getInstance(this);
    restaurantList = db.getRestaurants();

    // Construct basic ArrayAdapter for ListView of restaurants
    adapter =
        new ArrayAdapter<Restaurant>(this, android.R.layout.simple_list_item_1, restaurantList);
    setListAdapter(adapter);

    // onClick listener changes activity to MenuActivity and passes restaurant_id
    ListView listView = getListView();
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            int rid = adapter.getItem(position).getRestaurantID();
            boolean acceptsMeals = adapter.getItem(position).getAcceptsMeals();

            // Toast for closed restaurants, and start new activity appropriately depending on
            // acceptsMeals
            if (rid == 3 || rid == 6) {
              // Prompts that the restaurants are closed
              Toast.makeText(getApplicationContext(), "Currently Closed", Toast.LENGTH_SHORT)
                  .show();
            } else if (acceptsMeals) {
              Intent intent = new Intent(RestaurantActivity.this, BudgetActivity.class);
              intent.putExtra("previous", "RestaurantActivity");
              intent.putExtra("rid", rid);
              startActivity(intent);
            } else {
              Intent intent = new Intent(RestaurantActivity.this, BudgetActivity2.class);
              intent.putExtra("previous", "RestaurantActivity");
              intent.putExtra("rid", rid);
              startActivity(intent);
            }
          }
        });
  }
  /**
   * 插入数据库表
   *
   * @param result
   */
  public synchronized void insertAllNotice(List<HashMap<String, Object>> result) {
    try {
      synchronized (DBHelper.getInstance(context)) {
        for (int i = 0; i < result.size(); i++) {
          String cloumns = "";
          String cloumnValues = "";
          HashMap<String, Object> map = result.get(i);
          Iterator<String> keyIter = map.keySet().iterator();
          String key;
          int count = 0;
          while (keyIter.hasNext()) {
            key = (String) keyIter.next();
            if (!TablesColumns.getAllFileds().contains(key)) {
              continue;
            }
            if (key != null) {
              if (count == 0) {
                cloumns += "'" + key + "'";
                cloumnValues += "'" + map.get(key).toString() + "'";
                count++;
              } else {
                cloumns += ",'" + key + "'";
                cloumnValues += ",'" + map.get(key).toString() + "'";
              }
            }
          }

          String sql =
              "insert into "
                  + TablesColumns.TABLENOTICE
                  + " "
                  + "("
                  + cloumns
                  + ") values ("
                  + cloumnValues
                  + ")";
          dataBase.execSQL(sql);
        }
        Intent intent = new Intent();
        intent.setAction(MainActivity.noticeInfobroastCast);
        if (context != null) {
          context.sendBroadcast(intent);
        }
      }
    } catch (SQLException e) {
    }
  }
  @Override
  protected String doInBackground(String... params) {

    String resultJSON = "";
    String METHOD = params[0];
    this.numero = params[1];
    this.__jsonToSend = params[2];
    Log.i(TAG, StaticFunctions.timeElapsed(this.__jsonToSend, "doInBack"));
    Log.d(TAG, this.__jsonToSend);

    SoapObject request = new SoapObject(NAMESPACE, METHOD);
    if (METHOD.compareTo("sms_check_transaction") == 0
        || METHOD.compareTo("whatsapp_device") == 0
        || METHOD.compareTo("Sales_point_whatsapp_synchronize") == 0)
      request.addProperty("jrquest", this.__jsonToSend);
    else {
      request.addProperty("sgateway", this.__jsonToSend);
    }
    SoapSerializationEnvelope envelope = getSoapSerializationEnvelope(request);
    HttpTransportSE transportSE = new HttpTransportSE(Settings.URL(this.context), 20000);
    transportSE.debug = true;
    transportSE.setXmlVersionTag(Settings.XML_VERSSION);
    try {
      transportSE.call(NAMESPACE + METHOD, envelope);
      testHttpResponse(transportSE);
    } catch (IOException | XmlPullParserException e) {
      DBHelper dbHelper = DBHelper.getInstance(this.context);
      dbHelper.insertLog(
          StaticFunctions.throwToString(e),
          "Problema de conexión con el web service. <<" + TAG + ">>");
    }

    if (envelope.bodyIn != null)
      if (((SoapObject) envelope.bodyIn).getPropertyCount() > 0) {
        SoapObject resultSOAP = (SoapObject) envelope.bodyIn;
        resultJSON = resultSOAP.getProperty(0).toString();
      }
    try {
      transportSE.getServiceConnection().disconnect();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return resultJSON;
  }
 public PasswordDAO(Context context) {
   dbHelper = DBHelper.getInstance(context);
   Log.i(TAG, "dbHelper: " + dbHelper.toString());
 }
Example #8
0
 private GestorEmergencias(Context context) {
   db = DBHelper.getInstance(context).open(context);
 }
  @Override
  protected void onPostExecute(String result) {
    DBHelper dbHelper = DBHelper.getInstance(this.context);

    Log.i(TAG, StaticFunctions.timeElapsed(this.__jsonToSend, "onPOSTExecute"));
    try {
      Log.d(TAG, result);
      JSONObject jsonObject = new JSONObject(result);

      if (jsonObject.has("Confirmation")) {

        String Confirmation = jsonObject.getString("Confirmation");
        String msgResponse = jsonObject.getString("msgResponse");
        String[] arrayParse = this.__jsonToSend.split("\\*");

        String folio;
        if (arrayParse.length == 6) {
          folio = arrayParse[3];
        } else {
          folio = arrayParse[1];
        }
        String folio_casiLimpio = folio.substring(3, 10);
        Log.d(TAG, folio_casiLimpio);
        if (Confirmation.compareTo("00") == 0) {
          Log.d(TAG, "Confirm-->" + this.numero + "Message--->" + msgResponse);
          String folioToUpdate = folio_casiLimpio.replaceFirst("^0+(?!$)", "");
          dbHelper.updateTransaction(
              folioToUpdate,
              jsonObject.getString("Confirmation"),
              RandomMessages.getStringRandom("Status", msgResponse, folio_casiLimpio),
              "1");

        } else if (Confirmation.compareTo("24") == 0 || Confirmation.compareTo("17") == 0) {
          Thread.sleep(3000);
          RequestWebService request = new RequestWebService(this.context);
          /**
           * saldo*folio*99 0 6563942495*20.00*22*52003*99*6561082873 1 tel para recargar 2 monto 3
           * carrier 4 folio 5 puerto 6 send user
           */
          String send = arrayParse[5];
          String recursiveJsonTosend;
          recursiveJsonTosend = "{\"Folio_Pos\":\"" + folio + "\",\"User\":\"" + send + "\"}";

          String folioToUpdate = folio.substring(3, 10).replaceFirst("^0+(?!$)", "");
          String differenceString = dbHelper.getDiffDateTransaction(folioToUpdate);
          double difference = 0.0;
          try {
            if (differenceString != null) {
              difference = Double.parseDouble(differenceString);
            }
          } catch (NullPointerException e) {
            e.printStackTrace();
          }

          if (difference < 120.0) {

            request.execute("sms_check_transaction", this.numero, recursiveJsonTosend);
          } else {
            dbHelper.updateTransaction(
                folioToUpdate,
                jsonObject.getString("Response"),
                RandomMessages.getStringRandom("Status", msgResponse, folio_casiLimpio),
                "1");
          }

        } else {
          String folioToUpdate = folio.substring(3, 10).replaceFirst("^0+(?!$)", "");
          dbHelper.updateTransaction(
              folioToUpdate,
              jsonObject.getString("Confirmation"),
              RandomMessages.getStringRandom("Status", msgResponse, folio_casiLimpio),
              "1");
        }
      } else if (jsonObject.has("Response")) {
        if (jsonObject.has("whatsapp_device")
            || jsonObject.has("Sales_point_whatsapp_synchronize")) {
          JSONArray contactsArray;
          WContacts wContacts = new WContacts(context);
          if (jsonObject.has("Sales_point_whatsapp_synchronize")) {
            contactsArray = jsonObject.getJSONArray("Sales_point_whatsapp_synchronize");

          } else {
            contactsArray = jsonObject.getJSONArray("whatsapp_device");
          }
          try {
            wContacts.insertContacts(contactsArray);
          } catch (RemoteException | OperationApplicationException e) {
            dbHelper.insertLog(
                StaticFunctions.throwToString(e), "Problema al sincronizar usuarios");
          }
        } else {
          if (jsonObject.getString("Response").compareTo("24") == 0
              || jsonObject.getString("Response").compareTo("17") == 0) {
            Thread.sleep(3000);

            String msgResponse = jsonObject.getString("MSG_Response");
            JSONObject jsonObjectSended = new JSONObject(this.__jsonToSend);

            String folio = jsonObjectSended.getString("Folio_Pos");
            String folio_casiLimpio = folio.substring(3, 10);
            String folioToUpdate = folio_casiLimpio.replaceFirst("^0+(?!$)", "");

            double difference = Double.parseDouble(dbHelper.getDiffDateTransaction(folioToUpdate));
            Log.d(TAG, String.valueOf(difference));
            if (difference < 120.0) {

              RequestWebService request = new RequestWebService(this.context);
              request.execute("sms_check_transaction", this.numero, this.__jsonToSend);
            } else {
              dbHelper.updateTransaction(
                  folioToUpdate,
                  jsonObject.getString("Response"),
                  RandomMessages.getStringRandom("Status", msgResponse, folio_casiLimpio),
                  "1");
            }

          } else {
            String msgResponse = jsonObject.getString("MSG_Response");
            String folio;
            if (jsonObject.has("Folio_POS")) {
              folio = jsonObject.getString("Folio_POS");
            } else {
              JSONObject jsonSended = new JSONObject(this.__jsonToSend);
              folio = jsonSended.getString("Folio_Pos");
            }

            String folio_casiLimpio = folio.replaceFirst(Settings.APP_ID(this.context), "");
            String folioToUpdate = folio_casiLimpio.replaceFirst("^0+(?!$)", "");

            dbHelper.updateTransaction(
                folioToUpdate,
                jsonObject.getString("Response"),
                RandomMessages.getStringRandom("Status", msgResponse, folio_casiLimpio),
                "1");
          }
        }

      } else {
        Messages messages =
            new Messages(
                new String[] {this.numero},
                "Hubo un problema con la respuesta del servido, Revisa tu saldo");
        messages.sendMessage();
        messages.close();
      }

    } catch (IOException | JSONException | TimeoutException | InterruptedException e) {
      dbHelper.insertLog(
          StaticFunctions.throwToString(e),
          "Problema al leer JSON, IO, TimeOut o Conexion Interrumpida <<" + TAG + ">>");

      try {
        if (this.numero != null) {
          Messages messages =
              new Messages(
                  new String[] {this.numero}, "Hubo un problema con la conexión, Revisa tu saldo!");
          messages.sendMessage();
          messages.close();
        }
      } catch (IOException | TimeoutException e1) {
        dbHelper.insertLog(
            StaticFunctions.throwToString(e1),
            "Problema al enviar mensaje, Error de IO o timeout con la base de datos <<"
                + TAG
                + ">>");
      }
    }
  }
Example #10
0
 public static String getMaxFavId(Context ctx, String playerId) {
   String maxId = null;
   DBHelper db = DBHelper.getInstance(ctx);
   maxId = db.getMaxFavIdByPlayer(playerId);
   return maxId;
 }
Example #11
0
 public static String getFavoriteId(Context ctx, String articleId) {
   String id = null;
   DBHelper db = DBHelper.getInstance(ctx);
   id = db.selectFavoriteIdByArticleId(articleId);
   return id;
 }
 public ThreadDAOImpl(Context context) {
   mHelper = DBHelper.getInstance(context);
 }
 public DBAdapter(Context context) {
   db = DBHelper.getInstance(context).getWritableDatabase();
 }