+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View view,
+ ContextMenuInfo menuInfo) {
+ // Inflate the menu from xml.
+ getMenuInflater().inflate(R.menu.context_menu, menu);
+
+ // Use the current item to create a custom view for the header.
+ final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
+ final Cursor c =
+ (Cursor) mAlarmsList.getAdapter().getItem((int) info.position);
+ final Alarm alarm = new Alarm(c);
+
+ // Construct the Calendar to compute the time.
+ final Calendar cal = Calendar.getInstance();
+ cal.set(Calendar.HOUR_OF_DAY, alarm.hour);
+ cal.set(Calendar.MINUTE, alarm.minutes);
+ final String time = Alarms.formatTime(this, cal);
+
+ // Inflate the custom view and set each TextView's text.
+ final View v = mFactory.inflate(R.layout.context_menu_header, null);
+ TextView textView = (TextView) v.findViewById(R.id.header_time);
+ textView.setText(time);
+ textView = (TextView) v.findViewById(R.id.header_label);
+ textView.setText(alarm.label);
+
+ // Set the custom view on the menu.
+ menu.setHeaderView(v);
+ // Change the text to "disable" if the alarm is already enabled.
+ if (alarm.enabled) {
+ menu.findItem(R.id.enable_alarm).setTitle(R.string.disable_alarm);
+ }
+ }
+
+ public void onItemClick(AdapterView parent, View v, int pos, long id) {
+ Intent intent = new Intent(this, SetAlarm.class);
+ intent.putExtra(Alarms.ALARM_ID, (int) id);
+ startActivity(intent);
+ }
+