Skip to content

Commit

Permalink
Reservation form
Browse files Browse the repository at this point in the history
No validation yet, restaurants are still static.
  • Loading branch information
dvdmunckhof committed Mar 19, 2015
1 parent 4cd91e9 commit 65ae151
Show file tree
Hide file tree
Showing 76 changed files with 1,204 additions and 14 deletions.
27 changes: 27 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
</component>
</module>

10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
compileSdkVersion 22
buildToolsVersion "22"

defaultConfig {
applicationId "edu.avans.hartigehap.a1"
minSdkVersion 15
targetSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
versionName "0.1-alpha1"
}
buildTypes {
release {
Expand All @@ -21,5 +21,5 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:appcompat-v7:22.0.0'
}
19 changes: 15 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.avans.hartigehap.a1">
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="edu.avans.hartigehap.a1" >

<application android:allowBackup="true" android:label="@string/app_name"
android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

<activity
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

Expand Down
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 app/src/main/java/edu/avans/hartigehap/a1/MainActivity.java
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 app/src/main/java/edu/avans/hartigehap/a1/MainFragment.java
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);
}
}
Loading

0 comments on commit 65ae151

Please sign in to comment.