// ex1, 获取gps信息的按钮的事件
  private void getGpsinfoButtonClick(View v) {
    if (mLocationHelper == null) {
      mLocationHelper = LocationHelper.getInstance();
    }

    int intRet = mLocationHelper.init(MainActivity.this, this);
    if (intRet == Constants.ERROR_CANT_GET_GPS_SERVICE) {
      Toast.makeText(this, "请打开GPS服务!", Toast.LENGTH_LONG).show();
    } else if (intRet == Constants.ERROR_CANT_GET_GPS_INFO) {
      Log.e(TAG, "无法获得GPS数据信息!");
      return;
    }
  }
 @Override
 protected void onResume() {
   // 需要刷新GPS获取信息
   if (mLocationHelper != null) {
     mLocationHelper.refresh();
   }
   super.onResume();
 }
  @Override
  public void onDestroy() {
    if (mLocationHelper != null) {
      mLocationHelper.uninit();
    }

    if ((mTimerHelper != null) && mUpdateTimerRunnable != null) {
      mTimerHelper.removeTimer(mUpdateTimerRunnable);
      mTimerHelper = null;
    }
    super.onDestroy();
  }
Example #4
0
 private static URL computeSharedConfigurationLocation() {
   String property = FrameworkProperties.getProperty(PROP_SHARED_CONFIG_AREA);
   if (property == null) return null;
   try {
     URL sharedConfigurationURL = LocationHelper.buildURL(property, true);
     if (sharedConfigurationURL == null) return null;
     if (sharedConfigurationURL.getPath().startsWith("/")) // $NON-NLS-1$
       // absolute
       return sharedConfigurationURL;
     URL installURL = installLocation.getURL();
     if (!sharedConfigurationURL.getProtocol().equals(installURL.getProtocol()))
       // different protocol
       return sharedConfigurationURL;
     sharedConfigurationURL = new URL(installURL, sharedConfigurationURL.getPath());
     FrameworkProperties.setProperty(
         PROP_SHARED_CONFIG_AREA, sharedConfigurationURL.toExternalForm());
   } catch (MalformedURLException e) {
     // do nothing here since it is basically impossible to get a bogus url
   }
   return null;
 }
Example #5
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.arc);
    locHelper = new LocationHelper();
    locHelper.getLocation(ARC.this, locationResult);
    locationControlTask = new LocationControl();
    /*lstView = (ListView)findViewById(R.id.listView1);
    lstView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    lstView.setTextFilterEnabled(true);*/
    colleges = getResources().getStringArray(R.array.colleges_array);
    longitude = getResources().getStringArray(R.array.longitude_array);
    latitude = getResources().getStringArray(R.array.latitude_array);
    college_address = getResources().getStringArray(R.array.College_address);
    // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.simplerow, colleges);

    // Assign adapter to ListView
    // lstView.setAdapter(adapter);
    // setListAdapter(new ArrayAdapter<String>(this,
    // android.R.layout.simple_list_item_checked, colleges));

    listView = (ExpandableListView) findViewById(R.id.list);
    List<Map<String, Object>> parentsList = new ArrayList<Map<String, Object>>();
    List<List<Map<String, Object>>> childrenList = new ArrayList<List<Map<String, Object>>>();

    PackageManager pm = getPackageManager();
    List<PackageInfo> packages = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    for (int i = 0; i < colleges.length; i++) {
      // String[] permissions = info.requestedPermissions;
      if (colleges != null) {
        Map<String, Object> parentData = new HashMap<String, Object>();
        parentData.put(PARENT, colleges[i]);
        parentsList.add(parentData);

        List<Map<String, Object>> childList = new ArrayList<Map<String, Object>>();
        for (int j = i; j <= i; j++) {
          Map<String, Object> childData = new HashMap<String, Object>();
          childData.put(CHILD, college_address[i]);
          childList.add(childData);
        }
        childrenList.add(childList);
      }
    }

    /* btnShowLocation = (Button) findViewById(R.id.btnShowLocation);

          // show location button click event
          btnShowLocation.setOnClickListener(new View.OnClickListener() {

    	@Override
    	public void onClick(View arg0) {
    		// create class object
            gps = new GPSTracker(ARC.this);

    		// check if GPS enabled
            if(gps.canGetLocation()){

            	 lat = gps.getLatitude();
            	 lng = gps.getLongitude();

            	// \n is for new line

            	double mindist=100000.0,l=0.0,g=0.0;
      		  int i,m=0;
      		  for(i=0;i<colleges.length;i++)
      		  {   Double c_lat=Double.parseDouble(latitude[i]);
      		      Double c_lng=Double.parseDouble(longitude[i]);

      			  double min=sqrt(pow((c_lat-lat),2)+pow((c_lng-lng),2));
      		       if (min<mindist)
      		       {
      		    	   l=c_lat;
      		    	   g=c_lng;
      		    	   mindist=min;
      		    	   m=i;

      		       }}
      		Toast.makeText(getApplicationContext(),"Nearest ARC is "+ colleges[m], Toast.LENGTH_LONG).show();

      		  listView.smoothScrollToPosition(m);


            }else{
            	// can't get location
            	// GPS or Network is not enabled
            	// Ask user to enable GPS/network in settings
            	gps.showSettingsAlert();
            }

    	}
    });*/
    SimpleExpandableListAdapter adapter =
        new SimpleExpandableListAdapter(
            ARC.this,
            parentsList,
            R.layout.expandablelistview_group,
            new String[] {PARENT},
            new int[] {R.id.TextViewGroup},
            childrenList,
            R.layout.raw,
            new String[] {CHILD},
            new int[] {R.id.permission});

    listView.setAdapter(adapter);
  }
