diff --git a/app/build.gradle b/app/build.gradle index fbbb510..3bb2c0f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion "29.0.1" defaultConfig { applicationId "com.mobilecomputing.sahayak" - minSdkVersion 21 + minSdkVersion 24 targetSdkVersion 29 versionCode 1 versionName "1.0" diff --git a/app/src/main/java/com/mobilecomputing/sahayak/Activities/MentorOptionsActivity.java b/app/src/main/java/com/mobilecomputing/sahayak/Activities/MentorOptionsActivity.java index beb6128..563299e 100644 --- a/app/src/main/java/com/mobilecomputing/sahayak/Activities/MentorOptionsActivity.java +++ b/app/src/main/java/com/mobilecomputing/sahayak/Activities/MentorOptionsActivity.java @@ -1,5 +1,9 @@ package com.mobilecomputing.sahayak.Activities; +import android.app.DatePickerDialog; +import android.app.TimePickerDialog; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; import android.icu.util.Calendar; import android.os.Bundle; @@ -10,6 +14,8 @@ import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.DatePicker; +import android.widget.SeekBar; import android.widget.Spinner; import android.widget.TextView; @@ -17,6 +23,7 @@ import com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment; import androidx.appcompat.app.AppCompatActivity; +import com.mobilecomputing.sahayak.JavaClasses.CustomTimePickerDialog; import com.mobilecomputing.sahayak.JavaClasses.Proposal; import com.mobilecomputing.sahayak.JavaClasses.ProposalLab; import com.mobilecomputing.sahayak.R; @@ -24,18 +31,25 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; + +import android.widget.TimePicker; import android.widget.Toast; -public class MentorOptionsActivity extends AppCompatActivity implements CalendarDatePickerDialogFragment.OnDateSetListener, - RadialTimePickerDialogFragment.OnTimeSetListener { +import org.w3c.dom.Text; + +public class MentorOptionsActivity extends AppCompatActivity /*implements CalendarDatePickerDialogFragment.OnDateSetListener, + RadialTimePickerDialogFragment.OnTimeSetListener*/ { CalendarDatePickerDialogFragment calDatePicker; private static final String FRAG_TAG_DATE_PICKER = "fragment_date_picker_name"; private static final String FRAG_TAG_TIME_PICKER = "timePickerDialogFragment"; - private int year; - private int monthOfYear; - private int dayOfMonth; + private DatePickerDialog.OnDateSetListener dateSetListener; + private int year; + private int monthOfYear; + private int dayOfMonth; + private CustomTimePickerDialog.OnTimeSetListener timeSetListener; private int hourOfDay; private int minute; + private boolean is24HourView; private int flagDate; private int flagTime; @@ -57,9 +71,16 @@ protected void onCreate(Bundle savedInstanceState) { final TextView skillsMentor = (TextView) findViewById(R.id.skillsMentor); final ProposalLab proposalLab = ProposalLab.get(getApplicationContext()); -// Button setDate = (Button) findViewById(R.id.setDate); + Button setDate = (Button) findViewById(R.id.setDate); Button setTime = (Button) findViewById(R.id.setTime); - final Date date = new Date(); + Calendar c = Calendar.getInstance(); + year = c.get(Calendar.YEAR); + monthOfYear = c.get(Calendar.MONTH); + dayOfMonth = c.get(Calendar.DAY_OF_MONTH); + hourOfDay = c.get(Calendar.HOUR_OF_DAY) + 1; + minute = 0; + is24HourView = true; +// final Date date = new Date(); // setDate.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { @@ -71,38 +92,155 @@ protected void onCreate(Bundle savedInstanceState) { // cdp.show(getSupportFragmentManager(), FRAG_TAG_DATE_PICKER); // } // }); - setTime.setOnClickListener(new View.OnClickListener() { + + final TextView textViewDateTime = (TextView) findViewById(R.id.textViewDateTime); + + setDate.setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View view) { + Calendar c = Calendar.getInstance(); +// year = c.get(Calendar.YEAR); +// monthOfYear = c.get(Calendar.MONTH); +// dayOfMonth = c.get(Calendar.DAY_OF_MONTH); + + DatePickerDialog dialog = new DatePickerDialog( + MentorOptionsActivity.this, + android.R.style.Theme_Holo_Light_Dialog_MinWidth, + dateSetListener, + year, monthOfYear, dayOfMonth + ); + dialog.getDatePicker().setMinDate(c.getTime().getTime()); + c.add(Calendar.DATE, 7); + dialog.getDatePicker().setMaxDate(c.getTime().getTime()); + dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + dialog.show(); + } + }); + + dateSetListener = new DatePickerDialog.OnDateSetListener() { + @Override + public void onDateSet(DatePicker datePicker, int i, int i1, int i2) { + year = i; + monthOfYear = i1; + dayOfMonth = i2; + flagDate = 1; + textViewDateTime.setText(dateAndTime()); + } + }; + +// setTime.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// RadialTimePickerDialogFragment rtpd = new RadialTimePickerDialogFragment() +// .setOnTimeSetListener(MentorOptionsActivity.this) +// .setDoneText("Done") +// .setCancelText("Cancel"); +// rtpd.show(getSupportFragmentManager(), FRAG_TAG_TIME_PICKER); +// } +// }); + + setTime.setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View view) { + Calendar c = Calendar.getInstance(); +// c.add(Calendar.HOUR_OF_DAY, 1); +// hourOfDay = c.get(Calendar.HOUR_OF_DAY); +// minute = 0; + + CustomTimePickerDialog dialog = new CustomTimePickerDialog( + MentorOptionsActivity.this, + android.R.style.Theme_Holo_Light_Dialog_MinWidth, + timeSetListener, + hourOfDay, minute, is24HourView + ); + dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + dialog.show(); + } + }); + + timeSetListener = new CustomTimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker timePicker, int i, int i1) { + hourOfDay = i; + minute = i1; + flagTime = 1; + textViewDateTime.setText(dateAndTime()); + } + }; + + textViewDateTime.setText(dateAndTime()); + +// final Spinner spinnerMinutes = (Spinner) findViewById(R.id.selectMinutes2); +// List minutes = new ArrayList(); +// minutes.add("15"); +// minutes.add("30"); +// minutes.add("45"); +// minutes.add("60"); +// minutes.add("75"); + + final SeekBar seekBarSessionTime = (SeekBar) findViewById(R.id.seekBarSessionTime); + final TextView textViewSessionTime = (TextView) findViewById(R.id.textViewSessionTime); + textViewSessionTime.setText(quartersToHHMM(seekBarSessionTime.getProgress())); + + final SeekBar seekBarTimeCap = (SeekBar) findViewById(R.id.seekBarTimeCap); + seekBarTimeCap.setMax(seekBarSessionTime.getProgress()); + seekBarTimeCap.setProgress(seekBarTimeCap.getMax()); + final TextView textViewTimeCap = (TextView) findViewById(R.id.textViewTimeCap); + textViewTimeCap.setText(quartersToHHMM(seekBarTimeCap.getProgress())); + + seekBarSessionTime.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override - public void onClick(View v) { - RadialTimePickerDialogFragment rtpd = new RadialTimePickerDialogFragment() - .setOnTimeSetListener(MentorOptionsActivity.this) - .setDoneText("Done") - .setCancelText("Cancel"); - rtpd.show(getSupportFragmentManager(), FRAG_TAG_TIME_PICKER); + public void onProgressChanged(SeekBar seekBar, int i, boolean b) { + String sessionTime = quartersToHHMM(i); + textViewSessionTime.setText(sessionTime); + + seekBarTimeCap.setMax(seekBarSessionTime.getProgress()); + seekBarTimeCap.setProgress(Math.min(seekBarTimeCap.getProgress(), seekBarTimeCap.getMax())); + textViewTimeCap.setText(quartersToHHMM(seekBarTimeCap.getProgress())); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } }); - final Spinner spinnerMinutes = (Spinner) findViewById(R.id.selectMinutes2); - List minutes = new ArrayList(); - minutes.add("15"); - minutes.add("30"); - minutes.add("45"); - minutes.add("60"); - minutes.add("75"); +// final ArrayAdapter minutesadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, minutes); +// spinnerMinutes.setAdapter(minutesadapter); - final ArrayAdapter minutesadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, minutes); - spinnerMinutes.setAdapter(minutesadapter); +// final Spinner spinnerMinutes2 = (Spinner) findViewById(R.id.selectMinutes); +// List minutes2 = new ArrayList(); +// minutes2.add("15"); +// minutes2.add("30"); +// minutes2.add("45"); +// minutes2.add("60"); +// minutes2.add("75"); - final Spinner spinnerMinutes2 = (Spinner) findViewById(R.id.selectMinutes); - List minutes2 = new ArrayList(); - minutes2.add("15"); - minutes2.add("30"); - minutes2.add("45"); - minutes2.add("60"); - minutes2.add("75"); + seekBarTimeCap.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int i, boolean b) { + String timeCap = quartersToHHMM(i); + textViewTimeCap.setText(timeCap); + } - final ArrayAdapter minutesadapter2 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, minutes2); - spinnerMinutes2.setAdapter(minutesadapter); + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }); + +// final ArrayAdapter minutesadapter2 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, minutes2); +// spinnerMinutes2.setAdapter(minutesadapter); Button addButton = (Button) findViewById(R.id.addButton); addButton.setOnClickListener(new View.OnClickListener() { @@ -112,8 +250,10 @@ public void onClick(View view) { if(flagTime==1) { String sSkillsMentor = skillsMentor.getText().toString(); String sCategoryMentor = spinner.getSelectedItem().toString(); - Integer endtime = Integer.parseInt(spinnerMinutes.getSelectedItem().toString()); - Integer timeCap = Integer.parseInt(spinnerMinutes2.getSelectedItem().toString()); +// Integer endtime = Integer.parseInt(spinnerMinutes.getSelectedItem().toString()); + Integer endtime = seekBarSessionTime.getProgress() * 15; +// Integer timeCap = Integer.parseInt(spinnerMinutes2.getSelectedItem().toString()); + Integer timeCap = seekBarTimeCap.getProgress() * 15; Integer endtimeHour = hourOfDay + endtime/60+ (minute + endtime)/60; Integer endtimeMinute = (minute + endtime)%60; Proposal proposal = new Proposal(proposalLab.getProposals().size(), sSkillsMentor); @@ -133,21 +273,54 @@ public void onClick(View view) { } - @Override - public void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear, int dayOfMonth) { - this.year=year; - this.monthOfYear=monthOfYear; - this.dayOfMonth=dayOfMonth; - flagDate=1; - - + private String dateAndTime() + { + String dt = ""; + dt += year + "/"; + if(monthOfYear < 10) + dt += "0"; + dt += monthOfYear + "/"; + if(dayOfMonth < 10) + dt += "0"; + dt += dayOfMonth + " "; + if(hourOfDay < 10) + dt += "0"; + dt += hourOfDay + ":"; + if(minute < 10) + dt += 0; + dt += minute; + return dt; } - @Override - public void onTimeSet(RadialTimePickerDialogFragment dialog, int hourOfDay, int minute) { - this.hourOfDay=hourOfDay; - this.minute=minute; - flagTime=1; + private String quartersToHHMM(int i) + { + int hours = i / 4; + int minutes = i % 4 * 15; + String hhmm = ""; + if(hours < 10) + hhmm += "0"; + hhmm += hours + ":"; + if(minutes < 10) + hhmm += "0"; + hhmm += minutes; + return hhmm; } +// @Override +// public void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear, int dayOfMonth) { +// this.year=year; +// this.monthOfYear=monthOfYear; +// this.dayOfMonth=dayOfMonth; +// flagDate=1; +// +// +// } +// @Override +// public void onTimeSet(RadialTimePickerDialogFragment dialog, int hourOfDay, int minute) { +// this.hourOfDay=hourOfDay; +// this.minute=minute; +// flagTime=1; +// +// } + } diff --git a/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/CustomTimePickerDialog.java b/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/CustomTimePickerDialog.java new file mode 100644 index 0000000..0947edb --- /dev/null +++ b/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/CustomTimePickerDialog.java @@ -0,0 +1,70 @@ +package com.mobilecomputing.sahayak.JavaClasses; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import android.app.TimePickerDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.widget.NumberPicker; +import android.widget.TimePicker; + +public class CustomTimePickerDialog extends TimePickerDialog { + + private final static int TIME_PICKER_INTERVAL = 15; + private TimePicker mTimePicker; + private final OnTimeSetListener mTimeSetListener; + + public CustomTimePickerDialog(Context context, int themeResId, OnTimeSetListener listener, + int hourOfDay, int minute, boolean is24HourView) { + super(context, themeResId, null, hourOfDay, + minute / TIME_PICKER_INTERVAL, is24HourView); + mTimeSetListener = listener; + } + + @Override + public void updateTime(int hourOfDay, int minuteOfHour) { + mTimePicker.setCurrentHour(hourOfDay); + mTimePicker.setCurrentMinute(minuteOfHour / TIME_PICKER_INTERVAL); + } + + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case BUTTON_POSITIVE: + if (mTimeSetListener != null) { + mTimeSetListener.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(), + mTimePicker.getCurrentMinute() * TIME_PICKER_INTERVAL); + } + break; + case BUTTON_NEGATIVE: + cancel(); + break; + } + } + + @Override + public void onAttachedToWindow() { + super.onAttachedToWindow(); + try { + Class classForid = Class.forName("com.android.internal.R$id"); + Field timePickerField = classForid.getField("timePicker"); + mTimePicker = (TimePicker) findViewById(timePickerField.getInt(null)); + Field field = classForid.getField("minute"); + + NumberPicker minuteSpinner = (NumberPicker) mTimePicker + .findViewById(field.getInt(null)); + minuteSpinner.setMinValue(0); + minuteSpinner.setMaxValue((60 / TIME_PICKER_INTERVAL) - 1); + List displayedValues = new ArrayList<>(); + for (int i = 0; i < 60; i += TIME_PICKER_INTERVAL) { + displayedValues.add(String.format("%02d", i)); + } + minuteSpinner.setDisplayedValues(displayedValues + .toArray(new String[displayedValues.size()])); + } catch (Exception e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_date_range_black_24dp.xml b/app/src/main/res/drawable/ic_date_range_black_24dp.xml new file mode 100644 index 0000000..165c6af --- /dev/null +++ b/app/src/main/res/drawable/ic_date_range_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/onboarding1.png b/app/src/main/res/drawable/onboarding1.png old mode 100755 new mode 100644 diff --git a/app/src/main/res/drawable/onboarding2.png b/app/src/main/res/drawable/onboarding2.png old mode 100755 new mode 100644 diff --git a/app/src/main/res/drawable/onboarding3.png b/app/src/main/res/drawable/onboarding3.png old mode 100755 new mode 100644 diff --git a/app/src/main/res/layout/activity_mentor_options.xml b/app/src/main/res/layout/activity_mentor_options.xml index 03fbc6b..52ee167 100644 --- a/app/src/main/res/layout/activity_mentor_options.xml +++ b/app/src/main/res/layout/activity_mentor_options.xml @@ -12,108 +12,153 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - - - - - - - - - - - - - - - - - - - -