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:galilei.kelimekavanozu.activity.PoemBuilderActivity.java

private void shuffleWords() {
    wordsContainer.removeAllViews();//from   w  w  w .j av  a 2 s  . c o  m

    final List<String> wordList = wordBank.loadWords();
    for (String w : wordList) {
        final TextView wordView = (TextView) getLayoutInflater().inflate(R.layout.word, null, true);
        wordView.setText(w);
        wordView.setOnTouchListener(new WordTouchListener());
        wordView.setTag(w);
        wordsContainer.addView(wordView);
    }

    Crashlytics.setInt(App.CRASHLYTICS_KEY_WORDBANK_COUNT, wordList.size());
}

From source file:com.kasungunathilaka.sarigama.ui.HomeActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        onBackPressed();/*from ww  w.  java2 s  .c o  m*/
        break;
    case R.id.action_search:
        setFragment(new SearchFragment());
        break;
    case R.id.action_about_developer:
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(HomeActivity.this);
        View dialogView = getLayoutInflater().inflate(R.layout.dialog_view_about_developer, null);
        alertDialogBuilder.setView(dialogView);
        ImageView ivClose = (ImageView) dialogView.findViewById(R.id.ivClose);
        TextView tvEmail = (TextView) dialogView.findViewById(R.id.tvEmail);
        final AlertDialog alertDialog = alertDialogBuilder.create();
        tvEmail.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    Intent emailIntent = new Intent(Intent.ACTION_SEND);
                    emailIntent.setType("plain/text");
                    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                            new String[] { "developer.kasun.gunathilaka@gmail.com" });
                    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Sarigama");
                    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
                    startActivity(emailIntent);
                    alertDialog.dismiss();
                }
                return false;
            }
        });
        ivClose.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    alertDialog.dismiss();
                }
                return false;
            }
        });
        alertDialog.show();
        break;
    case R.id.action_exit:
        finish();
        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(9999);
        System.exit(0);
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:eu.geopaparazzi.core.maptools.FeaturePageAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final Feature feature = featuresList.get(position);

    int bgColor = Compat.getColor(context, eu.geopaparazzi.library.R.color.formbgcolor);
    int textColor = Compat.getColor(context, eu.geopaparazzi.library.R.color.formcolor);

    ScrollView scrollView = new ScrollView(context);
    ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);//from w w  w  .j av  a  2s . co  m
    scrollLayoutParams.setMargins(10, 10, 10, 10);
    scrollView.setLayoutParams(scrollLayoutParams);
    scrollView.setBackgroundColor(bgColor);

    LinearLayout linearLayoutView = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    int margin = 10;
    layoutParams.setMargins(margin, margin, margin, margin);
    linearLayoutView.setLayoutParams(layoutParams);
    linearLayoutView.setOrientation(LinearLayout.VERTICAL);
    int padding = 10;
    linearLayoutView.setPadding(padding, padding, padding, padding);
    scrollView.addView(linearLayoutView);

    List<String> attributeNames = feature.getAttributeNames();
    List<String> attributeValues = feature.getAttributeValuesStrings();
    List<String> attributeTypes = feature.getAttributeTypes();
    for (int i = 0; i < attributeNames.size(); i++) {
        final String name = attributeNames.get(i);
        String value = attributeValues.get(i);
        String typeString = attributeTypes.get(i);
        EDataType type = EDataType.getType4Name(typeString);

        TextView textView = new TextView(context);
        textView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        textView.setPadding(padding, padding, padding, padding);
        textView.setText(name);
        textView.setTextColor(textColor);
        // textView.setTextAppearance(context, android.R.style.TextAppearance_Medium);

        linearLayoutView.addView(textView);

        final TextView editView = getEditView(feature, name, type, value);
        LinearLayout.LayoutParams editViewParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        editViewParams.setMargins(margin, 0, margin, 0);
        editView.setLayoutParams(editViewParams);
        editView.setPadding(padding * 2, padding, padding * 2, padding);
        editView.setFocusable(!isReadOnly);

        if (isReadOnly) {
            editView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    String text = editView.getText().toString();
                    FeatureUtilities.viewIfApplicable(v.getContext(), text);
                    return false;
                }
            });
        }
        linearLayoutView.addView(editView);
    }

    /*
     * add also area and length
     */
    if (feature.getOriginalArea() > -1) {
        TextView areaTextView = new TextView(context);
        areaTextView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        areaTextView.setPadding(padding, padding, padding, padding);
        areaTextView.setText(context.getString(eu.geopaparazzi.core.R.string.area_colon)
                + areaLengthFormatter.format(feature.getOriginalArea()));
        areaTextView.setTextColor(textColor);
        TextView lengthTextView = new TextView(context);
        lengthTextView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        lengthTextView.setPadding(padding, padding, padding, padding);
        lengthTextView.setText(context.getString(eu.geopaparazzi.core.R.string.length_colon)
                + areaLengthFormatter.format(feature.getOriginalLength()));
        lengthTextView.setTextColor(textColor);
        linearLayoutView.addView(areaTextView);
        linearLayoutView.addView(lengthTextView);
    }
    container.addView(scrollView);

    return scrollView;
}

