コード例 #1
0
ファイル: MainActivity.java プロジェクト: dymin01/GMGPS
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    map = mapFragment.getMap();

    // 현재 위치로 가는 버튼 표시
    map.setMyLocationEnabled(true);
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(SEOUL, 15)); // 초기 위치...수정필요

    MyLocation.LocationResult locationResult =
        new MyLocation.LocationResult() {
          @Override
          public void gotLocation(Location location) {

            String msg = "lon: " + location.getLongitude() + " -- lat: " + location.getLatitude();
            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
            drawMarker(location);
          }
        };

    MyLocation myLocation = new MyLocation();
    myLocation.getLocation(getApplicationContext(), locationResult);
  }
コード例 #2
0
ファイル: InputActivity.java プロジェクト: westlinkin/BitHiro
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   getMenuInflater().inflate(R.menu.action_bar_input, menu);
   //    	menu_show = menu;
   menu.getItem(1).setVisible(MyLocation.isMenuShow_1(this));
   menu.getItem(0).setVisible(MyLocation.isMenuShow_0(this));
   Log.v("isServiceRunning", String.valueOf(MyLocation.isMenuShow_1(this)));
   return true;
 }
コード例 #3
0
  @Override
  public void onCreate(Bundle savedBundleInstance) {
    super.onCreate(savedBundleInstance);

    setContentView(R.layout.activity);
    con = getApplicationContext();
    MyLocation ml = new MyLocation();
    ml.onCreate(con);
    lv_nearest_restro_list = (ListView) findViewById(R.id.nearest_restro_list);
    lv_nearest_restro_list.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //			    Toast.makeText(getApplicationContext(),
            //			      "Click ListItem Number " + position, Toast.LENGTH_LONG)
            //			      .show();
          }
        });

    FetchJSON fj = new FetchJSON();
    fj.execute("");
  }
コード例 #4
0
ファイル: InputActivity.java プロジェクト: westlinkin/BitHiro
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        // app icon in action bar clicked; go home
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        return true;

      case R.id.menu_run:
        if (et_input.getText().toString().trim().equals("")) {
          return true;
        }
        // 判断是否有网络连接
        if (!(MyLocation.hasNetworkConnection(this))) {
          Toast.makeText(this, getResources().getString(R.string.networkError), Toast.LENGTH_SHORT)
              .show();
          return true;
        }
        address_info = et_input.getText().toString().trim();
        Intent i_service = new Intent(InputActivity.this, MockLocation.class);
        Bundle bundle = new Bundle();
        bundle.putString("virtual_address", address_info);
        //   Log.v(TAG, address_info);
        i_service.putExtras(bundle);

        startService(i_service);

        // 启动提示
        NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification mNotification =
            new Notification(
                R.drawable.location_place,
                getResources().getString(R.string.begin_loaction),
                System.currentTimeMillis());
        PendingIntent contentIntent =
            PendingIntent.getActivity(InputActivity.this, 0, getIntent(), 0);
        mNotification.setLatestEventInfo(
            InputActivity.this,
            getResources().getString(R.string.begin_loaction),
            address_info,
            contentIntent);
        mNotification.defaults = Notification.DEFAULT_SOUND;
        mNotification.flags = Notification.FLAG_NO_CLEAR;
        mNotificationManager.notify(R.drawable.location_place, mNotification);

        // 关闭整个activity
        Intent i_finish = new Intent(InputActivity.this, FinishActivity.class);
        i_finish.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i_finish);
        overridePendingTransition(0, 0);
        this.finish();

        return true;

      case R.id.menu_stop:
        Intent i_service_stop = new Intent(InputActivity.this, MockLocation.class);
        stopService(i_service_stop);

        // 清除提示
        NotificationManager mNotificationManager_stop =
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification mNotification_stop =
            new Notification(
                R.drawable.location_place,
                getResources().getString(R.string.stop_loaction),
                System.currentTimeMillis());
        PendingIntent contentIntent_stop =
            PendingIntent.getActivity(InputActivity.this, 0, getIntent(), 0);
        mNotification_stop.setLatestEventInfo(
            InputActivity.this,
            getResources().getString(R.string.stop_loaction),
            address_info,
            contentIntent_stop);
        // mNotification.defaults = Notification.DEFAULT_SOUND;
        mNotification_stop.flags = Notification.FLAG_AUTO_CANCEL;
        mNotificationManager_stop.notify(R.drawable.location_place, mNotification_stop);
        mNotificationManager_stop.cancel(R.drawable.location_place);

        // 刷新界面
        Intent i_reflesh_stop = new Intent(InputActivity.this, InputActivity.class);
        i_reflesh_stop.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i_reflesh_stop);
        overridePendingTransition(0, 0);
        return true;

        //  case R.id.menu_run:
        // begin traval

        //	return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }
