Example usage for android.view View setOnLongClickListener

List of usage examples for android.view View setOnLongClickListener

Introduction

In this page you can find the example usage for android.view View setOnLongClickListener.

Prototype

public void setOnLongClickListener(@Nullable OnLongClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked and held.

Usage

From source file:Main.java

/**
 * Removes the cheat sheet for the given view by removing the view's {@link
 * View.OnLongClickListener}.//from   w  w  w  .j a v a 2s.  c  o m
 *
 * @param view The view whose cheat sheet should be removed.
 */
public static void remove(final View view) {
    view.setOnLongClickListener(null);
}

From source file:Main.java

public static void onLongClick(OnLongClickListener listener, View... views) {
    if (listener == null || views == null)
        throw new IllegalArgumentException();
    for (View itm : views)
        itm.setOnLongClickListener(listener);
}

From source file:Main.java

/**
 * Sets up a cheat sheet (tooltip) for the given view by setting its {@link
 * View.OnLongClickListener}. When the view is long-pressed, a {@link Toast} with
 * the view's {@link View#getContentDescription() content description} will be
 * shown either above (default) or below the view (if there isn't room above it).
 *
 * @param view The view to add a cheat sheet for.
 *///from w  w  w.jav a 2 s  . c o  m
public static void setup(View view) {
    view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            return show(view, view.getContentDescription());
        }
    });
}

From source file:Main.java

/**
 * Sets up a cheat sheet (tooltip) for the given view by setting its {@link
 * View.OnLongClickListener}. When the view is long-pressed, a {@link Toast} with
 * the given text will be shown either above (default) or below the view (if there isn't room
 * above it).//from   ww  w . j a v a2  s . c  o  m
 *
 * @param view      The view to add a cheat sheet for.
 * @param textResId The string resource containing the text to show on long-press.
 */
public static void setup(View view, final int textResId) {
    view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            return show(view, view.getContext().getString(textResId));
        }
    });
}

From source file:Main.java

/**
 * Sets up a cheat sheet (tooltip) for the given view by setting its {@link
 * View.OnLongClickListener}. When the view is long-pressed, a {@link Toast} with
 * the given text will be shown either above (default) or below the view (if there isn't room
 * above it).//  w w w.j  a v  a 2s .co  m
 *
 * @param view The view to add a cheat sheet for.
 * @param text The text to show on long-press.
 */
public static void setup(View view, final CharSequence text) {
    view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            return show(view, text);
        }
    });
}

From source file:com.svpino.longhorn.artifacts.StockTileProcessor.java

private static View createTile(Fragment fragment, Stock stock, int index, boolean spanned) {

    View view = ((LayoutInflater) fragment.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(spanned ? R.layout.stock_tile_spanned : R.layout.stock_tile_not_spanned, null);

    StockTileViewHolder stockTileViewHolder = new StockTileViewHolder(fragment.getResources(), view, stock,
            index, spanned);//from w ww.  ja  v a2 s .  c om
    stockTileViewHolder.refresh(fragment.getResources());
    view.setTag(stockTileViewHolder);

    view.setOnClickListener((OnClickListener) fragment);

    if (index > 2) {
        view.setOnLongClickListener((OnLongClickListener) fragment);

        if (!stock.isMarketIndex()) {
            enableTileAsADropLocation(fragment, view);
        }

    }

    return view;
}

From source file:android.support.v7.widget.TooltipCompatHandler.java

/**
 * Set the tooltip text for the view./*from w w  w  .j  a  v a2 s .c  o m*/
 *
 * @param view        view to set the tooltip on
 * @param tooltipText the tooltip text
 */
public static void setTooltipText(View view, CharSequence tooltipText) {
    // The code below is not attempting to update the tooltip text
    // for a pending or currently active tooltip, because it may lead
    // to updating the wrong tooltipin in some rare cases (e.g. when
    // action menu item views are recycled). Instead, the tooltip is
    // canceled/hidden. This might still be the wrong tooltip,
    // but hiding wrong tooltip is less disruptive UX.
    if (sPendingHandler != null && sPendingHandler.mAnchor == view) {
        setPendingHandler(null);
    }
    if (TextUtils.isEmpty(tooltipText)) {
        if (sActiveHandler != null && sActiveHandler.mAnchor == view) {
            sActiveHandler.hide();
        }
        view.setOnLongClickListener(null);
        view.setLongClickable(false);
        view.setOnHoverListener(null);
    } else {
        new TooltipCompatHandler(view, tooltipText);
    }
}

From source file:com.micabyte.android.app.BaseActivity.java

private static void unbindViewReferences(View view) {
    // set all listeners to null
    try {//  w  w w  . j a va 2s.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:pl.allegro.fogger.ui.context.ActivityWithContextMenu.java

@Override
public void registerForContextMenu(final View view) {
    view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override/*from   ww  w  . java2  s .  c o m*/
        public boolean onLongClick(View v) {
            menuResId = ActivityWithContextMenu.this.getContextMenuResId(view);
            verifyMenuResId();
            dialogWithBlurredBackgroundLauncher.showDialog(createDialog());
            return true;
        }
    });
}

From source file:com.deange.textfaker.ui.adapter.MessageListAdapter.java

@Override
public void bindView(View view, final Context context, final Cursor cursor) {

    view.setOnLongClickListener(mLongPressListener);
    ((Activity) mContext).registerForContextMenu(view);

    final ConversationMessage message = new ConversationMessage(cursor);
    final String formattedDate = Formatter.formatMessageDate(new Date(message.getTime()));

    ((TextView) view.findViewById(R.id.text_view)).setText(message.getText());
    ((TextView) view.findViewById(R.id.date_view)).setText(formattedDate);

    ((QuickContactDivot) view.findViewById(R.id.avatar)).setImageToDefault();
}