Example usage for android.app TimePickerDialog TimePickerDialog

List of usage examples for android.app TimePickerDialog TimePickerDialog

Introduction

In this page you can find the example usage for android.app TimePickerDialog TimePickerDialog.

Prototype

public TimePickerDialog(Context context, OnTimeSetListener listener, int hourOfDay, int minute,
        boolean is24HourView) 

Source Link

Document

Creates a new time picker dialog.

Usage

From source file:com.morgan.sunrisealarm.MainActivity.java

public void layoutClicked(View view) {
    final WidgetId widget = new WidgetId(view);

    Switch onOffSwitch = (Switch) findViewById(widget.getSwitchId());
    if (onOffSwitch.isChecked()) {
        final TextView alarmText = (TextView) findViewById(widget.getAlarmTextId());

        AlarmTime time = new AlarmTime(alarmText.getText().toString());
        TimePickerDialog timePicker;//from   w  w  w.j  a  v a  2 s . co m

        timePicker = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                AlarmTime time = new AlarmTime(selectedHour, selectedMinute);
                alarmText.setText(time.getString());

                Command command = new Command();
                command.setAlarm(widget.getAlarmId(), selectedHour, selectedMinute);
            }
        }, time.getHour(), time.getMin(), true);
        timePicker.show();
    }
}

From source file:com.cachirulop.moneybox.activity.MovementDetailActivity.java

/**
 * Handler for the change insert time button
 * //from   w  w w. j ava 2 s.  c o  m
 * @param v
 *            view that launch the event
 */
public void onChangeInsertTimeClick(View v) {
    Calendar cal;
    TimePickerDialog dlg;
    TimePickerDialog.OnTimeSetListener lt;

    cal = Calendar.getInstance();

    lt = new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hour, int minute) {
            onInsertTimeSet(view, hour, minute);
        }
    };

    cal.setTime(_movement.getInsertDate());

    dlg = new TimePickerDialog(this, lt, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), true);

    dlg.show();
}

From source file:com.commonsdroid.fragmentdialog.AlertFragmentDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    setCancelable(isCancelable);//from   ww  w. j  a va2s .  c  om
    if (TextUtils.isEmpty(positiveText)) {
        positiveText = "OK";
        Log.d("CHECK", "" + com.commonsdroid.fragmentdialog.R.string.ok);
    }

    if (TextUtils.isEmpty(negativeText)) {
        negativeText = "Cancel";
    }
    switch (type) {
    case DIALOG_TYPE_OK:
        /*show dialog with positive button*/
        return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
                .setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        if (alertButtonClickListener != null)
                            alertButtonClickListener.onPositiveButtonClick(identifier);

                    }
                }).create();
    case DIALOG_TYPE_YES_NO:
        /*show dialog with positive and negative button*/
        return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
                .setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        if (alertButtonClickListener != null)
                            alertButtonClickListener.onPositiveButtonClick(identifier);

                    }
                }).setNegativeButton(negativeText, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        if (alertButtonClickListener != null)
                            alertButtonClickListener.onNegativeButtonClick(identifier);

                    }
                }).create();
    case DATE_DIALOG:
        /*show date picker dialog*/
        return new DatePickerDialog(getActivity(), AlertFragmentDialog.this, sYear, sMonth, sDate);
    case TIME_DIALOG:
        /*show time picker dialog*/
        return new TimePickerDialog(getActivity(), AlertFragmentDialog.this, sHour, sMinute, true);
    case SIMPLE_LIST_DIALOG:
        /**
         * show simple list dialog
         */
        return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_item).create();
    case SINGLE_CHOICE_LIST_DIALOG:
        /*show single choice list dialog*/
        return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_singlechoice).create();
    case MULTI_CHOICE_LIST_DIALOG:
        /*show multichoice list dialog*/
        Dialog multipleChoice = new Dialog(getActivity());
        multipleChoice.setContentView(R.layout.list_multichoice);
        multipleChoice.setTitle(title);
        ListView listView = (ListView) multipleChoice.findViewById(R.id.lstMultichoiceList);
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // Manage selected items here

                CheckedTextView textView = (CheckedTextView) view;
                if (textView.isChecked()) {

                } else {

                }
                Log.e("CHECK", "clicked pos : " + position + " checked : " + textView.isChecked());
            }
        });

        final ArrayAdapter<String> arraySingleChoiceAdapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.select_dialog_multichoice, dialogList);

        listView.setAdapter(arraySingleChoiceAdapter);
        multipleChoice.show();
        /*multipleChoice.setNegativeButton(R.string.cancel,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
        multipleChoice.setPositiveButton(R.string.cancel, new OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
              dismiss();      
              sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem);
           }
        });*/
        /* multipleChoice.setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {
                
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (alSelectedItem.size() != 0) {
                        sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem);
                    }
                }
            });*/
        //         multipleChoice.create();

        //         singleChoiceListDialog.setCancelable(false);

        /* multipleChoice.setMultiChoiceItems(items, null,
            new DialogInterface.OnMultiChoiceClickListener() {
             @Override
                public void onClick(DialogInterface dialog, int which,
                        boolean isChecked) {
                    if (isChecked) {
                        alSelectedItem.add(items[which]);
                    } else {
                        alSelectedItem.remove(items[which]);
                    }
                }
            });
           multipleChoice.setNegativeButton(R.string.cancel,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
           multipleChoice.setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {
                
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (alSelectedItem.size() != 0) {
                        sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem);
                    }
                }
            });*/
        return multipleChoice;//.create();

    }
    return null;
}

