Example usage for android.widget TextView setOnTouchListener

List of usage examples for android.widget TextView setOnTouchListener

Introduction

In this page you can find the example usage for android.widget TextView setOnTouchListener.

Prototype

public void setOnTouchListener(OnTouchListener l) 

Source Link

Document

Register a callback to be invoked when a touch event is sent to this view.

Usage

From source file:Main.java

/** Suppress virtual keyboard until user's first tap */
public static void suppressVirtualKeyboard(final TextView editor) {
    final int inputType = editor.getInputType();
    editor.setInputType(InputType.TYPE_NULL);
    editor.setOnTouchListener((v, event) -> {
        editor.setInputType(inputType);/*  w ww  . j av  a2s .c om*/
        editor.setOnTouchListener(null);
        return false;
    });
}

From source file:Main.java

public static void setTextWithLinks(TextView textView, String htmlText) {
    setHtmlText(textView, htmlText);/*  w  ww  .j a  va  2 s . c  om*/
    textView.setOnTouchListener((v, event) -> {
        int action = event.getAction();
        if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
            int x = (int) event.getX();
            int y = (int) event.getY();

            TextView widget = (TextView) v;
            x -= widget.getTotalPaddingLeft();
            y -= widget.getTotalPaddingTop();

            x += widget.getScrollX();
            y += widget.getScrollY();

            Layout layout = widget.getLayout();
            int line = layout.getLineForVertical(y);
            int off = layout.getOffsetForHorizontal(line, x);

            ClickableSpan[] link = Spannable.Factory.getInstance().newSpannable(widget.getText()).getSpans(off,
                    off, ClickableSpan.class);

            if (link.length != 0) {
                if (action == MotionEvent.ACTION_UP) {
                    link[0].onClick(widget);
                }
                return true;
            }
        }
        return false;
    });
}

From source file:io.github.hidroh.materialistic.AppUtils.java

public static void setTextWithLinks(TextView textView, CharSequence html) {
    textView.setText(html);/*from   w ww . j a  v a  2 s  . c  o m*/
    // TODO https://code.google.com/p/android/issues/detail?id=191430
    //noinspection Convert2Lambda
    textView.setOnTouchListener(new View.OnTouchListener() {
        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
                int x = (int) event.getX();
                int y = (int) event.getY();

                TextView widget = (TextView) v;
                x -= widget.getTotalPaddingLeft();
                y -= widget.getTotalPaddingTop();

                x += widget.getScrollX();
                y += widget.getScrollY();

                Layout layout = widget.getLayout();
                int line = layout.getLineForVertical(y);
                int off = layout.getOffsetForHorizontal(line, x);

                ClickableSpan[] link = Spannable.Factory.getInstance().newSpannable(widget.getText())
                        .getSpans(off, off, ClickableSpan.class);

                if (link.length != 0) {
                    if (action == MotionEvent.ACTION_UP) {
                        link[0].onClick(widget);
                    }
                    return true;
                }
            }
            return false;
        }
    });
}

From source file:com.shenma.yueba.yangjia.activity.MainActivityForYangJia.java

/**
 * ?//  w  ww. j a  v a2  s . co  m
 */
private void initView() {
    TextView yangjia_msg_textview = (TextView) findViewById(R.id.yangjia_msg_textview);
    round_view = findViewById(R.id.round_view);
    registerBroadcase();
    //      yangjia_msg_textview.setOnClickListener(new OnClickListener() {
    //         
    //         @Override
    //         public void onClick(View v) {
    //            setRedView(false);
    //         }
    //      });
    TextView tv_center = (TextView) findViewById(R.id.tv_center);
    tv_center.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {//?
                //               showDialog();
                showBottomDialog();
            }
            return true;
        }
    });

    tv_center.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(MainActivityForYangJia.this, "click", 1000).show();
        }
    });
    // TabHostTabHost
    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
    // fragment
    int count = fragmentArray.length;
    for (int i = 0; i < count; i++) {
        // ?Tab?
        TabSpec tabSpec = mTabHost.newTabSpec(mTextviewArray[i]).setIndicator(getTabItemView(i));
        // TabTab?
        mTabHost.addTab(tabSpec, fragmentArray[i], null);
    }
    mTabHost.getTabWidget().setDividerDrawable(null); //tab
    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            if (tabId.equals("?")) {
                setRedView(false);
            }
        }
    });
}

From source file:org.mifos.androidclient.main.CollectionSheetActivity.java

