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

The following examples show how to use android.widget.ImageView#setImageURI() . 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: MainActivity.java    From Pomfshare with GNU General Public License v2.0 6 votes vote down vote up
private void displayAndUpload(Host host) {
	ContentResolver cr = getContentResolver();
	if (imageUri != null) {
		ImageView view = (ImageView)findViewById(R.id.sharedImageView);
		view.setImageURI(imageUri);

		ParcelFileDescriptor inputPFD = null; 
		try {
			inputPFD = cr.openFileDescriptor(imageUri, "r");				
		} catch (FileNotFoundException e) {
			Log.e(tag, e.getMessage());
			Toast toast = Toast.makeText(getApplicationContext(), "Unable to read file.", Toast.LENGTH_SHORT);
			toast.show();				
		}

		new Uploader(this, inputPFD, host).execute(imageUri.getLastPathSegment(), cr.getType(imageUri));
	}
}
 
Example 2
Source File: MainActivity.java    From aviary-android-sdk-demo with MIT License 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // After getting the photo from the camera
    if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK) {
        // Start up Aviary
        Intent newIntent = new Intent( this, FeatherActivity.class );
        newIntent.setData( Uri.fromFile(mPhotoFile) );
        newIntent.putExtra( Constants.EXTRA_IN_API_KEY_SECRET, "YOUR_SECRET_HERE" );
        startActivityForResult( newIntent, REUSLT_INVOKE_EDITOR );

    }

    // After getting the image result from Aviary
    if(requestCode == REUSLT_INVOKE_EDITOR && resultCode == RESULT_OK) {
        Uri theURI = data.getData();
        Toast.makeText(this, "Got Aviary!: " + theURI, Toast.LENGTH_SHORT).show();
        ImageView theImage = (ImageView) findViewById(R.id.image);
        theImage.setImageURI(theURI);
    }
}
 
Example 3
Source File: ImageLoaderTools.java    From Social with Apache License 2.0 6 votes vote down vote up
public void displayImage(String mResName, ImageView imageView) {
    if(mResName.startsWith("http://")){
        mImageLoader.displayImage(mResName, imageView);
    }else if(mResName.startsWith("assets://"))
    {
        mImageLoader.displayImage(mResName, imageView);
    }
    else if(mResName.startsWith("file:///mnt"))
    {
        mImageLoader.displayImage(mResName, imageView);
    }
    else if(mResName.startsWith("content://"))
    {
        mImageLoader.displayImage(mResName, imageView);
    }
    else if(mResName.startsWith("drawable://"))
    {
        mImageLoader.displayImage(mResName, imageView);
    }
    else{
        Uri uri = Uri.parse(mResName);
        imageView.setImageURI(uri);
    }

}
 
Example 4
Source File: MainActivity.java    From shotwatch with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mText = (TextView) findViewById(R.id.text);
    mImage = (ImageView) findViewById(R.id.image);

    mShotWatch = new ShotWatch(getContentResolver(), new ShotWatch.Listener() {
        @Override
        public void onScreenShotTaken(ScreenshotData screenshotData) {
            mText.setText(screenshotData.getFileName());
            Uri uri = Uri.parse(screenshotData.getPath());
            mImage.setImageURI(uri);
        }
    });
}
 
Example 5
Source File: FormFragment.java    From shaky-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    Toolbar toolbar = (Toolbar) view.findViewById(R.id.shaky_toolbar);
    EditText messageEditText = (EditText) view.findViewById(R.id.shaky_form_message);
    ImageView attachmentImageView = (ImageView) view.findViewById(R.id.shaky_form_attachment);

    Uri screenshotUri = getArguments().getParcelable(KEY_SCREENSHOT_URI);
    int sendIconResource = getArguments().getInt(KEY_MENU);

    String title = getArguments().getString(KEY_TITLE);
    toolbar.setTitle(title);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.setNavigationOnClickListener(createNavigationClickListener());
    toolbar.inflateMenu(sendIconResource);
    toolbar.setOnMenuItemClickListener(createMenuClickListener(messageEditText));

    String hint = getArguments().getString(KEY_HINT);
    messageEditText.setHint(hint);
    messageEditText.requestFocus();

    attachmentImageView.setImageURI(screenshotUri);
    attachmentImageView.setOnClickListener(createNavigationClickListener());
}
 