From source file:org.onebusaway.android.ui.TripPlanFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Init Google Play Services as early as possible in the Fragment lifecycle to give it time
    if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) == ConnectionResult.SUCCESS) {
        mGoogleApiClient = LocationUtils.getGoogleApiClientWithCallbacks(getContext());
        mGoogleApiClient.connect();//from  ww w.j  av a 2 s .  c  o  m
    }

    Bundle bundle = getArguments();
    mBuilder = new TripRequestBuilder(bundle);

    final View view = inflater.inflate(R.layout.fragment_trip_plan, container, false);
    setHasOptionsMenu(true);

    mFromAddressTextArea = (AutoCompleteTextView) view.findViewById(R.id.fromAddressTextArea);
    mToAddressTextArea = (AutoCompleteTextView) view.findViewById(R.id.toAddressTextArea);
    mFromCurrentLocationImageButton = (ImageButton) view.findViewById(R.id.fromCurrentLocationImageButton);
    mToCurrentLocationImageButton = (ImageButton) view.findViewById(R.id.toCurrentLocationImageButton);
    mDate = (Spinner) view.findViewById(R.id.date);
    mDateAdapter = new ArrayAdapter(getActivity(), R.layout.simple_list_item);
    mDate.setAdapter(mDateAdapter);

    mTime = (Spinner) view.findViewById(R.id.time);
    mTimeAdapter = new ArrayAdapter(getActivity(), R.layout.simple_list_item);
    mTime.setAdapter(mTimeAdapter);

    mLeavingChoice = (Spinner) view.findViewById(R.id.leavingChoiceSpinner);

    mLeavingChoiceAdapter = ArrayAdapter.createFromResource(getContext(),
            R.array.trip_plan_leaving_arriving_array, R.layout.simple_list_item);
    mLeavingChoiceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mLeavingChoice.setAdapter(mLeavingChoiceAdapter);

    // Set mLeavingChoice onclick adapter in onResume() so we do not fire it when setting it
    final TimePickerDialog.OnTimeSetListener timeCallback = new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hour, int minute) {
            mMyCalendar.set(Calendar.HOUR_OF_DAY, hour);
            mMyCalendar.set(Calendar.MINUTE, minute);
            resetDateTimeLabels();
            mBuilder.setDateTime(mMyCalendar);
            checkRequestAndSubmit();
        }
    };

    final DatePickerDialog.OnDateSetListener dateCallback = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            mMyCalendar.set(Calendar.YEAR, year);
            mMyCalendar.set(Calendar.MONTH, monthOfYear);
            mMyCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            resetDateTimeLabels();
            mBuilder.setDateTime(mMyCalendar);
            checkRequestAndSubmit();
        }

    };

    mDate.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                new DatePickerDialog(view.getContext(), dateCallback, mMyCalendar.get(Calendar.YEAR),
                        mMyCalendar.get(Calendar.MONTH), mMyCalendar.get(Calendar.DAY_OF_MONTH)).show();
            }

            return true;
        }
    });

    mTime.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                new TimePickerDialog(view.getContext(), timeCallback, mMyCalendar.get(Calendar.HOUR_OF_DAY),
                        mMyCalendar.get(Calendar.MINUTE), false).show();
            }
            return true;
        }
    });

    ImageButton resetTimeButton = (ImageButton) view.findViewById(R.id.resetTimeImageButton);

    resetTimeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mMyCalendar = Calendar.getInstance();
            mBuilder.setDateTime(mMyCalendar);
            resetDateTimeLabels();
            checkRequestAndSubmit();
        }
    });

    setUpAutocomplete(mFromAddressTextArea, USE_FROM_ADDRESS);
    setUpAutocomplete(mToAddressTextArea, USE_TO_ADDRESS);

    mToCurrentLocationImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mToAddressTextArea.setText(getString(R.string.tripplanner_current_location));
            mToAddress = makeAddressFromLocation();
            mBuilder.setTo(mToAddress);
            checkRequestAndSubmit();
        }
    });

    mFromCurrentLocationImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFromAddressTextArea.setText(getString(R.string.tripplanner_current_location));
            mFromAddress = makeAddressFromLocation();
            mBuilder.setFrom(mFromAddress);
            checkRequestAndSubmit();
        }
    });

    // Start: default from address is Current Location, to address is unset
    return view;
}