protected void updateContent(CollectionSheetData collectionSheet) {
    if (collectionSheet != null) {
        mCollectionSheetData = collectionSheet;

        TextView textView = (TextView) findViewById(R.id.collectionSheet_centerInfo);
        textView.setText("  + " + mCenter.getDisplayName());
        textView.setOnTouchListener(this);

        if (CollectionSheetHolder.getCollectionSheetData() == null) {
            mCollectionSheetData = collectionSheet;
        } else {//ww w .  java2s.  c om
            mCollectionSheetData = CollectionSheetHolder.getCollectionSheetData();
        }

        mSelectedCustomer = CollectionSheetHolder.getCurrentCustomer();
        if (mSelectedCustomer != null) {
            updateCustomers(collectionSheet);
        }

        if (collectionSheet.getCollectionSheetCustomer() != null
                && collectionSheet.getCollectionSheetCustomer().size() > 0) {

            ExpandableListView expandableListView = (ExpandableListView) findViewById(
                    R.id.collectionSheet_entries);
            CollectionSheetExpandableListAdapter adapter = new CollectionSheetExpandableListAdapter(
                    mCollectionSheetData, this);
            expandableListView.setAdapter(adapter);
            expandableListView.setOnItemLongClickListener(this);
            expandableListView.setOnChildClickListener(this);
            ArrayList<SaveCollectionSheetCustomer> saveCollectionSheetCustomers = new ArrayList<SaveCollectionSheetCustomer>();
            prepareSaveCollectionSheet(saveCollectionSheetCustomers);
            CollectionSheetHolder.getSaveCollectionSheet();
            mSaveCustomer.setSaveCollectionSheetCustomers(saveCollectionSheetCustomers);
            CollectionSheetHolder.setSaveCollectionSheet(mSaveCustomer);
            CollectionSheetHolder.setCollectionSheetData(mCollectionSheetData);
        }
    }

}

From source file:com.abid_mujtaba.fetchheaders.AccountsActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.accounts);/*  w ww.j ava  2 s .c o  m*/

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    LinearLayout accountList = (LinearLayout) findViewById(R.id.account_list);

    LayoutInflater li = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    for (int ii = 0; ii < Account.numberOfAccounts(); ii++) {
        TextView tv = (TextView) li.inflate(R.layout.account_setting_name, null);
        tv.setText(Account.get(ii).name());
        tv.setId(ii); // Store the account_id as the view id
        tv.setOnCreateContextMenuListener(onCreateContextMenuListener);
        tv.setOnTouchListener(onTouchListener);

        tv.setOnClickListener(listener);

        accountList.addView(tv);
    }
}

From source file:net.vexelon.myglob.fragments.HomeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (Defs.LOG_ENABLED)
        Log.v(Defs.LOG_TAG, "HomeFragment.onCreateView()");

    View v = inflater.inflate(R.layout.main, container, false);

    TextView tvPhoneNumber = (TextView) v.findViewById(R.id.tv_profile_number);
    tvPhoneNumber.setOnClickListener(this);
    tvPhoneNumber.setOnTouchListener(this);

    ImageView ivSelection = (ImageView) v.findViewById(R.id.iv_user_selection);
    ivSelection.setImageResource(R.drawable.ab_default_holo_dark);

    return v;/*from   w ww .  j av  a  2s.  co m*/
}

From source file:opensourceproject.kanjisteps.Practice_slides.java

public int quizByLevelOnyomi() {
    enableButtons();//  w w w .j a va2s .  c  om
    KanjiToStudyAdapter dbAdapter = new KanjiToStudyAdapter(this);
    Cursor cursor = dbAdapter.getItemsByLevelRandom(level_marker, 0);
    TextView txt = (TextView) findViewById(R.id.textToDisplay);
    TextView txtDblTap = (TextView) findViewById(R.id.textDoubleTap);
    txtDblTap.setOnClickListener(this);
    txtDblTap.setOnTouchListener(gestureListener);
    txtDblTap.setVisibility(View.INVISIBLE);

    String temp = "";
    if (cursor.moveToNext()) {
        int indexOfKanji = cursor.getColumnIndex(dbAdapter.myKanjiDb.COLUMN_KANJI);
        temp = cursor.getString(indexOfKanji);

        txt.setText(temp);
        txt.setTextSize(50);
        txt.setTextColor(Color.GRAY);
        txt.setTag("2"); //2 means japanese READING
        populateButtonChoicesOnyomi(cursor, dbAdapter);
        return 0;
    } else {
        /*
        txt.setTextSize(20);
        txt.setTextColor(Color.GRAY);
        txt.setText("You don't have any items to review yet! Check back later.");
        resetButtons();
        */
        return 1;
    }
}

From source file:opensourceproject.kanjisteps.Practice_slides.java

public int quizByLevelMeaning() {
    enableButtons();/* ww  w . ja va2 s.  c  o  m*/
    KanjiToStudyAdapter dbAdapter = new KanjiToStudyAdapter(this);
    Cursor cursor = dbAdapter.getItemsByLevelRandom(level_marker, 1);
    TextView txt = (TextView) findViewById(R.id.textToDisplay);
    TextView txtDblTap = (TextView) findViewById(R.id.textDoubleTap);
    txtDblTap.setOnClickListener(this);
    txtDblTap.setOnTouchListener(gestureListener);
    txtDblTap.setVisibility(View.INVISIBLE);
    String temp = "";
    if (cursor.moveToNext()) {
        int indexOfKanji = cursor.getColumnIndex(dbAdapter.myKanjiDb.COLUMN_KANJI);
        temp = cursor.getString(indexOfKanji);

        txt.setText(temp);
        txt.setTextSize(50);
        txt.setTextColor(Color.GRAY);
        txt.setTag("1"); //1 means ENGLISH meaning
        populateButtonChoicesMeaning(cursor, dbAdapter);
        return 0;
    } else {
        /*
        txt.setText("You don't have any items to review yet! Check back later.");
        txt.setTextSize(20);
        txt.setTextColor(Color.GRAY);
                
        resetButtons();
        */
        return 1; //display notice that there is nothing to review yet.
    }

}

