예제 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_help_request_map);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment =
        (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    // get the infoBundle from the intent
    infoBundle = getIntent().getParcelableExtra(Config.INTENT_INFO_BUNDLE);

    // so that we don't receive new notification when the activity has already been started...
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    sp.edit().putBoolean(Config.SHARED_PREFS_ALARM_ACTIVE, true).apply();

    // get the message of the pin and display it
    TextView msgView = (TextView) findViewById(R.id.msg);
    String msg = getString(R.string.message_prefix);
    if (infoBundle.message.equals("")) msg += getString(R.string.no_personal_message);
    else msg += infoBundle.message;
    msgView.setText(msg);

    Button accept = (Button) findViewById(R.id.accept);
    accept.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            HelpOthers.this.onAccept();
          }
        });

    Button decline = (Button) findViewById(R.id.decline);
    decline.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            declined = true;
            finish();
          }
        });

    // the list of HelperLocationUpdate implementation that will get called if the location changes
    locationUpdates = new LinkedList<>();

    // create the map combiner
    mapCombiner = new HelperMapCombiner();
    mapCombiner.register(this);

    // build Google API client to get the last known location
    buildGoogleApiClient();
    mGoogleApiClient.connect();

    String firebaseUrl = sp.getString(Config.INTENT_FIREBASE_ALARM_URL, "");
    OnGoingAlarmHelper alarm =
        new OnGoingAlarmHelper(getApplicationContext(), firebaseUrl, mapCombiner, infoBundle);
    alarm.registerOnCancelListener(this);
    locationUpdates.add(alarm);
  }
예제 #2
0
 // mapCombiner update: gets called when the map combiner gets an update of the pin location
 @Override
 public void onUpdate() {
   Location newLoc = (Location) mapCombiner.getMap().values().toArray()[0];
   LatLng loc = new LatLng(newLoc.getLatitude(), newLoc.getLongitude());
   pinMarker.setPosition(loc);
 }