@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { this.wwwRoot = new File( this.getFilesDir().getAbsolutePath() + File.separator + LocationUtils.assetsFlag); if (this.wwwRoot.exists()) { this.wwwRoot.delete(); } LocationUtils.copyAsset(this.getContext(), this.getFilesDir()); this.httpServer = new DelveHTTPD(8080, this.wwwRoot); } catch (Exception e) { e.toString(); } // Initialize activity super.init(); // Clear cache if you want super.appView.clearCache(true); super.appView.getSettings().setAllowFileAccess(true); super.appView.getSettings().setAllowContentAccess(true); super.setStringProperty("errorUrl", "file:///android_asset/www/error.html"); // if error loading // file in // super.loadUrl(). super.loadUrl("http://localhost:8080/"); // super.loadUrl("file:///android_asset/www/index.html"); // super.loadUrl("http://192.168.1.102/"); }
public JSONStringer generateDeviceJSON(Context context, boolean isFirst, String userAccount) { LocationUtils location = new LocationUtils(context); JSONStringer deviceJson = new JSONStringer(); try { deviceJson.object(); deviceJson.key("deviceid"); // deviceJson.value(getsDeviceIdSHA1()); deviceJson.value(getPseudoID()); deviceJson.key("useraccount"); deviceJson.value(userAccount); // /TODO deviceJson.key("devicename"); deviceJson.value(sDeviceManufacturer); deviceJson.key("devicetype"); deviceJson.value("1"); // 1手机 deviceJson.key("deviceos"); deviceJson.value(2000); // Android deviceJson.key("devicemac"); deviceJson.value(WLAN_MAC); deviceJson.key("devicephonenum"); deviceJson.value(TEL); deviceJson.key("deviceislock"); deviceJson.value(0); deviceJson.key("deviceisdel"); deviceJson.value(0); deviceJson.key("deviceinittime"); Date date = new Date(); deviceJson.value(date.getTime()); // TODO 日期格式 long型 deviceJson.key("devicevalidperiod"); deviceJson.value(365); // //TODO 暂定365天有效。服务器需要支持修改 deviceJson.key("deviceisillegal"); deviceJson.value(0); deviceJson.key("deviceisactive"); deviceJson.value(isFirst ? 1 : 0); // 第一台设备不做peer校验,直接注册 deviceJson.key("deviceislogout"); deviceJson.value(0); deviceJson.key("deviceeaster"); deviceJson.value(userAccount); deviceJson.key("bakstr1"); deviceJson.value(location.getLocation()); // TODO 目前是经度+空格+纬度 deviceJson.endObject(); Log.d(TAG, "JSON-----" + deviceJson.toString()); } catch (JSONException e) { e.printStackTrace(); } return deviceJson; }
/** * Report location updates to the UI. * * @param location The updated location. */ @Override public void onLocationChanged(Location location) { // Report to the UI that the location was updated mConnectionStatus.setText(R.string.location_updated); // In the UI, set the latitude and longitude to the value received mLatLng.setText(LocationUtils.getLatLng(this, location)); }
@Override public void run() { if (lastBestLocation == null) { lastBestLocation = LocationUtils.findMostAccurateLastKnownLocation(appContext); } // TODO addAndSendLocations(lastBestLocation,....); locationManager.removeUpdates(AlarmReciever.this); Log.d(TAG, "Location updates removed!"); }
@Override public void addLocation(Location loc) { if (LocationUtils.isUnknown(loc)) { return; } if (locations == null) { this.locations = new ArrayList(1); // Start small } locations.add(LocationImpl.get(loc)); }
/** * Standard way of building the message of a {@link LocatableException}, as a Java-like stack * trace of locations. * * @param message the exception's message, given by <code>super.getMessage()</code> (can be null) * @param locations the location list (can be null) * @return the message, or <code>null</code> no message and locations were given. */ public static String getMessage(String message, List locations) { if (locations == null || locations.isEmpty()) { return message; } // Produce a Java-like stacktrace with locations StringBuffer buf = message == null ? new StringBuffer() : new StringBuffer(message); for (int i = 0; i < locations.size(); i++) { buf.append("\n\tat ").append(LocationUtils.toString((Location) locations.get(i))); } return buf.toString(); }
/** * Invoked by the "Get Location" button. * * <p>Calls getLastLocation() to get the current location * * @param v The view object associated with this method, in this case a Button. */ public void getLocation(View v) { // If Google Play Services is available if (servicesConnected()) { // Get the current location Location currentLocation = mLocationClient.getLastLocation(); // Display the current location in the UI mLatLng.setText(LocationUtils.getLatLng(this, currentLocation)); } }
/** * Add to the location stack all locations of an exception chain. This allows to have all possible * location information in the stacktrace, as some exceptions like SAXParseException don't output * their location in printStackTrace(). * * <p>Traversal of the call chain stops at the first <code>Locatable</code> exception which is * supposed to handle the loction of its causes by itself. * * <p>This method is static as a convenience for {@link LocatedRuntimeException other * implementations} of locatable exceptions. * * @param self the current locatable exception * @param cause a cause of <code>self</code> */ public static void addCauseLocations(MultiLocatable self, Throwable cause) { if (cause == null || cause instanceof Locatable) { // Locatable handles its location itself return; } // Add parent location first addCauseLocations(self, cause.getCause()); // then ourselve's Location loc = LocationUtils.getLocation(cause); if (LocationUtils.isKnown(loc)) { // Get the exception's short name String name = cause.getClass().getName(); int pos = name.lastIndexOf('.'); if (pos != -1) { name = name.substring(pos + 1); } loc = new LocationImpl( "[" + name + "]", loc.getURI(), loc.getLineNumber(), loc.getColumnNumber()); self.addLocation(loc); } }
public void getLocation(View v) { if (serviceConnected()) { Location location = _locationClient.getLastLocation(); _textViewLatLng.setText(LocationUtils.getLatLong(this, location)); } }
// LocationListener @Override public void onLocationChanged(Location location) { _textViewConnectionStatus.setText(R.string.location_updated); _textViewLatLng.setText(LocationUtils.getLatLong(this, location)); }