public void addTimer() { long timeOn = mTimeOnDate.getTime(); // time in milliseconds long timeOff = mTimeOffDate.getTime(); // time in milliseconds long duration = timeOff - timeOn; if (duration < 0) { duration += 86400000; // milliseconds per day } long now = new Date().getTime(); long timeFromNow = timeOn - now; if (timeFromNow < 0) { timeFromNow += 86400000; } String url = "http://" + mHardwareUnit.getBasePath() + ":" + mHardwareUnit.getPortNumber() + "/hack/setTimer?socket=" + mDevice.getSocketId() + "&timeFromNow=" + timeFromNow + "&duration=" + duration + "&isRepeated=" + mIsRepeatedCheckBox.isChecked(); HackCommand setTimerCommand = new HackCommand(SetTimerActivity.this, mHardwareUnit, url) { @Override public void doSuccess(JSONObject response) { super.doSuccess(response); long timerId = mTimerDataSource.addTimer( mDeviceId, mTimeOnDate.getTime(), mTimeOffDate.getTime(), mIsRepeatedCheckBox.isChecked()); startDeviceDetailsActivity(); } }; setTimerCommand.send(); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // This ID represents the Home or Up button. In the case of this // activity, the Up button is shown. Use NavUtils to allow users // to navigate up one level in the application structure. For // more details, see the Navigation pattern on Android Design: // // http://developer.android.com/design/patterns/navigation.html#up-vs-back // Intent upIntent = NavUtils.getParentActivityIntent(this); upIntent.putExtra(SingleUnitActivity.EXTRA_DEVICE_ID, mDeviceId); upIntent.putExtra(SingleUnitActivity.EXTRA_HARDWARE_UNIT_ID, mHardwareUnit.getId()); NavUtils.navigateUpTo(this, upIntent); return true; } return super.onOptionsItemSelected(item); }
public void startDeviceDetailsActivity() { Intent intent = new Intent(this, DeviceDetailsActivity.class); intent.putExtra(SingleUnitActivity.EXTRA_DEVICE_ID, mDeviceId); intent.putExtra(SingleUnitActivity.EXTRA_HARDWARE_UNIT_ID, mHardwareUnit.getId()); startActivity(intent); }