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.keylesspalace.tusky.activity.ComposeActivity.java

private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
    final QueuedMedia item = new QueuedMedia(type, uri, new ImageView(this), mediaSize);
    ImageView view = item.preview;
    Resources resources = getResources();
    int side = resources.getDimensionPixelSize(R.dimen.compose_media_preview_side);
    int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
    int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(side, side);
    layoutParams.setMargins(margin, 0, margin, marginBottom);
    view.setLayoutParams(layoutParams);/*  w w  w .  j a  va 2 s. com*/
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageBitmap(preview);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            removeMediaFromQueue(item);
        }
    });
    mediaPreviewBar.addView(view);
    mediaQueued.add(item);
    int queuedCount = mediaQueued.size();
    if (queuedCount == 1) {
        /* The media preview bar is actually not inset in the EditText, it just overlays it and
         * is aligned to the bottom. But, so that text doesn't get hidden under it, extra
         * padding is added at the bottom of the EditText. */
        int totalHeight = side + margin + marginBottom;
        textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(),
                textEditor.getPaddingRight(), totalHeight);
        // If there's one video in the queue it is full, so disable the button to queue more.
        if (item.type == QueuedMedia.Type.VIDEO) {
            disableMediaPicking();
        }
    } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
        // Limit the total media attachments, also.
        disableMediaPicking();
    }
    if (queuedCount >= 1) {
        showMarkSensitive(true);
    }
    waitForMediaLatch.countUp();
    if (mediaSize > STATUS_MEDIA_SIZE_LIMIT && type == QueuedMedia.Type.IMAGE) {
        downsizeMedia(item);
    } else {
        uploadMedia(item);
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

private void setAvatar(ImageView imageView, final String email) {
    if (FriendsPlugin.SYSTEM_FRIEND.equals(email)) {
        imageView.setImageResource(R.drawable.ic_dashboard);
    } else {//from   w w  w  . j a v  a  2 s .c  o  m
        imageView.setImageBitmap(mFriendsPlugin.getAvatarBitmap(email, true));
        final SafeViewOnClickListener listener = getFriendDetailOnClickListener(email);
        if (listener != null)
            imageView.setOnClickListener(listener);
    }
}

From source file:com.aibasis.parent.adapter.MessageAdapter.java

/**
 * ?/*from www  . jav a2 s  . com*/
 * @param message
 * @param imageView
 */
private void setUserAvatar(final EMMessage message, ImageView imageView) {
    if (message.direct == Direct.SEND) {
        //?
        UserUtils.setCurrentUserAvatar(context, imageView);
    } else {
        UserUtils.setUserAvatar(context, message.getFrom(), imageView);
    }
    imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(context, UserProfileActivity.class);
            intent.putExtra("username", message.getFrom());
            context.startActivity(intent);
        }
    });
}

From source file:cm.aptoide.pt.ApkInfo.java

private void download(ViewCache cache, ViewObb obb) {
    if (category.equals(Category.ITEMBASED) || category.equals(Category.TOP)
            || category.equals(Category.TOPFEATURED) || category.equals(Category.EDITORSCHOICE)) {

        download = new ViewDownloadManagement(viewApk.getPath(), viewApk, cache, obb);

    } else {/*from  w  ww  .j av a 2 s  .c om*/

        download = new ViewDownloadManagement(viewApk.getPath(), viewApk, cache,
                db.getServer(viewApk.getRepo_id(), false).getLogin(), obb);

    }

    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            ImageView manage = (ImageView) findViewById(R.id.icon_manage);
            ////                                    manage.setVisibility(View.GONE);
            manage.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    setupQuickActions(view);
                }
            });
            findViewById(R.id.download_progress).setVisibility(View.VISIBLE);
            //                                    findViewById(R.id.icon_manage).setVisibility(View.VISIBLE);
            findViewById(R.id.downloading_name).setVisibility(View.INVISIBLE);
        }
    });

    try {

        serviceDownloadManager.callStartDownloadAndObserve(download, serviceDownloadManagerCallback);

        //                                if(mainObbUrl!=null){
        //                                    ViewApk apk = new ViewApk(viewApk.getId(), viewApk.getApkid(), viewApk.getName() + " - MainOBB", 0, "", "0", "0", "", "", viewApk.getRepo_id());
        //                                    ViewDownloadManagement download = new ViewDownloadManagement(mainObbUrl, apk, mainObbCache, true, true);
        //                                    serviceDownloadManager.callStartDownload(download);
        //                                }
        //                                serviceDownloadManager.callStartDownload();
        //                                serviceDownloadManager.callStartDownload();
    } catch (RemoteException e) {
        e.printStackTrace();
    }

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            findViewById(R.id.btinstall).setOnClickListener(installListener);
        }
    });
}