From source file:com.example.pdftranslator.ScreenSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout containing a title and body text.
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_screen_slide_page, container, false);
    String textFromPdf;//from   ww w.  j  a  v a2s. c  o  m
    TextView textViewDisplayer;
    //    LinkedHashMap<Integer, String>   letter_index = new  LinkedHashMap<Integer,String>();
    //   int i;

    try {

        textFromPdf = PdfTextExtractor.getTextFromPage(ActivityTextDisplayer.reader, mPageNumber + 1);
        textFromPdf = textArranged(textFromPdf);

        /*      for( i = 0; i < textFromPdf.length(); i++)
                 letter_index.put(i,Character.toString( textFromPdf.charAt(i)));
              ActivityTextDisplayer.letter_index = letter_index;
        */

        textViewDisplayer = (TextView) rootView.findViewById(android.R.id.text1);
        textViewDisplayer.setOnTouchListener(this);
        textViewDisplayer.setText(textFromPdf);

    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    return rootView;
}

From source file:com.pitchedapps.primenumbercalculator.Calculator.java

License:asdf

void addOnTouchListenerText(View view) {
    TextView text = (TextView) view;
    text.setOnTouchListener(new View.OnTouchListener() {
        @Override/* w  ww  .  j  a  va 2s. co m*/
        public boolean onTouch(View v, MotionEvent e) {
            x = (int) e.getX() + v.getLeft();
            y = (int) e.getY() + v.getTop();
            return false;
        }
    });
}

From source file:com.eall.installer.widget.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {

            final TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            RippleDrawable.For(tab, getResources().getColor(R.color.color_primary));
            tab.setTextColor(tabTextColor);
            tab.setOnTouchListener(new OnTouchListener() {
                @Override//ww  w  . j  a  v a2 s  .  com
                public boolean onTouch(View v, MotionEvent event) {
                    return false;
                }
            });

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
            if (i == selectedPosition) {
                RippleDrawable.For(tab, getResources().getColor(R.color.color_primary_400));
                tab.setTextColor(selectedTabTextColor);
            }
        }
    }
}

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  av a2  s  .co  m

    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:org.noise_planet.noisecapture.Results.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    boolean showTooltip = sharedPref.getBoolean("settings_tooltip", true);
    setContentView(R.layout.activity_results);
    this.measurementManager = new MeasurementManager(this);
    Intent intent = getIntent();/*  www  . ja v a2 s. c o  m*/
    if (intent != null && intent.hasExtra(RESULTS_RECORD_ID)) {
        record = measurementManager.getRecord(intent.getIntExtra(RESULTS_RECORD_ID, -1));
    } else {
        // Read the last stored record
        List<Storage.Record> recordList = measurementManager.getRecords();
        if (!recordList.isEmpty()) {
            record = recordList.get(0);
        } else {
            // Message for starting a record
            Toast.makeText(getApplicationContext(), getString(R.string.no_results), Toast.LENGTH_LONG).show();
            initDrawer();
            return;
        }
    }
    tags = measurementManager.getTags(record.getId());
    initDrawer(record.getId());
    toolTip = (ToolTipRelativeLayout) findViewById(R.id.activity_tooltip);

    // RNE PieChart
    rneChart = (PieChart) findViewById(R.id.RNEChart);
    // Disable tooltip as it crash with this view
    //if(showTooltip) {
    //    rneChart.setOnTouchListener(new ToolTipListener(this, R.string.result_tooltip_rne));
    //}
    initRNEChart();
    Legend lrne = rneChart.getLegend();
    lrne.setTextColor(Color.WHITE);
    lrne.setTextSize(8f);
    lrne.setPosition(LegendPosition.RIGHT_OF_CHART_CENTER);
    lrne.setEnabled(true);

    // NEI PieChart
    neiChart = (PieChart) findViewById(R.id.NEIChart);
    initNEIChart();

    Legend lnei = neiChart.getLegend();
    lnei.setEnabled(false);

    // Cumulated spectrum
    sChart = (BarChart) findViewById(R.id.spectrumChart);
    initSpectrumChart();
    Legend ls = sChart.getLegend();
    ls.setEnabled(false); // Hide legend

    TextView minText = (TextView) findViewById(R.id.textView_value_Min_SL);
    minText.setText(R.string.no_valid_dba_value);
    if (showTooltip) {
        ToolTipListener touchListener = new ToolTipListener(this, R.string.result_tooltip_minsl);
        minText.setOnTouchListener(touchListener);
        findViewById(R.id.textView_label_Min_SL).setOnTouchListener(touchListener);
    }

    TextView maxText = (TextView) findViewById(R.id.textView_value_Max_SL);
    maxText.setText(R.string.no_valid_dba_value);
    if (showTooltip) {
        ToolTipListener touchListener = new ToolTipListener(this, R.string.result_tooltip_maxsl);
        maxText.setOnTouchListener(touchListener);
        findViewById(R.id.textView_label_Max_SL).setOnTouchListener(touchListener);
    }

    TextView la10Text = (TextView) findViewById(R.id.textView_value_LA10);
    la10Text.setText(R.string.no_valid_dba_value);
    if (showTooltip) {
        ToolTipListener touchListener = new ToolTipListener(this, R.string.result_tooltip_la10);
        la10Text.setOnTouchListener(touchListener);
        findViewById(R.id.textView_label_la10_SL).setOnTouchListener(touchListener);
    }

    TextView la50Text = (TextView) findViewById(R.id.textView_value_LA50);
    la50Text.setText(R.string.no_valid_dba_value);
    if (showTooltip) {
        ToolTipListener touchListener = new ToolTipListener(this, R.string.result_tooltip_la50);
        la50Text.setOnTouchListener(touchListener);
        findViewById(R.id.textView_label_la50_SL).setOnTouchListener(touchListener);
    }

    TextView la90Text = (TextView) findViewById(R.id.textView_value_LA90);
    la90Text.setText(R.string.no_valid_dba_value);
    if (showTooltip) {
        ToolTipListener touchListener = new ToolTipListener(this, R.string.result_tooltip_la90);
        la90Text.setOnTouchListener(touchListener);
        findViewById(R.id.textView_label_la90_SL).setOnTouchListener(touchListener);
    }

    // Action on Map button
    Button buttonmap = (Button) findViewById(R.id.mapBtn);
    buttonmap.setEnabled(true);
    buttonmap.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Go to map page
            Intent a = new Intent(getApplicationContext(), MapActivity.class);
            a.putExtra(RESULTS_RECORD_ID, record.getId());
            startActivity(a);
            finish();
        }
    });
    View measureButton = findViewById(R.id.measureBtn);
    measureButton.setOnClickListener(new OnGoToMeasurePage(this));
    // Action on export button

    Button exportComment = (Button) findViewById(R.id.uploadBtn);
    exportComment.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            runOnUiThread(new SendResults(Results.this, record.getId()));
        }
    });

    exportComment.setEnabled(record.getUploadId().isEmpty());

    AsyncTask.execute(new LoadMeasurements(this));
}

