Example usage for android.widget ImageView setOnClickListener

List of usage examples for android.widget ImageView setOnClickListener

Introduction

In this page you can find the example usage for android.widget ImageView setOnClickListener.

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:com.yojiokisoft.yumekanow.activity.MakeCardActivity.java

/**
 * ???//from w w w  .ja va2 s .c o m
 * 
 * @param list
 */
private void setBackImageList(List<BackImageEntity> list) {
    int cnt = mBackImgContainer.getChildCount();
    if (cnt > 0) {
        mBackImgContainer.removeAllViews();
    }
    int w = MyResource.dip2Px(53);
    int h = MyResource.dip2Px(80);
    int p = MyResource.dip2Px(3);
    int size = list.size();
    for (int i = 0; i < size; i++) {
        ImageView image = new ImageView(this);
        MyImage.setImageThum(image, list.get(i));
        image.setLayoutParams(new LinearLayout.LayoutParams(w, h));
        image.setPadding(p, p, p, p);
        image.setTag(i);
        image.setOnClickListener(mBackImageClicked);
        mBackImgContainer.addView(image);
    }
}

From source file:com.landenlabs.all_devtool.IconBaseFragment.java

/**
 * Show a 'LayerDrawable'  information./* ww  w  .  j av  a  2s.com*/
 *
 * @param imageView
 * @param row1
 * @param row2
 * @param iconD
 * @param layerIdx
 */
private void showLayerIcon(final ImageView imageView, TableRow row1, TableRow row2, Drawable iconD,
        int layerIdx) {

    if (iconD != null) {
        ImageView layerImageView = new ImageView(imageView.getContext());

        layerImageView.setImageDrawable(iconD);
        layerImageView.setPadding(10, 10, 10, 10);
        layerImageView.setMinimumHeight(8);
        layerImageView.setMinimumWidth(8);
        layerImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView.setImageDrawable(((ImageView) v).getDrawable());
            }
        });

        TextView stateTextView = new TextView(imageView.getContext());
        stateTextView.setText(String.valueOf(layerIdx));
        stateTextView.setTextSize(12);
        stateTextView.setGravity(Gravity.CENTER);

        row1.addView(stateTextView);
        row2.addView(layerImageView);
    }
}

From source file:eu.pellerito.popularmoviesproject2.fragment.DetailFragment.java

private void viewTrailer(@NonNull List<MovieTrailer> trailer) {

    if ((mContext != null) && (trailerArrayList != null)) {

        LayoutInflater layoutInflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        final String[] strKey = new String[1];

        for (int i = 0; i < trailer.size(); i++) {

            strKey[0] = trailer.get(i).getKey();

            View view = layoutInflater.inflate(R.layout.layout_trailer, layoutWrapper, false);

            LinearLayout linearLayoutWrapper = ButterKnife.findById(view, R.id.trailer_wrapper);

            LinearLayout.LayoutParams layoutParamsImage = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

            layoutParamsImage.setMargins(8, 8, 8, 8);

            if (trailerTitle != null) {
                separatorTrailer.setVisibility(View.VISIBLE);
                trailerTitle.setVisibility(View.VISIBLE);
            }//from  ww w .  ja va  2s  .c  o  m

            final ImageView image = new ImageView(mContext);
            image.setTag(trailer.get(i).getName());
            image.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.youtube));

            image.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    playTrailer(strKey[0]);
                }
            });

            LinearLayout.LayoutParams layoutParamsTextView = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

            layoutParamsTextView.setMargins(8, 8, 8, 8);

            TextView textView = new TextView(mContext);
            textView.setText(trailer.get(i).getName());
            textView.setGravity(Gravity.CENTER_VERTICAL);
            textView.setLines(2);

            linearLayoutWrapper.addView(image, layoutParamsImage);
            linearLayoutWrapper.addView(textView, layoutParamsTextView);

            if (layoutBaseTrailer != null) {
                layoutBaseTrailer.addView(linearLayoutWrapper);
            }

        }
    }
}

