Example usage for android.view View setOnTouchListener

List of usage examples for android.view View setOnTouchListener

Introduction

In this page you can find the example usage for android.view View 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:com.syncedsynapse.kore2.ui.RemoteFragment.java

private void setupRepeatButton(View button, final ApiMethod<String> action) {
    button.setOnTouchListener(new RepeatListener(UIUtils.initialButtonRepeatInterval,
            UIUtils.buttonRepeatInterval, new View.OnClickListener() {
                @Override//from w  ww  .  java  2 s.c  o  m
                public void onClick(View v) {
                    action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler);
                }
            }, buttonInAnim, buttonOutAnim));
}

From source file:ua.com.spasetv.testintuitions.FragExerciseTwo.java

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    if (isOnTouchKeyOn) {
        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
            int item = arrayButtons.indexOf(view);
            checkAnswer(item);//from  ww w  .  ja  v a 2 s.c o  m

            view.setOnTouchListener(null); //unset touch listener on the button you pressed
            if (++numberOpenButton == CORRECT_ANSWERS_EX_TWO) {//four buttons is opened
                if (++numberRepeatExercise < REPEAT_EX_TWO) {//and going to repeat
                    isOnTouchKeyOn = false;
                    arrayButtons.get(item).startAnimation(animPauseBeforeOpenAll);
                } else {
                    isOnTouchKeyOn = false;
                    setProgressBar(numberRepeatExercise);
                    arrayButtons.get(item).startAnimation(animPauseBeforeOpenAll);
                }
            }
        }
    }
    return false;
}

From source file:com.numenta.taurus.instance.InstanceListFragment.java

@SuppressLint("ShowToast")
@Override/* w ww.j a v  a2 s.c o  m*/
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    View list = getListView();
    list.setOnTouchListener(new TouchListener(list));
    _toast = Toast.makeText(getActivity(), "", Toast.LENGTH_SHORT);
}

From source file:de.mrapp.android.dialog.AbstractMaterialDialogFragment.java

@Override
public final View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View view = inflateLayout();
    view.setOnTouchListener(createCanceledOnTouchListener());

    if (savedInstanceState != null) {
        onRestoreInstanceState(savedInstanceState);
    }/* w ww  . j av a2s . c  o m*/

    Window window = getDialog().getWindow();
    assert window != null;
    onAttachDecorators(window, view, getChildFragmentManager());
    return view;
}

From source file:de.aw.awlib.adapters.AWBaseAdapter.java

/**
 * Wird aus {@link AWBaseAdapter#onBindViewHolder(AWLibViewHolder, int)}  gerufen. Erbende
 * Klassen muesen pruefen, ob der ItemViewType < 0 ist, in diesem Fall wird eine View gezeigt,
 * die hier bearbeitet wurde.//from   www  .java2s  .c  o  m
 */
@CallSuper
@Override
public void onBindViewHolder(final AWLibViewHolder holder, final int position) {
    switch (holder.getItemViewType()) {
    case UNDODELETEVIEW:
        View view = holder.itemView.findViewById(R.id.llUndo);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int mPosition = mPendingDeleteItemPosition;
                mPendingDeleteItemPosition = NO_POSITION;
                notifyItemChanged(mPosition);
            }
        });
        TextView tv = holder.itemView.findViewById(R.id.tvGeloescht);
        tv.setText(mTextResID);
        view = holder.itemView.findViewById(R.id.llGeloescht);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (holder.getAdapterPosition() != NO_POSITION) {
                    mPendingDeleteItemPosition = NO_POSITION;
                }
                onItemDismissed(mPendingDeleteItemPosition);
            }
        });
        break;
    default:
        if (onTouchStartDragResID != -1) {
            holder.itemView.setHapticFeedbackEnabled(true);
            View handleView = holder.itemView.findViewById(onTouchStartDragResID);
            handleView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                        AWBaseAdapter.this.onStartDrag(holder);
                    }
                    if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_UP) {
                        AWBaseAdapter.this.onStopDrag(holder);
                    }
                    v.performClick();
                    return true;
                }
            });
        }
    }
}