Example #6
0
 @Override
 protected void onStop() {
   locHelper.stopLocationUpdates();
   locationControlTask.cancel(true);
   super.onStop();
 }
Example #7
0
 /**
  * Builds a URL with the given specification
  *
  * @param spec the URL specification
  * @param trailingSlash flag to indicate a trailing slash on the spec
  * @return a URL
  */
 public static URL buildURL(String spec, boolean trailingSlash) {
   return LocationHelper.buildURL(spec, trailingSlash);
 }
Example #8
0
 private static URL computeInstallConfigurationLocation() {
   String property = FrameworkProperties.getProperty(PROP_INSTALL_AREA);
   if (property != null) return LocationHelper.buildURL(property, true);
   return null;
 }
  private void getPlaces() {
    // Get some cool places!

    Location location = LocationHelper.getLocation(this);

    if (location != null) {
      Log.i(TAG, "Location!");
    }
    double latitude = 33.8303090;
    double longitude = -118.3068440;

    try {
      Request request =
          new Request.Builder()
              .url(
                  "https://maps.googleapis.com/maps/api/place/nearbysearch/json?key="
                      + getString(R.string.apiKey)
                      + "&"
                      + "location="
                      + latitude
                      + ","
                      + longitude
                      + "&"
                      + "radius="
                      + 500
                      + "&"
                      + "type=food"
                      + "&"
                      + "rankBy=distance") //  500 meters
              .build();

      Log.i(TAG, request.toString());

      okHttpClient
          .newCall(request)
          .enqueue(
              new Callback() {
                @Override
                public void onFailure(Request request, IOException e) {
                  // SOMETHING WENT WRONG
                  // TODO: Insert AlertDialog here!

                }

                @Override
                public void onResponse(Response response) throws IOException {
                  // SOMETHING AWESOME HAPPENED
                  Handler uiThread = new Handler(getBaseContext().getMainLooper());
                  JsonParser parser = new JsonParser();
                  String data = response.body().string();
                  JsonElement element = parser.parse(data);

                  if (element.isJsonObject()) {
                    JsonArray results = element.getAsJsonObject().get("results").getAsJsonArray();

                    for (int i = 0; i < results.size(); i++) {
                      JsonObject place = results.get(i).getAsJsonObject();
                      String name = place.get("name").getAsString();
                      String address = place.get("vicinity").getAsString();
                      boolean isOpen;

                      if (place.has("opening_hours")) {
                        JsonObject openHours = place.get("opening_hours").getAsJsonObject();
                        isOpen = openHours.get("open_now").getAsBoolean();
                      } else {
                        isOpen = false;
                      }

                      Place item = new Place(name, address, isOpen);

                      model.add(item);
                    }

                    uiThread.post(
                        new Runnable() {
                          @Override
                          public void run() {
                            buildListview();
                          }
                        });
                  } else {
                    Log.e(TAG, "=====FAILURE=====");
                    Log.e(TAG, "element is not a JsonElement");
                  }
                }
              });

    } catch (Exception e) {
      e.printStackTrace();
    }
  }