From source file:com.cachirulop.moneybox.activity.MovementDetailActivity.java

/**
 * Handler for the change get date button
 * /*from w w w.ja va  2s .c o  m*/
 * @param v
 *            view that launch the event
 */
public void onChangeGetTimeClick(View v) {
    Calendar cal;
    TimePickerDialog dlg;
    TimePickerDialog.OnTimeSetListener lt;

    cal = Calendar.getInstance();

    lt = new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hour, int minute) {
            onGetTimeSet(view, hour, minute);
        }
    };

    cal.setTime(_movement.getGetDate());

    dlg = new TimePickerDialog(this, lt, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), true);

    dlg.show();
}

From source file:tinygsn.gui.android.ActivityViewData.java

private void addTableViewModeCustomize() {
    table_view_mode = (TableLayout) findViewById(R.id.table_view_mode);
    table_view_mode.removeAllViews();/*from   w ww.ja  v a 2s . c om*/

    // Row From
    TableRow row = new TableRow(this);
    TextView txt = new TextView(this);
    txt.setText("From: ");
    txt.setTextColor(Color.parseColor("#000000"));
    row.addView(txt);

    //      Date time = new Date();
    startTime = new Date();
    startTime.setMinutes(startTime.getMinutes() - 1);
    endTime = new Date();

    // Start Time
    SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
    txtStartTime = new TextView(this);
    txtStartTime.setText(formatter.format(startTime) + "");
    txtStartTime.setTextColor(Color.parseColor("#000000"));
    txtStartTime.setBackgroundColor(Color.parseColor("#61a7db"));
    row.addView(txtStartTime);

    txtStartTime.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new TimePickerDialog(context, startTimeSetListener, dateAndTime.get(Calendar.HOUR_OF_DAY) - 1,
                    dateAndTime.get(Calendar.MINUTE), true).show();
        }
    });

    // Add space
    txt = new TextView(this);
    txt.setText("     ");
    row.addView(txt);

    // Start Date
    formatter = new SimpleDateFormat("dd/MM/yyyy");
    // txtStartDate, txtStartTime
    txtStartDate = new TextView(this);
    txtStartDate.setText(formatter.format(startTime) + "");
    txtStartDate.setTextColor(Color.parseColor("#000000"));
    txtStartDate.setBackgroundColor(Color.parseColor("#61a7db"));
    row.addView(txtStartDate);

    txtStartDate.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new DatePickerDialog(context, startDateSetListener, dateAndTime.get(Calendar.YEAR),
                    dateAndTime.get(Calendar.MONTH), dateAndTime.get(Calendar.DAY_OF_MONTH)).show();
        }
    });

    table_view_mode.addView(row);

    // Add a space row
    row = new TableRow(this);
    txt = new TextView(this);
    txt.setText("-");
    row.addView(txt);
    table_view_mode.addView(row);

    // Row To
    row = new TableRow(this);
    txt = new TextView(this);
    txt.setText("To");
    txt.setTextColor(Color.parseColor("#000000"));
    row.addView(txt);

    // End Time
    formatter = new SimpleDateFormat("HH:mm:ss");
    txtEndTime = new TextView(this);
    txtEndTime.setText(formatter.format(endTime) + "");
    txtEndTime.setTextColor(Color.parseColor("#000000"));
    txtEndTime.setBackgroundColor(Color.parseColor("#61a7db"));
    row.addView(txtEndTime);

    txtEndTime.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new TimePickerDialog(context, endTimeSetListener, dateAndTime.get(Calendar.HOUR_OF_DAY),
                    dateAndTime.get(Calendar.MINUTE), true).show();
        }
    });

    // Add space
    txt = new TextView(this);
    txt.setText("     ");
    row.addView(txt);

    // End Date
    formatter = new SimpleDateFormat("dd/MM/yyyy");
    // txtStartDate, txtStartTime
    txtEndDate = new TextView(this);
    txtEndDate.setText(formatter.format(endTime) + "");
    txtEndDate.setTextColor(Color.parseColor("#000000"));
    txtEndDate.setBackgroundColor(Color.parseColor("#61a7db"));
    row.addView(txtEndDate);

    txtEndDate.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new DatePickerDialog(context, endDateSetListener, dateAndTime.get(Calendar.YEAR),
                    dateAndTime.get(Calendar.MONTH), dateAndTime.get(Calendar.DAY_OF_MONTH)).show();
        }
    });

    table_view_mode.addView(row);

    // Row
    row = new TableRow(this);
    Button detailBtn = new Button(this);
    detailBtn.setTextSize(TEXT_SIZE + 4);
    detailBtn.setText("Detail");
    detailBtn.setTextColor(Color.parseColor("#000000"));
    detailBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

    Button plotDataBtn = new Button(this);
    plotDataBtn.setTextSize(TEXT_SIZE + 4);
    plotDataBtn.setText("Plot data");
    plotDataBtn.setTextColor(Color.parseColor("#000000"));
    plotDataBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            viewChart();
        }
    });

    TableRow.LayoutParams params = new TableRow.LayoutParams();
    // params.addRule(TableRow.LayoutParams.FILL_PARENT);
    params.span = 2;

    row.addView(detailBtn, params);
    row.addView(plotDataBtn, params);
    row.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    table_view_mode.addView(row);

}

