List of usage examples for android.view ContextMenu setHeaderView
public ContextMenu setHeaderView(View view);
From source file:vn.cybersoft.obs.android.activities.PowerScheduleActivity.java
@Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { // Inflate the menu from xml. getMenuInflater().inflate(R.menu.time_schedule_context_menu, menu); // Use the current item to create a custom view for the header. final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; final Cursor c = (Cursor) mScheduleList.getAdapter().getItem((int) info.position); final PowerSchedule schedule = new PowerSchedule(c); // Inflate the custom view and set each TextView's text. final View v = mInflater.inflate(R.layout.context_menu_header, null); TextView textView = (TextView) v.findViewById(R.id.header_time); textView.setText(getString(R.string.percentage, schedule.level)); textView = (TextView) v.findViewById(R.id.header_mode); textView.setText(Utils.getString(this, OptimalMode.getMode(getContentResolver(), schedule.modeId).name, R.string.class)); // Set the custom view on the menu. menu.setHeaderView(v); // Change the text based on the state of the schedule. if (schedule.enabled) { menu.findItem(R.id.enable_schedule).setTitle(R.string.disable_schedule); }/* www . ja va 2 s.c o m*/ }
From source file:net.sourceforge.servestream.fragment.AlarmClockFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { // Inflate the menu from xml. getActivity().getMenuInflater().inflate(R.menu.alarm_clock_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(getActivity(), cal); // Inflate the custom view and set each TextView's text. final View v = mFactory.inflate(R.layout.context_menu_header, new LinearLayout(getActivity()), false); TextView textView = (TextView) v.findViewById(R.id.header_time); textView.setText(time);//from w w w.j a v a2s.co m 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 based on the state of the alarm. if (alarm.enabled) { menu.findItem(R.id.enable_alarm).setTitle(R.string.disable_alarm); } }
From source file:vn.cybersoft.obs.android.activities.TimeScheduleActivity.java
@Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { // Inflate the menu from xml. getMenuInflater().inflate(R.menu.time_schedule_context_menu, menu); // Use the current item to create a custom view for the header. final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; final Cursor c = (Cursor) mScheduleList.getAdapter().getItem((int) info.position); final TimeSchedule schedule = new TimeSchedule(c); // Construct the Calendar to compute the time. final Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, schedule.hour); cal.set(Calendar.MINUTE, schedule.minutes); final String time = TimeSchedule.formatTime(this, cal); // Inflate the custom view and set each TextView's text. final View v = mInflater.inflate(R.layout.context_menu_header, null); TextView textView = (TextView) v.findViewById(R.id.header_time); textView.setText(time);/* w w w . j av a 2s . com*/ textView = (TextView) v.findViewById(R.id.header_mode); textView.setText(Utils.getString(this, OptimalMode.getMode(getContentResolver(), schedule.modeId).name, R.string.class)); // Set the custom view on the menu. menu.setHeaderView(v); // Change the text based on the state of the schedule. if (schedule.enabled) { menu.findItem(R.id.enable_schedule).setTitle(R.string.disable_schedule); } }
From source file:com.binoy.vibhinna.VibhinnaFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); AdapterView.AdapterContextMenuInfo info; PropManager propmanager = new PropManager(getActivity().getApplicationContext()); try {/*from w ww . j a v a 2 s .c om*/ // Casts the incoming data object into the type for AdapterView // objects. info = (AdapterView.AdapterContextMenuInfo) menuInfo; } catch (ClassCastException e) { // If the menu object can't be cast, logs an error. Log.w("Exception", "exception in getting menuinfo"); return; } Cursor cursor = (Cursor) getListAdapter().getItem(info.position); String s1 = Constants.SD_PATH + propmanager.mbActivePath(); String s2 = cursor.getString(7); if (cursor.equals(null) || s1.equals(s2)) return; if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { LayoutInflater headerInflater = (LayoutInflater) getSherlockActivity() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); ViewGroup header = (ViewGroup) headerInflater.inflate(R.layout.context_menu_header, null); TextView title = (TextView) header.findViewById(R.id.context_menu_title); title.setText(cursor.getString(1)); menu.setHeaderView(header); } else menu.setHeaderTitle(cursor.getString(1)); android.view.MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.context_menu, menu); }
From source file:com.android.browser.BookmarksPageCallbacks.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { BookmarkContextMenuInfo info = (BookmarkContextMenuInfo) menuInfo; BrowserBookmarksAdapter adapter = getChildAdapter(info.groupPosition); Cursor cursor = adapter.getItem(info.childPosition); if (!canEdit(cursor)) { return;/*from w ww . j a v a 2s .c o m*/ } boolean isFolder = cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0; final Activity activity = getActivity(); MenuInflater inflater = activity.getMenuInflater(); inflater.inflate(R.menu.bookmarkscontext, menu); if (isFolder) { menu.setGroupVisible(R.id.FOLDER_CONTEXT_MENU, true); } else { menu.setGroupVisible(R.id.BOOKMARK_CONTEXT_MENU, true); if (mDisableNewWindow) { menu.findItem(R.id.new_window_context_menu_id).setVisible(false); } } BookmarkItem header = new BookmarkItem(activity); header.setEnableScrolling(true); populateBookmarkItem(cursor, header, isFolder); menu.setHeaderView(header); int count = menu.size(); for (int i = 0; i < count; i++) { menu.getItem(i).setOnMenuItemClickListener(mContextItemClickListener); } }
From source file:com.androsz.electricsleepbeta.alarmclock.AlarmClock.java
@Override public void onCreateContextMenu(final ContextMenu menu, final View view, final ContextMenuInfo menuInfo) { // Inflate the menu from xml. // super.getMenuInflater().inflate(R.menu.context_menu, (Menu)menu); menu.add(android.view.Menu.NONE, R.id.enable_alarm, android.view.Menu.NONE, R.string.enable_alarm); menu.add(android.view.Menu.NONE, R.id.edit_alarm, android.view.Menu.NONE, R.string.menu_edit_alarm); menu.add(android.view.Menu.NONE, R.id.delete_alarm, android.view.Menu.NONE, R.string.delete_alarm); // Use the current item to create a custom view for the header. final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; final Cursor c = (Cursor) mAlarmsList.getAdapter().getItem(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);//from ww w .j a v a 2 s . c o m 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 based on the state of the alarm. if (alarm.enabled) { menu.findItem(R.id.enable_alarm).setTitle(R.string.disable_alarm); } }
From source file:com.baohume.browser.BookmarksPageCallbacks.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { BookmarkExpandableView.BookmarkContextMenuInfo info = (BookmarkExpandableView.BookmarkContextMenuInfo) menuInfo; BrowserBookmarksAdapter adapter = getChildAdapter(info.groupPosition); Cursor cursor = adapter.getItem(info.childPosition); if (!canEdit(cursor)) { return;/*from www .j a va 2s. c o m*/ } boolean isFolder = cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0; final Activity activity = getActivity(); MenuInflater inflater = activity.getMenuInflater(); inflater.inflate(R.menu.bookmarkscontext, menu); if (isFolder) { menu.setGroupVisible(R.id.FOLDER_CONTEXT_MENU, true); } else { menu.setGroupVisible(R.id.BOOKMARK_CONTEXT_MENU, true); if (mDisableNewWindow) { menu.findItem(R.id.new_window_context_menu_id).setVisible(false); } } BookmarkItem header = new BookmarkItem(activity); header.setEnableScrolling(true); populateBookmarkItem(cursor, header, isFolder); menu.setHeaderView(header); int count = menu.size(); for (int i = 0; i < count; i++) { menu.getItem(i).setOnMenuItemClickListener(mContextItemClickListener); } }
From source file:com.borqs.browser.combo.BookmarksPageCallbacks.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { BookmarkContextMenuInfo info = (BookmarkContextMenuInfo) menuInfo; BrowserBookmarksAdapter adapter = getChildAdapter(info.groupPosition); Cursor cursor = adapter.getItem(info.childPosition); if (!canEdit(cursor)) { return;/*from w w w . j a v a 2s.c o m*/ } boolean isFolder = cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0; final Activity activity = this; MenuInflater inflater = activity.getMenuInflater(); inflater.inflate(R.menu.bookmarkscontext, menu); if (isFolder) { menu.setGroupVisible(R.id.FOLDER_CONTEXT_MENU, true); } else { menu.setGroupVisible(R.id.BOOKMARK_CONTEXT_MENU, true); if (mDisableNewWindow) { menu.findItem(R.id.new_window_context_menu_id).setVisible(false); } } BookmarkItem header = new BookmarkItem(activity); header.setEnableScrolling(true); populateBookmarkItem(cursor, header, isFolder); menu.setHeaderView(header); int count = menu.size(); for (int i = 0; i < count; i++) { menu.getItem(i).setOnMenuItemClickListener(mContextItemClickListener); } }