Search in sources :

Example 71 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by DirtyUnicorns.

the class ResourcesImpl method loadXmlResourceParser.

/**
     * Loads an XML parser for the specified file.
     *
     * @param file the path for the XML file to parse
     * @param id the resource identifier for the file
     * @param assetCookie the asset cookie for the file
     * @param type the type of resource (used for logging)
     * @return a parser for the specified XML file
     * @throws NotFoundException if the file could not be loaded
     */
@NonNull
XmlResourceParser loadXmlResourceParser(@NonNull String file, @AnyRes int id, int assetCookie, @NonNull String type) throws NotFoundException {
    if (id != 0) {
        try {
            synchronized (mCachedXmlBlocks) {
                final int[] cachedXmlBlockCookies = mCachedXmlBlockCookies;
                final String[] cachedXmlBlockFiles = mCachedXmlBlockFiles;
                final XmlBlock[] cachedXmlBlocks = mCachedXmlBlocks;
                // First see if this block is in our cache.
                final int num = cachedXmlBlockFiles.length;
                for (int i = 0; i < num; i++) {
                    if (cachedXmlBlockCookies[i] == assetCookie && cachedXmlBlockFiles[i] != null && cachedXmlBlockFiles[i].equals(file)) {
                        return cachedXmlBlocks[i].newParser();
                    }
                }
                // Not in the cache, create a new block and put it at
                // the next slot in the cache.
                final XmlBlock block = mAssets.openXmlBlockAsset(assetCookie, file);
                if (block != null) {
                    final int pos = (mLastCachedXmlBlockIndex + 1) % num;
                    mLastCachedXmlBlockIndex = pos;
                    final XmlBlock oldBlock = cachedXmlBlocks[pos];
                    if (oldBlock != null) {
                        oldBlock.close();
                    }
                    cachedXmlBlockCookies[pos] = assetCookie;
                    cachedXmlBlockFiles[pos] = file;
                    cachedXmlBlocks[pos] = block;
                    return block.newParser();
                }
            }
        } catch (Exception e) {
            final NotFoundException rnf = new NotFoundException("File " + file + " from xml type " + type + " resource ID #0x" + Integer.toHexString(id));
            rnf.initCause(e);
            throw rnf;
        }
    }
    throw new NotFoundException("File " + file + " from xml type " + type + " resource ID #0x" + Integer.toHexString(id));
}
Also used : NotFoundException(android.content.res.Resources.NotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NotFoundException(android.content.res.Resources.NotFoundException) NonNull(android.annotation.NonNull)

Example 72 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by DirtyUnicorns.

the class ColorStateList method createFromXml.

/**
     * Creates a ColorStateList from an XML document using given a set of
     * {@link Resources} and a {@link Theme}.
     *
     * @param r Resources against which the ColorStateList should be inflated.
     * @param parser Parser for the XML document defining the ColorStateList.
     * @param theme Optional theme to apply to the color state list, may be
     *              {@code null}.
     * @return A new color state list.
     */
@NonNull
public static ColorStateList createFromXml(@NonNull Resources r, @NonNull XmlPullParser parser, @Nullable Theme theme) throws XmlPullParserException, IOException {
    final AttributeSet attrs = Xml.asAttributeSet(parser);
    int type;
    while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
    // Seek parser to start tag.
    }
    if (type != XmlPullParser.START_TAG) {
        throw new XmlPullParserException("No start tag found");
    }
    return createFromXmlInner(r, parser, attrs, theme);
}
Also used : AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NonNull(android.annotation.NonNull)

Example 73 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerService method queryIntentReceiversInternal.

@NonNull
private List<ResolveInfo> queryIntentReceiversInternal(Intent intent, String resolvedType, int flags, int userId) {
    if (!sUserManager.exists(userId))
        return Collections.emptyList();
    flags = updateFlagsForResolve(flags, userId, intent);
    ComponentName comp = intent.getComponent();
    if (comp == null) {
        if (intent.getSelector() != null) {
            intent = intent.getSelector();
            comp = intent.getComponent();
        }
    }
    if (comp != null) {
        List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
        ActivityInfo ai = getReceiverInfo(comp, flags, userId);
        if (ai != null) {
            ResolveInfo ri = new ResolveInfo();
            ri.activityInfo = ai;
            list.add(ri);
        }
        return list;
    }
    // reader
    synchronized (mPackages) {
        String pkgName = intent.getPackage();
        if (pkgName == null) {
            return mReceivers.queryIntent(intent, resolvedType, flags, userId);
        }
        final PackageParser.Package pkg = mPackages.get(pkgName);
        if (pkg != null) {
            return mReceivers.queryIntentForPackage(intent, resolvedType, flags, pkg.receivers, userId);
        }
        return Collections.emptyList();
    }
}
Also used : EphemeralResolveInfo(android.content.pm.EphemeralResolveInfo) ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) PackageParser(android.content.pm.PackageParser) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) NonNull(android.annotation.NonNull)

