package com.quemb.qmbform.view;

import com.quemb.qmbform.R;
import com.quemb.qmbform.descriptor.RowDescriptor;

import android.content.Context;
import android.os.Build;
import android.widget.TimePicker;

import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * Created by tonimoeckel on 15.07.14.
 */
public class FormTimeInlineFieldCell extends FormTimeFieldCell implements
        TimePicker.OnTimeChangedListener {

    private TimePicker mTimePicker;

    public FormTimeInlineFieldCell(Context context,
                                   RowDescriptor rowDescriptor) {
        super(context, rowDescriptor);
    }


    @Override
    protected void init() {

        super.init();
        mTimePicker = (TimePicker) findViewById(R.id.timePicker);


    }

    @Override
    protected int getResource() {
        return R.layout.time_inline_field_cell;
    }

    @Override
    protected void initDatePicker(Calendar calendar) {

        if (Build.VERSION.SDK_INT >= 23)
        {
            getTimePicker().setHour(calendar.get(Calendar.HOUR_OF_DAY));
            getTimePicker().setMinute(calendar.get(Calendar.MINUTE));
        }
        else
        {
            getTimePicker().setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
            getTimePicker().setCurrentMinute(calendar.get(Calendar.MINUTE));
        }
        getTimePicker().setOnTimeChangedListener(this);
        getTimePicker().setIs24HourView(true);

    }

    @Override
    public void onCellSelected() {
        super.onCellSelected();

        getTimePicker().setVisibility(getTimePicker().getVisibility() == VISIBLE ? GONE : VISIBLE);

    }

    public TimePicker getTimePicker() {
        return mTimePicker;
    }

    @Override
    public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {

        Date date = new Date();
        date.setTime(TimeUnit.HOURS.toMillis(hourOfDay) + TimeUnit.MINUTES.toMillis(minute));

        onDateChanged(date);

    }
}

@@ -889,32 +889,69 @@
 ld_cell;%0A    %7D%0A%0A
+    @SuppressWarnings(%22deprecation%22)%0A
     @Override%0A  
@@ -1045,10 +1045,29 @@
  %3E= 
-23
+Build.VERSION_CODES.M
 )%0A  

Update FormTimeInlineFieldCell.java