/** {@inheritDoc} */
  public void onSensorChanged(SensorEvent evt) {
    if (!computing.compareAndSet(false, true)) return;

    if (evt.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
      grav[0] = evt.values[0];
      grav[1] = evt.values[1];
      grav[2] = evt.values[2];
    } else if (evt.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
      mag[0] = evt.values[0];
      mag[1] = evt.values[1];
      mag[2] = evt.values[2];
    }

    float gravity = grav[0] + grav[1] + grav[2];
    float magnetic = mag[0] + mag[1] + mag[2];

    float gravDiff = Math.abs(gravity - prevGrav);
    float magDiff = Math.abs(magnetic - prevMag);
    // Log.i(TAG, "gravDiff="+gravDiff+" magDiff="+magDiff);

    if ((Float.compare(prevGrav, 0.0f) != 0 && Float.compare(prevMag, 0.0f) != 0)
        && (gravDiff > gravThreshold || magDiff > magThreshold)) {
      GlobalData.setPhoneInMotion(true);
    } else {
      GlobalData.setPhoneInMotion(false);
    }

    prevGrav = gravity;
    prevMag = magnetic;

    computing.set(false);
  }
  @Override
  public void onReceive(Context context, Intent intent) {

    GlobalData.logE("#### EventsCalendarBroadcastReceiver.onReceive", "xxx");

    if (!GlobalData.getApplicationStarted(context))
      // application is not started
      return;

    GlobalData.loadPreferences(context);

    if (GlobalData.getGlobalEventsRuning(context)) {
      GlobalData.logE("@@@ EventsCalendarBroadcastReceiver.onReceive", "xxx");

      boolean calendarEventsExists = false;

      DataWrapper dataWrapper = new DataWrapper(context, false, false, 0);
      calendarEventsExists =
          dataWrapper.getDatabaseHandler().getTypeEventsCount(DatabaseHandler.ETYPE_CALENDAR) > 0;
      GlobalData.logE(
          "EventsCalendarBroadcastReceiver.onReceive",
          "calendarEventsExists=" + calendarEventsExists);
      dataWrapper.invalidateDataWrapper();

      if (calendarEventsExists) {
        // start service
        Intent eventsServiceIntent = new Intent(context, EventsService.class);
        eventsServiceIntent.putExtra(
            GlobalData.EXTRA_BROADCAST_RECEIVER_TYPE, BROADCAST_RECEIVER_TYPE);
        startWakefulService(context, eventsServiceIntent);
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_summary_board_game_solo);

    GlobalData globalData = (GlobalData) getApplicationContext();
    ListView summaryList = (ListView) findViewById(R.id.summaryList);
    summaryList.setAdapter(
        new SummaryListAdapter(getApplicationContext(), R.layout.row_model_summary, globalData));

    TextView txtTotalTime = (TextView) findViewById(R.id.txtTotalTime);
    TextView txtTotalDifference = (TextView) findViewById(R.id.txtTotalDifference);
    TextView txtTotalNumbersCaught = (TextView) findViewById(R.id.txtTotalNumbersCaught);
    TextView txtRatio = (TextView) findViewById(R.id.txtRatio);

    txtTotalTime.setText("Total time : " + globalData.getChrono().getText());
    int totalDiff = 0;
    int nbElems = globalData.getTabNumbersTaps().size() - 1;
    for (int i = 0; i < nbElems; i++) {
      totalDiff += globalData.getTabNumbersToCatch().get(i) - globalData.getTabNumbersTaps().get(i);
    }
    // add penality of the last catch number
    totalDiff -=
        globalData.getTabNumbersToCatch().get(nbElems)
            - globalData.getTabNumbersTaps().get(nbElems);
    txtTotalDifference.setText("Total difference : " + totalDiff);
    // -1 because the last one are saved (the last are bigger than the numbers caught)
    txtTotalNumbersCaught.setText(
        "Total caught : " + (globalData.getTabNumbersToCatch().size() - 1));

    double ratio =
        totalDiff > 0
            ? (double) (globalData.getTabNumbersToCatch().size() - 1) / (double) totalDiff
            : 0;
    double ratioTwoDecimal = (double) ((int) (ratio * 100)) / 100;
    txtRatio.setText("Ratio : " + ratioTwoDecimal);
  }
  @TargetApi(Build.VERSION_CODES.M)
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_manager_for_approval, container, false);
    managerToBeApproved = (ListView) view.findViewById(R.id.managerToBeApproved);
    jsonString = GlobalData.getManagerToBeApprovedData();

    try {
      jsonObject = new JSONObject(jsonString);
      jsonArray = jsonObject.getJSONArray("server_response");
      int count = 0;

      managerForApprovalAdapter =
          new ManagerForApprovalAdapter(
              this.getActivity(), R.layout.row_layout_manager_tobe_approved);
      managerToBeApproved.setAdapter(managerForApprovalAdapter);
      managerForApprovalAdapter.notifyDataSetChanged();

      while (count < jsonArray.length()) {
        JSONObject JO = jsonArray.getJSONObject(count);
        employeeName = JO.getString("employee_name");
        employeeEmail = JO.getString("employee_email");
        taskName = JO.getString("task_name");
        taskDescription = JO.getString("task_description");
        taskAmount = JO.getString("task_amount");

        ManagerForApprovalList managerForApprovalList =
            new ManagerForApprovalList(
                employeeEmail, employeeName, taskAmount, taskDescription, taskName);
        managerForApprovalAdapter.add(managerForApprovalList);
        count++;
      }

    } catch (JSONException e) {
      e.printStackTrace();
    }
    return view;
  }
Example #5
0
 public ParseJson(JSONArray images) {
   this.images = images;
   GlobalData global = GlobalData.getInstance();
   imageData = global.getImageData();
 }