From source file:com.xiaoyu.DoctorHelp.chat.chatuidemo.adapter.MessageAdapter.java

/**
 * /*from w  w w . j  av a 2 s .  co  m*/
 *
 * @param localThumb   
 * @param iv
 * @param thumbnailUrl 
 * @param message
 */
private void showVideoThumbView(String localThumb, ImageView iv, String thumbnailUrl, final EMMessage message) {
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(localThumb);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
                EMLog.d(TAG, "video view is on click");
                Intent intent = new Intent(activity, ShowVideoActivity.class);
                intent.putExtra("localpath", videoBody.getLocalUrl());
                intent.putExtra("secret", videoBody.getSecret());
                intent.putExtra("remotepath", videoBody.getRemoteUrl());
                if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat
                        && message.getChatType() != ChatType.ChatRoom) {
                    message.isAcked = true;
                    try {
                        EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);

            }
        });

    } else {
        new LoadVideoImageTask().execute(localThumb, thumbnailUrl, iv, activity, message, this);
    }

}

From source file:cn.hbm.superwechat.adapter.MessageAdapter.java

/**
 * Super?/*from  ww  w  . ja v a2  s  . c om*/
 *
 * @param message
 * @param imageView
 */
private void setUserAvatar(final EMMessage message, ImageView imageView) {
    if (message.direct == Direct.SEND) {
        //?
        UserUtils.setMyUserAvatar(context, imageView);
    } else {
        UserUtils.setUserAvatar(context, message.getFrom(), imageView);
    }
    imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(context, UserProfileActivity.class);
            intent.putExtra("username", message.getFrom());
            intent.putExtra("groupId", message.getFrom());
            context.startActivity(intent);
        }
    });
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

