Example usage for android.widget TextView setOnLongClickListener

List of usage examples for android.widget TextView setOnLongClickListener

Introduction

In this page you can find the example usage for android.widget TextView 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:com.cssweb.android.quote.QHSCGridActivity.java

private void AddViewItem(int paramInt1, LinearLayout paramLinearLayout, int paramInt2, int paramInt3,
        int paramInt4, boolean paramBoolean) {
    TextView localTextView = new TextView(this);
    float f = this.mFontSize;
    localTextView.setTextSize(f);/* w w w .j  a v  a  2  s.c om*/

    localTextView.setGravity(Gravity.CENTER);
    localTextView.setFocusable(paramBoolean);
    localTextView.setOnClickListener(mClickListener);
    localTextView.setOnLongClickListener(mLongClickListener);
    localTextView.setOnTouchListener(this); // touch
    localTextView.setTag(paramInt2);
    localTextView.setEnabled(paramBoolean);
    localTextView.setSingleLine(true);
    Resources localResources = getResources();
    Drawable localDrawable = null;
    if (paramInt4 == 0 && paramInt3 >= 0) {// 
        int i1 = this.residTitleCol;
        int i8 = 0;
        localTextView.setTextColor(paramInt1);
        if (paramInt3 == 0) {
            localDrawable = localResources.getDrawable(i1);
            i8 = localDrawable.getIntrinsicWidth();
        } else if (paramInt3 == 100) {
            localDrawable = localResources.getDrawable(this.residTitleScrollCol[2]);
            i8 = localDrawable.getIntrinsicWidth();
            i8 += 20;
        } else if (paramInt3 == 13) {
            localDrawable = localResources.getDrawable(this.residTitleScrollCol[0]);
            i8 = localDrawable.getIntrinsicWidth();

        } else if (paramInt3 % 2 == 0) {
            localDrawable = localResources.getDrawable(this.residTitleScrollCol[1]);
            i8 = localDrawable.getIntrinsicWidth();
        } else {
            localDrawable = localResources.getDrawable(this.residTitleScrollCol[0]);
            i8 = localDrawable.getIntrinsicWidth();
        }
        localTextView.setBackgroundDrawable(localDrawable);
        int i6 = localDrawable.getIntrinsicHeight();
        localTextView.setHeight(i6 + CssSystem.getTableTitleHeight(this));
        localTextView.setWidth(i8);
        paramLinearLayout.addView(localTextView);
        return;
    }
    if (paramInt4 != 0 && paramInt3 >= 0) {
        int i8 = 0;
        localTextView.setTextColor(paramInt1);
        if (paramInt3 == 0) {
            localDrawable = localResources.getDrawable(this.residCol);
            i8 = localDrawable.getIntrinsicWidth();
        } else if (paramInt3 == 100) {
            localDrawable = localResources.getDrawable(this.residScrollCol[2]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();
            i8 += 20;
        } else if (paramInt3 == 13) {
            localDrawable = localResources.getDrawable(this.residScrollCol[0]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();

        } else if (paramInt3 % 2 == 0) {
            localDrawable = localResources.getDrawable(this.residScrollCol[1]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();
        } else {
            localDrawable = localResources.getDrawable(this.residScrollCol[0]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();
        }
        localTextView.setBackgroundDrawable(localDrawable);
        int i6 = localDrawable.getIntrinsicHeight();
        localTextView.setHeight(i6 + rowHeight);
        localTextView.setWidth(i8);
        paramLinearLayout.addView(localTextView);
        return;
    }
}

From source file:com.github.kanata3249.ffxieq.android.FoodSelectorActivity.java

@Override
protected void onStart() {
    super.onStart();

    FoodListView flv;// w  ww  .j ava  2s . co m

    flv = (FoodListView) findViewById(R.id.ListView);
    if (flv != null) {
        flv.setFilterByID(mFilterID);
        flv.setFilterByType(mFilterByType);
        flv.setParam(getDAO());

        flv.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                Intent result = new Intent();

                result.putExtra("From", "FoodSelector");
                result.putExtra("Id", arg3);
                setResult(RESULT_OK, result);
                finish();
            }

        });

        flv.setOnItemLongClickListener(new OnItemLongClickListener() {
            public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                mLongClickingItemId = arg3;
                FoodSelectorActivity.this.openContextMenu(arg0);
                return true;
            }
        });

        registerForContextMenu(flv);
    }

    {
        Food cur = getDAO().instantiateFood(mCurrent);
        if (cur == null) {
            cur = new Food(-1, getString(R.string.FoodNotSelected), "");
        }
        if (cur != null) {
            TextView tv;
            View.OnLongClickListener listener = new View.OnLongClickListener() {
                public boolean onLongClick(View v) {
                    mLongClickingItemId = mCurrent;
                    FoodSelectorActivity.this.openContextMenu(v);
                    return true;
                }
            };

            tv = (TextView) findViewById(R.id.Name);
            if (tv != null) {
                tv.setText(cur.getName());
                tv.setOnLongClickListener(listener);
                registerForContextMenu(tv);
            }
            tv = (TextView) findViewById(R.id.Description);
            if (tv != null) {
                tv.setText(cur.getDescription());
                tv.setOnLongClickListener(listener);
                registerForContextMenu(tv);
            }
        }
    }
}

