Java Code Examples for android.widget.ImageView#setMaxWidth()

The following examples show how to use android.widget.ImageView#setMaxWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaymentRequestSection.java    From delion with Apache License 2.0 6 votes vote down vote up
private View createIcon(GridLayout parent, int rowIndex) {
    // The icon has a pre-defined width.
    ImageView icon = new ImageView(parent.getContext());
    icon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
    icon.setBackgroundResource(R.drawable.payments_ui_logo_bg);
    icon.setImageResource(mOption.getDrawableIconId());
    icon.setMaxWidth(mIconMaxWidth);

    // The icon floats to the right of everything.
    GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams(
            GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLayout.spec(2, 1));
    iconParams.topMargin = mVerticalMargin;
    ApiCompatibilityUtils.setMarginStart(iconParams, mLargeSpacing);
    parent.addView(icon, iconParams);

    icon.setOnClickListener(OptionSection.this);
    return icon;
}
 
Example 2
Source File: PaymentRequestSection.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private View createOptionIcon(GridLayout parent, int rowIndex, boolean editIconExists) {
    // The icon has a pre-defined width.
    ImageView optionIcon = new ImageView(parent.getContext());
    optionIcon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
    optionIcon.setBackgroundResource(R.drawable.payments_ui_logo_bg);
    optionIcon.setImageDrawable(mOption.getDrawableIcon());
    optionIcon.setMaxWidth(mIconMaxWidth);

    // Place option icon at column three if no edit icon.
    int columnStart = editIconExists ? 2 : 3;
    GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams(
            GridLayout.spec(rowIndex, 1, GridLayout.CENTER),
            GridLayout.spec(columnStart, 1));
    iconParams.topMargin = mVerticalMargin;
    parent.addView(optionIcon, iconParams);

    optionIcon.setOnClickListener(OptionSection.this);
    return optionIcon;
}
 
Example 3
Source File: PagedViewWidget.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
public void applyFromAppWidgetProviderInfo(AppWidgetProviderInfo info,
        int maxWidth, int[] cellSpan, WidgetPreviewLoader loader) {
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();

    mIsAppWidget = true;
    mInfo = info;
    final ImageView image = (ImageView) findViewById(R.id.widget_preview);
    if (maxWidth > -1) {
        image.setMaxWidth(maxWidth);
    }
    final TextView name = (TextView) findViewById(R.id.widget_name);
    name.setText(info.label);
    final TextView dims = (TextView) findViewById(R.id.widget_dims);
    if (dims != null) {
        int hSpan = Math.min(cellSpan[0], (int) grid.numColumns);
        int vSpan = Math.min(cellSpan[1], (int) grid.numRows);
        dims.setText(String.format(mDimensionsFormatString, hSpan, vSpan));
    }
    mWidgetPreviewLoader = loader;
}
 
Example 4
Source File: PaymentRequestSection.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private View createOptionIcon(GridLayout parent, int rowIndex, boolean editIconExists) {
    // The icon has a pre-defined width.
    ImageView optionIcon = new ImageView(parent.getContext());
    optionIcon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
    if (mOption.isEditable()) {
        optionIcon.setMaxWidth(mEditableOptionIconMaxWidth);
    } else {
        optionIcon.setMaxWidth(mNonEditableOptionIconMaxWidth);
    }
    optionIcon.setAdjustViewBounds(true);
    optionIcon.setImageDrawable(mOption.getDrawableIcon());

    // Place option icon at column three if no edit icon.
    int columnStart = editIconExists ? 2 : 3;
    GridLayout.LayoutParams iconParams =
            new GridLayout.LayoutParams(GridLayout.spec(rowIndex, 1, GridLayout.CENTER),
                    GridLayout.spec(columnStart, 1, GridLayout.CENTER));
    iconParams.topMargin = mVerticalMargin;
    parent.addView(optionIcon, iconParams);

    optionIcon.setOnClickListener(OptionSection.this);
    return optionIcon;
}
 