From source file:com.syncedsynapse.kore2.ui.RemoteFragment.java

private void setupNoRepeatButton(View button, final ApiMethod<String> clickAction,
        final ApiMethod<String> longClickAction) {
    // Set animation
    button.setOnTouchListener(feedbackTouckListener);
    if (clickAction != null) {
        button.setOnClickListener(new View.OnClickListener() {
            @Override/*from   w  w w  .j a  va 2  s  . c om*/
            public void onClick(View v) {
                clickAction.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler);
            }
        });
    }
    if (longClickAction != null) {
        button.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                longClickAction.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler);
                return true;
            }
        });
    }
}

From source file:com.chess.genesis.activity.GameListOnlineFrag.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    initBaseContentFrag(container);/*from   w  w w  .ja v  a2  s  .  c  o m*/

    final View view = inflater.inflate(R.layout.fragment_gamelist_online, container, false);

    gamelistadapter_arr = new GameListAdapter[3];
    net = new NetworkClient(act, handle);
    progress = new ProgressMsg(act);

    try {
        // Set "waiting for opponent"
        final JSONArray pool = new JSONArray(Pref.getString(act, R.array.pf_poolinfo));
        final View tpool = view.findViewById(R.id.game_search);

        tpool.setVisibility((pool.length() == 0) ? View.GONE : View.VISIBLE);
        tpool.setOnClickListener(this);
        tpool.setOnTouchListener(this);
    } catch (final JSONException e) {
        throw new RuntimeException(e.getMessage(), e);
    }

    final SwipeTabsPagerAdapter tabAdapter = new SwipeTabsPagerAdapter(act, act.getSupportFragmentManager());
    tabAdapter.setTitles(new String[] { "Their Turn", "Your Turn", "Archive Games" });

    final SwipeTabs swipetabs = (SwipeTabs) view.findViewById(R.id.swipetabs);
    swipetabs.setAdapter(tabAdapter);

    pager = (ViewPager) view.findViewById(R.id.swipe_list);
    tabAdapter.setViewPager(pager);
    pager.setAdapter(new GameListPager());
    pager.setOnPageChangeListener(swipetabs);
    pager.setCurrentItem(YOUR_PAGE);

    return view;
}

From source file:com.cicada.yuanxiaobao.common.BaseAdapterHelper.java

/**
 * Sets the on touch listener of the view.
 * /*from w  ww  . j  a  v a  2s. c o  m*/
 * @param viewId
 *            The view id.
 * @param listener
 *            The on touch listener;
 * @return The BaseAdapterHelper for chaining.
 */
public BaseAdapterHelper setOnTouchListener(int viewId, View.OnTouchListener listener) {
    View view = retrieveView(viewId);
    view.setOnTouchListener(listener);
    return this;
}

From source file:com.groksolutions.grok.mobile.metric.MetricDetailFragment.java

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

    _lineChartView = (LineChartView) view.findViewById(R.id.line_chart_view);
    _lineChartView.setOnTouchListener(new TouchListener(_lineChartView));
    View instanceChartView = view.findViewById(R.id.instance_anomaly_chart);
    instanceChartView.setOnTouchListener(new TouchListener(instanceChartView));
    View metricChartView = view.findViewById(R.id.metric_anomaly_chart);
    metricChartView.setOnTouchListener(new TouchListener(metricChartView));
    view.setOnTouchListener(new TouchListener(view));

    return view;/*w  w  w  .  j  a  v  a2 s.c  om*/
}