From source file:net.evecom.androidecssp.activity.event.ContinueAddActivity.java

/**
 * //  ww  w .j a v a 2s  .c  o  m
 * 
 * 
 * @author Stark Zhou
 * @created 2015-12-30 2:44:26
 */
private void init() {
    initGallery();
    clearLocation();
    clearFilesRecord();
    calendar = Calendar.getInstance();
    typeValueKeyMap.put("", "1");
    typeValueKeyMap.put("", "2");
    happenAreaBlock = (RelativeLayout) findViewById(R.id.happen_area_block);
    happenAreaBlock.setVisibility(View.GONE);
    happenDateBlock = (RelativeLayout) findViewById(R.id.happen_date_block);
    happenDateBlock.setVisibility(View.GONE);
    happenAddrBlock = (RelativeLayout) findViewById(R.id.happen_addr_block);
    happenAddrBlock.setVisibility(View.GONE);
    reportTime = (TextView) findViewById(R.id.continue_reporttime_add);
    reportDate = (TextView) findViewById(R.id.continue_reportdate_add);
    eventName = (TextView) findViewById(R.id.continue_eventname_add);
    eventName.setText(eventInfo.getStr("eventname"));
    continueMonitor = (TextView) findViewById(R.id.continue_monitor_add);
    continueName = (EditText) findViewById(R.id.continue_name_add);
    happenTime = (TextView) findViewById(R.id.happen_time_add);
    happenDate = (TextView) findViewById(R.id.happen_date_add);
    continueType = (TextView) findViewById(R.id.continue_type_add);
    continueType.setText("");
    continueArea = (TextView) findViewById(R.id.continue_area_add);
    continueAddr = (EditText) findViewById(R.id.continue_addr_add);
    continueDept = (TextView) findViewById(R.id.continue_dept_add);
    continueReporter = (EditText) findViewById(R.id.continue_reporter_add);
    String userName = ShareUtil.getString(getApplicationContext(), "PASSNAME", "usernameCN", "0");
    continueReporter.setText(userName);
    continueTel = (EditText) findViewById(R.id.continue_tel_add);
    continueContent = (EditText) findViewById(R.id.continue_content_add);
    continueStep = (EditText) findViewById(R.id.continue_step_add);
    continueRemark = (EditText) findViewById(R.id.continue_remark_add);
    happenDate.setText(calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-"
            + calendar.get(Calendar.DAY_OF_MONTH));
    happenTime.setText(calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE));
    reportDate.setText(calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-"
            + calendar.get(Calendar.DAY_OF_MONTH));
    reportTime.setText(calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE));

    // 
    happenDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            calendar = Calendar.getInstance();
            happenDate.setBackgroundResource(R.drawable.time_btn_press);
            new DatePickerDialog(ContinueAddActivity.this, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker arg0, int year, int monthOfYear, int dayOfMonth) {
                    happenDate.setText("" + year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
                    happenDate.setBackgroundResource(R.drawable.time_btn);
                }
            }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))
                    .show();

        }
    });
    happenTime.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            calendar = Calendar.getInstance();
            happenTime.setBackgroundResource(R.drawable.time_btn_press);
            new TimePickerDialog(ContinueAddActivity.this, new TimePickerDialog.OnTimeSetListener() {
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    happenTime.setText(hourOfDay + ":" + minute);
                    happenTime.setBackgroundResource(R.drawable.time_btn);
                }
            }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true).show();

        }
    });

    reportDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            calendar = Calendar.getInstance();
            reportDate.setBackgroundResource(R.drawable.time_btn_press);
            new DatePickerDialog(ContinueAddActivity.this, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker arg0, int year, int monthOfYear, int dayOfMonth) {
                    reportDate.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
                    reportDate.setBackgroundResource(R.drawable.time_btn);
                }
            }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))
                    .show();
        }
    });

    reportTime.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            reportTime.setBackgroundResource(R.drawable.time_btn_press);
            calendar = Calendar.getInstance();
            new TimePickerDialog(ContinueAddActivity.this, new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    reportTime.setText(hourOfDay + ":" + minute);
                    reportTime.setBackgroundResource(R.drawable.time_btn);
                }
            }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true).show();
        }
    });

}

