Example usage for android.widget ImageView setImageURI

List of usage examples for android.widget ImageView setImageURI

Introduction

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

Prototype

@android.view.RemotableViewMethod(asyncImpl = "setImageURIAsync")
public void setImageURI(@Nullable Uri uri) 

Source Link

Document

Sets the content of this ImageView to the specified Uri.

Usage

From source file:Main.java

public static void settingPicture(ImageView imageView, Uri imageUri) {
    imageView.setImageURI(null);
    imageView.setImageURI(imageUri);
}

From source file:Main.java

public static void loadFresco(String imageUrl, ImageView imageView) {
    Uri uri = Uri.parse(imageUrl);
    imageView.setImageURI(uri);
}

From source file:com.evvsoft.treeview.SimpleJsonTreeViewAdapter.java

/**
 * Called by bindView() to set the image for an ImageView but only if
 * there is no existing ViewBinder or if the existing ViewBinder cannot
 * handle binding to an ImageView.//w w w .  j a v  a2s  . c o m
 *
 * By default, the value will be treated as an image resource. If the
 * value cannot be used as an image resource, the value is used as an
 * image Uri.
 *
 * This method is called instead of {@link #setViewImage(ImageView, int)}
 * if the supplied data is not an int or Integer.
 *
 * @param v ImageView to receive an image
 * @param value the value retrieved from the data set
 *
 * @see #setViewImage(ImageView, int)
 */
public static void setViewImage(ImageView v, String value) {
    try {
        v.setImageResource(Integer.parseInt(value));
    } catch (NumberFormatException nfe) {
        v.setImageURI(Uri.parse(value));
    }
}

From source file:com.jacr.instagramtrendreader.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.frg_main, container, false);

    ImageView imv = (ImageView) view.findViewById(R.id.upperImg);
    imv.setImageURI(Uri.fromFile(new File(imagePath)));
    imv.setOnClickListener(new OnClickListener() {

        @Override//from  w  w  w .  j av a2 s.  c  om
        public void onClick(View v) {
            Bundle b = new Bundle();
            b.putInt(Main.ACTION_IMAGE_CLICK, key);
            Util.sendBroadcast(getActivity(), Main.ACTION_IMAGE_CLICK, b);

        }

    });

    return view;

}

From source file:my.home.lehome.asynctask.LoadProfileHeaderBgAsyncTask.java

@Override
protected void onPreExecute() {
    ImageView imageView = mImageView.get();
    if (imageView != null) {
        imageView.setImageURI(null);
        this.mWidth = imageView.getWidth();
        this.mHeight = imageView.getHeight();
        this.mScaleType = imageView.getScaleType();
    }/*from  w w  w .j  av a  2s  .com*/
    ProgressBar progressBar = mProgressBar.get();
    if (progressBar != null) {
        progressBar.setVisibility(View.VISIBLE);
    }
}

From source file:com.jacr.instagramtrendreader.ImageDetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.frg_images_details, container, false);

    // Views/*from   ww  w . j ava 2s  . c  om*/
    TextView txtPublishDate = (TextView) view.findViewById(R.id.txtDateValue);
    TextView txtAuthor = (TextView) view.findViewById(R.id.txtUsernameValue);
    TextView txtTags = (TextView) view.findViewById(R.id.txtTagsValue);
    ImageView imv = (ImageView) view.findViewById(R.id.imvDetails);

    txtPublishDate.setText(formatearFecha(publishDate));
    txtAuthor.setText(author);
    txtTags.setText(tags);
    imv.setImageURI(Uri.fromFile(new File(imagePath)));
    imv.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            final Activity act = ImageDetailsFragment.this.getActivity();
            Intent in = new Intent(act, HTMLViewer.class);
            Bundle b = new Bundle();
            b.putString(HTMLViewer.KEY_USERNAME, author);
            b.putString(HTMLViewer.KEY_URL_IMAGE, urlDowloadImage);
            in.putExtras(b);
            act.startActivity(in);
        }

    });

    return view;
}

From source file:com.example.android.dragsource.DragSourceFragment.java