Example 6
Source File: SimpleImageDialog.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@Override
protected View onCreateContentView(Bundle savedInstanceState) {

    View view;

    int scale = getArguments().getInt(SCALE_TYPE, Scale.FIT.nativeInt);

    if (scale == Scale.FIT.nativeInt){
        view = inflate(R.layout.simpledialogfragment_image);

    } else if (scale == Scale.SCROLL_VERTICAL.nativeInt){
        view = inflate(R.layout.simpledialogfragment_image_vert_scroll);

    } else if (scale == Scale.SCROLL_HORIZONTAL.nativeInt) {
        view = inflate(R.layout.simpledialogfragment_image_hor_scroll);

    } else {
        return null;
    }


    ImageView imageView = (ImageView) view.findViewById(R.id.image);
    ProgressBar loading = (ProgressBar) view.findViewById(R.id.progressBar);

    if (getArguments().containsKey(IMAGE_URI)) {
        imageView.setImageURI((Uri) getArguments().getParcelable(IMAGE_URI));
    } else if (getArguments().containsKey(DRAWABLE_RESOURCE)) {
        imageView.setImageResource(getArguments().getInt(DRAWABLE_RESOURCE));
    } else if (getArguments().containsKey(CREATOR_CLASS)) {
        Bundle args = getArguments();
        args.putString(TAG, getTag());
        new ImageCreator(imageView, loading).execute(args);
    } else if (getArguments().containsKey(BITMAP)) {
        imageView.setImageBitmap((Bitmap) getArguments().getParcelable(BITMAP));
    }

    return view;
}
 
Example 7
Source File: MailChatterCompose.java    From framework with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addAttachment(OValues values) {
    View attachmentView = LayoutInflater.from(this)
            .inflate(R.layout.base_attachment_item, horizontalScrollView, false);
    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);
}
 
Example 8
Source File: OtherMetadataFragment.java    From android-LNotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the Contact information on the screen when a contact is picked.
 *
 * @param contactUri The Uri from which the contact is retrieved.
 */
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));
    }
}
 
Example 9
Source File: ImageActivity.java    From AndroidProgramming3e with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_image);

    Uri pathUri = getIntent().getData();
    ImageView imageView = (ImageView) findViewById(R.id.image_view);
    imageView.setImageURI(pathUri);
}
 
Example 10
Source File: MailChatterCompose.java    From hr with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addAttachment(OValues values) {
    View attachmentView = LayoutInflater.from(this)
            .inflate(R.layout.base_attachment_item, horizontalScrollView, false);
    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);
}
 
Example 11
Source File: DefaultImageRenderer.java    From chips-input-layout with MIT License 5 votes vote down vote up
@Override
public void renderAvatar(ImageView imageView, Chip chip) {
    if (chip.getAvatarUri() != null) {
        imageView.setImageURI(chip.getAvatarUri());
    } else if (chip.getAvatarDrawable() != null) {
        imageView.setImageDrawable(chip.getAvatarDrawable());
    } else {
        imageView.setImageBitmap(LetterTileProvider
                .getInstance(imageView.getContext())
                .getLetterTile(chip.getTitle()));
    }
}
 
Example 12
Source File: MarkSubmitActivity.java    From school_shop with MIT License 5 votes vote down vote up
private void initView() {
	initQiniuToken();
	initToolbar();
	markImageView = (ImageView)findViewById(R.id.mark_submit_imageView);
	despEditText = (EditText)findViewById(R.id.mark_submit_editext);
	
	tagInfoList = new ArrayList<TagInfo>();
	tagInfoList = (List<TagInfo>)getIntent().getSerializableExtra("taglist");
	String urisString = getIntent().getExtras().getString("Uri");
	imgUri = Uri.parse(urisString);
	markImageView.setImageURI(imgUri);
	userInfo = AccountInfoUtils.getUserInfo(this);
}
 
Example 13
Source File: GalleryView.java    From Favorite-Android-Client with Apache License 2.0 5 votes vote down vote up
@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
     requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
      setContentView(R.layout.imageview);
      
      getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
      //Hide logo
      getSupportActionBar().setDisplayShowHomeEnabled(false);
      //Load partially transparent black background
      getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_bg_black));

       mImageView = (ImageView) findViewById(R.id.iv_photo);

      Intent intent = getIntent();// 인텐트 받아오고
