Example usage for android.widget ImageView setOnTouchListener

List of usage examples for android.widget ImageView setOnTouchListener

Introduction

In this page you can find the example usage for android.widget ImageView 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

public static void handleTouches(ImageView button) {
    button.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent m) {
            if (m.getAction() == MotionEvent.ACTION_DOWN) {
                darkenImage((ImageView) v);
            } else if (m.getAction() == MotionEvent.ACTION_UP) {
                ((ImageView) v).setColorFilter(null);
            }/*from w w w .  j  a  v a  2s  . c  om*/
            return false;
        }
    });
}

From source file:Main.java

public static void addTouchFeedback(final ImageView view) {
    view.setOnTouchListener(new View.OnTouchListener() {
        private Rect rect;

        @Override/*from   w  w  w. ja v a2 s . co  m*/
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                view.setColorFilter(Color.argb(50, 0, 0, 0));
                rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
            }
            if (event.getAction() == MotionEvent.ACTION_UP) {
                view.setColorFilter(Color.argb(0, 0, 0, 0));
            }
            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                if (!rect.contains(v.getLeft() + (int) event.getX(), v.getTop() + (int) event.getY())) {
                    view.setColorFilter(Color.argb(0, 0, 0, 0));
                }
            }
            return false;
        }
    });
}

From source file:com.ezeeideas.wordjam.TestDialog.java

private void refreshData() {
    if (mType == TEST_RESULT_PASS) {
        setContentView(R.layout.test_pass);
    } else if (mType == TEST_RESULT_FAIL) {
        setContentView(R.layout.test_fail);

        TextView title = (TextView) findViewById(R.id.test_fail_title);
        TextView text = (TextView) findViewById(R.id.test_fail_text);

        if (mAnswer.length() > 0) {
            title.setText(mContext.getResources().getString(R.string.test_fail_title_with_answer));

            String text_str = String
                    .format(mContext.getResources().getString(R.string.test_fail_text_with_answer), mAnswer);
            text.setText(text_str);//from www .  j  a va  2 s.  c o  m
        } else {
            title.setText(mContext.getResources().getString(R.string.test_fail_title_without_answer));
            text.setText(mContext.getResources().getString(R.string.test_fail_text_without_answer));
        }

        LinearLayout layout = (LinearLayout) findViewById(R.id.layout_root);
        layout.setOnTouchListener(this);

        ImageView imageView = (ImageView) findViewById(R.id.test_fail_image);
        imageView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                Utils.Log("onTouch called for layout");
                return true;
            }
        });

        /*
        imageView.setOnTouchListener(new View.OnTouchListener() {
                   
           public boolean onTouch(View v, MotionEvent event) {
              // TODO Auto-generated method stub
              Utils.Log("onTouch2 called!");
              return true;
           }
        });
        */

    } else if (mType == TEST_RESULT_SUMMARY) {
        setContentView(R.layout.test_result);

        TextView total_tests = (TextView) findViewById(R.id.test_result_total_tests);
        total_tests.setText(Integer.toString(mNumTests));

        TextView passed_tests = (TextView) findViewById(R.id.test_result_passed_tests);
        passed_tests.setText(Integer.toString(mNumTestsPassed));

        TextView hints_used = (TextView) findViewById(R.id.test_result_hints_used);
        hints_used.setText(Integer.toString(mNumHintsUsed));
    }
}

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

private void setButtonsTouchListener() {
    for (ImageView imageView : arrayButtons) {
        imageView.setOnTouchListener(this);
    }// www .j  a  va2s  .  c  om
}

From source file:org.libreoffice.impressremote.adapter.SlidesPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup aViewGroup, int aPosition) {
    ImageView aSlideView = (ImageView) getView(aViewGroup);

    if (isSlidePreviewAvailable(aPosition)) {
        setUpSlidePreview(aSlideView, aPosition);
    } else {//ww w.  ja  va 2s.  c om
        setUpUnknownSlidePreview(aSlideView);
    }

    // touch listener that handles tap and double-tap
    aSlideView.setOnTouchListener(mSlideTouchListener);

    aViewGroup.addView(aSlideView);

    return aSlideView;
}

From source file:com.facebook.android.friendsmash.RequestUserArrayAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View listItemView = inflater.inflate(R.layout.request_list_item_view, parent, false);
    ProfilePictureView profilePicView = (ProfilePictureView) listItemView
            .findViewById(R.id.requestListItemProfilePic);
    TextView nameView = (TextView) listItemView.findViewById(R.id.requestListItemName);
    final ImageView checkBox = (ImageView) listItemView.findViewById(R.id.requestListItemCheckbox);

    JSONObject currentUser = users.get(position);

    profilePicView.setProfileId(currentUser.optString("id"));
    profilePicView.setCropped(true);// ww  w .j a  va 2  s  .c  o  m
    nameView.setText(currentUser.optString("first_name"));

    checkBox.setOnTouchListener(new View.OnTouchListener() {
        boolean checked = false;

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // toggle image 
            if (checked) {
                checked = false;
                checkBox.setImageResource(R.drawable.checkbox_cold);
            } else {
                checked = true;
                checkBox.setImageResource(R.drawable.checkbox_hot);
            }
            return false;
        }
    });

    return listItemView;
}

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