From source file:com.arlib.floatingsearchview.util.view.MenuView.java

/**
 * Hides all the menu items flagged with "ifRoom"
 *
 * @param withAnim/*from  ww  w  . j av  a  2  s . c o m*/
 */
public void hideIfRoomItems(boolean withAnim) {

    if (mMenu == -1)
        return;

    mActionShowAlwaysItems.clear();
    cancelChildAnimListAndClear();

    List<MenuItemImpl> showAlwaysActionItems = filter(mMenuItems, new MenuItemImplPredicate() {
        @Override
        public boolean apply(MenuItemImpl menuItem) {
            return menuItem.requiresActionButton();
        }
    });

    int actionItemIndex;
    for (actionItemIndex = 0; actionItemIndex < mActionItems.size()
            && actionItemIndex < showAlwaysActionItems.size(); actionItemIndex++) {

        final MenuItemImpl actionItem = showAlwaysActionItems.get(actionItemIndex);

        if (mActionItems.get(actionItemIndex).getItemId() != showAlwaysActionItems.get(actionItemIndex)
                .getItemId()) {

            ImageView action = (ImageView) getChildAt(actionItemIndex);
            action.setImageDrawable(Util.setIconColor(actionItem.getIcon(), mActionIconColor));

            action.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (mMenuCallback != null)
                        mMenuCallback.onMenuItemSelected(mMenuBuilder, actionItem);
                }
            });

        }

        mActionShowAlwaysItems.add(actionItem);
    }

    final int diff = mActionItems.size() - actionItemIndex + (mHasOverflow ? 1 : 0);

    anims = new ArrayList<>();

    for (int i = 0; i < actionItemIndex; i++) {
        final View currentChild = getChildAt(i);
        final float destTransX = ACTION_DIMENSION_PX * diff - (mHasOverflow ? Util.dpToPx(8) : 0);
        anims.add(ViewPropertyObjectAnimator.animate(currentChild)
                .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                .setInterpolator(new AccelerateInterpolator()).addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {

                        currentChild.setTranslationX(destTransX);
                    }
                }).translationXBy(destTransX).get());
    }

    for (int i = actionItemIndex; i < diff + actionItemIndex; i++) {

        final View currentView = getChildAt(i);

        currentView.setClickable(false);

        if (i != getChildCount() - 1)
            anims.add(ViewPropertyObjectAnimator.animate(currentView)
                    .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                    .addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {

                            currentView.setTranslationX(ACTION_DIMENSION_PX);
                        }
                    }).translationXBy(ACTION_DIMENSION_PX).get());

        anims.add(ViewPropertyObjectAnimator.animate(currentView)
                .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                .addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {

                        currentView.setScaleX(0.5f);
                    }
                }).scaleX(.5f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView)
                .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                .addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {

                        currentView.setScaleY(0.5f);
                    }
                }).scaleY(.5f).get());
        anims.add(ViewPropertyObjectAnimator.animate(getChildAt(i))
                .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                .addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {

                        currentView.setAlpha(0.0f);
                    }
                }).alpha(0.0f).get());
    }

    final int actinItemsCount = actionItemIndex;
    if (!anims.isEmpty()) {

        AnimatorSet animSet = new AnimatorSet();
        if (!withAnim)
            animSet.setDuration(0);
        animSet.playTogether(anims.toArray(new ObjectAnimator[anims.size()]));
        animSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                if (mOnVisibleWidthChanged != null)
                    mOnVisibleWidthChanged.onVisibleWidthChanged(((int) ACTION_DIMENSION_PX * actinItemsCount));
            }
        });
        animSet.start();
    }

}