From source file:com.brodev.socialapp.view.MarketPlaceDetail.java

private void initView() {

    ImageView userImage = (ImageView) this.findViewById(R.id.image_user);

    if (!"".equals(marketPlace.getUser_image_path())) {
        networkUntil.drawImageUrl(userImage, marketPlace.getUser_image_path(), R.drawable.loading);
    }//from  ww  w . jav  a 2 s .  co  m

    userImage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Intent intent = new Intent(MarketPlaceDetail.this, FriendTabsPager.class);
            intent.putExtra("user_id", marketPlace.getUser_id());
            startActivity(intent);
            return false;
        }
    });

    // set title
    TextView title = (TextView) this.findViewById(R.id.title);
    title.setText(marketPlace.getTitle());
    colorView.changeColorText(title, user.getColor());

    // set content
    TextView content = (TextView) this.findViewById(R.id.content);

    // interesting part starts from here here:
    Html.ImageGetter ig = imageGetter.create(0, marketPlace.getText(), content);

    content.setTag(0);
    content.setText(Html.fromHtml(marketPlace.getText(), ig, null));

    TextView timestampTxt = (TextView) findViewById(R.id.txtTimestamp);
    timestampTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.posted_on"));
    TextView timestamp = (TextView) findViewById(R.id.time_stamp);
    timestamp.setText(marketPlace.getTime_stamp());
    TextView price = (TextView) this.findViewById(R.id.price);

    if (marketPlace.getPrice() == 0) {
        price.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.free"));
    } else {
        price.setText(marketPlace.getCurrency() + " " + marketPlace.getPrice());
    }

    TextView locationTxt = (TextView) findViewById(R.id.txtLocation);
    locationTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.location"));
    TextView txtLocation = (TextView) this.findViewById(R.id.location);
    String location = marketPlace.getCountry_name();

    if (!marketPlace.getCountry_child_name().equals("")) {
        location += " > " + marketPlace.getCountry_child_name();
    }
    if (!marketPlace.getCity_name().equals("")) {
        location += " > " + marketPlace.getCity_name();
    }

    txtLocation.setText(location);
    // set short text
    TextView fullnameTxt = (TextView) findViewById(R.id.txtFullname);
    fullnameTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.posted_by"));

    TextView shortText = (TextView) findViewById(R.id.fullName);
    shortText.setText(marketPlace.getFull_name());
    colorView.changeColorText(shortText, user.getColor());

    shortText.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Intent intent = new Intent(MarketPlaceDetail.this, FriendTabsPager.class);
            intent.putExtra("user_id", marketPlace.getUser_id());
            startActivity(intent);
            return false;
        }
    });

    TextView total_like = (TextView) findViewById(R.id.total_like);
    total_like.setText(String.valueOf(marketPlace.getTotal_like()));
    colorView.changeColorText(total_like, user.getColor());

    TextView total_comment = (TextView) findViewById(R.id.total_comment);
    total_comment.setText(String.valueOf(marketPlace.getTotal_comment()));
    colorView.changeColorText(total_comment, user.getColor());

    ImageView likeImg = (ImageView) this.findViewById(R.id.likes_feed_txt);
    ImageView commentImg = (ImageView) this.findViewById(R.id.comments_feed_txt);
    colorView.changeColorLikeCommnent(likeImg, commentImg, user.getColor());

    //get list images
    if (!marketPlace.getImages().equals("")) {
        LinearLayout listImages = (LinearLayout) findViewById(R.id.listImages);
        JSONObject objOutputImage = null;
        try {
            JSONArray objImages = new JSONArray(marketPlace.getImages());
            for (int i = 0; i < objImages.length(); i++) {
                objOutputImage = objImages.getJSONObject(i);
                ImageView imageView = new ImageView(getApplicationContext());

                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                        (int) getResources().getDimension(R.dimen.marketplace_image),
                        (int) getResources().getDimension(R.dimen.marketplace_image));

                lp.setMargins(5, 5, 5, 0);

                imageView.setLayoutParams(lp);

                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                final String imagePath = objOutputImage.getString("image_path");
                networkUntil.drawImageUrl(imageView, imagePath, R.drawable.loading);

                imageView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getApplicationContext(), ImageActivity.class);
                        intent.putExtra("image", imagePath);
                        intent.putExtra("title", marketPlace.getTitle());
                        startActivity(intent);
                    }
                });

                listImages.addView(imageView);

            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        this.findViewById(R.id.horizontalScrollView1).setVisibility(View.GONE);
        this.findViewById(R.id.marketplace_list_image_view).setVisibility(View.GONE);
    }

}