From source file:com.sastra.app.timetable.TimetableActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.timetable_main);

    Log.d(TAG, "Entered On Create");

    ActionBar Bar = getActionBar();/* w  w w.j  a v  a  2 s  .co  m*/
    Bar.setLogo(R.drawable.ic_launcher_1);
    //Bar.setTitle("");
    // String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/SASTRA Timetable/files/test.txt";

    SharedPreferences mPreferences = this.getSharedPreferences("AB", MODE_PRIVATE);

    boolean firstTime = mPreferences.getBoolean("firstTime", true);
    if (firstTime) {

        SharedPreferences.Editor editor = mPreferences.edit();
        editor.putBoolean("firstTime", false);
        editor.commit();
        Dialog d2 = new Dialog(this);
        d2.setTitle("HELP");
        d2.setCanceledOnTouchOutside(true);
        TextView tv = new TextView(this);
        tv.setText(
                "This application can be used to store your timetable.First,click on Manage Subjects Icon(Wrench Icon) inorder to add all your subjects.Click on Add Subjects on top and enter the details of your subject.The fields that appear are optional and not manditory.Once you have added all the subjects,go back to the main screen and click on Add Classes icon(Plus Icon) to add the different classes to your timetable.The fields that appear are again optional and all of them need not be filled.You can long press on any particular subject to edit or delete them.You can delete all the informations using Delete All(Garbage Icon) option.");
        ScrollView sav = new ScrollView(this);
        sav.addView(tv);
        LayoutParams lap = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        d2.addContentView(sav, lap);
        d2.show();
    }

    boolean enabled = true;

    Bar.setHomeButtonEnabled(enabled);

    //File database=getApplicationContext().getDatabasePath("massey.db");
    // if (database.exists()) {
    data = new InternalDB(this);
    // }

    // add fragments
    mFragments = new ArrayList<Fragment>();

    mFragments.add(Fragment.instantiate(this, MONDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, TUESDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, WEDNESDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, THURSDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, FRIDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, SATURDAYFRAGMENT));

    // adapter
    mAdapter = new MainPagerAdapter(getSupportFragmentManager(), mFragments);

    // pager
    mPager = (ViewPager) findViewById(R.id.view_pager);

    mPager.setAdapter(mAdapter);

    // indicator
    mIndicator = (TitlePageIndicator) findViewById(R.id.title_indicator);

    //mIndicator.setBackgroundColor(0x0106000e);
    //mIndicator.setFooterColor(0xffffff);
    mIndicator.setTextColor(0xFF000000);
    mIndicator.setSelectedColor(0xFF000000);
    mIndicator.setViewPager(mPager);

    intent = new Intent(getApplicationContext(), AddSubjects.class);//intent = new Intent(getApplicationContext(), AddSubjects.class);

    builder = new AlertDialog.Builder(this);
    builder.setMessage("Are you sure you want to delete all lessons?").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    data.open();
                    data.deleteAllHours();
                    data.close();
                    // update();
                    mAdapter.notifyDataSetChanged();
                    mAdapter.finishUpdate(mPager);
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    alert = builder.create();

    builder2 = new AlertDialog.Builder(this);
    builder2.setMessage("Are you sure you want to delete this lesson?").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    data.open();
                    data.deleteHour(OLDSName, OLDHDay, OLDHType, OLDHClass, OLDHStart, OLDHEnd);
                    data.close();
                    //update();
                    mAdapter.notifyDataSetChanged();
                    mAdapter.finishUpdate(mPager);
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    alert2 = builder2.create();

    //added

    addDialog = new Dialog(this);
    addDialog.setCancelable(false);
    action = "insert";
    addDialog.setTitle("Add Class");
    addDialog.setContentView(R.layout.timetable_addhour);

    HType = (EditText) addDialog.findViewById(R.id.typeEdit);
    HClass = (EditText) addDialog.findViewById(R.id.classroomEdit);
    arraydays = new String[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
    HDay = (Spinner) addDialog.findViewById(R.id.day);
    arrayadapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, arraydays);
    arrayadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    HDay.setAdapter(arrayadapter);
    HDay.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            selectedDay = arraydays[position];
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });

    fromDialog = new TimePickerDialog(this, fromTimeSetListener, 12, 0, true);
    toDialog = new TimePickerDialog(this, toTimeSetListener, 12, 0, true);

    //This place is important.

    SName = (Spinner) addDialog.findViewById(R.id.SName);
    SName.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            selectedSubject = (String) arraySubjects[position];
            Log.d("AB", "We are inside the setOnItemSelectedListener for Sname : 264");
            Log.d("AB", selectedSubject);
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });

    Button buttonFrom = (Button) addDialog.findViewById(R.id.buttonFrom);
    buttonFrom.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            fromDialog.show();
        }
    });

    Button buttonTo = (Button) addDialog.findViewById(R.id.buttonTo);
    buttonTo.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            toDialog.show();
        }
    });

    start = (TextView) addDialog.findViewById(R.id.start);
    end = (TextView) addDialog.findViewById(R.id.end);

    Button cancel = (Button) addDialog.findViewById(R.id.cancel);
    cancel.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            addDialog.cancel();
            fromDialog.updateTime(12, 0);
            toDialog.updateTime(12, 0);
            start.setText("--:--");
            end.setText("--:--");
            HType.setText(null);
            HClass.setText(null);
        }

    });

    Button ok = (Button) addDialog.findViewById(R.id.ok);
    ok.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            int HDay = SDay2IDay(selectedDay);
            if (action.equals("insert")) {
                data.open();
                data.insertIntoHours(selectedSubject, HDay, HType.getText().toString(),
                        HClass.getText().toString(), start.getText().toString(), end.getText().toString());
                data.close();
            } else if (action.equals("edit")) {
                data.open();
                data.updateHours(OLDSName, OLDHType, OLDHClass, OLDHDay, OLDHStart, OLDHEnd, selectedSubject,
                        HDay, HType.getText().toString(), HClass.getText().toString(),
                        start.getText().toString(), end.getText().toString());
                data.close();
            }
            addDialog.cancel();
            fromDialog.updateTime(12, 0);
            toDialog.updateTime(12, 0);
            start.setText("--:--");
            end.setText("--:--");
            HType.setText(null);
            HClass.setText(null);
            mAdapter.notifyDataSetChanged();
            //update();
            mAdapter.finishUpdate(mPager);
        }
    });

}

