下面列出了android.widget.ImageView#setImageURI ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
@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);
}
});
}
@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());
}
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);
}
}
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));
}
}
@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;
}
/** 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));
}
@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());
}
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);
}
@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()));
}
}
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);
}
@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);
}
/**
* 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));
}
}
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);
}
public void setImageDrawable(int viewId, Uri uri) {
ImageView target = findViewById(viewId);
target.setImageURI(uri);
}
/**
* 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));
}
}
/**
* 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));
}
}
/**
* 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));
}
}
/**
* 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));
}
}
/**
* 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));
}
}