@Nullable
@Override/*from   w w w. j  av  a2  s  .  c  o m*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_dragsource, null);

    // Set up two image views for global drag and drop with a permission grant.
    Uri imageUri = getFileUri(R.drawable.image1, "image1.png");
    ImageView imageView = (ImageView) view.findViewById(R.id.image_one);
    setUpDraggableImage(imageView, imageUri);
    imageView.setImageURI(imageUri);

    imageUri = getFileUri(R.drawable.image2, "image2.png");
    imageView = (ImageView) view.findViewById(R.id.image_two);
    setUpDraggableImage(imageView, imageUri);
    imageView.setImageURI(imageUri);

    // Set up the local drop target area.
    final ImageView localImageTarget = (ImageView) view.findViewById(R.id.local_target);
    localImageTarget.setOnDragListener(new ImageDragListener() {
        @Override
        protected boolean setImageUri(View view, DragEvent event, Uri uri) {
            mLocalImageUri = uri;
            Log.d(TAG, "Setting local image to: " + uri);
            return super.setImageUri(view, event, uri);
        }
    });

    if (savedInstanceState != null) {
        final String uriString = savedInstanceState.getString(IMAGE_URI);
        if (uriString != null) {
            mLocalImageUri = Uri.parse(uriString);
            Log.d(TAG, "Restoring local image to: " + mLocalImageUri);
            localImageTarget.setImageURI(mLocalImageUri);
        }
    }
    return view;
}

From source file:com.example.android.lnotifications.OtherMetadataFragment.java

/**
 * Updates the Contact information on the screen when a contact is picked.
 *
 * @param contactUri The Uri from which the contact is retrieved.
 *///ww w  . ja v a 2  s . c om
private void updateContactEntryFromUri(Uri contactUri) {
    Cursor cursor = getActivity().getContentResolver().query(contactUri, null, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {
        int idx = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
        String name = cursor.getString(idx);
        idx = cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_ID);
        String hasPhoto = cursor.getString(idx);

        Uri photoUri = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
        ImageView contactPhoto = (ImageView) getActivity().findViewById(R.id.contact_photo);
        if (hasPhoto != null) {
            contactPhoto.setImageURI(photoUri);
        } else {
            Drawable defaultContactDrawable = getActivity().getResources()
                    .getDrawable(R.drawable.ic_contact_picture);
            contactPhoto.setImageDrawable(defaultContactDrawable);
        }
        TextView contactName = (TextView) getActivity().findViewById(R.id.contact_name);
        contactName.setText(name);

        getActivity().findViewById(R.id.contact_entry).setVisibility(View.VISIBLE);
        getActivity().findViewById(R.id.attach_person).setVisibility(View.GONE);
        getActivity().findViewById(R.id.click_to_change).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                findContact();
            }
        });
        Log.i(TAG, String.format("Contact updated. Name %s, PhotoUri %s", name, photoUri));
    }
}

From source file:com.DGSD.Teexter.UI.Recipient.RecipientAlternatesAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    int position = cursor.getPosition();

    TextView display = (TextView) view.findViewById(android.R.id.title);
    ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
    RecipientEntry entry = getRecipientEntry(position);
    if (position == 0) {
        display.setText(cursor.getString(EmailQuery.NAME));
        display.setVisibility(View.VISIBLE);
        imageView.setImageURI(entry.getPhotoThumbnailUri());
        imageView.setVisibility(View.VISIBLE);
    } else {//  w ww. j  a  va2  s .  c o  m
        display.setVisibility(View.GONE);
        imageView.setVisibility(View.GONE);
    }
    TextView destination = (TextView) view.findViewById(android.R.id.text1);
    destination.setText(cursor.getString(EmailQuery.ADDRESS));

    TextView destinationType = (TextView) view.findViewById(android.R.id.text2);
    if (destinationType != null) {
        destinationType
                .setText(Email.getTypeLabel(context.getResources(), cursor.getInt(EmailQuery.ADDRESS_TYPE),
                        cursor.getString(EmailQuery.ADDRESS_LABEL)).toString().toUpperCase());
    }
}

From source file:com.odoo.base.addons.mail.widget.MailChatterCompose.java

private void addAttachment(OValues values) {
    View attachmentView = LayoutInflater.from(this).inflate(R.layout.base_attachment_item, horizontalScrollView,
            false);//  ww  w.ja  v a2  s .  co m
    String fileName = values.getString("name");
    String type = values.getString("file_type");
    ImageView imgPreview = (ImageView) attachmentView.findViewById(R.id.attachmentPreview);
    if (type.contains("image")) {
        OLog.log(values.getString("file_uri"));
        imgPreview.setImageURI(Uri.parse(values.getString("file_uri")));
    } else if (type.contains("audio")) {
        imgPreview.setImageResource(R.drawable.audio);
    } else if (type.contains("video")) {
        imgPreview.setImageResource(R.drawable.video);
    } else {
        imgPreview.setImageResource(R.drawable.file);
    }
    OControls.setText(attachmentView, R.id.attachmentFileName, fileName);
    attachmentView.setTag(values);
    attachmentView.findViewById(R.id.btnRemoveAttachment).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            horizontalScrollView.removeView((View) v.getParent());
        }
    });
    horizontalScrollView.addView(attachmentView);
}