Example #1
0
  @Override
  public void processReceivedRecommendations() {
    displayRecommendations();

    if (!ClientAuthentication.getIfRecommendNotifyAdded()) {
      // add to notify
      ArrayList<FullTrip> recommendations = Storage.getRecommendations();

      int i = 1;

      for (FullTrip ft : recommendations) {
        Intent myIntent = new Intent(MainActivity.this, RecommendationAlarmReceiver.class);
        myIntent.setData(Uri.parse("timer:" + i));
        myIntent.putExtra("selectedTrip", ft);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent, 0);

        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

        // notify the user half an hour before the beginning of the trip
        am.set(AlarmManager.RTC_WAKEUP, ft.getStartTime().getTime() - 1800000, pendingIntent);

        ClientAuthentication.setIfRecommendNotifyAdded(true);

        i++;
      }
    }
  }
Example #2
0
  @Override
  protected void onResume() {
    super.onResume();

    boolean finish = getIntent().getBooleanExtra("FINISH", false);
    if (finish) {
      // clear user profile
      ClientAuthentication.initProfile();
      ClientAuthentication.clearGlobalVariables();

      // clear trip, recommendations, etc.
      Storage.clearAll();
      startActivity(new Intent(MainActivity.this, LoginActivity.class));
      finish();
    } else {
      /* GetBusStops */
      if (Storage.isEmptyBusStops()) {
        getBusStops();
      }

      /* GetRecommendations */
      if (!Storage.isEmptyRecommendations()) {
        displayRecommendations();
      } else {
        getRecommendations();
      }
    }
  }
Example #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Locale locale = new Locale(ClientAuthentication.getLanguage());
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext()
        .getResources()
        .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
    setContentView(R.layout.activity_main);
    initAlertDialog();

    Toolbar toolbar = (Toolbar) findViewById(R.id.actionToolBar);
    destination = (AutoCompleteTextView) findViewById(R.id.main_search_destination);
    context = getApplicationContext();
    setSupportActionBar(toolbar);

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view_main);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getBaseContext());
    recyclerView.setLayoutManager(linearLayoutManager);

    String[] addresses = getAddressesFromFileAsset();
    if (addresses != null) {
      ArrayAdapter<String> adapterString =
          new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, addresses);
      destination.setAdapter(adapterString);
    }

    // Hide the keyboard when launching this activity
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  }
 public void sendGeofenceInfo() {
   Storage.turnLocationsToJson();
   JSONObject geofenceInfo = Storage.getGeofenceInfo();
   if (geofenceInfo.length() != 0) {
     String userID = ClientAuthentication.getClientId();
     new SendStoreGeofenceInfoRequest().execute(userID, geofenceInfo.toString());
   }
 }
Example #5
0
  // Called when the user clicks on the quick search button
  public void openMainSearch(View view) {
    String startPositionLatitude, startPositionLongitude, edPosition, userId, startTime, endTime;
    String requestTime, priority;
    Date now = new Date();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);

    startPositionLatitude = String.valueOf(Storage.getLatitude());
    startPositionLongitude = String.valueOf(Storage.getLongitude());
    edPosition = destination.getText().toString();
    userId = ClientAuthentication.getClientId();
    startTime = df.format(now);
    requestTime = df.format(now);
    endTime = "null";
    priority = "distance";

    if (!edPosition.trim().isEmpty()
        && Storage.getLatitude() != 0.0
        && Storage.getLongitude() != 0.0) {
      SendQuickTravelRequest asyncTask = new SendQuickTravelRequest();
      asyncTask.delegate = this;
      asyncTask.execute(
          userId,
          startTime,
          endTime,
          requestTime,
          startPositionLatitude,
          startPositionLongitude,
          edPosition,
          priority);
    } else if (edPosition.trim().isEmpty()) {
      CharSequence text = getString(R.string.java_search_enterdestination);
      Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
      toast.show();
    } else {
      CharSequence text = getString(R.string.java_search_locationdisabled);
      Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
      toast.show();
    }
  }