From source file:org.thoughtcrime.securesms.logsubmit.SubmitLogFragment.java

private TextView handleBuildSuccessTextView(final String logUrl) {
    TextView showText = new TextView(getActivity());

    showText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    showText.setPadding(15, 30, 15, 30);
    showText.setText(getString(R.string.log_submit_activity__copy_this_url_and_add_it_to_your_issue, logUrl));
    showText.setAutoLinkMask(Activity.RESULT_OK);
    showText.setMovementMethod(LinkMovementMethod.getInstance());
    showText.setOnLongClickListener(new View.OnLongClickListener() {

        @Override/*from   w w  w  . j  a  v  a  2 s  .com*/
        public boolean onLongClick(View v) {
            @SuppressWarnings("deprecation")
            ClipboardManager manager = (ClipboardManager) getActivity()
                    .getSystemService(Activity.CLIPBOARD_SERVICE);
            manager.setText(logUrl);
            Toast.makeText(getActivity(), R.string.log_submit_activity__copied_to_clipboard, Toast.LENGTH_SHORT)
                    .show();
            return true;
        }
    });

    Linkify.addLinks(showText, Linkify.WEB_URLS);
    return showText;
}

From source file:com.makotojava.android.debate.PolicySpeechFragment.java

private void createSpeechTimerOnLongClickListener(TextView speechTimer) {
    speechTimer.setOnLongClickListener(new OnLongClickListener() {
        @Override/*from  w  w w. j a va2s . c om*/
        public boolean onLongClick(View v) {
            getActivity().startActionMode(new ActionMode.Callback() {
                @Override
                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                @Override
                public void onDestroyActionMode(ActionMode mode) {
                    // Nothing to do
                }

                @Override
                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    // Inflate the menu
                    MenuInflater inflater = mode.getMenuInflater();
                    inflater.inflate(R.menu.speech_timer_context_menu, menu);
                    return true;
                }

                @Override
                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    boolean ret = false;
                    switch (item.getItemId()) {
                    case R.id.speech_context_menu_item_reset:
                        Log.i(TAG, "CONTEXT MENU: Speech Timer **RESET**");
                        long originalDurationInMillis = _speechTimer.reset();
                        updateTimerTextView(_speechTimerTextView, originalDurationInMillis);
                        _speechTimerTextView.setTextColor(Color.BLACK);
                        ret = true;
                        break;
                    case R.id.speech_context_menu_item_set:
                        Log.i(TAG, "CONTEXT MENU: Speech Timer **SET**");
                        // Display dialog to set Timer
                        FragmentManager fragMan = getActivity().getFragmentManager();
                        TimePickerFragment dialog = TimePickerFragment.newInstance(
                                _speechTimer.getMillisUntilFinished(), _speech.getDurationInMinutes(),
                                RQID_SPEECHTIMER);
                        dialog.setTargetFragment(PolicySpeechFragment.this, 0);
                        dialog.show(fragMan, MINUTES_SECONDS_PICKER_TITLE);
                        _speechTimerTextView.setTextColor(Color.BLACK);
                        ret = true;
                        break;
                    }
                    return ret;
                }
            });
            return true;
        }
    });
}

From source file:com.makotojava.android.debate.PolicySpeechFragment.java