private View makeHeader(ViewGroup parent, boolean button, float density) {
    if (C.API_LOLLIPOP) {
        LinearLayout linearLayout = new LinearLayout(context);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        View divider = makeSimpleDivider();
        int paddingTop = divider.getPaddingBottom();
        divider.setPadding(divider.getPaddingLeft(), divider.getPaddingTop(), divider.getPaddingRight(), 0);
        linearLayout.addView(divider, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        LinearLayout linearLayout2 = new LinearLayout(context);
        linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
        linearLayout.addView(linearLayout2, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        TextView textView = makeCommonTextView(true);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, (int) (32f * density), 1);
        layoutParams.setMargins((int) (16f * density), paddingTop, (int) (16f * density), (int) (8f * density));
        linearLayout2.addView(textView, layoutParams);
        ViewHolder holder = new ViewHolder();
        holder.text = textView;//from   w  w w  .  j a  va  2s  .  c o  m
        if (button) {
            ImageView imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.CENTER);
            imageView.setBackgroundResource(ResourceUtils.getResourceId(context,
                    android.R.attr.borderlessButtonStyle, android.R.attr.background, 0));
            imageView.setOnClickListener(headerButtonListener);
            imageView.setImageAlpha(0x5e);
            int size = (int) (48f * density);
            layoutParams = new LinearLayout.LayoutParams(size, size);
            layoutParams.rightMargin = (int) (4f * density);
            linearLayout2.addView(imageView, layoutParams);
            holder.extra = imageView;
            holder.icon = imageView;
        }
        linearLayout.setTag(holder);
        return linearLayout;
    } else {
        View view = LayoutInflater.from(context)
                .inflate(ResourceUtils.getResourceId(context, android.R.attr.preferenceCategoryStyle,
                        android.R.attr.layout, android.R.layout.preference_category), parent, false);
        ViewHolder holder = new ViewHolder();
        holder.text = (TextView) view.findViewById(android.R.id.title);
        if (button) {
            int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
            view.measure(measureSpec, measureSpec);
            int size = view.getMeasuredHeight();
            if (size == 0) {
                size = (int) (32f * density);
            }
            FrameLayout frameLayout = new FrameLayout(context);
            frameLayout.addView(view);
            view = frameLayout;
            ImageView imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            int padding = (int) (4f * density);
            imageView.setPadding(padding, padding, padding, padding);
            frameLayout.addView(imageView,
                    new FrameLayout.LayoutParams((int) (48f * density), size, Gravity.END));
            View buttonView = new View(context);
            buttonView.setBackgroundResource(
                    ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0));
            buttonView.setOnClickListener(headerButtonListener);
            frameLayout.addView(buttonView, FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.MATCH_PARENT);
            holder.extra = buttonView;
            holder.icon = imageView;
        }
        view.setTag(holder);
        return view;
    }
}

From source file:fi.mikuz.boarder.gui.internet.DownloadBoardList.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.internet_download);
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mViewPager = (ViewPager) findViewById(R.id.viewPager);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from   w  ww .j  av a  2 s .  co m
        public void onPageSelected(int position) {
            setPageTitle(position + 1);
        }
    });

    setNewViewPager();
    mSearch = (EditText) findViewById(R.id.searchInput);
    mCurrentSearch = "";
    ImageView refresh = (ImageView) findViewById(R.id.refresh);

    Button orderByDate = (Button) findViewById(R.id.orderByDate);
    Button orderByRate = (Button) findViewById(R.id.orderByRate);
    mOrderRule = ORDER_RULE_CHANGE_TIME;
    mOrderDirection = ORDER_DIRECTION_DESCENDING;
    mMaxResults = 40;

    Bundle extras = getIntent().getExtras();
    if (extras.getSerializable(InternetMenu.LOGIN_KEY) != null) {
        @SuppressWarnings("unchecked")
        HashMap<String, String> lastSession = (HashMap<String, String>) extras
                .getSerializable(InternetMenu.LOGIN_KEY);

        mLoggedIn = true;
        mUserId = lastSession.get(InternetMenu.USER_ID_KEY);
        mSessionToken = lastSession.get(InternetMenu.SESSION_TOKEN_KEY);
    }

    mSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) {
            String search = mSearch.getText().toString();
            if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN
                    && !search.equals(mCurrentSearch)) {
                mCurrentSearch = search;
                setNewViewPager();
            }
            return true;
        }
    });

    refresh.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            refreshViewPager();
        }
    });

    orderByDate.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (mOrderRule.equals(ORDER_RULE_CHANGE_TIME)
                    && mOrderDirection.equals(ORDER_DIRECTION_DESCENDING)) {
                mOrderDirection = ORDER_DIRECTION_ASCENDING;
            } else {
                mOrderRule = ORDER_RULE_CHANGE_TIME;
                mOrderDirection = ORDER_DIRECTION_DESCENDING;
            }
            setNewViewPager();
        }
    });

    orderByRate.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (mOrderRule.equals(ORDER_RULE_BOARD_RATING)
                    && mOrderDirection.equals(ORDER_DIRECTION_DESCENDING)) {
                mOrderDirection = ORDER_DIRECTION_ASCENDING;
            } else {
                mOrderRule = ORDER_RULE_BOARD_RATING;
                mOrderDirection = ORDER_DIRECTION_DESCENDING;
            }
            setNewViewPager();
        }
    });

}

