-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No validation yet, restaurants are still static.
- Loading branch information
1 parent
4cd91e9
commit 65ae151
Showing
76 changed files
with
1,204 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
app/src/main/java/edu/avans/hartigehap/a1/BetterTimePickerDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package edu.avans.hartigehap.a1; | ||
|
||
import android.app.TimePickerDialog; | ||
import android.content.Context; | ||
import android.widget.TimePicker; | ||
|
||
import java.lang.reflect.Field; | ||
import java.text.DateFormat; | ||
import java.util.Calendar; | ||
|
||
public class BetterTimePickerDialog extends TimePickerDialog { | ||
private int minHour = -1, minMinute = -1, maxHour = 24, maxMinute = 60; | ||
private int currentHour, currentMinute; | ||
|
||
private Calendar calendar = Calendar.getInstance(); | ||
private DateFormat dateFormat; | ||
|
||
public BetterTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { | ||
super(context, callBack, hourOfDay, minute, is24HourView); | ||
|
||
currentHour = hourOfDay; | ||
currentMinute = minute; | ||
dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); | ||
|
||
try { | ||
Class<?> superclass = getClass().getSuperclass(); | ||
Field mTimePickerField = superclass.getDeclaredField("mTimePicker"); | ||
mTimePickerField.setAccessible(true); | ||
TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); | ||
mTimePicker.setOnTimeChangedListener(this); | ||
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ignored) { | ||
} | ||
} | ||
|
||
public void setMin(int hour, int minute) { | ||
minHour = hour; | ||
minMinute = minute; | ||
} | ||
|
||
public void setMax(int hour, int minute) { | ||
maxHour = hour; | ||
maxMinute = minute; | ||
} | ||
|
||
@Override | ||
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { | ||
//super.onTimeChanged(view, hourOfDay, minute); | ||
|
||
boolean validTime = true; | ||
if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ | ||
validTime = false; | ||
} | ||
|
||
if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ | ||
validTime = false; | ||
} | ||
|
||
if(validTime) { | ||
currentHour = hourOfDay; | ||
currentMinute = minute; | ||
} | ||
else { | ||
updateTime(currentHour, currentMinute); | ||
} | ||
updateTime(currentHour, currentMinute); | ||
updateDialogTitle(view, currentHour, currentMinute); | ||
} | ||
|
||
private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { | ||
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); | ||
calendar.set(Calendar.MINUTE, minute); | ||
String title = dateFormat.format(calendar.getTime()); | ||
setTitle(title); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/edu/avans/hartigehap/a1/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package edu.avans.hartigehap.a1; | ||
|
||
import android.support.v7.app.ActionBarActivity; | ||
import android.os.Bundle; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
|
||
|
||
public class MainActivity extends ActionBarActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
if (savedInstanceState == null) { | ||
getSupportFragmentManager().beginTransaction().add(R.id.container, new MainFragment()).commit(); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
getMenuInflater().inflate(R.menu.menu_main, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
// Handle action bar item clicks here. The action bar will | ||
// automatically handle clicks on the Home/Up button, so long | ||
// as you specify a parent activity in AndroidManifest.xml. | ||
int id = item.getItemId(); | ||
|
||
//noinspection SimplifiableIfStatement | ||
if (id == R.id.action_settings) { | ||
return true; | ||
} | ||
|
||
return super.onOptionsItemSelected(item); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
app/src/main/java/edu/avans/hartigehap/a1/MainFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package edu.avans.hartigehap.a1; | ||
|
||
import android.app.Activity; | ||
import android.app.DatePickerDialog; | ||
import android.support.v4.app.Fragment; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.inputmethod.InputMethodManager; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.DatePicker; | ||
import android.widget.EditText; | ||
import android.widget.Spinner; | ||
|
||
import java.text.Format; | ||
import java.util.Calendar; | ||
|
||
import edu.avans.hartigehap.a1.timepicker.TimePickerDialog; | ||
|
||
/** | ||
* A simple {@link Fragment} subclass. | ||
*/ | ||
public class MainFragment extends Fragment implements View.OnClickListener { | ||
private Format dateFormat; | ||
|
||
private EditText editTextDate; | ||
private EditText editTextTimeStart; | ||
private EditText editTextTimeEnd; | ||
|
||
DatePickerDialog datePickerDialog; | ||
TimePickerDialog timePickerDialog; | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
View rootView = inflater.inflate(R.layout.fragment_main, container, false); | ||
rootView.requestFocus(); | ||
dateFormat = android.text.format.DateFormat.getLongDateFormat(getActivity()); | ||
|
||
Spinner spinner = (Spinner) rootView.findViewById(R.id.form_restaurant); | ||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this.getActivity(), R.array.form_restaurants, R.layout.spinner_item); | ||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | ||
spinner.setAdapter(adapter); | ||
|
||
editTextDate = (EditText) rootView.findViewById(R.id.form_date); | ||
editTextDate.setOnClickListener(this); | ||
editTextTimeStart = (EditText) rootView.findViewById(R.id.form_time_start); | ||
editTextTimeStart.setOnClickListener(this); | ||
editTextTimeEnd = (EditText) rootView.findViewById(R.id.form_time_end); | ||
editTextTimeEnd.setOnClickListener(this); | ||
|
||
setupPickers(); | ||
|
||
return rootView; | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
int id = v.getId(); | ||
hideSoftKeyboard(); | ||
|
||
switch (id) { | ||
case R.id.form_date: | ||
datePickerDialog.show(); | ||
break; | ||
case R.id.form_time_start: | ||
case R.id.form_time_end: | ||
timePickerDialog.show(); | ||
break; | ||
} | ||
} | ||
|
||
public void hideSoftKeyboard() { | ||
InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); | ||
inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0); | ||
} | ||
|
||
private void setupPickers() { | ||
final Calendar calendar = Calendar.getInstance(); | ||
|
||
// Date picker | ||
DatePickerDialog.OnDateSetListener dateListener = new DatePickerDialog.OnDateSetListener() { | ||
@Override | ||
public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) { | ||
calendar.set(year, monthOfYear, dayOfMonth); | ||
editTextDate.setText(dateFormat.format(calendar.getTime())); | ||
} | ||
}; | ||
datePickerDialog = new DatePickerDialog(getActivity(), dateListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); | ||
datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis()); | ||
|
||
final String timeFormat = getString(R.string.time_format); | ||
TimePickerDialog.TimeChangedListener listener = new TimePickerDialog.TimeChangedListener() { | ||
@Override | ||
public void onTimeChanged(int hourStart, int minuteStart, int hourEnd, int minuteEnd) { | ||
editTextTimeStart.setText(String.format(timeFormat, hourStart, minuteStart)); | ||
editTextTimeEnd.setText(String.format(timeFormat, hourEnd, minuteEnd)); | ||
} | ||
}; | ||
timePickerDialog = new TimePickerDialog(getActivity(), listener); | ||
} | ||
} |
Oops, something went wrong.