From source file:com.itime.team.itime.fragments.MeetingSubPreferenceFragment.java

@Override
public void onClick(View v) {
    final int id = v.getId();
    switch (id) {
    case R.id.setting_meeting_start_date: {
        final Calendar cal = Calendar.getInstance();
        DatePickerDialog datePicker = new DatePickerDialog(getContext(),
                new DatePickerDialog.OnDateSetListener() {
                    @Override//from   ww  w . jav  a2s. c om
                    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                        mStartsDate.setText(String.format("%d/%d/%d", dayOfMonth, monthOfYear + 1, year));
                        mStartsDateCalendar.set(year, monthOfYear, dayOfMonth);
                    }
                }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
        datePicker.show();
        break;
    }
    case R.id.setting_meeting_start_time:
    case R.id.setting_meeting_end_time: {
        final Calendar cal = Calendar.getInstance();
        TimePickerDialog timePicker = new TimePickerDialog(getContext(),
                new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        TextView time = id == R.id.setting_meeting_start_time ? mStartsTime : mEndsTime;

                        if (id == R.id.setting_meeting_start_time) {
                            mStartsTimeHour = hourOfDay;
                            mStartsTimeMinute = minute;
                        } else {
                            mEndsTimeHour = hourOfDay;
                            mEndsTimeMinute = minute;
                        }

                        time.setText(hourOfDay + ":" + minute);
                    }
                }, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), false);
        timePicker.show();
        break;
    }
    case R.id.setting_meeting_repeat: {
        Intent intent = new Intent(getActivity(), SettingsActivity.class);
        intent.putExtra("Settings", 6);
        startActivityForResult(intent, REPEAT_SETTINGS);

        break;
    }
    case R.id.setting_meeting_type: {
        String text = isPrefer ? Type.UNAVAILABLE.getText() : Type.PREFER.getText();
        isPrefer = !isPrefer;
        mType.setText(text);
        mParcelablePreference.preferenceType = text;
        break;
    }
    }
}