Example 5
Source File: PagedViewWidget.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
public void applyFromAppWidgetProviderInfo(AppWidgetProviderInfo info,
        int maxWidth, int[] cellSpan, WidgetPreviewLoader loader) {
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();

    mIsAppWidget = true;
    mInfo = info;
    final ImageView image = (ImageView) findViewById(R.id.widget_preview);
    if (maxWidth > -1) {
        image.setMaxWidth(maxWidth);
    }
    final TextView name = (TextView) findViewById(R.id.widget_name);
    name.setText(AppWidgetManagerCompat.getInstance(getContext()).loadLabel(info));
    final TextView dims = (TextView) findViewById(R.id.widget_dims);
    if (dims != null) {
        int hSpan = Math.min(cellSpan[0], (int) grid.numColumns);
        int vSpan = Math.min(cellSpan[1], (int) grid.numRows);
        dims.setText(String.format(mDimensionsFormatString, hSpan, vSpan));
    }
    mWidgetPreviewLoader = loader;
}
 
Example 6
Source File: MoDialogView.java    From a with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 显示图像和文本
 */
public void showImageText(Bitmap bitmap, String text) {
    removeAllViews();
    LayoutInflater.from(getContext()).inflate(R.layout.mo_dialog_image_text, this, true);
    CardView cardView = findViewById(R.id.cv_content);
    cardView.setOnClickListener(null);
    ImageView imageView = findViewById(R.id.image_view);
    TextView tvCanCopy = findViewById(R.id.tv_can_copy);
    int imageWidth = Math.min(cardView.getWidth(), cardView.getHeight());
    imageView.setMaxWidth(imageWidth - 20);
    imageView.setMaxHeight(imageWidth - 20);
    imageView.setImageBitmap(bitmap);
    tvCanCopy.setText(text);
}
 
Example 7
Source File: ImageViewUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 设置 ImageView 最大宽度
 * @param imageView ImageView
 * @param maxWidth  最大宽度
 * @return {@link ImageView}
 */
public static ImageView setMaxWidth(final ImageView imageView, final int maxWidth) {
    if (imageView != null) {
        imageView.setMaxWidth(maxWidth);
    }
    return imageView;
}
 
Example 8
Source File: MoDialogView.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 显示图像和文本
 */
public void showImageText(Bitmap bitmap, String text) {
    removeAllViews();
    LayoutInflater.from(getContext()).inflate(R.layout.mo_dialog_image_text, this, true);
    CardView cardView = findViewById(R.id.cv_content);
    cardView.setOnClickListener(null);
    ImageView imageView = findViewById(R.id.image_view);
    TextView tvCanCopy = findViewById(R.id.tv_can_copy);
    int imageWidth = Math.min(cardView.getWidth(), cardView.getHeight());
    imageView.setMaxWidth(imageWidth - 20);
    imageView.setMaxHeight(imageWidth - 20);
    imageView.setImageBitmap(bitmap);
    tvCanCopy.setText(text);
}
 
Example 9
Source File: InfoLayoutHelper.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
public static void addResourceImage(Activity activity, LinearLayout layout, int imgResource, int width, int height) {
    ImageView image = new ImageView(activity);
    image.setImageResource(imgResource);
    if (width > 0) image.setMaxWidth(width);
    if (height > 0) image.setMaxHeight(height);
    image.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    layout.addView(image);
}
 
Example 10
Source File: ZjbImageLoader.java    From Android-Application-ZJB with Apache License 2.0 5 votes vote down vote up
/**
 * url的格式如下
 * http://site.com/image.png // from Web
 * file:///mnt/sdcard/image.png // from SD card
 * file:///mnt/sdcard/video.mp4 // from SD card (video thumbnail)
 * content://media/external/images/media/13 // from content provider
 * content://media/external/video/media/13 // from content provider (video thumbnail)
 * assets://image.png // from assets
 * drawable:// + R.drawable.img // from drawables (non-9patch images)
 *
 * @param view
 */
