List of usage examples for android.view View setOnLongClickListener
public void setOnLongClickListener(@Nullable OnLongClickListener l)
From source file:lk.vega.centerconsole.MainActivity.java
private void setButtonConfigurations(View v, int resId) { v.setOnLongClickListener(this); v.setBackgroundResource(resId);/*ww w. j a va 2s. c o m*/ v.setOnClickListener(this); }
From source file:pl.allegro.fogger.ui.context.ActivityWithContextMenu.java
@Override public void unregisterForContextMenu(View view) { super.unregisterForContextMenu(view); view.setOnLongClickListener(null); }
From source file:net.reichholf.dreamdroid.activities.VirtualRemoteActivity.java
/** * Registers an OnClickListener for a specific GUI Element. OnClick the * function <code>onButtonClicked</code> will be called with the given id * //from w ww . ja v a2 s .co m * @param v * The view to register an OnClickListener for * @param id * The item ID to register the listener for */ protected void registerOnClickListener(View v, final int id) { v.setLongClickable(true); v.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { onButtonClicked(id, true); return true; } }); v.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onButtonClicked(id, false); } }); }
From source file:com.chess.genesis.activity.Settings.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = this; final Pref pref = new Pref(this); // set layout mode final boolean isTablet = pref.getBool(R.array.pf_tabletMode); if (isTablet) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); else//from www .j a va 2s . c o m setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setContentView(R.layout.activity_settings); addPreferencesFromResource(R.xml.settings); net = new NetworkClient(this, handle); progress = new ProgressMsg(this); final View button = findViewById(R.id.topbar_genesis); button.setOnLongClickListener(this); final boolean isLoggedin = pref.getBool(R.array.pf_isLoggedIn); final Preference bench = findPreference("benchmark"); bench.setOnPreferenceClickListener(this); final IntListPreference poll = (IntListPreference) findPreference(pref.key(R.array.pf_notifierPolling)); poll.setOnPreferenceChangeListener(this); CheckBoxPreference check = (CheckBoxPreference) findPreference(pref.key(R.array.pf_emailNoteEnabled)); check.setOnPreferenceChangeListener(this); check.setEnabled(isLoggedin); check = (CheckBoxPreference) findPreference(pref.key(R.array.pf_noteEnabled)); check.setOnPreferenceChangeListener(this); check.setEnabled(isLoggedin); CallBackPreference callbackPref = (CallBackPreference) findPreference("deleteLocalTable"); callbackPref.setCallBack(this); callbackPref = (CallBackPreference) findPreference("resyncOnlineTable"); callbackPref.setCallBack(this); callbackPref.setEnabled(isLoggedin); callbackPref = (CallBackPreference) findPreference("resyncArchiveTable"); callbackPref.setCallBack(this); callbackPref.setEnabled(isLoggedin); callbackPref = (CallBackPreference) findPreference("resyncMsgTable"); callbackPref.setCallBack(this); callbackPref.setEnabled(isLoggedin); callbackPref = (CallBackPreference) findPreference("bcReset"); callbackPref.setCallBack(this); // Set email note value from server if (pref.getBool(R.array.pf_isLoggedIn)) { progress.setText("Retrieving Settings"); net.get_option("emailnote"); new Thread(net).start(); } }
From source file:com.pranavpandey.smallapp.sample.SmallAppSample.java
private void setupOptionMenu() { View header = LayoutInflater.from(this).inflate(R.layout.header, new LinearLayout(this), false); final View optionMenu = header.findViewById(R.id.option_menu); optionMenu.setOnLongClickListener(new View.OnLongClickListener() { @Override//from w ww . ja va 2s . co m public boolean onLongClick(View v) { SmallTheme.getInstance().showHeaderHint(v, R.string.sas_options); return false; } }); optionMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(getContext(), optionMenu); try { Field[] fields = popup.getClass().getDeclaredFields(); for (Field field : fields) { if ("mPopup".equals(field.getName())) { field.setAccessible(true); Object menuPopupHelper = field.get(popup); Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName()); Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class); setForceIcons.invoke(menuPopupHelper, true); break; } } } catch (Exception e) { e.printStackTrace(); } popup.getMenuInflater().inflate(R.menu.main, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_settings: showSettings(); break; case R.id.menu_about: new AboutDialog(SmallAppSample.this, R.mipmap.ic_launcher, R.string.app_name, Type.LIST) .show(getRootView()); break; case R.id.menu_sources: SmallUtils.openLink(SmallAppSample.this, getRootView(), SOURCES_LINK, null, Type.GRID); break; } return true; } }); popup.show(); } }); getWindow().setHeaderView(header); }
From source file:org.ciasaboark.tacere.activity.AboutActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_about); ongoingToast = Toast.makeText(this, "", Toast.LENGTH_SHORT); // Show the Up button in the action bar. setupActionBar();//from www . j a va 2 s . com TextView sourceText = (TextView) findViewById(id.about_source_text); sourceText.setMovementMethod(LinkMovementMethod.getInstance()); TextView bugsText = (TextView) findViewById(id.about_bugs_text); bugsText.setMovementMethod(LinkMovementMethod.getInstance()); TextView commentsText = (TextView) findViewById(id.about_comments_text); commentsText.setMovementMethod(LinkMovementMethod.getInstance()); TextView versionText = (TextView) findViewById(id.about_version_number); String formattedVersion = String.format(getString(R.string.about_version), Versioning.getVersionCode()); versionText.setText(formattedVersion); TextView basicOrPro = (TextView) findViewById(id.about_version_pro); String type; Authenticator authenticator = new Authenticator(this); if (authenticator.isAuthenticated()) { type = "Pro version"; } else { type = "Basic version"; } basicOrPro.setText(type); final View betaSettingsHeaderContent = findViewById(id.about_header_beta_settings); betaSettingsHeaderContent.setOnTouchListener(mOnTouch); final View normalHeaderContent = findViewById(id.about_header_normal); normalHeaderContent.setOnTouchListener(mOnTouch); normalHeaderContent.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { toggleVisibility(normalHeaderContent); return true; } }); betaSettingsHeaderContent.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { toggleVisibility(normalHeaderContent); return true; } }); final View betaSettingsClickArea = findViewById(id.about_header_beta_settings_clickarea); betaSettingsClickArea.setOnTouchListener(mOnTouch); final SwitchCompat betaSettingsSwitch = (SwitchCompat) findViewById(id.about_header_beta_settings_switch); final BetaPrefs betaPrefs = new BetaPrefs(this); betaSettingsSwitch.setChecked(betaPrefs.isBetaPrefsUnlocked()); betaSettingsClickArea.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { betaSettingsSwitch.performClick(); betaPrefs.setIsBetaPrefsUnlocked(betaSettingsSwitch.isChecked()); } }); betaSettingsClickArea.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { toggleVisibility(normalHeaderContent); return true; } }); }
From source file:org.ciasaboark.tacere.activity.fragment.AboutFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_about, container, false); context = getActivity();//from w ww .j a v a2s . c o m ongoingToast = Toast.makeText(context, "", Toast.LENGTH_SHORT); TextView sourceText = (TextView) rootView.findViewById(id.about_source_text); sourceText.setMovementMethod(LinkMovementMethod.getInstance()); TextView bugsText = (TextView) rootView.findViewById(id.about_bugs_text); bugsText.setMovementMethod(LinkMovementMethod.getInstance()); TextView commentsText = (TextView) rootView.findViewById(id.about_comments_text); commentsText.setMovementMethod(LinkMovementMethod.getInstance()); TextView versionText = (TextView) rootView.findViewById(id.about_version_number); String formattedVersion = String.format(getString(R.string.about_version), Versioning.getVersionCode()); versionText.setText(formattedVersion); //textview using marquee scrolling, but this only works if the textview is selected versionText.setSelected(true); TextView versionType = (TextView) rootView.findViewById(id.about_version_type); String type; Authenticator authenticator = new Authenticator(context); type = authenticator.getAuthenticatedTypeString() + " version"; versionType.setText(type); final View betaSettingsHeaderContent = rootView.findViewById(id.about_header_beta_settings); betaSettingsHeaderContent.setOnTouchListener(mOnTouch); final View normalHeaderContent = rootView.findViewById(id.about_header_normal); normalHeaderContent.setOnTouchListener(mOnTouch); normalHeaderContent.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { toggleVisibility(normalHeaderContent); return true; } }); betaSettingsHeaderContent.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { toggleVisibility(normalHeaderContent); return true; } }); final View betaSettingsClickArea = rootView.findViewById(id.about_header_beta_settings_clickarea); betaSettingsClickArea.setOnTouchListener(mOnTouch); final SwitchCompat betaSettingsSwitch = (SwitchCompat) rootView .findViewById(id.about_header_beta_settings_switch); final BetaPrefs betaPrefs = new BetaPrefs(context); betaSettingsSwitch.setChecked(betaPrefs.isBetaPrefsUnlocked()); betaSettingsClickArea.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { betaSettingsSwitch.performClick(); betaPrefs.setIsBetaPrefsUnlocked(betaSettingsSwitch.isChecked()); } }); betaSettingsClickArea.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { toggleVisibility(normalHeaderContent); return true; } }); return rootView; }
From source file:com.launcher.silverfish.AppDrawerTabFragment.java
@SuppressWarnings("deprecation") private void setClickListeners(View view, final String appName, final int appIndex) { // Start a drag action when icon is long clicked view.setOnLongClickListener(new View.OnLongClickListener() { @Override/*from ww w . j a v a 2s . c o m*/ public boolean onLongClick(View view) { // Add data to the clipboard String[] mime_type = { ClipDescription.MIMETYPE_TEXT_PLAIN }; ClipData data = new ClipData(Constants.DRAG_APP_MOVE, mime_type, new ClipData.Item(appName)); data.addItem(new ClipData.Item(Integer.toString(appIndex))); data.addItem(new ClipData.Item(getTag())); // The drag shadow is simply the app's icon View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder( view.findViewById(R.id.item_app_icon)); // "This method was deprecated in API level 24. Use startDragAndDrop() // for newer platform versions." if (Build.VERSION.SDK_INT < 24) { view.startDrag(data, shadowBuilder, view, 0); } else { view.startDragAndDrop(data, shadowBuilder, view, 0); } return true; } }); // Start the app activity when icon is clicked. view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = mPacMan.getLaunchIntentForPackage(appName); startActivity(i); } }); }
From source file:li.klass.fhem.fragments.core.BaseFragment.java
private void showConnectionError(String content) { if (isNavigation) return;// ww w . j av a 2 s .c o m View view = getView(); if (view == null) return; View errorLayout = view.findViewById(R.id.errorLayout); if (errorLayout == null) return; errorLayout.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { ErrorHolder.sendLastErrorAsMail(getActivity()); return true; } }); errorLayout.setVisibility(View.VISIBLE); TextView errorView = (TextView) view.findViewById(R.id.errorView); errorView.setText(content); }
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 ww . ja va2 s .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)); } } }