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));
}
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);
}
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();
}
}
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;
}
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;
}
Aggregations