public void into(View view) {
    if (null != view) {
        //1.设置尺寸
        if (view instanceof ImageView) {
            ImageView imageView = (ImageView) view;
            if (mQiniuWidth > 0 && mQiniuHeight > 0) {
                imageView.setMaxHeight(mQiniuHeight);
                imageView.setMaxWidth(mQiniuWidth);
            }
            if (mDefaultDrawable != null) {
                imageView.setImageDrawable(mDefaultDrawable);
            } else if (mDefaultRes != 0) {
                imageView.setImageResource(mDefaultRes);
            }
        } else if (view instanceof AnimationImageView) {
            AnimationImageView imageSwitcher = (AnimationImageView) view;
            if (mQiniuWidth > 0 && mQiniuHeight > 0) {
                imageSwitcher.setQiniuHeight(mQiniuHeight);
                imageSwitcher.setQiniuWidth(mQiniuWidth);
            }
            if (mDefaultDrawable != null) {
                imageSwitcher.setImageDrawable(mDefaultDrawable);
            } else if (mDefaultRes != 0) {
                imageSwitcher.setImageResource(mDefaultRes);
            }
        }
    }

    ZjbImageLoader.display(this.mUrl, view, this.build(),
            this.mImageLoadingListener, this.mImageLoadingProgressListener);
}
 
Example 11
Source File: PaymentRequestSection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static ImageView createAndAddLogoView(ViewGroup parent, int startMargin) {
    ImageView view = new ImageView(parent.getContext());
    view.setMaxWidth(parent.getContext().getResources().getDimensionPixelSize(
            R.dimen.payments_section_logo_width));
    view.setAdjustViewBounds(true);

    // The logo has a pre-defined height and width.
    LayoutParams params =
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(params, startMargin);
    parent.addView(view, params);
    return view;
}
 
Example 12
Source File: SearchViewHacker.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void disableMagIcon(SearchView searchView) {
    ImageView searchImageView = (ImageView) findView(searchView, "mSearchHintIcon");
    searchImageView.setMaxWidth(0);
    searchImageView.setImageBitmap(null);
    searchImageView.setVisibility(View.GONE);
    searchImageView.setAdjustViewBounds(true);
}
 
Example 13
Source File: TGABitmapViewerActivity.java    From TGAReader with MIT License 5 votes vote down vote up
private ImageView createTGAImageView(String path) {
	Bitmap bitmap = createTGABitmap(path);
	if(bitmap != null) {
		ImageView imageView = new ImageView(this);
		imageView.setImageBitmap(bitmap);
		imageView.setAdjustViewBounds(true);
		imageView.setMaxWidth(128);
		imageView.setMaxHeight(128);
		imageView.setPadding(8, 8, 0, 0);
		return imageView;
	}
	return null;
}
 
