use of android.annotation.NonNull in project android_frameworks_base by AOSPA.
the class MenuPopupHelper method createPopup.
/**
* Creates the popup and assigns cached properties.
*
* @return an initialized popup
*/
@NonNull
private MenuPopup createPopup() {
final WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
final Display display = windowManager.getDefaultDisplay();
final Point displaySize = new Point();
display.getRealSize(displaySize);
final int smallestWidth = Math.min(displaySize.x, displaySize.y);
final int minSmallestWidthCascading = mContext.getResources().getDimensionPixelSize(com.android.internal.R.dimen.cascading_menus_min_smallest_width);
final boolean enableCascadingSubmenus = smallestWidth >= minSmallestWidthCascading;
final MenuPopup popup;
if (enableCascadingSubmenus) {
popup = new CascadingMenuPopup(mContext, mAnchorView, mPopupStyleAttr, mPopupStyleRes, mOverflowOnly);
} else {
popup = new StandardMenuPopup(mContext, mMenu, mAnchorView, mPopupStyleAttr, mPopupStyleRes, mOverflowOnly);
}
// Assign immutable properties.
popup.addMenu(mMenu);
popup.setOnDismissListener(mInternalOnDismissListener);
// Assign mutable properties. These may be reassigned later.
popup.setAnchorView(mAnchorView);
popup.setCallback(mPresenterCallback);
popup.setForceShowIcon(mForceShowIcon);
popup.setGravity(mDropDownGravity);
return popup;
}
use of android.annotation.NonNull in project android_frameworks_base by AOSPA.
the class DrawableInflater method inflateFromClass.
@NonNull
private Drawable inflateFromClass(@NonNull String className) {
try {
Constructor<? extends Drawable> constructor;
synchronized (CONSTRUCTOR_MAP) {
constructor = CONSTRUCTOR_MAP.get(className);
if (constructor == null) {
final Class<? extends Drawable> clazz = mClassLoader.loadClass(className).asSubclass(Drawable.class);
constructor = clazz.getConstructor();
CONSTRUCTOR_MAP.put(className, constructor);
}
}
return constructor.newInstance();
} catch (NoSuchMethodException e) {
final InflateException ie = new InflateException("Error inflating class " + className);
ie.initCause(e);
throw ie;
} catch (ClassCastException e) {
// If loaded class is not a Drawable subclass.
final InflateException ie = new InflateException("Class is not a Drawable " + className);
ie.initCause(e);
throw ie;
} catch (ClassNotFoundException e) {
// If loadClass fails, we should propagate the exception.
final InflateException ie = new InflateException("Class not found " + className);
ie.initCause(e);
throw ie;
} catch (Exception e) {
final InflateException ie = new InflateException("Error inflating class " + className);
ie.initCause(e);
throw ie;
}
}
use of android.annotation.NonNull in project android_frameworks_base by AOSPA.
the class AnimatedVectorDrawable method ensureAnimatorSet.
@NonNull
private void ensureAnimatorSet() {
if (mAnimatorSetFromXml == null) {
// TODO: Skip the AnimatorSet creation and init the VectorDrawableAnimator directly
// with a list of LocalAnimators.
mAnimatorSetFromXml = new AnimatorSet();
mAnimatedVectorState.prepareLocalAnimators(mAnimatorSetFromXml, mRes);
mAnimatorSet.init(mAnimatorSetFromXml);
mRes = null;
}
}
use of android.annotation.NonNull in project android_frameworks_base by AOSPA.
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 AOSPA.
the class ResourcesImpl method getQuantityText.
@NonNull
CharSequence getQuantityText(@PluralsRes int id, int quantity) throws NotFoundException {
PluralRules rule = getPluralRule();
CharSequence res = mAssets.getResourceBagText(id, attrForQuantityCode(rule.select(quantity)));
if (res != null) {
return res;
}
res = mAssets.getResourceBagText(id, ID_OTHER);
if (res != null) {
return res;
}
throw new NotFoundException("Plural resource ID #0x" + Integer.toHexString(id) + " quantity=" + quantity + " item=" + rule.select(quantity));
}
Aggregations