List of usage examples for android.view View setOnCreateContextMenuListener
public void setOnCreateContextMenuListener(OnCreateContextMenuListener l)
From source file:com.micabyte.android.app.BaseActivity.java
private static void unbindViewReferences(View view) { // set all listeners to null try {//from w w w. ja v a2s.com view.setOnClickListener(null); } catch (Throwable mayHappen) { // NOOP - not supported by all views/versions } try { view.setOnCreateContextMenuListener(null); } catch (Throwable mayHappen) { // NOOP - not supported by all views/versions } try { view.setOnFocusChangeListener(null); } catch (Throwable mayHappen) { // NOOP - not supported by all views/versions } try { view.setOnKeyListener(null); } catch (Throwable mayHappen) { // NOOP - not supported by all views/versions } try { view.setOnLongClickListener(null); } catch (Throwable mayHappen) { // NOOP - not supported by all views/versions } try { view.setOnClickListener(null); } catch (Throwable mayHappen) { // NOOP - not supported by all views/versions } // set background to null Drawable d = view.getBackground(); if (d != null) { d.setCallback(null); } if (view instanceof ImageView) { final ImageView imageView = (ImageView) view; d = imageView.getDrawable(); if (d != null) { d.setCallback(null); } imageView.setImageDrawable(null); imageView.setImageBitmap(null); } if (view instanceof ImageButton) { final ImageButton imageB = (ImageButton) view; d = imageB.getDrawable(); if (d != null) { d.setCallback(null); } imageB.setImageDrawable(null); } // destroy WebView if (view instanceof WebView) { view.destroyDrawingCache(); ((WebView) view).destroy(); } }
From source file:meizhi.meizhi.malin.utils.DestroyCleanUtil.java
@SuppressLint("ObsoleteSdkInt") @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static void unBindView(View view) { if (view == null) return;/*from w w w . j a va2s . c o m*/ Drawable drawable; int i; //1. try { view.setOnClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //2. try { view.setOnCreateContextMenuListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //3. try { view.setOnFocusChangeListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //4. try { view.setOnKeyListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //5. try { view.setOnLongClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //6. try { view.setOnTouchListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //7. try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { view.setOnApplyWindowInsetsListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //8. try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { view.setOnContextClickListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //9. try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { view.setOnScrollChangeListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //10. try { view.setOnDragListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //11. try { view.setOnGenericMotionListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //12. try { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {//13 view.setOnHoverListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //13. try { view.setOnSystemUiVisibilityChangeListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } /** * @see SwipeRefreshLayout#onDetachedFromWindow() */ if (view.getBackground() != null && !view.getClass().getName().equals(CIRCLE_CLASS)) { try { view.getBackground().setCallback(null); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {//16 view.setBackgroundDrawable(null); } else { view.setBackground(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } } //ImageView if (view instanceof ImageView) { try { ImageView imageView = (ImageView) view; drawable = imageView.getDrawable(); if (drawable != null) { drawable.setCallback(null); } imageView.setImageDrawable(null); imageView.setImageBitmap(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //TextView if (view instanceof TextView) { try { TextView textView = (TextView) view; textView.setCompoundDrawables(null, null, null, null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setCompoundDrawablesRelative(null, null, null, null); } textView.setCursorVisible(false); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //ImageButton if (view instanceof ImageButton) { try { ImageButton imageButton = (ImageButton) view; drawable = imageButton.getDrawable(); if (drawable != null) { drawable.setCallback(null); } imageButton.setImageDrawable(null); imageButton.setImageBitmap(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //ListView if (view instanceof ListView) { ListView listView = (ListView) view; try { listView.setAdapter(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnScrollListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnItemClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnItemLongClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnItemSelectedListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //RecyclerView if (view instanceof RecyclerView) { try { RecyclerView recyclerView = (RecyclerView) view; recyclerView.setAdapter(null); recyclerView.setChildDrawingOrderCallback(null); recyclerView.setOnScrollListener(null); recyclerView.addOnScrollListener(null); recyclerView.removeOnScrollListener(null); recyclerView.setRecyclerListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //WebView if (view instanceof WebView) { WebView webView = (WebView) view; try { webView.stopLoading(); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.removeAllViews(); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.setWebChromeClient(null); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.setWebViewClient(null); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.destroy(); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { if (null != view.getParent() && view.getParent() instanceof ViewGroup) { ((ViewGroup) view.getParent()).removeView(view); } } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } } //SurfaceView if (view instanceof SurfaceView) { try { SurfaceView surfaceView = (SurfaceView) view; SurfaceHolder holder = surfaceView.getHolder(); if (holder != null) { Surface surface = holder.getSurface(); if (surface != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { surface.release(); } } } } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } } view.destroyDrawingCache(); view.clearAnimation(); if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; int childCount = (viewGroup).getChildCount(); for (i = 0; i < childCount; i++) { unBindView((viewGroup).getChildAt(i)); } } }
From source file:com.workingagenda.democracydroid.Adapters.ViewHolders.EpisodeViewHolder.java
public EpisodeViewHolder(final View itemView) { super(itemView); img = itemView.findViewById(R.id.row_image); txt = itemView.findViewById(R.id.row_title); tag = itemView.findViewById(R.id.row_tag); tag.setMaxLines(3);/*from w w w. jav a 2 s .c om*/ mOptions = itemView.findViewById(R.id.row_options); mDownload = itemView.findViewById(R.id.row_download); itemView.setOnCreateContextMenuListener(this); }
From source file:com.darshancomputing.BatteryIndicatorPro.AlarmsFragment.java
private void bindView(View view) { final TextView summary_tv = (TextView) view.findViewById(R.id.alarm_summary); final View summary_box = view.findViewById(R.id.alarm_summary_box); final CompoundButton toggle = (CompoundButton) view.findViewById(R.id.toggle); final int id = mCursor.getInt(AlarmDatabase.INDEX_ID); String type = mCursor.getString(AlarmDatabase.INDEX_TYPE); String threshold = mCursor.getString(AlarmDatabase.INDEX_THRESHOLD); Boolean enabled = (mCursor.getInt(AlarmDatabase.INDEX_ENABLED) == 1); String s = pfrag.str.alarm_types_display[pfrag.str.indexOf(pfrag.str.alarm_type_values, type)]; if (type.equals("temp_rises")) { s += " " + pfrag.str.formatTemp(Integer.valueOf(threshold), convertF, false); } else if (type.equals("charge_drops") || type.equals("charge_rises")) { s += " " + threshold + "%"; }// www .ja v a 2 s .c om final String summary = s; summary_tv.setText(summary); toggle.setChecked(enabled); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { alarms.setEnabled(id, isChecked); } }); summary_box.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { curId = id; curIndex = mAlarmsList.indexOfChild((View) v.getParent().getParent()); getActivity().getMenuInflater().inflate(R.menu.alarm_item_context, menu); menu.setHeaderTitle(summary); } }); summary_box.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, android.view.KeyEvent event) { if (keyCode == event.KEYCODE_DPAD_CENTER && event.getAction() == event.ACTION_DOWN) v.setPressed(true); return false; } }); summary_box.setOnClickListener(new OnClickListener() { public void onClick(View v) { ComponentName comp = new ComponentName(getActivity().getPackageName(), AlarmEditActivity.class.getName()); startActivity(new Intent().setComponent(comp).putExtra(AlarmEditActivity.EXTRA_ALARM_ID, id)); } }); }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
public boolean showMenu(final Menu menu, final View from, final boolean fromTouch) { if (from != null) { if (showIContextMenu(menu, from, fromTouch) == null) { from.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { public void onCreateContextMenu(ContextMenu cmenu, View v, ContextMenuInfo menuInfo) { MenuUtils.transferMenu(menu, cmenu, false); }/* w w w.jav a 2 s .co m*/ }); return from.showContextMenu(); } else return true; } else openOptionsMenu(); return false; }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
public void setupBaseBarButtons(Menu menu, boolean flush) { if (flush)//from ww w . ja v a 2 s.c om mLastMenuClass = ""; TableLayout mBaseBar = (TableLayout) findViewById(R.id.base_bar); mToolbarButtons = (ViewGroup) findViewById(R.id.base_row); mStaticButtons = (ViewGroup) findViewById(R.id.title_static_buttons); OpenFragment f = getSelectedFragment(); boolean topButtons = false; if (!getResources().getBoolean(R.bool.allow_split_actionbar) || !(getSetting(null, "pref_basebar", true) || mBaseBar == null || mToolbarButtons == null) && findViewById(R.id.title_buttons) != null) { mToolbarButtons = (ViewGroup) findViewById(R.id.title_buttons); if (mToolbarButtons == null && !BEFORE_HONEYCOMB) mToolbarButtons = (ViewGroup) getActionBar().getCustomView().findViewById(R.id.title_buttons); if (mBaseBar != null) mBaseBar.setVisibility(View.GONE); topButtons = true; } if (!shouldFlushMenu(menu)) return; USE_SPLIT_ACTION_BAR = !topButtons; if (mToolbarButtons != null) { mToolbarButtons.removeAllViews(); //if(!topButtons) mToolbarButtons.measure(LayoutParams.MATCH_PARENT, getResources().getDimensionPixelSize(R.dimen.actionbar_compat_height)); int i = -1; int btnWidth = getResources().getDimensionPixelSize(R.dimen.actionbar_compat_button_width) + (getResources().getDimensionPixelSize(R.dimen.vpi_padding_horizontal) * 2); // (int)(16 * getResources().getDimension(R.dimen.one_dp)); int tblWidth = mToolbarButtons.getWidth(); if (tblWidth <= 0 && !topButtons) tblWidth = getWindowWidth(); if (topButtons || tblWidth <= 0 || tblWidth > getWindowWidth() || !getResources().getBoolean(R.bool.ignore_max_base_buttons)) tblWidth = btnWidth * getResources().getInteger(R.integer.max_base_buttons); ArrayList<View> buttons = new ArrayList<View>(); buttons.addAll(ViewUtils.findChildByClass(mToolbarButtons, ImageButton.class)); boolean maxedOut = false; while (++i < menu.size()) { if (buttons.size() * btnWidth >= tblWidth) { maxedOut = true; Logger.LogDebug("Base bar full after #" + i + " ~ " + buttons.size() + " (" + (buttons.size() * btnWidth) + ">" + tblWidth + ")!"); break; } else if (menu.getItem(i) instanceof MenuItemImpl) { final MenuItemImpl item = (MenuItemImpl) menu.getItem(i); //if(item.getItemId() == R.id.title_menu) break; if (!item.isCheckable() && item.isVisible()) { View btn = makeMenuButton(item, mToolbarButtons); if (item.hasSubMenu()) btn.setTag(item.getSubMenu()); else if (!BEFORE_HONEYCOMB && item.getActionView() != null) { if (DEBUG) Logger.LogDebug("ACTION VIEW!!!"); btn = item.getActionView(); //ActionBarHelper h = ActionBarHelper.createInstance(this); } buttons.add(btn); if (i > 0) btn.setNextFocusLeftId(menu.getItem(i - 1).getItemId()); if (i < menu.size() - 1) btn.setNextFocusRightId(menu.getItem(i + 1).getItemId()); if (!USE_PRETTY_MENUS || topButtons) btn.setOnCreateContextMenuListener(this); menu.getItem(i).setVisible(false); btn.setOnClickListener(this); btn.setOnFocusChangeListener(this); btn.setOnKeyListener(this); if (mToolbarButtons.findViewById(menu.getItem(i).getItemId()) == null) mToolbarButtons.addView(btn); //menu.removeItem(item.getItemId()); if (DEBUG) Logger.LogDebug("Added " + item.getTitle() + " to base bar."); } //else Logger.LogWarning(item.getTitle() + " should not show. " + item.getShowAsAction() + " :: " + item.getFlags()); } } mToolbarButtons.setVisibility(View.VISIBLE); mLastMenuClass = f.getClassName(); if (MenuUtils.countVisibleMenus(mMainMenu) > 0) { if (maxedOut && buttons.size() > 0) { View old = buttons.remove(buttons.size() - 1); MenuUtils.setMenuVisible(mMainMenu, true, old.getId()); mToolbarButtons.removeView(old); } final ImageButton btn = (ImageButton) getLayoutInflater().inflate(R.layout.toolbar_button, mToolbarButtons); btn.setImageResource(R.drawable.ic_menu_more); //btn.measure(getResources().getDimensionPixelSize(R.dimen.actionbar_compat_button_home_width), getResources().getDimensionPixelSize(R.dimen.actionbar_compat_height)); btn.setId(R.id.menu_more); if (buttons.size() > 0) { buttons.get(buttons.size() - 1).setNextFocusRightId(R.id.menu_more); btn.setNextFocusLeftId(buttons.get(buttons.size() - 1).getId()); } btn.setOnKeyListener(this); btn.setOnClickListener(this); btn.setOnLongClickListener(this); btn.setFocusable(true); btn.setOnFocusChangeListener(this); buttons.add(btn); mToolbarButtons.addView(btn); } if (buttons.size() > 0) { View last = buttons.get(buttons.size() - 1); last.setNextFocusRightId(android.R.id.home); if (findViewById(android.R.id.home) != null) findViewById(android.R.id.home).setNextFocusLeftId(last.getId()); } Logger.LogDebug("Added " + buttons.size() + " children to Base Bar."); if (mBaseBar != null) { if (buttons.size() < 1) mBaseBar.setVisibility(View.GONE); else mBaseBar.setStretchAllColumns(true); } } else if (BEFORE_HONEYCOMB) Logger.LogWarning("No Base Row!?"); }
From source file:android.app.Activity.java
/** * Registers a context menu to be shown for the given view (multiple views * can show the context menu). This method will set the * {@link OnCreateContextMenuListener} on the view to this activity, so * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be * called when it is time to show the context menu. * /* w w w . j av a 2 s. c o m*/ * @see #unregisterForContextMenu(View) * @param view The view that should show a context menu. */ public void registerForContextMenu(View view) { view.setOnCreateContextMenuListener(this); }
From source file:android.app.Activity.java
/** * Prevents a context menu to be shown for the given view. This method will remove the * {@link OnCreateContextMenuListener} on the view. * //from ww w . j av a 2 s . c o m * @see #registerForContextMenu(View) * @param view The view that should stop showing a context menu. */ public void unregisterForContextMenu(View view) { view.setOnCreateContextMenuListener(null); }