Example 14
Source File: MucDetailsContextMenuHelper.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
public static boolean onContextItemSelected(MenuItem item, User user, XmppActivity activity, final String fingerprint) {
    final Conversation conversation = user.getConversation();
    final XmppConnectionService.OnAffiliationChanged onAffiliationChanged = activity instanceof XmppConnectionService.OnAffiliationChanged ? (XmppConnectionService.OnAffiliationChanged) activity : null;
    final Jid jid = user.getRealJid();
    final Account account = conversation.getAccount();
    final Contact contact = jid == null ? null : account.getRoster().getContact(jid);
    switch (item.getItemId()) {
        case R.id.action_show_avatar:
            final ImageView view = new ImageView(activity);
            view.setAdjustViewBounds(true);
            view.setMaxHeight(R.dimen.avatar_big);
            view.setMaxWidth(R.dimen.avatar_big);
            view.setBackgroundColor(Color.WHITE);
            view.setScaleType(ImageView.ScaleType.FIT_XY);
            AvatarWorkerTask.loadAvatar(user, view, R.dimen.avatar_big);
            final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setView(view);
            builder.create().show();
            return true;
        case R.id.action_contact_details:
            if (contact != null) {
                activity.switchToContactDetails(contact, fingerprint);
            }
            return true;
        case R.id.start_conversation:
            startConversation(user, activity);
            return true;
        case R.id.add_contact:
            activity.showAddToRosterDialog(contact);
            return true;
        case R.id.give_admin_privileges:
            activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.ADMIN, onAffiliationChanged);
            return true;
        case R.id.give_membership:
        case R.id.remove_admin_privileges:
        case R.id.revoke_owner_privileges:
            activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.MEMBER, onAffiliationChanged);
            return true;
        case R.id.give_owner_privileges:
            activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.OWNER, onAffiliationChanged);
            return true;
        case R.id.remove_membership:
            activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.NONE, onAffiliationChanged);
            return true;
        case R.id.kick_from_room:
            kickFromRoom(user, activity, onAffiliationChanged);
            return true;
        case R.id.ban_from_room:
            banFromRoom(user, activity, onAffiliationChanged);
            return true;
        case R.id.send_private_message:
            if (activity instanceof ConversationsActivity) {
                ConversationFragment conversationFragment = ConversationFragment.get(activity);
                if (conversationFragment != null) {
                    activity.invalidateOptionsMenu();
                    conversationFragment.privateMessageWith(user.getFullJid());
                    return true;
                }
            }
            activity.privateMsgInMuc(conversation, user.getName());
            return true;
        case R.id.invite:
            if (user.getAffiliation().ranks(MucOptions.Affiliation.MEMBER)) {
                activity.xmppConnectionService.directInvite(conversation, jid.asBareJid());
            } else {
                activity.xmppConnectionService.invite(conversation, jid);
            }
            return true;
        case R.id.context_muc_contact_block_unblock:
            try {
                activity.xmppConnectionService.sendBlockRequest(new RawBlockable(account, user.getFullJid()), false);
                activity.xmppConnectionService.leaveMuc(conversation);
                activity.xmppConnectionService.joinMuc(conversation);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return true;
        case R.id.highlight_in_muc:
            activity.highlightInMuc(conversation, user.getName());
            return true;
        default:
            return false;
    }
}
 
Example 15
Source File: MediaLayout.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
private View setupImage(String imageURI, String bigImageURI) {
    View mediaPane = null;
    try {
        int[] maxBounds = getMaxCenterViewBounds();
        final String imageFilename = ReferenceManager.instance().DeriveReference(imageURI).getLocalURI();
        final File imageFile = new File(imageFilename);
        if (imageFile.exists()) {
            Bitmap b = MediaUtil.inflateDisplayImage(getContext(), imageURI, maxBounds[0],
                    maxBounds[1]);
            if (b != null) {
                ImageView mImageView = new ImageView(getContext());
                if (useResizingImageView()) {
                    mImageView = new ResizingImageView(getContext(), imageURI, bigImageURI);
                    mImageView.setAdjustViewBounds(true);
                    mImageView.setMaxWidth(maxBounds[0]);
                    mImageView.setMaxHeight(maxBounds[1]);
                } else {
                    mImageView.setScaleType(ImageView.ScaleType.CENTER);
                }
                mImageView.setPadding(10, 10, 10, 10);
                if (imageFilename.toLowerCase().endsWith(IMAGE_GIF_EXTENSION)) {
                    Glide.with(mImageView).asGif()
                            .override(b.getWidth(), b.getHeight())
                            .load(imageFilename)
                            .into(mImageView);
                    b.recycle();
                } else {
                    mImageView.setImageBitmap(b);
                }
                mImageView.setId(IMAGE_VIEW_ID);
                mediaPane = mImageView;
            }
        } else {
            // An error hasn't been logged. We should have an image, but the file doesn't
            // exist.
            mediaPane = getMissingMediaView(imageURI,
                    StringUtils.getStringRobust(getContext(), R.string.video_download_prompt),
                    true);
        }
    } catch (InvalidReferenceException e) {
        Log.e(TAG, "image invalid reference exception");
        e.printStackTrace();
    }
    return mediaPane;
}
 
