@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(); } }