コード例 #5
0
  private void setupLocationReceiver() {
    // Create Trip
    String cTrip =
        restTest.post(
            MobilemileagetrackerActivity.SITE_URL,
            "trip/",
            "{\"name\": \"" + tripName + "\", \"device\": \"" + device_uri + "\"}",
            username,
            password,
            MobilemileagetrackerActivity.SITE_PORT);
    //			   restTest.post(MobilemileagetrackerActivity.SITE_URL, "device/", "{\"device_type\":
    // \"Android\", \"name\": \""+user+" Phone\", \"uuid\": \""+myuuid+"\"}" ,user, pw,
    // MobilemileagetrackerActivity.SITE_PORT);

    String dog = "{\"name\": \"" + tripName + "\", \"device\": \"" + device_uri + "\"}";

    // Get Created Trip ID
    String trips =
        restTest.get(
            MobilemileagetrackerActivity.SITE_URL,
            "trip/",
            username,
            password,
            MobilemileagetrackerActivity.SITE_PORT);
    GsonBuilder gsonb = new GsonBuilder();
    Gson gson = gsonb.create();
    DeviceResponse rDevices = null;

    TripResponse tR = gson.fromJson(trips, TripResponse.class);
    Trip[] tripList = tR.trips;

    for (int x = 0; x < tripList.length; x++) {
      if (tripList[x].name.equals(tripName)) trip_uri = tripList[x].resource_uri;
    }

    locationResult =
        new LocationResult() {
          @Override
          public void gotLocation(final Location location) {
            // double acc = location.getAccuracy()/3.2808399;
            // POST locations to current trip
            String cLocData =
                "{"
                    + "\"altitude\": 1.0, "
                    + "\"horizontal_accuracy\":"
                    + location.getAccuracy()
                    + ",\"latitude\": "
                    + String.valueOf(location.getLatitude())
                    + ",\"longitude\": "
                    + String.valueOf(location.getLongitude())
                    + ",\"timestamp\": \""
                    + String.valueOf(location.getTime())
                    + "\""
                    + ",\"trip\": \""
                    + trip_uri
                    + "\", "
                    + "\"vertical_accuracy\": 0.0}";
            String cLoc =
                restTest.post(
                    MobilemileagetrackerActivity.SITE_URL,
                    "location/",
                    "{"
                        + "\"altitude\": 1.0, "
                        + "\"horizontal_accuracy\":"
                        + location.getAccuracy()
                        + ",\"latitude\": "
                        + String.valueOf(location.getLatitude())
                        + ",\"longitude\": "
                        + String.valueOf(location.getLongitude())
                        + ",\"timestamp\": \""
                        + String.valueOf(location.getTime())
                        + "\""
                        + ",\"trip\": \""
                        + trip_uri
                        + "\", "
                        + "\"vertical_accuracy\": 0.0}",
                    username,
                    password,
                    MobilemileagetrackerActivity.SITE_PORT);
          }
        };

    myLocation = new MyLocation();
    myLocation.trackLocation(this, locationResult);
  }
コード例 #6
0
 public void onPause() {
   super.onPause();
   myLocation.stopTracking();
 }