Example usage for android.content ContentResolver SCHEME_ANDROID_RESOURCE

List of usage examples for android.content ContentResolver SCHEME_ANDROID_RESOURCE

Introduction

In this page you can find the example usage for android.content ContentResolver SCHEME_ANDROID_RESOURCE.

Prototype

String SCHEME_ANDROID_RESOURCE

To view the source code for android.content ContentResolver SCHEME_ANDROID_RESOURCE.

Click Source Link

Usage

From source file:android.support.v7.widget.SuggestionsAdapter.java

/**
 * Gets a drawable by URI, without using the cache.
 *
 * @return A drawable, or {@code null} if the drawable could not be loaded.
 *//* w  w w . jav a  2  s .  c  o  m*/
private Drawable getDrawable(Uri uri) {
    try {
        String scheme = uri.getScheme();
        if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(scheme)) {
            // Load drawables through Resources, to get the source density information
            try {
                return getDrawableFromResourceUri(uri);
            } catch (Resources.NotFoundException ex) {
                throw new FileNotFoundException("Resource does not exist: " + uri);
            }
        } else {
            // Let the ContentResolver handle content and file URIs.
            InputStream stream = mProviderContext.getContentResolver().openInputStream(uri);
            if (stream == null) {
                throw new FileNotFoundException("Failed to open " + uri);
            }
            try {
                return Drawable.createFromStream(stream, null);
            } finally {
                try {
                    stream.close();
                } catch (IOException ex) {
                    Log.e(LOG_TAG, "Error closing icon stream for " + uri, ex);
                }
            }
        }
    } catch (FileNotFoundException fnfe) {
        Log.w(LOG_TAG, "Icon not found: " + uri + ", " + fnfe.getMessage());
        return null;
    }
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SuggestionsAdapter.java

/**
 * Gets a drawable by URI, without using the cache.
 *
 * @return A drawable, or {@code null} if the drawable could not be loaded.
 *///  w ww. j  av a  2  s.  co m
private Drawable getDrawable(Uri uri) {
    try {
        String scheme = uri.getScheme();
        if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(scheme)) {
            // Load drawables through Resources, to get the source density information
            try {
                return getTheDrawable(uri);
            } catch (Resources.NotFoundException ex) {
                throw new FileNotFoundException("Resource does not exist: " + uri);
            }
        } else {
            // Let the ContentResolver handle content and file URIs.
            InputStream stream = mProviderContext.getContentResolver().openInputStream(uri);
            if (stream == null) {
                throw new FileNotFoundException("Failed to open " + uri);
            }
            try {
                return Drawable.createFromStream(stream, null);
            } finally {
                try {
                    stream.close();
                } catch (IOException ex) {
                    Log.e(LOG_TAG, "Error closing icon stream for " + uri, ex);
                }
            }
        }
    } catch (FileNotFoundException fnfe) {
        Log.w(LOG_TAG, "Icon not found: " + uri + ", " + fnfe.getMessage());
        return null;
    }
}

From source file:me.ccrama.redditslide.Views.SubsamplingScaleImageView.java

/**
 * Set the image source from a bitmap, resource, asset, file or other URI, providing a preview image to be
 * displayed until the full size image is loaded, starting with a given orientation setting, scale and center.
 * This is the best method to use when you want scale and center to be restored after screen orientation change;
 * it avoids any redundant loading of tiles in the wrong orientation.
 * <p/>//from  w ww.  j av a 2s .c  om
 * You must declare the dimensions of the full size image by calling {@link ImageSource#dimensions(int, int)}
 * on the imageSource object. The preview source will be ignored if you don't provide dimensions,
 * and if you provide a bitmap for the full size image.
 *
 * @param imageSource   Image source. Dimensions must be declared.
 * @param previewSource Optional source for a preview image to be displayed and allow interaction while the full size image loads.
 * @param state         State to be restored. Nullable.
 */