Example 74 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by DirtyUnicorns.

the class MediaPlayer method easyPlaybackParams.

/**
     * Sets playback rate and audio mode.
     *
     * @param rate the ratio between desired playback rate and normal one.
     * @param audioMode audio playback mode. Must be one of the supported
     * audio modes.
     *
     * @throws IllegalStateException if the internal player engine has not been
     * initialized.
     * @throws IllegalArgumentException if audioMode is not supported.
     *
     * @hide
     */
@NonNull
public PlaybackParams easyPlaybackParams(float rate, @PlaybackRateAudioMode int audioMode) {
    PlaybackParams params = new PlaybackParams();
    params.allowDefaults();
    switch(audioMode) {
        case PLAYBACK_RATE_AUDIO_MODE_DEFAULT:
            params.setSpeed(rate).setPitch(1.0f);
            break;
        case PLAYBACK_RATE_AUDIO_MODE_STRETCH:
            params.setSpeed(rate).setPitch(1.0f).setAudioFallbackMode(params.AUDIO_FALLBACK_MODE_FAIL);
            break;
        case PLAYBACK_RATE_AUDIO_MODE_RESAMPLE:
            params.setSpeed(rate).setPitch(rate);
            break;
        default:
            final String msg = "Audio playback mode " + audioMode + " is not supported";
            throw new IllegalArgumentException(msg);
    }
    return params;
}
Also used : PlaybackParams(android.media.PlaybackParams) NonNull(android.annotation.NonNull)

Example 75 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by DirtyUnicorns.

the class StaticLayout_Delegate method computePrimitives.

/**
     * Compute metadata each character - things which help in deciding if it's possible to break
     * at a point or not.
     */
@NonNull
private static List<Primitive> computePrimitives(@NonNull char[] text, @NonNull float[] widths, int length, @NonNull List<Integer> breaks) {
    // Initialize the list with a guess of the number of primitives:
    // 2 Primitives per non-whitespace char and approx 5 chars per word (i.e. 83% chars)
    List<Primitive> primitives = new ArrayList<Primitive>(((int) Math.ceil(length * 1.833)));
    int breaksSize = breaks.size();
    int breakIndex = 0;
    for (int i = 0; i < length; i++) {
        char c = text[i];
        if (c == CHAR_SPACE || c == CHAR_ZWSP) {
            primitives.add(PrimitiveType.GLUE.getNewPrimitive(i, widths[i]));
        } else if (c == CHAR_TAB) {
            primitives.add(PrimitiveType.VARIABLE.getNewPrimitive(i));
        } else if (c != CHAR_NEWLINE) {
            while (breakIndex < breaksSize && breaks.get(breakIndex) < i) {
                breakIndex++;
            }
            Primitive p;
            if (widths[i] != 0) {
                if (breakIndex < breaksSize && breaks.get(breakIndex) == i) {
                    p = PrimitiveType.PENALTY.getNewPrimitive(i, 0, 0);
                } else {
                    p = PrimitiveType.WORD_BREAK.getNewPrimitive(i, 0);
                }
                primitives.add(p);
            }
            primitives.add(PrimitiveType.BOX.getNewPrimitive(i, widths[i]));
        }
    }
    // final break at end of everything
    primitives.add(PrimitiveType.PENALTY.getNewPrimitive(length, 0, -PrimitiveType.PENALTY_INFINITY));
    return primitives;
}
Also used : ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) NonNull(android.annotation.NonNull)

Aggregations

NonNull (android.annotation.NonNull)322 ArrayList (java.util.ArrayList)46 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 IOException (java.io.IOException)35 ComponentName (android.content.ComponentName)25 File (java.io.File)22 XmlPullParser (org.xmlpull.v1.XmlPullParser)20 Intent (android.content.Intent)18 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)16 ResolveInfo (android.content.pm.ResolveInfo)16 Bundle (android.os.Bundle)15 RemoteException (android.os.RemoteException)15 FileNotFoundException (java.io.FileNotFoundException)15 Paint (android.graphics.Paint)14 PackageParser (android.content.pm.PackageParser)12 ContentResolver (android.content.ContentResolver)10 UserInfo (android.content.pm.UserInfo)10 StorageManager (android.os.storage.StorageManager)10 VolumeInfo (android.os.storage.VolumeInfo)10 KeyCharacteristics (android.security.keymaster.KeyCharacteristics)10