private void createAffPrepTimerOnLongClickListener(TextView speechTimer) {
    speechTimer.setOnLongClickListener(new OnLongClickListener() {
        @Override//from  w  w  w. j av  a  2 s . co  m
        public boolean onLongClick(View v) {
            getActivity().startActionMode(new ActionMode.Callback() {
                @Override
                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                @Override
                public void onDestroyActionMode(ActionMode mode) {
                    // Nothing to do
                }

                @Override
                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    // Inflate the menu
                    MenuInflater inflater = mode.getMenuInflater();
                    inflater.inflate(R.menu.affprep_timer_context_menu, menu);
                    return true;
                }

                @Override
                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    boolean ret = false;
                    switch (item.getItemId()) {
                    case R.id.affprep_context_menu_reset:
                        Log.i(TAG, "CONTEXT MENU: Aff Prep Timer **RESET**");
                        long originalDurationInMillis = getAffirmativePrepTimer().reset();
                        updateTimerTextView(_affirmativePrepTimerTextView, originalDurationInMillis);
                        getPolicySpeechSingleton().setAffirmativePrepRemainingTime(originalDurationInMillis);
                        _affirmativePrepTimerTextView.setTextColor(Color.BLACK);
                        ret = true;
                        break;
                    case R.id.affprep_context_menu_set:
                        Log.i(TAG, "CONTEXT MENU: Aff Prep Timer **SET**");
                        // Display dialog to set Timer
                        FragmentManager fragMan = getActivity().getFragmentManager();
                        TimePickerFragment dialog = TimePickerFragment.newInstance(
                                getAffirmativePrepTimer().getMillisUntilFinished(),
                                PolicySpeechFactory.PREP_TIME_IN_MINUTES, RQID_AFFPREPTIMER);
                        dialog.setTargetFragment(PolicySpeechFragment.this, 0);
                        dialog.show(fragMan, MINUTES_SECONDS_PICKER_TITLE);
                        _affirmativePrepTimerTextView.setTextColor(Color.BLACK);
                        ret = true;
                        break;
                    }
                    return ret;
                }
            });
            return true;
        }
    });
}

From source file:com.makotojava.android.debate.PolicySpeechFragment.java

private void createNegPrepTimerOnLongClickListener(TextView speechTimer) {
    speechTimer.setOnLongClickListener(new OnLongClickListener() {
        @Override//from www  . java  2  s.  c om
        public boolean onLongClick(View v) {
            getActivity().startActionMode(new ActionMode.Callback() {
                @Override
                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                @Override
                public void onDestroyActionMode(ActionMode mode) {
                    // Nothing to do
                }

                @Override
                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    // Inflate the menu
                    MenuInflater inflater = mode.getMenuInflater();
                    inflater.inflate(R.menu.negprep_timer_context_menu, menu);
                    return true;
                }

                @Override
                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    boolean ret = false;
                    switch (item.getItemId()) {
                    case R.id.negprep_context_menu_reset:
                        Log.i(TAG, "CONTEXT MENU: Neg Prep Timer **RESET**");
                        long originalDurationInMillis = getNegativePrepTimer().reset();
                        updateTimerTextView(_negativePrepTimerTextView, originalDurationInMillis);
                        getPolicySpeechSingleton().setNegativePrepRemainingTime(originalDurationInMillis);
                        _negativePrepTimerTextView.setTextColor(Color.BLACK);
                        ret = true;
                        break;
                    case R.id.negprep_context_menu_set:
                        Log.i(TAG, "CONTEXT MENU: Neg Prep Timer **SET**");
                        // Display dialog to set Timer
                        FragmentManager fragMan = getActivity().getFragmentManager();
                        TimePickerFragment dialog = TimePickerFragment.newInstance(
                                getNegativePrepTimer().getMillisUntilFinished(),
                                PolicySpeechFactory.PREP_TIME_IN_MINUTES, RQID_NEGPREPTIMER);
                        dialog.setTargetFragment(PolicySpeechFragment.this, 0);
                        dialog.show(fragMan, MINUTES_SECONDS_PICKER_TITLE);
                        _negativePrepTimerTextView.setTextColor(Color.BLACK);
                        ret = true;
                        break;
                    }
                    return ret;
                }
            });
            return true;
        }
    });
}