public final void setImage(ImageSource imageSource, ImageSource previewSource, ImageViewState state) {
    setAlpha(0);
    if (imageSource == null) {
        throw new NullPointerException("imageSource must not be null");
    }

    reset(true);
    if (state != null) {
        restoreState(state);
    }

    if (previewSource != null) {
        if (imageSource.getBitmap() != null) {
            throw new IllegalArgumentException(
                    "Preview image cannot be used when a bitmap is provided for the main image");
        }
        if (imageSource.getSWidth() <= 0 || imageSource.getSHeight() <= 0) {
            throw new IllegalArgumentException(
                    "Preview image cannot be used unless dimensions are provided for the main image");
        }
        this.sWidth = imageSource.getSWidth();
        this.sHeight = imageSource.getSHeight();
        this.pRegion = previewSource.getSRegion();
        if (previewSource.getBitmap() != null) {
            this.bitmapIsCached = previewSource.isCached();
            onPreviewLoaded(previewSource.getBitmap());
        } else {
            Uri uri = previewSource.getUri();
            if (uri == null && previewSource.getResource() != null) {
                uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getContext().getPackageName()
                        + "/" + previewSource.getResource());
            }
            BitmapLoadTask task = new BitmapLoadTask(this, getContext(), bitmapDecoderFactory, uri, true);
            execute(task);
        }
    }

    if (imageSource.getBitmap() != null && imageSource.getSRegion() != null) {
        onImageLoaded(Bitmap.createBitmap(imageSource.getBitmap(), imageSource.getSRegion().left,
                imageSource.getSRegion().top, imageSource.getSRegion().width(),
                imageSource.getSRegion().height()), ORIENTATION_0, false);
    } else if (imageSource.getBitmap() != null) {
        onImageLoaded(imageSource.getBitmap(), ORIENTATION_0, imageSource.isCached());
    } else {
        sRegion = imageSource.getSRegion();
        uri = imageSource.getUri();
        if (uri == null && imageSource.getResource() != null) {
            uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getContext().getPackageName()
                    + "/" + imageSource.getResource());
        }
        doLoader(imageSource, false);
    }
}

From source file:com.tandong.sa.sherlock.widget.SuggestionsAdapter.java

/**
 * Gets a drawable by URI, without using the cache.
 * /*from   ww  w .java  2s . c  o  m*/
 * @return A drawable, or {@code null} if the drawable could not be loaded.
 */
private Drawable getDrawable(Uri uri) {
    try {
        String scheme = uri.getScheme();
        if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(scheme)) {
            // Load drawables through Resources, to get the source density
            // information
            try {
                return getTheDrawable(uri);
            } catch (Resources.NotFoundException ex) {
                throw new FileNotFoundException("Resource does not exist: " + uri);
            }
        } else {
            // Let the ContentResolver handle content and file URIs.
            InputStream stream = mProviderContext.getContentResolver().openInputStream(uri);
            if (stream == null) {
                throw new FileNotFoundException("Failed to open " + uri);
            }
            try {
                return Drawable.createFromStream(stream, null);
            } finally {
                try {
                    stream.close();
                } catch (IOException ex) {
                    Log.e(LOG_TAG, "Error closing icon stream for " + uri, ex);
                }
            }
        }
    } catch (FileNotFoundException fnfe) {
        Log.w(LOG_TAG, "Icon not found: " + uri + ", " + fnfe.getMessage());
        return null;
    }
}

From source file:com.android.quicksearchbox.ShortcutRepositoryImplLog.java

private String getIconUriString(Source source, String drawableId) {
    // Fast path for empty icons
    if (TextUtils.isEmpty(drawableId) || "0".equals(drawableId)) {
        return null;
    }//from   w  w  w .j av  a  2s  .c  om
    // Fast path for icon URIs
    if (drawableId.startsWith(ContentResolver.SCHEME_ANDROID_RESOURCE)
            || drawableId.startsWith(ContentResolver.SCHEME_CONTENT)
            || drawableId.startsWith(ContentResolver.SCHEME_FILE)) {
        return drawableId;
    }
    Uri uri = source.getIconUri(drawableId);
    return uri == null ? null : uri.toString();
}

From source file:com.onesignal.GenerateNotification.java

private static Uri getCustomSound(JSONObject gcmBundle) {
    int soundId;/*from   w ww  .j a v a  2 s.  c  om*/
    String sound = null;
    try {
        if (gcmBundle.has("sound"))
            sound = gcmBundle.getString("sound");
    } catch (Throwable t) {
        return null;
    }

    if (isValidResourceName(sound)) {
        soundId = contextResources.getIdentifier(sound, "raw", packageName);
        if (soundId != 0)
            return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + packageName + "/" + soundId);
    }

    soundId = contextResources.getIdentifier("onesignal_default_sound", "raw", packageName);
    if (soundId != 0)
        return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + packageName + "/" + soundId);

    soundId = contextResources.getIdentifier("gamethrive_default_sound", "raw", packageName);
    if (soundId != 0)
        return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + packageName + "/" + soundId);

    return null;
}