Search in sources :

Example 1 with MainActivity

use of kogvet.eye.MainActivity in project Eye by tommyolsson.

the class FragmentCreateEvent method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View inf = inflater.inflate(R.layout.fragment_create_event, container, false);
    // Changes title to the subject name
    ((MainActivity) getActivity()).setActionBarTitle(getResources().getString(R.string.newActivity));
    ((MainActivity) getActivity()).showBackButton();
    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    subjectEditText = (EditText) inf.findViewById(R.id.subjectEditText);
    locationEditText = (EditText) inf.findViewById(R.id.locationEditText);
    dateEditText = (EditText) inf.findViewById(R.id.dateEditText);
    startEditText = (EditText) inf.findViewById(R.id.startEditText);
    endEditText = (EditText) inf.findViewById(R.id.endEditText);
    dateEditText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // To show current date in the datepicker
            final Calendar mCalendar = Calendar.getInstance();
            int mYear = mCalendar.get(Calendar.YEAR);
            int mMonth = mCalendar.get(Calendar.MONTH);
            int mDay = mCalendar.get(Calendar.DAY_OF_MONTH);
            DatePickerDialog mDatePicker = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {

                public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
                    // TODO Auto-generated method stub
                    /*  Set picked date in textedit  */
                    String myFormat = "yyyy-MM-dd";
                    SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.getDefault());
                    mCalendar.set(Calendar.YEAR, selectedyear);
                    mCalendar.set(Calendar.MONTH, selectedmonth);
                    mCalendar.set(Calendar.DAY_OF_MONTH, selectedday);
                    dateEditText.setText(sdf.format(mCalendar.getTime()));
                }
            }, mYear, mMonth, mDay);
            mDatePicker.getDatePicker().setCalendarViewShown(false);
            mDatePicker.setTitle("Select date");
            mDatePicker.show();
        }
    });
    startEditText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Calendar mcurrentTime = Calendar.getInstance();
            int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
            int minute = mcurrentTime.get(Calendar.MINUTE);
            TimePickerDialog mTimePicker;
            mTimePicker = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                    startEditText.setText(String.format("%02d:%02d", selectedHour, selectedMinute));
                }
            }, hour, minute, // Yes 24 hour time
            true);
            mTimePicker.setTitle("Select Time");
            mTimePicker.show();
        }
    });
    endEditText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Calendar mcurrentTime = Calendar.getInstance();
            int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
            int minute = mcurrentTime.get(Calendar.MINUTE);
            TimePickerDialog mTimePicker;
            mTimePicker = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                    endEditText.setText(String.format("%02d:%02d", selectedHour, selectedMinute));
                }
            }, hour, minute, // Yes 24 hour time
            true);
            mTimePicker.setTitle("Select Time");
            mTimePicker.show();
        }
    });
    checkBox = inf.findViewById(R.id.checkBox);
    checkBox.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (((CheckBox) v).isChecked()) {
                // Disables editText for time if event is all day
                startEditText.setEnabled(false);
                endEditText.setEnabled(false);
                isAllDay = true;
            } else {
                startEditText.setEnabled(true);
                endEditText.setEnabled(true);
                isAllDay = false;
            }
        }
    });
    createButton = inf.findViewById(R.id.createButton);
    createButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String subject = subjectEditText.getText().toString();
            String location = locationEditText.getText().toString();
            String date = dateEditText.getText().toString();
            String start = startEditText.getText().toString();
            String end = endEditText.getText().toString();
            Log.i("Ämne", subject);
            Log.i("Plats", location);
            Log.i("Datum", date);
            Log.i("Start", start);
            Log.i("Slut", end);
            Log.i("Heldag", Boolean.toString(isAllDay));
            if (subject.matches("")) {
                Toast.makeText(getContext(), "Namn på aktivitet saknas", Toast.LENGTH_SHORT).show();
            } else {
                if (isAllDay) {
                    LocalDate ld = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                    String endDate = ld.plusDays(1).toString();
                    ((MainActivity) getActivity()).createEventGraphAPI(subject, location, date, endDate, "00", "00", isAllDay);
                } else {
                    ((MainActivity) getActivity()).createEventGraphAPI(subject, location, date, date, start, end, isAllDay);
                }
                Toast.makeText(getContext(), "Aktivitet skapad", Toast.LENGTH_SHORT).show();
                getActivity().onBackPressed();
            }
        }
    });
    return inf;
}
Also used : TimePicker(android.widget.TimePicker) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) MainActivity(kogvet.eye.MainActivity) View(android.view.View) LocalDate(org.threeten.bp.LocalDate) DatePicker(android.widget.DatePicker) SimpleDateFormat(java.text.SimpleDateFormat) Nullable(android.support.annotation.Nullable)

Example 2 with MainActivity

use of kogvet.eye.MainActivity in project Eye by tommyolsson.