From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpAirPlane.java

private void setLister() {

    timePicker = new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

        }//w w w  . j  a  v a  2s .  c o  m
    };
    timerPicker.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new TimePickerDialog(getActivity(), timePicker, 24, 59, true).show();
        }
    });

    departure.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity());

            final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.select_dialog_item);
            arrayAdapter.add(getString(R.string.pop_map_option1));
            arrayAdapter.add(getString(R.string.pop_map_option2));

            builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String strName = arrayAdapter.getItem(which);

                    switch (which) {
                    case 0:
                        Intent map = new Intent(getActivity(), OrderMapActivity.class);
                        Bundle b = new Bundle();
                        b.putInt(Constants.ARG_POSITION, Constants.DEPARTURE_QUERY_GPS);
                        map.putExtras(b);
                        startActivityForResult(map, Constants.DEPARTURE_QUERY_GPS);

                        break;
                    case 1:
                        Intent page = new Intent(getActivity(), BookmarksMapListActivity.class);
                        Bundle flag = new Bundle();
                        flag.putInt(Constants.ARG_POSITION, Constants.DEPARTURE_QUERY_BOOKMARK);
                        page.putExtras(flag);
                        startActivityForResult(page, Constants.DEPARTURE_QUERY_BOOKMARK);

                        break;
                    }
                }
            });
            builderSingle.show();
        }
    });

    stop.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity());

            final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.select_dialog_item);
            arrayAdapter.add(getString(R.string.pop_map_option1));
            arrayAdapter.add(getString(R.string.pop_map_option2));

            builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String strName = arrayAdapter.getItem(which);

                    switch (which) {
                    case 0:
                        Intent map = new Intent(getActivity(), OrderMapActivity.class);
                        Bundle b = new Bundle();
                        b.putInt(Constants.ARG_POSITION, Constants.STOP_QUERY_GPS);
                        map.putExtras(b);
                        startActivityForResult(map, Constants.STOP_QUERY_GPS);

                        break;
                    case 1:
                        Intent page = new Intent(getActivity(), BookmarksMapListActivity.class);
                        Bundle flag = new Bundle();
                        flag.putInt(Constants.ARG_POSITION, Constants.STOP_QUERY_GPS);
                        page.putExtras(flag);
                        startActivityForResult(page, Constants.STOP_QUERY_BOOKMARK);

                        break;
                    }
                }
            });
            builderSingle.show();
        }
    });

    destination.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity());

            final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.select_dialog_item);
            arrayAdapter.add(getString(R.string.pop_map_option1));
            arrayAdapter.add(getString(R.string.pop_map_option2));

            builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String strName = arrayAdapter.getItem(which);

                    switch (which) {
                    case 0:
                        Intent map = new Intent(getActivity(), OrderMapActivity.class);
                        Bundle b = new Bundle();
                        b.putInt(Constants.ARG_POSITION, Constants.DESTINATION_QUERY_GPS);
                        map.putExtras(b);
                        startActivityForResult(map, Constants.DESTINATION_QUERY_GPS);

                        break;
                    case 1:
                        Intent page = new Intent(getActivity(), BookmarksMapListActivity.class);
                        Bundle flag = new Bundle();
                        flag.putInt(Constants.ARG_POSITION, Constants.DESTINATION_QUERY_GPS);
                        page.putExtras(flag);
                        startActivityForResult(page, Constants.DESTINATION_QUERY_BOOKMARK);

                        break;
                    }
                }
            });
            builderSingle.show();
        }
    });

    getDataFromDB();
    linearLayout_spec.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // custom dialog
            final Dialog dialog = new Dialog(getActivity());
            dialog.setContentView(R.layout.client_take_ride_selectspec_requirement);
            dialog.setTitle(getString(R.string.txt_take_spec));
            Button cancel = (Button) dialog.findViewById(R.id.button_category_cancel);
            Button ok = (Button) dialog.findViewById(R.id.button_category_ok);

            //dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            // set the custom dialog components - text, image and button
            ListView requirement = (ListView) dialog.findViewById(R.id.listViewDialog);

            requirement.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

                    ClientTakeRideSelectSpecListItem item = mCommentListData.get(position);
                    item.check = !item.check;
                    mCommentListData.set(position, item);
                    listViewAdapter.notifyDataSetChanged();
                }
            });

            if (listViewAdapter == null) {
                listViewAdapter = new ClientTakeRideSelectSpecListItemAdapter(getActivity(), 0,
                        mCommentListData);

            }
            requirement.setAdapter(listViewAdapter);
            listViewAdapter.notifyDataSetChanged();

            dialog.show();
            cancel.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    dialog.cancel();
                }
            });

            String require;
            ok.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String require = "";
                    for (ClientTakeRideSelectSpecListItem item : mCommentListData) {
                        if (item.check) {
                            spec_list.add(item);
                            require += item.book_title + ",";
                        }
                    }

                    if (!require.isEmpty())
                        require = require.substring(0, require.length() - 1);
                    spec_value.setText(require);
                    dialog.cancel();
                }
            });

        }
    });

    spec.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // custom dialog
            final Dialog dialog = new Dialog(getActivity());
            dialog.setContentView(R.layout.client_take_ride_selectspec_requirement);
            dialog.setTitle(getString(R.string.txt_take_spec));
            Button cancel = (Button) dialog.findViewById(R.id.button_category_ok);

            //dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            // set the custom dialog components - text, image and button
            ListView requirement = (ListView) dialog.findViewById(R.id.listViewDialog);

            getDataFromDB();
            listViewAdapter = new ClientTakeRideSelectSpecListItemAdapter(getActivity(), 0, mCommentListData);
            requirement.setAdapter(listViewAdapter);
            listViewAdapter.notifyDataSetChanged();

            dialog.show();
            cancel.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    dialog.cancel();
                }
            });

        }
    });

    spinner_airport_location_destination.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) {
            currentLocation = tainStationList.get(position);
            destination_detail = new LocationAddress();
            destination_detail.setLongitude(Double.parseDouble(currentLocation.getLng()));
            destination_detail.setLatitude(Double.parseDouble(currentLocation.getLat()));
            destination_detail.setAddress(currentLocation.getStreetAddress().substring(3,
                    currentLocation.getStreetAddress().length()));
            destination_detail.setLocation(currentLocation.getLocation());
            String zipCode = (getTrainStationZip(currentLocation.getLocation()));
            destination_detail.setZipCode(zipCode);
            destination_detail.setCountryName("Taiwan");
            destination_detail.setLocality(currentLocation.getStreetAddress());
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });

    spinner_airport_location_departure.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) {
            currentLocation = tainStationList.get(position);
            departure_detail = new LocationAddress();
            departure_detail.setLongitude(Double.parseDouble(currentLocation.getLng()));
            departure_detail.setLatitude(Double.parseDouble(currentLocation.getLat()));
            departure_detail.setAddress(currentLocation.getStreetAddress().substring(3,
                    currentLocation.getStreetAddress().length()));
            departure_detail.setLocation(currentLocation.getLocation());
            //departure_detail.setZipCode(currentLocation.getStreetAddress().substring(0,3));
            String zipCode = (getTrainStationZip(currentLocation.getLocation()));
            departure_detail.setZipCode(zipCode);
            departure_detail.setCountryName("Taiwan");
            departure_detail.setLocality(currentLocation.getStreetAddress());
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });

}