@Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    date = (Date) getArguments().getSerializable(ARG_TIME);

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    year = calendar.get(Calendar.YEAR);
    month = calendar.get(Calendar.MONTH);
    day = calendar.get(Calendar.DAY_OF_MONTH);
    int hour = calendar.get(Calendar.HOUR);
    int minute = calendar.get(Calendar.MINUTE);

    View v = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_time, null);

    mTimePicker = (TimePicker) v.findViewById(R.id.dialog_time_time_picker);
    mTimePicker.setHour(hour);
    mTimePicker.setMinute(minute);

    mTimePicker.setOnTimeChangedListener(
        new TimePicker.OnTimeChangedListener() {
          @Override
          public void onTimeChanged(TimePicker view, int hour, int minute) {
            date = new GregorianCalendar(year, month, day, hour, minute).getTime();
            getArguments().putSerializable(EXTRA_TIME, date);
          }
        });

    return new AlertDialog.Builder(getActivity())
        .setView(v)
        .setTitle(R.string.time_picker_title)
        .setPositiveButton(
            android.R.string.ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                int hour = mTimePicker.getHour();
                int minute = mTimePicker.getMinute();
                /*Date date = (Date) getArguments().getSerializable(ARG_TIME);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                int year = calendar.get(Calendar.YEAR);
                int month = calendar.get(Calendar.MONTH);
                int day = calendar.get(Calendar.DAY_OF_MONTH);*/
                Date date = new GregorianCalendar(year, month, day, hour, minute).getTime();
                sendResult(Activity.RESULT_OK, date);
              }
            })
        .create();
  }
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   Log.i(TAG, "On create view...");
   // Inflate the layout for this fragment
   LocalTime time = LocalTime.now();
   if (getArguments() != null) {
     time = new DateTime(getArguments().getLong(ARG_TIME)).toLocalTime();
   }
   View view = inflater.inflate(R.layout.fragment_time_picker, container, false);
   mTimePicker = (TimePicker) view.findViewById(R.id.time_picker);
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
     mTimePicker.setHour(time.getHourOfDay());
     mTimePicker.setMinute(time.getMinuteOfHour());
   } else {
     mTimePicker.setCurrentHour(time.getHourOfDay());
     mTimePicker.setCurrentMinute(time.getMinuteOfHour());
   }
   return view;
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task_detail);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    setSupportActionBar(toolbar);

    LineColorPicker colorPicker = (LineColorPicker) findViewById(R.id.picker);

    // set color palette
    colorPicker.setColors(
        new int[] {
          Color.parseColor("#b8c847"),
          Color.parseColor("#67bb43"),
          Color.parseColor("#41b691"),
          Color.parseColor("#4182b6"),
          Color.parseColor("#4149b6"),
          Color.parseColor("#7641b6"),
          Color.parseColor("#b741a7"),
          Color.parseColor("#c54657"),
          Color.parseColor("#d1694a")
        });

    // set on change listener
    colorPicker.setOnColorChangedListener(
        new OnColorChangedListener() {
          @Override
          public void onColorChanged(int c) {
            task_color = c;
            // Log.d(TAG, "Selected color " + Integer.toHexString(c));
          }
        });

    // get selected color
    // task_color = colorPicker.getColor();

    Bundle extras = getIntent().getExtras();
    task_id = extras.getLong(EXTRA_TASK_ID);
    task_name = extras.getString(EXTRA_TASK_NAME);
    setTitle(task_name);
    task_desc = extras.getString(EXTRA_TASK_DESC);
    task_done = extras.getBoolean(EXTRA_TASK_DONE);
    task_color = extras.getInt(EXTRA_TASK_COLOR);
    colorPicker.setSelectedColor(task_color);

    task_limitedate = extras.getString(EXTRA_TASK_LIMITE_DATE);
    int callingActivity = getIntent().getIntExtra("calling-activity", 0);

    switch (callingActivity) {
      case ActivityConstants.TasksList:
        EditText name = (EditText) findViewById(R.id.editTextTaskName);
        EditText desc = (EditText) findViewById(R.id.editTextTaskDescription);
        DatePicker date = (DatePicker) findViewById(R.id.datePickerTask);
        TimePicker time = (TimePicker) findViewById(R.id.timePickerTask);
        CheckBox checkBox = (CheckBox) findViewById(R.id.checkBoxTaskDetail);
        checkBox.setOnCheckedChangeListener(
            new CompoundButton.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                task_done = isChecked;
              }
            });
        name.setText(task_name);
        desc.setText(task_desc);
        checkBox.setChecked(task_done);

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-hh:mm");
        Date theDate = new Date();
        try {
          theDate = format.parse(task_limitedate);
        } catch (ParseException e) {
          e.printStackTrace();
        }
        Calendar myCal = new GregorianCalendar();
        myCal.setTime(theDate);
        int Year = myCal.get(Calendar.YEAR);
        int Month = myCal.get(Calendar.MONTH);
        int Day = myCal.get(Calendar.DAY_OF_MONTH);
        int Hour = myCal.get(Calendar.HOUR_OF_DAY);
        int Min = myCal.get(Calendar.MINUTE);
        date.init(
            Year,
            Month,
            Day,
            new DatePicker.OnDateChangedListener() {
              @Override
              public void onDateChanged(
                  DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                // Notify the user.
              }
            });
        time.setIs24HourView(true);
        int currentapiVersion = android.os.Build.VERSION.SDK_INT;
        if (currentapiVersion >= Build.VERSION_CODES.M) {
          time.setHour(Hour);
          time.setMinute(Min);
        } else {
          time.setCurrentHour(Hour);
          time.setCurrentMinute(Min);
        }

        break;
    }
  }