Beispiel #1
0
 public static void checkEvents(Context context) {
   JSONArray json = PreferenceHelper.getInstance().getNotifications();
   if (json.length() > 0) {
     try {
       Common.onReceiveMSG(json.getJSONObject(0).toString(), context, false);
     } catch (Exception e) {
     }
   }
 }
 void saveChecked() {
   try {
     JSONArray jsa = new JSONArray();
     for (Entry<Integer, Supplier> entry : checked.entrySet()) {
       // int key = entry.getKey();
       Supplier value = entry.getValue();
       if (value != null) {
         jsa.put(value.toString());
       }
     }
     preferenceHelper.setChecked(jsa.toString());
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.driver_activity_add_supplier);
    preferenceHelper = new PreferenceHelper(this);
    mUser = preferenceHelper.getUserInfo();
    btn_next = (ImageView) findViewById(R.id.btn_next);
    btn_minus = (ImageView) findViewById(R.id.btn_minus);
    btn_plus = (ImageView) findViewById(R.id.btn_plus);
    btn_next.setOnClickListener(this);
    btn_minus.setOnClickListener(this);
    btn_plus.setOnClickListener(this);

    txt_value_mile = (TextView) findViewById(R.id.txt_value_mile);
    txt_value_mile.setText(String.valueOf(valueMile));

    listView = (ListView) findViewById(R.id.list);
    adapter = new MyAdapter();
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position >= 0 && position < mList.size()) {
              Supplier item = mList.get(position);
              if (checked.get(item.id) == null) {
                checked.put(item.id, item);
              } else {
                checked.remove(item.id);
              }
              adapter.notifyDataSetChanged();
            }
          }
        });
  }