Example 16
Source File: MessageBoard.java    From apigee-android-sdk with Apache License 2.0 4 votes vote down vote up
private void createPosts() {

		//get total number of posts from Posts.java
		int numPosts = ((Messagee) this.getApplication()).messController.getPosts().getNumPosts();

		//clear all posts from llPosts
		llPosts.removeAllViews();

		//create individual post layouts and add to llPosts
		for(int i=numPosts-1; i>=0; i--){

			/*cell layout:

			  		|picture| |arrow| |Username|
			  		|		| |image| |Post ............|
			  		|       | |     | |Post ............|
			        |		| |     | |Post ............|


			 */

			//create layout for post cell
			LinearLayout llCell = new LinearLayout(this);
			llCell.setOrientation(LinearLayout.HORIZONTAL);

			//create layout to hold username and post message
			LinearLayout llUserAndPost = new LinearLayout(this);
			llUserAndPost.setOrientation(LinearLayout.VERTICAL);

			//Create image holder for user image
			ImageView postImage = new ImageView(this);
			postImage.setMaxWidth(dpToPix(50));
			postImage.setBackgroundColor(getResources().getColor(R.color.black));
			postImage.setPadding(dpToPix(1), dpToPix(1), dpToPix(1), dpToPix(1));
			postImage.setMaxHeight(dpToPix(50));
			postImage.setScaleType(ImageView.ScaleType.FIT_XY);
			postImage.setAdjustViewBounds(true);
			String imURL = ((Messagee) this.getApplication()).messController.getPosts().getPicURLByIndex(i);
			postImage.setImageDrawable(((Messagee) this.getApplication()).messController.getPostImages().getImage(imURL));

			//draw arrow
			ImageView arrowImage = new ImageView(this);
			arrowImage.setMaxWidth(dpToPix(30));
			arrowImage.setMaxHeight(dpToPix(30));
			arrowImage.setScaleType(ImageView.ScaleType.FIT_XY);
			arrowImage.setAdjustViewBounds(true);
			arrowImage.setImageDrawable(getResources().getDrawable(R.drawable.arrow));

			//text holder for username
			String username = ((Messagee) this.getApplication()).messController.getPosts().getPostNameByIndex(i);
			TextView usernameText = new TextView(this);
			usernameText.setPadding(0, 0, 0, dpToPix(4));
			usernameText.setTextColor(getResources().getColor(R.color.black));
			usernameText.setText(username);
			usernameText.setTypeface(null,1);
			usernameText.setTextSize(17);

			//text holder for message
			String postMessage = ((Messagee) this.getApplication()).messController.getPosts().getPostMessageByIndex(i);
			TextView postText = new TextView(this);
			postText.setTextColor(getResources().getColor(R.color.post_message_gray));
			postText.setText(postMessage);
			postText.setTextSize(17);

			//add username and post text to a linear layout
			llUserAndPost.addView(usernameText);
			llUserAndPost.addView(postText);

			//set layout properties and add rounded rectangle border
			llUserAndPost.setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_corners_white));
			llUserAndPost.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
			llUserAndPost.setPadding(dpToPix(14), dpToPix(10), dpToPix(14), dpToPix(10));

			//add images and text layout to create the post layout
			llCell.addView(postImage);
			llCell.addView(arrowImage);
			llCell.addView(llUserAndPost);
			llCell.setPadding(dpToPix(10f), dpToPix(18f), dpToPix(10f), 0);

			//add post layout to layout containing all posts
			llPosts.addView(llCell);

		}

	}