use of net.osmand.plus.plugins.osmedit.fragments.BasicEditPoiFragment in project Osmand by osmandapp.
the class OpeningHoursHoursDialogFragment method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle args = getArguments();
final boolean isStart = args.getBoolean(IS_START);
final OpeningHoursParser.BasicOpeningHourRule item = (OpeningHoursParser.BasicOpeningHourRule) args.getSerializable(BASIC_OPENING_HOUR_RULE);
final int rulePosition = args.getInt(RULE_POSITION);
final int timePosition = args.getInt(TIME_POSITION);
final boolean newTimeSpan = timePosition == item.timesSize();
final boolean createNew = rulePosition == -1 || newTimeSpan;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
int time;
if (isStart) {
time = newTimeSpan ? DEFAULT_START_TIME : item.getStartTime(timePosition);
} else {
time = newTimeSpan ? DEFAULT_END_TIME : item.getEndTime(timePosition);
}
int hour = time / 60;
int minute = time - hour * 60;
final TimePicker timePicker = new TimePicker(getActivity());
timePicker.setIs24HourView(DateFormat.is24HourFormat(getActivity()));
timePicker.setCurrentHour(hour);
timePicker.setCurrentMinute(minute);
builder.setView(timePicker).setPositiveButton(isStart && createNew ? R.string.next_proceed : R.string.shared_string_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
timePicker.clearFocus();
int minute = timePicker.getCurrentMinute();
int hourOfDay = timePicker.getCurrentHour();
int time = minute + hourOfDay * 60;
if (newTimeSpan) {
item.addTimeRange(DEFAULT_START_TIME, DEFAULT_END_TIME);
}
if (isStart && createNew) {
item.setStartTime(time, timePosition);
OpeningHoursHoursDialogFragment.createInstance(item, rulePosition, false, timePosition).show(getFragmentManager(), "TimePickerDialogFragment");
} else {
if (isStart) {
item.setStartTime(time, timePosition);
} else {
item.setEndTime(time, timePosition);
}
((BasicEditPoiFragment) getParentFragment()).setBasicOpeningHoursRule(item, rulePosition);
}
}
}).setNegativeButton(R.string.shared_string_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
BasicEditPoiFragment editPoiFragment = ((BasicEditPoiFragment) getParentFragment());
if (editPoiFragment != null) {
editPoiFragment.removeUnsavedOpeningHours();
}
}
});
int paddingInDp = 18;
float density = getActivity().getResources().getDisplayMetrics().density;
int paddingInPx = (int) (paddingInDp * density);
final TypedValue textColorTypedValue = new TypedValue();
getActivity().getTheme().resolveAttribute(android.R.attr.textColorPrimary, textColorTypedValue, true);
int textColor = textColorTypedValue.data;
TextView titleTextView = new TextView(getActivity());
titleTextView.setText(isStart ? getActivity().getString(R.string.opening_at) : getActivity().getString(R.string.closing_at));
titleTextView.setPadding(paddingInPx, paddingInPx, paddingInPx, paddingInPx);
titleTextView.setGravity(Gravity.CENTER_VERTICAL);
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
titleTextView.setTextColor(textColor);
Typeface typeface = titleTextView.getTypeface();
titleTextView.setTypeface(typeface, Typeface.BOLD);
builder.setCustomTitle(titleTextView);
return builder.create();
}
Aggregations