From source file:com.android.launcher3.Hotseat.java

void resetLayout() {
    mContent.removeAllViewsInLayout();//from   w  w  w .  j  a  va 2 s  . c  o  m

    if (!FeatureFlags.NO_ALL_APPS_ICON) {
        // Add the Apps button
        Context context = getContext();
        int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank();

        LayoutInflater inflater = LayoutInflater.from(context);
        TextView allAppsButton = (TextView) inflater.inflate(R.layout.all_apps_button, mContent, false);
        Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);

        mLauncher.resizeIconDrawable(d);
        int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
        Rect bounds = d.getBounds();
        d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx,
                bounds.bottom - scaleDownPx / 2);
        allAppsButton.setCompoundDrawables(null, d, null, null);

        allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
        allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
        if (mLauncher != null) {
            mLauncher.setAllAppsButton(allAppsButton);
            allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
            allAppsButton.setOnClickListener(mLauncher);
            allAppsButton.setOnLongClickListener(mLauncher);
            allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
        }

        // Note: We do this to ensure that the hotseat is always laid out in the orientation of
        // the hotseat in order regardless of which orientation they were added
        int x = getCellXFromOrder(allAppsButtonRank);
        int y = getCellYFromOrder(allAppsButtonRank);
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1);
        lp.canReorder = false;
        mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
    }
}

From source file:org.anhonesteffort.flock.EditAutoRenewActivity.java

private void handleEnableForm() {
    Log.d(TAG, "handleEnableForm()");

    EditText cardExpirationView = (EditText) findViewById(R.id.card_expiration);
    EditText cardNumberView = (EditText) findViewById(R.id.card_number);
    TextView cardCVCView = (TextView) findViewById(R.id.card_cvc);

    cardNumberView.setFocusable(true);//from  w  ww  . j  av  a2  s .  co m
    cardNumberView.setFocusableInTouchMode(true);
    cardExpirationView.setFocusable(true);
    cardExpirationView.setFocusableInTouchMode(true);
    cardCVCView.setFocusable(true);
    cardCVCView.setFocusableInTouchMode(true);

    cardNumberView.setOnTouchListener(null);
    cardExpirationView.setOnTouchListener(null);
    cardCVCView.setOnTouchListener(null);
}