From source file:com.makotojava.android.debate.PolicySpeechFragment.java

private void createCrossExTimerOnLongClickListener(TextView speechTimer) {
    speechTimer.setOnLongClickListener(new OnLongClickListener() {
        @Override//from ww  w .  j ava 2  s .  c o m
        public boolean onLongClick(View v) {
            getActivity().startActionMode(new ActionMode.Callback() {
                @Override
                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                @Override
                public void onDestroyActionMode(ActionMode mode) {
                    // Nothing to do
                }

                @Override
                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    // Inflate the menu
                    MenuInflater inflater = mode.getMenuInflater();
                    inflater.inflate(R.menu.crossex_timer_context_menu, menu);
                    return true;
                }

                @Override
                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    boolean ret = false;
                    switch (item.getItemId()) {
                    case R.id.crossex_context_menu_reset:
                        Log.i(TAG, "CONTEXT MENU: CrossEx Timer **RESET**");
                        long originalDurationInMillis = _crossexTimer.reset();
                        updateTimerTextView(_crossexTimerTextView, originalDurationInMillis);
                        _crossexTimerTextView.setTextColor(Color.BLACK);
                        mode.finish();
                        ret = true;
                        break;
                    case R.id.crossex_context_menu_set:
                        Log.i(TAG, "CONTEXT MENU: CrossEx Timer **SET**");
                        // Display dialog to set Timer
                        FragmentManager fragMan = getActivity().getFragmentManager();
                        TimePickerFragment dialog = TimePickerFragment.newInstance(
                                _crossexTimer.getMillisUntilFinished(), _speech.getCrossExDurationInMinutes(),
                                RQID_CROSSEXTIMER);
                        dialog.setTargetFragment(PolicySpeechFragment.this, 0);
                        dialog.show(fragMan, MINUTES_SECONDS_PICKER_TITLE);
                        _crossexTimerTextView.setTextColor(Color.BLACK);
                        mode.finish();
                        ret = true;
                        break;
                    }
                    return ret;
                }
            });
            return true;
        }
    });
}

From source file:it.mb.whatshare.MainActivity.java

/**
 * Refreshes the layout of this activity, also reloading configured devices
 * from files.// ww w. j a  v  a2 s  .co  m
 */
private void updateLayout() {
    if (outboundDevice == null) {
        try {
            Pair<PairedDevice, String> paired = SendToGCMActivity.loadOutboundPairing(this);
            if (paired != null)
                outboundDevice = paired.first;
        } catch (OptionalDataException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // it's ok
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    final TextView outboundView = (TextView) findViewById(R.id.outbound_device);
    if (outboundDevice != null) {
        outboundView.setText(outboundDevice.type);
    } else {
        outboundView.setText(R.string.no_device);
    }

    final boolean outboundConfigured = outboundDevice != null;
    outboundView.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (outboundConfigured) {
                Dialogs.confirmRemoveOutbound(outboundDevice, MainActivity.this);
            } else {
                showOutboundConfiguration();
            }
            return true;
        }
    });
}

From source file:com.coinblesk.client.CurrentBalanceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_balance, container, false);

    recyclerView = (RecyclerView) view.findViewById(R.id.txhistoryview);
    View empty = view.findViewById(R.id.txhistory_emptyview);
    recyclerView.setEmptyView(empty);//from  w ww .  jav a 2s .  c om
    transactionAdapter = new TransactionWrapperRecyclerViewAdapter(new ArrayList<TransactionWrapper>());
    recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
    recyclerView.setAdapter(transactionAdapter);
    updateTransactions();

    ImageView switcher = (ImageView) view.findViewById(R.id.balance_switch_image_view);
    switcher.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (SharedPrefUtils.isBitcoinPrimaryBalance(getActivity())) {
                SharedPrefUtils.setFiatPrimaryBalance(getActivity());
            } else {
                SharedPrefUtils.setBitcoinPrimaryBalance(getActivity());
            }
            refreshBalance();
        }
    });

    TextView t1 = (TextView) view.findViewById(R.id.balance_large);
    TextView t2 = (TextView) view.findViewById(R.id.balance_large_currency);
    TextView t3 = (TextView) view.findViewById(R.id.balance_small);
    TextView t4 = (TextView) view.findViewById(R.id.balance_small_currency);

    View.OnLongClickListener listener = new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            DialogFragment fragment = CurrencyDialogFragment.newInstance();
            if (fragment != null) {
                fragment.show(CurrentBalanceFragment.this.getFragmentManager(), TAG);
            }
            return true;
        }
    };

    t1.setOnLongClickListener(listener);
    t2.setOnLongClickListener(listener);
    t3.setOnLongClickListener(listener);
    t4.setOnLongClickListener(listener);
    return view;
}