From source file:com.p2c.thelife.SettingsFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    // show the progress dialog while getting the user profile
    m_progressDialog = ProgressDialog.show(getActivity(), getResources().getString(R.string.waiting),
            getResources().getString(R.string.retrieving_account), true, true);
    Server server = new Server(getActivity());
    server.queryUserProfile(TheLifeConfiguration.getOwnerDS().getId(), this, "queryUserProfile");

    // Setup button click listeners
    Button showLicenseButton = (Button) getActivity().findViewById(R.id.show_license);
    ImageView userAvatar = (ImageView) getActivity().findViewById(R.id.settings_image);
    Button updatePhotoPrompt = (Button) getActivity().findViewById(R.id.settings_update_photo_prompt);

    Button saveButton = (Button) getActivity().findViewById(R.id.button1);

    showLicenseButton.setOnClickListener(new View.OnClickListener() {
        @Override//from   w  ww  .  j a va 2  s.  co  m
        public void onClick(View v) {
            showLicense(v);
        }
    });

    userAvatar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            selectImage(v);
        }
    });

    updatePhotoPrompt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            selectImage(v);
        }
    });
    saveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setUserProfile(v);
        }
    });

    super.onViewCreated(view, savedInstanceState);
}

From source file:kr.wdream.ui.Components.PagerSlidingTabStrip.java

private void addIconTab(final int position, int resId) {
    ImageView tab = new ImageView(getContext()) {
        @Override//from w w  w. j ava  2 s .c  o m
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if (pager.getAdapter() instanceof IconTabProvider) {
                ((IconTabProvider) pager.getAdapter()).customOnDraw(canvas, position);
            }
        }
    };
    tab.setFocusable(true);
    tab.setImageResource(resId);
    tab.setScaleType(ImageView.ScaleType.CENTER);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });
    tabsContainer.addView(tab);
    tab.setSelected(position == currentPosition);
}

From source file:com.yi4all.rupics.ImageDetailActivity.java

private void initBtn() {
    topBarPanel = findViewById(R.id.image_top_bar);
    topBarPanel.setVisibility(View.GONE);

    popMenuPanel = findViewById(R.id.image_pop_menu);

    TextView tv = (TextView) findViewById(R.id.image_title_txt);
    tv.setText(issue.getCategory().getName() + "-" + issue.getName());

    ImageView back = (ImageView) findViewById(R.id.image_back_btn);
    back.setOnClickListener(new OnClickListener() {

        @Override/*from   w w  w .  j  a v  a  2s.c  o  m*/
        public void onClick(View v) {
            finish();
        }
    });

    ImageView pop = (ImageView) findViewById(R.id.image_pop_btn);
    pop.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (popMenuPanel.getVisibility() == View.VISIBLE) {
                popMenuPanel.setVisibility(View.GONE);
            } else {
                popMenuPanel.setVisibility(View.VISIBLE);
            }
        }
    });

    //      final TextView wallpaperBtn = (TextView) findViewById(R.id.wallpaperBtn);

    final TextView slideshowBtn = (TextView) findViewById(R.id.slideshowBtn);

    final TextView shareBtn = (TextView) findViewById(R.id.shareBtn);

    final TextView downloadBtn = (TextView) findViewById(R.id.downloadBtn);

    //      wallpaperBtn.setOnClickListener(new OnClickListener() {
    //         public void onClick(View v) {
    //            String img = imgList.get(imageSequence).getUrl();
    //            String path = Utils.convertUrl2Path(ImageDetailActivity.this, img);
    //            if (path != null && new File(path).exists()) {
    //               try {
    //                  ImageDetailActivity.this.setWallpaper(BitmapFactory.decodeFile(path));
    //               } catch (IOException e) {
    //                  e.printStackTrace();
    //               }
    //            } else {
    //               // give a tip to user
    //               Utils.toastMsg(ImageDetailActivity.this, R.string.noImageWallpaper);
    //            }
    //            Utils.toastMsg(ImageDetailActivity.this, R.string.setWallpaperSuccess);
    //         }
    //      });

    slideshowBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            isSlideshow = !isSlideshow;
            if (isSlideshow) {

                startSlideShow();
                topBarPanel.setVisibility(View.GONE);
                popMenuPanel.setVisibility(View.GONE);

                slideshowBtn.setText(R.string.slideshow_pause);
            } else {
                topBarPanel.setVisibility(View.VISIBLE);

                slideshowBtn.setText(R.string.slideshow);
            }

        }
    });

    shareBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            //            Intent intent = createShareIntent();
            byte[] bytes = getCurrentImage();
            if (bytes == null) {
                Utils.toastMsg(ImageDetailActivity.this, R.string.noImageShare);
            } else {
                //             ImageDetailActivity.this.startActivity(intent);
                popMenuPanel.setVisibility(View.GONE);
                UMServiceFactory.shareTo(ImageDetailActivity.this, getString(R.string.shareImageMmsBody),
                        bytes);
            }

        }
    });

    downloadBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (getService().sureLimitation()) {
                popMenuPanel.setVisibility(View.GONE);

                final ProgressDialog pd = ProgressDialog.show(ImageDetailActivity.this,
                        getString(R.string.waitTitle), getString(R.string.downloadAllImage), false, false);
                final Handler handler = new Handler() {
                    int current = 0;
                    int total = imgList.size();
                    int size = 0;

                    @Override
                    public void handleMessage(Message msg) {
                        current++;

                        pd.setMessage(getString(R.string.downloadAllImage) + current + "/" + total);

                        if (msg.arg2 > 0) {
                            size += msg.arg2;
                        }

                        if (current >= total) {
                            if (size > 0) {
                                getService().addUserConsumedKbytes(size);
                            }
                            pd.dismiss();
                        }
                    }
                };
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        for (ImageModel im : imgList) {
                            String imgUrl = im.getUrl();
                            String path = Utils.convertUrl2Path(ImageDetailActivity.this, imgUrl);
                            util.runSaveUrl(path, imgUrl, handler);
                        }

                    }
                }).start();
            }
        }
    });

}

