@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_stop); if (savedInstanceState == null) { getFragmentManager() .beginTransaction() .add(R.id.container, new PlaceholderFragment()) .commit(); } MobileDevice myDevice = new MobileDevice(); this.dayOfWeek = myDevice.getWeekday(); this.deviceMinutes = myDevice.getAllMinutes(); // NOTE that the fileName is the stopNumber in a .txt file. Eg. 3852.txt File myFile = getApplicationContext().getFileStreamPath(stopNumber + ".txt"); // delete the file for testing purposes // myFile.delete(); // if the file exists we can read the times from the device itself if (!myFile.exists()) { // Set up BusStop and Activity UI new setDataFromInternet().execute(); } else { setDataFromPhone(myFile); } }
public void setDataFromPhone(File myFile) { try { FileReader fileReader = new FileReader(myFile); BufferedReader bufferedReader = new BufferedReader(fileReader); stopText = (TextView) findViewById(R.id.show_title); stopText.setText(bufferedReader.readLine().substring(0, 4)); inboundText = (TextView) findViewById(R.id.inbound); inboundText.setText(bufferedReader.readLine()); outboundText = (TextView) findViewById(R.id.outbound); outboundText.setText(bufferedReader.readLine()); test = (TextView) findViewById(R.id.page_source); MobileDevice myDevice = new MobileDevice(); test.setText(myDevice.getWeekday() + " " + deviceMinutes); test.append("\n" + bufferedReader.readLine()); String outBoundLine = bufferedReader.readLine(); test.append("\n" + outBoundLine); test.append("\nRead from phone."); test.append("\nNextTime: " + minutesToTime(nextTime(stringLineToArray(outBoundLine)))); test.append("\n752 = " + minutesToTime(752)); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
public MobileDevice create(MobileDevice device) { MapSqlParameterSource params = new MapSqlParameterSource(toParams(device)); KeyHolder keyHolder = new GeneratedKeyHolder(); externalDwNamedJdbcTemplate.update(INSERT_NEW_DEVICE, params, keyHolder); Long rowId = (Long) keyHolder.getKeys().get("id"); return MobileDevice.builder(device).withId(rowId).build(); }
private Map<String, Object> toParams(MobileDevice device) { return buildParams( "id", device.getId(), "playerId", device.getPlayerId(), "gameType", device.getGameType(), "platform", device.getPlatform().name(), "appId", device.getAppId(), "deviceId", device.getDeviceId(), "pushToken", device.getPushToken(), "active", device.isActive()); }
public static MobileDevice convertToMobileDevice(Device device) { MobileDevice mobileDevice = null; if (device != null) { mobileDevice = new MobileDevice(); mobileDevice.setMobileDeviceId(device.getDeviceIdentifier()); mobileDevice.setImei(getPropertyValue(device, MOBILE_DEVICE_IMEI)); mobileDevice.setImsi(getPropertyValue(device, MOBILE_DEVICE_IMSI)); mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL)); mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION)); mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR)); mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE)); mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE)); mobileDevice.setSerial(getPropertyValue(device, MOBILE_DEVICE_SERIAL)); mobileDevice.setOsBuildDate(getPropertyValue(device, MOBILE_DEVICE_OS_BUILD_DATE)); if (device.getProperties() != null) { Map<String, String> deviceProperties = new HashMap<String, String>(); for (Device.Property deviceProperty : device.getProperties()) { deviceProperties.put(deviceProperty.getName(), deviceProperty.getValue()); } mobileDevice.setDeviceProperties(deviceProperties); } else { mobileDevice.setDeviceProperties(new HashMap<String, String>()); } } return mobileDevice; }
public static Device convertToDevice(MobileDevice mobileDevice) { Device device = null; if (mobileDevice != null) { device = new Device(); List<Device.Property> propertyList = new ArrayList<Device.Property>(); propertyList.add(getProperty(MOBILE_DEVICE_IMEI, mobileDevice.getImei())); propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi())); propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel())); propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion())); propertyList.add(getProperty(MOBILE_DEVICE_OS_BUILD_DATE, mobileDevice.getOsBuildDate())); propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor())); if (mobileDevice.getLatitude() != null) { propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude())); } if (mobileDevice.getLongitude() != null) { propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude())); } propertyList.add(getProperty(MOBILE_DEVICE_SERIAL, mobileDevice.getSerial())); if (mobileDevice.getDeviceProperties() != null) { for (Map.Entry<String, String> deviceProperty : mobileDevice.getDeviceProperties().entrySet()) { propertyList.add(getProperty(deviceProperty.getKey(), deviceProperty.getValue())); } } device.setProperties(propertyList); device.setDeviceIdentifier(mobileDevice.getMobileDeviceId()); } return device; }