Example usage for android.widget ImageView getContext

List of usage examples for android.widget ImageView getContext

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:com.mooc.viewpage_photoview_circleindicator.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    //?//from  ww  w  .  j  av  a 2s . c  om
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);//???bitmap??
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    //
    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    mBaseRotation = 0.0f;

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}

From source file:co.taqat.call.CallActivity.java

private void setContactInformation(TextView contactName, ImageView contactPicture, LinphoneAddress lAddress) {
    LinphoneContact lContact = ContactsManager.getInstance().findContactFromAddress(lAddress);
    if (lContact == null) {
        contactName.setText(LinphoneUtils.getAddressDisplayName(lAddress));
        contactPicture.setImageResource(R.drawable.avatar);
    } else {/*from  www.j av  a  2s.  co  m*/
        contactName.setText(lContact.getFullName());
        LinphoneUtils.setImagePictureFromUri(contactPicture.getContext(), contactPicture,
                lContact.getPhotoUri(), lContact.getThumbnailUri());
    }
}

From source file:org.linphone.CallActivity.java

private void setContactInformation(TextView contactName, ImageView contactPicture, LinphoneAddress lAddress) {
    LinphoneContact lContact = ContactsManager.getInstance().findContactFromAddress(lAddress);
    if (lContact == null) {
        contactName.setText(LinphoneUtils.getAddressDisplayName(lAddress));
        contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
    } else {//from ww w  .  j a  v a 2 s  .  c o m
        contactName.setText(lContact.getFullName());
        LinphoneUtils.setImagePictureFromUri(contactPicture.getContext(), contactPicture,
                lContact.getPhotoUri(), lContact.getThumbnailUri());
    }
}

From source file:uk.co.senab.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView, PdfiumCore pdfiumCore, PdfDocument pdfDocument, int pageIndex,
        float pageScale, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    this.pdfiumCore = pdfiumCore;
    this.pdfDocument = pdfDocument;
    this.pageIndex = pageIndex;

    pdfiumCore.openPage(pdfDocument, pageIndex);
    originalBitmapSize.set((int) (pageScale * pdfiumCore.getPageWidthPoint(pdfDocument, pageIndex)),
            (int) (pageScale * pdfiumCore.getPageHeightPoint(pdfDocument, pageIndex)));

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;/*from  w  ww. jav  a 2  s. c om*/
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    // Finally, update the UI so that we're zoomable

    setZoomable(zoomable);
}

From source file:com.mooc.viewpage_photoview_circleindicator.photoview.PhotoViewAttacher.java

/**
 * Calculate Matrix for FIT_CENTER/* w  w  w  .  j  a va2s.  c  o m*/
 *
 * @param d - Drawable being displayed
 */
private void updateBaseMatrix(Drawable d, boolean isFirst) {
    ImageView imageView = getImageView();
    if (null == imageView || null == d) {
        return;
    }

    //?ImageViewdrawable
    final float viewWidth = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    final int drawableWidth = d.getIntrinsicWidth();
    final int drawableHeight = d.getIntrinsicHeight();

    mBaseMatrix.reset();

    final float widthScale = viewWidth / drawableWidth;
    final float heightScale = viewHeight / drawableHeight;

    if (mScaleType == ScaleType.CENTER) {
        mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F);

    } else if (mScaleType == ScaleType.CENTER_CROP) {
        float scale = Math.max(widthScale, heightScale);
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else if (mScaleType == ScaleType.CENTER_INSIDE) {
        float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else {
        RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
        RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);

        if ((int) mBaseRotation % 180 != 0) {
            mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth);
        }

        switch (mScaleType) {

        case FIT_CENTER:
            //scaleType

            final float mutiple = (float) PhotoViewHelper.screenWidth(imageView.getContext())
                    / ((float) drawableWidth);

            mBaseMatrix.setScale(mutiple, mutiple, 0, 0);

            //                    mBaseMatrix
            //                            .setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);

            break;

        case FIT_START:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
            break;

        case FIT_END:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
            break;

        case FIT_XY:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
            break;

        default:
            break;
        }
    }

    resetMatrix();
}