From source file:com.social.solution.unused.AddSegment.java

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

    mSwipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
    mSwipeLayout.setProgressViewOffset(false, 150, 200);

    storedView = view;//from  w w w .  j  a  va  2s. c  om

    parentActivity = getActivity();
    mInflater = LayoutInflater.from(parentActivity);

    //imageUrls = TweetBank.getAllImageUrls();
    //imageTweets =  TweetBank.getAllNewsTweets();

    mRequestQueue = Volley.newRequestQueue(parentActivity);
    mImageLoader = new ImageLoader(mRequestQueue, new ImageLoader.ImageCache() {
        private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(10);

        public void putBitmap(String url, Bitmap bitmap) {
            mCache.put(url, bitmap);
        }

        public Bitmap getBitmap(String url) {
            return mCache.get(url);
        }
    });

    listView = (ObservableListView) view.findViewById(R.id.mylist);

    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        // Scroll to the specified position after layout
        Bundle args = getArguments();
        if (args != null && args.containsKey(ARG_INITIAL_POSITION)) {
            final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0);
            ScrollUtils.addOnGlobalLayoutListener(listView, new Runnable() {
                @Override
                public void run() {
                    // scrollTo() doesn't work, should use setSelection()
                    listView.setSelection(initialPosition);
                }
            });
        }

        // TouchInterceptionViewGroup should be a parent view other than ViewPager.
        // This is a workaround for the issue #117:
        // https://github.com/ksoichiro/Android-ObservableScrollView/issues/117
        listView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.root));
        listView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }

    View newsrowslist = (View) inflater.inflate(R.layout.newsrowslistlayout, listView, false);

    newsrowslist.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            System.out.println("pranjal danger");
            return false;
        }
    });

    //imageAdapter              = new ImageAdapter(parentActivity);
    //imageAdapterHorizontal    = new ImageAdapterHorizontal(parentActivity);

    setmydata(listView, inflater.inflate(R.layout.padding, listView, false));

    //listView.setAdapter(imageAdapterHorizontal);

    listView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //System.out.println("hello pranjal how are you");
            return false;
        }
    });

    /*
    View horizontalView  = null;
    ViewGroup imageviews = null;
    int count            = 0;
            
    for (Tweet t : imageTweets) {
    if(count == 0) {
        //horizontalView = inflater.inflate(R.layout.myhorizontalscrollviewa, null);//, true);
        horizontalView = inflater.inflate(R.layout.myhorizontalscrollviewa, container, false);
        TextView    tv = new TextView(parentActivity);
        tv.setText("POLITICS");
        newsrowslist.addView(tv);
        newsrowslist.addView(horizontalView);
        imageviews     = (ViewGroup) horizontalView.findViewById(R.id.imageviews);
    }
            
    ++count;
    count = count%5;
            
    //final View v = mInflater.inflate(R.layout.new_grid_item, null);
    final View v = mInflater.inflate(R.layout.new_grid_item, container, false);
    final SquareImageView picture = (SquareImageView) v.findViewById(R.id.picture);
    final TextView name = (TextView) v.findViewById(R.id.picturetext);
            
    name.setTag(0);
    name.setTag(R.id.action0, name.getTop());
            
    name.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int flag = (int) v.getTag();
            Layout t = name.getLayout();
            
            int left = name.getLeft();
            int right = name.getRight();
            int bottom = name.getBottom();
            
            if (flag == 0) {
                //name.setMaxLines(5);
                System.out.println("pranjal LAYOUT 0 width = " + t.getWidth() + " height " + t.getHeight());
                int top = 0;
                // l t r b
                name.layout(left, top, right, picture.getBottom());
                name.setBackgroundColor(Color.parseColor("#FF000000"));
                name.setGravity(Gravity.NO_GRAVITY);
                name.setTag(1);
            } else {
                //name.setMaxLines(2);
                System.out.println("pranjal LAYOUT 1 width = " + t.getWidth() + " height " + t.getHeight());
                int top = (int) name.getTag(R.id.action0);
            
                System.out.println("new top position is " + top);
            
                // l t r b
                name.layout(left, picture.getBottom() - 40, right, picture.getBottom());
                name.setGravity(Gravity.NO_GRAVITY);
                name.setTag(0);
            }
            return false;
        }
    });
            
    picture.setImageUrl(t.entities.media.get(0).mediaUrl, mImageLoader);
    String temp  = t.text;
    temp = temp+"\n";
    String temp1 = temp.replaceAll("http.*?\\s", " ").replaceAll("http.*?\\n", "");
    System.out.println("STRING1 "+temp+ " STRING2 "+temp1);
    name.setText(Html.fromHtml("<b>@" + t.user.screenName + "</b><br>" + temp1));
    imageviews.addView(v);
    }*/
    return view;
}