path = intent.getStringExtra("path");
image_uri = intent.getParcelableExtra("uri");
      edit_mode = intent.getBooleanExtra("edit", false);
     // Drawable bitmap = getResources().getDrawable(R.drawable.splash);
     if(path != null) mImageView.setImageBitmap(Global.UriToBitmapCompress(Uri.fromFile(new File(path))));
     if(image_uri != null) mImageView.setImageURI(image_uri);
      // The MAGIC happens here!
      mAttacher = new PhotoViewAttacher(mImageView);

      // Lets attach some listeners, not required though!
      mAttacher.setOnMatrixChangeListener(new MatrixChangeListener());
      mAttacher.setOnPhotoTapListener(new PhotoTapListener());
  }
 
Example 14
Source File: DownloadManagerActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);

	BroadcastReceiver receiver = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
				long downloadId = intent.getLongExtra(
						DownloadManager.EXTRA_DOWNLOAD_ID, 0);
				Query query = new Query();
				query.setFilterById(enqueue);
				Cursor c = dm.query(query);
				if (c.moveToFirst()) {
					int columnIndex = c
							.getColumnIndex(DownloadManager.COLUMN_STATUS);
					if (DownloadManager.STATUS_SUCCESSFUL == c
							.getInt(columnIndex)) {

						ImageView view = (ImageView) findViewById(R.id.imageView1);
						String uriString = c
								.getString(c
										.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
						view.setImageURI(Uri.parse(uriString));
					}
				}
			}
		}
	};

	registerReceiver(receiver, new IntentFilter(
			DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
 
Example 15
Source File: ViewHolderImpl.java    From commonadapter with MIT License 4 votes vote down vote up
public void setImageDrawable(int viewId, Uri uri) {
    ImageView target = findViewById(viewId);
    target.setImageURI(uri);
}
 
Example 16
Source File: SimpleCursorAdapter.java    From V.FlyoutTest with MIT License 3 votes vote down vote up
/**
 * 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.
 *
 * 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.
 *
 * Intended to be overridden by Adapters that need to filter strings
 * retrieved from the database.
 *
 * @param v ImageView to receive an image
 * @param value the value retrieved from the cursor
 */
public void setViewImage(ImageView v, String value) {
    try {
        v.setImageResource(Integer.parseInt(value));
    } catch (NumberFormatException nfe) {
        v.setImageURI(Uri.parse(value));
    }
}
 
Example 17
Source File: SimpleCursorAdapter.java    From guideshow with MIT License 3 votes vote down vote up
/**
 * 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.
 *
 * 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.
 *
 * Intended to be overridden by Adapters that need to filter strings
 * retrieved from the database.
 *
 * @param v ImageView to receive an image
 * @param value the value retrieved from the cursor
 */
public void setViewImage(ImageView v, String value) {
    try {
        v.setImageResource(Integer.parseInt(value));
    } catch (NumberFormatException nfe) {
        v.setImageURI(Uri.parse(value));
    }
}
 
Example 18
Source File: SimpleDragSortCursorAdapter.java    From Overchan-Android with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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.
 *
 * 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.
 *
 * Intended to be overridden by Adapters that need to filter strings
 * retrieved from the database.
 *
 * @param v ImageView to receive an image
 * @param value the value retrieved from the cursor
 */
public void setViewImage(ImageView v, String value) {
    try {
        v.setImageResource(Integer.parseInt(value));
    } catch (NumberFormatException nfe) {
        v.setImageURI(Uri.parse(value));
    }
}
 
Example 19
Source File: SimpleDragSortCursorAdapter.java    From mobile-manager-tool with MIT License 3 votes vote down vote up
/**
 * 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.
 *
 * 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.
 *
 * Intended to be overridden by Adapters that need to filter strings
 * retrieved from the database.
 *
 * @param v ImageView to receive an image
 * @param value the value retrieved from the cursor
 */
public void setViewImage(ImageView v, String value) {
    try {
        v.setImageResource(Integer.parseInt(value));
    } catch (NumberFormatException nfe) {
        v.setImageURI(Uri.parse(value));
    }
}
 
Example 20
Source File: SimpleCursorRecyclerAdapter.java    From android-atleap with Apache License 2.0 3 votes vote down vote up
/**
 * 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.
 *
 * 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.
 *
 * Intended to be overridden by Adapters that need to filter strings
 * retrieved from the database.
 *
 * @param v ImageView to receive an image
 * @param value the value retrieved from the cursor
 */
public void setViewImage(ImageView v, String value) {
    try {
        v.setImageResource(Integer.parseInt(value));
    } catch (NumberFormatException nfe) {
        v.setImageURI(Uri.parse(value));
    }
}