From source file:maimeng.yodian.app.client.android.chat.adapter.MessageAdapter.java

/**
 * start image into image view/*from   w w  w. j  a va  2 s . c  om*/
 *
 * @param thumbernailPath
 * @param iv
 * @return the image exists or not
 */
private boolean showImageView(final String thumbernailPath, final ImageView iv, final String localFullSizePath,
        String remoteDir, final EMMessage message) {
    // String imagename =
    // localFullSizePath.substring(localFullSizePath.lastIndexOf("/") + 1,
    // localFullSizePath.length());
    // final String remote = remoteDir != null ? remoteDir+imagename :
    // imagename;
    final String remote = remoteDir;
    EMLog.d("###", "local = " + localFullSizePath + " remote: " + remote);
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(thumbernailPath);
    if (bitmap != null && false) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EMLog.d(TAG, "image view on click");
                Intent intent = new Intent(activity, ShowBigImage.class);
                File file = new File(localFullSizePath);
                if (file.exists()) {
                    Uri uri = Uri.fromFile(file);
                    intent.putExtra("uri", uri);
                    EMLog.d(TAG, "here need to check why download everytime");
                } else {
                    // The local full size pic does not exist yet.
                    // ShowBigImage needs to download it from the server
                    // first
                    // intent.putExtra("", message.get);
                    ImageMessageBody body = (ImageMessageBody) message.getBody();
                    intent.putExtra("secret", body.getSecret());
                    intent.putExtra("remotepath", remote);
                }
                if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat
                        && message.getChatType() != ChatType.ChatRoom) {
                    try {
                        EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                        message.isAcked = true;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                Bundle options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, iv, "img")
                        .toBundle();
                ActivityCompat.startActivity(activity, intent, options);
            }
        });
        return true;
    } else {
        new LoadImageTask().execute(thumbernailPath, localFullSizePath, remote, message.getChatType(), iv,
                activity, message, iv.getContext());
        return true;
    }

}

From source file:im.vector.adapters.VectorRoomSummaryAdapter.java

