/// <summary>Gets a drawable by URI, without using the cache.</summary> /// <remarks>Gets a drawable by URI, without using the cache.</remarks> /// <returns> /// A drawable, or /// <code>null</code> /// if the drawable could not be loaded. /// </returns> private android.graphics.drawable.Drawable getDrawable(System.Uri uri) { try { string scheme = uri.Scheme; if (android.content.ContentResolver.SCHEME_ANDROID_RESOURCE.Equals(scheme)) { // Load drawables through Resources, to get the source density information android.content.ContentResolver.OpenResourceIdResult r = mProviderContext.getContentResolver ().getResourceId(uri); try { return(r.r.getDrawable(r.id)); } catch (android.content.res.Resources.NotFoundException) { throw new java.io.FileNotFoundException("Resource does not exist: " + uri); } } else { // Let the ContentResolver handle content and file URIs. java.io.InputStream stream = mProviderContext.getContentResolver().openInputStream (uri); if (stream == null) { throw new java.io.FileNotFoundException("Failed to open " + uri); } try { return(android.graphics.drawable.Drawable.createFromStream(stream, null)); } finally { try { stream.close(); } catch (System.IO.IOException ex) { android.util.Log.e(LOG_TAG, "Error closing icon stream for " + uri, ex); } } } } catch (java.io.FileNotFoundException fnfe) { android.util.Log.w(LOG_TAG, "Icon not found: " + uri + ", " + fnfe.Message); return(null); } }
private void resolveUri() { if (mDrawable != null) { return; } android.content.res.Resources rsrc = getResources(); if (rsrc == null) { return; } android.graphics.drawable.Drawable d = null; if (mResource != 0) { try { d = rsrc.getDrawable(mResource); } catch (System.Exception e) { android.util.Log.w("ImageView", "Unable to find resource: " + mResource, e); // Don't try again. mUri = null; } } else { if (mUri != null) { string scheme = mUri.Scheme; if (android.content.ContentResolver.SCHEME_ANDROID_RESOURCE.Equals(scheme)) { try { // Load drawable through Resources, to get the source density information android.content.ContentResolver.OpenResourceIdResult r = mContext.getContentResolver ().getResourceId(mUri); d = r.r.getDrawable(r.id); } catch (System.Exception e) { android.util.Log.w("ImageView", "Unable to open content: " + mUri, e); } } else { if (android.content.ContentResolver.SCHEME_CONTENT.Equals(scheme) || android.content.ContentResolver .SCHEME_FILE.Equals(scheme)) { try { d = android.graphics.drawable.Drawable.createFromStream(mContext.getContentResolver ().openInputStream(mUri), null); } catch (System.Exception e) { android.util.Log.w("ImageView", "Unable to open content: " + mUri, e); } } else { d = android.graphics.drawable.Drawable.createFromPath(mUri.ToString()); } } if (d == null) { java.io.Console.Out.println("resolveUri failed on bad bitmap uri: " + mUri); // Don't try again. mUri = null; } } else { return; } } updateDrawable(d); }