From source file:com.arlib.floatingsearchview.util.view.MenuView.java

/**
 * Shows all the menu items that were hidden by hideIfRoomItems(boolean withAnim)
 *
 * @param withAnim//from   ww  w.  j ava  2s  . c  o m
 */
public void showIfRoomItems(boolean withAnim) {

    if (mMenu == -1)
        return;

    cancelChildAnimListAndClear();

    if (mMenuItems.isEmpty())
        return;

    anims = new ArrayList<>();

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

        final View currentView = getChildAt(i);

        if (i < mActionItems.size()) {
            ImageView action = (ImageView) currentView;
            final MenuItem actionItem = mActionItems.get(i);
            action.setImageDrawable(Util.setIconColor(actionItem.getIcon(), mActionIconColor));

            action.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (mMenuCallback != null)
                        mMenuCallback.onMenuItemSelected(mMenuBuilder, actionItem);
                }
            });
        }

        //todo go over logic
        int animDuration = withAnim ? SHOW_IF_ROOM_ITEMS_ANIM_DURATION : 0;

        Interpolator interpolator = new DecelerateInterpolator();

        //todo check logic
        if (i > mActionShowAlwaysItems.size() - 1)
            interpolator = new LinearInterpolator();

        currentView.setClickable(true);
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setTranslationX(0);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).translationX(0).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setScaleX(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).scaleX(1.0f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setScaleY(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).scaleY(1.0f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setAlpha(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).alpha(1.0f).get());
    }

    AnimatorSet animSet = new AnimatorSet();

    //temporary, from laziness
    if (!withAnim)
        animSet.setDuration(0);
    animSet.playTogether(anims.toArray(new ObjectAnimator[anims.size()]));
    animSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {

            if (mOnVisibleWidthChanged != null)
                mOnVisibleWidthChanged.onVisibleWidthChanged(
                        (getChildCount() * (int) ACTION_DIMENSION_PX) - (mHasOverflow ? Util.dpToPx(8) : 0));
        }
    });
    animSet.start();

}