Beispiel #4
0
  // Phan tich msg tu server socket hoac google cloud message
  public static void onReceiveMSG(String message, Context context, boolean automatic) {
    try {
      //			try {
      //                PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
      //                PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK,
      // "My Tag");
      //                wl.acquire();
      //			} catch (Exception e2) { }
      JSONObject jso = new JSONObject(message);

      String id = "";
      if (automatic) {
        //                if (jso.getString("cmd").equals("has_order") ||
        // jso.getString("cmd").equals("accept_order") ||
        // jso.getString("cmd").equals("deny_order")){
        //                    id = new PreferenceHelper(context).addNotification(message,1);
        id = PreferenceHelper.getInstance().addNotification(message, 1);
        //                }
      } else {
        id = jso.getString("id");
        jso = new JSONObject(jso.getString("data"));
      }

      String cmd = jso.getString("cmd");
      JSONObject data = jso.getJSONObject("data");

      if (dateTimeDifferenceGeneric(data.getString("time"), DATE_NOTIFICATION_MASK) > 2) {
        return;
      }

      if (cmd.equals("has_order")) {
        playSound(context);
        Log.i("notificaiton", "has order");

        // showNotification(context, "You have an order!");
        int customer_id = data.getInt("customer_id");
        int order_id = data.getInt("order_id");
        // if(StatusActivity.CURRENT_STATUS == StatusActivity.STATUS_ORDERHAS ||
        // StatusActivity.CURRENT_STATUS == StatusActivity.STATUS_ORDERSUBMIT) return;
        Intent intent = new Intent(context, HasOrderActivity.class);
        intent.putExtra("customer_id", customer_id);
        intent.putExtra("order_id", order_id);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("notify_id", id);
        notify(context, intent, "You have an order!");
        context.startActivity(intent);
      } else if (cmd.equals("accept_order")) {
        // showNotification(context,"Order has accepted!" );

        int customer_id = data.getInt("customer_id");
        int order_id = data.getInt("order_id");
        int estimate_time = data.getInt("estimate_time");
        String start_time = data.getString("start_time");
        String addressDestination = data.getString("address");
        Intent intent = new Intent(context, DriverConfirmActivity.class);
        intent.putExtra("customer_id", customer_id);
        intent.putExtra("order_id", order_id);
        intent.putExtra("notify_id", id);
        intent.putExtra("estimate_time", estimate_time);
        intent.putExtra("address", addressDestination);
        intent.putExtra("start_time", start_time);
        intent.putExtra("notification", true);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        notify(context, intent, "Order has accepted!");
        context.startActivity(intent);
      } else if (cmd.equals("deny_order")) {
        //				showNotification(context, "Order has denied!");
        int customer_id = data.getInt("customer_id");
        int order_id = data.getInt("order_id");
        // if(StatusActivity.CURRENT_STATUS == StatusActivity.STATUS_ORERLOST) return;
        Intent intent = new Intent(context, OrderLostActivity.class);
        intent.putExtra("customer_id", customer_id);
        intent.putExtra("order_id", order_id);
        intent.putExtra("notify_id", id);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        notify(context, intent, "Order has denied!");
        context.startActivity(intent);
      } else if (cmd.equals("has_voice")) {
        int from_id = data.getInt("from");
        final String file_url = data.getString("url");
        //				if(StatusActivity.CURRENT_STATUS == StatusActivity.STATUS_ORERLOST) return;
        //				Intent intent = new Intent(context, OrderLostActivity.class);
        //				intent.putExtra("from_id", from_id);
        //				intent.putExtra("file_url", file_url);
        //				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //				context.startActivity(intent);
        new Thread(
                new Runnable() {

                  @Override
                  public void run() {
                    MyPlayer player = new MyPlayer();
                    try {
                      player.mPlay(file_url);
                    } catch (IllegalArgumentException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                    } catch (SecurityException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                    } catch (IllegalStateException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                    } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                    }
                  }
                })
            .start();
      } else if (cmd.equals("request_confirm")) {
        //				showNotification(context, "You have a request!");

        int from = data.getInt("from");
        int order_id = data.getInt("order_id");
        // if(StatusActivity.CURRENT_STATUS != StatusActivity.STATUS_ORERCONFIRM) return;
        Intent intent = new Intent();
        intent.setAction(DriverConfirmActivity.REQUEST_CONFIRM);
        intent.putExtra("from", from);
        intent.putExtra("order_id", order_id);
        intent.putExtra("notify_id", id);
        notify(context, intent, "You have a request!");
        PreferenceHelper.getInstance().removeNotification(id);
        context.sendBroadcast(intent);
      } else if (cmd.equals("accept_confirm")) {
        //				showNotification(context, "Order has accepted!");

        int from = data.getInt("from");
        int order_id = data.getInt("order_id");
        // if(StatusActivity.CURRENT_STATUS != StatusActivity.STATUS_ORERCONFIRM) return;
        Intent intent = new Intent();
        intent.setAction(DriverConfirmActivity.ACCEPT_CONFIRM);
        intent.putExtra("from", from);
        intent.putExtra("order_id", order_id);
        intent.putExtra("notify_id", id);
        notify(context, intent, "Order has accepted!");
        PreferenceHelper.getInstance().removeNotification(id);
        context.sendBroadcast(intent);
      } else if (cmd.equals("deny_confirm")) {
        //				showNotification(context, "Order has denied!");

        int from = data.getInt("from");
        int order_id = data.getInt("order_id");
        if (StatusActivity.CURRENT_STATUS != StatusActivity.STATUS_ORERCONFIRM) return;
        Intent intent = new Intent();
        intent.setAction(DriverConfirmActivity.DENY_CONFIRM);
        intent.putExtra("from", from);
        intent.putExtra("order_id", order_id);
        intent.putExtra("notify_id", id);
        notify(context, intent, "Order has denied!");
        PreferenceHelper.getInstance().removeNotification(id);
        context.sendBroadcast(intent);
      } else if (cmd.equals("drivers_list")) {
        //                showNotification(context, "Driver responded");

        //                int from = data.getInt("from");
        int order_id = data.getInt("order_id");
        //                if(StatusActivity.CURRENT_STATUS != StatusActivity.STATUS_ORERCONFIRM)
        // return;
        Intent intent = new Intent();
        intent.setAction(WaitDriversActivity.DRIVER_RESPONDED);
        //                intent.putExtra("from", from);
        intent.putExtra("order_id", order_id);
        intent.putExtra("notify_id", id);

        notify(context, intent, "Driver responded");
        PreferenceHelper.getInstance().removeNotification(id);
        context.sendBroadcast(intent);
      } else if (cmd.equals("cancel_order")) {
        int order_id = data.getInt("order_id");
        Intent intent = new Intent();
        if (PreferenceHelper.getInstance().getUserInfo().type.equals(User.CUSTOMER)) {
          intent.setAction(OrderConfirmedActivity.CANCELLED_ORDER);
          //                    notify(context,intent,"Driver cancelled");
        } else if (PreferenceHelper.getInstance().getUserInfo().type.equals(User.DRIVER)) {
          intent.setAction(DriverConfirmActivity.CANCELLED_ORDER);
          intent.setAction(ActiveOrdersActivity.CANCELLED_ORDER);
          //                    notify(context,intent,"Customer cancelled");
        }
        intent.putExtra("order_id", order_id);

        PreferenceHelper.getInstance().removeNotification(id);
        context.sendBroadcast(intent);
      } else if (cmd.equals("processed_order")) {
        int order_id = data.getInt("order_id");
        Intent intent = new Intent();
        intent.setAction(HasOrderActivity.PROCESSED_ORDER);
        intent.setAction(SubmitOrderActivity.PROCESSED_ORDER);
        intent.putExtra("order_id", order_id);
        PreferenceHelper.getInstance().removeNotification(id);
        context.sendBroadcast(intent);
      } else if (cmd.equals("force_confirm")) {
        int order_id = data.getInt("order_id");
        Intent intent = new Intent();
        intent.setAction(OrderConfirmedActivity.ACCEPT_CONFIRM);
        intent.putExtra("order_id", order_id);
        PreferenceHelper.getInstance().removeNotification(id);
        context.sendBroadcast(intent);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }