@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_places); // Get and set the toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.places_toolbar); toolbar.setNavigationIcon(R.drawable.ic_back_white_24dp); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayShowHomeEnabled(true); } mProgress = (ProgressBar) findViewById(R.id.places_progress); mList = (ListView) findViewById(R.id.places_list); // Create the name dialog. This needs to be done only once mName = new EditText(this); mName.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mName.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); mNameDialog = new AlertDialog.Builder(this) .setTitle(R.string.places_name_dialog_title) .setView(mName) .setNegativeButton(R.string.places_name_dialog_cancel, null) .setPositiveButton(R.string.places_name_dialog_accept, null) .create(); mNameDialog.setOnShowListener(this); // Load the primary places HttpRequest.get(this, API.URL.getPrimaryPlaces()); }
@Override protected void onDialogClosed(boolean positiveResult) { if (positiveResult) { persistInt(mValue); User user = ((CompassApplication) getContext().getApplicationContext()).getUser(); user.setDailyNotifications(mValue); HttpRequest.put(null, API.URL.putUserProfile(user), API.BODY.putUserProfile(user)); } else { mValue = parsePreference(getKey(), getContext()); } }
@Override public void onClick(View view) { String name = mName.getText().toString().trim(); // If the user didn't input a name, don't let him continue if (name.equals("")) { Toast.makeText(this, R.string.places_name_dialog_empty, Toast.LENGTH_SHORT).show(); } else { // Check if the name is already set boolean duplicate = false; for (UserPlace userPlace : mAdapter.getPlaces()) { if (userPlace.getName().equals(name)) { duplicate = true; break; } } // If the name exists, don't let the user continue if (duplicate) { Toast.makeText(this, R.string.places_name_dialog_chosen, Toast.LENGTH_SHORT).show(); } else { // If everything checks out, dismiss the dialog mNameDialog.dismiss(); // If we are editing the name, then save it if (mEdition) { mCurrentPlace.getPlace().setName(mName.getText().toString().trim()); mAdapter.notifyDataSetChanged(); HttpRequest.put( null, API.URL.postPutPlace(mCurrentPlace), API.BODY.postPutPlace(mCurrentPlace)); // Update the place in the database PlaceTableHandler handler = new PlaceTableHandler(this); handler.updatePlace(mCurrentPlace); handler.close(); } // Otherwise this is a new place request, fire the place picker else { Intent add = new Intent(this, PlacePickerActivity.class); add.putExtra(PlacePickerActivity.PLACE_KEY, new UserPlace(name)); startActivityForResult(add, PLACE_PICKER_REQUEST_CODE); } } } }
/** * Snoozes a notification time-wise. * * @param year the year to snooze to. * @param month the month to snooze to. * @param day the day to snooze to. * @param hour the hour to snooze to. * @param minute the minute to snooze to. */ private void snooze(int year, int month, int day, int hour, int minute) { // Translate to strings String monthString = month + ""; String dayString = day + ""; String hourString = hour + ""; String minuteString = minute + ""; // Process the data if (monthString.length() == 1) { monthString = "0" + monthString; } if (dayString.length() == 1) { dayString = "0" + dayString; } if (hourString.length() == 1) { hourString = "0" + hourString; } if (minuteString.length() == 1) { minuteString = "0" + minuteString; } // Prepare the strings String date = year + "-" + monthString + "-" + dayString; String time = hourString + ":" + minuteString; // Log the data to verify format Log.i(TAG, "Notification snoozed to " + date + " " + time); HttpRequest.put(null, API.URL.putSnooze(mGcmMessage.getId()), API.BODY.putSnooze(date, time)); cancelNotification(); // Kill the activity setResult(RESULT_OK); Toast.makeText(this, R.string.later_toast, Toast.LENGTH_SHORT).show(); finish(); }