From source file:de.uni_weimar.m18.anatomiederstadt.element.LocationFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_location, container, false);
    ImageView staticMapView = (ImageView) view.findViewById(R.id.staticMapView);
    Uri staticMapUri = Uri.parse("https://maps.googleapis.com/maps/api/staticmap").buildUpon()
            .appendQueryParameter("center", mLatitude + "," + mLongitude).appendQueryParameter("zoom", "17")
            .appendQueryParameter("size", "400x250")
            .appendQueryParameter("markers", "color:black|" + mLatitude + "," + mLongitude).build();

    Picasso.with(getActivity()).load(staticMapUri.toString()).into(staticMapView);

    staticMapView.setOnClickListener(new View.OnClickListener() {
        @Override//from   www .java2 s  .c  o m
        public void onClick(View v) {
            Uri gmmIntentUri = Uri.parse(
                    "geo:" + mLatitude + "," + mLongitude + "?q=" + mLatitude + "," + mLongitude + "(Ziel)");
            Log.v(LOG_TAG, "Requested location intent: " + gmmIntentUri.toString());
            Intent intent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
            intent.setPackage("com.google.android.apps.maps");
            startActivity(intent);
        }
    });

    mInfoText = (TextView) view.findViewById(R.id.locationInfoText);
    mInfoText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCheatCounter++;
            if (mCheatCounter >= 8) {
                mListener.inProximityAction(mTargetId);
            }
        }
    });
    final LocationListener locationListener = this;

    Button updateButton = (Button) view.findViewById(R.id.updateLocationButton);
    updateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInfoText != null) {
                mInfoText.setText("...");
                mInfoText.setVisibility(View.VISIBLE);
            }
            // Request location update
            LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest,
                    locationListener);
        }
    });

    return view;
}

From source file:net.konyan.yangonbusonthemap.HomeActivity.java

private void initUi(Bundle saveState) {

    ImageView ivMenu = (ImageView) findViewById(R.id.iv_action_menu);
    ivMenu.setOnClickListener(new View.OnClickListener() {
        @Override//  w  ww  .j  av a  2  s.c o  m
        public void onClick(View view) {
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            drawer.openDrawer(GravityCompat.START);
        }
    });

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    initBottomSheet();

    View view = navigationView.getHeaderView(0);
    RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.rg_language);
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int i) {
            switch (i) {
            case R.id.nav_radio_lan_en:
                language = LANGUAGE_EN;
                MyPref.putInt(KEY_LANGUAGE, LANGUAGE_EN);
                break;
            case R.id.nav_radio_lan_mm:
                language = LANGUAGE_MM;
                MyPref.putInt(KEY_LANGUAGE, LANGUAGE_MM);
                break;
            case R.id.nav_radio_lan_zg:
                language = LANGUAGE_ZG;
                MyPref.putInt(KEY_LANGUAGE, LANGUAGE_ZG);
                break;
            }

            initData();

            if (nearByMarkers != null) {
                clearMarkers(nearByMarkers, null);
            }
            if (layerLine != null) {
                layerLine.removeLayerFromMap();
            }
            if (busRouteMarkers != null) {
                clearMarkers(busRouteMarkers, null);
                currentSelectBus = -1;
            }
            mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
        }
    });

    switch (language) {
    case LANGUAGE_EN:
        ((RadioButton) view.findViewById(R.id.nav_radio_lan_en)).setChecked(true);
        break;
    case LANGUAGE_MM:
        ((RadioButton) view.findViewById(R.id.nav_radio_lan_mm)).setChecked(true);
        break;
    case LANGUAGE_ZG:
        ((RadioButton) view.findViewById(R.id.nav_radio_lan_zg)).setChecked(true);
        break;
    }

    if (saveState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.content_home, YangonMapFragment.newInstance(null, null)).commit();
    }

}