/**
 * Compute the View that should be used to render the child,
 * given its position and its groups position
 *///from   w  w  w  . j a v  a 2 s.com
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
        ViewGroup parent) {
    // sanity check
    if (null == mSummaryListByGroupPosition) {
        return null;
    }
    if (convertView == null) {
        convertView = mLayoutInflater.inflate(mChildLayoutResourceId, parent, false);
    }

    if (!mMxSession.isAlive()) {
        return convertView;
    }

    int roomNameBlack = ThemeUtils.getColor(mContext, R.attr.riot_primary_text_color);
    int fushiaColor = ContextCompat.getColor(mContext, R.color.vector_fuchsia_color);
    int vectorDefaultTimeStampColor = ThemeUtils.getColor(mContext, R.attr.default_text_light_color);
    int vectorGreenColor = ContextCompat.getColor(mContext, R.color.vector_green_color);
    int vectorSilverColor = ContextCompat.getColor(mContext, R.color.vector_silver_color);

    // retrieve the UI items
    ImageView avatarImageView = convertView.findViewById(R.id.room_avatar);
    TextView roomNameTxtView = convertView.findViewById(R.id.roomSummaryAdapter_roomName);
    TextView roomMsgTxtView = convertView.findViewById(R.id.roomSummaryAdapter_roomMessage);
    View bingUnreadMsgView = convertView.findViewById(R.id.bing_indicator_unread_message);
    TextView timestampTxtView = convertView.findViewById(R.id.roomSummaryAdapter_ts);
    View separatorView = convertView.findViewById(R.id.recents_separator);
    View separatorGroupView = convertView.findViewById(R.id.recents_groups_separator_line);
    final View actionView = convertView.findViewById(R.id.roomSummaryAdapter_action);
    final ImageView actionImageView = convertView.findViewById(R.id.roomSummaryAdapter_action_image);
    TextView unreadCountTxtView = convertView.findViewById(R.id.roomSummaryAdapter_unread_count);
    View directChatIcon = convertView.findViewById(R.id.room_avatar_direct_chat_icon);
    View encryptedIcon = convertView.findViewById(R.id.room_avatar_encrypted_icon);

    View invitationView = convertView.findViewById(R.id.recents_groups_invitation_group);
    Button preViewButton = convertView.findViewById(R.id.recents_invite_preview_button);
    Button rejectButton = convertView.findViewById(R.id.recents_invite_reject_button);

    View showMoreView = convertView.findViewById(R.id.roomSummaryAdapter_show_more_layout);
    View actionClickArea = convertView.findViewById(R.id.roomSummaryAdapter_action_click_area);

    // directory management
    if ((mDirectoryGroupPosition == groupPosition) || (mRoomByAliasGroupPosition == groupPosition)) {
        // some items are show
        bingUnreadMsgView.setVisibility(View.INVISIBLE);
        timestampTxtView.setVisibility(View.GONE);
        actionImageView.setVisibility(View.GONE);
        invitationView.setVisibility(View.GONE);
        separatorView.setVisibility(View.GONE);
        separatorGroupView.setVisibility(View.VISIBLE);
        showMoreView.setVisibility(View.VISIBLE);
        actionClickArea.setVisibility(View.GONE);
        unreadCountTxtView.setVisibility(View.GONE);
        directChatIcon.setVisibility(View.GONE);
        encryptedIcon.setVisibility(View.GONE);

        if (mDirectoryGroupPosition == groupPosition) {
            roomNameTxtView.setText(mContext.getResources().getString(R.string.directory_search_results_title));

            if (!TextUtils.isEmpty(mSearchedPattern)) {
                if (null == mMatchedPublicRoomsCount) {
                    roomMsgTxtView
                            .setText(mContext.getResources().getString(R.string.directory_searching_title));
                } else {
                    String value = mMatchedPublicRoomsCount.toString();

                    if (mMatchedPublicRoomsCount >= PublicRoomsManager.PUBLIC_ROOMS_LIMIT) {
                        value = "> " + PublicRoomsManager.PUBLIC_ROOMS_LIMIT;
                    }

                    roomMsgTxtView.setText(
                            mContext.getResources().getQuantityString(R.plurals.directory_search_rooms_for,
                                    mMatchedPublicRoomsCount, value, mSearchedPattern));
                }
            } else {
                if (null == mPublicRoomsCount) {
                    roomMsgTxtView.setText(null);
                } else {
                    roomMsgTxtView.setText(mContext.getResources().getQuantityString(
                            R.plurals.directory_search_rooms, mPublicRoomsCount, mPublicRoomsCount));
                }
            }

            avatarImageView.setImageBitmap(VectorUtils.getAvatar(avatarImageView.getContext(),
                    VectorUtils.getAvatarColor(null), null, true));
        } else {
            roomNameTxtView.setText(mSearchedPattern);
            roomMsgTxtView.setText("");
            avatarImageView.setImageBitmap(VectorUtils.getAvatar(avatarImageView.getContext(),
                    VectorUtils.getAvatarColor(null), "@", true));
        }
        return convertView;
    }

    showMoreView.setVisibility(View.GONE);

    RoomSummary childRoomSummary = mSummaryListByGroupPosition.get(groupPosition).get(childPosition);
    final Room childRoom = mMxSession.getDataHandler().getStore().getRoom(childRoomSummary.getRoomId());
    int unreadMsgCount = childRoomSummary.getUnreadEventsCount();
    int highlightCount = 0;
    int notificationCount = 0;

    if (null != childRoom) {
        highlightCount = childRoom.getHighlightCount();
        notificationCount = childRoom.getNotificationCount();

        if (mMxSession.getDataHandler().getBingRulesManager().isRoomMentionOnly(childRoom.getRoomId())) {
            notificationCount = highlightCount;
        }
    }

    // get last message to be displayed
    CharSequence lastMsgToDisplay = getChildMessageToDisplay(childRoomSummary);

    // display the room avatar
    final String roomName = VectorUtils.getRoomDisplayName(mContext, mMxSession, childRoom);
    VectorUtils.loadRoomAvatar(mContext, mMxSession, avatarImageView, childRoom);

    // display the room name
    roomNameTxtView.setText(roomName);
    roomNameTxtView.setTextColor(roomNameBlack);
    roomNameTxtView.setTypeface(null, (0 != unreadMsgCount) ? Typeface.BOLD : Typeface.NORMAL);

    // display the last message
    roomMsgTxtView.setText(lastMsgToDisplay);

    // set the timestamp
    timestampTxtView.setText(getFormattedTimestamp(childRoomSummary.getLatestReceivedEvent()));
    timestampTxtView.setTextColor(vectorDefaultTimeStampColor);
    timestampTxtView.setTypeface(null, Typeface.NORMAL);

    // set bing view background colour
    int bingUnreadColor;
    if (0 != highlightCount) {
        bingUnreadColor = fushiaColor;
    } else if (0 != notificationCount) {
        bingUnreadColor = vectorGreenColor;
    } else if (0 != unreadMsgCount) {
        bingUnreadColor = vectorSilverColor;
    } else {
        bingUnreadColor = Color.TRANSPARENT;
    }
    bingUnreadMsgView.setBackgroundColor(bingUnreadColor);

    // display the unread badge counter
    if ((0 != notificationCount)) {
        unreadCountTxtView.setVisibility(View.VISIBLE);
        unreadCountTxtView.setText(String.valueOf(notificationCount));
        unreadCountTxtView.setTypeface(null, Typeface.BOLD);
        setUnreadBackground(unreadCountTxtView, bingUnreadColor);
    } else {
        unreadCountTxtView.setVisibility(View.GONE);
    }

    // some items are shown
    boolean isInvited = false;

    if (null != childRoom) {
        isInvited = childRoom.isInvited();
    }

    if (null != childRoom) {
        directChatIcon.setVisibility(
                RoomUtils.isDirectChat(mMxSession, childRoom.getRoomId()) ? View.VISIBLE : View.GONE);
        encryptedIcon.setVisibility(childRoom.isEncrypted() ? View.VISIBLE : View.GONE);
    } else {
        directChatIcon.setVisibility(View.GONE);
        encryptedIcon.setVisibility(View.GONE);
    }

    bingUnreadMsgView.setVisibility(isInvited ? View.INVISIBLE : View.VISIBLE);
    invitationView.setVisibility(isInvited ? View.VISIBLE : View.GONE);

    final String fRoomId = childRoomSummary.getRoomId();

    if (isInvited) {
        actionClickArea.setVisibility(View.GONE);

        preViewButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mListener) {
                    mListener.onPreviewRoom(mMxSession, fRoomId);
                }
            }
        });

        rejectButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mListener) {
                    mListener.onRejectInvitation(mMxSession, fRoomId);
                }
            }
        });

        // display an exclamation mark like the webclient
        unreadCountTxtView.setVisibility(View.VISIBLE);
        unreadCountTxtView.setText("!");
        unreadCountTxtView.setTypeface(null, Typeface.BOLD);
        setUnreadBackground(unreadCountTxtView, fushiaColor);
        timestampTxtView.setVisibility(View.GONE);
        actionImageView.setVisibility(View.GONE);
    } else {

        final boolean isFavorite = groupPosition == mFavouritesGroupPosition;
        final boolean isLowPrior = groupPosition == mLowPriorGroupPosition;

        actionClickArea.setVisibility(View.VISIBLE);
        actionClickArea.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RoomUtils.displayPopupMenu(mContext, mMxSession, childRoom, actionView, isFavorite, isLowPrior,
                        mMoreActionListener);
            }
        });

        timestampTxtView.setVisibility(mIsSearchMode ? View.INVISIBLE : View.VISIBLE);
        actionImageView.setVisibility(mIsSearchMode ? View.INVISIBLE : View.VISIBLE);
    }

    separatorView.setVisibility(isLastChild ? View.GONE : View.VISIBLE);
    separatorGroupView
            .setVisibility((isLastChild && ((groupPosition + 1) < getGroupCount())) ? View.VISIBLE : View.GONE);

    return convertView;
}