/** This method initialise all the views in project */
private void initView() {
    // set song name
    TextView songName = (TextView) findViewById(R.id.songName);
    songName.setText(video.getTitle());//from   w  w  w.  ja  v a  2s  .  c  o m
    colorView.changeColorText(songName, user.getColor());

    // set short text
    TextView shortText = (TextView) findViewById(R.id.shortText);
    shortText.setText(video.getFull_name());

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

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

    TextView content = (TextView) findViewById(R.id.videoContent);
    content.setText(video.getText());

    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());

    ImageView videoImage = (ImageView) findViewById(R.id.videoImage);
    if (video.isYoutube()) {
        networkUntil.drawImageUrl(videoImage, video.GetBigImage(), R.drawable.loading);
    } else {
        networkUntil.drawImageUrl(videoImage, video.getImage_path(), R.drawable.loading);
    }

    if (!video.getDuration().equals("")) {
        TextView duration = (TextView) findViewById(R.id.duration);
        duration.setText(video.getDuration());
    }

    // set User image
    ImageView userImage = (ImageView) findViewById(R.id.image_user);
    networkUntil.drawImageUrl(userImage, video.getUser_image_path(), R.drawable.loading);
    userImage.setOnTouchListener(new View.OnTouchListener() {

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

    videoImage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (video.isYoutube()) {
                String videoId = video.getTubeId();
                Intent lVideoIntent = new Intent(null, Uri.parse("ytv://" + videoId), getApplicationContext(),
                        OpenYouTubePlayerActivity.class);
                startActivity(lVideoIntent);
            } else {
                Intent intent = new Intent(getApplicationContext(), WebviewActivity.class);
                Log.i("CHECKLINK", video.getWeb_link());
                intent.putExtra("html", video.getWeb_link());

                startActivity(intent);
            }

            return false;
        }
    });

}

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

/** This method initialise all the views in project */
private void initView() {
    buttonPlayPause = (ImageButton) findViewById(R.id.buttonPlayPause);
    buttonPlayPause.setOnClickListener(this);

    seekBarProgress = (SeekBar) findViewById(R.id.SeekBarTestPlay);
    seekBarProgress.setMax(99); // It means 100% .0-99
    seekBarProgress.setOnTouchListener(this);

    mediaPlayer = new MediaPlayer();
    mediaPlayer.setOnBufferingUpdateListener(this);
    mediaPlayer.setOnCompletionListener(this);

    try {//w  w w . j a v a2  s  . c  o  m
        mediaPlayer.setDataSource(music.getSong_path()); // setup song from
        // http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3
        // URL to
        // mediaplayer
        // data source
        mediaPlayer.prepareAsync(); // you must call this method after setup
        // the datasource in setDataSource
        // method. After calling prepare() the
        // instance of MediaPlayer starts load
        // data from URL to internal buffer.
    } catch (Exception e) {
        e.printStackTrace();
    }

    mediaFileLengthInMilliseconds = mediaPlayer.getDuration(); // gets the
    // song
    // length in
    // milliseconds
    // from URL

    // set song name
    TextView songName = (TextView) findViewById(R.id.songName);
    songName.setText(music.getTitle());
    colorView.changeColorText(songName, user.getColor());

    // set short text
    TextView shortText = (TextView) findViewById(R.id.shortText);
    shortText.setText(music.getShort_text());

    TextView time_stamp = (TextView) findViewById(R.id.time_stamp);
    time_stamp.setText(music.getTime_stamp());
    TextView total_like = (TextView) findViewById(R.id.total_like);
    total_like.setText(music.getTotal_like());
    colorView.changeColorText(total_like, user.getColor());

    TextView total_comment = (TextView) findViewById(R.id.total_comment);
    total_comment.setText(music.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());

    // set User image
    ImageView userImage = (ImageView) findViewById(R.id.image_user);
    networkUntil.drawImageUrl(userImage, music.getUser_image_path(), R.drawable.loading);
    userImage.setOnTouchListener(new View.OnTouchListener() {

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

}

From source file:com.example.slidingmenuexample.ui.NXTRemoteControl.java

private void setupUI() {
    if (mControlsMode == MODE_BUTTONS) {
        setContentView(R.layout.remote_control);

        ImageView buttonUp = (ImageView) findViewById(R.id.button_up);
        buttonUp.setOnTouchListener(new DirectionButtonOnTouchListener(1, 1));

        ImageView buttonLeft = (ImageView) findViewById(R.id.button_left);
        buttonLeft.setOnTouchListener(new DirectionButtonOnTouchListener(-0.6, 0.6));
        ImageView buttonDown = (ImageView) findViewById(R.id.button_down);
        buttonDown.setOnTouchListener(new DirectionButtonOnTouchListener(-1, -1));
        ImageView buttonRight = (ImageView) findViewById(R.id.button_right);
        buttonRight.setOnTouchListener(new DirectionButtonOnTouchListener(0.6, -0.6));

        SeekBar powerSeekBar = (SeekBar) findViewById(R.id.power_seekbar);
        powerSeekBar.setProgress(mPower);
        powerSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            @Override// w w  w. j  a  va  2 s . co m
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                mPower = progress;
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });

        mStateDisplay = (TextView) findViewById(R.id.state_display);

        mConnectButton = (ImageView) findViewById(R.id.button_b);
        mConnectButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!NO_BT) {
                    findBrick();
                } else {
                    mState = NXTTalker.STATE_CONNECTED;
                    displayState();
                }
            }
        });

        mDisconnectButton = (ImageView) findViewById(R.id.button_a);
        mDisconnectButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mNXTTalker.stop();
            }
        });

        displayState();
    }
}

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  w  w w.j a va2  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);
    }

}