Search in sources :

Example 36 with NotFoundException

use of android.content.res.Resources.NotFoundException in project platform_frameworks_base by android.

the class Resources_Delegate method openRawResource.

@LayoutlibDelegate
static InputStream openRawResource(Resources resources, int id, TypedValue value) throws NotFoundException {
    getValue(resources, id, value, true);
    String path = value.string.toString();
    File f = new File(path);
    if (f.isFile()) {
        try {
            // and actually load it as a 9-patch instead of a normal bitmap
            if (path.toLowerCase().endsWith(NinePatch.EXTENSION_9PATCH)) {
                return new NinePatchInputStream(f);
            }
            return new FileInputStream(f);
        } catch (FileNotFoundException e) {
            NotFoundException exception = new NotFoundException();
            exception.initCause(e);
            throw exception;
        }
    }
    throw new NotFoundException();
}
Also used : NinePatchInputStream(com.android.layoutlib.bridge.util.NinePatchInputStream) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) File(java.io.File) FileInputStream(java.io.FileInputStream) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 37 with NotFoundException

use of android.content.res.Resources.NotFoundException in project platform_frameworks_base by android.

the class InputManagerService method getKeyboardLayoutOverlay.

// Native callback.
private String[] getKeyboardLayoutOverlay(InputDeviceIdentifier identifier) {
    if (!mSystemReady) {
        return null;
    }
    String keyboardLayoutDescriptor = getCurrentKeyboardLayoutForInputDevice(identifier);
    if (keyboardLayoutDescriptor == null) {
        return null;
    }
    final String[] result = new String[2];
    visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {

        @Override
        public void visitKeyboardLayout(Resources resources, int keyboardLayoutResId, KeyboardLayout layout) {
            try {
                result[0] = layout.getDescriptor();
                result[1] = Streams.readFully(new InputStreamReader(resources.openRawResource(keyboardLayoutResId)));
            } catch (IOException ex) {
            } catch (NotFoundException ex) {
            }
        }
    });
    if (result[0] == null) {
        Slog.w(TAG, "Could not get keyboard layout with descriptor '" + keyboardLayoutDescriptor + "'.");
        return null;
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Resources(android.content.res.Resources) KeyboardLayout(android.hardware.input.KeyboardLayout) IOException(java.io.IOException)

Example 38 with NotFoundException

use of android.content.res.Resources.NotFoundException in project platform_frameworks_base by android.

the class Ringtone method playFallbackRingtone.

private boolean playFallbackRingtone() {
    if (mAudioManager.getStreamVolume(AudioAttributes.toLegacyStreamType(mAudioAttributes)) != 0) {
        int ringtoneType = RingtoneManager.getDefaultType(mUri);
        if (ringtoneType == -1 || RingtoneManager.getActualDefaultRingtoneUri(mContext, ringtoneType) != null) {
            // Default ringtone, try fallback ringtone.
            try {
                AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(com.android.internal.R.raw.fallbackring);
                if (afd != null) {
                    mLocalPlayer = new MediaPlayer();
                    if (afd.getDeclaredLength() < 0) {
                        mLocalPlayer.setDataSource(afd.getFileDescriptor());
                    } else {
                        mLocalPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
                    }
                    mLocalPlayer.setAudioAttributes(mAudioAttributes);
                    synchronized (mPlaybackSettingsLock) {
                        applyPlaybackProperties_sync();
                    }
                    mLocalPlayer.prepare();
                    startLocalPlayer();
                    afd.close();
                    return true;
                } else {
                    Log.e(TAG, "Could not load fallback ringtone");
                }
            } catch (IOException ioe) {
                destroyLocalPlayer();
                Log.e(TAG, "Failed to open fallback ringtone");
            } catch (NotFoundException nfe) {
                Log.e(TAG, "Fallback ringtone does not exist");
            }
        } else {
            Log.w(TAG, "not playing fallback for " + mUri);
        }
    }
    return false;
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) NotFoundException(android.content.res.Resources.NotFoundException) IOException(java.io.IOException)

Example 39 with NotFoundException

use of android.content.res.Resources.NotFoundException in project platform_frameworks_base by android.

the class StorageManagerBaseTest method createObbFile.

/**
     * Creates an OBB file (with the given name), into the app's standard files directory
     *
     * @param name The name of the OBB file we want to create/write to
     * @param rawResId The raw resource ID of the OBB file in the package
     * @return A {@link File} representing the file to write to
     */
protected File createObbFile(String name, int rawResId) {
    File outFile = null;
    try {
        final File filesDir = mContext.getFilesDir();
        outFile = new File(filesDir, name);
        copyRawToFile(rawResId, outFile);
    } catch (NotFoundException e) {
        if (outFile != null) {
            outFile.delete();
        }
    }
    return outFile;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) File(java.io.File)

Example 40 with NotFoundException

use of android.content.res.Resources.NotFoundException in project platform_frameworks_base by android.

the class StorageManagerBaseTest method copyRawToFile.

/**
     * Helper to copy a raw resource file to an actual specified file
     *
     * @param rawResId The raw resource ID of the OBB resource file
     * @param outFile A File representing the file we want to copy the OBB to
     * @throws NotFoundException If the resource file could not be found
     */
private void copyRawToFile(int rawResId, File outFile) throws NotFoundException {
    Resources res = mContext.getResources();
    InputStream is = null;
    try {
        is = res.openRawResource(rawResId);
    } catch (NotFoundException e) {
        Log.i(LOG_TAG, "Failed to load resource with id: " + rawResId);
        throw e;
    }
    FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1);
    assertTrue(FileUtils.copyToFile(is, outFile));
    FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1);
}
Also used : DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) Resources(android.content.res.Resources)

Aggregations

NotFoundException (android.content.res.Resources.NotFoundException)165 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)49 Resources (android.content.res.Resources)47 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 FileNotFoundException (java.io.FileNotFoundException)34 IOException (java.io.IOException)34 ApplicationInfo (android.content.pm.ApplicationInfo)31 File (java.io.File)30 InputStream (java.io.InputStream)28 FileInputStream (java.io.FileInputStream)20 Drawable (android.graphics.drawable.Drawable)19 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)16 Nullable (android.annotation.Nullable)15 XmlResourceParser (android.content.res.XmlResourceParser)12 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)12 ArrayResourceValue (com.android.ide.common.rendering.api.ArrayResourceValue)12 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)12 NonNull (android.annotation.NonNull)10 ColorDrawable (android.graphics.drawable.ColorDrawable)10 DensityBasedResourceValue (com.android.ide.common.rendering.api.DensityBasedResourceValue)8