From source file:com.yisheng.ysim.main.fragment.MainActivity.java

/**
 * init views//from   www . j av a 2  s  .com
 */
private void initView() {
    unreadLabel = (TextView) findViewById(R.id.unread_msg_number);
    unreadAddressLable = (TextView) findViewById(R.id.unread_address_number);
    titleLayout = (RelativeLayout) findViewById(R.id.title);
    mTabs = new Button[5];
    mTabs[0] = (Button) findViewById(R.id.btn_conversation);
    mTabs[1] = (Button) findViewById(R.id.btn_cs);
    mTabs[2] = (Button) findViewById(R.id.btn_address_list);
    mTabs[3] = (Button) findViewById(R.id.btn_find);
    mTabs[4] = (Button) findViewById(R.id.btn_profile);
    // select first tab
    mTabs[0].setSelected(true);

    final ImageView ivAdd = (ImageView) findViewById(R.id.iv_add);
    final FXPopWindow fxPopWindow = new FXPopWindow(this, R.layout.fx_popupwindow_add,
            new FXPopWindow.OnItemClickListener() {
                @Override
                public void onClick(int position) {
                    switch (position) {
                    //??
                    case 0:
                        startActivity(new Intent(MainActivity.this, GroupAddMembersActivity.class));
                        break;
                    //?
                    case 1:
                        startActivity(new Intent(MainActivity.this, AddFriendsPreActivity.class));
                        break;
                    //
                    case 2:
                        startActivity(new Intent(MainActivity.this, ScanCaptureActivity.class));
                        break;
                    //???
                    case 3:
                        break;
                    }
                }
            });
    ivAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fxPopWindow.showPopupWindow(ivAdd);
        }
    });

}

From source file:github.daneren2005.dsub.fragments.SelectDirectoryFragment.java

private void setupButtonEvents(View header) {
    ImageView shareButton = (ImageView) header.findViewById(R.id.select_album_share);
    if (share != null || podcastId != null
            || !Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_SHARED, true)
            || Util.isOffline(context) || !UserUtil.canShare() || artistInfo != null) {
        shareButton.setVisibility(View.GONE);
    } else {//from   w  ww.  ja  v a2s.  c om
        shareButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                createShare(SelectDirectoryFragment.this.entries);
            }
        });
    }

    final ImageButton starButton = (ImageButton) header.findViewById(R.id.select_album_star);
    if (directory != null && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true)
            && artistInfo == null) {
        if (directory.isStarred()) {
            starButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star));
        } else {
            starButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.star_outline));
        }
        starButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toggleStarred(directory, new OnStarChange() {
                    @Override
                    void starChange(boolean starred) {
                        if (directory.isStarred()) {
                            starButton.setImageResource(
                                    DrawableTint.getDrawableRes(context, R.attr.star_outline));
                            starButton.setImageDrawable(
                                    DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star));
                        } else {
                            starButton.setImageResource(
                                    DrawableTint.getDrawableRes(context, R.attr.star_outline));
                        }
                    }
                });
            }
        });
    } else {
        starButton.setVisibility(View.GONE);
    }

    View ratingBarWrapper = header.findViewById(R.id.select_album_rate_wrapper);
    final RatingBar ratingBar = (RatingBar) header.findViewById(R.id.select_album_rate);
    if (directory != null
            && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_RATING, true)
            && !Util.isOffline(context) && artistInfo == null) {
        ratingBar.setRating(directory.getRating());
        ratingBarWrapper.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setRating(directory, new OnRatingChange() {
                    @Override
                    void ratingChange(int rating) {
                        ratingBar.setRating(directory.getRating());
                    }
                });
            }
        });
    } else {
        ratingBar.setVisibility(View.GONE);
    }
}