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;
    }

    @SuppressWarnings("deprecation")
    @Override
    protected void initDatePicker(Calendar calendar) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        {
            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);

    }
}

@@ -163,16 +163,55 @@
 .Build;%0A
+import android.text.format.DateFormat;%0A
 import a
@@ -1117,35 +1117,33 @@
   %7B%0A            
-get
+m
 TimePicker().set
@@ -1132,26 +1132,24 @@
  mTimePicker
-()
 .setHour(cal
@@ -1186,35 +1186,33 @@
 ));%0A            
-get
+m
 TimePicker().set
@@ -1201,26 +1201,24 @@
  mTimePicker
-()
 .setMinute(c
@@ -1285,35 +1285,33 @@
   %7B%0A            
-get
+m
 TimePicker().set
@@ -1296,34 +1296,32 @@
      mTimePicker
-()
 .setCurrentHour(
@@ -1361,35 +1361,33 @@
 ));%0A            
-get
+m
 TimePicker().set
@@ -1376,26 +1376,24 @@
  mTimePicker
-()
 .setCurrentM
@@ -1440,35 +1440,33 @@
       %7D%0A        
-get
+m
 TimePicker().set
@@ -1455,26 +1455,24 @@
  mTimePicker
-()
 .setOnTimeCh
@@ -1492,24 +1492,25 @@
 (this);%0A
+%0A
         
 getTimeP
@@ -1493,35 +1493,94 @@
 this);%0A%0A        
-get
+if (DateFormat.is24HourFormat(getContext()))%0A                m
 TimePicker().set
@@ -1569,26 +1569,24 @@
  mTimePicker
-()
 .setIs24Hour
@@ -1695,19 +1695,17 @@
         
-get
+m
 TimePick
@@ -1706,18 +1706,16 @@
 mePicker
-()
 .setVisi
@@ -1721,19 +1721,17 @@
 ibility(
-get
+m
 TimePick
@@ -1732,18 +1732,16 @@
 mePicker
-()
 .getVisi

Update FormTimeInlineFieldCell.java