the class FragmentOpenEvent method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View inf = inflater.inflate(R.layout.fragment_open_event, container, false);
    setText(inf);
    // Changes title to the subject name
    ((MainActivity) getActivity()).setActionBarTitle(event.getSubject());
    ((MainActivity) getActivity()).showBackButton();
    // Buttons
    checkBox = inf.findViewById(R.id.checkBox);
    showBox();
    checkBox.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String id = event.getId();
            String url = "https://graph.microsoft.com/beta/me/events/" + id;
            String importance = event.getImportance();
            ((MainActivity) getActivity()).patchGraphAPI(url, importance);
        }
    });
    return inf;
}
Also used : MainActivity(kogvet.eye.MainActivity) TextView(android.widget.TextView) View(android.view.View) Nullable(android.support.annotation.Nullable)

Example 3 with MainActivity

use of kogvet.eye.MainActivity in project Eye by tommyolsson.

the class FragmentHome method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_home, container, false);
    ((MainActivity) getActivity()).getSupportActionBar().show();
    ((MainActivity) getActivity()).setActionBarTitle(getResources().getString(R.string.menu_home));
    ((MainActivity) getActivity()).showBackButton();
    TextView currentDate = view.findViewById(R.id.dateToday);
    currentDate.setText(getCurrentDate());
    mSwipeRefreshLayout = view.findViewById(R.id.swiperefresh);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            myUpdateOperation();
        }
    });
    return view;
}
Also used : TextView(android.widget.TextView) MainActivity(kogvet.eye.MainActivity) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Nullable(android.support.annotation.Nullable)

Example 4 with MainActivity

use of kogvet.eye.MainActivity in project Eye by tommyolsson.

the class FragmentOpenMeeting method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View inf = inflater.inflate(R.layout.fragment_open_meeting, container, false);
    setText(inf);
    // Buttons
    bookButton = inf.findViewById(R.id.bookButton);
    cancelButton = inf.findViewById(R.id.cancelButton);
    showButton();
    bookButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String id = event.getId();
            String url = "https://graph.microsoft.com/beta/me/events/" + id + "/accept";
            ((MainActivity) getActivity()).postGraphAPI(url);
            event.getResponseStatus().setResponse("accepted");
            recreateFragment();
            Toast.makeText(getContext(), "Bokat", Toast.LENGTH_SHORT).show();
        }
    });
    cancelButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String id = event.getId();
            String url = "https://graph.microsoft.com/beta/me/events/" + id + "/tentativelyAccept";
            ((MainActivity) getActivity()).postGraphAPI(url);
            event.getResponseStatus().setResponse("tentativelyAccepted");
            recreateFragment();
            Toast.makeText(getContext(), "Avbokat", Toast.LENGTH_SHORT).show();
        }
    });
    // Changes title to the subject name
    ((MainActivity) getActivity()).setActionBarTitle(event.getSubject());
    ((MainActivity) getActivity()).showBackButton();
    return inf;
}
Also used : MainActivity(kogvet.eye.MainActivity) TextView(android.widget.TextView) View(android.view.View) Nullable(android.support.annotation.Nullable)

Example 5 with MainActivity

use of kogvet.eye.MainActivity in project Eye by tommyolsson.

the class TabFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_tab_layout, container, false);
    ((MainActivity) getActivity()).setActionBarTitle(getResources().getString(R.string.menu_calendar));
    ((MainActivity) getActivity()).showBackButton();
    final TabLayout tabLayout = view.findViewById(R.id.tabLayout);
    DayOfWeek weekDay = LocalDateTime.now().getDayOfWeek();
    tabLayout.addTab(tabLayout.newTab().setText(weekDay.getDisplayName(TextStyle.FULL, Locale.getDefault())));
    LocalDate date = LocalDate.now();
    TemporalField woy = WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear();
    int weekNumber = date.get(woy);
    tabLayout.addTab(tabLayout.newTab().setText("Vecka " + weekNumber));
    viewPager = view.findViewById(R.id.viewpager);
    PagerAdapter pagerAdapter = new PagerAdapter(getChildFragmentManager(), allEvents);
    viewPager.setAdapter(pagerAdapter);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });
    return view;
}
Also used : DayOfWeek(org.threeten.bp.DayOfWeek) TemporalField(org.threeten.bp.temporal.TemporalField) TabLayout(android.support.design.widget.TabLayout) MainActivity(kogvet.eye.MainActivity) View(android.view.View) LocalDate(org.threeten.bp.LocalDate) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)6 View (android.view.View)6 MainActivity (kogvet.eye.MainActivity)6 TextView (android.widget.TextView)3 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)2 RecyclerView (android.support.v7.widget.RecyclerView)2 LocalDate (org.threeten.bp.LocalDate)2 DatePickerDialog (android.app.DatePickerDialog)1 TimePickerDialog (android.app.TimePickerDialog)1 TabLayout (android.support.design.widget.TabLayout)1 DatePicker (android.widget.DatePicker)1 TimePicker (android.widget.TimePicker)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 DayOfWeek (org.threeten.bp.DayOfWeek)1 TemporalField (org.threeten.bp.temporal.TemporalField)1