From source file:com.github.kanata3249.ffxieq.android.AugmentSelectorActivity.java

@Override
protected void onStart() {
    super.onStart();

    AugmentListView lv;//w w w  .  jav a 2  s . c  o  m

    lv = (AugmentListView) findViewById(R.id.ListView);
    if (lv != null) {
        lv.setFilterByID(mFilterID);
        lv.setOrderByName(mOrderByName);
        lv.setFilterByType(mFilterByType);
        lv.setParam(getDAO(), mPart, mRace, mJob, mLevel);

        lv.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                Intent result = new Intent();

                result.putExtra("From", "AugmentSelector");
                result.putExtra("Part", mPart);
                result.putExtra("Id", -1);
                result.putExtra("AugId", arg3);
                setResult(RESULT_OK, result);
                finish();
            }

        });

        lv.setOnItemLongClickListener(new OnItemLongClickListener() {
            public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                mLongClickingItemId = arg3;
                AugmentSelectorActivity.this.openContextMenu(arg0);
                return true;
            }
        });

        registerForContextMenu(lv);
    }

    {
        Equipment cur = getDAO().instantiateEquipment(mCurrent, mAugID);
        if (cur == null) {
            cur = new Equipment(-1, getString(R.string.EquipmentNotSelected), "", "", "", "", 0, 0, false,
                    false, "");
        }
        if (cur != null) {
            TextView tv;
            View.OnLongClickListener listener = new View.OnLongClickListener() {
                public boolean onLongClick(View v) {
                    mLongClickingItemId = mAugID;
                    AugmentSelectorActivity.this.openContextMenu(v);
                    return true;
                }
            };

            tv = (TextView) findViewById(R.id.Name);
            if (tv != null) {
                tv.setText(cur.getName());
                tv.setOnLongClickListener(listener);
                registerForContextMenu(tv);
            }
            tv = (TextView) findViewById(R.id.Job);
            if (tv != null) {
                tv.setText(cur.getJob());
                tv.setOnLongClickListener(listener);
                registerForContextMenu(tv);
            }
            tv = (TextView) findViewById(R.id.Description);
            if (tv != null) {
                tv.setText(cur.getDescription());
                tv.setOnLongClickListener(listener);
                registerForContextMenu(tv);
            }
            tv = (TextView) findViewById(R.id.Augment);
            if (tv != null) {
                if (cur.getAugment().length() == 0) {
                    tv.setHeight(0);
                } else {
                    tv.setText(cur.getAugment());
                }
                tv.setOnLongClickListener(listener);
                registerForContextMenu(tv);
            }
            tv = (TextView) findViewById(R.id.Level);
            if (tv != null) {
                if (tv != null) {
                    int lvl = cur.getLevel();
                    if (lvl > 0)
                        tv.setText(((Integer) lvl).toString());
                    else
                        tv.setText("");
                }
                tv.setOnLongClickListener(listener);
                registerForContextMenu(tv);
            }
            tv = (TextView) findViewById(R.id.Race);
            if (tv != null) {
                tv.setText(cur.getRace());
                tv.setOnLongClickListener(listener);
                registerForContextMenu(tv);
            }
            tv = (TextView) findViewById(R.id.Ex);
            if (tv != null) {
                if (cur.isEx())
                    tv.setVisibility(View.VISIBLE);
                else
                    tv.setVisibility(View.INVISIBLE);
                tv.setOnLongClickListener(listener);
                registerForContextMenu(tv);
            }
            tv = (TextView) findViewById(R.id.Rare);
            if (tv != null) {
                if (cur.isRare())
                    tv.setVisibility(View.VISIBLE);
                else
                    tv.setVisibility(View.INVISIBLE);
                tv.setOnLongClickListener(listener);
                registerForContextMenu(tv);
            }

        }
    }
}